From nobody Sun Feb 8 16:31:09 2026 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 1548786141402347.71045488461425; Tue, 29 Jan 2019 10:22:21 -0800 (PST) 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 DE562C0C6C21; Tue, 29 Jan 2019 18:22:15 +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 7203B2C6C0; Tue, 29 Jan 2019 18:22:14 +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 8D147180339A; Tue, 29 Jan 2019 18:22:13 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x0TIMC6T001792 for ; Tue, 29 Jan 2019 13:22:12 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1F3342B592; Tue, 29 Jan 2019 18:22:12 +0000 (UTC) Received: from unknown0050b6a41c42.attlocal.net.com (ovpn-116-45.phx2.redhat.com [10.3.116.45]) by smtp.corp.redhat.com (Postfix) with ESMTP id BCF7616E31 for ; Tue, 29 Jan 2019 18:22:11 +0000 (UTC) From: John Ferlan To: libvir-list@redhat.com Date: Tue, 29 Jan 2019 13:22:00 -0500 Message-Id: <20190129182208.23788-2-jferlan@redhat.com> In-Reply-To: <20190129182208.23788-1-jferlan@redhat.com> References: <20190129182208.23788-1-jferlan@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v5 1/9] storage: Add default mount options for fs/netfs storage pools 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: , 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.32]); Tue, 29 Jan 2019 18:22:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" https://bugzilla.redhat.com/show_bug.cgi?id=3D1584663 Modify the command generation to add some default options to the fs/netfs storage pools based on the OS type. For Linux, it'll be the "nodev, nosuid, noexec". For FreeBSD, it'll be "nosuid, noexec". For others, just leave the options alone. Modify the storagepoolxml2argvtest to handle the fact that the same input XML could generate different output XML based on whether Linux, FreeBSD, or other was being built. Signed-off-by: John Ferlan Reviewed-by: Daniel P. Berrang=C3=A9 --- src/storage/storage_util.c | 36 ++++++++++++-- .../pool-fs-freebsd.argv | 1 + .../pool-fs-linux.argv | 1 + .../pool-netfs-auto-freebsd.argv | 1 + .../pool-netfs-auto-linux.argv | 1 + .../pool-netfs-cifs-freebsd.argv | 1 + .../pool-netfs-cifs-linux.argv | 1 + .../pool-netfs-freebsd.argv | 1 + .../pool-netfs-gluster-freebsd.argv | 2 + .../pool-netfs-gluster-linux.argv | 2 + .../pool-netfs-linux.argv | 1 + tests/storagepoolxml2argvtest.c | 48 +++++++++++++++---- 12 files changed, 84 insertions(+), 12 deletions(-) create mode 100644 tests/storagepoolxml2argvdata/pool-fs-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-fs-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.a= rgv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-cifs-freebsd.a= rgv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-cifs-linux.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-gluster-freebs= d.argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-gluster-linux.= argv create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-linux.argv diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c index a84ee5b600..d63237ce8f 100644 --- a/src/storage/storage_util.c +++ b/src/storage/storage_util.c @@ -34,6 +34,11 @@ # ifndef FS_NOCOW_FL # define FS_NOCOW_FL 0x00800000 /* Do not cow file */ # endif +# define default_mount_opts "nodev,nosuid,noexec" +#elif defined(__FreeBSD__) +# define default_mount_opts "nosuid,noexec" +#else +# define default_mount_opts "" #endif =20 #if WITH_BLKID @@ -4261,12 +4266,34 @@ virStorageBackendFileSystemGetPoolSource(virStorage= PoolObjPtr pool) } =20 =20 +static void +virStorageBackendFileSystemMountAddOptions(virCommandPtr cmd, + const char *providedOpts) +{ + VIR_AUTOFREE(char *) mountOpts =3D NULL; + virBuffer buf =3D VIR_BUFFER_INITIALIZER; + + if (*default_mount_opts !=3D '\0') + virBufferAsprintf(&buf, "%s,", default_mount_opts); + + if (providedOpts) + virBufferAsprintf(&buf, "%s,", providedOpts); + + virBufferTrim(&buf, ",", -1); + mountOpts =3D virBufferContentAndReset(&buf); + + if (mountOpts) + virCommandAddArgList(cmd, "-o", mountOpts, NULL); +} + + static void virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd, const char *src, virStoragePoolDefPtr def) { virCommandAddArgList(cmd, src, def->target.path, NULL); + virStorageBackendFileSystemMountAddOptions(cmd, NULL); } =20 =20 @@ -4278,8 +4305,8 @@ virStorageBackendFileSystemMountGlusterArgs(virComman= dPtr cmd, const char *fmt; =20 fmt =3D virStoragePoolFormatFileSystemNetTypeToString(def->source.form= at); - virCommandAddArgList(cmd, "-t", fmt, src, "-o", "direct-io-mode=3D1", - def->target.path, NULL); + virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); + virStorageBackendFileSystemMountAddOptions(cmd, "direct-io-mode=3D1"); } =20 =20 @@ -4291,8 +4318,8 @@ virStorageBackendFileSystemMountCIFSArgs(virCommandPt= r cmd, const char *fmt; =20 fmt =3D virStoragePoolFormatFileSystemNetTypeToString(def->source.form= at); - virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, - "-o", "guest", NULL); + virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); + virStorageBackendFileSystemMountAddOptions(cmd, "guest"); } =20 =20 @@ -4308,6 +4335,7 @@ virStorageBackendFileSystemMountDefaultArgs(virComman= dPtr cmd, else fmt =3D virStoragePoolFormatFileSystemNetTypeToString(def->source.= format); virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); + virStorageBackendFileSystemMountAddOptions(cmd, NULL); } =20 =20 diff --git a/tests/storagepoolxml2argvdata/pool-fs-freebsd.argv b/tests/sto= ragepoolxml2argvdata/pool-fs-freebsd.argv new file mode 100644 index 0000000000..a35d73e254 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-fs-freebsd.argv @@ -0,0 +1 @@ +mount -t ext3 /dev/sda6 /mnt -o nosuid,noexec diff --git a/tests/storagepoolxml2argvdata/pool-fs-linux.argv b/tests/stora= gepoolxml2argvdata/pool-fs-linux.argv new file mode 100644 index 0000000000..19543f442d --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-fs-linux.argv @@ -0,0 +1 @@ +mount -t ext3 /dev/sda6 /mnt -o nodev,nosuid,noexec diff --git a/tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv b/t= ests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv new file mode 100644 index 0000000000..39e5c97aed --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-auto-freebsd.argv @@ -0,0 +1 @@ +mount localhost:/var/lib/libvirt/images /mnt -o nosuid,noexec diff --git a/tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv b/tes= ts/storagepoolxml2argvdata/pool-netfs-auto-linux.argv new file mode 100644 index 0000000000..1f82d3d29c --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-auto-linux.argv @@ -0,0 +1 @@ +mount localhost:/var/lib/libvirt/images /mnt -o nodev,nosuid,noexec diff --git a/tests/storagepoolxml2argvdata/pool-netfs-cifs-freebsd.argv b/t= ests/storagepoolxml2argvdata/pool-netfs-cifs-freebsd.argv new file mode 100644 index 0000000000..d72749a032 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-cifs-freebsd.argv @@ -0,0 +1 @@ +mount -t cifs //example.com/samba_share /mnt/cifs -o nosuid,noexec,guest diff --git a/tests/storagepoolxml2argvdata/pool-netfs-cifs-linux.argv b/tes= ts/storagepoolxml2argvdata/pool-netfs-cifs-linux.argv new file mode 100644 index 0000000000..85aa9cf23f --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-cifs-linux.argv @@ -0,0 +1 @@ +mount -t cifs //example.com/samba_share /mnt/cifs -o nodev,nosuid,noexec,g= uest diff --git a/tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv b/tests/= storagepoolxml2argvdata/pool-netfs-freebsd.argv new file mode 100644 index 0000000000..05c1951f32 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-freebsd.argv @@ -0,0 +1 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nosuid,noexec diff --git a/tests/storagepoolxml2argvdata/pool-netfs-gluster-freebsd.argv = b/tests/storagepoolxml2argvdata/pool-netfs-gluster-freebsd.argv new file mode 100644 index 0000000000..700107d78e --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-gluster-freebsd.argv @@ -0,0 +1,2 @@ +mount -t glusterfs example.com:/volume /mnt/gluster -o nosuid,noexec,\ +direct-io-mode=3D1 diff --git a/tests/storagepoolxml2argvdata/pool-netfs-gluster-linux.argv b/= tests/storagepoolxml2argvdata/pool-netfs-gluster-linux.argv new file mode 100644 index 0000000000..9535c8a1b9 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-gluster-linux.argv @@ -0,0 +1,2 @@ +mount -t glusterfs example.com:/volume /mnt/gluster -o nodev,nosuid,noexec= ,\ +direct-io-mode=3D1 diff --git a/tests/storagepoolxml2argvdata/pool-netfs-linux.argv b/tests/st= oragepoolxml2argvdata/pool-netfs-linux.argv new file mode 100644 index 0000000000..22fafd7b32 --- /dev/null +++ b/tests/storagepoolxml2argvdata/pool-netfs-linux.argv @@ -0,0 +1 @@ +mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nodev,nosuid,noexec diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtes= t.c index 2f2d40e027..0331d3497b 100644 --- a/tests/storagepoolxml2argvtest.c +++ b/tests/storagepoolxml2argvtest.c @@ -96,6 +96,8 @@ testCompareXMLToArgvFiles(bool shouldFail, struct testInfo { bool shouldFail; const char *pool; + bool linuxOut; + bool freebsdOut; }; =20 static int @@ -110,9 +112,19 @@ testCompareXMLToArgvHelper(const void *data) abs_srcdir, info->pool) < 0) goto cleanup; =20 - if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s.argv", - abs_srcdir, info->pool) < 0 && !info->shouldFail) - goto cleanup; + if (info->linuxOut) { + if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s-linux.arg= v", + abs_srcdir, info->pool) < 0 && !info->shouldFail) + goto cleanup; + } else if (info->freebsdOut) { + if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s-freebsd.a= rgv", + abs_srcdir, info->pool) < 0 && !info->shouldFail) + goto cleanup; + } else { + if (virAsprintf(&cmdline, "%s/storagepoolxml2argvdata/%s.argv", + abs_srcdir, info->pool) < 0 && !info->shouldFail) + goto cleanup; + } =20 result =3D testCompareXMLToArgvFiles(info->shouldFail, poolxml, cmdlin= e); =20 @@ -129,9 +141,9 @@ mymain(void) { int ret =3D 0; =20 -#define DO_TEST_FULL(shouldFail, pool) \ +#define DO_TEST_FULL(shouldFail, pool, linuxOut, freebsdOut) \ do { \ - struct testInfo info =3D { shouldFail, pool }; \ + struct testInfo info =3D { shouldFail, pool, linuxOut, freebsdOut = }; \ if (virTestRun("Storage Pool XML-2-argv " pool, \ testCompareXMLToArgvHelper, &info) < 0) \ ret =3D -1; \ @@ -139,14 +151,19 @@ mymain(void) while (0); =20 #define DO_TEST(pool, ...) \ - DO_TEST_FULL(false, pool) + DO_TEST_FULL(false, pool, false, false) =20 #define DO_TEST_FAIL(pool, ...) \ - DO_TEST_FULL(true, pool) + DO_TEST_FULL(true, pool, false, false) + +#define DO_TEST_LINUX(pool, ...) \ + DO_TEST_FULL(false, pool, true, false) + +#define DO_TEST_FREEBSD(pool, ...) \ + DO_TEST_FULL(false, pool, false, true) =20 DO_TEST_FAIL("pool-dir"); DO_TEST_FAIL("pool-dir-naming"); - DO_TEST("pool-fs"); DO_TEST("pool-logical"); DO_TEST("pool-logical-nopath"); DO_TEST("pool-logical-create"); @@ -155,10 +172,25 @@ mymain(void) DO_TEST_FAIL("pool-disk-device-nopartsep"); DO_TEST_FAIL("pool-iscsi"); DO_TEST_FAIL("pool-iscsi-auth"); +#ifdef __linux__ + DO_TEST_LINUX("pool-fs"); + DO_TEST_LINUX("pool-netfs"); + DO_TEST_LINUX("pool-netfs-auto"); + DO_TEST_LINUX("pool-netfs-gluster"); + DO_TEST_LINUX("pool-netfs-cifs"); +#elif defined(__FreeBSD__) + DO_TEST_FREEBSD("pool-fs"); + DO_TEST_FREEBSD("pool-netfs"); + DO_TEST_FREEBSD("pool-netfs-auto"); + DO_TEST_FREEBSD("pool-netfs-gluster"); + DO_TEST_FREEBSD("pool-netfs-cifs"); +#else + DO_TEST("pool-fs"); DO_TEST("pool-netfs"); DO_TEST("pool-netfs-auto"); DO_TEST("pool-netfs-gluster"); DO_TEST("pool-netfs-cifs"); +#endif DO_TEST_FAIL("pool-scsi"); DO_TEST_FAIL("pool-scsi-type-scsi-host"); DO_TEST_FAIL("pool-scsi-type-fc-host"); --=20 2.20.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list