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