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

Nitesh Konkar niteshkonkar.libvirt at gmail.com
Mon May 2 13:59:58 UTC 2016


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

Signed-off-by: Nitesh Konkar <nitkon12 at linux.vnet.ibm.com>
---
 tools/virsh-domain.c | 32 +++++++++++++++++++-------------
 1 file changed, 19 insertions(+), 13 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index d9fde4d..5cfd6a3 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11302,7 +11302,7 @@ static bool
 cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom = NULL;
-    char *doc = NULL;
+    char *doc_live = NULL, *doc_config = NULL;
     bool functionReturn = false;
     unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
     bool current = vshCommandOptBool(cmd, "current");
@@ -11317,8 +11317,6 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
 
     if (config || persistent)
         flags |= VIR_DOMAIN_AFFECT_CONFIG;
-    if (live)
-        flags |= VIR_DOMAIN_AFFECT_LIVE;
 
     if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))
         return false;
@@ -11327,15 +11325,23 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
         virDomainIsActive(dom) == 1)
         flags |= VIR_DOMAIN_AFFECT_LIVE;
 
-    if (flags & VIR_DOMAIN_AFFECT_CONFIG)
-        doc = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE);
-    else
-        doc = virDomainGetXMLDesc(dom, 0);
+    if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+        if (!(doc_config = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE)))
+            goto cleanup;
+        if (!(functionReturn = virshDomainDetachInterface(doc_config, flags, dom, ctl, cmd)))
+            goto cleanup;
+    }
 
-    if (!doc)
-        goto cleanup;
-    else
-       functionReturn = virshDomainDetachInterface(doc, flags, dom, ctl, cmd);
+    flags = 0;
+
+    if (live || (!live && !config))
+        flags |= VIR_DOMAIN_AFFECT_LIVE;
+
+    if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+        if (!(doc_live = virDomainGetXMLDesc(dom, 0)))
+           goto cleanup;
+        functionReturn = virshDomainDetachInterface(doc_live, flags, dom, ctl, cmd);
+    }
 
  cleanup:
     if (functionReturn == false) {
@@ -11344,8 +11350,8 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, "%s", _("Interface detached successfully\n"));
         functionReturn = true;
     }
-
-    VIR_FREE(doc);
+    VIR_FREE(doc_live);
+    VIR_FREE(doc_config);
     virDomainFree(dom);
     return functionReturn;
 }
-- 
1.8.3.1




More information about the libvir-list mailing list