[PATCH 2/2] virsh: Pass the correct live/config xml to virshDomainDetachInterface.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



cmdDetachInterface function checks for live config
flags and then passes the live/config domain xml
to virshDomainDetachInterface accordingly.

Signed-off-by: Nitesh Konkar <nitkon12@xxxxxxxxxxxxxxxxxx>
---
 tools/virsh-domain.c | 46 +++++++++++++++++++++++++---------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 1b4e9f0..ff467df 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11292,10 +11292,10 @@ static bool
 cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom = NULL;
-    char *doc = NULL;
+    char *doc_live = NULL, *doc_config = NULL;
     const char *mac = NULL, *type = NULL;
-    bool ret = false;
-    unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
+    int flags = 0;
+    bool ret = false, affect_config, affect_live;
     bool current = vshCommandOptBool(cmd, "current");
     bool config = vshCommandOptBool(cmd, "config");
     bool live = vshCommandOptBool(cmd, "live");
@@ -11312,27 +11312,31 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
     if (vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0)
         goto cleanup;
 
-    if (config || persistent)
-        flags |= VIR_DOMAIN_AFFECT_CONFIG;
-    if (live)
-        flags |= VIR_DOMAIN_AFFECT_LIVE;
-
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         return false;
 
-    if (persistent &&
-        virDomainIsActive(dom) == 1)
-        flags |= VIR_DOMAIN_AFFECT_LIVE;
+    affect_config = (config || persistent);
 
-    if (flags & VIR_DOMAIN_AFFECT_CONFIG)
-        doc = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE);
-    else
-        doc = virDomainGetXMLDesc(dom, 0);
+    if (affect_config) {
+        if (!(doc_config = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE)))
+            goto cleanup;
+        if (!(ret = virshDomainDetachInterface(doc_config, flags | VIR_DOMAIN_AFFECT_CONFIG, dom, ctl, current, type, mac)))
+            goto cleanup;
+    }
 
-    if (!doc)
-        goto cleanup;
-    else
-        ret = virshDomainDetachInterface(doc, flags, dom, ctl, current, type, mac);
+    affect_live = (live || (persistent && virDomainIsActive(dom) == 1));
+
+    if (affect_live || !affect_config) {
+        flags = 0;
+
+        if (affect_live)
+            flags |= VIR_DOMAIN_AFFECT_LIVE;
+
+        if (!(doc_live = virDomainGetXMLDesc(dom, 0)))
+            goto cleanup;
+
+        ret = virshDomainDetachInterface(doc_live, flags, dom, ctl, current, type, mac);
+    }
 
  cleanup:
     if (!ret) {
@@ -11340,8 +11344,8 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
     } else {
         vshPrint(ctl, "%s", _("Interface detached successfully\n"));
     }
-
-    VIR_FREE(doc);
+    VIR_FREE(doc_live);
+    VIR_FREE(doc_config);
     virDomainFree(dom);
     return ret;
 }
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]