File kdump-try-both-kexec_load-and-kexec_file_load.patch of Package kdump.21349

From: Lance Wang <lzwang@suse.com>
Date: Tue, 16 Jan 2018 13:53:40 +0100
Subject: Try both kexec_load(2) and kexec_file_load(2)
References: bsc#951144
Upstream: merged
Git-commit: ab9c22489ef7627e3f0ad67f46ea19e8d401d044

The logic in load.sh will use kexec_load first. If kexec_load fails
or is blocked by kernel, then it will try kexec_load_file on
x86_64.

Signed-off-by: Joey Lee <jlee@suse.com>
Signed-off-by: Lance Wang <lzwang@suse.com>
Signed-off-by: Petr Tesarik <ptesarik@suse.com>
---
 init/load.sh |   38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

--- a/init/load.sh
+++ b/init/load.sh
@@ -138,11 +138,6 @@ function build_kexec_options()
         options="$options --noio"
     fi
 
-    # add -s on x86_64 for signature verification of kernel
-    if [ "$(uname -i)" = "x86_64" ] ; then
-	options="$options -s"
-    fi
-
     echo "$options"
 }
 
@@ -151,6 +146,7 @@ function build_kexec_options()
 function load_kdump_kexec()
 {
     local result
+    local output
 
     if [ ! -f "$kdump_initrd" ] ; then
         echo "No kdump initial ramdisk found. Tried to locate $kdump_initrd."
@@ -163,19 +159,35 @@ function load_kdump_kexec()
     KEXEC_CALL="$KEXEC -p $kdump_kernel --append=\"$kdump_commandline\""
     KEXEC_CALL="$KEXEC_CALL --initrd=$kdump_initrd $kexec_options"
 
-    kdump_echo "Loading kdump kernel: $KEXEC_CALL"
+    kdump_echo "Starting load kdump kernel with kexec_file_load(2)"
+    kdump_echo "kexec cmdline: $KEXEC_CALL -s"
 
-    local output
-    output=$(eval "$KEXEC_CALL" 2>&1)
-    if [ $? -eq 0 ] ; then
-	result=0
-    else
-	result=1
+    output=$(eval "$KEXEC_CALL -s" 2>&1)
+    result=$?
+    if [ $result -eq 255 ] ; then
+        echo $output | grep -q 'syscall kexec_file_load not available' && result=7
     fi
 
     # print stderr in any case to show warnings that normally
     # would be supressed (bnc#374185)
-    echo -n "$output"
+    echo -n "$output"; echo
+
+    if [ $result -eq 0 ] ; then
+        kdump_logger "Loaded kdump kernel: $KEXEC_CALL -s, Result: $output"
+        return 0
+    elif [ $result -ne 7 ]; then
+        kdump_logger "FAILED to load kdump kernel: $KEXEC_CALL -s, Result: $output"
+        return $result
+    fi
+
+    # kexec_file_load(2) not available
+    kdump_echo "kexec_file_load(2) not available"
+    kdump_echo "Starting load kdump kernel with kexec_load(2)"
+    kdump_echo "kexec cmdline: $KEXEC_CALL"
+
+    output=$(eval "$KEXEC_CALL" 2>&1)
+    result=$?
+    echo -n "$output";echo
 
     if [ $result -eq 0 ] ; then
         kdump_logger "Loaded kdump kernel: $KEXEC_CALL, Result: $output"
openSUSE Build Service is sponsored by