render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
99cbc7
From 8e9adc7c2b4e7b6e09ae45b8b31bac0696f99ee1 Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <8e9adc7c2b4e7b6e09ae45b8b31bac0696f99ee1@dist-git>
99cbc7
From: John Ferlan <jferlan@redhat.com>
99cbc7
Date: Wed, 3 Apr 2019 09:57:29 -0400
99cbc7
Subject: [PATCH] storage: Add the nfsvers to the command line
99cbc7
MIME-Version: 1.0
99cbc7
Content-Type: text/plain; charset=UTF-8
99cbc7
Content-Transfer-Encoding: 8bit
99cbc7
99cbc7
https://bugzilla.redhat.com/show_bug.cgi?id=1584663
99cbc7
99cbc7
If protocolVer present, add the -o nfsvers=# to the command
99cbc7
line for the NFS Storage Pool
99cbc7
99cbc7
Signed-off-by: John Ferlan <jferlan@redhat.com>
99cbc7
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
99cbc7
(cherry picked from commit 3d3647e14f680015495f0f4650df8a2c1e230ec8)
99cbc7
99cbc7
Resolve a build issue since VIR_AUTOFREE is not present downstream.
99cbc7
99cbc7
Signed-off-by: John Ferlan <jferlan@redhat.com>
99cbc7
Message-Id: <20190403135730.2551-2-jferlan@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
---
99cbc7
 src/storage/storage_util.c                    | 21 +++++++++++++------
99cbc7
 .../pool-netfs-protocol-ver-freebsd.argv      |  1 +
99cbc7
 .../pool-netfs-protocol-ver-linux.argv        |  2 ++
99cbc7
 .../pool-netfs-protocol-ver.argv              |  1 +
99cbc7
 tests/storagepoolxml2argvtest.c               |  3 +++
99cbc7
 5 files changed, 22 insertions(+), 6 deletions(-)
99cbc7
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv
99cbc7
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv
99cbc7
 create mode 100644 tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv
99cbc7
99cbc7
diff --git a/src/storage/storage_util.c b/src/storage/storage_util.c
99cbc7
index 48117bef62..b0bea21e88 100644
99cbc7
--- a/src/storage/storage_util.c
99cbc7
+++ b/src/storage/storage_util.c
99cbc7
@@ -4276,10 +4276,11 @@ virStorageBackendFileSystemMountAddOptions(virCommandPtr cmd,
99cbc7
 static void
99cbc7
 virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd,
99cbc7
                                         const char *src,
99cbc7
-                                        virStoragePoolDefPtr def)
99cbc7
+                                        virStoragePoolDefPtr def,
99cbc7
+                                        const char *nfsVers)
99cbc7
 {
99cbc7
     virCommandAddArgList(cmd, src, def->target.path, NULL);
99cbc7
-    virStorageBackendFileSystemMountAddOptions(cmd, NULL);
99cbc7
+    virStorageBackendFileSystemMountAddOptions(cmd, nfsVers);
99cbc7
 }
99cbc7
 
99cbc7
 
99cbc7
@@ -4312,7 +4313,8 @@ virStorageBackendFileSystemMountCIFSArgs(virCommandPtr cmd,
99cbc7
 static void
99cbc7
 virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd,
99cbc7
                                             const char *src,
99cbc7
-                                            virStoragePoolDefPtr def)
99cbc7
+                                            virStoragePoolDefPtr def,
99cbc7
+                                            const char *nfsVers)
99cbc7
 {
99cbc7
     const char *fmt;
99cbc7
 
99cbc7
@@ -4321,7 +4323,7 @@ virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd,
99cbc7
     else
99cbc7
         fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format);
99cbc7
     virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL);
99cbc7
-    virStorageBackendFileSystemMountAddOptions(cmd, NULL);
99cbc7
+    virStorageBackendFileSystemMountAddOptions(cmd, nfsVers);
99cbc7
 }
99cbc7
 
99cbc7
 
99cbc7
@@ -4339,15 +4341,22 @@ virStorageBackendFileSystemMountCmd(virStoragePoolDefPtr def,
99cbc7
     bool cifsfs = (def->type == VIR_STORAGE_POOL_NETFS &&
99cbc7
                    def->source.format == VIR_STORAGE_POOL_NETFS_CIFS);
99cbc7
     virCommandPtr cmd = NULL;
99cbc7
+    char *nfsVers = NULL;
99cbc7
+
99cbc7
+    if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer > 0 &&
99cbc7
+        virAsprintf(&nfsVers, "nfsvers=%u", def->source.protocolVer) < 0)
99cbc7
+        return NULL;
99cbc7
 
99cbc7
     cmd = virCommandNew(MOUNT);
99cbc7
     if (netauto)
99cbc7
-        virStorageBackendFileSystemMountNFSArgs(cmd, src, def);
99cbc7
+        virStorageBackendFileSystemMountNFSArgs(cmd, src, def, nfsVers);
99cbc7
     else if (glusterfs)
99cbc7
         virStorageBackendFileSystemMountGlusterArgs(cmd, src, def);
99cbc7
     else if (cifsfs)
99cbc7
         virStorageBackendFileSystemMountCIFSArgs(cmd, src, def);
99cbc7
     else
99cbc7
-        virStorageBackendFileSystemMountDefaultArgs(cmd, src, def);
99cbc7
+        virStorageBackendFileSystemMountDefaultArgs(cmd, src, def, nfsVers);
99cbc7
+
99cbc7
+    VIR_FREE(nfsVers);
99cbc7
     return cmd;
99cbc7
 }
99cbc7
diff --git a/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv
99cbc7
new file mode 100644
99cbc7
index 0000000000..59d09d2e5d
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-freebsd.argv
99cbc7
@@ -0,0 +1 @@
99cbc7
+mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nosuid,noexec,nfsvers=3
99cbc7
diff --git a/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv
99cbc7
new file mode 100644
99cbc7
index 0000000000..c819a089d2
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv
99cbc7
@@ -0,0 +1,2 @@
99cbc7
+mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nodev,nosuid,noexec,\
99cbc7
+nfsvers=3
99cbc7
diff --git a/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv
99cbc7
new file mode 100644
99cbc7
index 0000000000..f26656d5b8
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2argvdata/pool-netfs-protocol-ver.argv
99cbc7
@@ -0,0 +1 @@
99cbc7
+mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3
99cbc7
diff --git a/tests/storagepoolxml2argvtest.c b/tests/storagepoolxml2argvtest.c
99cbc7
index 0ea8b3b94c..1e48910566 100644
99cbc7
--- a/tests/storagepoolxml2argvtest.c
99cbc7
+++ b/tests/storagepoolxml2argvtest.c
99cbc7
@@ -166,18 +166,21 @@ mymain(void)
99cbc7
     DO_TEST_LINUX("pool-fs");
99cbc7
     DO_TEST_LINUX("pool-netfs");
99cbc7
     DO_TEST_LINUX("pool-netfs-auto");
99cbc7
+    DO_TEST_LINUX("pool-netfs-protocol-ver");
99cbc7
     DO_TEST_LINUX("pool-netfs-gluster");
99cbc7
     DO_TEST_LINUX("pool-netfs-cifs");
99cbc7
 #elif defined(__FreeBSD__)
99cbc7
     DO_TEST_FREEBSD("pool-fs");
99cbc7
     DO_TEST_FREEBSD("pool-netfs");
99cbc7
     DO_TEST_FREEBSD("pool-netfs-auto");
99cbc7
+    DO_TEST_FREEBSD("pool-netfs-protocol-ver");
99cbc7
     DO_TEST_FREEBSD("pool-netfs-gluster");
99cbc7
     DO_TEST_FREEBSD("pool-netfs-cifs");
99cbc7
 #else
99cbc7
     DO_TEST("pool-fs");
99cbc7
     DO_TEST("pool-netfs");
99cbc7
     DO_TEST("pool-netfs-auto");
99cbc7
+    DO_TEST("pool-netfs-protocol-ver");
99cbc7
     DO_TEST("pool-netfs-gluster");
99cbc7
     DO_TEST("pool-netfs-cifs");
99cbc7
 #endif
99cbc7
-- 
99cbc7
2.21.0
99cbc7