Blame SOURCES/kvm-pc-bios-s390-ccw-fix-non-sequential-boot-entries-eck.patch

1bdc94
From 3ded1fcf70af2fa1a3a785b777e7f724bd285fc3 Mon Sep 17 00:00:00 2001
1bdc94
From: Thomas Huth <thuth@redhat.com>
1bdc94
Date: Mon, 7 May 2018 07:58:07 +0200
1bdc94
Subject: [PATCH 11/13] pc-bios/s390-ccw: fix non-sequential boot entries
1bdc94
 (eckd)
1bdc94
1bdc94
RH-Author: Thomas Huth <thuth@redhat.com>
1bdc94
Message-id: <1525679888-9234-6-git-send-email-thuth@redhat.com>
1bdc94
Patchwork-id: 80053
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-ma PATCH 5/6] pc-bios/s390-ccw: fix non-sequential boot entries (eckd)
1bdc94
Bugzilla: 1523857
1bdc94
RH-Acked-by: David Hildenbrand <david@redhat.com>
1bdc94
RH-Acked-by: Cornelia Huck <cohuck@redhat.com>
1bdc94
RH-Acked-by: Laszlo Ersek <lersek@redhat.com>
1bdc94
1bdc94
From: Collin Walling <walling@linux.ibm.com>
1bdc94
1bdc94
zIPL boot menu entries can be non-sequential. Let's account
1bdc94
for this issue for the s390 zIPL boot menu. Since this boot
1bdc94
menu is actually an imitation and is not completely capable
1bdc94
of everything the real zIPL menu can do, let's also print a
1bdc94
different banner to the user.
1bdc94
1bdc94
Signed-off-by: Collin Walling <walling@linux.ibm.com>
1bdc94
Reported-by: Vasily Gorbik <gor@linux.ibm.com>
1bdc94
Reviewed-by: Thomas Huth <thuth@redhat.com>
1bdc94
Reviewed-by: Janosch Frank <frankja@linux.ibm.com>
1bdc94
Signed-off-by: Thomas Huth <thuth@redhat.com>
1bdc94
(cherry picked from commit 7385e947fc65a44dd05abb86c874beb915c1989c)
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 pc-bios/s390-ccw/menu.c | 29 ++++++++++++++++++++---------
1bdc94
 1 file changed, 20 insertions(+), 9 deletions(-)
1bdc94
1bdc94
diff --git a/pc-bios/s390-ccw/menu.c b/pc-bios/s390-ccw/menu.c
1bdc94
index 96eec81..aaf5d61 100644
1bdc94
--- a/pc-bios/s390-ccw/menu.c
1bdc94
+++ b/pc-bios/s390-ccw/menu.c
1bdc94
@@ -158,7 +158,7 @@ static void boot_menu_prompt(bool retry)
1bdc94
     }
1bdc94
 }
1bdc94
 
1bdc94
-static int get_boot_index(int entries)
1bdc94
+static int get_boot_index(bool *valid_entries)
1bdc94
 {
1bdc94
     int boot_index;
1bdc94
     bool retry = false;
1bdc94
@@ -168,7 +168,8 @@ static int get_boot_index(int entries)
1bdc94
         boot_menu_prompt(retry);
1bdc94
         boot_index = get_index();
1bdc94
         retry = true;
1bdc94
-    } while (boot_index < 0 || boot_index >= entries);
1bdc94
+    } while (boot_index < 0 || boot_index >= MAX_BOOT_ENTRIES ||
1bdc94
+             !valid_entries[boot_index]);
1bdc94
 
1bdc94
     sclp_print("\nBooting entry #");
1bdc94
     sclp_print(uitoa(boot_index, tmp, sizeof(tmp)));
1bdc94
@@ -176,7 +177,8 @@ static int get_boot_index(int entries)
1bdc94
     return boot_index;
1bdc94
 }
1bdc94
 
1bdc94
-static void zipl_println(const char *data, size_t len)
1bdc94
+/* Returns the entry number that was printed */
1bdc94
+static int zipl_print_entry(const char *data, size_t len)
1bdc94
 {
1bdc94
     char buf[len + 2];
1bdc94
 
1bdc94
@@ -185,12 +187,15 @@ static void zipl_println(const char *data, size_t len)
1bdc94
     buf[len + 1] = '\0';
1bdc94
 
1bdc94
     sclp_print(buf);
1bdc94
+
1bdc94
+    return buf[0] == ' ' ? atoui(buf + 1) : atoui(buf);
1bdc94
 }
1bdc94
 
1bdc94
 int menu_get_zipl_boot_index(const char *menu_data)
1bdc94
 {
1bdc94
     size_t len;
1bdc94
-    int entries;
1bdc94
+    int entry;
1bdc94
+    bool valid_entries[MAX_BOOT_ENTRIES] = {false};
1bdc94
     uint16_t zipl_flag = *(uint16_t *)(menu_data - ZIPL_FLAG_OFFSET);
1bdc94
     uint16_t zipl_timeout = *(uint16_t *)(menu_data - ZIPL_TIMEOUT_OFFSET);
1bdc94
 
1bdc94
@@ -202,19 +207,25 @@ int menu_get_zipl_boot_index(const char *menu_data)
1bdc94
         timeout = zipl_timeout * 1000;
1bdc94
     }
1bdc94
 
1bdc94
-    /* Print and count all menu items, including the banner */
1bdc94
-    for (entries = 0; *menu_data; entries++) {
1bdc94
+    /* Print banner */
1bdc94
+    sclp_print("s390-ccw zIPL Boot Menu\n\n");
1bdc94
+    menu_data += strlen(menu_data) + 1;
1bdc94
+
1bdc94
+    /* Print entries */
1bdc94
+    while (*menu_data) {
1bdc94
         len = strlen(menu_data);
1bdc94
-        zipl_println(menu_data, len);
1bdc94
+        entry = zipl_print_entry(menu_data, len);
1bdc94
         menu_data += len + 1;
1bdc94
 
1bdc94
-        if (entries < 2) {
1bdc94
+        valid_entries[entry] = true;
1bdc94
+
1bdc94
+        if (entry == 0) {
1bdc94
             sclp_print("\n");
1bdc94
         }
1bdc94
     }
1bdc94
 
1bdc94
     sclp_print("\n");
1bdc94
-    return get_boot_index(entries - 1); /* subtract 1 to exclude banner */
1bdc94
+    return get_boot_index(valid_entries);
1bdc94
 }
1bdc94
 
1bdc94
 
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94