[libvirt] [PATCH] Allow duration=0 for virsh nodesuspend

Daniel P. Berrange berrange at redhat.com
Fri Nov 30 19:18:57 UTC 2012


From: "Daniel P. Berrange" <berrange at redhat.com>

The virNodeSuspend API allows for a duration of 0, to mean no
timed wakup. virsh needlessly forbids this though

Signed-off-by: Daniel P. Berrange <berrange at redhat.com>
---
 tools/virsh-domain.c | 34 ++++++++++++++++++++--------------
 tools/virsh-host.c   |  2 +-
 2 files changed, 21 insertions(+), 15 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 3ca246b..9f1a3d4 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4030,8 +4030,8 @@ static const vshCmdOptDef opts_shutdown[] = {
 static bool
 cmdShutdown(vshControl *ctl, const vshCmd *cmd)
 {
-    virDomainPtr dom;
-    bool ret = true;
+    virDomainPtr dom = NULL;
+    bool ret = false;
     const char *name;
     const char *mode = NULL;
     int flags = 0;
@@ -4062,14 +4062,13 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
         } else {
             vshError(ctl, _("Unknown mode %s value, expecting "
                             "'acpi', 'agent', 'initctl' or 'signal'"), mode);
-            return false;
+            goto cleanup;
         }
         tmp++;
     }
-    virStringFreeList(modes);
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
-        return false;
+        goto cleanup;
 
     if (flags)
         rv = virDomainShutdownFlags(dom, flags);
@@ -4079,10 +4078,14 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
         vshPrint(ctl, _("Domain %s is being shutdown\n"), name);
     } else {
         vshError(ctl, _("Failed to shutdown domain %s"), name);
-        ret = false;
+        goto cleanup;
     }
 
-    virDomainFree(dom);
+    ret = true;
+cleanup:
+    if (dom)
+        virDomainFree(dom);
+    virStringFreeList(modes);
     return ret;
 }
 
@@ -4104,8 +4107,8 @@ static const vshCmdOptDef opts_reboot[] = {
 static bool
 cmdReboot(vshControl *ctl, const vshCmd *cmd)
 {
-    virDomainPtr dom;
-    bool ret = true;
+    virDomainPtr dom = NULL;
+    bool ret = false;
     const char *name;
     const char *mode = NULL;
     int flags = 0;
@@ -4135,23 +4138,26 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
         } else {
             vshError(ctl, _("Unknown mode %s value, expecting "
                             "'acpi', 'agent', 'initctl' or 'signal'"), mode);
-            return false;
+            goto cleanup;
         }
         tmp++;
     }
-    virStringFreeList(modes);
 
     if (!(dom = vshCommandOptDomain(ctl, cmd, &name)))
-        return false;
+        goto cleanup;
 
     if (virDomainReboot(dom, flags) == 0) {
         vshPrint(ctl, _("Domain %s is being rebooted\n"), name);
     } else {
         vshError(ctl, _("Failed to reboot domain %s"), name);
-        ret = false;
+        goto cleanup;
     }
 
-    virDomainFree(dom);
+    ret = true;
+cleanup:
+    if (dom)
+        virDomainFree(dom);
+    virStringFreeList(modes);
     return ret;
 }
 
diff --git a/tools/virsh-host.c b/tools/virsh-host.c
index 3701f56..3d13e01 100644
--- a/tools/virsh-host.c
+++ b/tools/virsh-host.c
@@ -537,7 +537,7 @@ cmdNodeSuspend(vshControl *ctl, const vshCmd *cmd)
         return false;
     }
 
-    if (duration <= 0) {
+    if (duration < 0) {
         vshError(ctl, "%s", _("Invalid duration"));
         return false;
     }
-- 
1.7.11.7




More information about the libvir-list mailing list