virsh: Add source-initiator opt to build the initiator of pool XML

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>
This commit is contained in:
Han Han 2020-08-25 11:50:33 +08:00 committed by Michal Privoznik
parent 14b895ad3a
commit 8eebceef43
2 changed files with 22 additions and 4 deletions

View 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*]

View File

@ -141,6 +141,10 @@
{.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)