From nobody Mon Sep 8 21:39:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1748941710; cv=none; d=zohomail.com; s=zohoarc; b=mbBDdwHXgKikwUttZladLglDBTLn3TxGQCXYIMmGR3uq14YR3e+j4xSTD24/BQ2qj7c2UvmHF5iVhYPWxoJmtMM5+VsDsu9tM6PsOaUnMdLTU5hulR8hwO+z63ELfakOGViHlvfpDtl2wqnYJ7DhhjQvMjhSHMNkwvrMHZZWN/c= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748941710; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=Rgu/KJuFMxgA+QcTs0NJTHNsxKewmy0c6huLu6vkoUM=; b=fYG5fuaIwB7yb13kncOkzKCZs7/Ds7kDdNZlrBUDGyKgNXdb+KceW1VsP23Sp2344BtWgF5zMd+VvpxZdZSAc7vNas+vAEOdXVdqYhnZC8JV0r3/K+MnTpU/vLTiQ12hOJpRC/bYSHyf3cQLhcr9gT/5YS0ublChcGKczdjwGhg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1748941710988122.53215522150924; Tue, 3 Jun 2025 02:08:30 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id CAD061353; Tue, 3 Jun 2025 05:08:29 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 43F0614A7; Tue, 3 Jun 2025 05:07:56 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 87B0D11CB; Tue, 3 Jun 2025 05:07:51 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 127ED1185 for ; Tue, 3 Jun 2025 05:07:51 -0400 (EDT) Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-512-rjMLB5gfN3OVtsctoguloA-1; Tue, 03 Jun 2025 05:07:49 -0400 Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ED75019560AF for ; Tue, 3 Jun 2025 09:07:48 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 788951956094 for ; Tue, 3 Jun 2025 09:07:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748941670; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2GdzxDQkL7Yybv+Cc7WC3GRUFMaGXLG412FFdjpEXgM=; b=aTUgIQXQsDskcNd+bZqdQucepGYU+Mh8hubQ3evyBp9jhxfiiz5YBMkDX1/IP4TZrKF40h E4BCs7YFMjK0xSxI+hV6FzC1NPHvpeOjaT6sE7UTzHp6hsr4eTqcDlvparMgrPHyX5FR7w w5RGGhSftuGTcOj7Kjs9HJup1rJgtOU= X-MC-Unique: rjMLB5gfN3OVtsctoguloA-1 X-Mimecast-MFC-AGG-ID: rjMLB5gfN3OVtsctoguloA_1748941669 To: devel@lists.libvirt.org Subject: [PATCH 1/2] util: Avoid statfs in virFileGetExistingParent Date: Tue, 3 Jun 2025 11:07:43 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: Mjuu0HzYHCrnmnoeJYGSXt6m7Py-l3L7B6nCECcbtlg_1748941669 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: DMEIGL35ADTFU2HVOSAXXCFT6A5BEBBZ X-Message-ID-Hash: DMEIGL35ADTFU2HVOSAXXCFT6A5BEBBZ X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Jiri Denemark via Devel Reply-To: Jiri Denemark X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748941711841116600 Content-Type: text/plain; charset="utf-8" From: Jiri Denemark 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 Reviewed-by: Martin Kletzander --- 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 =3D g_strdup(path); - struct statfs sb; char *p =3D NULL; =20 /* Try less and less of the path until we get to a directory we can st= at. * Even if we don't have 'x' permission on any directory in the path o= n the * NFS server (assuming it's NFS), we will be able to stat the mount p= oint. */ - while (statfs(dirpath, &sb) < 0 && p !=3D dirpath) { + while (!virFileExists(dirpath) && p !=3D dirpath) { if (!(p =3D strrchr(dirpath, '/'))) { virReportSystemError(EINVAL, _("Invalid relative path '%1$s'"), path); diff --git a/tests/virfilemock.c b/tests/virfilemock.c index 4f1b8aecd7..5a09cce855 100644 --- a/tests/virfilemock.c +++ b/tests/virfilemock.c @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef __linux__ # include #endif @@ -32,6 +33,7 @@ static FILE *(*real_setmntent)(const char *filename, const char *type); static int (*real_statfs)(const char *path, struct statfs *buf); static char *(*real_realpath)(const char *path, char *resolved); +static int (*real_access)(const char *path, int mode); =20 =20 static void @@ -43,6 +45,7 @@ init_syms(void) VIR_MOCK_REAL_INIT(setmntent); VIR_MOCK_REAL_INIT(statfs); VIR_MOCK_REAL_INIT(realpath); + VIR_MOCK_REAL_INIT(access); } =20 =20 @@ -200,3 +203,28 @@ realpath(const char *path, char *resolved) =20 return real_realpath(path, resolved); } + + +int +access(const char *path, int mode) +{ + const char *mtab =3D getenv("LIBVIRT_MTAB"); + + init_syms(); + + if (mtab && mode =3D=3D F_OK) { + struct statfs buf; + + /* The real statfs works on any existing file on a filesystem, whi= le + * our mocked version only works on the mount point. Thus we have = to + * pretend no files on the filesystem exist to make sure + * virFileGetExistingParent returns the mount point which can late= r be + * checked by statfs. Instead of checking we were called for a mou= nt + * point by walking through the mtab, we just call our mocked stat= fs + * that does it for us. + */ + return statfs_mock(mtab, path, &buf); + } + + return real_access(path, mode); +} --=20 2.49.0 From nobody Mon Sep 8 21:39:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass(p=reject dis=none) header.from=lists.libvirt.org ARC-Seal: i=1; a=rsa-sha256; t=1748941730; cv=none; d=zohomail.com; s=zohoarc; b=WZTyPh8MgCDiiqo7MF2Qwuvh14x/e9zeOhzu/R5K9EUAduqjvA0KNAssAZ3rKWBiTgi5h8vZu/uerTwYmKKXT3yAuH9Fbe/VxIiGwhYEziKKMSv7InKVpJsJZgxI+Fqk1+Ls3p3MJtLssalR0TWG2jzycuA69RpypFltA9JSO6I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1748941730; h=Content-Type:Content-Transfer-Encoding:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:Reply-To:References:Subject:Subject:To:To:Message-Id:Cc; bh=Xi+lv1kRA12m13PFJVDsdn0Y54rR2VLT+S4lz7r2TEg=; b=kzoaBnKQzIxveUVKFKqtRChz2OxkAYceu65fXxAQJsZ970o95F2wMiMVAY+QSmTUYkw+WMEiP82I9GUxQj7bNr+cxF2Xc3qjjskH0M4vw+0RjXC1ImZ5zup48mh5iZWqbzVW/6j6BEeCqKSY4YSnJYUf/zIia4n/HTPiJLAVfX0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=pass header.from= (p=reject dis=none) Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1748941730770562.2399793298541; Tue, 3 Jun 2025 02:08:50 -0700 (PDT) Received: by lists.libvirt.org (Postfix, from userid 996) id A57821393; Tue, 3 Jun 2025 05:08:49 -0400 (EDT) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 136B81403; Tue, 3 Jun 2025 05:08:04 -0400 (EDT) Received: by lists.libvirt.org (Postfix, from userid 996) id 1DA2C1542; Tue, 3 Jun 2025 05:08:00 -0400 (EDT) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id B1BE51542 for ; Tue, 3 Jun 2025 05:07:53 -0400 (EDT) Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-443-M628VQDxMAW_LVQxYi3kJA-1; Tue, 03 Jun 2025 05:07:51 -0400 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E09AC19560B1 for ; Tue, 3 Jun 2025 09:07:50 +0000 (UTC) Received: from orkuz (unknown [10.43.3.115]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 6C39C19560AB for ; Tue, 3 Jun 2025 09:07:50 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1748941673; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=nD8wRSRxQW9uve/8/XR6p34DP4JdwNJbEmvKxEVku9U=; b=H8e/jtMGqNiknBe+EIKIOEr3k/VUHuO+zEaryEm+fhV01+Jcqb7dIgpiIbWco8y5O/zUwb LH8bOsXeBYiCz/RLuQM2hnN5YcKgm9OpbiYCZoy5hYHDMbrVK/87BrbGkjOvtrG4y1Qwq0 hESm/MkzKr9pJ9Pvnrh8MRFImdIKgkE= X-MC-Unique: M628VQDxMAW_LVQxYi3kJA-1 X-Mimecast-MFC-AGG-ID: M628VQDxMAW_LVQxYi3kJA_1748941671 To: devel@lists.libvirt.org Subject: [PATCH 2/2] util: Move virFileGetExistingParent out of ifdef __linux__ Date: Tue, 3 Jun 2025 11:07:44 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: DDrITzTF-Q_Ga2Nh8QLz-TcBJN735NYSbR8oog51ZXc_1748941671 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: 7KYBDKZVBGUHTA4DL6537XX2YPFWMFBP X-Message-ID-Hash: 7KYBDKZVBGUHTA4DL6537XX2YPFWMFBP X-MailFrom: jdenemar@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: From: Jiri Denemark via Devel Reply-To: Jiri Denemark X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1748941732034116600 Content-Type: text/plain; charset="utf-8" From: Jiri Denemark 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 --- src/util/virfile.c | 55 +++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index d79a60baee..1b3f37db7a 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3444,6 +3444,34 @@ virFileRemoveLastComponent(char *path) path[0] =3D '\0'; } =20 + +static char * +virFileGetExistingParent(const char *path) +{ + g_autofree char *dirpath =3D g_strdup(path); + char *p =3D NULL; + + /* Try less and less of the path until we get to a directory we can st= at. + * Even if we don't have 'x' permission on any directory in the path o= n the + * NFS server (assuming it's NFS), we will be able to stat the mount p= oint. + */ + while (!virFileExists(dirpath) && p !=3D dirpath) { + if (!(p =3D strrchr(dirpath, '/'))) { + virReportSystemError(EINVAL, + _("Invalid relative path '%1$s'"), path); + return NULL; + } + + if (p =3D=3D dirpath) + *(p + 1) =3D '\0'; + else + *p =3D '\0'; + } + + return g_steal_pointer(&dirpath); +} + + #ifdef __linux__ =20 # ifndef NFS_SUPER_MAGIC @@ -3557,33 +3585,6 @@ virFileIsSharedFsFUSE(const char *path, } =20 =20 -static char * -virFileGetExistingParent(const char *path) -{ - g_autofree char *dirpath =3D g_strdup(path); - char *p =3D NULL; - - /* Try less and less of the path until we get to a directory we can st= at. - * Even if we don't have 'x' permission on any directory in the path o= n the - * NFS server (assuming it's NFS), we will be able to stat the mount p= oint. - */ - while (!virFileExists(dirpath) && p !=3D dirpath) { - if (!(p =3D strrchr(dirpath, '/'))) { - virReportSystemError(EINVAL, - _("Invalid relative path '%1$s'"), path); - return NULL; - } - - if (p =3D=3D dirpath) - *(p + 1) =3D '\0'; - else - *p =3D '\0'; - } - - return g_steal_pointer(&dirpath); -} - - static const struct virFileSharedFsData virFileSharedFs[] =3D { { .fstype =3D VIR_FILE_SHFS_NFS, .magic =3D NFS_SUPER_MAGIC }, { .fstype =3D VIR_FILE_SHFS_GFS2, .magic =3D GFS2_MAGIC }, --=20 2.49.0