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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]