[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH v3 03/11] virsh: Add source-mount-opts for pool commands



https://bugzilla.redhat.com/show_bug.cgi?id=1584663

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'>
    <name>nfstest</name>
    <source>
      <host name='localhost'/>
      <dir path='/var/lib/libvirt/images'/>
      <format type='nfs'/>
      <mount_opts>
        <option name='nodev'/>
        <option name='nosuid'/>
      </mount_opts>
    </source>
    <target>
      <path>/mnt</path>
    </target>
  </pool>

Signed-off-by: John Ferlan <jferlan redhat com>
---
 tools/virsh-pool.c | 35 ++++++++++++++++++++++++++++++++---
 tools/virsh.pod    |  6 ++++++
 2 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c
index 70ca39bd3d..79b33a8885 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,7 +351,13 @@ 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);
@@ -394,6 +406,21 @@ virshBuildPoolXML(vshControl *ctl,
         if (srcName)
             virBufferAsprintf(&buf, "<name>%s</name>\n", srcName);
 
+        if (mountOpts) {
+            size_t i;
+
+            virBufferAddLit(&buf, "<mount_opts>\n");
+            virBufferAdjustIndent(&buf, 2);
+
+            for (i = 0; i < noptsList; i++)
+                virBufferAsprintf(&buf, "<option name='%s'/>\n",
+                                  optsList[i]);
+
+            virBufferAdjustIndent(&buf, -2);
+            virBufferAddLit(&buf, "</mount_opts>\n");
+        }
+
+
         virBufferAdjustIndent(&buf, -2);
         virBufferAddLit(&buf, "</source>\n");
     }
@@ -409,14 +436,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..718efcb07e 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -3887,6 +3887,7 @@ just I<--build> is provided, then B<pool-build> is called with no flags.
 [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>]]
+[I<--source-mount-opts mountOpts>]
 [[I<--adapter-name name>] | [I<--adapter-wwnn> wwnn I<--adapter-wwpn> wwpn]
 [I<--adapter-parent parent> |
  I<--adapter-parent-wwnn parent_wwnn> I<adapter-parent-wwpn parent_wwpn> |
@@ -3929,6 +3930,11 @@ the storage pool. The I<authtype> is either chap for iscsi I<type> pools or
 ceph for rbd I<type> pools. Either the secret I<usage> or I<uuid> value may
 be provided, but not both.
 
+[I<--source-mount-opts mountOpts>] provides a string to be used when creating
+the mount command for a netfs type pool. The I<mountOpts> must be in a comma
+separated list format. Valid I<mountOpts> that may be provided are "nosuid",
+"noexec", "nodev", and "ro".
+
 [I<--adapter-name name>] defines the scsi_hostN adapter name to be used for
 the scsi_host adapter type pool.
 
-- 
2.20.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]