mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-06 00:43:48 +00:00
virsh: cpupin: Extract getter code into a separate function
This commit is contained in:
parent
783584b52b
commit
773f3bd3cc
@ -6374,6 +6374,68 @@ virshPrintPinInfo(vshControl *ctl,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static bool
|
||||||
|
virshVcpuPinQuery(vshControl *ctl,
|
||||||
|
virDomainPtr dom,
|
||||||
|
unsigned int vcpu,
|
||||||
|
bool got_vcpu,
|
||||||
|
int maxcpu,
|
||||||
|
unsigned int flags)
|
||||||
|
{
|
||||||
|
unsigned char *cpumap = NULL;
|
||||||
|
int cpumaplen;
|
||||||
|
size_t i;
|
||||||
|
int ncpus;
|
||||||
|
bool ret = false;
|
||||||
|
|
||||||
|
if ((ncpus = virshCPUCountCollect(ctl, dom, flags, true)) < 0) {
|
||||||
|
if (ncpus == -1) {
|
||||||
|
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"));
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (got_vcpu && vcpu >= ncpus) {
|
||||||
|
if (flags & VIR_DOMAIN_AFFECT_LIVE ||
|
||||||
|
(!(flags & VIR_DOMAIN_AFFECT_CONFIG) &&
|
||||||
|
virDomainIsActive(dom) == 1))
|
||||||
|
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);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
||||||
|
cpumap = vshMalloc(ctl, ncpus * cpumaplen);
|
||||||
|
if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap,
|
||||||
|
cpumaplen, flags)) >= 0) {
|
||||||
|
vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU Affinity"));
|
||||||
|
vshPrintExtra(ctl, "----------------------------------\n");
|
||||||
|
for (i = 0; i < ncpus; i++) {
|
||||||
|
if (got_vcpu && i != vcpu)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
vshPrint(ctl, "%4zu: ", i);
|
||||||
|
ret = virshPrintPinInfo(ctl, VIR_GET_CPUMAP(cpumap, cpumaplen, i),
|
||||||
|
cpumaplen);
|
||||||
|
vshPrint(ctl, "\n");
|
||||||
|
if (!ret)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static unsigned char *
|
static unsigned char *
|
||||||
virshParseCPUList(vshControl *ctl, int *cpumaplen,
|
virshParseCPUList(vshControl *ctl, int *cpumaplen,
|
||||||
const char *cpulist, int maxcpu)
|
const char *cpulist, int maxcpu)
|
||||||
@ -6416,8 +6478,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned char *cpumap = NULL;
|
unsigned char *cpumap = NULL;
|
||||||
int cpumaplen;
|
int cpumaplen;
|
||||||
int maxcpu, ncpus;
|
int maxcpu;
|
||||||
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");
|
||||||
@ -6456,49 +6517,10 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
/* Query mode: show CPU affinity information then exit.*/
|
/* Query mode: show CPU affinity information then exit.*/
|
||||||
if (!cpulist) {
|
if (!cpulist) {
|
||||||
if ((ncpus = virshCPUCountCollect(ctl, dom, flags, true)) < 0) {
|
ret = virshVcpuPinQuery(ctl, dom, vcpu, got_vcpu, maxcpu, flags);
|
||||||
if (ncpus == -1) {
|
|
||||||
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;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (got_vcpu && vcpu >= ncpus) {
|
|
||||||
if (flags & VIR_DOMAIN_AFFECT_LIVE ||
|
|
||||||
(!(flags & VIR_DOMAIN_AFFECT_CONFIG) &&
|
|
||||||
virDomainIsActive(dom) == 1))
|
|
||||||
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,
|
|
||||||
cpumaplen, flags)) >= 0) {
|
|
||||||
vshPrintExtra(ctl, "%s %s\n", _("VCPU:"), _("CPU Affinity"));
|
|
||||||
vshPrintExtra(ctl, "----------------------------------\n");
|
|
||||||
for (i = 0; i < ncpus; i++) {
|
|
||||||
if (got_vcpu && i != vcpu)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
vshPrint(ctl, "%4zu: ", i);
|
|
||||||
ret = virshPrintPinInfo(ctl, VIR_GET_CPUMAP(cpumap, cpumaplen, i),
|
|
||||||
cpumaplen);
|
|
||||||
vshPrint(ctl, "\n");
|
|
||||||
if (!ret)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
/* Pin mode: pinning specified vcpu to specified physical cpus*/
|
/* Pin mode: pinning specified vcpu to specified physical cpus*/
|
||||||
if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
|
if (!(cpumap = virshParseCPUList(ctl, &cpumaplen, cpulist, maxcpu)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -6512,7 +6534,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
ret = true;
|
ret = true;
|
||||||
}
|
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(cpumap);
|
VIR_FREE(cpumap);
|
||||||
|
Loading…
Reference in New Issue
Block a user