File libvirt-virsh-domain-Add-live-config-current-logic-to-cmdAttachDisk.patch of Package libvirt
From 355429535bf8a6320a27625f99a4cf44748ff95c Mon Sep 17 00:00:00 2001
Message-Id: <355429535bf8a6320a27625f99a4cf44748ff95c@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 15 Jul 2014 17:33:37 +0200
Subject: [PATCH] virsh-domain: Add --live, --config, --current logic to
cmdAttachDisk
https://bugzilla.redhat.com/show_bug.cgi?id=1117177
Use the approach established in commit
69ce3ffa8d431e9810607c6e00b7cfcc481b491d to improve this function too.
(cherry picked from commit 37772499e050b7c9d3f136d8c2e07b67e8ff26d6)
Conflicts:
tools/virsh-domain.c - context and C99 struct init
tools/virsh.pod - context - missing --print-xml from upstream
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
tools/virsh-domain.c | 47 ++++++++++++++++++++++++++++++++++++++---------
tools/virsh.pod | 14 ++++++++++++--
2 files changed, 50 insertions(+), 11 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index ff1fd3d..f9d2e1b 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -206,8 +206,6 @@ static const vshCmdOptDef opts_attach_disk[] = {
{"cache", VSH_OT_STRING, 0, N_("cache mode of disk device")},
{"type", VSH_OT_STRING, 0, N_("target device type")},
{"mode", VSH_OT_STRING, 0, N_("mode of device reading and writing")},
- {"persistent", VSH_OT_ALIAS, 0, "config"},
- {"config", VSH_OT_BOOL, 0, N_("affect next boot")},
{"sourcetype", VSH_OT_STRING, 0, N_("type of source (block|file)")},
{"serial", VSH_OT_STRING, 0, N_("serial of disk device")},
{"shareable", VSH_OT_BOOL, 0, N_("shareable between domains")},
@@ -215,6 +213,23 @@ static const vshCmdOptDef opts_attach_disk[] = {
{"address", VSH_OT_STRING, 0, N_("address of disk device")},
{"multifunction", VSH_OT_BOOL, 0,
N_("use multifunction pci under specified address")},
+ {.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")
+ },
+
{NULL, 0, 0, NULL}
};
@@ -375,11 +390,25 @@ 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;
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)))
goto cleanup;
@@ -394,6 +423,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "target", &target) <= 0)
goto cleanup;
+ if (persistent &&
+ virDomainIsActive(dom) == 1)
+ flags |= VIR_DOMAIN_AFFECT_LIVE;
+
if (vshCommandOptString(cmd, "driver", &driver) < 0 ||
vshCommandOptString(cmd, "subdriver", &subdriver) < 0 ||
vshCommandOptString(cmd, "type", &type) < 0 ||
@@ -518,14 +551,10 @@ cmdAttachDisk(vshControl *ctl, const vshCmd *cmd)
xml = virBufferContentAndReset(&buf);
- 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);
- }
VIR_FREE(xml);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index e10e34d..e3a8bd5 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1762,6 +1762,7 @@ usage. For passthrough host devices, see also B<nodedev-detach>,
needed if the device does not use managed mode.
=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>]
@@ -1782,8 +1783,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".
@@ -1795,6 +1794,17 @@ scsi:controller.bus.unit or ide:controller.bus.unit.
I<multifunction> indicates specified pci address is a multifunction pci device
address.
+
+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>]
--
2.0.0