]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: improve schedinfo querying ability
authorEric Blake <eblake@redhat.com>
Tue, 17 May 2011 22:06:12 +0000 (16:06 -0600)
committerDaniel Veillard <veillard@redhat.com>
Sun, 29 May 2011 10:51:16 +0000 (18:51 +0800)
Since we can now set just --live or --config, we also need to be
able to query that back.

In the case of setting both --live and --config, it shouldn't matter
which value we read back; otherwise, since querying treats the two
flags as mutually exclusive, so does this patch.

* tools/virsh.c (cmdSchedinfo): Use new API where appropriate.

tools/virsh.c

index 82409ecfb8cee935354011371659815e42ac5f11..418ef838807e577e2720862ef0bfced0a3a011a9 100644 (file)
@@ -1745,7 +1745,7 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
 
     /* Print SchedulerType */
     schedulertype = virDomainGetSchedulerType(dom, &nparams);
-    if (schedulertype != NULL){
+    if (schedulertype != NULL) {
         vshPrint(ctl, "%-15s: %s\n", _("Scheduler"),
              schedulertype);
         VIR_FREE(schedulertype);
@@ -1758,12 +1758,22 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
         params = vshMalloc(ctl, sizeof(*params) * nparams);
 
         memset(params, 0, sizeof(*params) * nparams);
-        ret = virDomainGetSchedulerParameters(dom, params, &nparams);
+        if (flags || current) {
+            /* We cannot query both live and config at once, so settle
+               on current in that case.  If we are setting, then the
+               two values should match when we re-query; otherwise, we
+               report the error later.  */
+            ret = virDomainGetSchedulerParametersFlags(dom, params, &nparams,
+                                                       ((live && config) ? 0
+                                                        : flags));
+        } else {
+            ret = virDomainGetSchedulerParameters(dom, params, &nparams);
+        }
         if (ret == -1)
             goto cleanup;
 
         /* See if any params are being set */
-        for (i = 0; i < nparams; i++){
+        for (i = 0; i < nparams; i++) {
             ret = cmdSchedInfoUpdate(ctl, cmd, &(params[i]));
             if (ret == -1)
                 goto cleanup;
@@ -1782,7 +1792,13 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
             if (ret == -1)
                 goto cleanup;
 
-            ret = virDomainGetSchedulerParameters(dom, params, &nparams);
+            if (flags || current)
+                ret = virDomainGetSchedulerParametersFlags(dom, params,
+                                                           &nparams,
+                                                           ((live && config) ? 0
+                                                            : flags));
+            else
+                ret = virDomainGetSchedulerParameters(dom, params, &nparams);
             if (ret == -1)
                 goto cleanup;
         } else {
@@ -1795,10 +1811,16 @@ cmdSchedinfo(vshControl *ctl, const vshCmd *cmd)
                          var_value_pair);
                 goto cleanup;
             }
+            /* When not doing --set, --live and --config do not mix.  */
+            if (live && config) {
+                vshError(ctl, "%s",
+                         _("cannot query both live and config at once"));
+                goto cleanup;
+            }
         }
 
         ret_val = true;
-        for (i = 0; i < nparams; i++){
+        for (i = 0; i < nparams; i++) {
             switch (params[i].type) {
             case VIR_TYPED_PARAM_INT:
                  vshPrint(ctl, "%-15s: %d\n",  params[i].field, params[i].value.i);