mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-10 14:57:42 +00:00
libxl: implement virDomainPinVcpuFlags
And use it to implement libxlDomainPinVcpu(), similarly to what happens in the QEMU driver. This way, it is possible to both query and change the vcpu affinity of a persistent but not running domain. In face, before this patch, we have: # virsh list --all Id Name State ---------------------------------------------------- 5 debian_32 running - fedora20_64 shut off # virsh vcpupin fedora20_64 0 2-4 --current error: this function is not supported by the connection driver: virDomainPinVcpuFlags After (same situation as above): # virsh vcpupin fedora20_64 0 2-4 --current # virsh vcpupin fedora20_64 0 VCPU: CPU Affinity ---------------------------------- 0: 2-4 Signed-off-by: Dario Faggioli <dario.faggioli@citrix.com> Cc: Jim Fehlig <jfehlig@suse.com> Cc: Ian Jackson <Ian.Jackson@eu.citrix.com>
This commit is contained in:
parent
2682d0d522
commit
520c3fbd1b
@ -2358,45 +2358,62 @@ cleanup:
|
||||
}
|
||||
|
||||
static int
|
||||
libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
|
||||
int maplen)
|
||||
libxlDomainPinVcpuFlags(virDomainPtr dom, unsigned int vcpu,
|
||||
unsigned char *cpumap, int maplen,
|
||||
unsigned int flags)
|
||||
{
|
||||
libxlDriverPrivatePtr driver = dom->conn->privateData;
|
||||
libxlDriverConfigPtr cfg = libxlDriverConfigGet(driver);
|
||||
libxlDomainObjPrivatePtr priv;
|
||||
virDomainDefPtr targetDef = NULL;
|
||||
virDomainObjPtr vm;
|
||||
int ret = -1;
|
||||
libxl_bitmap map;
|
||||
|
||||
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
|
||||
VIR_DOMAIN_AFFECT_CONFIG, -1);
|
||||
|
||||
if (!(vm = libxlDomObjFromDomain(dom)))
|
||||
goto cleanup;
|
||||
|
||||
if (virDomainPinVcpuEnsureACL(dom->conn, vm->def) < 0)
|
||||
if (virDomainPinVcpuFlagsEnsureACL(dom->conn, vm->def, flags) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (!virDomainObjIsActive(vm)) {
|
||||
if ((flags & VIR_DOMAIN_AFFECT_LIVE) && !virDomainObjIsActive(vm)) {
|
||||
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
|
||||
_("cannot pin vcpus on an inactive domain"));
|
||||
_("domain is inactive"));
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
priv = vm->privateData;
|
||||
|
||||
map.size = maplen;
|
||||
map.map = cpumap;
|
||||
if (libxl_set_vcpuaffinity(priv->ctx, dom->id, vcpu, &map) != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to pin vcpu '%d' with libxenlight"), vcpu);
|
||||
if (virDomainLiveConfigHelperMethod(cfg->caps, driver->xmlopt, vm,
|
||||
&flags, &targetDef) < 0)
|
||||
goto cleanup;
|
||||
|
||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||
targetDef = vm->def;
|
||||
}
|
||||
|
||||
if (!vm->def->cputune.vcpupin) {
|
||||
if (VIR_ALLOC(vm->def->cputune.vcpupin) < 0)
|
||||
/* Make sure coverity knows targetDef is valid at this point. */
|
||||
sa_assert(targetDef);
|
||||
|
||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||
libxl_bitmap map = { .size = maplen, .map = cpumap };
|
||||
libxlDomainObjPrivatePtr priv;
|
||||
|
||||
priv = vm->privateData;
|
||||
if (libxl_set_vcpuaffinity(priv->ctx, dom->id, vcpu, &map) != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to pin vcpu '%d' with libxenlight"),
|
||||
vcpu);
|
||||
goto cleanup;
|
||||
vm->def->cputune.nvcpupin = 0;
|
||||
}
|
||||
}
|
||||
if (virDomainVcpuPinAdd(&vm->def->cputune.vcpupin,
|
||||
&vm->def->cputune.nvcpupin,
|
||||
|
||||
if (!targetDef->cputune.vcpupin) {
|
||||
if (VIR_ALLOC(targetDef->cputune.vcpupin) < 0)
|
||||
goto cleanup;
|
||||
targetDef->cputune.nvcpupin = 0;
|
||||
}
|
||||
if (virDomainVcpuPinAdd(&targetDef->cputune.vcpupin,
|
||||
&targetDef->cputune.nvcpupin,
|
||||
cpumap,
|
||||
maplen,
|
||||
vcpu) < 0) {
|
||||
@ -2405,11 +2422,14 @@ libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
if (virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm) < 0)
|
||||
goto cleanup;
|
||||
|
||||
ret = 0;
|
||||
|
||||
if (flags & VIR_DOMAIN_AFFECT_LIVE) {
|
||||
ret = virDomainSaveStatus(driver->xmlopt, cfg->stateDir, vm);
|
||||
} else if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
|
||||
ret = virDomainSaveConfig(cfg->configDir, targetDef);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
if (vm)
|
||||
virObjectUnlock(vm);
|
||||
@ -2417,6 +2437,14 @@ cleanup:
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
libxlDomainPinVcpu(virDomainPtr dom, unsigned int vcpu, unsigned char *cpumap,
|
||||
int maplen)
|
||||
{
|
||||
return libxlDomainPinVcpuFlags(dom, vcpu, cpumap, maplen,
|
||||
VIR_DOMAIN_AFFECT_LIVE);
|
||||
}
|
||||
|
||||
static int
|
||||
libxlDomainGetVcpuPinInfo(virDomainPtr dom, int ncpumaps,
|
||||
unsigned char *cpumaps, int maplen,
|
||||
@ -4320,6 +4348,7 @@ static virDriver libxlDriver = {
|
||||
.domainSetVcpusFlags = libxlDomainSetVcpusFlags, /* 0.9.0 */
|
||||
.domainGetVcpusFlags = libxlDomainGetVcpusFlags, /* 0.9.0 */
|
||||
.domainPinVcpu = libxlDomainPinVcpu, /* 0.9.0 */
|
||||
.domainPinVcpuFlags = libxlDomainPinVcpuFlags, /* 1.2.1 */
|
||||
.domainGetVcpus = libxlDomainGetVcpus, /* 0.9.0 */
|
||||
.domainGetVcpuPinInfo = libxlDomainGetVcpuPinInfo, /* 1.2.1 */
|
||||
.domainGetXMLDesc = libxlDomainGetXMLDesc, /* 0.9.0 */
|
||||
|
Loading…
Reference in New Issue
Block a user