storage: pool: Allow more intricate nfs protocol versions

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>
This commit is contained in:
Peter Krempa 2022-06-23 17:17:06 +02:00
parent 5333cf9d2f
commit c44930d932
8 changed files with 16 additions and 19 deletions

View File

@ -350,7 +350,7 @@ following child elements:
``protocol`` ``protocol``
For a ``netfs`` Storage Pool provide a mechanism to define which NFS 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 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` :since:`Since 5.1.0`
``vendor`` ``vendor``
Provides optional information about the vendor of the storage device. This Provides optional information about the vendor of the storage device. This

View File

@ -577,9 +577,7 @@
<ref name="sourcefmtnetfs"/> <ref name="sourcefmtnetfs"/>
<optional> <optional>
<element name="protocol"> <element name="protocol">
<attribute name="ver"> <attribute name="ver"/>
<ref name="unsignedInt"/>
</attribute>
</element> </element>
</optional> </optional>
<optional> <optional>

View File

@ -483,6 +483,7 @@ virStoragePoolSourceClear(virStoragePoolSource *source)
virStorageAuthDefFree(source->auth); virStorageAuthDefFree(source->auth);
VIR_FREE(source->vendor); VIR_FREE(source->vendor);
VIR_FREE(source->product); VIR_FREE(source->product);
VIR_FREE(source->protocolVer);
} }
@ -526,7 +527,6 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
virStoragePoolOptions *options; virStoragePoolOptions *options;
int n; int n;
g_autoptr(virStorageAuthDef) authdef = NULL; g_autoptr(virStorageAuthDef) authdef = NULL;
g_autofree char *ver = NULL;
g_autofree xmlNodePtr *nodeset = NULL; g_autofree xmlNodePtr *nodeset = NULL;
g_autofree char *sourcedir = NULL; g_autofree char *sourcedir = NULL;
VIR_XPATH_NODE_AUTORESTORE(ctxt) VIR_XPATH_NODE_AUTORESTORE(ctxt)
@ -634,7 +634,7 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
} }
/* Option protocol version string (NFSvN) */ /* 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) && if ((source->format != VIR_STORAGE_POOL_NETFS_NFS) &&
(source->format != VIR_STORAGE_POOL_NETFS_AUTO)) { (source->format != VIR_STORAGE_POOL_NETFS_AUTO)) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@ -643,10 +643,11 @@ virStoragePoolDefParseSource(xmlXPathContextPtr ctxt,
virStoragePoolFormatFileSystemNetTypeToString(source->format)); virStoragePoolFormatFileSystemNetTypeToString(source->format));
return -1; return -1;
} }
if (virStrToLong_uip(ver, NULL, 0, &source->protocolVer) < 0) {
virReportError(VIR_ERR_XML_ERROR, if (strchr(source->protocolVer, ',')) {
_("storage pool protocol ver '%s' is malformed"), virReportError(VIR_ERR_XML_DETAIL,
ver); _("storage pool protocol ver '%s' must not contain ','"),
source->protocolVer);
return -1; return -1;
} }
} }
@ -1099,9 +1100,7 @@ virStoragePoolSourceFormat(virBuffer *buf,
if (src->auth) if (src->auth)
virStorageAuthDefFormat(buf, src->auth); virStorageAuthDefFormat(buf, src->auth);
if (src->protocolVer) virBufferEscapeString(buf, "<protocol ver='%s'/>\n", src->protocolVer);
virBufferAsprintf(buf, "<protocol ver='%u'/>\n", src->protocolVer);
virBufferEscapeString(buf, "<vendor name='%s'/>\n", src->vendor); virBufferEscapeString(buf, "<vendor name='%s'/>\n", src->vendor);
virBufferEscapeString(buf, "<product name='%s'/>\n", src->product); virBufferEscapeString(buf, "<product name='%s'/>\n", src->product);

View File

@ -213,7 +213,7 @@ struct _virStoragePoolSource {
int format; int format;
/* Protocol version value for netfs */ /* Protocol version value for netfs */
unsigned int protocolVer; char *protocolVer;
}; };
typedef struct _virStoragePoolTarget virStoragePoolTarget; typedef struct _virStoragePoolTarget virStoragePoolTarget;

View File

@ -4201,8 +4201,8 @@ virStorageBackendFileSystemMountCmd(const char *cmdstr,
virCommand *cmd = NULL; virCommand *cmd = NULL;
g_autofree char *nfsVers = NULL; g_autofree char *nfsVers = NULL;
if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer > 0) if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer)
nfsVers = g_strdup_printf("nfsvers=%u", def->source.protocolVer); nfsVers = g_strdup_printf("nfsvers=%s", def->source.protocolVer);
cmd = virCommandNew(cmdstr); cmd = virCommandNew(cmdstr);
if (netauto) if (netauto)

View File

@ -1,5 +1,5 @@
mount \ mount \
-o nodev,nosuid,noexec,nfsvers=3 \ -o nodev,nosuid,noexec,nfsvers=4.1 \
-t nfs \ -t nfs \
localhost:/var/lib/libvirt/images \ localhost:/var/lib/libvirt/images \
/mnt /mnt

View File

@ -8,7 +8,7 @@
<host name='localhost'/> <host name='localhost'/>
<dir path='/var/lib/libvirt/images'/> <dir path='/var/lib/libvirt/images'/>
<format type='nfs'/> <format type='nfs'/>
<protocol ver='3'/> <protocol ver='4.1'/>
</source> </source>
<target> <target>
<path>/mnt</path> <path>/mnt</path>

View File

@ -8,7 +8,7 @@
<host name='localhost'/> <host name='localhost'/>
<dir path='/var/lib/libvirt/images'/> <dir path='/var/lib/libvirt/images'/>
<format type='nfs'/> <format type='nfs'/>
<protocol ver='3'/> <protocol ver='4.1'/>
</source> </source>
<target> <target>
<path>/mnt</path> <path>/mnt</path>