mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 04:25:18 +00:00
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=1160559 Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
parent
af20423264
commit
81dd81e475
@ -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,
|
|||||||
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)
|
|||||||
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,17 +6526,13 @@ 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
VIR_FREE(cpumaps);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Pin mode: pinning specified vcpu to specified physical cpus*/
|
/* Pin mode: pinning specified vcpu to specified physical cpus*/
|
||||||
if (!(cpumap = vshParseCPUList(ctl, cpulist, maxcpu, cpumaplen)))
|
if (!(cpumap = vshParseCPUList(ctl, cpulist, maxcpu, cpumaplen)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -6552,8 +6544,9 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0)
|
if (virDomainPinVcpuFlags(dom, vcpu, cpumap, cpumaplen, flags) != 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = true;
|
ret = true;
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(cpumap);
|
VIR_FREE(cpumap);
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user