[PATCH v3 03/12] 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.

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

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index ea474d55ac..6a7eb12f77 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -10051,6 +10051,207 @@ testConnectGetAllDomainStats(virConnectPtr conn,
     return ret;
 }
 
+static int
+testDomainDetachDeviceLiveAndConfig(virDomainDef *vmdef,
+                                    virDomainDeviceDef *dev)
+{
+    virDomainChrDef *chr;
+
+    switch (dev->type) {
+    case VIR_DOMAIN_DEVICE_DISK:
+        if (virDomainDriverDetachDiskDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_NET:
+        if (virDomainDriverDetachNetDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_SOUND:
+        if (virDomainDriverDetachSoundDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_HOSTDEV:
+        if (virDomainDriverDetachHostdevDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_LEASE:
+        if (virDomainDriverDetachLeaseDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_CONTROLLER:
+        if (virDomainDriverDetachControllerDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_FS:
+        if (virDomainDriverDetachFSDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_RNG:
+        if (virDomainDriverDetachRNGDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_MEMORY:
+        if (virDomainDriverDetachMemoryDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_REDIRDEV:
+        if (virDomainDriverDetachRedirdevDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_SHMEM:
+        if (virDomainDriverDetachShmemDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_WATCHDOG:
+        if (virDomainDriverDetachWatchdogDeviceConfig(vmdef) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_INPUT:
+        if (virDomainDriverDetachInputDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_VSOCK:
+        if (virDomainDriverDetachVsockDeviceConfig(vmdef, dev) < 0)
+            return -1;
+
+        break;
+
+    case VIR_DOMAIN_DEVICE_CHR:
+        if (!(chr = virDomainChrRemove(vmdef, dev->data.chr)))
+            return -1;
+
+        virDomainChrDefFree(chr);
+        break;
+
+    case VIR_DOMAIN_DEVICE_VIDEO:
+    case VIR_DOMAIN_DEVICE_GRAPHICS:
+    case VIR_DOMAIN_DEVICE_HUB:
+    case VIR_DOMAIN_DEVICE_SMARTCARD:
+    case VIR_DOMAIN_DEVICE_MEMBALLOON:
+    case VIR_DOMAIN_DEVICE_NVRAM:
+    case VIR_DOMAIN_DEVICE_NONE:
+    case VIR_DOMAIN_DEVICE_TPM:
+    case VIR_DOMAIN_DEVICE_PANIC:
+    case VIR_DOMAIN_DEVICE_IOMMU:
+    case VIR_DOMAIN_DEVICE_AUDIO:
+    case VIR_DOMAIN_DEVICE_LAST:
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+                       _("detach of device '%s' is not supported"),
+                       virDomainDeviceTypeToString(dev->type));
+        return -1;
+    }
+
+    return 0;
+}
+
+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;
+    virDomainDeviceDef *dev = NULL;
+    unsigned int parse_flags = VIR_DOMAIN_DEF_PARSE_INACTIVE;
+    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 (!(def = virDomainObjGetOneDef(vm, flags)))
+        goto cleanup;
+
+    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) < 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);
+    }
+    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);
+}
+
 /*
  * Test driver
  */
@@ -10148,6 +10349,7 @@ static virHypervisorDriver testHypervisorDriver = {
     .domainFSFreeze = testDomainFSFreeze, /* 5.7.0 */
     .domainFSThaw = testDomainFSThaw, /* 5.7.0 */
     .domainFSTrim = testDomainFSTrim, /* 5.7.0 */
+    .domainDetachDeviceFlags = testDomainDetachDeviceFlags, /* 7.10.0 */
     .domainGetAutostart = testDomainGetAutostart, /* 0.3.2 */
     .domainSetAutostart = testDomainSetAutostart, /* 0.3.2 */
     .domainGetDiskErrors = testDomainGetDiskErrors, /* 5.4.0 */
-- 
2.33.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