Add an optional way to define which NFS Server version will be
used to content the target NFS server.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
docs/formatstorage.html.in | 7 ++++++
docs/schemas/storagepool.rng | 7 ++++++
src/conf/storage_conf.c | 22 +++++++++++++++++++
src/conf/storage_conf.h | 3 +++
.../pool-netfs-protocol-ver.xml | 21 ++++++++++++++++++
.../pool-netfs-protocol-ver.xml | 21 ++++++++++++++++++
tests/storagepoolxml2xmltest.c | 1 +
7 files changed, 82 insertions(+)
create mode 100644 tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml
create mode 100644 tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml
diff --git a/docs/formatstorage.html.in b/docs/formatstorage.html.in
index 97c90f0797..58f5eb2e2e 100644
--- a/docs/formatstorage.html.in
+++ b/docs/formatstorage.html.in
@@ -127,6 +127,7 @@
<host name='localhost'/>
<dir path='/var/lib/libvirt/images'/>
<format type='nfs'/>
+ <protocol ver='3'/>
<mount_opts>
<option name='nodev'/>
<option name='nosuid'/>
@@ -399,6 +400,12 @@
LVM metadata type. All drivers are required to have a default
value for this, so it is optional. <span class="since">Since
0.4.1</span></dd>
+ <dt><code>protocol</code></dt>
+ <dd>For a <code>netfs</code> Storage Pool provide a mechanism to
+ define which NFS protocol version number will be used to contact
+ the server's NFS service. The attribute <code>ver</code> accepts
+ an unsigned integer as the version number to use.
+ <span class="since">Since 5.1.0</span></dd>
<dt><code>mount_opts</code></dt>
<dd>Provide an optional set of mount options for the
<code>netfs</code>
pool startup or creation to be provided via the "-o" option.
diff --git a/docs/schemas/storagepool.rng b/docs/schemas/storagepool.rng
index d52856b556..a32c89b94c 100644
--- a/docs/schemas/storagepool.rng
+++ b/docs/schemas/storagepool.rng
@@ -531,6 +531,13 @@
<ref name='sourceinfohost'/>
<ref name='sourceinfodir'/>
<ref name='sourcefmtnetfs'/>
+ <optional>
+ <element name='protocol'>
+ <attribute name='ver'>
+ <ref name='unsignedInt'/>
+ </attribute>
+ </element>
+ </optional>
<optional>
<ref name='sourcemountopts'/>
</optional>
diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index aafb7980e7..8ec360e4a1 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -428,6 +428,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
virStorageAuthDefPtr authdef = NULL;
char *name = NULL;
char *port = NULL;
+ char *ver = NULL;
int n;
relnode = ctxt->node;
@@ -554,6 +555,24 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
authdef = NULL;
}
+ /* Option protocol version string (NFSvN) */
+ if ((ver = virXPathString("string(./protocol/@ver)", ctxt))) {
+ if ((source->format != VIR_STORAGE_POOL_NETFS_NFS) &&
+ (source->format != VIR_STORAGE_POOL_NETFS_AUTO)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("storage pool protocol ver unsupported for "
+ "pool type '%s'"),
+
virStoragePoolFormatFileSystemNetTypeToString(source->format));
+ goto cleanup;
+ }
+ if (virStrToLong_uip(ver, NULL, 0, &source->protocolVer) < 0) {
+ virReportError(VIR_ERR_XML_ERROR,
+ _("storage pool protocol ver '%s' is
malformaed"),
+ ver);
+ goto cleanup;
+ }
+ }
+
/* Optional, but defined mount ops */
VIR_FREE(nodeset);
n = virXPathNodeSet("./mount_opts/option", ctxt, &nodeset);
@@ -997,6 +1016,9 @@ virStoragePoolSourceFormat(virBufferPtr buf,
if (src->auth)
virStorageAuthDefFormat(buf, src->auth);
+ if (src->protocolVer)
+ virBufferAsprintf(buf, "<protocol ver='%u'/>\n",
src->protocolVer);
+
if (src->mountOpts) {
virBufferAddLit(buf, "<mount_opts>\n");
virBufferAdjustIndent(buf, 2);
diff --git a/src/conf/storage_conf.h b/src/conf/storage_conf.h
index c23e6720ac..f36d4daa3c 100644
--- a/src/conf/storage_conf.h
+++ b/src/conf/storage_conf.h
@@ -201,6 +201,9 @@ struct _virStoragePoolSource {
* or lvm version, etc.
*/
int format;
+
+ /* Protocol version value for netfs */
+ unsigned int protocolVer;
};
typedef struct _virStoragePoolTarget virStoragePoolTarget;
diff --git a/tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml
b/tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml
new file mode 100644
index 0000000000..40f3f94e41
--- /dev/null
+++ b/tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml
@@ -0,0 +1,21 @@
+<pool type='netfs'>
+ <name>nfsimages</name>
+ <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
+ <capacity>0</capacity>
+ <allocation>0</allocation>
+ <available>0</available>
+ <source>
+ <host name='localhost'/>
+ <dir path='/var/lib/libvirt/images'/>
+ <format type='nfs'/>
+ <protocol ver='3'/>
+ </source>
+ <target>
+ <path>/mnt</path>
+ <permissions>
+ <mode>0700</mode>
+ <owner>0</owner>
+ <group>0</group>
+ </permissions>
+ </target>
+</pool>
diff --git a/tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml
b/tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml
new file mode 100644
index 0000000000..5fcad1305b
--- /dev/null
+++ b/tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml
@@ -0,0 +1,21 @@
+<pool type='netfs'>
+ <name>nfsimages</name>
+ <uuid>7641d5a8-af11-f730-a34e-0a7dfcede71f</uuid>
+ <capacity unit='bytes'>0</capacity>
+ <allocation unit='bytes'>0</allocation>
+ <available unit='bytes'>0</available>
+ <source>
+ <host name='localhost'/>
+ <dir path='/var/lib/libvirt/images'/>
+ <format type='nfs'/>
+ <protocol ver='3'/>
+ </source>
+ <target>
+ <path>/mnt</path>
+ <permissions>
+ <mode>0700</mode>
+ <owner>0</owner>
+ <group>0</group>
+ </permissions>
+ </target>
+</pool>
diff --git a/tests/storagepoolxml2xmltest.c b/tests/storagepoolxml2xmltest.c
index 08d9a08020..ecdc2715b0 100644
--- a/tests/storagepoolxml2xmltest.c
+++ b/tests/storagepoolxml2xmltest.c
@@ -83,6 +83,7 @@ mymain(void)
DO_TEST("pool-iscsi-auth");
DO_TEST("pool-netfs");
DO_TEST("pool-netfs-auto");
+ DO_TEST("pool-netfs-protocol-ver");
DO_TEST("pool-netfs-gluster");
DO_TEST("pool-netfs-cifs");
DO_TEST("pool-netfs-mountopts");
--
2.20.1