File libvirt-virsh-domain-Add-live-config-current-logic-to-cmdDetachDevice.patch of Package libvirt

From ee29053868f33d83072aca96ed036d9840b315d8 Mon Sep 17 00:00:00 2001
Message-Id: <ee29053868f33d83072aca96ed036d9840b315d8@dist-git>
From: Peter Krempa <pkrempa@redhat.com>
Date: Tue, 15 Jul 2014 17:33:38 +0200
Subject: [PATCH] virsh-domain: Add --live, --config, --current logic to
 cmdDetachDevice

https://bugzilla.redhat.com/show_bug.cgi?id=1117177

Use the established approach to improve this function too.

(cherry picked from commit d87f72107304d5f8b159f7660b93813d624ed763)

Conflicts:
	tools/virsh-domain.c - context with c99 init refactor

Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 tools/virsh-domain.c | 46 +++++++++++++++++++++++++++++++++++++---------
 tools/virsh.pod      | 19 +++++++++++++++----
 2 files changed, 52 insertions(+), 13 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index f9d2e1b..4e827e1 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -7620,8 +7620,22 @@ static const vshCmdInfo info_detach_device[] = {
 static const vshCmdOptDef opts_detach_device[] = {
     {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")},
     {"file",   VSH_OT_DATA, VSH_OFLAG_REQ, N_("XML file")},
-    {"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}
 };
 
@@ -7633,11 +7647,29 @@ cmdDetachDevice(vshControl *ctl, const vshCmd *cmd)
     char *buffer = NULL;
     int ret;
     bool funcRet = false;
-    unsigned int flags;
+    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)))
         return false;
 
+    if (persistent &&
+        virDomainIsActive(dom) == 1)
+        flags |= VIR_DOMAIN_AFFECT_LIVE;
+
     if (vshCommandOptString(cmd, "file", &from) <= 0)
         goto cleanup;
 
@@ -7646,14 +7678,10 @@ cmdDetachDevice(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 != 0)
         ret = virDomainDetachDeviceFlags(dom, buffer, flags);
-    } else {
+    else
         ret = virDomainDetachDevice(dom, buffer);
-    }
 
     if (ret < 0) {
         vshError(ctl, _("Failed to detach device from %s"), from);
diff --git a/tools/virsh.pod b/tools/virsh.pod
index e3a8bd5..88c5994 100644
--- a/tools/virsh.pod
+++ b/tools/virsh.pod
@@ -1829,16 +1829,27 @@ B<Note>: the optional target value is the name of a device to be created
 as the back-end on the node. If not provided a device named "vnetN" or "vifN"
 will be created automatically.
 
-=item B<detach-device> I<domain> I<FILE> [I<--config>]
+=item B<detach-device> I<domain> I<FILE>
+[[[I<--live>] [I<--config>] | [I<--current>]] | [I<--persistent>]]
 
 Detach a device from the domain, takes the same kind of XML descriptions
 as command B<attach-device>.
-If I<--config> is specified, alter persistent configuration, effect observed
-on next boot, for compatibility purposes, I<--persistent> is alias of
-I<--config>.
 For passthrough host devices, see also B<nodedev-reattach>, 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.
+
+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>]
 
 Detach a disk device from a domain. The I<target> is the device as seen
-- 
2.0.0

openSUSE Build Service is sponsored by