File libvirt-virsh-domain-Add-live-config-current-logic-to-cmdDetachDisk.patch of Package libvirt
From f6b4265674ea387b27ed0b6e6f23ef0e8f080255 Mon Sep 17 00:00:00 2001
Message-Id: <f6b4265674ea387b27ed0b6e6f23ef0e8f080255@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 15 Jul 2014 17:33:39 +0200
Subject: [PATCH] virsh-domain: Add --live, --config, --current logic to
cmdDetachDisk
https://bugzilla.redhat.com/show_bug.cgi?id=1117177
Use the established approach to improve this function too.
(cherry picked from commit b685a73ed94884950c611ef0a0efe98971595adf)
Conflicts:
tools/virsh-domain.c - context with c99 init refactor
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
tools/virsh-domain.c | 60 +++++++++++++++++++++++++++++++++++++---------------
tools/virsh.pod | 19 +++++++++++++----
2 files changed, 58 insertions(+), 21 deletions(-)
diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 4e827e1..eae4d09 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -8139,8 +8139,22 @@ static const vshCmdInfo info_detach_disk[] = {
static const vshCmdOptDef opts_detach_disk[] = {
{"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
{"target", VSH_OT_DATA, VSH_OFLAG_REQ, N_("target of disk device")},
- {"persistent", VSH_OT_ALIAS, 0, "config"},
- {"config", VSH_OT_BOOL, 0, N_("affect next boot")},
+ {.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}
};
@@ -8153,8 +8167,22 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
char *doc = NULL;
int ret;
bool functionReturn = false;
- unsigned int flags;
xmlNodePtr disk_node = NULL;
+ bool current = vshCommandOptBool(cmd, "current");
+ bool config = vshCommandOptBool(cmd, "config");
+ bool live = vshCommandOptBool(cmd, "live");
+ bool persistent = vshCommandOptBool(cmd, "persistent");
+ unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+
+ 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;
@@ -8162,10 +8190,13 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptString(cmd, "target", &target) <= 0)
goto cleanup;
- doc = virDomainGetXMLDesc(dom, 0);
- if (!doc)
+ if (!(doc = virDomainGetXMLDesc(dom, 0)))
goto cleanup;
+ if (persistent &&
+ virDomainIsActive(dom) == 1)
+ flags |= VIR_DOMAIN_AFFECT_LIVE;
+
if (!(disk_node = vshFindDisk(doc, target, VSH_FIND_DISK_NORMAL)))
goto cleanup;
@@ -8173,24 +8204,19 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
VSH_PREPARE_DISK_XML_NONE)))
goto cleanup;
- if (vshCommandOptBool(cmd, "config")) {
- flags = VIR_DOMAIN_AFFECT_CONFIG;
- if (virDomainIsActive(dom) == 1)
- flags |= VIR_DOMAIN_AFFECT_LIVE;
- ret = virDomainDetachDeviceFlags(dom,
- disk_xml,
- flags);
- } else {
+ if (flags != 0)
+ ret = virDomainDetachDeviceFlags(dom, disk_xml, flags);
+ else
ret = virDomainDetachDevice(dom, disk_xml);
- }
if (ret != 0) {
vshError(ctl, "%s", _("Failed to detach disk"));
- } else {
- vshPrint(ctl, "%s", _("Disk detached successfully\n"));
- functionReturn = true;
+ goto cleanup;
}
+ vshPrint(ctl, "%s", _("Disk detached successfully\n"));
+ functionReturn = true;
+
cleanup:
xmlFreeNode(disk_node);
VIR_FREE(disk_xml);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index 88c5994..25fa4f0 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1850,13 +1850,24 @@ an offline domain, and like I<--live> I<--config> for a running domain.
Note that older versions of virsh used I<--config> as an alias for
I<--persistent>.
-=item B<detach-disk> I<domain> I<target> [I<--config>]
+=item B<detach-disk> I<domain> I<target>
+[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]]
Detach a disk device from a domain. The I<target> is the device as seen
from the domain.
-If I<--config> is specified, alter persistent configuration, effect observed
-on next boot, for compatibility purposes, I<--persistent> is alias of
-I<--config>.
+
+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.
+
+Note that older versions of virsh used I<--config> as an alias for
+I<--persistent>.
=item B<detach-interface> I<domain> I<type> [I<--mac mac>] [I<--config>]
--
2.0.0