]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Tue Jun 19 10:30:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
authorRichard W.M. Jones <rjones@redhat.com>
Tue, 19 Jun 2007 09:32:04 +0000 (09:32 +0000)
committerRichard W.M. Jones <rjones@redhat.com>
Tue, 19 Jun 2007 09:32:04 +0000 (09:32 +0000)
        * src/virsh.c: vcpupin command now documented properly and
          gives clearer error messages if the cpulist is wrong
          (Masayuki Sunou).

ChangeLog
src/virsh.c

index dc5259801bfa7ce09453e8aa77f799385538a1fb..cce9daa8b58992c2056491562c54866e0ed64e5b 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+Tue Jun 19 10:30:00 BST 2007 Richard W.M. Jones <rjones@redhat.com>
+
+       * src/virsh.c: vcpupin command now documented properly and
+         gives clearer error messages if the cpulist is wrong
+         (Masayuki Sunou).
+
 Tue Jun 19 11:11:18 CEST 2007 Daniel Veillard <veillard@redhat.com>
 
        * src/xend_internal.c: drop the release information as this
index aac3794a59b08ab01e2fd2ba8de43c80386c8242..5a9568dd446c255bd42963c69bdcc7acf22ba3a3 100644 (file)
@@ -1508,7 +1508,7 @@ cmdVcpuinfo(vshControl * ctl, vshCmd * cmd)
  * "vcpupin" command
  */
 static vshCmdInfo info_vcpupin[] = {
-    {"syntax", "vcpupin <domain>"},
+    {"syntax", "vcpupin <domain> <vcpu> <cpulist>"},
     {"help", gettext_noop("control domain vcpu affinity")},
     {"desc", gettext_noop("Pin domain VCPUs to host physical CPUs.")},
     {NULL, NULL}
@@ -1533,6 +1533,8 @@ cmdVcpupin(vshControl * ctl, vshCmd * cmd)
     int vcpufound = 0;
     unsigned char *cpumap;
     int cpumaplen;
+    int i;
+    enum { expect_num, expect_num_or_comma } state;
 
     if (!vshConnectionUsability(ctl, ctl->conn, TRUE))
         return FALSE;
@@ -1566,6 +1568,42 @@ cmdVcpupin(vshControl * ctl, vshCmd * cmd)
         return FALSE;
     }
 
+    /* Check that the cpulist parameter is a comma-separated list of
+     * numbers and give an intelligent error message if not.
+     */
+    if (cpulist[0] == '\0') {
+        vshError(ctl, FALSE, _("cpulist: Invalid format. Empty string."));
+        virDomainFree (dom);
+        return FALSE;
+    }
+
+    state = expect_num;
+    for (i = 0; cpulist[i]; i++) {
+        switch (state) {
+        case expect_num:
+            if (!isdigit (cpulist[i])) {
+                vshError( ctl, FALSE, _("cpulist: %s: Invalid format. Expecting digit at position %d (near '%c')."), cpulist, i, cpulist[i]);
+                virDomainFree (dom);
+                return FALSE;
+            }
+            state = expect_num_or_comma;
+            break;
+        case expect_num_or_comma:
+            if (cpulist[i] == ',')
+                state = expect_num;
+            else if (!isdigit (cpulist[i])) {
+                vshError(ctl, FALSE, _("cpulist: %s: Invalid format. Expecting digit or comma at position %d (near '%c')."), cpulist, i, cpulist[i]);
+                virDomainFree (dom);
+                return FALSE;
+            }
+        }
+    }
+    if (state == expect_num) {
+        vshError(ctl, FALSE, _("cpulist: %s: Invalid format. Trailing comma at position %d."), cpulist, i);
+        virDomainFree (dom);
+        return FALSE;
+    }
+
     cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
     cpumap = vshCalloc(ctl, 1, cpumaplen);