From: Andrea Bolognani Date: Fri, 2 Aug 2024 13:23:37 +0000 (+0200) Subject: utils: Use overrides in virFileIsSharedFS() X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=f7b9313ec7dd9878df605c39f0a003eccdf96141;p=libvirt.git utils: Use overrides in virFileIsSharedFS() If the local admin has explicitly declared that a certain filesystem is to be considered shared, we should treat it as such. Signed-off-by: Andrea Bolognani Reviewed-by: Stefan Berger Reviewed-by: Peter Krempa --- diff --git a/src/util/virfile.c b/src/util/virfile.c index e02ad0ef65..a8abd7d913 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3804,9 +3804,49 @@ virFileGetDefaultHugepage(virHugeTLBFS *fs, return NULL; } +static bool +virFileIsSharedFSOverride(const char *path, + char *const *overrides) +{ + g_autofree char *dirpath = NULL; + char *p = NULL; + + if (!path || path[0] != '/' || !overrides) + return false; + + if (g_strv_contains((const char *const *) overrides, path)) + return true; + + dirpath = g_strdup(path); + + /* Continue until we've scanned the entire path */ + while (p != dirpath) { + + /* 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'; + + if (g_strv_contains((const char *const *) overrides, dirpath)) + return true; + } + + return false; +} + int virFileIsSharedFS(const char *path, - char *const *overrides G_GNUC_UNUSED) + char *const *overrides) { + if (virFileIsSharedFSOverride(path, overrides)) + return 1; + return virFileIsSharedFSType(path, VIR_FILE_SHFS_NFS | VIR_FILE_SHFS_GFS2 |