storage: Add the nfsvers to the command line

If protocolVer present, add the -o nfsvers=# to the command
line for the NFS Storage Pool

Signed-off-by: John Ferlan <jferlan@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
John Ferlan 2019-01-11 13:42:18 -05:00
parent 801f8cfb37
commit 3d3647e14f
5 changed files with 20 additions and 6 deletions

View File

@ -4290,10 +4290,11 @@ virStorageBackendFileSystemMountAddOptions(virCommandPtr cmd,
static void static void
virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd, virStorageBackendFileSystemMountNFSArgs(virCommandPtr cmd,
const char *src, const char *src,
virStoragePoolDefPtr def) virStoragePoolDefPtr def,
const char *nfsVers)
{ {
virCommandAddArgList(cmd, src, def->target.path, NULL); virCommandAddArgList(cmd, src, def->target.path, NULL);
virStorageBackendFileSystemMountAddOptions(cmd, NULL); virStorageBackendFileSystemMountAddOptions(cmd, nfsVers);
} }
@ -4326,7 +4327,8 @@ virStorageBackendFileSystemMountCIFSArgs(virCommandPtr cmd,
static void static void
virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd, virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd,
const char *src, const char *src,
virStoragePoolDefPtr def) virStoragePoolDefPtr def,
const char *nfsVers)
{ {
const char *fmt; const char *fmt;
@ -4335,7 +4337,7 @@ virStorageBackendFileSystemMountDefaultArgs(virCommandPtr cmd,
else else
fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format); fmt = virStoragePoolFormatFileSystemNetTypeToString(def->source.format);
virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL); virCommandAddArgList(cmd, "-t", fmt, src, def->target.path, NULL);
virStorageBackendFileSystemMountAddOptions(cmd, NULL); virStorageBackendFileSystemMountAddOptions(cmd, nfsVers);
} }
@ -4354,16 +4356,21 @@ virStorageBackendFileSystemMountCmd(const char *cmdstr,
bool cifsfs = (def->type == VIR_STORAGE_POOL_NETFS && bool cifsfs = (def->type == VIR_STORAGE_POOL_NETFS &&
def->source.format == VIR_STORAGE_POOL_NETFS_CIFS); def->source.format == VIR_STORAGE_POOL_NETFS_CIFS);
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
VIR_AUTOFREE(char *) nfsVers = NULL;
if (def->type == VIR_STORAGE_POOL_NETFS && def->source.protocolVer > 0 &&
virAsprintf(&nfsVers, "nfsvers=%u", def->source.protocolVer) < 0)
return NULL;
cmd = virCommandNew(cmdstr); cmd = virCommandNew(cmdstr);
if (netauto) if (netauto)
virStorageBackendFileSystemMountNFSArgs(cmd, src, def); virStorageBackendFileSystemMountNFSArgs(cmd, src, def, nfsVers);
else if (glusterfs) else if (glusterfs)
virStorageBackendFileSystemMountGlusterArgs(cmd, src, def); virStorageBackendFileSystemMountGlusterArgs(cmd, src, def);
else if (cifsfs) else if (cifsfs)
virStorageBackendFileSystemMountCIFSArgs(cmd, src, def); virStorageBackendFileSystemMountCIFSArgs(cmd, src, def);
else else
virStorageBackendFileSystemMountDefaultArgs(cmd, src, def); virStorageBackendFileSystemMountDefaultArgs(cmd, src, def, nfsVers);
return cmd; return cmd;
} }

View File

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

View File

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

View File

@ -0,0 +1 @@
mount -t nfs localhost:/var/lib/libvirt/images /mnt -o nfsvers=3

View File

@ -176,18 +176,21 @@ mymain(void)
DO_TEST_LINUX("pool-fs"); DO_TEST_LINUX("pool-fs");
DO_TEST_LINUX("pool-netfs"); DO_TEST_LINUX("pool-netfs");
DO_TEST_LINUX("pool-netfs-auto"); DO_TEST_LINUX("pool-netfs-auto");
DO_TEST_LINUX("pool-netfs-protocol-ver");
DO_TEST_LINUX("pool-netfs-gluster"); DO_TEST_LINUX("pool-netfs-gluster");
DO_TEST_LINUX("pool-netfs-cifs"); DO_TEST_LINUX("pool-netfs-cifs");
#elif defined(__FreeBSD__) #elif defined(__FreeBSD__)
DO_TEST_FREEBSD("pool-fs"); DO_TEST_FREEBSD("pool-fs");
DO_TEST_FREEBSD("pool-netfs"); DO_TEST_FREEBSD("pool-netfs");
DO_TEST_FREEBSD("pool-netfs-auto"); DO_TEST_FREEBSD("pool-netfs-auto");
DO_TEST_FREEBSD("pool-netfs-protocol-ver");
DO_TEST_FREEBSD("pool-netfs-gluster"); DO_TEST_FREEBSD("pool-netfs-gluster");
DO_TEST_FREEBSD("pool-netfs-cifs"); DO_TEST_FREEBSD("pool-netfs-cifs");
#else #else
DO_TEST("pool-fs"); DO_TEST("pool-fs");
DO_TEST("pool-netfs"); DO_TEST("pool-netfs");
DO_TEST("pool-netfs-auto"); DO_TEST("pool-netfs-auto");
DO_TEST("pool-netfs-protocol-ver");
DO_TEST("pool-netfs-gluster"); DO_TEST("pool-netfs-gluster");
DO_TEST("pool-netfs-cifs"); DO_TEST("pool-netfs-cifs");
#endif #endif