Blame SOURCES/kvm-pc-bios-s390-ccw-Scan-through-all-devices-if-no-boot.patch

f66865
From 911dc631f9ab68c6acfd4b401fbcfaa3b58a4fb6 Mon Sep 17 00:00:00 2001
f66865
From: Thomas Huth <thuth@redhat.com>
f66865
Date: Fri, 9 Oct 2020 10:08:46 -0400
f66865
Subject: [PATCH 10/14] pc-bios/s390-ccw: Scan through all devices if no boot
f66865
 device specified
f66865
f66865
RH-Author: Thomas Huth <thuth@redhat.com>
f66865
Message-id: <20201009100849.264994-7-thuth@redhat.com>
f66865
Patchwork-id: 98600
f66865
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 6/9] pc-bios/s390-ccw: Scan through all devices if no boot device specified
f66865
Bugzilla: 1846975
f66865
RH-Acked-by: Jens Freimann <jfreimann@redhat.com>
f66865
RH-Acked-by: David Hildenbrand <david@redhat.com>
f66865
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
f66865
f66865
If no boot device has been specified (via "bootindex=..."), the s390-ccw
f66865
bios scans through all devices to find a bootable device. But so far, it
f66865
stops at the very first block device (including virtio-scsi controllers
f66865
without attached devices) that it finds, no matter whether it is bootable
f66865
or not. That leads to some weird situatation where it is e.g. possible
f66865
to boot via:
f66865
f66865
 qemu-system-s390x -hda /path/to/disk.qcow2
f66865
f66865
but not if there is e.g. a virtio-scsi controller specified before:
f66865
f66865
 qemu-system-s390x -device virtio-scsi -hda /path/to/disk.qcow2
f66865
f66865
While using "bootindex=..." is clearly the preferred way of booting
f66865
on s390x, we still can make the life for the users at least a little
f66865
bit easier if we look at all available devices to find a bootable one.
f66865
f66865
Buglink: https://bugzilla.redhat.com/show_bug.cgi?id=1846975
f66865
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
f66865
Message-Id: <20200806105349.632-7-thuth@redhat.com>
f66865
Signed-off-by: Thomas Huth <thuth@redhat.com>
f66865
(cherry picked from commit 869d0e2f593dd37297c366203f006b9acd1b7b45)
f66865
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
f66865
---
f66865
 pc-bios/s390-ccw/main.c | 46 +++++++++++++++++++++++++++--------------
f66865
 1 file changed, 31 insertions(+), 15 deletions(-)
f66865
f66865
diff --git a/pc-bios/s390-ccw/main.c b/pc-bios/s390-ccw/main.c
f66865
index 456733fbee..5c1c98341d 100644
f66865
--- a/pc-bios/s390-ccw/main.c
f66865
+++ b/pc-bios/s390-ccw/main.c
f66865
@@ -191,20 +191,8 @@ static void boot_setup(void)
f66865
 static void find_boot_device(void)
f66865
 {
f66865
     VDev *vdev = virtio_get_device();
f66865
-    int ssid;
f66865
     bool found;
f66865
 
f66865
-    if (!have_iplb) {
f66865
-        for (ssid = 0; ssid < 0x3; ssid++) {
f66865
-            blk_schid.ssid = ssid;
f66865
-            found = find_subch(-1);
f66865
-            if (found) {
f66865
-                return;
f66865
-            }
f66865
-        }
f66865
-        panic("Could not find a suitable boot device (none specified)\n");
f66865
-    }
f66865
-
f66865
     switch (iplb.pbt) {
f66865
     case S390_IPL_TYPE_CCW:
f66865
         debug_print_int("device no. ", iplb.ccw.devno);
f66865
@@ -270,14 +258,42 @@ static void ipl_boot_device(void)
f66865
     }
f66865
 }
f66865
 
f66865
+/*
f66865
+ * No boot device has been specified, so we have to scan through the
f66865
+ * channels to find one.
f66865
+ */
f66865
+static void probe_boot_device(void)
f66865
+{
f66865
+    int ssid, sch_no, ret;
f66865
+
f66865
+    for (ssid = 0; ssid < 0x3; ssid++) {
f66865
+        blk_schid.ssid = ssid;
f66865
+        for (sch_no = 0; sch_no < 0x10000; sch_no++) {
f66865
+            ret = is_dev_possibly_bootable(-1, sch_no);
f66865
+            if (ret < 0) {
f66865
+                break;
f66865
+            }
f66865
+            if (ret == true) {
f66865
+                ipl_boot_device();      /* Only returns if unsuccessful */
f66865
+            }
f66865
+        }
f66865
+    }
f66865
+
f66865
+    sclp_print("Could not find a suitable boot device (none specified)\n");
f66865
+}
f66865
+
f66865
 int main(void)
f66865
 {
f66865
     sclp_setup();
f66865
     css_setup();
f66865
     boot_setup();
f66865
-    find_boot_device();
f66865
-    enable_subchannel(blk_schid);
f66865
-    ipl_boot_device();
f66865
+    if (have_iplb) {
f66865
+        find_boot_device();
f66865
+        enable_subchannel(blk_schid);
f66865
+        ipl_boot_device();
f66865
+    } else {
f66865
+        probe_boot_device();
f66865
+    }
f66865
 
f66865
     panic("Failed to load OS from hard disk\n");
f66865
     return 0; /* make compiler happy */
f66865
-- 
f66865
2.27.0
f66865