[PATCH 2/2] virsh: Pass the corect 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 | 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

--
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]