From nobody Mon Feb 9 10:57:19 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1662384880; cv=none; d=zohomail.com; s=zohoarc; b=A2WGRE/W/x7fFxTM+imOukfvcjc/ICrlzcJ95TBgiR+ixfghpC3J0Q8bKnpSw1cwQToWT1e0B9Vf1eqZ2chKbbCTaUAbo/8AmuZsbFzd5JpqmeTVzaAJx0H/g7elDW4ZVvj+SCoklvKWg9PtcJmZGfthYN+ZRUNc7qfGKRMORhs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662384880; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=cbSEyEjipCSM896pNHvWCr8t63ui2f+HenTyWRRkg7o=; b=aAN5jTQy00WeOnordcHK4YHKmf6i/3OeKJnC0fm36sJgAwODNTTEDMY3RMtcZMyJ/qwAH7CLtzfoYHFLAd2Rzgdg1YTblEl5Fw4kG3+gN9pNqmq/nMUFfnCgTrrvw5XQAyMFjElPxtqgFk1pZ4dWs4tnWm1wGaGcPnAAuTqE/kk= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1662384880096893.6314546889994; Mon, 5 Sep 2022 06:34:40 -0700 (PDT) Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647-1Yewjm08OJepgYDz9s4PJA-1; Mon, 05 Sep 2022 09:34:33 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 218028037AA; Mon, 5 Sep 2022 13:34:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (unknown [10.30.29.100]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0E3B9945DD; Mon, 5 Sep 2022 13:34:31 +0000 (UTC) Received: from mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (localhost [IPv6:::1]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id E71A41946A48; Mon, 5 Sep 2022 13:34:30 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.rdu2.redhat.com [10.11.54.2]) by mm-prod-listman-01.mail-001.prod.us-east-1.aws.redhat.com (Postfix) with ESMTP id 586A7194B97A for ; Mon, 5 Sep 2022 13:34:29 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 3F88440D2830; Mon, 5 Sep 2022 13:34:29 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id A6B9D40D282E for ; Mon, 5 Sep 2022 13:34:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662384879; h=from:from:sender:sender: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:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=cbSEyEjipCSM896pNHvWCr8t63ui2f+HenTyWRRkg7o=; b=PRwFyVweb1nKtk1okrl8semhrPKXVNUxzrSK84YN3rLY9Pp3HvyKGzWDdTuKX7M81vakGW af355wxKG3N/doEUG3o7BzNdqOhhrtIbVUsM5YSpxsWYCcL2IXkwQv6/XwrkhFatW+EuMJ PbfRuJtUawsQeePaPf0TkX6JFoguem0= X-MC-Unique: 1Yewjm08OJepgYDz9s4PJA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 4/7] util: virfile: Rewrite matching of FUSE-based shared filesystems Date: Mon, 5 Sep 2022 15:34:18 +0200 Message-Id: <287b7c467335f7994f9bf5efc10f9a1590c4f9e4.1662384799.git.pkrempa@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.2 X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libvir-list-bounces@redhat.com Sender: "libvir-list" X-Scanned-By: MIMEDefang 2.79 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1662384880809100002 Content-Type: text/plain; charset="utf-8" 'virFileIsSharedFixFUSE' was used to update the 'f_type' field for certain shared filesystem types. This patch renames it to 'virFileIsSharedFsFUSE' and makes it directly return whether the FUSE filesystem is shared or not and simplifies additions to the list of shared FUSE filesystems. Signed-off-by: Peter Krempa --- src/util/virfile.c | 54 ++++++++++++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index a8443acf8d..33a3ffe8f7 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3324,17 +3324,27 @@ virFileRemoveLastComponent(char *path) # define PROC_MOUNTS "/proc/mounts" + +struct virFileSharedFsData { + const char *mnttype; + unsigned int fstype; +}; + +static const struct virFileSharedFsData virFileSharedFsFUSE[] =3D { + { .mnttype =3D "fuse.glusterfs", .fstype =3D VIR_FILE_SHFS_GFS2 }, + { .mnttype =3D "fuse.quobyte", .fstype =3D VIR_FILE_SHFS_QB }, +}; + static int -virFileIsSharedFixFUSE(const char *path, - long long *f_type) +virFileIsSharedFsFUSE(const char *path, + unsigned int fstypes) { FILE *f =3D NULL; struct mntent mb; char mntbuf[1024]; - char *mntDir =3D NULL; - char *mntType =3D NULL; g_autofree char *canonPath =3D NULL; size_t maxMatching =3D 0; + bool isShared =3D false; if (!(canonPath =3D virFileCanonicalizePath(path))) { virReportSystemError(errno, _("unable to canonicalize %s"), path); @@ -3359,28 +3369,30 @@ virFileIsSharedFixFUSE(const char *path, continue; if (len > maxMatching) { + size_t i; + bool found =3D false; + + for (i =3D 0; i < G_N_ELEMENTS(virFileSharedFsFUSE); i++) { + if (STREQ_NULLABLE(mb.mnt_type, virFileSharedFsFUSE[i].mnt= type) && + (fstypes & virFileSharedFsFUSE[i].fstype) > 0) { + found =3D true; + break; + } + } + + VIR_DEBUG("Updating shared=3D'%d' for mountpoint '%s' type '%s= '", + found, p, mb.mnt_type); + + isShared =3D found; maxMatching =3D len; - VIR_FREE(mntType); - VIR_FREE(mntDir); - mntDir =3D g_strdup(mb.mnt_dir); - mntType =3D g_strdup(mb.mnt_type); } } endmntent(f); - if (STREQ_NULLABLE(mntType, "fuse.glusterfs")) { - VIR_DEBUG("Found gluster FUSE mountpoint=3D%s for path=3D%s. " - "Fixing shared FS type", mntDir, canonPath); - *f_type =3D GFS2_MAGIC; - } else if (STREQ_NULLABLE(mntType, "fuse.quobyte")) { - VIR_DEBUG("Found Quobyte FUSE mountpoint=3D%s for path=3D%s. " - "Fixing shared FS type", mntDir, canonPath); - *f_type =3D QB_MAGIC; - } + if (isShared) + return 1; - VIR_FREE(mntType); - VIR_FREE(mntDir); return 0; } @@ -3432,8 +3444,8 @@ virFileIsSharedFSType(const char *path, f_type =3D sb.f_type; if (f_type =3D=3D FUSE_SUPER_MAGIC) { - VIR_DEBUG("Found FUSE mount for path=3D%s. Trying to fix it", path= ); - virFileIsSharedFixFUSE(path, &f_type); + VIR_DEBUG("Found FUSE mount for path=3D%s", path); + return virFileIsSharedFsFUSE(path, fstypes); } VIR_DEBUG("Check if path %s with FS magic %lld is shared", --=20 2.37.1