On Tue, Jun 03, 2025 at 11:07:43AM +0200, Jiri Denemark via Devel wrote:
From: Jiri Denemark <jdene...@redhat.com>

The code was separated from virFileIsSharedFSType which is Linux-only,
but virFileGetExistingParent is also called from
virFileIsSharedFSOverride which is OS independent. Thus we can't use
statfs. Let's use virFileExists (access) instead, we were not interested
in anything but success/failure from statfs anyway.

Signed-off-by: Jiri Denemark <jdene...@redhat.com>
---
src/util/virfile.c  |  3 +--
tests/virfilemock.c | 28 ++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/src/util/virfile.c b/src/util/virfile.c
index 06e8e08ddc..d79a60baee 100644
--- a/src/util/virfile.c
+++ b/src/util/virfile.c
@@ -3561,14 +3561,13 @@ static char *
virFileGetExistingParent(const char *path)
{
    g_autofree char *dirpath = g_strdup(path);
-    struct statfs sb;
    char *p = NULL;

    /* Try less and less of the path until we get to a directory we can stat.

s/stat/access/ maybe?

     * 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 (statfs(dirpath, &sb) < 0 && p != dirpath) {
+    while (!virFileExists(dirpath) && p != dirpath) {
        if (!(p = strrchr(dirpath, '/'))) {
            virReportSystemError(EINVAL,
                                 _("Invalid relative path '%1$s'"), path);

Attachment: signature.asc
Description: PGP signature

Reply via email to