]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add source-initiator opt to build the initiator of pool XML
authorHan Han <hhan@redhat.com>
Tue, 25 Aug 2020 03:50:33 +0000 (11:50 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Tue, 25 Aug 2020 07:32:05 +0000 (09:32 +0200)
For iscsi-direct pool, the initiator is necessary for pool defining:
<pool type="iscsi-direct">
 ...
    <initiator>
      <iqn name="iqn.2013-06.com.example:iscsi-initiator"/>
    </initiator>
...
</pool>

Add --source-initiator to fill the initiator iqn for
pool-create-as/pool-define-as subcommands.

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

Signed-off-by: Han Han <hhan@redhat.com>
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
docs/manpages/virsh.rst
tools/virsh-pool.c

index 9187037a561552fbae15f5b0d54d1a597a0ba24b..0482fe8b26f2470061f63f989eb62e1b3f80410c 100644 (file)
@@ -5732,6 +5732,7 @@ pool-create-as
    pool-create-as name type
       [--source-host hostname] [--source-path path] [--source-dev path]
       [--source-name name] [--target path] [--source-format format]
+      [--source-initiator initiator-iqn]
       [--auth-type authtype --auth-username username
       [--secret-usage usage | --secret-uuid uuid]]
       [--source-protocol-ver ver]
@@ -5769,6 +5770,9 @@ the host file system.
 [*--source-format format*] provides information about the format of the
 pool (pool types fs, netfs, disk, logical).
 
+[*--source-initiator initiator-iqn*] provides the initiator iqn for iscsi
+connection of the pool (pool type iscsi-direct).
+
 [*--auth-type authtype* *--auth-username username*
 [*--secret-usage usage* | *--secret-uuid uuid*]]
 provides the elements required to generate authentication credentials for
@@ -5831,6 +5835,7 @@ pool-define-as
    pool-define-as name type
       [--source-host hostname] [--source-path path] [--source-dev path]
       [*--source-name name*] [*--target path*] [*--source-format format*]
+      [--source-initiator initiator-iqn]
       [*--auth-type authtype* *--auth-username username*
       [*--secret-usage usage* | *--secret-uuid uuid*]]
       [*--source-protocol-ver ver*]
index fd43d3bb6261b2915a45bbe2e686d990148d403e..9fac590ec3fef353988a83b6b4f615b72dfe77e7 100644 (file)
     {.name = "source-protocol-ver", \
      .type = VSH_OT_STRING, \
      .help = N_("nfsvers value for NFS pool mount option") \
+    }, \
+    {.name = "source-initiator", \
+     .type = VSH_OT_STRING, \
+     .help = N_("initiator iqn for underlying storage") \
     }
 
 virStoragePoolPtr
@@ -324,7 +328,8 @@ virshBuildPoolXML(vshControl *ctl,
                *secretUsage = NULL, *adapterName = NULL, *adapterParent = NULL,
                *adapterWwnn = NULL, *adapterWwpn = NULL, *secretUUID = NULL,
                *adapterParentWwnn = NULL, *adapterParentWwpn = NULL,
-               *adapterParentFabricWwn = NULL, *protoVer = NULL;
+               *adapterParentFabricWwn = NULL, *protoVer = NULL,
+               *srcInitiator = NULL;
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
 
     VSH_EXCLUSIVE_OPTIONS("secret-usage", "secret-uuid");
@@ -352,15 +357,16 @@ virshBuildPoolXML(vshControl *ctl,
         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, "source-protocol-ver", &protoVer) < 0) {
+        vshCommandOptStringReq(ctl, cmd, "source-protocol-ver", &protoVer) < 0 ||
+        vshCommandOptStringReq(ctl, cmd, "source-initiator", &srcInitiator) < 0) {
         return false;
     }
 
     virBufferAsprintf(&buf, "<pool type='%s'>\n", type);
     virBufferAdjustIndent(&buf, 2);
     virBufferAsprintf(&buf, "<name>%s</name>\n", name);
-    if (srcHost || srcPath || srcDev || srcFormat || srcName ||
-        (adapterWwnn && adapterWwpn) || adapterName) {
+    if (srcHost || srcPath || srcDev || srcInitiator || srcFormat ||
+        srcName || (adapterWwnn && adapterWwpn) || adapterName) {
         virBufferAddLit(&buf, "<source>\n");
         virBufferAdjustIndent(&buf, 2);
 
@@ -370,6 +376,13 @@ virshBuildPoolXML(vshControl *ctl,
             virBufferAsprintf(&buf, "<dir path='%s'/>\n", srcPath);
         if (srcDev)
             virBufferAsprintf(&buf, "<device path='%s'/>\n", srcDev);
+        if (srcInitiator) {
+            virBufferAddLit(&buf, "<initiator>\n");
+            virBufferAdjustIndent(&buf, 2);
+            virBufferAsprintf(&buf, "<iqn name='%s'/>\n", srcInitiator);
+            virBufferAdjustIndent(&buf, -2);
+            virBufferAddLit(&buf, "</initiator>\n");
+        }
         if (adapterWwnn && adapterWwpn) {
             virBufferAddLit(&buf, "<adapter type='fc_host'");
             if (adapterParent)