[PATCH 5/6] qemu: command: Don't format -device isa-fdc, ... twice with two floppy drives

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

 



Fix regression introduced in 42fd5a58adb. With q35 machine type which
requires the explicitly specified FDC we'd format two  isa-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@xxxxxxxxxx>
---
 src/qemu/qemu_command.c                            | 100 +++++++++++++--------
 tests/qemuxml2argvdata/boot-complex-bootindex.args |   2 +-
 tests/qemuxml2argvdata/boot-complex.args           |   2 +-
 tests/qemuxml2argvdata/boot-strict.args            |   2 +-
 .../disk-floppy-q35-2_11.x86_64-latest.args        |   2 +-
 .../disk-floppy-q35-2_9.x86_64-latest.args         |   3 +-
 tests/qemuxml2argvdata/disk-floppy-tray.args       |   2 +-
 tests/qemuxml2argvdata/disk-floppy.args            |   2 +-
 .../disk-floppy.x86_64-latest.args                 |   2 +-
 tests/qemuxml2argvdata/user-aliases.args           |   2 +-
 10 files changed, 71 insertions(+), 48 deletions(-)

diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index daf037328f..1169164a39 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -2143,50 +2143,78 @@ 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;

-        if (bootindexStr) {
-            virCommandAddArg(cmd, "-global");
-            virCommandAddArgFormat(cmd, "isa-fdc.%s", bootindexStr);
+        bootFloppy = 0;
+
+        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 +2304,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 +2355,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 +2368,10 @@ qemuBuildDisksCommandLine(virCommandPtr cmd,
             return -1;
     }

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

diff --git a/tests/qemuxml2argvdata/boot-complex-bootindex.args b/tests/qemuxml2argvdata/boot-complex-bootindex.args
index cae9a42c0c..56cefb60a5 100644
--- a/tests/qemuxml2argvdata/boot-complex-bootindex.args
+++ b/tests/qemuxml2argvdata/boot-complex-bootindex.args
@@ -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,\
diff --git a/tests/qemuxml2argvdata/boot-complex.args b/tests/qemuxml2argvdata/boot-complex.args
index cae9a42c0c..56cefb60a5 100644
--- a/tests/qemuxml2argvdata/boot-complex.args
+++ b/tests/qemuxml2argvdata/boot-complex.args
@@ -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,\
diff --git a/tests/qemuxml2argvdata/boot-strict.args b/tests/qemuxml2argvdata/boot-strict.args
index 11bac4ec79..9dc90454fd 100644
--- a/tests/qemuxml2argvdata/boot-strict.args
+++ b/tests/qemuxml2argvdata/boot-strict.args
@@ -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,\
diff --git a/tests/qemuxml2argvdata/disk-floppy-q35-2_11.x86_64-latest.args b/tests/qemuxml2argvdata/disk-floppy-q35-2_11.x86_64-latest.args
index 3c3d99f1d5..e38f7040ec 100644
--- a/tests/qemuxml2argvdata/disk-floppy-q35-2_11.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/disk-floppy-q35-2_11.x86_64-latest.args
@@ -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 \
diff --git a/tests/qemuxml2argvdata/disk-floppy-q35-2_9.x86_64-latest.args b/tests/qemuxml2argvdata/disk-floppy-q35-2_9.x86_64-latest.args
index 69be8616de..e4ece864fe 100644
--- a/tests/qemuxml2argvdata/disk-floppy-q35-2_9.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/disk-floppy-q35-2_9.x86_64-latest.args
@@ -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
diff --git a/tests/qemuxml2argvdata/disk-floppy-tray.args b/tests/qemuxml2argvdata/disk-floppy-tray.args
index d50a01871d..25138661e2 100644
--- a/tests/qemuxml2argvdata/disk-floppy-tray.args
+++ b/tests/qemuxml2argvdata/disk-floppy-tray.args
@@ -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
diff --git a/tests/qemuxml2argvdata/disk-floppy.args b/tests/qemuxml2argvdata/disk-floppy.args
index 3c3177c510..a7cd66af42 100644
--- a/tests/qemuxml2argvdata/disk-floppy.args
+++ b/tests/qemuxml2argvdata/disk-floppy.args
@@ -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
diff --git a/tests/qemuxml2argvdata/disk-floppy.x86_64-latest.args b/tests/qemuxml2argvdata/disk-floppy.x86_64-latest.args
index 302e19b36a..8f10c980c9 100644
--- a/tests/qemuxml2argvdata/disk-floppy.x86_64-latest.args
+++ b/tests/qemuxml2argvdata/disk-floppy.x86_64-latest.args
@@ -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 \
diff --git a/tests/qemuxml2argvdata/user-aliases.args b/tests/qemuxml2argvdata/user-aliases.args
index c2d93fb7b7..089a7d8d4b 100644
--- a/tests/qemuxml2argvdata/user-aliases.args
+++ b/tests/qemuxml2argvdata/user-aliases.args
@@ -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 \
-- 
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