From nobody Mon Sep 16 20:29:54 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 153909294846574.35306741195825; Tue, 9 Oct 2018 06:49:08 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 9681030001DD; Tue, 9 Oct 2018 13:49:06 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 54DD417F60; Tue, 9 Oct 2018 13:49:06 +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 E16D618005B2; Tue, 9 Oct 2018 13:49:05 +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 w99Dmvi7007102 for ; Tue, 9 Oct 2018 09:48:57 -0400 Received: by smtp.corp.redhat.com (Postfix) id 1D77E1001F5E; Tue, 9 Oct 2018 13:48:57 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7043F103BAB2; Tue, 9 Oct 2018 13:48:56 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Tue, 9 Oct 2018 15:48:47 +0200 Message-Id: <6fb19a29408c95c2e8c67b825261574cd1bff300.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 4/4] virfile: Rework virFileIsSharedFixFUSE 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.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 09 Oct 2018 13:49:07 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" There are couple of things wrong with the current implementation. The first one is that in the first loop the code tries to build a list of fuse.glusterfs mount points. Well, since the strings are allocated in a temporary buffer and are not duplicated this results in wrong decision made later in the code. The second problem is that the code does not take into account subtree mounts. For instance, if there's a fuse.gluster mounted at /some/path and another FS mounted at /some/path/subdir the code would not recognize this subdir mount. Reported-by: Han Han Signed-off-by: Michal Privoznik --- src/util/virfile.c | 58 +++++++++++++---------------------- tests/virfiledata/mounts3.txt | 2 ++ tests/virfiletest.c | 2 ++ 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 666d703f99..19f504cc6d 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3468,18 +3468,14 @@ static int virFileIsSharedFixFUSE(const char *path, long *f_type) { - char *dirpath =3D NULL; - const char **mounts =3D NULL; - size_t nmounts =3D 0; - char *p; FILE *f =3D NULL; struct mntent mb; char mntbuf[1024]; + char *mntDir =3D NULL; + char *mntType =3D NULL; + size_t maxMatching =3D 0; int ret =3D -1; =20 - if (VIR_STRDUP(dirpath, path) < 0) - return -1; - if (!(f =3D setmntent(PROC_MOUNTS, "r"))) { virReportSystemError(errno, _("Unable to open %s"), @@ -3488,43 +3484,33 @@ virFileIsSharedFixFUSE(const char *path, } =20 while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) { - if (STRNEQ("fuse.glusterfs", mb.mnt_type)) + const char *p; + size_t len =3D strlen(mb.mnt_dir); + + if (!(p =3D STRSKIP(path, mb.mnt_dir))) continue; =20 - if (VIR_APPEND_ELEMENT_COPY(mounts, nmounts, mb.mnt_dir) < 0) - goto cleanup; - } - - /* Add NULL sentinel so that this is a virStringList */ - if (VIR_REALLOC_N(mounts, nmounts + 1) < 0) - goto cleanup; - mounts[nmounts] =3D NULL; - - do { - if ((p =3D strrchr(dirpath, '/')) =3D=3D NULL) { - virReportSystemError(EINVAL, - _("Invalid relative path '%s'"), path); - goto cleanup; + if (len > maxMatching) { + len =3D maxMatching; + VIR_FREE(mntType); + VIR_FREE(mntDir); + if (VIR_STRDUP(mntDir, mb.mnt_dir) < 0 || + VIR_STRDUP(mntType, mb.mnt_type) < 0) + goto cleanup; } + } =20 - if (p =3D=3D dirpath) - *(p+1) =3D '\0'; - else - *p =3D '\0'; - - if (virStringListHasString(mounts, dirpath)) { - VIR_DEBUG("Found gluster FUSE mountpoint=3D%s for path=3D%s. " - "Fixing shared FS type", dirpath, path); - *f_type =3D GFS2_MAGIC; - break; - } - } while (p !=3D dirpath); + if (STREQ_NULLABLE(mntType, "fuse.glusterfs")) { + VIR_DEBUG("Found gluster FUSE mountpoint=3D%s for path=3D%s. " + "Fixing shared FS type", mntDir, path); + *f_type =3D GFS2_MAGIC; + } =20 ret =3D 0; cleanup: + VIR_FREE(mntType); + VIR_FREE(mntDir); endmntent(f); - VIR_FREE(mounts); - VIR_FREE(dirpath); return ret; } =20 diff --git a/tests/virfiledata/mounts3.txt b/tests/virfiledata/mounts3.txt index 226f67dc00..134c6e8f81 100644 --- a/tests/virfiledata/mounts3.txt +++ b/tests/virfiledata/mounts3.txt @@ -31,3 +31,5 @@ hugetlbfs /hugepages2M hugetlbfs rw,relatime,mode=3D1777,= pagesize=3D2M 0 0 none /run/user/1000 tmpfs rw,relatime,mode=3D700,uid=3D1000 0 0 host:/nfs /nfs nfs4 rw,relatime,vers=3D4.1,rsize=3D1048576,wsize=3D1048576= ,namlen=3D255,hard,proto=3Dtcp6,timeo=3D600,retrans=3D2,sec=3Dsys,clientadd= r=3D::,local_lock=3Dnone,addr=3D:: 0 0 dev /nfs/blah devtmpfs rw,nosuid,relatime,size=3D10240k,nr_inodes=3D409306= 0,mode=3D755 0 0 +host:/gv0 /gluster fuse.glusterfs rw 0 0 +root@host:/tmp/mkdir /gluster/sshfs fuse.sshfs rw 0 0 diff --git a/tests/virfiletest.c b/tests/virfiletest.c index 42d918aecc..d5102b1cc4 100644 --- a/tests/virfiletest.c +++ b/tests/virfiletest.c @@ -454,6 +454,8 @@ mymain(void) 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); DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/nfs/blah", false); + DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/gluster/file", true); + DO_TEST_FILE_IS_SHARED_FS_TYPE("mounts3.txt", "/gluster/sshfs/file", f= alse); =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