]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu: command: Don't format -device isa-fdc,... twice with two floppy drives
authorPeter Krempa <pkrempa@redhat.com>
Thu, 9 Aug 2018 11:50:22 +0000 (13:50 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 9 Aug 2018 15:00:54 +0000 (17:00 +0200)
Fix regression introduced in <42fd5a58adb>. With q35 machine type which
requires the explicitly specified FDC we'd format twoisa-fdc
controllers to the command line as the code was moved to a place where
it's called per-disk.

Move the call back after formatting all disks and reiterate the disks to
find the floppy controllers.

This also moves the '-global' directive which sets up the default
ISA-FDC to the end after all the disks but since we are modifying the
properties it is safe to do so.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/qemu/qemu_command.c
tests/qemuxml2argvdata/boot-complex.args
tests/qemuxml2argvdata/boot-strict.args
tests/qemuxml2argvdata/disk-floppy-q35-2_11.x86_64-latest.args
tests/qemuxml2argvdata/disk-floppy-q35-2_9.x86_64-latest.args
tests/qemuxml2argvdata/disk-floppy-tray.args
tests/qemuxml2argvdata/disk-floppy.args
tests/qemuxml2argvdata/disk-floppy.x86_64-latest.args
tests/qemuxml2argvdata/user-aliases.args

index daf037328ff01eae139c4e8ca6128fd6744a79f8..65bd88a6522dce611b99aa6fc155d6e0a13d3423 100644 (file)
@@ -2143,50 +2143,77 @@ qemuBuildDiskDeviceStr(const virDomainDef *def,
 
 
 static int
-qemuBuildFloppyCommandLineOptions(virCommandPtr cmd,
-                                  const virDomainDef *def,
-                                  virDomainDiskDefPtr disk,
-                                  virQEMUCapsPtr qemuCaps,
-                                  unsigned int bootindex)
+qemuBuildFloppyCommandLineControllerOptions(virCommandPtr cmd,
+                                            const virDomainDef *def,
+                                            virQEMUCapsPtr qemuCaps,
+                                            unsigned int bootFloppy)
 {
     virBuffer fdc_opts = VIR_BUFFER_INITIALIZER;
+    bool explicitfdc = qemuDomainNeedsFDC(def);
+    bool hasfloppy = false;
+    unsigned int bootindex;
     char driveLetter;
     char *backendAlias = NULL;
     char *backendStr = NULL;
     char *bootindexStr = NULL;
+    size_t i;
     int ret = -1;
 
-    if (disk->info.addr.drive.unit)
-        driveLetter = 'B';
-    else
-        driveLetter = 'A';
+    virBufferAddLit(&fdc_opts, "isa-fdc,");
 
-    if (qemuDomainDiskGetBackendAlias(disk, qemuCaps, &backendAlias) < 0)
-        goto cleanup;
+    for (i = 0; i < def->ndisks; i++) {
+        virDomainDiskDefPtr disk = def->disks[i];
 
-    if (backendAlias &&
-        virAsprintf(&backendStr, "drive%c=%s", driveLetter, backendAlias) < 0)
-        goto cleanup;
+        if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC)
+            continue;
 
-    if (bootindex &&
-        virAsprintf(&bootindexStr, "bootindex%c=%u", driveLetter, bootindex) < 0)
-        goto cleanup;
+        hasfloppy = true;
 
-    if (!qemuDomainNeedsFDC(def)) {
-        if (backendStr) {
-            virCommandAddArg(cmd, "-global");
-            virCommandAddArgFormat(cmd, "isa-fdc.%s", backendStr);
+        if (disk->info.bootIndex) {
+            bootindex = disk->info.bootIndex;
+        } else {
+            bootindex = bootFloppy;
+            bootFloppy = 0;
         }
 
-        if (bootindexStr) {
-            virCommandAddArg(cmd, "-global");
-            virCommandAddArgFormat(cmd, "isa-fdc.%s", bootindexStr);
+        if (disk->info.addr.drive.unit)
+            driveLetter = 'B';
+        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;
+
+        if (!explicitfdc) {
+            if (backendStr) {
+                virCommandAddArg(cmd, "-global");
+                virCommandAddArgFormat(cmd, "isa-fdc.%s", backendStr);
+            }
+
+            if (bootindexStr) {
+                virCommandAddArg(cmd, "-global");
+                virCommandAddArgFormat(cmd, "isa-fdc.%s", bootindexStr);
+            }
+        } else {
+            virBufferStrcat(&fdc_opts, backendStr, ",", NULL);
+            virBufferStrcat(&fdc_opts, bootindexStr, ",", NULL);
         }
-    } else {
+
+        VIR_FREE(backendAlias);
+        VIR_FREE(backendStr);
+        VIR_FREE(bootindexStr);
+    }
+
+    if (explicitfdc && hasfloppy) {
         /* Newer Q35 machine types require an explicit FDC controller */
-        virBufferAddLit(&fdc_opts, "isa-fdc,");
-        virBufferStrcat(&fdc_opts, backendStr, ",", NULL);
-        virBufferStrcat(&fdc_opts, bootindexStr, NULL);
         virBufferTrim(&fdc_opts, ",", -1);
         virCommandAddArg(cmd, "-device");
         virCommandAddArgBuffer(cmd, &fdc_opts);
@@ -2276,11 +2303,7 @@ qemuBuildDiskCommandLine(virCommandPtr cmd,
         return -1;
 
     if (!qemuDiskBusNeedsDriveArg(disk->bus)) {
-        if (disk->bus == VIR_DOMAIN_DISK_BUS_FDC) {
-            if (qemuBuildFloppyCommandLineOptions(cmd, def, disk, qemuCaps,
-                                                  bootindex) < 0)
-                return -1;
-        } else {
+        if (disk->bus != VIR_DOMAIN_DISK_BUS_FDC) {
             virCommandAddArg(cmd, "-device");
 
             if (!(optstr = qemuBuildDiskDeviceStr(def, disk, bootindex,
@@ -2331,10 +2354,6 @@ qemuBuildDisksCommandLine(virCommandPtr cmd,
                 bootindex = bootCD;
                 bootCD = 0;
                 break;
-            case VIR_DOMAIN_DISK_DEVICE_FLOPPY:
-                bootindex = bootFloppy;
-                bootFloppy = 0;
-                break;
             case VIR_DOMAIN_DISK_DEVICE_DISK:
             case VIR_DOMAIN_DISK_DEVICE_LUN:
                 bootindex = bootDisk;
@@ -2348,6 +2367,9 @@ qemuBuildDisksCommandLine(virCommandPtr cmd,
             return -1;
     }
 
+    if (qemuBuildFloppyCommandLineControllerOptions(cmd, def, qemuCaps, bootFloppy) < 0)
+        return -1;
+
     return 0;
 }
 
index cae9a42c0cec76280155fb2f45b38e6b36c5c164..56cefb60a5aece5c86612cfa30ede52ca6c4d855 100644 (file)
@@ -36,9 +36,9 @@ readonly=on \
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,\
 bootindex=1 \
 -drive file=/dev/fd0,format=raw,if=none,id=drive-fdc0-0-0 \
+-drive file=/dev/fd1,format=raw,if=none,id=drive-fdc0-0-1 \
 -global isa-fdc.driveA=drive-fdc0-0-0 \
 -global isa-fdc.bootindexA=4 \
--drive file=/dev/fd1,format=raw,if=none,id=drive-fdc0-0-1 \
 -global isa-fdc.driveB=drive-fdc0-0-1 \
 -netdev user,id=hostnet0 \
 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=00:11:22:33:44:11,bus=pci.0,\
index 11bac4ec795101f077356451be2aa0513744577f..9dc90454fd0fa57f614000baa9583a049903249f 100644 (file)
@@ -37,9 +37,9 @@ readonly=on \
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0,\
 bootindex=1 \
 -drive file=/dev/fd0,format=raw,if=none,id=drive-fdc0-0-0 \
+-drive file=/dev/fd1,format=raw,if=none,id=drive-fdc0-0-1 \
 -global isa-fdc.driveA=drive-fdc0-0-0 \
 -global isa-fdc.bootindexA=4 \
--drive file=/dev/fd1,format=raw,if=none,id=drive-fdc0-0-1 \
 -global isa-fdc.driveB=drive-fdc0-0-1 \
 -netdev user,id=hostnet0 \
 -device virtio-net-pci,netdev=hostnet0,id=net0,mac=00:11:22:33:44:11,bus=pci.0,\
index 3c3d99f1d56a2647c7785097d42160597e315e70..e38f7040eca7624fb3b45c7268f3162d0fe6688e 100644 (file)
@@ -28,9 +28,9 @@ addr=0x1 \
 -device pcie-root-port,port=0x9,chassis=2,id=pci.2,bus=pcie.0,addr=0x1.0x1 \
 -device qemu-xhci,id=usb,bus=pci.1,addr=0x0 \
 -drive file=/tmp/firmware.img,format=raw,if=none,id=drive-fdc0-0-0 \
+-drive file=/tmp/data.img,format=qcow2,if=none,id=drive-fdc0-0-1 \
 -global isa-fdc.driveA=drive-fdc0-0-0 \
 -global isa-fdc.bootindexA=1 \
--drive file=/tmp/data.img,format=qcow2,if=none,id=drive-fdc0-0-1 \
 -global isa-fdc.driveB=drive-fdc0-0-1 \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
 resourcecontrol=deny \
index 69be8616de136536d6f9038de66f090370106c20..e4ece864fe1ae20796496555c5068b8ff266f8cd 100644 (file)
@@ -28,9 +28,8 @@ addr=0x1 \
 -device pcie-root-port,port=0x9,chassis=2,id=pci.2,bus=pcie.0,addr=0x1.0x1 \
 -device qemu-xhci,id=usb,bus=pci.1,addr=0x0 \
 -drive file=/tmp/firmware.img,format=raw,if=none,id=drive-fdc0-0-0 \
--device isa-fdc,driveA=drive-fdc0-0-0,bootindexA=1 \
 -drive file=/tmp/data.img,format=qcow2,if=none,id=drive-fdc0-0-1 \
--device isa-fdc,driveB=drive-fdc0-0-1 \
+-device isa-fdc,driveA=drive-fdc0-0-0,bootindexA=1,driveB=drive-fdc0-0-1 \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
 resourcecontrol=deny \
 -msg timestamp=on
index d50a01871d6d5a8db96618b9159a7f393b28b844..25138661e2c61c1116e7cb523d2942b86b969662 100644 (file)
@@ -25,7 +25,7 @@ server,nowait \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,\
 bootindex=1 \
 -drive file=/dev/fd0,format=raw,if=none,id=drive-fdc0-0-0 \
--global isa-fdc.driveA=drive-fdc0-0-0 \
 -drive if=none,id=drive-fdc0-0-1 \
+-global isa-fdc.driveA=drive-fdc0-0-0 \
 -global isa-fdc.driveB=drive-fdc0-0-1 \
 -device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x3
index 3c3177c510c58ba4b9efea141da9392db7d3ca5f..a7cd66af42b73d1c7a026b3d882b88967f57fa7e 100644 (file)
@@ -25,6 +25,6 @@ server,nowait \
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,\
 bootindex=1 \
 -drive file=/dev/fd0,format=raw,if=none,id=drive-fdc0-0-0 \
--global isa-fdc.driveA=drive-fdc0-0-0 \
 -drive file=/tmp/firmware.img,format=raw,if=none,id=drive-fdc0-0-1 \
+-global isa-fdc.driveA=drive-fdc0-0-0 \
 -global isa-fdc.driveB=drive-fdc0-0-1
index 302e19b36ad4819e3a1412fc14d85f4f2bcc5b8c..8f10c980c9abf27979592121d4aa106c5376fa70 100644 (file)
@@ -27,8 +27,8 @@ file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
 -device ide-hd,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0,bootindex=1 \
 -drive file=/dev/fd0,format=raw,if=none,id=drive-fdc0-0-0 \
--global isa-fdc.driveA=drive-fdc0-0-0 \
 -drive file=/tmp/firmware.img,format=raw,if=none,id=drive-fdc0-0-1 \
+-global isa-fdc.driveA=drive-fdc0-0-0 \
 -global isa-fdc.driveB=drive-fdc0-0-1 \
 -sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
 resourcecontrol=deny \
index c2d93fb7b7a5971725502b5becee07c57cc8f628..089a7d8d4b5f84c7c0e4ab747371701ee9de1abe 100644 (file)
@@ -40,7 +40,6 @@ server,nowait \
 -usb \
 -drive file=/var/lib/libvirt/images/fd.img,format=raw,if=none,\
 id=drive-ua-myDisk1,cache=none \
--global isa-fdc.driveA=drive-ua-myDisk1 \
 -drive file=/var/lib/libvirt/images/gentoo.qcow2,format=qcow2,if=none,\
 id=drive-ua-myDisk2 \
 -device virtio-blk-pci,bus=pci.0,addr=0x5,drive=drive-ua-myDisk2,id=ua-myDisk2,\
@@ -57,6 +56,7 @@ id=ua-myEncryptedDisk1 \
 if=none,id=drive-ua-WhatAnAwesomeCDROM,media=cdrom,readonly=on,cache=none \
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ua-WhatAnAwesomeCDROM,\
 id=ua-WhatAnAwesomeCDROM,bootindex=2 \
+-global isa-fdc.driveA=drive-ua-myDisk1 \
 -netdev tap,fd=3,id=hostua-CheckoutThisNIC,vhost=on,vhostfd=44 \
 -device virtio-net-pci,netdev=hostua-CheckoutThisNIC,id=ua-CheckoutThisNIC,\
 mac=52:54:00:d6:c0:0b,bus=pci.0,addr=0x3 \