Re: [PATCH 08/10] utils: Use overrides in virFileIsSharedFS()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Mar 20, 2024 at 10:19:13 +0100, Andrea Bolognani wrote:
> If the filesystem wasn't determined to be a shared one via the
> type check, try comparing it with the additional paths that
> have been configured by the local admin.
> 
> Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
> ---
>  src/util/virfile.c | 86 ++++++++++++++++++++++++++++++++++++++--------
>  1 file changed, 72 insertions(+), 14 deletions(-)
> 
> diff --git a/src/util/virfile.c b/src/util/virfile.c
> index a6a7de9829..ac9b5a77a6 100644
> --- a/src/util/virfile.c
> +++ b/src/util/virfile.c
> @@ -3795,22 +3795,80 @@ virFileGetDefaultHugepage(virHugeTLBFS *fs,
>      return NULL;
>  }
>  
> +static int
> +virFileIsSharedFSOverrideCompare(const char *path,
> +                                 char *const *overrides)
> +{
> +    char *const *iter = overrides;
> +
> +    while (*iter != NULL) {
> +        if (STREQ(path, *iter))
> +            return 1;
> +        iter++;

This is g_strv_contains in disguise.


> +    }
> +
> +    return 0;
> +}
> +
> +static int
> +virFileIsSharedFSOverride(const char *path,
> +                          char *const *overrides)
> +{
> +    g_autofree char *dirpath = NULL;
> +    char *p = NULL;
> +    int ret = 0;
> +
> +    if (!path || path[0] != '/' || !overrides)
> +        return ret;

Return 0 directly.

> +
> +    dirpath = g_strdup(path);
> +
> +    ret = virFileIsSharedFSOverrideCompare(dirpath, overrides);

Same here, return success directly rather than having the reader look
what's happening.

> +
> +    /* Continue until we've scanned the entire path or found a match */
> +    while (p != dirpath && ret == 0) {
> +
> +        /* Find the last slash */
> +        if ((p = strrchr(dirpath, '/')) == NULL)
> +            break;
> +
> +        /* Truncate the path by overwriting the slash that we've just
> +         * found with a null byte. If it is the very first slash in
> +         * the path, we need to handle things slightly differently */
> +        if (p == dirpath)
> +            *(p+1) = '\0';
> +        else
> +            *p = '\0';
> +
> +        ret = virFileIsSharedFSOverrideCompare(dirpath, overrides);

Here too.

> +    }
> +
> +    return ret;

And return failure/negative answer here also directly. Also consider
returning boolean as it's returning just 1 and 0, which would make the
first question I had (What do the return values mean?!?!) auto-answered.

> +}
> +
_______________________________________________
Devel mailing list -- devel@xxxxxxxxxxxxxxxxx
To unsubscribe send an email to devel-leave@xxxxxxxxxxxxxxxxx




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux