The test driver can share the same code with qemu driver when implement
testDomainGetIOThreadsConfig, so extract it for test driver to use.
Signed-off-by: Luke Yue <lukedyue(a)gmail.com>
---
src/conf/domain_conf.c | 60 ++++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 4 +++
src/libvirt_private.syms | 1 +
src/qemu/qemu_driver.c | 53 +----------------------------------
4 files changed, 66 insertions(+), 52 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 2721e2269e..03a0fb55fe 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31219,3 +31219,63 @@ virDomainDelIOThreadCheck(virDomainDef *def,
return 0;
}
+
+
+/**
+ * virDomainGetIOThreadsConfig:
+ * @targetDef: domain definition
+ * @info: information about the IOThread in a domain
+ *
+ * Returns the number of IOThreads in the given domain or -1 in case of error
+ */
+int
+virDomainGetIOThreadsConfig(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;
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 0d06939e2b..7d2f1420ba 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -4148,3 +4148,7 @@ virDomainAddIOThreadCheck(virDomainDef *def,
int
virDomainDelIOThreadCheck(virDomainDef *def,
unsigned int iothread_id);
+
+int
+virDomainGetIOThreadsConfig(virDomainDef *targetDef,
+ virDomainIOThreadInfoPtr **info);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index fa0462a133..06b875e045 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -423,6 +423,7 @@ virDomainFSWrpolicyTypeFromString;
virDomainFSWrpolicyTypeToString;
virDomainGetBlkioParametersAssignFromDef;
virDomainGetFilesystemForTarget;
+virDomainGetIOThreadsConfig;
virDomainGraphicsAuthConnectedTypeFromString;
virDomainGraphicsAuthConnectedTypeToString;
virDomainGraphicsDefFree;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 334c043b60..e7365570d4 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5080,57 +5080,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,
@@ -5157,7 +5106,7 @@ qemuDomainGetIOThreadInfo(virDomainPtr dom,
if (!targetDef)
ret = qemuDomainGetIOThreadsLive(driver, vm, info);
else
- ret = qemuDomainGetIOThreadsConfig(targetDef, info);
+ ret = virDomainGetIOThreadsConfig(targetDef, info);
cleanup:
virDomainObjEndAPI(&vm);
--
2.32.0