From nobody Mon Sep 16 20:32:22 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1539092943299251.93358478268112; Tue, 9 Oct 2018 06:49:03 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4BEE361476; Tue, 9 Oct 2018 13:49:01 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EF0E06F95C; Tue, 9 Oct 2018 13:49:00 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 999F64CAAD; Tue, 9 Oct 2018 13:49:00 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w99Dmuei007095 for ; Tue, 9 Oct 2018 09:48:56 -0400 Received: by smtp.corp.redhat.com (Postfix) id 212A81001F5E; Tue, 9 Oct 2018 13:48:56 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 763171062242; Tue, 9 Oct 2018 13:48:55 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 9 Oct 2018 15:48:46 +0200 Message-Id: <673f4713518a9b027bf4de0c130038ca1380735f.1539092795.git.mprivozn@redhat.com> In-Reply-To: References: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Cc: hhan@redhat.com Subject: [libvirt] [PATCH 3/4] virFileIsSharedFSType: Detect direct mount points X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Tue, 09 Oct 2018 13:49:02 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" If the given path is already a mount point (e.g. a bind mount of a file, or simply a direct mount point of a FS), then our code fails to detect that because the first thing it does is cutting off part after last slash '/'. Signed-off-by: Michal Privoznik Reviewed-by: Jiri Denemark --- src/util/virfile.c | 8 ++++---- tests/virfiletest.c | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 2a7e87102a..666d703f99 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3534,15 +3534,16 @@ virFileIsSharedFSType(const char *path, int fstypes) { VIR_AUTOFREE(char *) dirpath =3D NULL; - char *p; + char *p =3D NULL; struct statfs sb; int statfs_ret; =20 if (VIR_STRDUP(dirpath, path) < 0) return -1; =20 - do { + statfs_ret =3D statfs(dirpath, &sb); =20 + while ((statfs_ret < 0) && (p !=3D dirpath)) { /* Try less and less of the path until we get to a * directory we can stat. Even if we don't have 'x' * permission on any directory in the path on the NFS @@ -3563,8 +3564,7 @@ virFileIsSharedFSType(const char *path, *p =3D '\0'; =20 statfs_ret =3D statfs(dirpath, &sb); - - } while ((statfs_ret < 0) && (p !=3D dirpath)); + } =20 if (statfs_ret < 0) { virReportSystemError(errno, diff --git a/tests/virfiletest.c b/tests/virfiletest.c index 22c163f0a0..42d918aecc 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -453,8 +453,7 @@ mymain(void) DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts1.txt", "/boot/vmlinuz", false); DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts2.txt", "/run/user/501/gvfs/some= /file", false); DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/file", true); - /* TODO Detect bind mounts */ - DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/blah", true); + DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/blah", false); =20 return ret !=3D 0 ? EXIT_FAILURE : EXIT_SUCCESS; } --=20 2.18.0 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list