c1c534
From 0d4d7811a11bcd2bf12446425e5e05014faecf52 Mon Sep 17 00:00:00 2001
c1c534
Message-Id: <0d4d7811a11bcd2bf12446425e5e05014faecf52@dist-git>
c1c534
From: Michal Privoznik <mprivozn@redhat.com>
c1c534
Date: Mon, 20 Nov 2017 11:08:53 +0100
c1c534
Subject: [PATCH] qemuBuildDriveDevStr: Prefer default alias for SATA bus
c1c534
c1c534
https://bugzilla.redhat.com/show_bug.cgi?id=1434451
c1c534
c1c534
Just like in 9324f67a572f9b32 we need to put default sata alias
c1c534
(which is hardcoded to "ide", obvious, right?) onto the command
c1c534
line instead of the one provided by user.
c1c534
c1c534
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c1c534
(cherry picked from commit f66e5896ad6013c2f31eef1c909999b33ba8847e)
c1c534
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c1c534
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
c1c534
---
c1c534
 src/qemu/qemu_command.c                            | 15 ++++++++--
c1c534
 .../qemuxml2argv-user-aliases2.args                |  1 +
c1c534
 .../qemuxml2argv-user-aliases2.xml                 | 34 ++++++++++++++++++++++
c1c534
 tests/qemuxml2argvtest.c                           |  1 +
c1c534
 4 files changed, 48 insertions(+), 3 deletions(-)
c1c534
 create mode 120000 tests/qemuxml2argvdata/qemuxml2argv-user-aliases2.args
c1c534
 create mode 100644 tests/qemuxml2argvdata/qemuxml2argv-user-aliases2.xml
c1c534
c1c534
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
c1c534
index 272ef610a3..7dc7387a15 100644
c1c534
--- a/src/qemu/qemu_command.c
c1c534
+++ b/src/qemu/qemu_command.c
c1c534
@@ -2076,9 +2076,18 @@ qemuBuildDriveDevStr(const virDomainDef *def,
c1c534
             virBufferAddLit(&opt, "ide-drive");
c1c534
         }
c1c534
 
c1c534
-        if (!(contAlias = virDomainControllerAliasFind(def, VIR_DOMAIN_CONTROLLER_TYPE_SATA,
c1c534
-                                                      disk->info.addr.drive.controller)))
c1c534
-           goto error;
c1c534
+        /* When domain has builtin SATA controller we don't put it onto cmd
c1c534
+         * line. Therefore we can't set its alias. In that case, use the
c1c534
+         * default one. */
c1c534
+        if (qemuDomainIsQ35(def) &&
c1c534
+            disk->info.addr.drive.controller == 0) {
c1c534
+            contAlias = "ide";
c1c534
+        } else {
c1c534
+            if (!(contAlias = virDomainControllerAliasFind(def,
c1c534
+                                                           VIR_DOMAIN_CONTROLLER_TYPE_SATA,
c1c534
+                                                           disk->info.addr.drive.controller)))
c1c534
+                goto error;
c1c534
+        }
c1c534
         virBufferAsprintf(&opt, ",bus=%s.%d",
c1c534
                           contAlias,
c1c534
                           disk->info.addr.drive.unit);
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-user-aliases2.args b/tests/qemuxml2argvdata/qemuxml2argv-user-aliases2.args
c1c534
new file mode 120000
c1c534
index 0000000000..e029bc0ec8
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-user-aliases2.args
c1c534
@@ -0,0 +1 @@
c1c534
+qemuxml2argv-boot-floppy-q35.args
c1c534
\ No newline at end of file
c1c534
diff --git a/tests/qemuxml2argvdata/qemuxml2argv-user-aliases2.xml b/tests/qemuxml2argvdata/qemuxml2argv-user-aliases2.xml
c1c534
new file mode 100644
c1c534
index 0000000000..a288b86117
c1c534
--- /dev/null
c1c534
+++ b/tests/qemuxml2argvdata/qemuxml2argv-user-aliases2.xml
c1c534
@@ -0,0 +1,34 @@
c1c534
+<domain type='qemu'>
c1c534
+  <name>QEMUGuest1</name>
c1c534
+  <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
c1c534
+  <memory unit='KiB'>219100</memory>
c1c534
+  <currentMemory unit='KiB'>219100</currentMemory>
c1c534
+  <vcpu placement='static'>1</vcpu>
c1c534
+  <os>
c1c534
+    <type arch='x86_64' machine='pc-q35-2.4'>hvm</type>
c1c534
+    <boot dev='fd'/>
c1c534
+  </os>
c1c534
+  <clock offset='utc'/>
c1c534
+  <on_poweroff>destroy</on_poweroff>
c1c534
+  <on_reboot>restart</on_reboot>
c1c534
+  <on_crash>destroy</on_crash>
c1c534
+  <devices>
c1c534
+    <emulator>/usr/bin/qemu-system-x86_64</emulator>
c1c534
+    <disk type='file' device='floppy'>
c1c534
+      <driver name='qemu' type='raw'/>
c1c534
+      <source file='/tmp/firmware.img'/>
c1c534
+      <target dev='fda' bus='fdc'/>
c1c534
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
c1c534
+    </disk>
c1c534
+    <controller type='sata' index='0'>
c1c534
+      <address type='pci' domain='0x0000' bus='0x00' slot='0x1f' function='0x2'/>
c1c534
+    </controller>
c1c534
+    <controller type='pci' index='0' model='pcie-root'>
c1c534
+      <alias name='ua-MySataController'/>
c1c534
+    </controller>
c1c534
+    <controller type='fdc' index='0'/>
c1c534
+    <input type='mouse' bus='ps2'/>
c1c534
+    <input type='keyboard' bus='ps2'/>
c1c534
+    <memballoon model='none'/>
c1c534
+  </devices>
c1c534
+</domain>
c1c534
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
c1c534
index ecc86d045c..ff9c8608aa 100644
c1c534
--- a/tests/qemuxml2argvtest.c
c1c534
+++ b/tests/qemuxml2argvtest.c
c1c534
@@ -2827,6 +2827,7 @@ mymain(void)
c1c534
             QEMU_CAPS_OBJECT_MEMORY_FILE, QEMU_CAPS_PIIX_DISABLE_S3,
c1c534
             QEMU_CAPS_PIIX_DISABLE_S4, QEMU_CAPS_VNC,
c1c534
             QEMU_CAPS_HDA_DUPLEX);
c1c534
+    DO_TEST("user-aliases2", QEMU_CAPS_DEVICE_IOH3420, QEMU_CAPS_ICH9_AHCI);
c1c534
 
c1c534
     if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL)
c1c534
         virFileDeleteTree(fakerootdir);
c1c534
-- 
c1c534
2.15.0
c1c534