From nobody Wed May 8 22:44:56 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 1538380577548194.9196886074842; Mon, 1 Oct 2018 00:56:17 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 284CB356EC; Mon, 1 Oct 2018 07:56:14 +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 8B26D76613; Mon, 1 Oct 2018 07:56:12 +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 E71414BB75; Mon, 1 Oct 2018 07:56:10 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w917u9U4007752 for ; Mon, 1 Oct 2018 03:56:09 -0400 Received: by smtp.corp.redhat.com (Postfix) id 93C02183B6; Mon, 1 Oct 2018 07:56:09 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id 14CDE183C0 for ; Mon, 1 Oct 2018 07:56:06 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Mon, 1 Oct 2018 09:56:01 +0200 Message-Id: <9d0b0de5eb13b5ead5d96522f9ffc4e8a0d528a0.1538380547.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH] virFileIsSharedFSType: Check for fuse.glusterfs too 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Mon, 01 Oct 2018 07:56:15 +0000 (UTC) X-ZohoMail: RDMRC_0 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1632711 GlusterFS is typically safe when it comes to migration. It's a network FS after all. However, it can be mounted via FUSE driver they provide. If that is the case we fail to identify it and think migration is not safe and require VIR_MIGRATE_UNSAFE flag. Signed-off-by: Michal Privoznik --- src/util/virfile.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++-- 1 file changed, 75 insertions(+), 2 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index f8ae07fe4a..ccffa063a6 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3458,6 +3458,75 @@ int virFilePrintf(FILE *fp, const char *msg, ...) # ifndef HUGETLBFS_MAGIC # define HUGETLBFS_MAGIC 0x958458f6 # endif +# ifndef FUSE_SUPER_MAGIC +# define FUSE_SUPER_MAGIC 0x65735546 +# endif + +# define PROC_MOUNTS "/proc/mounts" + +static int +virFileIsShareFixFUSE(const char *path, + long *f_type) +{ + char *dirpath =3D NULL; + const char **mounts =3D NULL; + size_t nmounts =3D 0; + size_t i; + char *p; + FILE *f =3D NULL; + struct mntent mb; + char mntbuf[1024]; + bool found =3D false; + int ret =3D -1; + + if (VIR_STRDUP(dirpath, path) < 0) + return -1; + + if (!(f =3D setmntent(PROC_MOUNTS, "r"))) { + virReportSystemError(errno, + _("Unable to open %s"), + PROC_MOUNTS); + goto cleanup; + } + + while (getmntent_r(f, &mb, mntbuf, sizeof(mntbuf))) { + if (STRNEQ("fuse.glusterfs", mb.mnt_type)) + continue; + + if (VIR_APPEND_ELEMENT_COPY(mounts, nmounts, mb.mnt_dir) < 0) + goto cleanup; + } + + do { + if ((p =3D strrchr(dirpath, '/')) =3D=3D NULL) { + virReportSystemError(EINVAL, + _("Invalid relative path '%s'"), path); + goto cleanup; + } + + if (p =3D=3D dirpath) + *(p+1) =3D '\0'; + else + *p =3D '\0'; + + for (i =3D 0; i < nmounts; i++) { + if (STREQ(dirpath, mounts[i])) { + found =3D true; + VIR_DEBUG("Found gluster FUSE mountpoint=3D%s for path=3D%= s. " + "Fixing shared FS type", mounts[i], path); + *f_type =3D GFS2_MAGIC; + } + } + } while (!found && p !=3D dirpath); + + ret =3D 0; + cleanup: + endmntent(f); + VIR_FREE(mounts); + VIR_FREE(dirpath); + return ret; +} + =20 int virFileIsSharedFSType(const char *path, @@ -3503,6 +3572,12 @@ virFileIsSharedFSType(const char *path, return -1; } =20 + if (sb.f_type =3D=3D FUSE_SUPER_MAGIC) { + VIR_DEBUG("Found FUSE mount for path=3D%s. Trying to fix it", path= ); + if (virFileIsShareFixFUSE(path, (long *) &sb.f_type) < 0) + return -1; + } + VIR_DEBUG("Check if path %s with FS magic %lld is shared", path, (long long int)sb.f_type); =20 @@ -3594,8 +3669,6 @@ virFileGetDefaultHugepageSize(unsigned long long *siz= e) return 0; } =20 -# define PROC_MOUNTS "/proc/mounts" - int virFileFindHugeTLBFS(virHugeTLBFSPtr *ret_fs, size_t *ret_nfs) --=20 2.16.4 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list