[PATCH V3] support for hotplug/hotunplug in test hypervisor

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

 



Signed-off-by: Thanos Makatos <thanos.makatos@xxxxxxxxxxx>
---
 src/test/test_driver.c | 59 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index e87d7cfd44..d605649262 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -10035,6 +10035,62 @@ testConnectGetDomainCapabilities(virConnectPtr conn G_GNUC_UNUSED,
     return virDomainCapsFormat(domCaps);
 }
 
+static int
+testVirDomainAttachDeviceFlags(virDomainPtr domain,
+                               const char *xml,
+                               unsigned int flags G_GNUC_UNUSED) {
+
+    int ret = -1;
+    virDomainObj *vm;
+    testDriver *driver;
+    virDomainDeviceDef *devConf;
+
+    if (!(vm = testDomObjFromDomain(domain)))
+        return -1;
+
+    driver = domain->conn->privateData;
+
+    if (!(devConf = virDomainDeviceDefParse(xml, vm->def, driver->xmlopt,
+                                            NULL, 0)))
+        goto out;
+
+    VIR_APPEND_ELEMENT(vm->def->hostdevs, vm->def->nhostdevs,
+                       devConf->data.hostdev);
+    virDomainDeviceDefFree(devConf);
+    ret = 0;
+out:
+    virDomainObjEndAPI(&vm);
+    return ret;
+}
+
+static int
+testVirDomainAttachDevice(virDomainPtr domain, const char *xml)
+{
+    return testVirDomainAttachDeviceFlags(domain, xml, 0);
+}
+
+static int
+testVirDomainDetachDeviceAlias(virDomainPtr domain,
+                               const char *alias,
+                               unsigned int flags G_GNUC_UNUSED)
+{
+    virDomainObj *vm;
+    size_t i;
+    bool found = false;
+
+    if (!(vm = testDomObjFromDomain(domain)))
+        return -1;
+
+    for (i = 0; i < vm->def->nhostdevs && !found; i++) {
+        if (!strcmp(vm->def->hostdevs[i]->info->alias, alias)) {
+            virDomainHostdevDefFree(vm->def->hostdevs[i]);
+            VIR_DELETE_ELEMENT(vm->def->hostdevs, i, vm->def->nhostdevs);
+            found = true;
+        }
+    }
+    virDomainObjEndAPI(&vm);
+    return found ? 0 : -1;
+}
 
 /*
  * Test driver
@@ -10058,6 +10114,9 @@ static virHypervisorDriver testHypervisorDriver = {
     .connectListDomains = testConnectListDomains, /* 0.1.1 */
     .connectNumOfDomains = testConnectNumOfDomains, /* 0.1.1 */
     .connectListAllDomains = testConnectListAllDomains, /* 0.9.13 */
+    .domainAttachDevice = testVirDomainAttachDevice, /* 9.9.0 */
+    .domainAttachDeviceFlags = testVirDomainAttachDeviceFlags, /* 9.9.0 */
+    .domainDetachDeviceAlias = testVirDomainDetachDeviceAlias, /* 9.9.0 */
     .domainCreateXML = testDomainCreateXML, /* 0.1.4 */
     .domainCreateXMLWithFiles = testDomainCreateXMLWithFiles, /* 5.7.0 */
     .domainLookupByID = testDomainLookupByID, /* 0.1.1 */
-- 
2.27.0




[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