From: Jiri Denemark Date: Tue, 3 Jun 2025 09:23:28 +0000 (+0200) Subject: util: Move virFileGetExistingParent out of ifdef __linux__ X-Git-Tag: v11.5.0-rc1~113 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b1393357c72b3baf04eefc35929002c62bcce80;p=thirdparty%2Flibvirt.git util: Move virFileGetExistingParent out of ifdef __linux__ The function is called by virFileIsSharedFSOverride which is not Linux specific and thus building on anything but Linux failes. Fixes: 94fb348d670f612c0b58901c9829b4eec81faa50 Signed-off-by: Jiri Denemark Reviewed-by: Martin Kletzander --- diff --git a/src/util/virfile.c b/src/util/virfile.c index 795f0218b4..3b7a795d45 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3444,6 +3444,34 @@ virFileRemoveLastComponent(char *path) path[0] = '\0'; } + +static char * +virFileGetExistingParent(const char *path) +{ + g_autofree char *dirpath = g_strdup(path); + char *p = NULL; + + /* Try less and less of the path until we get to a directory we can access. + * Even if we don't have 'x' permission on any directory in the path on the + * NFS server (assuming it's NFS), we will be able to stat the mount point. + */ + while (!virFileExists(dirpath) && p != dirpath) { + if (!(p = strrchr(dirpath, '/'))) { + virReportSystemError(EINVAL, + _("Invalid relative path '%1$s'"), path); + return NULL; + } + + if (p == dirpath) + *(p + 1) = '\0'; + else + *p = '\0'; + } + + return g_steal_pointer(&dirpath); +} + + #ifdef __linux__ # ifndef NFS_SUPER_MAGIC @@ -3557,33 +3585,6 @@ virFileIsSharedFsFUSE(const char *path, } -static char * -virFileGetExistingParent(const char *path) -{ - g_autofree char *dirpath = g_strdup(path); - char *p = NULL; - - /* Try less and less of the path until we get to a directory we can access. - * Even if we don't have 'x' permission on any directory in the path on the - * NFS server (assuming it's NFS), we will be able to stat the mount point. - */ - while (!virFileExists(dirpath) && p != dirpath) { - if (!(p = strrchr(dirpath, '/'))) { - virReportSystemError(EINVAL, - _("Invalid relative path '%1$s'"), path); - return NULL; - } - - if (p == dirpath) - *(p + 1) = '\0'; - else - *p = '\0'; - } - - return g_steal_pointer(&dirpath); -} - - static const struct virFileSharedFsData virFileSharedFs[] = { { .fstype = VIR_FILE_SHFS_NFS, .magic = NFS_SUPER_MAGIC }, { .fstype = VIR_FILE_SHFS_GFS2, .magic = GFS2_MAGIC },