On Thu, Nov 29, 2018 at 02:52:17PM +0100, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
> ---
>  src/libvirt_private.syms |   3 +
>  src/util/virfile.c       | 121 +++++++++++++++++++++++++++++++++++++++
>  src/util/virfile.h       |  11 ++++
>  3 files changed, 135 insertions(+)
> 
> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
> index 5018a13e9c..8e5b610ab1 100644
> --- a/src/libvirt_private.syms
> +++ b/src/libvirt_private.syms
> @@ -1827,6 +1827,7 @@ virFileGetACLs;
>  virFileGetHugepageSize;
>  virFileGetMountReverseSubtree;
>  virFileGetMountSubtree;
> +virFileGetXAtrr;

s/Atrr/Attr/

> @@ -1873,6 +1875,7 @@ virFileRewriteStr;
>  virFileSanitizePath;
>  virFileSetACLs;
>  virFileSetupDev;
> +virFileSetXAtrr;

s/Atrr/Attr/


> +#if HAVE_LIBATTR
> +/**
> + * virFileGetXAtrr;
> + * @path: a filename
> + * @name: name of xattr
> + * @value: read value
> + *
> + * Reads xattr with @name for given @path and stores it into
> + * @value. Caller is responsible for freeing @value.
> + *
> + * Returns: 0 on success,
> + *         -1 otherwise (with errno set).
> + */
> +int
> +virFileGetXAtrr(const char *path,
> +                const char *name,
> +                char **value)
> +{
> +    char *buf = NULL;
> +    int ret = -1;
> +
> +    /* We might be racing with somebody who sets the same attribute. */
> +    do {
> +        ssize_t need;
> +        ssize_t got;
> +
> +        /* The first call determines how many bytes we need to allocate. */
> +        if ((need = getxattr(path, name, NULL, 0)) < 0)
> +            goto cleanup;
> +
> +        if (VIR_REALLOC_N_QUIET(buf, need + 1) < 0)
> +            goto cleanup;
> +
> +        if ((got = getxattr(path, name, buf, need)) < 0) {
> +            if (errno == ERANGE)
> +                continue;
> +            goto cleanup;
> +        }
> +
> +        buf[got] = '\0';
> +        break;
> +    } while (1);

Nitpick, I'd expect the while(1) at the top. Only use this style of
loop when the checked loop condition would mistakenly prevent the first
iteration running.

> +
> +    VIR_STEAL_PTR(*value, buf);
> +    ret = 0;
> + cleanup:
> +    VIR_FREE(buf);
> +    return ret;
> +}

Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to