[PATCH v4 6/8] test_driver: Implement virDomainDetachDeviceFlags

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Introduce testDomainChgDevice for further development (just like what we
did for IOThread). And introduce testDomainDetachDeviceLiveAndConfig for
detaching devices.

Also as we implement testDomainChgDevice for both DetachDeviceFlags and
DetachDeviceAlias, we could easily implement virDomainDetachDeviceAlias
and virDomainDetachDevice.

Signed-off-by: Luke Yue <lukedyue@xxxxxxxxx>
---
 src/test/test_driver.c | 149 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 149 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 21caa83be7..6cd1e75771 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -10022,6 +10022,152 @@ testConnectGetAllDomainStats(virConnectPtr conn,
     return ret;
 }
 
+
+static int
+testDomainDetachDeviceLiveAndConfig(virDomainDef *vmdef,
+                                    virDomainDeviceDef *dev,
+                                    unsigned int flags,
+                                    unsigned int parse_flags,
+                                    virDomainXMLOption *xmlopt)
+{
+    /* Though the function called virDomainDetachDeviceConfig, for
+    test driver, it could be for both live and config */
+    return virDomainDetachDeviceConfig(vmdef, dev, NULL, flags,
+                                       parse_flags, xmlopt);
+}
+
+static int
+testDomainDoChgDevice(testDriver *driver,
+                      virDomainDeviceAction action,
+                      const char *xml,
+                      const char *alias,
+                      virDomainDef *def,
+                      unsigned int flags)
+{
+    virDomainDeviceDef *dev = NULL;
+    unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
+    int ret = -1;
+
+    if (action == VIR_DOMAIN_DEVICE_ACTION_DETACH)
+        parse_flags |= VIR_DOMAIN_DEF_PARSE_SKIP_VALIDATE;
+
+    if (xml) {
+        if (!(dev = virDomainDeviceDefParse(xml, def, driver->xmlopt,
+                                            driver->caps, parse_flags)))
+            goto cleanup;
+    } else if (alias) {
+        dev = g_new0(virDomainDeviceDef, 1);
+        if (virDomainDefFindDevice(def, alias, dev, true) < 0)
+            goto cleanup;
+    }
+
+    if (dev == NULL)
+        goto cleanup;
+
+    switch (action) {
+    case VIR_DOMAIN_DEVICE_ACTION_ATTACH:
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("attaching devices is not supported"));
+        goto cleanup;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ACTION_DETACH:
+        if (testDomainDetachDeviceLiveAndConfig(def, dev, flags, parse_flags,
+                                                driver->xmlopt) < 0)
+            goto cleanup;
+        break;
+
+    case VIR_DOMAIN_DEVICE_ACTION_UPDATE:
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("updating devices is not supported"));
+        goto cleanup;
+        break;
+    }
+
+    ret = 0;
+
+ cleanup:
+    if (xml) {
+        virDomainDeviceDefFree(dev);
+    } else {
+        g_free(dev);
+    }
+    return ret;
+}
+
+static int
+testDomainChgDevice(virDomainPtr dom,
+                    virDomainDeviceAction action,
+                    const char *xml,
+                    const char *alias,
+                    unsigned int flags)
+{
+    testDriver *driver = dom->conn->privateData;
+    virDomainObj *vm = NULL;
+    virDomainDef *def;
+    virDomainDef *persistentDef;
+
+    int ret = -1;
+
+    virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
+                  VIR_DOMAIN_AFFECT_CONFIG, -1);
+
+    if (!(vm = testDomObjFromDomain(dom)))
+        goto cleanup;
+
+    if (virDomainObjUpdateModificationImpact(vm, &flags) < 0)
+        goto cleanup;
+
+    if (virDomainObjGetDefs(vm, flags, &def, &persistentDef) < 0)
+        goto cleanup;
+
+    if (def) {
+        if (testDomainDoChgDevice(driver, action, xml,
+                                  alias, def, flags) < 0) {
+            goto cleanup;
+        }
+    }
+
+    if (persistentDef) {
+        if (testDomainDoChgDevice(driver, action, xml,
+                                  alias, persistentDef, flags) < 0) {
+            goto cleanup;
+        }
+    }
+
+    ret = 0;
+
+ cleanup:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+static int
+testDomainDetachDeviceFlags(virDomainPtr dom,
+                            const char *xml,
+                            unsigned int flags)
+{
+    return testDomainChgDevice(dom, VIR_DOMAIN_DEVICE_ACTION_DETACH,
+                               xml, NULL, flags);
+}
+
+static int
+testDomainDetachDeviceAlias(virDomainPtr dom,
+                            const char *alias,
+                            unsigned int flags)
+{
+    return testDomainChgDevice(dom, VIR_DOMAIN_DEVICE_ACTION_DETACH,
+                               NULL, alias, flags);
+}
+
+static int
+testDomainDetachDevice(virDomainPtr dom,
+                       const char *xml)
+{
+    return testDomainDetachDeviceFlags(dom, xml,
+                                       VIR_DOMAIN_AFFECT_LIVE);
+}
+
 /*
  * Test driver
  */
@@ -10119,6 +10265,9 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainFSFreeze = testDomainFSFreeze, /* 5.7.0 */
     .domainFSThaw = testDomainFSThaw, /* 5.7.0 */
     .domainFSTrim = testDomainFSTrim, /* 5.7.0 */
+    .domainDetachDevice = testDomainDetachDevice, /* 8.0.0 */
+    .domainDetachDeviceAlias = testDomainDetachDeviceAlias, /* 8.0.0 */
+    .domainDetachDeviceFlags = testDomainDetachDeviceFlags, /* 8.0.0 */
     .domainGetAutostart = testDomainGetAutostart, /* 0.3.2 */
     .domainSetAutostart = testDomainSetAutostart, /* 0.3.2 */
     .domainGetDiskErrors = testDomainGetDiskErrors, /* 5.4.0 */
-- 
2.34.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux