diff options
author | Peter Krempa <pkrempa@redhat.com> | 2013-05-28 11:07:33 +0200 |
---|---|---|
committer | Peter Krempa <pkrempa@redhat.com> | 2013-06-03 14:23:02 +0200 |
commit | 37772499e050b7c9d3f136d8c2e07b67e8ff26d6 (patch) | |
tree | 066166e7bc4646045f044ede186da365615a75f9 /tools | |
parent | f81c95b31f1c1cc95cb7e52cf8af98cbd624e0c1 (diff) | |
download | libvirt-37772499e050b7c9d3f136d8c2e07b67e8ff26d6.tar.gz |
virsh-domain: Add --live, --config, --current logic to cmdAttachDisk
Use the approach established in commit
69ce3ffa8d431e9810607c6e00b7cfcc481b491d to improve this function too.
Diffstat (limited to 'tools')
-rw-r--r-- | tools/virsh-domain.c | 53 | ||||
-rw-r--r-- | tools/virsh.pod | 13 |
2 files changed, 48 insertions, 18 deletions
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index e354e446f9..cc6640c052 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -299,14 +299,6 @@ static const vshCmdOptDef opts_attach_disk[] = { .type = VSH_OT_STRING, .help = N_("mode of device reading and writing") }, - {.name = "persistent", - .type = VSH_OT_ALIAS, - .help = "config" - }, - {.name = "config", - .type = VSH_OT_BOOL, - .help = N_("affect next boot") - }, {.name = "sourcetype", .type = VSH_OT_STRING, .help = N_("type of source (block|file)") @@ -335,7 +327,22 @@ static const vshCmdOptDef opts_attach_disk[] = { .type = VSH_OT_BOOL, .help = N_("print XML document rather than attach the disk") }, - + {.name = "persistent", + .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} }; @@ -496,15 +503,33 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) struct DiskAddress diskAddr; bool isFile = false, functionReturn = false; int ret; - unsigned int flags; + unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; const char *stype = NULL; virBuffer buf = VIR_BUFFER_INITIALIZER; char *xml = NULL; struct stat st; + 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; + if (persistent && + virDomainIsActive(dom) == 1) + flags |= VIR_DOMAIN_AFFECT_LIVE; + if (vshCommandOptStringReq(ctl, cmd, "source", &source) < 0 || vshCommandOptStringReq(ctl, cmd, "target", &target) < 0 || vshCommandOptStringReq(ctl, cmd, "driver", &driver) < 0 || @@ -635,14 +660,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd) goto cleanup; } - if (vshCommandOptBool(cmd, "config")) { - flags = VIR_DOMAIN_AFFECT_CONFIG; - if (virDomainIsActive(dom) == 1) - flags |= VIR_DOMAIN_AFFECT_LIVE; + if (flags) ret = virDomainAttachDeviceFlags(dom, xml, flags); - } else { + else ret = virDomainAttachDevice(dom, xml); - } if (ret != 0) { vshError(ctl, "%s", _("Failed to attach disk")); diff --git a/tools/virsh.pod b/tools/virsh.pod index 0837224b33..a7e3a8f09a 100644 --- a/tools/virsh.pod +++ b/tools/virsh.pod @@ -1846,6 +1846,7 @@ results as some fields may be autogenerated and thus match devices other than expected. =item B<attach-disk> I<domain> I<source> I<target> +[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]] [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>] @@ -1866,8 +1867,6 @@ alternative to the disk default, although this use only replaces the media within the existing virtual cdrom or floppy device; consider using B<update-device> for this usage instead. I<mode> can specify the two specific mode I<readonly> or I<shareable>. -I<--config> indicates the changes will affect the next boot of the domain, -for compatibility purposes, I<--persistent> is alias of I<--config>. I<sourcetype> can indicate the type of source (block|file) I<cache> can be one of "default", "none", "writethrough", "writeback", "directsync" or "unsafe". @@ -1882,6 +1881,16 @@ address. If I<--print-xml> is specified, then the XML of the disk that would be attached is printed instead. +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. + =item B<attach-interface> I<domain> I<type> I<source> [I<--target target>] [I<--mac mac>] [I<--script script>] [I<--model model>] [I<--config>] [I<--inbound average,peak,burst>] [I<--outbound average,peak,burst>] |