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

Michal Privoznik mprivozn at redhat.com
Mon Feb 3 16:17:12 UTC 2014


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 at redhat.com>
---
 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




More information about the libvir-list mailing list