On 06/28/2015 10:10 PM, Luyao Huang wrote: > If usr pass a vcpu which exceed guest maxvcpu number, virsh client > will only output an header like this: > > # virsh vcpupin test3 1000 > VCPU: CPU Affinity > ---------------------------------- > > After this patch: > > # virsh vcpupin test3 1000 > error: vcpu 1000 is out of range of cpu count 2 > > Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx> > --- > tools/virsh-domain.c | 5 +++++ > 1 file changed, 5 insertions(+) > Seemed odd that this check wasn't there - so I did some digging... Pavel's commit id '81dd81e' removed a check that seems to be what is desired in this path (or was there before his change): if (vcpu >= info.nrVirtCpu) { vshError(ctl, "%s", _("vcpupin: vCPU index out of range.")); goto cleanup; return false; } As part of this commit, you'll note there was a test change in "tests/vcpupin": # An out-of-range vCPU number deserves a diagnostic, too. $abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 0,1 > out 2>&1 test $? = 1 || fail=1 cat <<\EOF > exp || fail=1 -error: vcpupin: vCPU index out of range. +error: invalid argument: requested vcpu is higher than allocated vcpus Searching on their error message lands one in test_driver.c/ testDomainPinVcpu(). So something specific for a set path, but the path you're hitting is the get path. FWIW: If a similar test was run on my system I get: # virsh vcpupin $dom 1000 0,1 error: invalid argument: vcpu 1000 is out of range of live cpu count 2 # So, if I understand everything that was done - then while your change is mostly correct, I think you could perhaps message the error similar to the vshCPUCountCollect failure (see the attached patch) Before I make that change for you - hopefully Pavel can take a look as well to be sure I haven't missed something. With any luck we this could be addressed before the 1.2.17 release, but if not since it's been a regression since 1.2.13 and no one's noticed, then another release probably won't hurt. John > diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c > index 27d62e9..681fc1a 100644 > --- a/tools/virsh-domain.c > +++ b/tools/virsh-domain.c > @@ -6497,6 +6497,11 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) > goto cleanup; > } > > + if (got_vcpu && vcpu >= ncpus) { > + vshError(ctl, _("vcpu %d is out of range of cpu count %d"), vcpu, ncpus); > + goto cleanup; > + } > + > cpumaplen = VIR_CPU_MAPLEN(maxcpu); > cpumap = vshMalloc(ctl, ncpus * cpumaplen); > if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap, >
>From 63e642f4ad9705118870a237afd9d0bc9084200d Mon Sep 17 00:00:00 2001 From: Luyao Huang <lhuang@xxxxxxxxxx> Date: Mon, 29 Jun 2015 10:10:15 +0800 Subject: [PATCH] virsh: report error if vcpu number exceed the guest maxvcpu number Commit id '81dd81e' caused a regression when attempting to print a specific vcpuid that is out of the range of the maximum vcpus for the guest, such as: $ virsh vcpupin $dom 1000 VCPU: CPU Affinity ---------------------------------- $ Rather than just recover the old message, let's adjust the message based on what would be displayed for a similar failure in the set path, such as: $ virsh vcpupin $dom 1000 error: vcpu 1000 is out of range of persistent cpu count 2 $ virsh vcpupin $dom 1000 --live error: vcpu 1000 is out of range of live cpu count 2 $ Signed-off-by: Luyao Huang <lhuang@xxxxxxxxxx> Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx> --- tools/virsh-domain.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 27d62e9..2ff2a40 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -6497,6 +6497,18 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) goto cleanup; } + if (got_vcpu && vcpu >= ncpus) { + if (flags & VIR_DOMAIN_AFFECT_LIVE) + vshError(ctl, + _("vcpu %d is out of range of live cpu count %d"), + vcpu, ncpus); + else + vshError(ctl, + _("vcpu %d is out of range of persistent cpu count %d"), + vcpu, ncpus); + goto cleanup; + } + cpumaplen = VIR_CPU_MAPLEN(maxcpu); cpumap = vshMalloc(ctl, ncpus * cpumaplen); if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap, -- 2.1.0
-- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list