
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@redhat.com> --- 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,