99cbc7
From acf8c5619852146eed84123c7f432db925781511 Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <acf8c5619852146eed84123c7f432db925781511@dist-git>
99cbc7
From: John Ferlan <jferlan@redhat.com>
99cbc7
Date: Wed, 3 Apr 2019 10:58:19 -0400
99cbc7
Subject: [PATCH] conf: Add optional NFS Source Pool <protocol ver='n'/> option
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
Add an optional way to define which NFS Server version will be
99cbc7
used to content the target NFS server.
99cbc7
99cbc7
Signed-off-by: John Ferlan <jferlan@redhat.com>
99cbc7
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
99cbc7
(cherry picked from commit 801f8cfb37f12007878df53332fdc03245a9d40d)
99cbc7
Message-Id: <20190403145819.4656-1-jferlan@redhat.com>
99cbc7
Reviewed-by: Ján Tomko <jtomko@redhat.com>
99cbc7
---
99cbc7
 docs/formatstorage.html.in                    | 16 ++++++++++++++
99cbc7
 docs/schemas/storagepool.rng                  |  7 ++++++
99cbc7
 src/conf/storage_conf.c                       | 22 +++++++++++++++++++
99cbc7
 src/conf/storage_conf.h                       |  3 +++
99cbc7
 .../pool-netfs-protocol-ver.xml               | 21 ++++++++++++++++++
99cbc7
 .../pool-netfs-protocol-ver.xml               | 21 ++++++++++++++++++
99cbc7
 tests/storagepoolxml2xmltest.c                |  1 +
99cbc7
 7 files changed, 91 insertions(+)
99cbc7
 create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml
99cbc7
 create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml
99cbc7
99cbc7
diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
99cbc7
index b6bf3edbd2..b1b76a1dda 100644
99cbc7
--- a/docs/formatstorage.html.in
99cbc7
+++ b/docs/formatstorage.html.in
99cbc7
@@ -121,6 +121,16 @@
99cbc7
 </source>
99cbc7
 ...
99cbc7
 
99cbc7
+    
99cbc7
+...
99cbc7
+  <source>
99cbc7
+    <host name='localhost'/>
99cbc7
+    <dir path='/var/lib/libvirt/images'/>
99cbc7
+    <format type='nfs'/>
99cbc7
+    <protocol ver='3'/>
99cbc7
+  </source>
99cbc7
+...
99cbc7
+
99cbc7
     
99cbc7
       
device
99cbc7
       
Provides the source for pools backed by physical devices
99cbc7
@@ -386,6 +396,12 @@
99cbc7
         LVM metadata type. All drivers are required to have a default
99cbc7
         value for this, so it is optional. Since 0.4.1
99cbc7
 
99cbc7
+      
protocol
99cbc7
+      
For a netfs Storage Pool provide a mechanism to
99cbc7
+        define which NFS protocol version number will be used to contact
99cbc7
+        the server's NFS service. The attribute ver accepts
99cbc7
+        an unsigned integer as the version number to use.
99cbc7
+        Since 5.1.0
99cbc7
       
vendor
99cbc7
       
Provides optional information about the vendor of the
99cbc7
         storage device. This contains a single
99cbc7
diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
99cbc7
index 52b2044bef..0cb8beb926 100644
99cbc7
--- a/docs/schemas/storagepool.rng
99cbc7
+++ b/docs/schemas/storagepool.rng
99cbc7
@@ -520,6 +520,13 @@
99cbc7
             <ref name='sourceinfohost'/>
99cbc7
             <ref name='sourceinfodir'/>
99cbc7
             <ref name='sourcefmtnetfs'/>
99cbc7
+            <optional>
99cbc7
+              <element name='protocol'>
99cbc7
+                <attribute name='ver'>
99cbc7
+                  <ref name='unsignedInt'/>
99cbc7
+                </attribute>
99cbc7
+              </element>
99cbc7
+            </optional>
99cbc7
             <optional>
99cbc7
               <ref name='sourceinfovendor'/>
99cbc7
             </optional>
99cbc7
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
99cbc7
index 5036ab9ef8..5a124a0a2f 100644
99cbc7
--- a/src/conf/storage_conf.c
99cbc7
+++ b/src/conf/storage_conf.c
99cbc7
@@ -415,6 +415,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
99cbc7
     virStorageAuthDefPtr authdef = NULL;
99cbc7
     char *name = NULL;
99cbc7
     char *port = NULL;
99cbc7
+    char *ver = NULL;
99cbc7
     int n;
99cbc7
 
99cbc7
     relnode = ctxt->node;
99cbc7
@@ -540,6 +541,24 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
99cbc7
         authdef = NULL;
99cbc7
     }
99cbc7
 
99cbc7
+    /* Option protocol version string (NFSvN) */
99cbc7
+    if ((ver = virXPathString("string(./protocol/@ver)", ctxt))) {
99cbc7
+        if ((source->format != VIR_STORAGE_POOL_NETFS_NFS) &&
99cbc7
+            (source->format != VIR_STORAGE_POOL_NETFS_AUTO)) {
99cbc7
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
99cbc7
+                           _("storage pool protocol ver unsupported for "
99cbc7
+                             "pool type '%s'"),
99cbc7
+                           virStoragePoolFormatFileSystemNetTypeToString(source->format));
99cbc7
+            goto cleanup;
99cbc7
+        }
99cbc7
+        if (virStrToLong_uip(ver, NULL, 0, &source->protocolVer) < 0) {
99cbc7
+            virReportError(VIR_ERR_XML_ERROR,
99cbc7
+                           _("storage pool protocol ver '%s' is malformaed"),
99cbc7
+                           ver);
99cbc7
+            goto cleanup;
99cbc7
+        }
99cbc7
+    }
99cbc7
+
99cbc7
     source->vendor = virXPathString("string(./vendor/@name)", ctxt);
99cbc7
     source->product = virXPathString("string(./product/@name)", ctxt);
99cbc7
 
99cbc7
@@ -956,6 +975,9 @@ virStoragePoolSourceFormat(virBufferPtr buf,
99cbc7
     if (src->auth)
99cbc7
         virStorageAuthDefFormat(buf, src->auth);
99cbc7
 
99cbc7
+    if (src->protocolVer)
99cbc7
+        virBufferAsprintf(buf, "<protocol ver='%u'/>\n", src->protocolVer);
99cbc7
+
99cbc7
     virBufferEscapeString(buf, "<vendor name='%s'/>\n", src->vendor);
99cbc7
     virBufferEscapeString(buf, "<product name='%s'/>\n", src->product);
99cbc7
 
99cbc7
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
99cbc7
index 15dfd8becf..3b637e2258 100644
99cbc7
--- a/src/conf/storage_conf.h
99cbc7
+++ b/src/conf/storage_conf.h
99cbc7
@@ -203,6 +203,9 @@ struct _virStoragePoolSource {
99cbc7
      * or lvm version, etc.
99cbc7
      */
99cbc7
     int format;
99cbc7
+
99cbc7
+    /* Protocol version value for netfs */
99cbc7
+    unsigned int protocolVer;
99cbc7
 };
99cbc7
 
99cbc7
 typedef struct _virStoragePoolTarget virStoragePoolTarget;
99cbc7
diff --git a/tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml b/tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml
99cbc7
new file mode 100644
99cbc7
index 0000000000..40f3f94e41
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml
99cbc7
@@ -0,0 +1,21 @@
99cbc7
+<pool type='netfs'>
99cbc7
+  <name>nfsimages</name>
99cbc7
+  <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
99cbc7
+  <capacity>0</capacity>
99cbc7
+  <allocation>0</allocation>
99cbc7
+  <available>0</available>
99cbc7
+  <source>
99cbc7
+    <host name='localhost'/>
99cbc7
+    <dir path='/var/lib/libvirt/images'/>
99cbc7
+    <format type='nfs'/>
99cbc7
+    <protocol ver='3'/>
99cbc7
+  </source>
99cbc7
+  <target>
99cbc7
+    <path>/mnt</path>
99cbc7
+    <permissions>
99cbc7
+      <mode>0700</mode>
99cbc7
+      <owner>0</owner>
99cbc7
+      <group>0</group>
99cbc7
+    </permissions>
99cbc7
+  </target>
99cbc7
+</pool>
99cbc7
diff --git a/tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml b/tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml
99cbc7
new file mode 100644
99cbc7
index 0000000000..5fcad1305b
99cbc7
--- /dev/null
99cbc7
+++ b/tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml
99cbc7
@@ -0,0 +1,21 @@
99cbc7
+<pool type='netfs'>
99cbc7
+  <name>nfsimages</name>
99cbc7
+  <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
99cbc7
+  <capacity unit='bytes'>0</capacity>
99cbc7
+  <allocation unit='bytes'>0</allocation>
99cbc7
+  <available unit='bytes'>0</available>
99cbc7
+  <source>
99cbc7
+    <host name='localhost'/>
99cbc7
+    <dir path='/var/lib/libvirt/images'/>
99cbc7
+    <format type='nfs'/>
99cbc7
+    <protocol ver='3'/>
99cbc7
+  </source>
99cbc7
+  <target>
99cbc7
+    <path>/mnt</path>
99cbc7
+    <permissions>
99cbc7
+      <mode>0700</mode>
99cbc7
+      <owner>0</owner>
99cbc7
+      <group>0</group>
99cbc7
+    </permissions>
99cbc7
+  </target>
99cbc7
+</pool>
99cbc7
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
99cbc7
index 29c0e42479..cf41b4d065 100644
99cbc7
--- a/tests/storagepoolxml2xmltest.c
99cbc7
+++ b/tests/storagepoolxml2xmltest.c
99cbc7
@@ -86,6 +86,7 @@ mymain(void)
99cbc7
     DO_TEST("pool-iscsi-auth");
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
     DO_TEST("pool-scsi");
99cbc7
-- 
99cbc7
2.21.0
99cbc7