[libvirt] [PATCH v2 4/6] storage: Add NFS storage pool mount options to command line

John Ferlan posted 6 patches 5 years, 10 months ago
There is a newer version of this series
[libvirt] [PATCH v2 4/6] storage: Add NFS storage pool mount options to command line
Posted by John Ferlan 5 years, 10 months ago
If the NetFS Storage Pool Namespace XML data exists, format the
mount options on the MOUNT command line.

When the pool is started, the options will be generated on the
command line along with the exportfs options already defined.
To view the options of the running pool, use either 'nfsstat -m'
or 'grep $POOLNAME /proc/mounts' for the added Flags/options.

Signed-off-by: John Ferlan <jferlan@redhat.com>
---
 src/storage/storage_util.c                    | 20 +++++++++++++++++++
 .../pool-netfs-mountopts.argv                 |  1 +
 tests/storagepoolxml2argvtest.c               |  4 ++++
 3 files changed, 25 insertions(+)
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-mountopts.argv

diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
index ff0a0239e6..debf5aa133 100644
--- a/src/storage/storage_util.c
+++ b/src/storage/storage_util.c
@@ -4352,6 +4352,26 @@ virStorageBackendFileSystemMountCmd(const char *cmdstr,
         virStorageBackendFileSystemMountCIFSArgs(cmd, src, def);
     else
         virStorageBackendFileSystemMountDefaultArgs(cmd, src, def);
+
+    if (def->type == VIR_STORAGE_POOL_NETFS && def->source.namespaceData) {
+        size_t i;
+        virStoragePoolNetFSMountOptionsDefPtr opts = def->source.namespaceData;
+        virBuffer buf = VIR_BUFFER_INITIALIZER;
+        VIR_AUTOFREE(char *) mountOpts = NULL;
+
+        for (i = 0; i < opts->noptions; i++)
+            virBufferAsprintf(&buf, "%s,", opts->options[i]);
+
+        virBufferTrim(&buf, ",", -1);
+
+        if (virBufferCheckError(&buf) < 0)
+            return NULL;
+
+        mountOpts = virBufferContentAndReset(&buf);
+
+        virCommandAddArgList(cmd, "-o", mountOpts, NULL);
+    }
+
     return cmd;
 }
 
diff --git a/tests/storagepoolxml2argvdata/pool-netfs-mountopts.argv b/tests/storagepoolxml2argvdata/pool-netfs-mountopts.argv
new file mode 100644
index 0000000000..16d35bc175
--- /dev/null
+++ b/tests/storagepoolxml2argvdata/pool-netfs-mountopts.argv
@@ -0,0 +1 @@
+mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nodev,nosuid
diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c
index 2f2d40e027..338fe6d5f5 100644
--- a/tests/storagepoolxml2argvtest.c
+++ b/tests/storagepoolxml2argvtest.c
@@ -144,6 +144,9 @@ mymain(void)
 #define DO_TEST_FAIL(pool, ...) \
     DO_TEST_FULL(true, pool)
 
+    if (storageRegisterAll() < 0)
+       return EXIT_FAILURE;
+
     DO_TEST_FAIL("pool-dir");
     DO_TEST_FAIL("pool-dir-naming");
     DO_TEST("pool-fs");
@@ -159,6 +162,7 @@ mymain(void)
     DO_TEST("pool-netfs-auto");
     DO_TEST("pool-netfs-gluster");
     DO_TEST("pool-netfs-cifs");
+    DO_TEST("pool-netfs-mountopts");
     DO_TEST_FAIL("pool-scsi");
     DO_TEST_FAIL("pool-scsi-type-scsi-host");
     DO_TEST_FAIL("pool-scsi-type-fc-host");
-- 
2.20.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list