[PATCH 15/15] virsh: Adapt to virDomain{Resume, Suspend}Flags

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

 



Things get complicated once we want to fall back to using the older
versions of APIs when talking to older libvirtd.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tools/virsh-domain.c | 52 +++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 39 insertions(+), 13 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index c3db94c..9f71770 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -2767,18 +2767,31 @@ cmdSuspend(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom;
     const char *name;
-    bool ret = true;
+    bool ret = false;
+    unsigned int flags = 0;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
-        return false;
+        return ret;
 
-    if (virDomainSuspend(dom) == 0) {
-        vshPrint(ctl, _("Domain %s suspended\n"), name);
-    } else {
-        vshError(ctl, _("Failed to suspend domain %s"), name);
-        ret = false;
+    if (virDomainSuspendFlags(dom, flags) < 0) {
+        /* Fallback to older API iff no flag was requested */
+        if (flags || last_error->code != VIR_ERR_NO_SUPPORT) {
+            vshError(ctl, _("Failed to suspend domain %s"), name);
+            goto cleanup;
+        }
+
+        virResetLastError();
+
+        if (virDomainSuspend(dom) < 0) {
+            vshError(ctl, _("Failed to suspend domain %s"), name);
+            goto cleanup;
+        }
     }
 
+    vshPrint(ctl, _("Domain %s suspended\n"), name);
+    ret = true;
+
+cleanup:
     virDomainFree(dom);
     return ret;
 }
@@ -4791,19 +4804,32 @@ static bool
 cmdResume(vshControl *ctl, const vshCmd *cmd)
 {
     virDomainPtr dom;
-    bool ret = true;
+    bool ret = false;
     const char *name;
+    unsigned int flags = 0;
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
         return false;
 
-    if (virDomainResume(dom) == 0) {
-        vshPrint(ctl, _("Domain %s resumed\n"), name);
-    } else {
-        vshError(ctl, _("Failed to resume domain %s"), name);
-        ret = false;
+    if (virDomainResumeFlags(dom, flags) < 0) {
+        /* Fallback to older API iff no flag was requested */
+        if (flags || last_error->code != VIR_ERR_NO_SUPPORT) {
+            vshError(ctl, _("Failed to resume domain %s"), name);
+            goto cleanup;
+        }
+
+        virResetLastError();
+
+        if (virDomainResume(dom) < 0) {
+            vshError(ctl, _("Failed to resume domain %s"), name);
+            goto cleanup;
+        }
     }
 
+    vshPrint(ctl, _("Domain %s resumed\n"), name);
+    ret = true;
+
+cleanup:
     virDomainFree(dom);
     return ret;
 }
-- 
1.8.5.2

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