[Libvir] [PATCH] Fix the check of <cpumap> in virsh vcpupin
Richard W.M. Jones
rjones at redhat.com
Mon Jun 18 16:20:13 UTC 2007
Richard W.M. Jones wrote:
> Index: src/virsh.c
> ===================================================================
> RCS file: /data/cvs/libvirt/src/virsh.c,v
> retrieving revision 1.85
> diff -u -r1.85 virsh.c
> --- src/virsh.c 18 Jun 2007 08:33:08 -0000 1.85
> +++ src/virsh.c 18 Jun 2007 11:00:59 -0000
> @@ -1505,7 +1505,7 @@
> * "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}
> @@ -1530,6 +1530,8 @@
> 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;
> @@ -1563,6 +1565,42 @@
> 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);
I want to commit this one if we're all happy with it ...?
Rich.
--
Emerging Technologies, Red Hat - http://et.redhat.com/~rjones/
Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod
Street, Windsor, Berkshire, SL4 1TE, United Kingdom. Registered in
England and Wales under Company Registration No. 03798903
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3237 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20070618/f1ad4ab1/attachment-0001.bin>
More information about the libvir-list
mailing list