]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
node_memory: Fix bug of node_memory_tune
authorOsier Yang <jyang@redhat.com>
Wed, 28 Nov 2012 14:11:07 +0000 (22:11 +0800)
committerOsier Yang <jyang@redhat.com>
Thu, 29 Nov 2012 07:36:41 +0000 (15:36 +0800)
The 3 options accept 0, and merely checking for non-zero values
would cause wrong results.

tools/virsh-host.c

index 5e6842a5bf874617908d03ef1814c2c6aa03578f..3701f56674691a68f0746d216a5994094c74f115 100644 (file)
@@ -965,35 +965,39 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
     unsigned int shm_pages_to_scan = 0;
     unsigned int shm_sleep_millisecs = 0;
     unsigned int shm_merge_across_nodes = 0;
+    bool has_shm_pages_to_scan = false;
+    bool has_shm_sleep_millisecs = false;
+    bool has_shm_merge_across_nodes = false;
     bool ret = false;
+    int rc = -1;
     int i = 0;
 
-    if (vshCommandOptUInt(cmd, "shm-pages-to-scan",
-                          &shm_pages_to_scan) < 0) {
+    if ((rc = vshCommandOptUInt(cmd, "shm-pages-to-scan",
+                                &shm_pages_to_scan)) < 0) {
         vshError(ctl, "%s", _("invalid shm-pages-to-scan number"));
         return false;
+    } else if (rc > 0) {
+        nparams++;
+        has_shm_pages_to_scan = true;
     }
 
-    if (vshCommandOptUInt(cmd, "shm-sleep-millisecs",
-                          &shm_sleep_millisecs) < 0) {
+    if ((rc = vshCommandOptUInt(cmd, "shm-sleep-millisecs",
+                                &shm_sleep_millisecs)) < 0) {
         vshError(ctl, "%s", _("invalid shm-sleep-millisecs number"));
         return false;
+    } else if (rc > 0) {
+        nparams++;
+        has_shm_sleep_millisecs = true;
     }
 
-    if (vshCommandOptUInt(cmd, "shm-merge-across-nodes",
-                          &shm_merge_across_nodes) < 0) {
+    if ((rc = vshCommandOptUInt(cmd, "shm-merge-across-nodes",
+                                &shm_merge_across_nodes)) < 0) {
         vshError(ctl, "%s", _("invalid shm-merge-across-nodes number"));
         return false;
-    }
-
-    if (shm_pages_to_scan)
-        nparams++;
-
-    if (shm_sleep_millisecs)
-        nparams++;
-
-    if (shm_merge_across_nodes)
+    } else if (rc > 0) {
         nparams++;
+        has_shm_merge_across_nodes = true;
+    }
 
     if (nparams == 0) {
         /* Get the number of memory parameters */
@@ -1030,7 +1034,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
         /* Set the memory parameters */
         params = vshCalloc(ctl, nparams, sizeof(*params));
 
-        if (i < nparams && shm_pages_to_scan) {
+        if (i < nparams && has_shm_pages_to_scan) {
             if (virTypedParameterAssign(&params[i++],
                                         VIR_NODE_MEMORY_SHARED_PAGES_TO_SCAN,
                                         VIR_TYPED_PARAM_UINT,
@@ -1038,7 +1042,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
                 goto error;
         }
 
-        if (i < nparams && shm_sleep_millisecs) {
+        if (i < nparams && has_shm_sleep_millisecs) {
             if (virTypedParameterAssign(&params[i++],
                                         VIR_NODE_MEMORY_SHARED_SLEEP_MILLISECS,
                                         VIR_TYPED_PARAM_UINT,
@@ -1046,7 +1050,7 @@ cmdNodeMemoryTune(vshControl *ctl, const vshCmd *cmd)
                 goto error;
         }
 
-        if (i < nparams && shm_merge_across_nodes) {
+        if (i < nparams && has_shm_merge_across_nodes) {
             if (virTypedParameterAssign(&params[i++],
                                         VIR_NODE_MEMORY_SHARED_MERGE_ACROSS_NODES,
                                         VIR_TYPED_PARAM_UINT,