mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Rewrite vshParseCPUList
Use virBitmap helpers that were added after this function. Change cpumaplen to int and fill it out by this function.
This commit is contained in:
parent
4c4b821ec3
commit
ff6d2314d8
@ -6335,95 +6335,26 @@ vshPrintPinInfo(unsigned char *cpumap, size_t cpumaplen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *
|
static unsigned char *
|
||||||
vshParseCPUList(vshControl *ctl, const char *cpulist,
|
vshParseCPUList(int *cpumaplen, const char *cpulist, int maxcpu)
|
||||||
int maxcpu, size_t cpumaplen)
|
|
||||||
{
|
{
|
||||||
unsigned char *cpumap = NULL;
|
unsigned char *cpumap = NULL;
|
||||||
const char *cur;
|
virBitmapPtr map = NULL;
|
||||||
bool unuse = false;
|
|
||||||
int cpu, lastcpu;
|
|
||||||
size_t i;
|
|
||||||
|
|
||||||
cpumap = vshCalloc(ctl, cpumaplen, sizeof(*cpumap));
|
if (cpulist[0] == 'r') {
|
||||||
|
if (!(map = virBitmapNew(maxcpu)))
|
||||||
/* Parse cpulist */
|
return NULL;
|
||||||
cur = cpulist;
|
virBitmapSetAll(map);
|
||||||
if (*cur == 'r') {
|
} else {
|
||||||
for (cpu = 0; cpu < maxcpu; cpu++)
|
if (virBitmapParse(cpulist, '\0', &map, maxcpu) < 0)
|
||||||
VIR_USE_CPU(cpumap, cpu);
|
return NULL;
|
||||||
return cpumap;
|
|
||||||
} else if (*cur == 0) {
|
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (*cur != 0) {
|
if (virBitmapToData(map, &cpumap, cpumaplen) < 0)
|
||||||
/* The char '^' denotes exclusive */
|
goto cleanup;
|
||||||
if (*cur == '^') {
|
|
||||||
cur++;
|
|
||||||
unuse = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Parse physical CPU number */
|
|
||||||
if (!c_isdigit(*cur))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if ((cpu = virParseNumber(&cur)) < 0)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (cpu >= maxcpu) {
|
|
||||||
vshError(ctl, _("Physical CPU %d doesn't exist."), cpu);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
virSkipSpaces(&cur);
|
|
||||||
|
|
||||||
if (*cur == ',' || *cur == 0) {
|
|
||||||
if (unuse)
|
|
||||||
VIR_UNUSE_CPU(cpumap, cpu);
|
|
||||||
else
|
|
||||||
VIR_USE_CPU(cpumap, cpu);
|
|
||||||
} else if (*cur == '-') {
|
|
||||||
/* The char '-' denotes range */
|
|
||||||
if (unuse)
|
|
||||||
goto error;
|
|
||||||
cur++;
|
|
||||||
virSkipSpaces(&cur);
|
|
||||||
|
|
||||||
/* Parse the end of range */
|
|
||||||
lastcpu = virParseNumber(&cur);
|
|
||||||
|
|
||||||
if (lastcpu < cpu)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (lastcpu >= maxcpu) {
|
|
||||||
vshError(ctl, _("Physical CPU %d doesn't exist."), lastcpu);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = cpu; i <= lastcpu; i++)
|
|
||||||
VIR_USE_CPU(cpumap, i);
|
|
||||||
|
|
||||||
virSkipSpaces(&cur);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (*cur == ',') {
|
|
||||||
cur++;
|
|
||||||
virSkipSpaces(&cur);
|
|
||||||
unuse = false;
|
|
||||||
} else if (*cur == 0) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return cpumap;
|
|
||||||
|
|
||||||
error:
|
|
||||||
vshError(ctl, "%s", _("cpulist: Invalid format."));
|
|
||||||
cleanup:
|
cleanup:
|
||||||
VIR_FREE(cpumap);
|
virBitmapFree(map);
|
||||||
return NULL;
|
return cpumap;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
@ -6434,7 +6365,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *cpulist = NULL;
|
const char *cpulist = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned char *cpumap = NULL;
|
unsigned char *cpumap = NULL;
|
||||||
size_t cpumaplen;
|
int cpumaplen;
|
||||||
int maxcpu, ncpus;
|
int maxcpu, ncpus;
|
||||||
size_t i;
|
size_t i;
|
||||||
bool config = vshCommandOptBool(cmd, "config");
|
bool config = vshCommandOptBool(cmd, "config");
|
||||||
@ -6473,7 +6404,6 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
|
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
|
||||||
return false;
|
return false;
|
||||||
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
|
||||||
|
|
||||||
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
if (!(dom = vshCommandOptDomain(ctl, cmd, NULL)))
|
||||||
return false;
|
return false;
|
||||||
@ -6495,6 +6425,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
||||||
cpumap = vshMalloc(ctl, ncpus * cpumaplen);
|
cpumap = vshMalloc(ctl, ncpus * cpumaplen);
|
||||||
if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap,
|
if ((ncpus = virDomainGetVcpuPinInfo(dom, ncpus, cpumap,
|
||||||
cpumaplen, flags)) >= 0) {
|
cpumaplen, flags)) >= 0) {
|
||||||
@ -6514,7 +6445,7 @@ cmdVcpuPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* 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(&cpumaplen, cpulist, maxcpu)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (flags == -1) {
|
if (flags == -1) {
|
||||||
@ -6579,7 +6510,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
const char *cpulist = NULL;
|
const char *cpulist = NULL;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned char *cpumap = NULL;
|
unsigned char *cpumap = NULL;
|
||||||
size_t cpumaplen;
|
int cpumaplen;
|
||||||
int maxcpu;
|
int maxcpu;
|
||||||
bool config = vshCommandOptBool(cmd, "config");
|
bool config = vshCommandOptBool(cmd, "config");
|
||||||
bool live = vshCommandOptBool(cmd, "live");
|
bool live = vshCommandOptBool(cmd, "live");
|
||||||
@ -6612,8 +6543,6 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
|
||||||
|
|
||||||
/* Query mode: show CPU affinity information then exit.*/
|
/* Query mode: show CPU affinity information then exit.*/
|
||||||
if (query) {
|
if (query) {
|
||||||
/* When query mode and neither "live", "config" nor "current"
|
/* When query mode and neither "live", "config" nor "current"
|
||||||
@ -6621,6 +6550,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
if (flags == -1)
|
if (flags == -1)
|
||||||
flags = VIR_DOMAIN_AFFECT_CURRENT;
|
flags = VIR_DOMAIN_AFFECT_CURRENT;
|
||||||
|
|
||||||
|
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
||||||
cpumap = vshMalloc(ctl, cpumaplen);
|
cpumap = vshMalloc(ctl, cpumaplen);
|
||||||
if (virDomainGetEmulatorPinInfo(dom, cpumap,
|
if (virDomainGetEmulatorPinInfo(dom, cpumap,
|
||||||
cpumaplen, flags) >= 0) {
|
cpumaplen, flags) >= 0) {
|
||||||
@ -6634,7 +6564,7 @@ cmdEmulatorPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Pin mode: pinning emulator threads to specified physical cpus*/
|
/* Pin mode: pinning emulator threads to specified physical cpus*/
|
||||||
if (!(cpumap = vshParseCPUList(ctl, cpulist, maxcpu, cpumaplen)))
|
if (!(cpumap = vshParseCPUList(&cpumaplen, cpulist, maxcpu)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (flags == -1)
|
if (flags == -1)
|
||||||
@ -6910,7 +6840,7 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
int maxcpu;
|
int maxcpu;
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
unsigned char *cpumap = NULL;
|
unsigned char *cpumap = NULL;
|
||||||
size_t cpumaplen;
|
int cpumaplen;
|
||||||
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;
|
||||||
|
|
||||||
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
VSH_EXCLUSIVE_OPTIONS_VAR(current, live);
|
||||||
@ -6936,9 +6866,8 @@ cmdIOThreadPin(vshControl *ctl, const vshCmd *cmd)
|
|||||||
|
|
||||||
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
|
if ((maxcpu = vshNodeGetCPUCount(ctl->conn)) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
cpumaplen = VIR_CPU_MAPLEN(maxcpu);
|
|
||||||
|
|
||||||
if (!(cpumap = vshParseCPUList(ctl, cpulist, maxcpu, cpumaplen)))
|
if (!(cpumap = vshParseCPUList(&cpumaplen, cpulist, maxcpu)))
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
if (virDomainPinIOThread(dom, iothread_id,
|
if (virDomainPinIOThread(dom, iothread_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user