[libvirt] [PATCH] virsh: Error prompt if one passes negative value for scheduler setting

Osier Yang jyang at redhat.com
Fri Jan 28 11:53:44 UTC 2011


As cgroup doesn't allow one writes negative into files like cpu.shares,
(e.g. echo -1> /cgroup/cpu/libvirt/qemu/rhel6/cpu.shares), user will be
confused if libvirt accepts negative value and converts it into unsigned
int (or long int, etc) silently.

* tools/virsh.c
---
 tools/virsh.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/tools/virsh.c b/tools/virsh.c
index cd54174..a0f2527 100644
--- a/tools/virsh.c
+++ b/tools/virsh.c
@@ -1652,7 +1652,8 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
             }
             break;
         case VIR_DOMAIN_SCHED_FIELD_UINT:
-            if (virStrToLong_ui(val, NULL, 10, &param->value.ui) < 0) {
+            if (STRPREFIX(val, "-") ||
+                virStrToLong_ui(val, NULL, 10, &param->value.ui) < 0) {
                 vshError(ctl, "%s",
                          _("Invalid value for parameter, expecting an unsigned int"));
                 return -1;
@@ -1666,7 +1667,8 @@ cmdSchedInfoUpdate(vshControl *ctl, const vshCmd *cmd,
             }
             break;
         case VIR_DOMAIN_SCHED_FIELD_ULLONG:
-            if (virStrToLong_ull(val, NULL, 10, &param->value.ul) < 0) {
+            if (STRPREFIX(val, "-") ||
+                virStrToLong_ull(val, NULL, 10, &param->value.ul) < 0) {
                 vshError(ctl, "%s",
                          _("Invalid value for parameter, expecting an unsigned long long"));
                 return -1;
--
1.7.3.2




More information about the libvir-list mailing list