diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 026dac1083..004fac4734 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -317,6 +317,12 @@ static const vshCmdOptDef opts_attach_disk[] = { .flags = 0, .help = N_("use multifunction pci under specified address") }, + {.name = "print-xml", + .type = VSH_OT_BOOL, + .flags = 0, + .help = N_("print XML document rather than attach the disk") + }, + {.name = NULL} }; @@ -480,11 +486,11 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) unsigned int flags; const char *stype = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; - char *xml; + char *xml = NULL; struct stat st; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) - goto cleanup; + return false; if (vshCommandOptString(cmd, "source", &source) <= 0) goto cleanup; @@ -620,6 +626,12 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) xml = virBufferContentAndReset(&buf); + if (vshCommandOptBool(cmd, "print-xml")) { + vshPrint(ctl, "%s", xml); + functionReturn = true; + goto cleanup; + } + if (vshCommandOptBool(cmd, "config")) { flags = VIR_DOMAIN_AFFECT_CONFIG; if (virDomainIsActive(dom) == 1) @@ -629,8 +641,6 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) ret = virDomainAttachDevice(dom, xml); } - VIR_FREE(xml); - if (ret != 0) { vshError(ctl, "%s", _("Failed to attach disk")); } else { @@ -639,8 +649,8 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) } cleanup: - if (dom) - virDomainFree(dom); + VIR_FREE(xml); + virDomainFree(dom); virBufferFreeAndReset(&buf); return functionReturn; } diff --git a/tools/virsh.pod b/tools/virsh.pod index e2a2aeca95..fd0f762abb 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1787,7 +1787,7 @@ needed if the device does not use managed mode. [I<--driver driver>] [I<--subdriver subdriver>] [I<--cache cache>] [I<--type type>] [I<--mode mode>] [I<--config>] [I<--sourcetype soucetype>] [I<--serial serial>] [I<--shareable>] [I<--rawio>] [I<--address address>] -[I<--multifunction>] +[I<--multifunction>] [I<--print-xml>] Attach a new disk device to the domain. I is path for the files and devices. I controls the bus or @@ -1817,6 +1817,9 @@ scsi:controller.bus.unit or ide:controller.bus.unit. I indicates specified pci address is a multifunction pci device address. +If I<--print-xml> is specified, then the XML of the disk that would be attached +is printed instead. + =item B I I I [I<--target target>] [I<--mac mac>] [I<--script script>] [I<--model model>] [I<--config>] [I<--inbound average,peak,burst>] [I<--outbound average,peak,burst>]