From nobody Mon Feb 9 03:14:01 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=1662384978; cv=none; d=zohomail.com; s=zohoarc; b=Mk1+M/8lDCdVH8zgUq1xF3DPtNWQuC7DtyHgFYu+2nTdBdCtyILTdYGmuLuCPC8xSzdiwBpc1MjM4SvdcYclFGGNZafU5DQ80x+N3A4djBt9tSxiOzYY/CiqPtSPCWn0mruzpcNINunSHP17he8dz3PzIuTCpycHqTU4RsdgnYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1662384978; 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=6w1w+lbpiOxMxy7ouT8VVL3UYzh82jnt5AGOfabXEZY=; b=Q6f1aga1NuGhvnie85qbTwiI02UnvUwhnxsxQLu3s3bFdm0XZVelk7LJ/tdg9UuDUf724/stESKfgu0yF60BSMRpohGgqllUkLnEYZJw4P2AhMfQ6tUCcs9fVeidM+4kGtiLDonnmR/kLigLm6D6nA4X+X42Stg8Yo3rfzMv3vM= 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 1662384978982720.7702810549686; Mon, 5 Sep 2022 06:36:18 -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-210-YDeY-wGGOMShHpGP_IVPsA-1; Mon, 05 Sep 2022 09:34:37 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id A55ED85828B; Mon, 5 Sep 2022 13:34:34 +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 5A6C42166B2E; Mon, 5 Sep 2022 13:34:34 +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 30FDA194B97A; Mon, 5 Sep 2022 13:34:34 +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 34AD81946A47 for ; Mon, 5 Sep 2022 13:34:33 +0000 (UTC) Received: by smtp.corp.redhat.com (Postfix) id 2882A40D2830; Mon, 5 Sep 2022 13:34:33 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.30]) by smtp.corp.redhat.com (Postfix) with ESMTP id 380F940D282E for ; Mon, 5 Sep 2022 13:34:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1662384978; 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=6w1w+lbpiOxMxy7ouT8VVL3UYzh82jnt5AGOfabXEZY=; b=cgmZQdJVgiAGQXct5dgIfcsEXqCtBJGyK7waSkdFOYjk4HYBz063O2e+va9iB4EBNMjcw+ ehmsL8J7g/aYKpBwcZ6umh4cTzazPSyrlTzUc6WpwfJhFVt8mM/BPba3EpFfr4wd598VLZ BXLcLEJ91tLcdbrA1DxAQ9UOk1GJ6BI= X-MC-Unique: YDeY-wGGOMShHpGP_IVPsA-1 X-Original-To: libvir-list@listman.corp.redhat.com From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 7/7] util: virFileIsSharedFSType: Simplify shared fs type declarations Date: Mon, 5 Sep 2022 15:34:21 +0200 Message-Id: <3f8316da96d202123918f628c8e5d6c7393a6d41.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.78 on 10.11.54.6 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: 1662384980628100001 Content-Type: text/plain; charset="utf-8" Use approach similar to virFileIsSharedFsFUSE to declaratively handle the filesystem magic numbers mapping to libvirt's fstypes. Signed-off-by: Peter Krempa --- src/util/virfile.c | 48 +++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 28 deletions(-) diff --git a/src/util/virfile.c b/src/util/virfile.c index 6302364797..ec40c04b1f 100644 --- a/src/util/virfile.c +++ b/src/util/virfile.c @@ -3324,6 +3324,7 @@ virFileRemoveLastComponent(char *path) struct virFileSharedFsData { const char *mnttype; + unsigned int magic; unsigned int fstype; }; @@ -3394,6 +3395,19 @@ virFileIsSharedFsFUSE(const char *path, } +static const struct virFileSharedFsData virFileSharedFs[] =3D { + { .fstype =3D VIR_FILE_SHFS_NFS, .magic =3D NFS_SUPER_MAGIC }, + { .fstype =3D VIR_FILE_SHFS_GFS2, .magic =3D GFS2_MAGIC }, + { .fstype =3D VIR_FILE_SHFS_OCFS, .magic =3D OCFS2_SUPER_MAGIC }, + { .fstype =3D VIR_FILE_SHFS_AFS, .magic =3D AFS_FS_MAGIC }, + { .fstype =3D VIR_FILE_SHFS_SMB, .magic =3D SMB_SUPER_MAGIC }, + { .fstype =3D VIR_FILE_SHFS_CIFS, .magic =3D CIFS_SUPER_MAGIC }, + { .fstype =3D VIR_FILE_SHFS_CEPH, .magic =3D CEPH_SUPER_MAGIC }, + { .fstype =3D VIR_FILE_SHFS_GPFS, .magic =3D GPFS_SUPER_MAGIC }, + { .fstype =3D VIR_FILE_SHFS_ACFS, .magic =3D VIR_ACFS_MAGIC }, +}; + + int virFileIsSharedFSType(const char *path, unsigned int fstypes) @@ -3403,6 +3417,7 @@ virFileIsSharedFSType(const char *path, struct statfs sb; int statfs_ret; long long f_type =3D 0; + size_t i; dirpath =3D g_strdup(path); @@ -3448,34 +3463,11 @@ virFileIsSharedFSType(const char *path, VIR_DEBUG("Check if path %s with FS magic %lld is shared", path, f_type); - if ((fstypes & VIR_FILE_SHFS_NFS) && - (f_type =3D=3D NFS_SUPER_MAGIC)) - return 1; - - if ((fstypes & VIR_FILE_SHFS_GFS2) && - (f_type =3D=3D GFS2_MAGIC)) - return 1; - if ((fstypes & VIR_FILE_SHFS_OCFS) && - (f_type =3D=3D OCFS2_SUPER_MAGIC)) - return 1; - if ((fstypes & VIR_FILE_SHFS_AFS) && - (f_type =3D=3D AFS_FS_MAGIC)) - return 1; - if ((fstypes & VIR_FILE_SHFS_SMB) && - (f_type =3D=3D SMB_SUPER_MAGIC)) - return 1; - if ((fstypes & VIR_FILE_SHFS_CIFS) && - (f_type =3D=3D CIFS_SUPER_MAGIC)) - return 1; - if ((fstypes & VIR_FILE_SHFS_CEPH) && - (f_type =3D=3D CEPH_SUPER_MAGIC)) - return 1; - if ((fstypes & VIR_FILE_SHFS_GPFS) && - (f_type =3D=3D GPFS_SUPER_MAGIC)) - return 1; - if ((fstypes & VIR_FILE_SHFS_ACFS) && - (f_type =3D=3D VIR_ACFS_MAGIC)) - return 1; + for (i =3D 0; i < G_N_ELEMENTS(virFileSharedFs); i++) { + if (f_type =3D=3D virFileSharedFs[i].magic && + (fstypes & virFileSharedFs[i].fstype) > 0) + return 1; + } return 0; } --=20 2.37.1