]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
domain_driver.c: Introduce and use virDomainDriverAddIOThreadCheck()
authorLuke Yue <lukedyue@gmail.com>
Wed, 15 Sep 2021 15:30:22 +0000 (23:30 +0800)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 23 Sep 2021 11:41:07 +0000 (13:41 +0200)
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@gmail.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/hypervisor/domain_driver.c
src/hypervisor/domain_driver.h
src/libvirt_private.syms
src/qemu/qemu_driver.c

index 2969d551734a27775cc5e26009285e4ab397d2bc..3eb24010539739bf5915ed3f4cf14cc74ae9ff46 100644 (file)
@@ -512,3 +512,67 @@ virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev,
 
     return virHostdevPCINodeDeviceDetach(hostdevMgr, pci);
 }
+
+/**
+ * virDomainDriverAddIOThreadCheck:
+ * @def: domain definition
+ * @iothread_id: iothread id
+ *
+ * Returns -1 if an IOThread is already using the given iothread id
+ */
+int
+virDomainDriverAddIOThreadCheck(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;
+}
+
+/**
+ * virDomainDriverDelIOThreadCheck:
+ * @def: domain definition
+ * @iothread_id: iothread id
+ *
+ * Returns -1 if there is no IOThread using the given iothread id
+ */
+int
+virDomainDriverDelIOThreadCheck(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;
+}
index 5970eef082908c71274b0c2a3895f4cd62c20fc1..d91d21bc91433a2dd124aefe43c7e83b61ca182f 100644 (file)
@@ -60,3 +60,9 @@ int virDomainDriverNodeDeviceReAttach(virNodeDevicePtr dev,
 int virDomainDriverNodeDeviceDetachFlags(virNodeDevicePtr dev,
                                          virHostdevManager *hostdevMgr,
                                          const char *driverName);
+
+int virDomainDriverAddIOThreadCheck(virDomainDef *def,
+                                    unsigned int iothread_id);
+
+int virDomainDriverDelIOThreadCheck(virDomainDef *def,
+                                    unsigned int iothread_id);
index 5e11eb1b5c9650e8c5e12c9bd972d5558e62f0dd..f27ed353ad66608dae70fbc72bcd8a100ef6db86 100644 (file)
@@ -1537,6 +1537,8 @@ virDomainCgroupSetupMemtune;
 
 
 # hypervisor/domain_driver.h
+virDomainDriverAddIOThreadCheck;
+virDomainDriverDelIOThreadCheck;
 virDomainDriverGenerateMachineName;
 virDomainDriverGenerateRootHash;
 virDomainDriverMergeBlkioDevice;
index cf27bbccf5d4dd1a02f4b328f1875bbff6c3d2c1..dffbbe8991e6fb40e61124cdc520eca893bd06fe 100644 (file)
@@ -5438,58 +5438,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
@@ -5623,7 +5571,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
 
         switch (action) {
         case VIR_DOMAIN_IOTHREAD_ACTION_ADD:
-            if (qemuDomainAddIOThreadCheck(def, iothread.iothread_id) < 0)
+            if (virDomainDriverAddIOThreadCheck(def, iothread.iothread_id) < 0)
                 goto endjob;
 
             if (qemuDomainHotplugAddIOThread(driver, vm, iothread.iothread_id) < 0)
@@ -5632,7 +5580,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
             break;
 
         case VIR_DOMAIN_IOTHREAD_ACTION_DEL:
-            if (qemuDomainDelIOThreadCheck(def, iothread.iothread_id) < 0)
+            if (virDomainDriverDelIOThreadCheck(def, iothread.iothread_id) < 0)
                 goto endjob;
 
             if (qemuDomainHotplugDelIOThread(driver, vm, iothread.iothread_id) < 0)
@@ -5661,7 +5609,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
     if (persistentDef) {
         switch (action) {
         case VIR_DOMAIN_IOTHREAD_ACTION_ADD:
-            if (qemuDomainAddIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
+            if (virDomainDriverAddIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
                 goto endjob;
 
             if (!virDomainIOThreadIDAdd(persistentDef, iothread.iothread_id))
@@ -5670,7 +5618,7 @@ qemuDomainChgIOThread(virQEMUDriver *driver,
             break;
 
         case VIR_DOMAIN_IOTHREAD_ACTION_DEL:
-            if (qemuDomainDelIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
+            if (virDomainDriverDelIOThreadCheck(persistentDef, iothread.iothread_id) < 0)
                 goto endjob;
 
             virDomainIOThreadIDDel(persistentDef, iothread.iothread_id);