Scratch this patch, will update later and send v2.

On Thu, Jul 19, 2018 at 6:41 PM Kairui Song <kasong@redhat.com> wrote:
Currently, we only rebuilt kdump initramfs on config file change,
fs change, or watchdog related change. This will not cover the case
that hardware changed but fs layout and other configurations still
stays the same, and kdump may fail.

To cover such case, we can detect and compare loaded kernel modules,
if a hardware change requires the image to be rebuilt, loaded kernel
modules must have changed.

Starting from commit 7047294 dracut will record loaded kernel modules
when the image is built if hostonly mode is enabled.  With this patch,
kdumpctl will compare the recorded value with currently loaded kernel
modules, and rebuild the image on change.

Signed-off-by: Kairui Song <kasong@redhat.com>
---
 kdumpctl | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/kdumpctl b/kdumpctl
index 13b8209..6260c50 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -458,6 +458,30 @@ check_wdt_modified()
        return 1
 }

+check_kmodules_modified()
+{
+       local _old_modules="$(lsinitrd $TARGET_INITRD -f */lib/dracut/loaded-kernel-modules.txt)"
+       local _new_modules="$(get_loaded_kernel_modules)"
+
+       [[ -z $_old_modules ]] && return 0
+
+       local _added_modules=$(comm -13 <(echo "$_old_modules" | sort) <(echo "$_new_modules" | sort))
+       local _dropped_modules=$(comm -23 <(echo "$_old_modules" | sort) <(echo "$_new_modules" | sort))
+
+       if [ "$_old_modules" != "$_new_modules" ]; then
+               echo "Detected change(s) of loaded kernel modules list:"
+               [[ -n $_added_modules ]] && for _module in $_added_modules; do
+                       echo "  +$_module"
+               done
+               [[ -n $_dropped_modules ]] && for _module in $_dropped_modules; do
+                       echo "  -$_module"
+               done
+               return 1
+       fi
+
+       return 0
+}
+
 # returns 0 if system is not modified
 # returns 1 if system is modified
 # returns 2 if system modification is invalid
@@ -485,6 +509,11 @@ check_system_modified()
                return 1
        fi

+       check_kmodules_modified
+       if [ $? -ne 0 ]; then
+               return 1
+       fi
+
        return 0
 }

--
2.17.1
_______________________________________________
kexec mailing list -- kexec@lists.fedoraproject.org
To unsubscribe send an email to kexec-leave@lists.fedoraproject.org
Fedora Code of Conduct: https://getfedora.org/code-of-conduct.html
List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines
List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org/message/TEY4NI5XNUXJJEO4Q54GTKRJSKPN5MJH/


--
Best Regards,
Kairui Song