提交 81dd81e4 编写于 作者: P Pavel Hrdina

virsh: fix vcpupin info

The "virDomainGetInfo" will get for running domain only live info and for
offline domain only config info. There was no way how to get config info
for running domain. We will use "vshCPUCountCollect" instead to get the
correct cpu count that we need to pass to "virDomainGetVcpuPinInfo".

Also cleanup some unnecessary variables and checks that are done by
drivers.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1160559Signed-off-by: NPavel Hrdina <phrdina@redhat.com>
上级 af204232
...@@ -43,7 +43,7 @@ compare exp out || fail=1 ...@@ -43,7 +43,7 @@ compare exp out || fail=1
$abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 0,1 > out 2>&1 $abs_top_builddir/tools/virsh --connect test:///default vcpupin test 100 0,1 > out 2>&1
test $? = 1 || fail=1 test $? = 1 || fail=1
cat <<\EOF > exp || fail=1 cat <<\EOF > exp || fail=1
error: vcpupin: vCPU index out of range. error: invalid argument: requested vcpu is higher than allocated vcpus
EOF EOF
compare exp out || fail=1 compare exp out || fail=1
......
...@@ -6450,20 +6450,17 @@ vshParseCPUList(vshControl *ctl, const char *cpulist, ...@@ -6450,20 +6450,17 @@ vshParseCPUList(vshControl *ctl, const char *cpulist,
static bool static bool
cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
{ {
virDomainInfo info;
virDomainPtr dom; virDomainPtr dom;
unsigned int vcpu = 0; unsigned int vcpu = 0;
const char *cpulist = NULL; const char *cpulist = NULL;
bool ret = false; bool ret = false;
unsigned char *cpumap = NULL; unsigned char *cpumap = NULL;
unsigned char *cpumaps = NULL;
size_t cpumaplen; size_t cpumaplen;
int maxcpu, ncpus; int maxcpu, ncpus;
size_t i; size_t i;
bool config = vshCommandOptBool(cmd, "config"); bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live"); bool live = vshCommandOptBool(cmd, "live");
bool current = vshCommandOptBool(cmd, "current"); bool current = vshCommandOptBool(cmd, "current");
bool query = false; /* Query mode if no cpulist */
int got_vcpu; int got_vcpu;
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT; unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
...@@ -6481,48 +6478,47 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) ...@@ -6481,48 +6478,47 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0) if (vshCommandOptStringReq(ctl, cmd, "cpulist", &cpulist) < 0)
return false; return false;
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL))) if (!cpulist)
return false; VSH_EXCLUSIVE_OPTIONS_VAR(live, config);
query = !cpulist;
if ((got_vcpu = vshCommandOptUInt(cmd, "vcpu", &vcpu)) < 0) { if ((got_vcpu = vshCommandOptUInt(cmd, "vcpu", &vcpu)) < 0) {
vshError(ctl, "%s", _("vcpupin: Invalid vCPU number.")); vshError(ctl, "%s", _("vcpupin: Invalid vCPU number."));
goto cleanup; return false;
} }
/* In pin mode, "vcpu" is necessary */ /* In pin mode, "vcpu" is necessary */
if (!query && got_vcpu == 0) { if (cpulist && got_vcpu == 0) {
vshError(ctl, "%s", _("vcpupin: Missing vCPU number in pin mode.")); vshError(ctl, "%s", _("vcpupin: Missing vCPU number in pin mode."));
goto cleanup; return false;
}
if (virDomainGetInfo(dom, &info) != 0) {
vshError(ctl, "%s", _("vcpupin: failed to get domain information."));
goto cleanup;
}
if (vcpu >= info.nrVirtCpu) {
vshError(ctl, "%s", _("vcpupin: vCPU index out of range."));
goto cleanup;
} }
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0) if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
goto cleanup; return false;
cpumaplen = VIR_CPU_MAPLEN(maxcpu); cpumaplen = VIR_CPU_MAPLEN(maxcpu);
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
return false;
/* Query mode: show CPU affinity information then exit.*/ /* Query mode: show CPU affinity information then exit.*/
if (query) { if (!cpulist) {
/* When query mode and neither "live", "config" nor "current" /* When query mode and neither "live", "config" nor "current"
* is specified, set VIR_DOMAIN_AFFECT_CURRENT as flags */ * is specified, set VIR_DOMAIN_AFFECT_CURRENT as flags */
if (flags == -1) if (flags == -1)
flags = VIR_DOMAIN_AFFECT_CURRENT; flags = VIR_DOMAIN_AFFECT_CURRENT;
cpumaps = vshMalloc(ctl, info.nrVirtCpu * cpumaplen); if ((ncpus = vshCPUCountCollect(ctl, dom, flags, true)) < 0) {
if ((ncpus = virDomainGetVcpuPinInfo(dom, info.nrVirtCpu, if (ncpus == -1) {
cpumaps, cpumaplen, flags)) >= 0) { if (flags & VIR_DOMAIN_AFFECT_LIVE)
vshError(ctl, "%s", _("cannot get vcpupin for offline domain"));
else
vshError(ctl, "%s", _("cannot get vcpupin for transient domain"));
}
goto cleanup;
}
cpumap = vshMalloc(ctl, ncpus * cpumaplen);
if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap,
cpumaplen, flags)) >= 0) {
vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU Affinity")); vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU Affinity"));
vshPrintExtra(ctl, "----------------------------------\n"); vshPrintExtra(ctl, "----------------------------------\n");
for (i = 0; i < ncpus; i++) { for (i = 0; i < ncpus; i++) {
...@@ -6530,30 +6526,27 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd) ...@@ -6530,30 +6526,27 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
continue; continue;
vshPrint(ctl, "%4zu: ", i); vshPrint(ctl, "%4zu: ", i);
ret = vshPrintPinInfo(cpumaps, cpumaplen, maxcpu, i); ret = vshPrintPinInfo(cpumap, cpumaplen, maxcpu, i);
vshPrint(ctl, "\n"); vshPrint(ctl, "\n");
if (!ret) if (!ret)
break; break;
} }
} }
VIR_FREE(cpumaps);
goto cleanup;
}
/* Pin mode: pinning specified vcpu to specified physical cpus*/
if (!(cpumap = vshParseCPUList(ctl, cpulist, maxcpu, cpumaplen)))
goto cleanup;
if (flags == -1) {
if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0)
goto cleanup;
} else { } else {
if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0) /* Pin mode: pinning specified vcpu to specified physical cpus*/
if (!(cpumap = vshParseCPUList(ctl, cpulist, maxcpu, cpumaplen)))
goto cleanup; goto cleanup;
if (flags == -1) {
if (virDomainPinVcpu(dom, vcpu, cpumap, cpumaplen) != 0)
goto cleanup;
} else {
if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0)
goto cleanup;
}
ret = true;
} }
ret = true;
cleanup: cleanup:
VIR_FREE(cpumap); VIR_FREE(cpumap);
virDomainFree(dom); virDomainFree(dom);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册