Users may want to specify their own "nr_cpus{maxcpus}=X",
in order not to cause conflicts, we need a way to explicitly
activate the nr_cpus automatic calculation. Default is off.
After the number of kdump cpus was determined, we also modify
"/etc/sysconfig/kdump" to announce the change.
Leave the implementation of calculate_kdump_cpus() to the
following patch.
Signed-off-by: Xunlei Pang <xlpang(a)redhat.com>
---
kdump.conf | 7 +++++++
kdumpctl | 41 ++++++++++++++++++++++++++++++++++++++---
2 files changed, 45 insertions(+), 3 deletions(-)
diff --git a/kdump.conf b/kdump.conf
index ebf9587..f170339 100644
--- a/kdump.conf
+++ b/kdump.conf
@@ -133,6 +133,12 @@
# fence_kdump notifications to (this option is mandatory to
# enable fence_kdump).
#
+# calc_kdump_cpus <0 | 1>
+# - By default, kdump will boot with the number of cpus specified
+# in "/etc/sysconfig/kdump" which is only one cpu by default.
+# Specify 1 to let kexec-tools intelligently caculate the number
+# of cpus for kdump kernel to boot with.
+#
#raw /dev/vg/lv_kdump
#ext4 /dev/vg/lv_kdump
@@ -153,3 +159,4 @@ core_collector makedumpfile -l --message-level 1 -d 31
#dracut_args --omit-drivers "cfg80211 snd" --add-drivers "ext2 ext3"
#fence_kdump_args -p 7410 -f auto -c 0 -i 10
#fence_kdump_nodes node1 node2
+#calc_kdump_cpus 1
diff --git a/kdumpctl b/kdumpctl
index ce71138..9cd785a 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -5,6 +5,7 @@ KDUMP_KERNELVER=""
KDUMP_COMMANDLINE=""
KEXEC_ARGS=""
KDUMP_CONFIG_FILE="/etc/kdump.conf"
+KDUMP_SYSCONFIG_FILE="/etc/sysconfig/kdump"
MKDUMPRD="/sbin/mkdumprd -f"
SAVE_PATH=/var/crash
SSH_KEY_LOCATION="/root/.ssh/kdump_id_rsa"
@@ -54,10 +55,44 @@ determine_dump_mode()
fi
}
+calculate_kdump_cpus()
+{
+ echo -n "1"
+}
+
+# Automatically choose the number of cpus used by kdump kernel,
+# and replace the old one in $KDUMP_COMMANDLINE_APPEND with it.
+determine_kdump_cpus()
+{
+ local _calc_needed calc_needed=0
+ local cpus
+
+ # No reserved memory case, simply return.
+ if [ "$(get_reserved_memory_mb)" -eq 0 ]; then
+ return
+ fi
+
+ _calc_needed=$(grep ^calc_kdump_cpus $KDUMP_CONFIG_FILE 2>/dev/null)
+ if [ $? -eq 0 ]; then
+ calc_needed=$(echo $_calc_needed | cut -d' ' -f2)
+ fi
+
+ if [ "$calc_needed" = 0 ]; then
+ return
+ fi
+
+ # We need to calculate the number of cpus for kdump kernel, and
+ # replace "nr_cpus{maxcpus}=X" with our caculated result.
+ cpus=$(calculate_kdump_cpus)
+ sed -i $KDUMP_SYSCONFIG_FILE -e "s/nr_cpus=[0-9]*/nr_cpus=$cpus/g"
+ sed -i $KDUMP_SYSCONFIG_FILE -e "s/maxcpus=[0-9]*/maxcpus=$cpus/g"
+}
+
determine_kdump_sysconfig()
{
- if [ -f /etc/sysconfig/kdump ]; then
- . /etc/sysconfig/kdump
+ if [ -f "$KDUMP_SYSCONFIG_FILE" ]; then
+ determine_kdump_cpus
+ . $KDUMP_SYSCONFIG_FILE
fi
}
@@ -287,7 +322,7 @@ check_config()
case "$config_opt" in
\#* | "")
;;
- raw|ext2|ext3|ext4|minix|btrfs|xfs|nfs|ssh|sshkey|path|core_collector|kdump_post|kdump_pre|extra_bins|extra_modules|default|force_rebuild|dracut_args|fence_kdump_args|fence_kdump_nodes)
+ raw|ext2|ext3|ext4|minix|btrfs|xfs|nfs|ssh|sshkey|path|core_collector|kdump_post|kdump_pre|extra_bins|extra_modules|default|force_rebuild|dracut_args|fence_kdump_args|fence_kdump_nodes|calc_kdump_cpus)
[ -z "$config_val" ] && {
echo "Invalid kdump config value for option $config_opt."
return 1;
--
1.8.3.1