[libvirt] [PATCH 0/4] test_driver: implement the remaining VCPUs-related APIs

Ilias Stamatis (4): test_driver: make testDomainGetVcpus report all vcpus test_driver: implement virDomainGetGuestVcpus test_driver: implement virDomainSetVcpu test_driver: implement virDomainSetGuestVcpus src/test/test_driver.c | 167 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 161 insertions(+), 6 deletions(-) -- 2.22.0

The current implementation of testDomainGetVcpus is erroneous. When offline vcpus are encountered in the vm definition, the corresponding fields in the output array are left empty. Additionally some vcpus are not reported at all due to the wrong invariant checking done in the loop. Make testDomainGetVcpus report all vcpus instead of reporting the online ones only. Set the state field in the virVcpuInfo structure appropriately in order to mark offline vcpus. --- src/test/test_driver.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 6f18baa265..a6f239b9f1 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2968,8 +2968,8 @@ static int testDomainGetVcpus(virDomainPtr domain, virBitmapSetAll(allcpumap); /* Clamp to actual number of vcpus */ - if (maxinfo > virDomainDefGetVcpus(privdom->def)) - maxinfo = virDomainDefGetVcpus(privdom->def); + if (maxinfo > virDomainDefGetVcpusMax(def)) + maxinfo = virDomainDefGetVcpusMax(def); memset(info, 0, sizeof(*info) * maxinfo); memset(cpumaps, 0, maxinfo * maplen); @@ -2978,9 +2978,6 @@ static int testDomainGetVcpus(virDomainPtr domain, virDomainVcpuDefPtr vcpu = virDomainDefGetVcpu(def, i); virBitmapPtr bitmap = NULL; - if (!vcpu->online) - continue; - if (vcpu->cpumask) bitmap = vcpu->cpumask; else if (def->cpumask) @@ -2992,7 +2989,7 @@ static int testDomainGetVcpus(virDomainPtr domain, virBitmapToDataBuf(bitmap, VIR_GET_CPUMAP(cpumaps, maplen, i), maplen); info[i].number = i; - info[i].state = VIR_VCPU_RUNNING; + info[i].state = vcpu->online; info[i].cpu = virBitmapLastSetBit(bitmap); /* Fake an increasing cpu time value */ -- 2.22.0

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> --- src/test/test_driver.c | 70 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index a6f239b9f1..99cba7db42 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2820,6 +2820,75 @@ testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags) return ret; } + +static int +testDomainGetGuestVcpus(virDomainPtr dom, + virTypedParameterPtr *params, + unsigned int *nparams, + unsigned int flags) +{ + virDomainObjPtr vm = NULL; + virBitmapPtr vcpus = NULL; + virBitmapPtr online = NULL; + virTypedParameterPtr par = NULL; + char *tmp = NULL; + size_t i; + int npar = 0; + int maxpar = 0; + int ret = -1; + + virCheckFlags(0, ret); + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjCheckActive(vm) < 0) + goto cleanup; + + if (!(vcpus = virBitmapNew(vm->def->maxvcpus))) + goto cleanup; + + if (!(online = virBitmapNew(vm->def->maxvcpus))) + goto cleanup; + + for (i = 0; i < vm->def->maxvcpus; i++) { + if (virBitmapSetBit(vcpus, i) < 0) + goto cleanup; + + if (vm->def->vcpus[i]->online && virBitmapSetBit(online, i) < 0) + goto cleanup; + } + +#define ADD_BITMAP(map, name) \ + if (!(tmp = virBitmapFormat(map))) \ + goto cleanup; \ + if (virTypedParamsAddString(&par, &npar, &maxpar, name, tmp) < 0) \ + goto cleanup; \ + VIR_FREE(tmp) + + ADD_BITMAP(vcpus, "vcpus"); + ADD_BITMAP(online, "online"); + + if (virBitmapClearBit(online, 0) < 0) + goto cleanup; + ADD_BITMAP(online, "offlinable"); +#undef ADD_BITMAP + + *params = par; + *nparams = npar; + par = NULL; + + ret = 0; + cleanup: + VIR_FREE(tmp); + virBitmapFree(vcpus); + virBitmapFree(online); + virDomainObjEndAPI(&vm); + virTypedParamsFree(par, npar); + return ret; +} + + static int testDomainGetMaxVcpus(virDomainPtr domain) { @@ -8964,6 +9033,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainSetVcpus = testDomainSetVcpus, /* 0.1.4 */ .domainSetVcpusFlags = testDomainSetVcpusFlags, /* 0.8.5 */ .domainGetVcpusFlags = testDomainGetVcpusFlags, /* 0.8.5 */ + .domainGetGuestVcpus = testDomainGetGuestVcpus, /* 5.7.0 */ .domainPinVcpu = testDomainPinVcpu, /* 0.7.3 */ .domainPinVcpuFlags = testDomainPinVcpuFlags, /* 5.6.0 */ .domainGetVcpus = testDomainGetVcpus, /* 0.7.3 */ -- 2.22.0

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> --- src/test/test_driver.c | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 99cba7db42..d6f1adf6e9 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -2995,6 +2995,81 @@ testDomainSetVcpus(virDomainPtr domain, unsigned int nrCpus) return testDomainSetVcpusFlags(domain, nrCpus, VIR_DOMAIN_AFFECT_LIVE); } + +static int +testDomainSetVcpu(virDomainPtr dom, + const char *cpumap, + int state, + unsigned int flags) +{ + virDomainObjPtr vm = NULL; + virDomainDefPtr def = NULL; + virDomainDefPtr persistentDef = NULL; + virBitmapPtr map = NULL; + ssize_t lastvcpu; + size_t i; + int ret = -1; + + virCheckFlags(VIR_DOMAIN_AFFECT_LIVE | + VIR_DOMAIN_AFFECT_CONFIG, -1); + + if (state != 0 && state != 1) { + virReportInvalidArg(state, "%s", _("unsupported state value")); + return -1; + } + + if (virBitmapParse(cpumap, &map, 32) < 0) + goto cleanup; + + if ((lastvcpu = virBitmapLastSetBit(map)) < 0) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("no vcpus selected for modification")); + goto cleanup; + } + + if (!(vm = testDomObjFromDomain(dom))) + goto cleanup; + + if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0) + goto cleanup; + + if (persistentDef) { + if (lastvcpu >= virDomainDefGetVcpusMax(persistentDef)) { + virReportError(VIR_ERR_INVALID_ARG, + _("vcpu %zd is not present in persistent config"), + lastvcpu); + goto cleanup; + } + } + + if (def) { + if (lastvcpu >= virDomainDefGetVcpusMax(def)) { + virReportError(VIR_ERR_INVALID_ARG, + _("vcpu %zd is not present in live config"), + lastvcpu); + goto cleanup; + } + } + + if (virBitmapIsBitSet(map, 0)) { + virReportError(VIR_ERR_INVALID_ARG, "%s", + _("vCPU '0' can't be modified")); + goto cleanup; + } + + for (i = 1; i < vm->def->maxvcpus - 1; i++) { + if (virBitmapIsBitSet(map, i)) + vm->def->vcpus[i]->online = state; + } + + ret = 0; + cleanup: + virBitmapFree(map); + virDomainObjEndAPI(&vm); + return ret; +} + + static int testDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo, @@ -9032,6 +9107,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetEmulatorPinInfo = testDomainGetEmulatorPinInfo, /* 5.6.0 */ .domainSetVcpus = testDomainSetVcpus, /* 0.1.4 */ .domainSetVcpusFlags = testDomainSetVcpusFlags, /* 0.8.5 */ + .domainSetVcpu = testDomainSetVcpu, /* 5.7.0 */ .domainGetVcpusFlags = testDomainGetVcpusFlags, /* 0.8.5 */ .domainGetGuestVcpus = testDomainGetGuestVcpus, /* 5.7.0 */ .domainPinVcpu = testDomainPinVcpu, /* 0.7.3 */ -- 2.22.0

Signed-off-by: Ilias Stamatis <stamatis.iliass@gmail.com> --- src/test/test_driver.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index d6f1adf6e9..6698fb7cf6 100755 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -3070,6 +3070,17 @@ testDomainSetVcpu(virDomainPtr dom, } +static int +testDomainSetGuestVcpus(virDomainPtr dom, + const char *cpumap, + int state, + unsigned int flags) +{ + virCheckFlags(0, -1); + return testDomainSetVcpu(dom, cpumap, state, VIR_DOMAIN_AFFECT_LIVE); +} + + static int testDomainGetVcpus(virDomainPtr domain, virVcpuInfoPtr info, int maxinfo, @@ -9108,6 +9119,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainSetVcpus = testDomainSetVcpus, /* 0.1.4 */ .domainSetVcpusFlags = testDomainSetVcpusFlags, /* 0.8.5 */ .domainSetVcpu = testDomainSetVcpu, /* 5.7.0 */ + .domainSetGuestVcpus = testDomainSetGuestVcpus, /* 5.7.0 */ .domainGetVcpusFlags = testDomainGetVcpusFlags, /* 0.8.5 */ .domainGetGuestVcpus = testDomainGetGuestVcpus, /* 5.7.0 */ .domainPinVcpu = testDomainPinVcpu, /* 0.7.3 */ -- 2.22.0
participants (1)
-
Ilias Stamatis