]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
storage: pool: Allow more intricate nfs protocol versions
authorPeter Krempa <pkrempa@redhat.com>
Thu, 23 Jun 2022 15:17:06 +0000 (17:17 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 1 Jul 2022 14:15:23 +0000 (16:15 +0200)
Treat the 'protocolVer' field as a string so that e.g. '4.1' can be
used. Forbid only ',' in the string as it's a separator of arguments for
mount options.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
docs/formatstorage.rst
src/conf/schemas/storagepool.rng
src/conf/storage_conf.c
src/conf/storage_conf.h
src/storage/storage_util.c
tests/storagepoolxml2argvdata/pool-netfs-protocol-ver-linux.argv
tests/storagepoolxml2xmlin/pool-netfs-protocol-ver.xml
tests/storagepoolxml2xmlout/pool-netfs-protocol-ver.xml

index ef15c0ac5c7aab830e117998edc4a3080dea87d7..83d7d141ac096cf049ef82ae1486099eabe2cc03 100644 (file)
@@ -350,7 +350,7 @@ following child elements:
 ``protocol``
    For a ``netfs`` Storage Pool provide a mechanism to define which NFS protocol
    version number will be used to contact the server's NFS service. The
-   attribute ``ver`` accepts an unsigned integer as the version number to use.
+   attribute ``ver`` accepts the version number to use.
    :since:`Since 5.1.0`
 ``vendor``
    Provides optional information about the vendor of the storage device. This
index bd24b8b8d091293cea48b8675d0de4309e72c38a..d81ead532ae67b3001b4e10a1b2492d01e769cc4 100644 (file)
             <ref name="sourcefmtnetfs"/>
             <optional>
               <element name="protocol">
-                <attribute name="ver">
-                  <ref name="unsignedInt"/>
-                </attribute>
+                <attribute name="ver"/>
               </element>
             </optional>
             <optional>
index 5da0bf20ddce42fe2594d367ce9fdefb0b40944a..79f16aadf330925d234f3eea14a30b5fa81f660f 100644 (file)
@@ -483,6 +483,7 @@ virStoragePoolSourceClear(virStoragePoolSource *source)
     virStorageAuthDefFree(source->auth);
     VIR_FREE(source->vendor);
     VIR_FREE(source->product);
+    VIR_FREE(source->protocolVer);
 }
 
 
@@ -526,7 +527,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
     virStoragePoolOptions *options;
     int n;
     g_autoptr(virStorageAuthDef) authdef = NULL;
-    g_autofree char *ver = NULL;
     g_autofree xmlNodePtr *nodeset = NULL;
     g_autofree char *sourcedir = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
@@ -634,7 +634,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
     }
 
     /* Option protocol version string (NFSvN) */
-    if ((ver = virXPathString("string(./protocol/@ver)", ctxt))) {
+    if ((source->protocolVer = 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,
@@ -643,10 +643,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
                            virStoragePoolFormatFileSystemNetTypeToString(source->format));
             return -1;
         }
-        if (virStrToLong_uip(ver, NULL, 0, &source->protocolVer) < 0) {
-            virReportError(VIR_ERR_XML_ERROR,
-                           _("storage pool protocol ver '%s' is malformed"),
-                           ver);
+
+        if (strchr(source->protocolVer, ',')) {
+            virReportError(VIR_ERR_XML_DETAIL,
+                           _("storage pool protocol ver '%s' must not contain ','"),
+                           source->protocolVer);
             return -1;
         }
     }
@@ -1099,9 +1100,7 @@ virStoragePoolSourceFormat(virBuffer *buf,
     if (src->auth)
         virStorageAuthDefFormat(buf, src->auth);
 
-    if (src->protocolVer)
-        virBufferAsprintf(buf, "<protocol ver='%u'/>\n", src->protocolVer);
-
+    virBufferEscapeString(buf, "<protocol ver='%s'/>\n", src->protocolVer);
     virBufferEscapeString(buf, "<vendor name='%s'/>\n", src->vendor);
     virBufferEscapeString(buf, "<product name='%s'/>\n", src->product);
 
index de39c3f2949feb42036cc368766b5de734b3c8a6..a1bf243935c563ccb7072c800b6e048a0f6ed853 100644 (file)
@@ -213,7 +213,7 @@ struct _virStoragePoolSource {
     int format;
 
     /* Protocol version value for netfs */
-    unsigned int protocolVer;
+    char *protocolVer;
 };
 
 typedef struct _virStoragePoolTarget virStoragePoolTarget;
index 6ed2078b65b125fde57e0cd90708c41c84e81644..3871718b09036ec2843d250fea7f9abed5280bcf 100644 (file)
@@ -4201,8 +4201,8 @@ virStorageBackendFileSystemMountCmd(const char *cmdstr,
     virCommand *cmd = NULL;
     g_autofree char *nfsVers = NULL;
 
-    if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer > 0)
-        nfsVers = g_strdup_printf("nfsvers=%u", def->source.protocolVer);
+    if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer)
+        nfsVers = g_strdup_printf("nfsvers=%s", def->source.protocolVer);
 
     cmd = virCommandNew(cmdstr);
     if (netauto)
index dac46a074ff78de2ec51a36bf4c47b629c465799..da3e0c59279eb63851a70ad5280bfb75ca125ce8 100644 (file)
@@ -1,5 +1,5 @@
 mount \
--o nodev,nosuid,noexec,nfsvers=3 \
+-o nodev,nosuid,noexec,nfsvers=4.1 \
 -t nfs \
 localhost:/var/lib/libvirt/images \
 /mnt
index 40f3f94e41c0c922bdbe0817612c9a68da592bc0..f35992e3c83762955c6e2e154691536307cd2600 100644 (file)
@@ -8,7 +8,7 @@
     <host name='localhost'/>
     <dir path='/var/lib/libvirt/images'/>
     <format type='nfs'/>
-    <protocol ver='3'/>
+    <protocol ver='4.1'/>
   </source>
   <target>
     <path>/mnt</path>
index 5fcad1305b4abc843577e6c36fe33406253d9c59..74c2f5edfeaaaf674594e84eee18bd3603ba1f60 100644 (file)
@@ -8,7 +8,7 @@
     <host name='localhost'/>
     <dir path='/var/lib/libvirt/images'/>
     <format type='nfs'/>
-    <protocol ver='3'/>
+    <protocol ver='4.1'/>
   </source>
   <target>
     <path>/mnt</path>