From nobody Fri Apr 26 09:51:58 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 1538565407023611.2534848005023; Wed, 3 Oct 2018 04:16:47 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.26]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 89D9D3002302; Wed, 3 Oct 2018 11:16:44 +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 47571300165D; Wed, 3 Oct 2018 11:16:44 +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 B9C3D4BB79; Wed, 3 Oct 2018 11:16:43 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w93BGgKb004520 for ; Wed, 3 Oct 2018 07:16:42 -0400 Received: by smtp.corp.redhat.com (Postfix) id 5F4AD66070; Wed, 3 Oct 2018 11:16:42 +0000 (UTC) Received: from moe.brq.redhat.com (unknown [10.43.2.192]) by smtp.corp.redhat.com (Postfix) with ESMTP id D55AA17F20 for ; Wed, 3 Oct 2018 11:16:38 +0000 (UTC) From: Michal Privoznik To: libvir-list@redhat.com Date: Wed, 3 Oct 2018 13:16:35 +0200 Message-Id: <9ea88aa46b3f761b44e9ef1900e50d2d8f982790.1538565339.git.mprivozn@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2] 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.84 on 10.5.11.26 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Wed, 03 Oct 2018 11:16:45 +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 Reviewed-by: Jiri Denemark --- diff to v1: - fixed the function name - switched from for() loop into virStringListHasString - ignoring retval of the function in the caller 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..2a7e87102a 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3458,6 +3458,76 @@ 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 +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]; + 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; + } + + /* 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 (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); + + ret =3D 0; + cleanup: + endmntent(f); + VIR_FREE(mounts); + VIR_FREE(dirpath); + return ret; +} + =20 int virFileIsSharedFSType(const char *path, @@ -3503,6 +3573,11 @@ 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= ); + virFileIsSharedFixFUSE(path, (long *) &sb.f_type); + } + 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