mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-20 07:59:00 +00:00
domain_driver.c: Introduce and use virDomainDriverGetIOThreadsConfig()
The test driver can share the same code with qemu driver when implement testDomainGetIOThreadsConfig, so extract it for test driver to use. Also add a new parameter `bitmap_size` to the function, it's used for specifying the bitmap size of the bitmap to generate, it would be helpful for test driver or some special situation. Signed-off-by: Luke Yue <lukedyue@gmail.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
958d0a5099
commit
fac57323fc
@ -576,3 +576,71 @@ virDomainDriverDelIOThreadCheck(virDomainDef *def,
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* virDomainDriverGetIOThreadsConfig:
|
||||
* @targetDef: domain definition
|
||||
* @info: information about the IOThread in a domain
|
||||
* @bitmap_size: generate bitmap with bitmap_size, 0 for getting the size
|
||||
* from host
|
||||
*
|
||||
* Returns the number of IOThreads in the given domain or -1 in case of error
|
||||
*/
|
||||
int
|
||||
virDomainDriverGetIOThreadsConfig(virDomainDef *targetDef,
|
||||
virDomainIOThreadInfoPtr **info,
|
||||
unsigned int bitmap_size)
|
||||
{
|
||||
virDomainIOThreadInfoPtr *info_ret = NULL;
|
||||
virBitmap *bitmap = NULL;
|
||||
virBitmap *cpumask = NULL;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
if (targetDef->niothreadids == 0)
|
||||
return 0;
|
||||
|
||||
info_ret = g_new0(virDomainIOThreadInfoPtr, targetDef->niothreadids);
|
||||
|
||||
for (i = 0; i < targetDef->niothreadids; i++) {
|
||||
info_ret[i] = g_new0(virDomainIOThreadInfo, 1);
|
||||
|
||||
/* IOThread ID's are taken from the iothreadids list */
|
||||
info_ret[i]->iothread_id = targetDef->iothreadids[i]->iothread_id;
|
||||
|
||||
cpumask = targetDef->iothreadids[i]->cpumask;
|
||||
if (!cpumask) {
|
||||
if (targetDef->cpumask) {
|
||||
cpumask = targetDef->cpumask;
|
||||
} else {
|
||||
if (bitmap_size) {
|
||||
if (!(bitmap = virBitmapNew(bitmap_size)))
|
||||
goto cleanup;
|
||||
virBitmapSetAll(bitmap);
|
||||
} else {
|
||||
if (!(bitmap = virHostCPUGetAvailableCPUsBitmap()))
|
||||
goto cleanup;
|
||||
}
|
||||
cpumask = bitmap;
|
||||
}
|
||||
}
|
||||
if (virBitmapToData(cpumask, &info_ret[i]->cpumap,
|
||||
&info_ret[i]->cpumaplen) < 0)
|
||||
goto cleanup;
|
||||
virBitmapFree(bitmap);
|
||||
bitmap = NULL;
|
||||
}
|
||||
|
||||
*info = g_steal_pointer(&info_ret);
|
||||
ret = targetDef->niothreadids;
|
||||
|
||||
cleanup:
|
||||
if (info_ret) {
|
||||
for (i = 0; i < targetDef->niothreadids; i++)
|
||||
virDomainIOThreadInfoFree(info_ret[i]);
|
||||
VIR_FREE(info_ret);
|
||||
}
|
||||
virBitmapFree(bitmap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -66,3 +66,7 @@ int virDomainDriverAddIOThreadCheck(virDomainDef *def,
|
||||
|
||||
int virDomainDriverDelIOThreadCheck(virDomainDef *def,
|
||||
unsigned int iothread_id);
|
||||
|
||||
int virDomainDriverGetIOThreadsConfig(virDomainDef *targetDef,
|
||||
virDomainIOThreadInfoPtr **info,
|
||||
unsigned int bitmap_size);
|
||||
|
@ -1541,6 +1541,7 @@ virDomainDriverAddIOThreadCheck;
|
||||
virDomainDriverDelIOThreadCheck;
|
||||
virDomainDriverGenerateMachineName;
|
||||
virDomainDriverGenerateRootHash;
|
||||
virDomainDriverGetIOThreadsConfig;
|
||||
virDomainDriverMergeBlkioDevice;
|
||||
virDomainDriverNodeDeviceDetachFlags;
|
||||
virDomainDriverNodeDeviceGetPCIInfo;
|
||||
|
@ -5025,57 +5025,6 @@ qemuDomainGetIOThreadsLive(virQEMUDriver *driver,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
qemuDomainGetIOThreadsConfig(virDomainDef *targetDef,
|
||||
virDomainIOThreadInfoPtr **info)
|
||||
{
|
||||
virDomainIOThreadInfoPtr *info_ret = NULL;
|
||||
virBitmap *bitmap = NULL;
|
||||
virBitmap *cpumask = NULL;
|
||||
size_t i;
|
||||
int ret = -1;
|
||||
|
||||
if (targetDef->niothreadids == 0)
|
||||
return 0;
|
||||
|
||||
info_ret = g_new0(virDomainIOThreadInfoPtr, targetDef->niothreadids);
|
||||
|
||||
for (i = 0; i < targetDef->niothreadids; i++) {
|
||||
info_ret[i] = g_new0(virDomainIOThreadInfo, 1);
|
||||
|
||||
/* IOThread ID's are taken from the iothreadids list */
|
||||
info_ret[i]->iothread_id = targetDef->iothreadids[i]->iothread_id;
|
||||
|
||||
cpumask = targetDef->iothreadids[i]->cpumask;
|
||||
if (!cpumask) {
|
||||
if (targetDef->cpumask) {
|
||||
cpumask = targetDef->cpumask;
|
||||
} else {
|
||||
if (!(bitmap = virHostCPUGetAvailableCPUsBitmap()))
|
||||
goto cleanup;
|
||||
cpumask = bitmap;
|
||||
}
|
||||
}
|
||||
if (virBitmapToData(cpumask, &info_ret[i]->cpumap,
|
||||
&info_ret[i]->cpumaplen) < 0)
|
||||
goto cleanup;
|
||||
virBitmapFree(bitmap);
|
||||
bitmap = NULL;
|
||||
}
|
||||
|
||||
*info = g_steal_pointer(&info_ret);
|
||||
ret = targetDef->niothreadids;
|
||||
|
||||
cleanup:
|
||||
if (info_ret) {
|
||||
for (i = 0; i < targetDef->niothreadids; i++)
|
||||
virDomainIOThreadInfoFree(info_ret[i]);
|
||||
VIR_FREE(info_ret);
|
||||
}
|
||||
virBitmapFree(bitmap);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int
|
||||
qemuDomainGetIOThreadInfo(virDomainPtr dom,
|
||||
@ -5102,7 +5051,7 @@ qemuDomainGetIOThreadInfo(virDomainPtr dom,
|
||||
if (!targetDef)
|
||||
ret = qemuDomainGetIOThreadsLive(driver, vm, info);
|
||||
else
|
||||
ret = qemuDomainGetIOThreadsConfig(targetDef, info);
|
||||
ret = virDomainDriverGetIOThreadsConfig(targetDef, info, 0);
|
||||
|
||||
cleanup:
|
||||
virDomainObjEndAPI(&vm);
|
||||
|
Loading…
x
Reference in New Issue
Block a user