Add the ability to add the mount options for the pool on the
virsh command line for pool-{create|define}-as commands, such as.
virsh pool-define-as nfstest netfs \
--source-host localhost \
--source-path "/var/lib/libvirt/images" \
--source-format nfs \
--source-mount-opts "nodev,nosuid" \
--target "/mnt"
in order to generate XML:
<pool type='netfs' xmlns:netfs='http://libvirt.org/schemas/storagepool/source/netfs/1.0'>
<name>nfstest</name>
<source>
<host name='localhost'/>
<dir path='/var/lib/libvirt/images'/>
<format type='nfs'/>
<netfs:mount_opts>
<netfs:option name='nodev'/>
<netfs:option name='nosuid'/>
</netfs:mount_opts>
</source>
<target>
<path>/mnt</path>
</target>
</pool>
Signed-off-by: John Ferlan <jferlan@redhat.com>
---
tools/virsh-pool.c | 39 +++++++++++++++++++++++++++++++++++----
tools/virsh.pod | 5 +++++
2 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index 70ca39bd3d..7f8de4a08c 100644
--- a/tools/virsh-pool.c
+++ b/tools/virsh-pool.c
@@ -136,6 +136,10 @@
{.name = "adapter-parent-fabric-wwn", \
.type = VSH_OT_STRING, \
.help = N_("adapter parent scsi_hostN fabric_wwn to be used for underlying vHBA storage") \
+ }, \
+ {.name = "source-mount-opts", \
+ .type = VSH_OT_STRING, \
+ .help = N_("comma separated list for NFS pool mount options") \
}
virStoragePoolPtr
@@ -319,7 +323,9 @@ virshBuildPoolXML(vshControl *ctl,
*secretUsage = NULL, *adapterName = NULL, *adapterParent = NULL,
*adapterWwnn = NULL, *adapterWwpn = NULL, *secretUUID = NULL,
*adapterParentWwnn = NULL, *adapterParentWwpn = NULL,
- *adapterParentFabricWwn = NULL;
+ *adapterParentFabricWwn = NULL, *mountOpts = NULL;
+ size_t noptsList = 0;
+ char **optsList = NULL;
virBuffer buf = VIR_BUFFER_INITIALIZER;
VSH_EXCLUSIVE_OPTIONS("secret-usage", "secret-uuid");
@@ -345,10 +351,19 @@ virshBuildPoolXML(vshControl *ctl,
vshCommandOptStringReq(ctl, cmd, "adapter-parent", &adapterParent) < 0 ||
vshCommandOptStringReq(ctl, cmd, "adapter-parent-wwnn", &adapterParentWwnn) < 0 ||
vshCommandOptStringReq(ctl, cmd, "adapter-parent-wwpn", &adapterParentWwpn) < 0 ||
- vshCommandOptStringReq(ctl, cmd, "adapter-parent-fabric-wwn", &adapterParentFabricWwn) < 0)
+ vshCommandOptStringReq(ctl, cmd, "adapter-parent-fabric-wwn", &adapterParentFabricWwn) < 0 ||
+ vshCommandOptStringReq(ctl, cmd, "source-mount-opts", &mountOpts) < 0)
+ goto cleanup;
+
+ if (mountOpts &&
+ !(optsList = virStringSplitCount(mountOpts, ",", 0, &noptsList)))
goto cleanup;
- virBufferAsprintf(&buf, "<pool type='%s'>\n", type);
+ virBufferAsprintf(&buf, "<pool type='%s'", type);
+ if (mountOpts)
+ virBufferAsprintf(&buf, " xmlns:netfs='%s'",
+ "http://libvirt.org/schemas/storagepool/source/netfs/1.0");
+ virBufferAddLit(&buf, ">\n");
virBufferAdjustIndent(&buf, 2);
virBufferAsprintf(&buf, "<name>%s</name>\n", name);
if (srcHost || srcPath || srcDev || srcFormat || srcName ||
@@ -394,6 +409,20 @@ virshBuildPoolXML(vshControl *ctl,
if (srcName)
virBufferAsprintf(&buf, "<name>%s</name>\n", srcName);
+ if (mountOpts) {
+ size_t i;
+
+ virBufferAddLit(&buf, "<netfs:mount_opts>\n");
+ virBufferAdjustIndent(&buf, 2);
+
+ for (i = 0; i < noptsList; i++)
+ virBufferAsprintf(&buf, "<netfs:option name='%s'/>\n",
+ optsList[i]);
+
+ virBufferAdjustIndent(&buf, -2);
+ virBufferAddLit(&buf, "</netfs:mount_opts>\n");
+ }
+
virBufferAdjustIndent(&buf, -2);
virBufferAddLit(&buf, "</source>\n");
}
@@ -409,14 +438,16 @@ virshBuildPoolXML(vshControl *ctl,
if (virBufferError(&buf)) {
vshError(ctl, "%s", _("Failed to allocate XML buffer"));
- return false;
+ goto cleanup;
}
+ virStringListFree(optsList);
*xml = virBufferContentAndReset(&buf);
*retname = name;
return true;
cleanup:
+ virStringListFree(optsList);
virBufferFreeAndReset(&buf);
return false;
}
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 86a4996cae..881981e159 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -3884,6 +3884,7 @@ just I<--build> is provided, then B<pool-build> is called with no flags.
=item B<pool-create-as> I<name> I<type>
[I<--source-host hostname>] [I<--source-path path>] [I<--source-dev path>]
+[I<--source-mount-opts mountOpts>]
[I<--source-name name>] [I<--target path>] [I<--source-format format>]
[I<--auth-type authtype> I<--auth-username username>
[I<--secret-usage usage> | I<--secret-uuid uuid>]]
@@ -3910,6 +3911,10 @@ gluster).
[I<--source-path path>] provides the source directory path for pools backed
by directories (pool type dir).
+[<--source-mount-opts mountOpts>] provides a string to be used when creating
+the mount command for a netfs type pool. The options must be in a comma
+separated list format as described by the mount options command.
+
[I<--source-dev path>] provides the source path for pools backed by physical
devices (pool types fs, logical, disk, iscsi, zfs).
--
2.20.1
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list