[libvirt] [PATCH 3/4] Allow multiple parameters for schedinfo

Martin Kletzander mkletzan at redhat.com
Thu Mar 14 09:27:34 UTC 2013


virsh schedinfo was able to set only one parameter at a time (not
counting the deprecated options), but it is useful to set more at
once, so this patch adds the possibility to do stuff like this:

virsh schedinfo <domain> cpu_shares=0 vcpu_period=0 vcpu_quota=0 \
emulator_period=0 emulator_quota=0

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=919372
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=919375

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 tools/virsh-domain.c | 55 ++++++++++++++++++++++++++--------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index ab90f58..a7cc9d5 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -4026,36 +4026,33 @@ static const vshCmdOptDef opts_schedinfo[] = {
      .flags = VSH_OFLAG_REQ,
      .help = N_("domain name, id or uuid")
     },
-    {.name = "set",
-     .type = VSH_OT_STRING,
-     .flags = VSH_OFLAG_NONE,
-     .help = N_("parameter=value")
-    },
     {.name = "weight",
      .type = VSH_OT_INT,
-     .flags = VSH_OFLAG_NONE,
+     .flags = VSH_OFLAG_REQ_OPT,
      .help = N_("weight for XEN_CREDIT")
     },
     {.name = "cap",
      .type = VSH_OT_INT,
-     .flags = VSH_OFLAG_NONE,
+     .flags = VSH_OFLAG_REQ_OPT,
      .help = N_("cap for XEN_CREDIT")
     },
     {.name = "current",
      .type = VSH_OT_BOOL,
-     .flags = 0,
      .help = N_("get/set current scheduler info")
     },
     {.name = "config",
      .type = VSH_OT_BOOL,
-     .flags = 0,
      .help = N_("get/set value to be used on next boot")
     },
     {.name = "live",
      .type = VSH_OT_BOOL,
-     .flags = 0,
      .help = N_("get/set value from running domain")
     },
+    {.name = "set",
+     .type = VSH_OT_ARGV,
+     .flags = VSH_OFLAG_NONE,
+     .help = N_("parameter=value")
+    },
     {.name = NULL}
 };

@@ -4064,9 +4061,9 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
                    virTypedParameterPtr src_params, int nsrc_params,
                    virTypedParameterPtr *update_params)
 {
-    const char *set_arg;
     char *set_field = NULL;
     char *set_val = NULL;
+    const vshCmdOpt *opt = NULL;
     virTypedParameterPtr param;
     virTypedParameterPtr params = NULL;
     int nparams = 0;
@@ -4076,17 +4073,6 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
     int val;
     int i;

-    if (vshCommandOptString(cmd, "set", &set_arg) > 0) {
-        set_field = vshStrdup(ctl, set_arg);
-        if (!(set_val = strchr(set_field, '='))) {
-            vshError(ctl, "%s", _("Invalid syntax for --set, expecting name=value"));
-            goto cleanup;
-        }
-
-        *set_val = '\0';
-        set_val++;
-    }
-
     for (i = 0; i < nsrc_params; i++) {
         param = &(src_params[i]);

@@ -4108,15 +4094,28 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
             continue;
         }

-        if (set_field && STREQ(set_field, param->field)) {
-            if (virTypedParamsAddFromString(&params, &nparams, &maxparams,
-                                            set_field, param->type,
-                                            set_val) < 0) {
-                vshSaveLibvirtError();
+        opt = NULL;
+        while ((opt = vshCommandOptArgv(cmd, opt))) {
+            set_field = vshStrdup(ctl, opt->data);
+            if (!(set_val = strchr(set_field, '='))) {
+                vshError(ctl, "%s", _("Invalid syntax for --set, expecting name=value"));
                 goto cleanup;
             }

-            continue;
+            *set_val = '\0';
+            set_val++;
+
+            if (STREQ(set_field, param->field)) {
+                if (virTypedParamsAddFromString(&params, &nparams, &maxparams,
+                                                set_field, param->type,
+                                                set_val) < 0) {
+                    vshSaveLibvirtError();
+                    goto cleanup;
+                }
+                VIR_FREE(set_field);
+                break;
+            }
+            VIR_FREE(set_field);
         }
     }

-- 
1.8.1.5




More information about the libvir-list mailing list