mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-04 21:47:16 +03:00
vmx: Refactor number parsing in virVMXParseConfig
Parsing of the cpu affinity list was using virParseNumber. Modernize it to get rid of the virParseNumber call. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
c0dae62e02
commit
5857a63519
@ -1500,19 +1500,35 @@ virVMXParseConfig(virVMXContext *ctx,
|
||||
}
|
||||
|
||||
if (sched_cpu_affinity != NULL && STRCASENEQ(sched_cpu_affinity, "all")) {
|
||||
const char *current = sched_cpu_affinity;
|
||||
int number, count = 0;
|
||||
VIR_AUTOSTRINGLIST afflist = NULL;
|
||||
char **aff;
|
||||
size_t naffs;
|
||||
|
||||
def->cpumask = virBitmapNew(VIR_DOMAIN_CPUMASK_LEN);
|
||||
if (!def->cpumask)
|
||||
goto cleanup;
|
||||
|
||||
while (*current != '\0') {
|
||||
if (!(afflist = virStringSplitCount(sched_cpu_affinity, ",", 0, &naffs)))
|
||||
goto cleanup;
|
||||
|
||||
if (naffs < numvcpus) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Expecting VMX entry 'sched.cpu.affinity' to contain "
|
||||
"at least as many values as 'numvcpus' (%lld) but "
|
||||
"found only %zu value(s)"), numvcpus, naffs);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
for (aff = afflist; *aff; aff++) {
|
||||
const char *current = *aff;
|
||||
unsigned int number;
|
||||
int rc;
|
||||
|
||||
virSkipSpaces(¤t);
|
||||
rc = virStrToLong_uip(current, (char **) ¤t, 10, &number);
|
||||
virSkipSpaces(¤t);
|
||||
|
||||
number = virParseNumber(¤t);
|
||||
|
||||
if (number < 0) {
|
||||
if (rc < 0 || *current != '\0') {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Expecting VMX entry 'sched.cpu.affinity' to be "
|
||||
"a comma separated list of unsigned integers but "
|
||||
@ -1528,31 +1544,6 @@ virVMXParseConfig(virVMXContext *ctx,
|
||||
}
|
||||
|
||||
ignore_value(virBitmapSetBit(def->cpumask, number));
|
||||
++count;
|
||||
|
||||
virSkipSpaces(¤t);
|
||||
|
||||
if (*current == ',') {
|
||||
++current;
|
||||
} else if (*current == '\0') {
|
||||
break;
|
||||
} else {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Expecting VMX entry 'sched.cpu.affinity' to be "
|
||||
"a comma separated list of unsigned integers but "
|
||||
"found '%s'"), sched_cpu_affinity);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
virSkipSpaces(¤t);
|
||||
}
|
||||
|
||||
if (count < numvcpus) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Expecting VMX entry 'sched.cpu.affinity' to contain "
|
||||
"at least as many values as 'numvcpus' (%lld) but "
|
||||
"found only %d value(s)"), numvcpus, count);
|
||||
goto cleanup;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user