mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
libxl: move libxlDomainSetVcpuAffinities to libxl_domain
Move libxlDomainSetVcpuAffinities from libxl_driver to libxl_domain for use by other libxl modules. Signed-off-by: Jim Fehlig <jfehlig@suse.com>
This commit is contained in:
parent
d8d713234e
commit
e394d39ed8
@ -800,3 +800,57 @@ cleanup:
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int
|
||||
libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm)
|
||||
{
|
||||
libxlDomainObjPrivatePtr priv = vm->privateData;
|
||||
virDomainDefPtr def = vm->def;
|
||||
libxl_bitmap map;
|
||||
virBitmapPtr cpumask = NULL;
|
||||
uint8_t *cpumap = NULL;
|
||||
virNodeInfo nodeinfo;
|
||||
size_t cpumaplen;
|
||||
int vcpu;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
if (libxlDriverNodeGetInfo(driver, &nodeinfo) < 0)
|
||||
goto cleanup;
|
||||
|
||||
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
|
||||
|
||||
for (vcpu = 0; vcpu < def->cputune.nvcpupin; ++vcpu) {
|
||||
if (vcpu != def->cputune.vcpupin[vcpu]->vcpuid)
|
||||
continue;
|
||||
|
||||
if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
|
||||
goto cleanup;
|
||||
|
||||
cpumask = def->cputune.vcpupin[vcpu]->cpumask;
|
||||
|
||||
for (i = 0; i < virBitmapSize(cpumask); ++i) {
|
||||
bool bit;
|
||||
ignore_value(virBitmapGetBit(cpumask, i, &bit));
|
||||
if (bit)
|
||||
VIR_USE_CPU(cpumap, i);
|
||||
}
|
||||
|
||||
map.size = cpumaplen;
|
||||
map.map = cpumap;
|
||||
|
||||
if (libxl_set_vcpuaffinity(priv->ctx, def->id, vcpu, &map) != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to pin vcpu '%d' with libxenlight"), vcpu);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
VIR_FREE(cpumap);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(cpumap);
|
||||
return ret;
|
||||
}
|
||||
|
@ -123,4 +123,8 @@ int
|
||||
libxlDomainAutoCoreDump(libxlDriverPrivatePtr driver,
|
||||
virDomainObjPtr vm);
|
||||
|
||||
int
|
||||
libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver,
|
||||
virDomainObjPtr vm);
|
||||
|
||||
#endif /* LIBXL_DOMAIN_H */
|
||||
|
@ -311,60 +311,6 @@ const struct libxl_event_hooks ev_hooks = {
|
||||
.disaster = NULL,
|
||||
};
|
||||
|
||||
static int
|
||||
libxlDomainSetVcpuAffinities(libxlDriverPrivatePtr driver, virDomainObjPtr vm)
|
||||
{
|
||||
libxlDomainObjPrivatePtr priv = vm->privateData;
|
||||
virDomainDefPtr def = vm->def;
|
||||
libxl_bitmap map;
|
||||
virBitmapPtr cpumask = NULL;
|
||||
uint8_t *cpumap = NULL;
|
||||
virNodeInfo nodeinfo;
|
||||
size_t cpumaplen;
|
||||
int vcpu;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
if (libxlDriverNodeGetInfo(driver, &nodeinfo) < 0)
|
||||
goto cleanup;
|
||||
|
||||
cpumaplen = VIR_CPU_MAPLEN(VIR_NODEINFO_MAXCPUS(nodeinfo));
|
||||
|
||||
for (vcpu = 0; vcpu < def->cputune.nvcpupin; ++vcpu) {
|
||||
if (vcpu != def->cputune.vcpupin[vcpu]->vcpuid)
|
||||
continue;
|
||||
|
||||
if (VIR_ALLOC_N(cpumap, cpumaplen) < 0)
|
||||
goto cleanup;
|
||||
|
||||
cpumask = def->cputune.vcpupin[vcpu]->cpumask;
|
||||
|
||||
for (i = 0; i < virBitmapSize(cpumask); ++i) {
|
||||
bool bit;
|
||||
ignore_value(virBitmapGetBit(cpumask, i, &bit));
|
||||
if (bit)
|
||||
VIR_USE_CPU(cpumap, i);
|
||||
}
|
||||
|
||||
map.size = cpumaplen;
|
||||
map.map = cpumap;
|
||||
|
||||
if (libxl_set_vcpuaffinity(priv->ctx, def->id, vcpu, &map) != 0) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Failed to pin vcpu '%d' with libxenlight"), vcpu);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
VIR_FREE(cpumap);
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
VIR_FREE(cpumap);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
libxlFreeMem(libxlDomainObjPrivatePtr priv, libxl_domain_config *d_config)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user