mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
vcpu: support all flags in test driver
* src/test/test_driver.c (testDomainGetVcpusFlags) (testDomainSetVcpusFlags): Support all flags. (testDomainUpdateVCPUs): Update cpu count here.
This commit is contained in:
parent
bf945ee97b
commit
6c9e6b9564
@ -450,6 +450,7 @@ testDomainUpdateVCPUs(virConnectPtr conn,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
dom->def->vcpus = nvcpus;
|
||||||
ret = 0;
|
ret = 0;
|
||||||
cleanup:
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
@ -2032,12 +2033,51 @@ cleanup:
|
|||||||
static int
|
static int
|
||||||
testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
|
testDomainGetVcpusFlags(virDomainPtr domain, unsigned int flags)
|
||||||
{
|
{
|
||||||
if (flags != (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_MAXIMUM)) {
|
testConnPtr privconn = domain->conn->privateData;
|
||||||
testError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"), flags);
|
virDomainObjPtr vm;
|
||||||
|
virDomainDefPtr def;
|
||||||
|
int ret = -1;
|
||||||
|
|
||||||
|
virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
|
||||||
|
VIR_DOMAIN_VCPU_CONFIG |
|
||||||
|
VIR_DOMAIN_VCPU_MAXIMUM, -1);
|
||||||
|
|
||||||
|
/* Exactly one of LIVE or CONFIG must be set. */
|
||||||
|
if (!(flags & VIR_DOMAIN_VCPU_LIVE) == !(flags & VIR_DOMAIN_VCPU_CONFIG)) {
|
||||||
|
testError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("invalid flag combination: (0x%x)"), flags);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return testGetMaxVCPUs(domain->conn, "test");
|
testDriverLock(privconn);
|
||||||
|
vm = virDomainFindByUUID(&privconn->domains, domain->uuid);
|
||||||
|
testDriverUnlock(privconn);
|
||||||
|
|
||||||
|
if (!vm) {
|
||||||
|
char uuidstr[VIR_UUID_STRING_BUFLEN];
|
||||||
|
virUUIDFormat(domain->uuid, uuidstr);
|
||||||
|
testError(VIR_ERR_NO_DOMAIN,
|
||||||
|
_("no domain with matching uuid '%s'"), uuidstr);
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & VIR_DOMAIN_VCPU_LIVE) {
|
||||||
|
if (!virDomainObjIsActive(vm)) {
|
||||||
|
testError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("domain not active"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
def = vm->def;
|
||||||
|
} else {
|
||||||
|
def = vm->newDef ? vm->newDef : vm->def;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (vm)
|
||||||
|
virDomainObjUnlock(vm);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -2053,21 +2093,30 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
|
|||||||
{
|
{
|
||||||
testConnPtr privconn = domain->conn->privateData;
|
testConnPtr privconn = domain->conn->privateData;
|
||||||
virDomainObjPtr privdom = NULL;
|
virDomainObjPtr privdom = NULL;
|
||||||
|
virDomainDefPtr def;
|
||||||
int ret = -1, maxvcpus;
|
int ret = -1, maxvcpus;
|
||||||
|
|
||||||
if (flags != VIR_DOMAIN_VCPU_LIVE) {
|
virCheckFlags(VIR_DOMAIN_VCPU_LIVE |
|
||||||
testError(VIR_ERR_INVALID_ARG, _("unsupported flags: (0x%x)"), flags);
|
VIR_DOMAIN_VCPU_CONFIG |
|
||||||
|
VIR_DOMAIN_VCPU_MAXIMUM, -1);
|
||||||
|
|
||||||
|
/* At least one of LIVE or CONFIG must be set. MAXIMUM cannot be
|
||||||
|
* mixed with LIVE. */
|
||||||
|
if ((flags & (VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG)) == 0 ||
|
||||||
|
(flags & (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_LIVE)) ==
|
||||||
|
(VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_LIVE)) {
|
||||||
|
testError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("invalid flag combination: (0x%x)"), flags);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
if (!nrCpus || (maxvcpus = testGetMaxVCPUs(domain->conn, NULL)) < nrCpus) {
|
||||||
|
testError(VIR_ERR_INVALID_ARG,
|
||||||
|
_("argument out of range: %d"), nrCpus);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Do this first before locking */
|
|
||||||
maxvcpus = testDomainGetMaxVcpus(domain);
|
|
||||||
if (maxvcpus < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
testDriverLock(privconn);
|
testDriverLock(privconn);
|
||||||
privdom = virDomainFindByName(&privconn->domains,
|
privdom = virDomainFindByUUID(&privconn->domains, domain->uuid);
|
||||||
domain->name);
|
|
||||||
testDriverUnlock(privconn);
|
testDriverUnlock(privconn);
|
||||||
|
|
||||||
if (privdom == NULL) {
|
if (privdom == NULL) {
|
||||||
@ -2075,13 +2124,17 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!virDomainObjIsActive(privdom)) {
|
if (!virDomainObjIsActive(privdom) && (flags & VIR_DOMAIN_VCPU_LIVE)) {
|
||||||
testError(VIR_ERR_OPERATION_INVALID,
|
testError(VIR_ERR_OPERATION_INVALID,
|
||||||
"%s", _("cannot hotplug vcpus for an inactive domain"));
|
"%s", _("cannot hotplug vcpus for an inactive domain"));
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We allow more cpus in guest than host */
|
/* We allow more cpus in guest than host, but not more than the
|
||||||
|
* domain's starting limit. */
|
||||||
|
if ((flags & (VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_LIVE)) ==
|
||||||
|
VIR_DOMAIN_VCPU_LIVE && privdom->def->maxvcpus < maxvcpus)
|
||||||
|
maxvcpus = privdom->def->maxvcpus;
|
||||||
if (nrCpus > maxvcpus) {
|
if (nrCpus > maxvcpus) {
|
||||||
testError(VIR_ERR_INVALID_ARG,
|
testError(VIR_ERR_INVALID_ARG,
|
||||||
"requested cpu amount exceeds maximum (%d > %d)",
|
"requested cpu amount exceeds maximum (%d > %d)",
|
||||||
@ -2089,12 +2142,49 @@ testDomainSetVcpusFlags(virDomainPtr domain, unsigned int nrCpus,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Update VCPU state for the running domain */
|
switch (flags) {
|
||||||
if (testDomainUpdateVCPUs(domain->conn, privdom, nrCpus, 0) < 0)
|
case VIR_DOMAIN_VCPU_MAXIMUM | VIR_DOMAIN_VCPU_CONFIG:
|
||||||
goto cleanup;
|
def = privdom->def;
|
||||||
|
if (virDomainObjIsActive(privdom)) {
|
||||||
|
if (privdom->newDef)
|
||||||
|
def = privdom->newDef;
|
||||||
|
else {
|
||||||
|
testError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("no persistent state"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
def->maxvcpus = nrCpus;
|
||||||
|
if (nrCpus < def->vcpus)
|
||||||
|
def->vcpus = nrCpus;
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
privdom->def->vcpus = nrCpus;
|
case VIR_DOMAIN_VCPU_CONFIG:
|
||||||
ret = 0;
|
def = privdom->def;
|
||||||
|
if (virDomainObjIsActive(privdom)) {
|
||||||
|
if (privdom->newDef)
|
||||||
|
def = privdom->newDef;
|
||||||
|
else {
|
||||||
|
testError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||||
|
_("no persistent state"));
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
def->vcpus = nrCpus;
|
||||||
|
ret = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_VCPU_LIVE:
|
||||||
|
ret = testDomainUpdateVCPUs(domain->conn, privdom, nrCpus, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case VIR_DOMAIN_VCPU_LIVE | VIR_DOMAIN_VCPU_CONFIG:
|
||||||
|
ret = testDomainUpdateVCPUs(domain->conn, privdom, nrCpus, 0);
|
||||||
|
if (ret == 0 && privdom->newDef)
|
||||||
|
privdom->newDef->vcpus = nrCpus;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
if (privdom)
|
if (privdom)
|
||||||
|
Loading…
Reference in New Issue
Block a user