render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7a3408
From c8aeb07255eb984a89be33ca3a0bafcebe088682 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <c8aeb07255eb984a89be33ca3a0bafcebe088682@dist-git>
7a3408
From: =?UTF-8?q?J=C3=A1n=20Tomko?= <jtomko@redhat.com>
7a3408
Date: Wed, 8 Jul 2015 15:56:47 +0200
7a3408
Subject: [PATCH] Explicitly format the isa-fdc controller for newer q35
7a3408
 machines
7a3408
MIME-Version: 1.0
7a3408
Content-Type: text/plain; charset=UTF-8
7a3408
Content-Transfer-Encoding: 8bit
7a3408
7a3408
Since QEMU commit ea96bc6 [1]:
7a3408
i386: drop FDC in pc-q35-2.4+ if neither it nor floppy drives are wanted
7a3408
the floppy controller is no longer implicit.
7a3408
7a3408
Specify it explicitly on the command line if the machine type version
7a3408
is 2.4 or later.
7a3408
7a3408
Note that libvirt's floppy drives do not result in QEMU implying the
7a3408
controller, because libvirt uses if=none instead of if=floppy.
7a3408
7a3408
https://bugzilla.redhat.com/show_bug.cgi?id=1227880
7a3408
7a3408
[1] http://git.qemu.org/?p=qemu.git;a=commitdiff;h=ea96bc6
7a3408
7a3408
(cherry picked from commit 4edf01c92cf9004aac2a505a38d92d13050c24bc)
7a3408
Signed-off-by: Ján Tomko <jtomko@redhat.com>
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_command.c                            | 31 +++++++++++++----
7a3408
 src/qemu/qemu_domain.c                             | 19 ++++++++++
7a3408
 src/qemu/qemu_domain.h                             |  1 +
7a3408
 .../qemuxml2argv-boot-floppy-q35.args              | 12 +++++++
7a3408
 .../qemuxml2argv-boot-floppy-q35.xml               | 40 ++++++++++++++++++++++
7a3408
 .../qemuxml2argv-bootindex-floppy-q35.args         | 11 ++++++
7a3408
 .../qemuxml2argv-bootindex-floppy-q35.xml          | 40 ++++++++++++++++++++++
7a3408
 tests/qemuxml2argvtest.c                           |  9 +++++
7a3408
 8 files changed, 156 insertions(+), 7 deletions(-)
7a3408
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-boot-floppy-q35.args
7a3408
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-boot-floppy-q35.xml
7a3408
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-bootindex-floppy-q35.args
7a3408
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-bootindex-floppy-q35.xml
7a3408
7a3408
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
7a3408
index d8ce22f..48d2ee0 100644
7a3408
--- a/src/qemu/qemu_command.c
7a3408
+++ b/src/qemu/qemu_command.c
7a3408
@@ -8837,9 +8837,9 @@ qemuBuildCommandLine(virConnectPtr conn,
7a3408
          * List of controller types that we add commandline args for,
7a3408
          * *in the order we want to add them*.
7a3408
          *
7a3408
-         * We don't add an explicit FD controller because the
7a3408
-         * provided PIIX4 device already includes one. It isn't possible to
7a3408
-         * remove the PIIX4.
7a3408
+         * The floppy controller is implicit on PIIX4 and older Q35
7a3408
+         * machines. For newer Q35 machines it is added out of the
7a3408
+         * controllers loop, after the floppy drives.
7a3408
          *
7a3408
          * We don't add PCI/PCIe root controller either, because it's
7a3408
          * implicit, but we do add PCI bridges and other PCI
7a3408
@@ -8860,6 +8860,8 @@ qemuBuildCommandLine(virConnectPtr conn,
7a3408
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
7a3408
     virBuffer boot_buf = VIR_BUFFER_INITIALIZER;
7a3408
     char *boot_order_str = NULL, *boot_opts_str = NULL;
7a3408
+    virBuffer fdc_opts = VIR_BUFFER_INITIALIZER;
7a3408
+    char *fdc_opts_str = NULL;
7a3408
 
7a3408
     VIR_DEBUG("conn=%p driver=%p def=%p mon=%p json=%d "
7a3408
               "qemuCaps=%p migrateFrom=%s migrateFD=%d "
7a3408
@@ -9810,8 +9812,12 @@ qemuBuildCommandLine(virConnectPtr conn,
7a3408
                                     disk->info.alias) < 0)
7a3408
                         goto error;
7a3408
 
7a3408
-                    virCommandAddArg(cmd, "-global");
7a3408
-                    virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
7a3408
+                    if (!qemuDomainMachineNeedsFDC(def)) {
7a3408
+                        virCommandAddArg(cmd, "-global");
7a3408
+                        virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
7a3408
+                    } else {
7a3408
+                        virBufferAsprintf(&fdc_opts, "%s,", optstr);
7a3408
+                    }
7a3408
                     VIR_FREE(optstr);
7a3408
 
7a3408
                     if (bootindex) {
7a3408
@@ -9821,8 +9827,12 @@ qemuBuildCommandLine(virConnectPtr conn,
7a3408
                                         bootindex) < 0)
7a3408
                             goto error;
7a3408
 
7a3408
-                        virCommandAddArg(cmd, "-global");
7a3408
-                        virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
7a3408
+                        if (!qemuDomainMachineNeedsFDC(def)) {
7a3408
+                            virCommandAddArg(cmd, "-global");
7a3408
+                            virCommandAddArgFormat(cmd, "isa-fdc.%s", optstr);
7a3408
+                        } else {
7a3408
+                            virBufferAsprintf(&fdc_opts, "%s,", optstr);
7a3408
+                        }
7a3408
                         VIR_FREE(optstr);
7a3408
                     }
7a3408
                 } else {
7a3408
@@ -9836,6 +9846,13 @@ qemuBuildCommandLine(virConnectPtr conn,
7a3408
                 }
7a3408
             }
7a3408
         }
7a3408
+        /* Newer Q35 machine types require an explicit FDC controller */
7a3408
+        virBufferTrim(&fdc_opts, ",", -1);
7a3408
+        if ((fdc_opts_str = virBufferContentAndReset(&fdc_opts))) {
7a3408
+            virCommandAddArg(cmd, "-device");
7a3408
+            virCommandAddArgFormat(cmd, "isa-fdc,%s", fdc_opts_str);
7a3408
+            VIR_FREE(fdc_opts_str);
7a3408
+        }
7a3408
     } else {
7a3408
         for (i = 0; i < def->ndisks; i++) {
7a3408
             char dev[NAME_MAX];
7a3408
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
7a3408
index f9bf32c..6590cf0 100644
7a3408
--- a/src/qemu/qemu_domain.c
7a3408
+++ b/src/qemu/qemu_domain.c
7a3408
@@ -3245,6 +3245,25 @@ qemuDomainMachineIsI440FX(const virDomainDef *def)
7a3408
 }
7a3408
 
7a3408
 
7a3408
+bool
7a3408
+qemuDomainMachineNeedsFDC(const virDomainDef *def)
7a3408
+{
7a3408
+    char *p = STRSKIP(def->os.machine, "pc-q35-");
7a3408
+
7a3408
+    if (p) {
7a3408
+        if (STRPREFIX(p, "1.") ||
7a3408
+            STRPREFIX(p, "2.0") ||
7a3408
+            STRPREFIX(p, "2.1") ||
7a3408
+            STRPREFIX(p, "2.2") ||
7a3408
+            STRPREFIX(p, "2.3"))
7a3408
+            return false;
7a3408
+        return true;
7a3408
+    }
7a3408
+    return false;
7a3408
+}
7a3408
+
7a3408
+
7a3408
+
7a3408
 /**
7a3408
  * qemuDomainUpdateCurrentMemorySize:
7a3408
  *
7a3408
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
7a3408
index 54e1e7b..66dbcf5 100644
7a3408
--- a/src/qemu/qemu_domain.h
7a3408
+++ b/src/qemu/qemu_domain.h
7a3408
@@ -465,6 +465,7 @@ virDomainChrSourceDefPtr qemuFindAgentConfig(virDomainDefPtr def);
7a3408
 
7a3408
 bool qemuDomainMachineIsQ35(const virDomainDef *def);
7a3408
 bool qemuDomainMachineIsI440FX(const virDomainDef *def);
7a3408
+bool qemuDomainMachineNeedsFDC(const virDomainDef *def);
7a3408
 
7a3408
 int qemuDomainUpdateCurrentMemorySize(virQEMUDriverPtr driver,
7a3408
                                       virDomainObjPtr vm);
7a3408
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy-q35.args b/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy-q35.args
7a3408
new file mode 100644
7a3408
index 0000000..464bfa9
7a3408
--- /dev/null
7a3408
+++ b/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy-q35.args
7a3408
@@ -0,0 +1,12 @@
7a3408
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
7a3408
+/usr/bin/qemu -S \
7a3408
+-M pc-q35-2.4 \
7a3408
+-m 214 -smp 1 \
7a3408
+-nographic -nodefaults \
7a3408
+-monitor unix:/tmp/test-monitor,server,nowait \
7a3408
+-no-acpi -boot a \
7a3408
+-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e \
7a3408
+-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x1 \
7a3408
+-drive file=/tmp/firmware.img,if=none,id=drive-fdc0-0-0 \
7a3408
+-device isa-fdc,driveA=drive-fdc0-0-0 \
7a3408
+-device virtio-balloon-pci,id=balloon0,bus=pci.2,addr=0x3
7a3408
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy-q35.xml b/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy-q35.xml
7a3408
new file mode 100644
7a3408
index 0000000..70d3262
7a3408
--- /dev/null
7a3408
+++ b/tests/qemuxml2argvdata/qemuxml2argv-boot-floppy-q35.xml
7a3408
@@ -0,0 +1,40 @@
7a3408
+<domain type='qemu'>
7a3408
+  <name>QEMUGuest1</name>
7a3408
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
7a3408
+  <memory unit='KiB'>219100</memory>
7a3408
+  <currentMemory unit='KiB'>219100</currentMemory>
7a3408
+  <vcpu placement='static'>1</vcpu>
7a3408
+  <os>
7a3408
+    <type arch='x86_64' machine='pc-q35-2.4'>hvm</type>
7a3408
+    <boot dev='fd'/>
7a3408
+  </os>
7a3408
+  <clock offset='utc'/>
7a3408
+  <on_poweroff>destroy</on_poweroff>
7a3408
+  <on_reboot>restart</on_reboot>
7a3408
+  <on_crash>destroy</on_crash>
7a3408
+  <devices>
7a3408
+    <emulator>/usr/bin/qemu</emulator>
7a3408
+    <disk type='file' device='floppy'>
7a3408
+      <driver name='qemu' type='raw'/>
7a3408
+      <source file='/tmp/firmware.img'/>
7a3408
+      <target dev='fda' bus='fdc'/>
7a3408
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
7a3408
+    </disk>
7a3408
+    <controller type='sata' index='0'>
7a3408
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
7a3408
+    </controller>
7a3408
+    <controller type='pci' index='0' model='pcie-root'/>
7a3408
+    <controller type='pci' index='1' model='dmi-to-pci-bridge'>
7a3408
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1e' function='0x0'/>
7a3408
+    </controller>
7a3408
+    <controller type='pci' index='2' model='pci-bridge'>
7a3408
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x01' function='0x0'/>
7a3408
+    </controller>
7a3408
+    <controller type='fdc' index='0'/>
7a3408
+    <input type='mouse' bus='ps2'/>
7a3408
+    <input type='keyboard' bus='ps2'/>
7a3408
+    <memballoon model='virtio'>
7a3408
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x03' function='0x0'/>
7a3408
+    </memballoon>
7a3408
+  </devices>
7a3408
+</domain>
7a3408
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-bootindex-floppy-q35.args b/tests/qemuxml2argvdata/qemuxml2argv-bootindex-floppy-q35.args
7a3408
new file mode 100644
7a3408
index 0000000..2f0627b
7a3408
--- /dev/null
7a3408
+++ b/tests/qemuxml2argvdata/qemuxml2argv-bootindex-floppy-q35.args
7a3408
@@ -0,0 +1,11 @@
7a3408
+LC_ALL=C PATH=/bin HOME=/home/test USER=test LOGNAME=test QEMU_AUDIO_DRV=none \
7a3408
+/usr/bin/qemu -S -M pc-q35-2.4 \
7a3408
+-m 214 -smp 1 \
7a3408
+-nographic -nodefaults \
7a3408
+-monitor unix:/tmp/test-monitor,server,nowait \
7a3408
+-no-acpi \
7a3408
+-device i82801b11-bridge,id=pci.1,bus=pcie.0,addr=0x1e \
7a3408
+-device pci-bridge,chassis_nr=2,id=pci.2,bus=pci.1,addr=0x1 \
7a3408
+-drive file=/tmp/firmware.img,if=none,id=drive-fdc0-0-0 \
7a3408
+-device isa-fdc,driveA=drive-fdc0-0-0,bootindexA=1 \
7a3408
+-device virtio-balloon-pci,id=balloon0,bus=pci.2,addr=0x3
7a3408
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-bootindex-floppy-q35.xml b/tests/qemuxml2argvdata/qemuxml2argv-bootindex-floppy-q35.xml
7a3408
new file mode 100644
7a3408
index 0000000..70d3262
7a3408
--- /dev/null
7a3408
+++ b/tests/qemuxml2argvdata/qemuxml2argv-bootindex-floppy-q35.xml
7a3408
@@ -0,0 +1,40 @@
7a3408
+<domain type='qemu'>
7a3408
+  <name>QEMUGuest1</name>
7a3408
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
7a3408
+  <memory unit='KiB'>219100</memory>
7a3408
+  <currentMemory unit='KiB'>219100</currentMemory>
7a3408
+  <vcpu placement='static'>1</vcpu>
7a3408
+  <os>
7a3408
+    <type arch='x86_64' machine='pc-q35-2.4'>hvm</type>
7a3408
+    <boot dev='fd'/>
7a3408
+  </os>
7a3408
+  <clock offset='utc'/>
7a3408
+  <on_poweroff>destroy</on_poweroff>
7a3408
+  <on_reboot>restart</on_reboot>
7a3408
+  <on_crash>destroy</on_crash>
7a3408
+  <devices>
7a3408
+    <emulator>/usr/bin/qemu</emulator>
7a3408
+    <disk type='file' device='floppy'>
7a3408
+      <driver name='qemu' type='raw'/>
7a3408
+      <source file='/tmp/firmware.img'/>
7a3408
+      <target dev='fda' bus='fdc'/>
7a3408
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
7a3408
+    </disk>
7a3408
+    <controller type='sata' index='0'>
7a3408
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
7a3408
+    </controller>
7a3408
+    <controller type='pci' index='0' model='pcie-root'/>
7a3408
+    <controller type='pci' index='1' model='dmi-to-pci-bridge'>
7a3408
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1e' function='0x0'/>
7a3408
+    </controller>
7a3408
+    <controller type='pci' index='2' model='pci-bridge'>
7a3408
+      <address type='pci' domain='0x0000' bus='0x01' slot='0x01' function='0x0'/>
7a3408
+    </controller>
7a3408
+    <controller type='fdc' index='0'/>
7a3408
+    <input type='mouse' bus='ps2'/>
7a3408
+    <input type='keyboard' bus='ps2'/>
7a3408
+    <memballoon model='virtio'>
7a3408
+      <address type='pci' domain='0x0000' bus='0x02' slot='0x03' function='0x0'/>
7a3408
+    </memballoon>
7a3408
+  </devices>
7a3408
+</domain>
7a3408
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
7a3408
index 574777b..bee6637 100644
7a3408
--- a/tests/qemuxml2argvtest.c
7a3408
+++ b/tests/qemuxml2argvtest.c
7a3408
@@ -607,6 +607,15 @@ mymain(void)
7a3408
     DO_TEST("boot-cdrom", NONE);
7a3408
     DO_TEST("boot-network", NONE);
7a3408
     DO_TEST("boot-floppy", NONE);
7a3408
+    DO_TEST("boot-floppy-q35",
7a3408
+            QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_PCI_BRIDGE,
7a3408
+            QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
7a3408
+            QEMU_CAPS_DRIVE, QEMU_CAPS_ICH9_AHCI);
7a3408
+    DO_TEST("bootindex-floppy-q35",
7a3408
+            QEMU_CAPS_DEVICE, QEMU_CAPS_DEVICE_PCI_BRIDGE,
7a3408
+            QEMU_CAPS_DEVICE_DMI_TO_PCI_BRIDGE,
7a3408
+            QEMU_CAPS_DRIVE, QEMU_CAPS_ICH9_AHCI, QEMU_CAPS_BOOT_MENU,
7a3408
+            QEMU_CAPS_BOOTINDEX);
7a3408
     DO_TEST("boot-multi", QEMU_CAPS_BOOT_MENU);
7a3408
     DO_TEST("boot-menu-enable",
7a3408
             QEMU_CAPS_BOOT_MENU, QEMU_CAPS_DEVICE, QEMU_CAPS_DRIVE);
7a3408
-- 
7a3408
2.4.5
7a3408