diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index eb8688de81..e354e446f9 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -173,13 +173,21 @@ static const vshCmdOptDef opts_attach_device[] = { .help = N_("XML file") }, {.name = "persistent", - .type = VSH_OT_ALIAS, - .help = "config" + .type = VSH_OT_BOOL, + .help = N_("make live change persistent") }, {.name = "config", .type = VSH_OT_BOOL, .help = N_("affect next boot") }, + {.name = "live", + .type = VSH_OT_BOOL, + .help = N_("affect running domain") + }, + {.name = "current", + .type = VSH_OT_BOOL, + .help = N_("affect current domain") + }, {.name = NULL} }; @@ -191,7 +199,21 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) char *buffer; int rv; bool ret = false; - unsigned int flags; + unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; + bool current = vshCommandOptBool(cmd, "current"); + bool config = vshCommandOptBool(cmd, "config"); + bool live = vshCommandOptBool(cmd, "live"); + bool persistent = vshCommandOptBool(cmd, "persistent"); + + VSH_EXCLUSIVE_OPTIONS_VAR(persistent, current); + + VSH_EXCLUSIVE_OPTIONS_VAR(current, live); + VSH_EXCLUSIVE_OPTIONS_VAR(current, config); + + if (config || persistent) + flags |= VIR_DOMAIN_AFFECT_CONFIG; + if (live) + flags |= VIR_DOMAIN_AFFECT_LIVE; if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) return false; @@ -199,19 +221,20 @@ cmdAttachDevice(vshControl *ctl, const vshCmd *cmd) if (vshCommandOptStringReq(ctl, cmd, "file", &from) < 0) goto cleanup; + if (persistent && + virDomainIsActive(dom) == 1) + flags |= VIR_DOMAIN_AFFECT_LIVE; + if (virFileReadAll(from, VSH_MAX_XML_FILE, &buffer) < 0) { vshReportError(ctl); goto cleanup; } - if (vshCommandOptBool(cmd, "config")) { - flags = VIR_DOMAIN_AFFECT_CONFIG; - if (virDomainIsActive(dom) == 1) - flags |= VIR_DOMAIN_AFFECT_LIVE; + if (flags) rv = virDomainAttachDeviceFlags(dom, buffer, flags); - } else { + else rv = virDomainAttachDevice(dom, buffer); - } + VIR_FREE(buffer); if (rv < 0) { diff --git a/tools/virsh.pod b/tools/virsh.pod index 7c8ce18975..0837224b33 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1816,7 +1816,8 @@ format of the device sections to get the most accurate set of accepted values. =over 4 -=item B I I [I<--config>] +=item B I I +[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]] Attach a device to the domain, using a device definition in an XML file using a device definition element such as or @@ -1824,13 +1825,22 @@ as the top-level element. See the documentation at L to learn about libvirt XML format for a device. If I<--config> is specified the command alters the persistent domain configuration with the device -attach taking effect the next time libvirt starts the domain. For -compatibility purposes, I<--persistent> is an alias of I<--config>. +attach taking effect the next time libvirt starts the domain. For cdrom and floppy devices, this command only replaces the media within an existing device; consider using B for this usage. For passthrough host devices, see also B, needed if the device does not use managed mode. +If I<--live> is specified, affect a running domain. +If I<--config> is specified, affect the next startup of a persistent domain. +If I<--current> is specified, affect the current domain state. +Both I<--live> and I<--config> flags may be given, but I<--current> is +exclusive. When no flag is specified legacy API is used whose behavior depends +on the hypervisor driver. + +For compatibility purposes, I<--persistent> behaves like I<--config> for +an offline domain, and like I<--live> I<--config> for a running domain. + B: using of partial device definition XML files may lead to unexpected results as some fields may be autogenerated and thus match devices other than expected.