[PATCH 26/55] qemu: alias: Generate QDEV name of the block backend for disks

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

 



When we stop using -drive qemu stops reporting it in some of the monitor
commands. To allow referring the disk frontends and the corresponding
block backends we need to know these names. Unfortunately different
buses require different names.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/qemu/qemu_alias.c   | 86 +++++++++++++++++++++++++++++++++++--------------
 src/qemu/qemu_alias.h   |  3 +-
 src/qemu/qemu_hotplug.c |  2 +-
 3 files changed, 65 insertions(+), 26 deletions(-)

diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index 80d9b6cf46..be3663f8d2 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -175,44 +175,82 @@ qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
 }


-/* Our custom -drive naming scheme used with id= */
 int
 qemuAssignDeviceDiskAlias(virDomainDefPtr def,
-                          virDomainDiskDefPtr disk)
+                          virDomainDiskDefPtr disk,
+                          virQEMUCapsPtr qemuCaps)
 {
+    qemuDomainDiskPrivatePtr diskPriv = QEMU_DOMAIN_DISK_PRIVATE(disk);
     const char *prefix = virDomainDiskBusTypeToString(disk->bus);
     int controllerModel = -1;

     if (disk->info.alias)
         return 0;

-    if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
-        if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
-            controllerModel = qemuDomainFindSCSIControllerModel(def,
-                                                                &disk->info);
-            if (controllerModel < 0)
+    if (!disk->info.alias) {
+        if (disk->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_DRIVE) {
+            if (disk->bus == VIR_DOMAIN_DISK_BUS_SCSI) {
+                controllerModel = qemuDomainFindSCSIControllerModel(def,
+                                                                    &disk->info);
+                if (controllerModel < 0)
+                    return -1;
+            }
+
+            if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI ||
+                controllerModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
+                if (virAsprintf(&disk->info.alias, "%s%d-%d-%d", prefix,
+                                disk->info.addr.drive.controller,
+                                disk->info.addr.drive.bus,
+                                disk->info.addr.drive.unit) < 0)
+                    return -1;
+            } else {
+                if (virAsprintf(&disk->info.alias, "%s%d-%d-%d-%d", prefix,
+                                disk->info.addr.drive.controller,
+                                disk->info.addr.drive.bus,
+                                disk->info.addr.drive.target,
+                                disk->info.addr.drive.unit) < 0)
+                    return -1;
+            }
+        } else {
+            int idx = virDiskNameToIndex(disk->dst);
+            if (virAsprintf(&disk->info.alias, "%s-disk%d", prefix, idx) < 0)
                 return -1;
         }
+    }

-        if (disk->bus != VIR_DOMAIN_DISK_BUS_SCSI ||
-            controllerModel == VIR_DOMAIN_CONTROLLER_MODEL_SCSI_LSILOGIC) {
-            if (virAsprintf(&disk->info.alias, "%s%d-%d-%d", prefix,
-                            disk->info.addr.drive.controller,
-                            disk->info.addr.drive.bus,
-                            disk->info.addr.drive.unit) < 0)
+    /* For -blockdev we need to know the QDEV ids of the block backend of the
+     * disk. The QDEV id used by qemu is based on the alias so we generate them
+     * here. */
+    if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+        switch ((virDomainDiskBus) disk->bus) {
+        case VIR_DOMAIN_DISK_BUS_IDE:
+        case VIR_DOMAIN_DISK_BUS_SATA:
+        case VIR_DOMAIN_DISK_BUS_SCSI:
+            if (VIR_STRDUP(diskPriv->backendQomName, disk->info.alias) < 0)
                 return -1;
-        } else {
-            if (virAsprintf(&disk->info.alias, "%s%d-%d-%d-%d", prefix,
-                            disk->info.addr.drive.controller,
-                            disk->info.addr.drive.bus,
-                            disk->info.addr.drive.target,
-                            disk->info.addr.drive.unit) < 0)
+            break;
+
+        case VIR_DOMAIN_DISK_BUS_VIRTIO:
+            if (virAsprintf(&diskPriv->backendQomName,
+                            "/machine/peripheral/%s/virtio-backend",
+                            disk->info.alias) < 0)
                 return -1;
+            break;
+
+        case VIR_DOMAIN_DISK_BUS_USB:
+            if (virAsprintf(&diskPriv->backendQomName,
+                            "/machine/peripheral/%s/%s.0/legacy[0]",
+                            disk->info.alias, disk->info.alias) < 0)
+                return -1;
+            break;
+
+        case VIR_DOMAIN_DISK_BUS_FDC:
+        case VIR_DOMAIN_DISK_BUS_XEN:
+        case VIR_DOMAIN_DISK_BUS_UML:
+        case VIR_DOMAIN_DISK_BUS_SD:
+        case VIR_DOMAIN_DISK_BUS_LAST:
+            break;
         }
-    } else {
-        int idx = virDiskNameToIndex(disk->dst);
-        if (virAsprintf(&disk->info.alias, "%s-disk%d", prefix, idx) < 0)
-            return -1;
     }

     return 0;
@@ -551,7 +589,7 @@ qemuAssignDeviceAliases(virDomainDefPtr def, virQEMUCapsPtr qemuCaps)
     size_t i;

     for (i = 0; i < def->ndisks; i++) {
-        if (qemuAssignDeviceDiskAlias(def, def->disks[i]) < 0)
+        if (qemuAssignDeviceDiskAlias(def, def->disks[i], qemuCaps) < 0)
             return -1;
     }
     for (i = 0; i < def->nnets; i++) {
diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h
index 7bfebff968..33b9937ea4 100644
--- a/src/qemu/qemu_alias.h
+++ b/src/qemu/qemu_alias.h
@@ -39,7 +39,8 @@ int qemuAssignDeviceControllerAlias(virDomainDefPtr domainDef,
                                     virDomainControllerDefPtr controller);

 int qemuAssignDeviceDiskAlias(virDomainDefPtr def,
-                              virDomainDiskDefPtr disk);
+                              virDomainDiskDefPtr disk,
+                              virQEMUCapsPtr qemuCaps);

 int qemuAssignDeviceHostdevAlias(virDomainDefPtr def,
                                  char **alias,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 1538abf155..87efd3b411 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -646,7 +646,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
     if (qemuHotplugPrepareDiskAccess(driver, vm, disk, NULL, false) < 0)
         goto cleanup;

-    if (qemuAssignDeviceDiskAlias(vm->def, disk) < 0)
+    if (qemuAssignDeviceDiskAlias(vm->def, disk, priv->qemuCaps) < 0)
         goto error;

     if (qemuDomainPrepareDiskSource(disk, priv, cfg) < 0)
-- 
2.16.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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