[PATCH 2/2] test_driver: provide basic disk hotunplug support

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

 



Signed-off-by: John Levon <john.levon@xxxxxxxxxxx>
---
 src/test/test_driver.c | 114 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 112 insertions(+), 2 deletions(-)

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index b7e36e8451..789b1a2222 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -10741,6 +10741,85 @@ testDomainDetachPrepNet(virDomainObj *vm,
 }
 
 
+static int
+testFindDisk(virDomainDef *def, const char *dst)
+{
+    size_t i;
+
+    for (i = 0; i < def->ndisks; i++) {
+        if (STREQ(def->disks[i]->dst, dst))
+            return i;
+    }
+
+    return -1;
+}
+
+static int
+testDomainDetachPrepDisk(virDomainObj *vm,
+                         virDomainDiskDef *match,
+                         virDomainDiskDef **detach)
+{
+    virDomainDiskDef *disk;
+    int idx;
+
+    if ((idx = testFindDisk(vm->def, match->dst)) < 0) {
+        virReportError(VIR_ERR_DEVICE_MISSING,
+                       _("disk %1$s not found"), match->dst);
+        return -1;
+    }
+    *detach = disk = vm->def->disks[idx];
+
+    switch ((virDomainDiskDevice) disk->device) {
+    case VIR_DOMAIN_DISK_DEVICE_DISK:
+    case VIR_DOMAIN_DISK_DEVICE_LUN:
+
+        switch (disk->bus) {
+        case VIR_DOMAIN_DISK_BUS_VIRTIO:
+        case VIR_DOMAIN_DISK_BUS_USB:
+        case VIR_DOMAIN_DISK_BUS_SCSI:
+            break;
+
+        case VIR_DOMAIN_DISK_BUS_IDE:
+        case VIR_DOMAIN_DISK_BUS_FDC:
+        case VIR_DOMAIN_DISK_BUS_XEN:
+        case VIR_DOMAIN_DISK_BUS_UML:
+        case VIR_DOMAIN_DISK_BUS_SATA:
+        case VIR_DOMAIN_DISK_BUS_SD:
+            virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                           _("This type of disk cannot be hot unplugged"));
+            return -1;
+
+        case VIR_DOMAIN_DISK_BUS_NONE:
+        case VIR_DOMAIN_DISK_BUS_LAST:
+        default:
+            virReportEnumRangeError(virDomainDiskBus, disk->bus);
+            return -1;
+        }
+        break;
+
+    case VIR_DOMAIN_DISK_DEVICE_CDROM:
+        if (disk->bus == VIR_DOMAIN_DISK_BUS_USB ||
+            disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
+            break;
+        }
+        G_GNUC_FALLTHROUGH;
+
+    case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
+                       _("disk device type '%1$s' cannot be detached"),
+                       virDomainDiskDeviceTypeToString(disk->device));
+        return -1;
+
+    case VIR_DOMAIN_DISK_DEVICE_LAST:
+    default:
+        virReportEnumRangeError(virDomainDiskDevice, disk->device);
+        return -1;
+    }
+
+    return 0;
+}
+
+
 static int
 testDomainRemoveHostDevice(testDriver *driver G_GNUC_UNUSED,
                            virDomainObj *vm,
@@ -10810,6 +10889,28 @@ testDomainRemoveNetDevice(testDriver *driver G_GNUC_UNUSED,
     return 0;
 }
 
+
+static int
+testDomainRemoveDiskDevice(testDriver *driver G_GNUC_UNUSED,
+                           virDomainObj *vm,
+                           virDomainDiskDef *disk)
+{
+    size_t i;
+
+    VIR_DEBUG("Removing disk %s from domain %p %s",
+              disk->info.alias, vm, vm->def->name);
+
+    for (i = 0; i < vm->def->ndisks; i++) {
+        if (vm->def->disks[i] == disk) {
+            virDomainDiskRemove(vm->def, i);
+            break;
+        }
+    }
+
+    virDomainDiskDefFree(disk);
+    return 0;
+}
+
 static int
 testDomainRemoveDevice(testDriver *driver,
                        virDomainObj *vm,
@@ -10835,8 +10936,11 @@ testDomainRemoveDevice(testDriver *driver,
         if (testDomainRemoveHostDevice(driver, vm, dev->data.hostdev) < 0)
             return -1;
         break;
-    case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_DISK:
+        if (testDomainRemoveDiskDevice(driver, vm, dev->data.disk) < 0)
+            return -1;
+        break;
+    case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_LEASE:
     case VIR_DOMAIN_DEVICE_FS:
     case VIR_DOMAIN_DEVICE_INPUT:
@@ -10900,8 +11004,14 @@ testDomainDetachDeviceLive(testDriver *driver,
         }
         break;
 
-    case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_DISK:
+        if (testDomainDetachPrepDisk(vm, match->data.disk,
+                                     &detach.data.disk) < 0) {
+            return -1;
+        }
+        break;
+
+    case VIR_DOMAIN_DEVICE_NONE:
     case VIR_DOMAIN_DEVICE_LEASE:
     case VIR_DOMAIN_DEVICE_FS:
     case VIR_DOMAIN_DEVICE_INPUT:
-- 
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