]> xenbits.xensource.com Git - libvirt.git/commitdiff
vbox: Generate disk address element in dumpxml
authorDawid Zamirski <dzamirski@datto.com>
Tue, 7 Nov 2017 18:49:28 +0000 (13:49 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Tue, 7 Nov 2017 20:38:43 +0000 (15:38 -0500)
This patch adds <address> element to each <disk> device since device
names alone won't adequately reflect the storage device layout in the
VM. With this patch, the ouput produced by dumpxml will faithfully
reproduce the storage layout of the VM if used with define.

src/vbox/vbox_common.c

index 661e09a27a12a104a8fd7b17a7090ff260682c66..8da08240ef22832d8b22b1758706a416ee22d48f 100644 (file)
@@ -3336,25 +3336,60 @@ vboxDumpDisks(virDomainDefPtr def, vboxDriverPtr data, IMachine *machine)
             goto cleanup;
         }
 
-        if (storageBus == StorageBus_IDE) {
+        disk->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE;
+        disk->info.addr.drive.bus = 0;
+        disk->info.addr.drive.unit = devicePort;
+
+        switch ((enum StorageBus) storageBus) {
+        case StorageBus_IDE:
             disk->bus = VIR_DOMAIN_DISK_BUS_IDE;
-        } else if (storageBus == StorageBus_SATA) {
-            sdCount++;
+            disk->info.addr.drive.bus = devicePort; /* primary, secondary */
+            disk->info.addr.drive.unit = deviceSlot; /* master, slave */
+
+            break;
+        case StorageBus_SATA:
             disk->bus = VIR_DOMAIN_DISK_BUS_SATA;
-        } else if (storageBus == StorageBus_SCSI) {
             sdCount++;
+
+            break;
+        case StorageBus_SCSI:
             disk->bus = VIR_DOMAIN_DISK_BUS_SCSI;
-        } else if (storageBus == StorageBus_Floppy) {
+            sdCount++;
+
+            break;
+        case StorageBus_Floppy:
             disk->bus = VIR_DOMAIN_DISK_BUS_FDC;
+
+            break;
+        case StorageBus_SAS:
+        case StorageBus_Null:
+            virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
+                           _("Unsupported null storage bus"));
+            goto cleanup;
         }
 
-        if (deviceType == DeviceType_HardDisk)
+        switch ((enum DeviceType) deviceType) {
+        case DeviceType_HardDisk:
             disk->device = VIR_DOMAIN_DISK_DEVICE_DISK;
-        else if (deviceType == DeviceType_Floppy)
+
+            break;
+        case DeviceType_Floppy:
             disk->device = VIR_DOMAIN_DISK_DEVICE_FLOPPY;
-        else if (deviceType == DeviceType_DVD)
+
+            break;
+        case DeviceType_DVD:
             disk->device = VIR_DOMAIN_DISK_DEVICE_CDROM;
 
+            break;
+        case DeviceType_Network:
+        case DeviceType_USB:
+        case DeviceType_SharedFolder:
+        case DeviceType_Null:
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Unsupported vbox device type: %d"), deviceType);
+            goto cleanup;
+        }
+
         if (readOnly == PR_TRUE)
             disk->src->readonly = true;