[libvirt] [PATCH v1 2/7] Introduce virFileFindHugeTLBFS

Daniel P. Berrange berrange at redhat.com
Mon Jul 21 15:01:36 UTC 2014


On Thu, Jul 17, 2014 at 06:12:43PM +0200, Michal Privoznik wrote:
> This should iterate over mount tab and search for hugetlbfs among with
> looking for the default value of huge pages.
> 
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>  src/libvirt_private.syms |   1 +
>  src/util/virfile.c       | 155 +++++++++++++++++++++++++++++++++++++++++++++++
>  src/util/virfile.h       |  12 ++++
>  3 files changed, 168 insertions(+)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 8d3671c..44403fd 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1297,6 +1297,7 @@ virFileDirectFdFlag;
>  virFileExists;
>  virFileFclose;
>  virFileFdopen;
> +virFileFindHugeTLBFS;
>  virFileFindMountPoint;
>  virFileFindResource;
>  virFileFindResourceFull;
> diff --git a/src/util/virfile.c b/src/util/virfile.c
> index 699b9f8..e1034b7 100644
> --- a/src/util/virfile.c
> +++ b/src/util/virfile.c

>  
> +int
> +virFileGetHugepageSize(const char *path,
> +                       unsigned long long *size)

This ought to be in libvirt_private.sym too

>  
> +int
> +virFileGetHugepageSize(const char *path,
> +                       unsigned long long *size)
> +{
> +    /* XXX implement me :-) */
> +    VIR_WARN("Trying to get huge page size on %s is not implemented yet.",
> +             path);
> +    *size = 2048; /* Pure guess */
> +    return 0;
> +}

Hmm, seems like we should really report an fatal error here, since
I don't think it makes sense to continue QEMU startup in this scenario.



> +
> +# define PROC_MOUNTS "/proc/mounts"
> +
> +int
> +virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
> +                     size_t *ret_nfs)
> +{
> +    int ret = -1;
> +    FILE *f = NULL;
> +    struct mntent mb;
> +    char mntbuf[1024];
> +    virHugeTLBFSPtr fs = NULL;
> +    size_t nfs = 0;
> +    unsigned long long default_hugepagesz;
> +
> +    if (virFileGetDefaultHugepageSize(&default_hugepagesz) < 0)
> +        goto cleanup;
> +
> +    if (!(f = setmntent(PROC_MOUNTS, "r"))) {
> +        virReportSystemError(errno,
> +                             _("Unable to open %s"),
> +                             PROC_MOUNTS);
> +        goto cleanup;
> +    }
> +
> +    while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) {
> +        virHugeTLBFSPtr tmp;
> +
> +        if (STRNEQ(mb.mnt_type, "hugetlbfs"))
> +            continue;
> +
> +        if (VIR_REALLOC_N(fs, nfs + 1) < 0)
> +            goto cleanup;
> +
> +        tmp = &fs[nfs];
> +        nfs++;

Perhaps VIR_EXPAND_N would be nicer ?

> +
> +        if (VIR_STRDUP(tmp->mnt_dir, mb.mnt_dir) < 0)
> +            goto cleanup;
> +
> +        if (virFileGetHugepageSize(tmp->mnt_dir, &tmp->size) < 0)
> +            goto cleanup;
> +
> +        tmp->deflt = tmp->size == default_hugepagesz;
> +    }
> +
> +    *ret_fs = fs;
> +    *ret_nfs = nfs;
> +    fs = NULL;
> +    nfs = 0;
> +    ret = 0;
> +
> + cleanup:
> +    endmntent(f);
> +    while (nfs)
> +        VIR_FREE(fs[--nfs].mnt_dir);
> +    VIR_FREE(fs);
> +    return ret;
> +}
> +
> +#else
> +
> +int
> +virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs,
> +                     size_t *ret_nfs)
> +{
> +    /* XXX implement me :-) */
> +    *ret_fs = NULL;
> +    *ret_nfs = 0;
> +    return 0;
> +}

Again report a fatal error here

> +#endif /* ! defined __linux__ && defined HAVE_MNTENT_H &&
> +          defined HAVE_GETMNTENT_R */


Regards,
Daniel
-- 
|: http://berrange.com      -o-    http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org              -o-             http://virt-manager.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org       -o-       http://live.gnome.org/gtk-vnc :|




More information about the libvir-list mailing list