[libvirt] [PATCH v5 8/9] storage: Add storage pool namespace options to fs and netfs command lines

John Ferlan jferlan at redhat.com
Tue Jan 29 18:22:07 UTC 2019


If the Storage Pool Namespace XML data exists, format the mount
options on the MOUNT command line and issue a VIR_WARN to indicate
that the storage pool was tainted by custom mount_opts.

When the pool is started, the options will be generated on the
command line along with the options already defined.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/storage/storage_util.c                    | 22 +++++++++++++++----
 .../pool-netfs-ns-mountopts-freebsd.argv      |  2 ++
 .../pool-netfs-ns-mountopts-linux.argv        |  2 ++
 .../pool-netfs-ns-mountopts.argv              |  1 +
 tests/storagepoolxml2argvtest.c               |  6 +++++
 5 files changed, 29 insertions(+), 4 deletions(-)
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index 4596cd4518..37b3d58667 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -4284,6 +4284,7 @@ virStorageBackendFileSystemGetPoolSource(virStoragePoolObjPtr pool)
 
 static void
 virStorageBackendFileSystemMountAddOptions(virCommandPtr cmd,
+                                           virStoragePoolDefPtr def,
                                            const char *providedOpts)
 {
     VIR_AUTOFREE(char *) mountOpts = NULL;
@@ -4295,6 +4296,19 @@ virStorageBackendFileSystemMountAddOptions(virCommandPtr cmd,
     if (providedOpts)
         virBufferAsprintf(&buf, "%s,", providedOpts);
 
+    if (def->namespaceData) {
+        size_t i;
+        virStoragePoolFSMountOptionsDefPtr opts = def->namespaceData;
+        char uuidstr[VIR_UUID_STRING_BUFLEN];
+
+        for (i = 0; i < opts->noptions; i++)
+            virBufferAsprintf(&buf, "%s,", opts->options[i]);
+
+        virUUIDFormat(def->uuid, uuidstr);
+        VIR_WARN("Storage Pool name='%s' uuid='%s' is tainted by custom "
+                 "mount_opts from XML", def->name, uuidstr);
+    }
+
     virBufferTrim(&buf, ",", -1);
     mountOpts = virBufferContentAndReset(&buf);
 
@@ -4310,7 +4324,7 @@ virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd,
                                         const char *nfsVers)
 {
     virCommandAddArgList(cmd, src, def->target.path, NULL);
-    virStorageBackendFileSystemMountAddOptions(cmd, nfsVers);
+    virStorageBackendFileSystemMountAddOptions(cmd, def, nfsVers);
 }
 
 
@@ -4323,7 +4337,7 @@ virStorageBackendFileSystemMountGlusterArgs(virCommandPtr cmd,
 
     fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format);
     virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL);
-    virStorageBackendFileSystemMountAddOptions(cmd, "direct-io-mode=1");
+    virStorageBackendFileSystemMountAddOptions(cmd, def, "direct-io-mode=1");
 }
 
 
@@ -4336,7 +4350,7 @@ virStorageBackendFileSystemMountCIFSArgs(virCommandPtr cmd,
 
     fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format);
     virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL);
-    virStorageBackendFileSystemMountAddOptions(cmd, "guest");
+    virStorageBackendFileSystemMountAddOptions(cmd, def, "guest");
 }
 
 
@@ -4353,7 +4367,7 @@ virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd,
     else
         fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format);
     virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL);
-    virStorageBackendFileSystemMountAddOptions(cmd, nfsVers);
+    virStorageBackendFileSystemMountAddOptions(cmd, def, nfsVers);
 }
 
 
diff --git a/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv
new file mode 100644
index 0000000000..ac5c0acd00
--- /dev/null
+++ b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-freebsd.argv
@@ -0,0 +1,2 @@
+mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nosuid,noexec,nfsvers=3,\
+sync,lazytime
diff --git a/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv
new file mode 100644
index 0000000000..8e10379c04
--- /dev/null
+++ b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts-linux.argv
@@ -0,0 +1,2 @@
+mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nodev,nosuid,noexec,\
+nfsvers=3,sync,lazytime
diff --git a/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv
new file mode 100644
index 0000000000..a63d6da456
--- /dev/null
+++ b/tests/storagepoolxml2argvdata/pool-netfs-ns-mountopts.argv
@@ -0,0 +1 @@
+mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3,sync,lazytime
diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c
index 88059cbdfc..786fb26402 100644
--- a/tests/storagepoolxml2argvtest.c
+++ b/tests/storagepoolxml2argvtest.c
@@ -162,6 +162,9 @@ mymain(void)
 #define DO_TEST_FREEBSD(pool, ...) \
     DO_TEST_FULL(false, pool, false, true)
 
+    if (storageRegisterAll() < 0)
+       return EXIT_FAILURE;
+
     DO_TEST_FAIL("pool-dir");
     DO_TEST_FAIL("pool-dir-naming");
     DO_TEST("pool-logical");
@@ -177,6 +180,7 @@ mymain(void)
     DO_TEST_LINUX("pool-netfs");
     DO_TEST_LINUX("pool-netfs-auto");
     DO_TEST_LINUX("pool-netfs-protocol-ver");
+    DO_TEST_LINUX("pool-netfs-ns-mountopts");
     DO_TEST_LINUX("pool-netfs-gluster");
     DO_TEST_LINUX("pool-netfs-cifs");
 #elif defined(__FreeBSD__)
@@ -184,6 +188,7 @@ mymain(void)
     DO_TEST_FREEBSD("pool-netfs");
     DO_TEST_FREEBSD("pool-netfs-auto");
     DO_TEST_FREEBSD("pool-netfs-protocol-ver");
+    DO_TEST_FREEBSD("pool-netfs-ns-mountopts");
     DO_TEST_FREEBSD("pool-netfs-gluster");
     DO_TEST_FREEBSD("pool-netfs-cifs");
 #else
@@ -191,6 +196,7 @@ mymain(void)
     DO_TEST("pool-netfs");
     DO_TEST("pool-netfs-auto");
     DO_TEST("pool-netfs-protocol-ver");
+    DO_TEST("pool-netfs-ns-mountopts");
     DO_TEST("pool-netfs-gluster");
     DO_TEST("pool-netfs-cifs");
 #endif
-- 
2.20.1




More information about the libvir-list mailing list