From 37772499e050b7c9d3f136d8c2e07b67e8ff26d6 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 28 May 2013 11:07:33 +0200 Subject: [PATCH] virsh-domain: Add --live, --config, --current logic to cmdAttachDisk Use the approach established in commit 69ce3ffa8d431e9810607c6e00b7cfcc481b491d to improve this function too. --- tools/virsh-domain.c | 53 +++++++++++++++++++++++++++++++------------- 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 I I I +[[[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 for this usage instead. I can specify the two specific mode I or I. -I<--config> indicates the changes will affect the next boot of the domain, -for compatibility purposes, I<--persistent> is alias of I<--config>. I can indicate the type of source (block|file) I 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 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>]