The test driver can share the same code with qemu driver when implement
testDomainAddIOThreadCheck and testDomainDelIOThreadCheck, so extract
them for test driver to use.
Signed-off-by: Luke Yue <lukedyue(a)gmail.com>
---
src/conf/domain_conf.c | 66 ++++++++++++++++++++++++++++++++++++++++
src/conf/domain_conf.h | 8 +++++
src/libvirt_private.syms | 2 ++
src/qemu/qemu_driver.c | 60 +++---------------------------------
4 files changed, 80 insertions(+), 56 deletions(-)
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 04c10df0a9..2721e2269e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -31153,3 +31153,69 @@ virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI &&
hostdev->source.subsys.u.pci.backend == VIR_DOMAIN_HOSTDEV_PCI_BACKEND_VFIO;
}
+
+
+/**
+ * virDomainAddIOThreadCheck:
+ * @def: domain definition
+ * @iothread_id: iothread id
+ *
+ * Returns -1 if an IOThread is already using the given iothread id
+ */
+int
+virDomainAddIOThreadCheck(virDomainDef *def,
+ unsigned int iothread_id)
+{
+ if (virDomainIOThreadIDFind(def, iothread_id)) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("an IOThread is already using iothread_id
'%u'"),
+ iothread_id);
+ return -1;
+ }
+
+ return 0;
+}
+
+
+/**
+ * virDomainDelIOThreadCheck:
+ * @def: domain definition
+ * @iothread_id: iothread id
+ *
+ * Returns -1 if there is no IOThread using the given iothread id
+ */
+int
+virDomainDelIOThreadCheck(virDomainDef *def,
+ unsigned int iothread_id)
+{
+ size_t i;
+
+ if (!virDomainIOThreadIDFind(def, iothread_id)) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("cannot find IOThread '%u' in iothreadids
list"),
+ iothread_id);
+ return -1;
+ }
+
+ for (i = 0; i < def->ndisks; i++) {
+ if (def->disks[i]->iothread == iothread_id) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("cannot remove IOThread %u since it "
+ "is being used by disk '%s'"),
+ iothread_id, def->disks[i]->dst);
+ return -1;
+ }
+ }
+
+ for (i = 0; i < def->ncontrollers; i++) {
+ if (def->controllers[i]->iothread == iothread_id) {
+ virReportError(VIR_ERR_INVALID_ARG,
+ _("cannot remove IOThread '%u' since it "
+ "is being used by controller"),
+ iothread_id);
+ return -1;
+ }
+ }
+
+ return 0;
+}
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 4d9d499b16..0d06939e2b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -4140,3 +4140,11 @@ virHostdevIsMdevDevice(const virDomainHostdevDef *hostdev)
bool
virHostdevIsVFIODevice(const virDomainHostdevDef *hostdev)
ATTRIBUTE_NONNULL(1);
+
+int
+virDomainAddIOThreadCheck(virDomainDef *def,
+ unsigned int iothread_id);
+
+int
+virDomainDelIOThreadCheck(virDomainDef *def,
+ unsigned int iothread_id);
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 43e6398ae5..fa0462a133 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -226,6 +226,7 @@ virDiskNameParse;
virDiskNameToBusDeviceIndex;
virDiskNameToIndex;
virDomainActualNetDefFree;
+virDomainAddIOThreadCheck;
virDomainAudioFormatTypeFromString;
virDomainAudioFormatTypeToString;
virDomainAudioIOCommonIsSet;
@@ -349,6 +350,7 @@ virDomainDefSetVcpus;
virDomainDefSetVcpusMax;
virDomainDefVcpuOrderClear;
virDomainDeleteConfig;
+virDomainDelIOThreadCheck;
virDomainDeviceAliasIsUserAlias;
virDomainDeviceDefCopy;
virDomainDeviceDefFree;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 235f575901..334c043b60 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5478,58 +5478,6 @@ qemuDomainHotplugDelIOThread(virQEMUDriver *driver,
}
-static int
-qemuDomainAddIOThreadCheck(virDomainDef *def,
- unsigned int iothread_id)
-{
- if (virDomainIOThreadIDFind(def, iothread_id)) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("an IOThread is already using iothread_id
'%u'"),
- iothread_id);
- return -1;
- }
-
- return 0;
-}
-
-
-static int
-qemuDomainDelIOThreadCheck(virDomainDef *def,
- unsigned int iothread_id)
-{
- size_t i;
-
- if (!virDomainIOThreadIDFind(def, iothread_id)) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("cannot find IOThread '%u' in iothreadids
list"),
- iothread_id);
- return -1;
- }
-
- for (i = 0; i < def->ndisks; i++) {
- if (def->disks[i]->iothread == iothread_id) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("cannot remove IOThread %u since it "
- "is being used by disk '%s'"),
- iothread_id, def->disks[i]->dst);
- return -1;
- }
- }
-
- for (i = 0; i < def->ncontrollers; i++) {
- if (def->controllers[i]->iothread == iothread_id) {
- virReportError(VIR_ERR_INVALID_ARG,
- _("cannot remove IOThread '%u' since it "
- "is being used by controller"),
- iothread_id);
- return -1;
- }
- }
-
- return 0;
-}
-
-
/**
* @params: Pointer to params list
* @nparams: Number of params to be parsed
@@ -5663,7 +5611,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
switch (action) {
case VIR_DOMAIN_IOTHREAD_ACTION_ADD:
- if (qemuDomainAddIOThreadCheck(def, iothread.iothread_id) < 0)
+ if (virDomainAddIOThreadCheck(def, iothread.iothread_id) < 0)
goto endjob;
if (qemuDomainHotplugAddIOThread(driver, vm, iothread.iothread_id) < 0)
@@ -5672,7 +5620,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
break;
case VIR_DOMAIN_IOTHREAD_ACTION_DEL:
- if (qemuDomainDelIOThreadCheck(def, iothread.iothread_id) < 0)
+ if (virDomainDelIOThreadCheck(def, iothread.iothread_id) < 0)
goto endjob;
if (qemuDomainHotplugDelIOThread(driver, vm, iothread.iothread_id) < 0)
@@ -5702,7 +5650,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
if (persistentDef) {
switch (action) {
case VIR_DOMAIN_IOTHREAD_ACTION_ADD:
- if (qemuDomainAddIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
+ if (virDomainAddIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
goto endjob;
if (!virDomainIOThreadIDAdd(persistentDef, iothread.iothread_id))
@@ -5711,7 +5659,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
break;
case VIR_DOMAIN_IOTHREAD_ACTION_DEL:
- if (qemuDomainDelIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
+ if (virDomainDelIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
goto endjob;
virDomainIOThreadIDDel(persistentDef, iothread.iothread_id);
--
2.32.0