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

[libvirt] [PATCHv2 30/62] qemu: command: Setup floppy drives via -device for blockdev



To allow referring to the drives via the QOM id we need to setup the
floppy drives with a proper ID. This means that -device should be used
for them.

There are the following quirks:
- FDC needs to be instantiated prior to any floppy device
- floppy drive specified via -device does not support 'bootindex'
    (hacked around by passing bootindexA=1 to the FDC)

Signed-off-by: Peter Krempa <pkrempa redhat com>
---
 src/qemu/qemu_command.c | 42 +++++++++++++++++++++++++++++++-----------
 1 file changed, 31 insertions(+), 11 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index a3fadc505d..72fdffa92a 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2060,6 +2060,10 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
             goto error;
         break;

+    case VIR_DOMAIN_DISK_BUS_FDC:
+        virBufferAsprintf(&opt, "floppy,unit=%d", disk->info.addr.drive.unit);
+        break;
+
     default:
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("unsupported disk bus '%s' with device setup"), bus);
@@ -2181,17 +2185,20 @@ qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
         else
             driveLetter = 'A';

-        if (qemuDomainDiskGetBackendAlias(disk, qemuCaps, &backendAlias) < 0)
-            goto cleanup;
-
-        if (backendAlias &&
-            virAsprintf(&backendStr, "drive%c=%s", driveLetter, backendAlias) < 0)
-            goto cleanup;
-
         if (bootindex &&
             virAsprintf(&bootindexStr, "bootindex%c=%u", driveLetter, bootindex) < 0)
             goto cleanup;

+        /* with -blockdev we setup the floppy device and it's backend with -device */
+        if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
+            if (qemuDomainDiskGetBackendAlias(disk, qemuCaps, &backendAlias) < 0)
+                goto cleanup;
+
+            if (backendAlias &&
+                virAsprintf(&backendStr, "drive%c=%s", driveLetter, backendAlias) < 0)
+                goto cleanup;
+        }
+
         if (!explicitfdc) {
             if (backendStr) {
                 virCommandAddArg(cmd, "-global");
@@ -2303,7 +2310,8 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
         return -1;

     if (!qemuDiskBusNeedsDriveArg(disk->bus)) {
-        if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC) {
+        if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC ||
+            virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV)) {
             virCommandAddArg(cmd, "-device");

             if (!(optstr = qemuBuildDiskDeviceStr(def, disk, bootindex,
@@ -2327,6 +2335,7 @@ qemuBuildDisksCommandLine(virCommandPtr cmd,
     unsigned int bootCD = 0;
     unsigned int bootFloppy = 0;
     unsigned int bootDisk = 0;
+    bool blockdev = virQEMUCapsGet(qemuCaps, QEMU_CAPS_BLOCKDEV);

     for (i = 0; i < def->os.nBootDevs; i++) {
         switch (def->os.bootDevs[i]) {
@@ -2342,6 +2351,12 @@ qemuBuildDisksCommandLine(virCommandPtr cmd,
         }
     }

+    /* If we want to express the floppy drives via -device, the controller needs
+     * to be instantiated prior to that */
+    if (blockdev &&
+        qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps, bootFloppy) < 0)
+        return -1;
+
     for (i = 0; i < def->ndisks; i++) {
         virDomainDiskDefPtr disk = def->disks[i];
         unsigned int bootindex = 0;
@@ -2362,12 +2377,17 @@ qemuBuildDisksCommandLine(virCommandPtr cmd,
             }
         }

-        if (qemuBuildDiskCommandLine(cmd, def, disk, qemuCaps,
-                                     bootindex) < 0)
+        /* The floppy device itself does not support the bootindex property
+         * so we need to set it up for the controller */
+        if (disk->device == VIR_DOMAIN_DISK_DEVICE_FLOPPY)
+            bootindex = 0;
+
+        if (qemuBuildDiskCommandLine(cmd, def, disk, qemuCaps, bootindex) < 0)
             return -1;
     }

-    if (qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps, bootFloppy) < 0)
+    if (!blockdev &&
+        qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps, bootFloppy) < 0)
         return -1;

     return 0;
-- 
2.16.2


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