Re: [libvirt] [PATCH v2] Allow multiple parameters for schedinfo

2013-04-03 Thread Martin Kletzander
On 04/03/2013 01:22 AM, Eric Blake wrote:
 On 03/21/2013 10:22 AM, Martin Kletzander wrote:
 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

 Invalid scheduler options are reported as well.  These were previously
 reported only if the command hadn't updated any values (when
 cmdSchedInfoUpdate returned 0).

 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=810078
 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 mklet...@redhat.com
 ---
 v2:
  - correctly report unsupported options
  - man page updated

  tests/virsh-schedinfo |   4 +-
  tools/virsh-domain.c  | 119 
 --
  tools/virsh.pod   |   4 +-
  3 files changed, 72 insertions(+), 55 deletions(-)
 
 ACK.
 

Thanks, pushed.

Martin

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH v2] Allow multiple parameters for schedinfo

2013-04-02 Thread Martin Kletzander
ping, still applicable on master :)

On 03/21/2013 05:22 PM, Martin Kletzander wrote:
 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
 
 Invalid scheduler options are reported as well.  These were previously
 reported only if the command hadn't updated any values (when
 cmdSchedInfoUpdate returned 0).
 
 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=810078
 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 mklet...@redhat.com
 ---
 v2:
  - correctly report unsupported options
  - man page updated
 
  tests/virsh-schedinfo |   4 +-
  tools/virsh-domain.c  | 119 
 --
  tools/virsh.pod   |   4 +-
  3 files changed, 72 insertions(+), 55 deletions(-)
 
 diff --git a/tests/virsh-schedinfo b/tests/virsh-schedinfo
 index 4f462f8..37f7bd3 100755
 --- a/tests/virsh-schedinfo
 +++ b/tests/virsh-schedinfo
 @@ -1,7 +1,7 @@
  #!/bin/sh
  # Ensure that virsh schedinfo --set invalid=val fails
 
 -# Copyright (C) 2010-2011 Red Hat, Inc.
 +# Copyright (C) 2010-2011, 2013 Red Hat, Inc.
 
  # This program is free software: you can redistribute it and/or modify
  # it under the terms of the GNU General Public License as published by
 @@ -37,7 +37,7 @@ fi
  . $srcdir/test-lib.sh
 
  printf 'Scheduler  : fair\n\n'  exp-out || framework_failure
 -printf 'error: invalid scheduler option: j=k\n'  exp-err || 
 framework_failure
 +printf 'error: invalid scheduler option: j\n'  exp-err || framework_failure
 
  fail=0
 
 diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
 index 128e516..cc2eddc 100644
 --- a/tools/virsh-domain.c
 +++ b/tools/virsh-domain.c
 @@ -3918,16 +3918,14 @@ static const vshCmdOptDef opts_schedinfo[] = {
   .flags = VSH_OFLAG_REQ,
   .help = N_(domain name, id or uuid)
  },
 -{.name = set,
 - .type = VSH_OT_STRING,
 - .help = N_(parameter=value)
 -},
  {.name = weight,
   .type = VSH_OT_INT,
 + .flags = VSH_OFLAG_REQ_OPT,
   .help = N_(weight for XEN_CREDIT)
  },
  {.name = cap,
   .type = VSH_OT_INT,
 + .flags = VSH_OFLAG_REQ_OPT,
   .help = N_(cap for XEN_CREDIT)
  },
  {.name = current,
 @@ -3942,72 +3940,100 @@ static const vshCmdOptDef opts_schedinfo[] = {
   .type = VSH_OT_BOOL,
   .help = N_(get/set value from running domain)
  },
 +{.name = set,
 + .type = VSH_OT_ARGV,
 + .flags = VSH_OFLAG_NONE,
 + .help = N_(parameter=value)
 +},
  {.name = NULL}
  };
 
  static int
 +cmdSchedInfoUpdateOne(vshControl *ctl,
 +  virTypedParameterPtr src_params, int nsrc_params,
 +  virTypedParameterPtr *params,
 +  int *nparams, int *maxparams,
 +  const char *field, const char *value)
 +{
 +virTypedParameterPtr param;
 +int ret = -1;
 +int i;
 +
 +for (i = 0; i  nsrc_params; i++) {
 +param = (src_params[i]);
 +
 +if (STRNEQ(field, param-field))
 +continue;
 +
 +if (virTypedParamsAddFromString(params, nparams, maxparams,
 +field, param-type,
 +value)  0) {
 +vshSaveLibvirtError();
 +goto cleanup;
 +}
 +ret = 0;
 +break;
 +}
 +
 +if (ret  0)
 +vshError(ctl, _(invalid scheduler option: %s), field);
 +
 + cleanup:
 +return ret;
 +}
 +
 +static int
  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;
 -virTypedParameterPtr param;
 +const char *val = NULL;
 +const vshCmdOpt *opt = NULL;
  virTypedParameterPtr params = NULL;
  int nparams = 0;
  int maxparams = 0;
  int ret = -1;
  int rv;
 -int val;
 -int i;
 
 -if (vshCommandOptString(cmd, set, set_arg)  0) {
 -set_field = vshStrdup(ctl, set_arg);
 +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));
 +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]);
 -
 -/* Legacy 

Re: [libvirt] [PATCH v2] Allow multiple parameters for schedinfo

2013-04-02 Thread Eric Blake
On 03/21/2013 10:22 AM, Martin Kletzander wrote:
 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
 
 Invalid scheduler options are reported as well.  These were previously
 reported only if the command hadn't updated any values (when
 cmdSchedInfoUpdate returned 0).
 
 Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=810078
 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 mklet...@redhat.com
 ---
 v2:
  - correctly report unsupported options
  - man page updated
 
  tests/virsh-schedinfo |   4 +-
  tools/virsh-domain.c  | 119 
 --
  tools/virsh.pod   |   4 +-
  3 files changed, 72 insertions(+), 55 deletions(-)

ACK.

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

[libvirt] [PATCH v2] Allow multiple parameters for schedinfo

2013-03-21 Thread Martin Kletzander
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

Invalid scheduler options are reported as well.  These were previously
reported only if the command hadn't updated any values (when
cmdSchedInfoUpdate returned 0).

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=810078
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 mklet...@redhat.com
---
v2:
 - correctly report unsupported options
 - man page updated

 tests/virsh-schedinfo |   4 +-
 tools/virsh-domain.c  | 119 --
 tools/virsh.pod   |   4 +-
 3 files changed, 72 insertions(+), 55 deletions(-)

diff --git a/tests/virsh-schedinfo b/tests/virsh-schedinfo
index 4f462f8..37f7bd3 100755
--- a/tests/virsh-schedinfo
+++ b/tests/virsh-schedinfo
@@ -1,7 +1,7 @@
 #!/bin/sh
 # Ensure that virsh schedinfo --set invalid=val fails

-# Copyright (C) 2010-2011 Red Hat, Inc.
+# Copyright (C) 2010-2011, 2013 Red Hat, Inc.

 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -37,7 +37,7 @@ fi
 . $srcdir/test-lib.sh

 printf 'Scheduler  : fair\n\n'  exp-out || framework_failure
-printf 'error: invalid scheduler option: j=k\n'  exp-err || framework_failure
+printf 'error: invalid scheduler option: j\n'  exp-err || framework_failure

 fail=0

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 128e516..cc2eddc 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -3918,16 +3918,14 @@ static const vshCmdOptDef opts_schedinfo[] = {
  .flags = VSH_OFLAG_REQ,
  .help = N_(domain name, id or uuid)
 },
-{.name = set,
- .type = VSH_OT_STRING,
- .help = N_(parameter=value)
-},
 {.name = weight,
  .type = VSH_OT_INT,
+ .flags = VSH_OFLAG_REQ_OPT,
  .help = N_(weight for XEN_CREDIT)
 },
 {.name = cap,
  .type = VSH_OT_INT,
+ .flags = VSH_OFLAG_REQ_OPT,
  .help = N_(cap for XEN_CREDIT)
 },
 {.name = current,
@@ -3942,72 +3940,100 @@ static const vshCmdOptDef opts_schedinfo[] = {
  .type = VSH_OT_BOOL,
  .help = N_(get/set value from running domain)
 },
+{.name = set,
+ .type = VSH_OT_ARGV,
+ .flags = VSH_OFLAG_NONE,
+ .help = N_(parameter=value)
+},
 {.name = NULL}
 };

 static int
+cmdSchedInfoUpdateOne(vshControl *ctl,
+  virTypedParameterPtr src_params, int nsrc_params,
+  virTypedParameterPtr *params,
+  int *nparams, int *maxparams,
+  const char *field, const char *value)
+{
+virTypedParameterPtr param;
+int ret = -1;
+int i;
+
+for (i = 0; i  nsrc_params; i++) {
+param = (src_params[i]);
+
+if (STRNEQ(field, param-field))
+continue;
+
+if (virTypedParamsAddFromString(params, nparams, maxparams,
+field, param-type,
+value)  0) {
+vshSaveLibvirtError();
+goto cleanup;
+}
+ret = 0;
+break;
+}
+
+if (ret  0)
+vshError(ctl, _(invalid scheduler option: %s), field);
+
+ cleanup:
+return ret;
+}
+
+static int
 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;
-virTypedParameterPtr param;
+const char *val = NULL;
+const vshCmdOpt *opt = NULL;
 virTypedParameterPtr params = NULL;
 int nparams = 0;
 int maxparams = 0;
 int ret = -1;
 int rv;
-int val;
-int i;

-if (vshCommandOptString(cmd, set, set_arg)  0) {
-set_field = vshStrdup(ctl, set_arg);
+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));
+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]);
-
-/* Legacy 'weight' and 'cap'  parameter */
-if (param-type == VIR_TYPED_PARAM_UINT 
-(STREQ(param-field, weight) || STREQ(param-field, cap)) 
-(rv = vshCommandOptInt(cmd, param-field, val)) != 0) {
-if (rv  0) {
-