This is based on previous clean up patches in: [PATCH 0/5] Simplify bind mount handling and clean up
Currently kexec-tools always depend on dump target to be mounted, which caused some inconvenience for setup.
So for user configured target, allow kdump to start and build initramfs even if target is not mounted.
When a mounted user configured target is used, the behavior is not changed.
When a unmounted user configured target is used, mkdumprd will look for corresponding mount info in fstab, and a entry with noauto option is founded, mkdumprd will try to mount it inplace with optoins specified in fstab and do basic checks on the device, then umount it.
If there is no fstab entry, mkdumprd will try to mount it in temporary path with defaults option, do same basic check and umount it.
If there is a fstab entry but "noauto" option is not used, then there must be some reason that the target device is not mounted, mkdumprd will error out.
When path based target is used, there is no behavior change.
Some examples:
Example 1, target is mounted kdump.conf: nfs 192.168.122.1:/srv/local/nfs path /var/crash core_collector makedumpfile -l --message-level 1 -d 31
mount info (from mount command): 192.168.122.1:/srv/local/nfs on /var/mnt/nfs2 type nfs4 (rw,relatime,vers=4.2,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.122.249,local_lock=none,addr=192.168.122.1)
mkdumprd will just do do basic kdump checks (fs size, path accisibility), and then build the initramfs using current mount info (mount point, target and options from current system).
Example 2, target is not mounted, and marked noauto in fstab: kdump.conf: nfs 192.168.122.1:/srv/local/nfs path /var/crash core_collector makedumpfile -l --message-level 1 -d 31
fstab: 192.168.122.1:/srv/local/nfs /mnt/nfs nfs defaults,noauto 0 0
mkdumprd will try to mount 192.168.122.1:/srv/local/nfs on /mnt/nfs, do basic kdump checks, and then build the initramfs using mount info in fstab.
Example 3, target is not mounted, and no entry in fstab: kdump.conf: nfs 192.168.122.1:/srv/local/nfs path /var/crash core_collector makedumpfile -l --message-level 1 -d 31
fstab or current mount: No info related to target.
mkdumprd will try to mount 192.168.122.1:/srv/local/nfs on /tmp/mkdumprd.XXXXXX/target with "mount -o defaults", do basic kdump checks, and then build the initramfs using defaults options.
In second kernel, target will be mounted on /kdumproot using default options.
Kairui Song (6): Fix the problem that kdump prints redundant / Add a is_mounted helper Allow calling mkdumprd from kdumpctl even if targat not mounted kdump-lib.sh: add fstab failback helper for getting mount info User get_mount_info to replace findmnt calls mkdumprd: generate usable kdump initramfs even target is not mounted
kdump-lib-initramfs.sh | 54 ++++++++--------- kdump-lib.sh | 58 +++++++++--------- kdumpctl | 9 +-- mkdumprd | 130 +++++++++++++++++++++++++++++------------ 4 files changed, 153 insertions(+), 98 deletions(-)
In second kernel, kdump always prints redundant '/':
kdump: saving to /sysroot//var/crash/127.0.0.1-2020-03-12-21:32:54/
Just trim it.
Signed-off-by: Kairui Song kasong@redhat.com --- kdump-lib-initramfs.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index a7c0bf9..653c872 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -127,7 +127,9 @@ dump_fs() # Remove -F in makedumpfile case. We don't want a flat format dump here. [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"`
- echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/" + local _dump_path=$(echo "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /) + + echo "kdump: saving to $_dump_path"
# Only remount to read-write mode if the dump target is mounted read-only. if [[ "$_op" = "ro"* ]]; then @@ -135,14 +137,14 @@ dump_fs() mount -o remount,rw $_dev $_mp || return 1 fi
- mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1 + mkdir -p $_dump_path || return 1
- save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/" - save_opalcore_fs "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/" + save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_path" + save_opalcore_fs "$_dump_path"
echo "kdump: saving vmcore" - $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete || return 1 - mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore + $CORE_COLLECTOR /proc/vmcore $_dump_path/vmcore-incomplete || return 1 + mv $_dump_path/vmcore-incomplete $_dump_path/vmcore sync
echo "kdump: saving vmcore complete"
Hi Kairui, On 03/13/20 at 11:03am, Kairui Song wrote:
In second kernel, kdump always prints redundant '/':
kdump: saving to /sysroot//var/crash/127.0.0.1-2020-03-12-21:32:54/
Is the // introduced in $_mp by findmnt? Just be curious.
Just trim it.
Signed-off-by: Kairui Song kasong@redhat.com
kdump-lib-initramfs.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index a7c0bf9..653c872 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -127,7 +127,9 @@ dump_fs() # Remove -F in makedumpfile case. We don't want a flat format dump here. [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"`
- echo "kdump: saving to $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
local _dump_path=$(echo "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/" | tr -s /)
echo "kdump: saving to $_dump_path"
# Only remount to read-write mode if the dump target is mounted read-only. if [[ "$_op" = "ro"* ]]; then
@@ -135,14 +137,14 @@ dump_fs() mount -o remount,rw $_dev $_mp || return 1 fi
- mkdir -p $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR || return 1
- mkdir -p $_dump_path || return 1
- save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
- save_opalcore_fs "$_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/"
save_vmcore_dmesg_fs ${DMESG_COLLECTOR} "$_dump_path"
save_opalcore_fs "$_dump_path"
echo "kdump: saving vmcore"
- $CORE_COLLECTOR /proc/vmcore $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete || return 1
- mv $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore-incomplete $_mp/$KDUMP_PATH/$HOST_IP-$DATEDIR/vmcore
$CORE_COLLECTOR /proc/vmcore $_dump_path/vmcore-incomplete || return 1
mv $_dump_path/vmcore-incomplete $_dump_path/vmcore sync
echo "kdump: saving vmcore complete"
-- 2.24.1 _______________________________________________ kexec mailing list -- kexec@lists.fedoraproject.org To unsubscribe send an email to kexec-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
Use is_mounted helper instaed of calling findmnt directly or checking if "mount" value is empty.
If findmnt looks for fstab as well, some non mounted entry will also return value. Required to support non-mounted target.
Signed-off-by: Kairui Song kasong@redhat.com --- kdump-lib-initramfs.sh | 2 +- kdump-lib.sh | 5 +++++ kdumpctl | 2 +- mkdumprd | 2 +- 4 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 653c872..83fb4c9 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -102,7 +102,7 @@ dump_fs() local _mp=$(findmnt -k -f -n -r -o TARGET $1) local _op=$(findmnt -k -f -n -r -o OPTIONS $1)
- if [ -z "$_mp" ]; then + if ! is_mounted "$_mp"; then _dev=$(findmnt -s -f -n -r -o SOURCE $1) _mp=$(findmnt -s -f -n -r -o TARGET $1) _op=$(findmnt -s -f -n -r -o OPTIONS $1) diff --git a/kdump-lib.sh b/kdump-lib.sh index 64d0603..5be9e46 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -246,6 +246,11 @@ get_target_from_path() echo $_target }
+is_mounted() +{ + findmnt -k -n $1 &>/dev/null +} + get_fs_type_from_target() { findmnt -k -f -n -r -o FSTYPE $1 diff --git a/kdumpctl b/kdumpctl index 3543bc2..76e066b 100755 --- a/kdumpctl +++ b/kdumpctl @@ -475,7 +475,7 @@ check_dump_fs_modified() fi fi
- if ! findmnt $_target >/dev/null; then + if ! is_mounted $_target; then echo "Dump target $_target is probably not mounted." return 2 fi diff --git a/mkdumprd b/mkdumprd index 8802307..16d9c4a 100644 --- a/mkdumprd +++ b/mkdumprd @@ -364,7 +364,7 @@ do extra_modules="$extra_modules $config_val" ;; ext[234]|xfs|btrfs|minix|nfs) - if ! findmnt $config_val >/dev/null; then + if ! is_mounted $config_val; then perror_exit "Dump target $config_val is probably not mounted." fi
Ignore mount check in kdumpctl, mkdumprd will still fail building and exit if target is not mounted.
Signed-off-by: Kairui Song kasong@redhat.com --- kdumpctl | 5 ----- 1 file changed, 5 deletions(-)
diff --git a/kdumpctl b/kdumpctl index 76e066b..3d64675 100755 --- a/kdumpctl +++ b/kdumpctl @@ -475,11 +475,6 @@ check_dump_fs_modified() fi fi
- if ! is_mounted $_target; then - echo "Dump target $_target is probably not mounted." - return 2 - fi - _new_mntpoint="$(get_kdump_path_from_target $_target)" _dracut_args=$(lsinitrd $TARGET_INITRD -f usr/lib/dracut/build-parameter.txt) if [[ -z "$_dracut_args" ]];then
This allows look up mount info even if target is not mounted.
Signed-off-by: Kairui Song kasong@redhat.com --- kdump-lib.sh | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh index 5be9e46..e10a64d 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -236,7 +236,7 @@ get_bind_mount_source() echo $_mntpoint$_path }
-# Return the real underlaying device of a path, ignore bind mounts +# Return the current underlaying device of a path, ignore bind mounts get_target_from_path() { local _target @@ -251,16 +251,31 @@ is_mounted() findmnt -k -n $1 &>/dev/null }
+get_mount_info() +{ + local _info_type=$1 _src_type=$2 _src=$3; shift 3 + local _info=$(findmnt --real -k -n -r -o $_info_type --$_src_type $_src $@) + + [ -z "$_info" ] && [ -e "/etc/fstab" ] && _info=$(findmnt --real -s -n -r -o $_info_type --$_src_type $_src $@) + + echo $_info +} + get_fs_type_from_target() { - findmnt -k -f -n -r -o FSTYPE $1 + get_mount_info FSTYPE source $1 -f +} + +get_mntopt_from_target() +{ + get_mount_info OPTIONS source $1 -f }
# Find the general mount point of a dump target, not the bind mount point get_mntpoint_from_target() { # Expcilitly specify --source to findmnt could ensure non-bind mount is returned - findmnt -k -f -n -r -o TARGET --source $1 + get_mount_info TARGET source $1 -f }
# Get the path where the target will be mounted in kdump kernel
Use get_mount_info so that fstab is used as a failback when look for mount info.
Signed-off-by: Kairui Song kasong@redhat.com --- kdump-lib-initramfs.sh | 40 +++++++++++++++++----------------------- kdump-lib.sh | 1 - kdumpctl | 4 ++-- mkdumprd | 42 +++++++++++++++--------------------------- 4 files changed, 34 insertions(+), 53 deletions(-)
diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 83fb4c9..e9f07d3 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -94,32 +94,25 @@ get_kdump_confs() fi }
-# dump_fs <mount point| device> +# dump_fs <mount point> dump_fs() { - local _do_umount="" - local _dev=$(findmnt -k -f -n -r -o SOURCE $1) - local _mp=$(findmnt -k -f -n -r -o TARGET $1) - local _op=$(findmnt -k -f -n -r -o OPTIONS $1) - - if ! is_mounted "$_mp"; then - _dev=$(findmnt -s -f -n -r -o SOURCE $1) - _mp=$(findmnt -s -f -n -r -o TARGET $1) - _op=$(findmnt -s -f -n -r -o OPTIONS $1) - - if [ -n "$_dev" ] && [ -n "$_mp" ]; then - echo "kdump: dump target $_dev is not mounted, trying to mount..." - mkdir -p $_mp - mount -o $_op $_dev $_mp - - if [ $? -ne 0 ]; then - echo "kdump: mounting failed (mount point: $_mp, option: $_op)" - return 1 - fi - _do_umount=1 - else - echo "kdump: error: Dump target $_dev is not usable" + local _do_umount + local _mp=$1 + local _dev=$(get_mount_info SOURCE target $_mp -f) + local _op=$(get_mount_info OPTIONS target $_mp -f) + + # If dump path have a corresponding device entry but not mounted, mount it. + if [ -n "$_dev" ] && ! is_mounted "$_mp"; then + echo "kdump: dump target $_dev is not mounted, trying to mount..." + mkdir -p $_mp + mount -o $_op $_dev $_mp + + if [ $? -ne 0 ]; then + echo "kdump: mounting failed (mount point: $_mp, option: $_op)" + return 1 fi + _do_umount=1 else echo "kdump: dump target is $_dev" fi @@ -266,6 +259,7 @@ read_kdump_conf() [ -n "$config_val" ] && add_dump_code "dump_fs $config_val" ;; ext[234]|xfs|btrfs|minix|nfs) + config_val=$(get_mntpoint_from_target "$config_val") add_dump_code "dump_fs $config_val" ;; raw) diff --git a/kdump-lib.sh b/kdump-lib.sh index e10a64d..8411d22 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -270,7 +270,6 @@ get_mntopt_from_target() { get_mount_info OPTIONS source $1 -f } - # Find the general mount point of a dump target, not the bind mount point get_mntpoint_from_target() { diff --git a/kdumpctl b/kdumpctl index 3d64675..0bf5c20 100755 --- a/kdumpctl +++ b/kdumpctl @@ -907,8 +907,8 @@ path_to_be_relabeled()
_target=$(local_fs_dump_target) if [[ -n "$_target" ]]; then - _mnt=$(findmnt -k -f -n -r -o TARGET $_target) - if [ -z "$_mnt" ]; then + _mnt=$(get_mntpoint_from_target $_target) + if ! is_mounted "$_mnt"; then return fi else diff --git a/mkdumprd b/mkdumprd index 16d9c4a..a4e3d1e 100644 --- a/mkdumprd +++ b/mkdumprd @@ -51,21 +51,18 @@ add_dracut_sshkey() {
# caller should ensure $1 is valid and mounted in 1st kernel to_mount() { - local _dev=$1 _source _new_mntpoint _fstype _options _mntopts _pdev - - _source=$(findmnt -k -f -n -r -o SOURCE $_dev) - _fstype=$(findmnt -k -f -n -r -o FSTYPE $_dev) - _new_mntpoint=$(get_kdump_path_from_target $_dev) - - [[ -e /etc/fstab ]] && _options=$(findmnt --fstab -f -n -r -o OPTIONS $_dev) - if [ -z "$_options" ]; then - _options=$(findmnt -k -f -n -r -o OPTIONS $_dev) - if [[ $_fstype == "nfs"* ]]; then - _options=$(echo $_options | sed 's/,addr=[^,]*//') - _options=$(echo $_options | sed 's/,proto=[^,]*//') - _options=$(echo $_options | sed 's/,clientaddr=[^,]*//') - fi + local _target=$1 _new_mntpoint _fstype _options _mntopts _pdev + + _fstype=$(get_fs_type_from_target $_target) + _options=$(get_mntopt_from_target $_target) + _new_mntpoint=$(get_kdump_path_from_target $_target) + + if [[ "$_fstype" == "nfs"* ]]; then + _options=$(echo $_options | sed 's/,addr=[^,]*//') + _options=$(echo $_options | sed 's/,proto=[^,]*//') + _options=$(echo $_options | sed 's/,clientaddr=[^,]*//') fi + # mount fs target as rw in 2nd kernel _options=$(echo $_options | sed 's/(^|,)ro($|,)/\1rw\2/g') # filter out 'noauto' here, it will be force appended later, avoid duplication @@ -77,28 +74,19 @@ to_mount() { _options="$_options,noauto"
_mntopts="$_new_mntpoint $_fstype $_options" - # for non-nfs _dev converting to use udev persistent name - if [ -b "$_source" ]; then - _pdev="$(get_persistent_dev $_source)" + # for non-nfs _target converting to use udev persistent name + if [ -b "$_target" ]; then + _pdev="$(get_persistent_dev $_target)" if [ -z "$_pdev" ]; then return 1 fi else - _pdev=$_dev + _pdev=$_target fi
echo "$_pdev $_mntopts" }
-is_readonly_mount() { - local _mnt - _mnt=$(findmnt -k -f -n -r -o OPTIONS $1) - - #fs/proc_namespace.c: show_mountinfo(): - #seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw"); - [[ "$_mnt" =~ ^ro ]] -} - #Function: get_ssh_size #$1=dump target #called from while loop and shouldn't read from stdin, so we're using "ssh -n"
Currently kexec-tools always depend on dump target to be mounted, which caused some inconvenience for setup.
So for user configured target, allow kdump to start and build initramfs even if target is not mounted.
When a mounted user configured target is used, the behavior is not changed.
When a unmounted user configured target is used, mkdumprd will look for corresponding mount info in fstab, and a entry with noauto option is founded, mkdumprd will try to mount it inplace with optoins specified in fstab and do basic checks on the device, then umount it.
If there is no fstab entry, mkdumprd will try to mount it in temporary path with defaults option, do same basic check and umount it.
If there is a fstab entry but "noauto" option is not used, then there must be some reason that the target device is not mounted, mkdumprd will error out.
When path based target is used, there is no behavior change.
Signed-off-by: Kairui Song kasong@redhat.com --- kdump-lib.sh | 33 ++++++------------ mkdumprd | 94 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 92 insertions(+), 35 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh index 8411d22..aa52a3b 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -284,12 +284,17 @@ get_kdump_path_from_target() local _mntpoint=$(get_mntpoint_from_target $1)
# mount under /sysroot if dump to root disk or mount under - # /kdumproot/$_mntpoint in other cases in 2nd kernel. systemd - # will be in charge to umount it. - if [ "$_mntpoint" = "/" ];then - _mntpoint="/sysroot" + # mount under /kdumproot if dump target is not mounted in first kernel + # mount under /kdumproot/$_mntpoint in other cases in 2nd kernel. + # systemd will be in charge to umount it. + if [ -z "$_mntpoint" ];then + _mntpoint="/kdumproot" else - _mntpoint="/kdumproot/$_mntpoint" + if [ "$_mntpoint" = "/" ];then + _mntpoint="/sysroot" + else + _mntpoint="/kdumproot/$_mntpoint" + fi fi
# strip duplicated "/" @@ -302,24 +307,6 @@ get_option_value() { strip_comments `grep "^$1[[:space:]]+" /etc/kdump.conf | tail -1 | cut -d\ -f2-` }
-check_save_path_fs() -{ - local _path=$1 - - if [ ! -d $_path ]; then - perror_exit "Dump path $_path does not exist." - fi -} - -# Check if path exists within dump target -check_save_path_user_configured() -{ - local _target=$1 _path=$2 - local _mnt=$(get_mntpoint_from_target $_target) - - check_save_path_fs "$_mnt/$_path" -} - is_atomic() { grep -q "ostree" /proc/cmdline diff --git a/mkdumprd b/mkdumprd index a4e3d1e..8fab37b 100644 --- a/mkdumprd +++ b/mkdumprd @@ -19,6 +19,20 @@ OVERRIDE_RESETTABLE=0 extra_modules="" dracut_args="--quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump""
+readonly MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" +[ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." +readonly MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target" + +trap ' + ret=$?; + is_mounted $MKDUMPRD_TMPMNT && umount -f $MKDUMPRD_TMPMNT; + [[ -d $MKDUMPRD_TMPDIR ]] && rm --one-file-system -rf -- "$MKDUMPRD_TMPDIR"; + exit $ret; + ' EXIT + +# clean up after ourselves no matter how we die. +trap 'exit 1;' SIGINT + is_wdt_addition_needed() { local active
@@ -51,11 +65,12 @@ add_dracut_sshkey() {
# caller should ensure $1 is valid and mounted in 1st kernel to_mount() { - local _target=$1 _new_mntpoint _fstype _options _mntopts _pdev + local _target=$1 _fstype=$2 _options=$3 _new_mntpoint _mntopts _pdev
- _fstype=$(get_fs_type_from_target $_target) - _options=$(get_mntopt_from_target $_target) _new_mntpoint=$(get_kdump_path_from_target $_target) + _fstype="${_fstype:-$(get_fs_type_from_target $_target)}" + _options="${_options:-$(get_mntopt_from_target $_options)}" + _options="${_options:-defaults}"
if [[ "$_fstype" == "nfs"* ]]; then _options=$(echo $_options | sed 's/,addr=[^,]*//') @@ -172,6 +187,67 @@ check_size() { fi }
+check_save_path_fs() +{ + local _path=$1 + + if [ ! -d $_path ]; then + perror_exit "Dump path $_path does not exist." + fi +} + +check_user_configured_target() +{ + local _target=$1 _cfg_fs_type=$2 _mounted + local _mnt=$(get_mntpoint_from_target $_target) + local _opt=$(get_mntopt_from_target $_target) + local _fstype=$(get_fs_type_from_target $_target) + + if [ -n "$_fstype" ]; then + # In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf + [[ $_fstype = "nfs"* ]] && _fstype=nfs + + if [ -n "$_cfg_fs_type" ] && [ "$_fstype" != "$_cfg_fs_type" ]; then + perror_exit ""$_target" have a wrong type config "$_cfg_fs_type", expected "$_fstype"" + fi + else + _fstype="$_cfg_fs_type" + _fstype="$_cfg_fs_type" + fi + + # For noauto mount, mount it inplace with default value. + # Else use the temporary target directory + if [ -n "$_mnt" ]; then + if ! is_mounted "$_mnt"; then + if [[ $_opt = *",noauto"* ]]; then + mount $_mnt + [ $? -ne 0 ] && perror_exit "Failed to mount $_target on $_mnt for kdump preflight check." + _mounted=$_mnt + else + perror_exit "$_target is configured in fstab but not mounted, please check its usability." + fi + fi + else + _mnt=$MKDUMPRD_TMPMNT + mkdir -p $_mnt + mount $_target $_mnt -t $_fstype -o defaults + [ $? -ne 0 ] && perror_exit "Failed to mount $_target for kdump preflight check." + _mounted=$_mnt + fi + + # For user configured target, use $SAVE_PATH as the dump path within the target + if [ ! -d "$_mnt/$SAVE_PATH" ]; then + perror_exit "Dump path "$SAVE_PATH" does not exist in dump target "$_target"" + fi + + check_size fs "$_target" + + # Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway + if [ -n "$_mounted" ]; then + umount -f -- $_mounted + fi +} + # $1: core_collector config value verify_core_collector() { local _cmd="${1%% *}" @@ -199,7 +275,7 @@ verify_core_collector() { }
add_mount() { - local _mnt=$(to_mount "$1") + local _mnt=$(to_mount $@)
if [ $? -ne 0 ]; then exit 1 @@ -352,14 +428,8 @@ do extra_modules="$extra_modules $config_val" ;; ext[234]|xfs|btrfs|minix|nfs) - if ! is_mounted $config_val; then - perror_exit "Dump target $config_val is probably not mounted." - fi - - # User configured target, use $SAVE_PATH as the dump path within the target - check_save_path_user_configured "$config_val" "$SAVE_PATH" - check_size fs "$config_val" - add_mount "$config_val" + check_user_configured_target "$config_val" "$config_opt" + add_mount "$config_val" "$config_opt" ;; raw) # checking raw disk writable
Hi Kairui, On 03/13/20 at 11:03am, Kairui Song wrote:
Currently kexec-tools always depend on dump target to be mounted, which caused some inconvenience for setup.
So for user configured target, allow kdump to start and build initramfs even if target is not mounted.
When a mounted user configured target is used, the behavior is not changed.
When a unmounted user configured target is used, mkdumprd will look for corresponding mount info in fstab, and a entry with noauto option is founded, mkdumprd will try to mount it inplace with optoins specified in fstab and do basic checks on the device, then umount it.
If there is no fstab entry, mkdumprd will try to mount it in temporary path with defaults option, do same basic check and umount it.
If there is a fstab entry but "noauto" option is not used, then there must be some reason that the target device is not mounted, mkdumprd will error out.
When path based target is used, there is no behavior change.
Since the behavior changed, can you also update the documentation? Specific for kdump.conf man page and the howto.txt
Signed-off-by: Kairui Song kasong@redhat.com
kdump-lib.sh | 33 ++++++------------ mkdumprd | 94 +++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 92 insertions(+), 35 deletions(-)
diff --git a/kdump-lib.sh b/kdump-lib.sh index 8411d22..aa52a3b 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -284,12 +284,17 @@ get_kdump_path_from_target() local _mntpoint=$(get_mntpoint_from_target $1)
# mount under /sysroot if dump to root disk or mount under
- # /kdumproot/$_mntpoint in other cases in 2nd kernel. systemd
- # will be in charge to umount it.
- if [ "$_mntpoint" = "/" ];then
_mntpoint="/sysroot"
- # mount under /kdumproot if dump target is not mounted in first kernel
- # mount under /kdumproot/$_mntpoint in other cases in 2nd kernel.
- # systemd will be in charge to umount it.
- if [ -z "$_mntpoint" ];then
else_mntpoint="/kdumproot"
_mntpoint="/kdumproot/$_mntpoint"
if [ "$_mntpoint" = "/" ];then_mntpoint="/sysroot"else_mntpoint="/kdumproot/$_mntpoint"fifi
# strip duplicated "/"
@@ -302,24 +307,6 @@ get_option_value() { strip_comments `grep "^$1[[:space:]]+" /etc/kdump.conf | tail -1 | cut -d\ -f2-` }
-check_save_path_fs() -{
- local _path=$1
- if [ ! -d $_path ]; then
perror_exit "Dump path $_path does not exist."- fi
-}
-# Check if path exists within dump target -check_save_path_user_configured() -{
- local _target=$1 _path=$2
- local _mnt=$(get_mntpoint_from_target $_target)
- check_save_path_fs "$_mnt/$_path"
-}
is_atomic() { grep -q "ostree" /proc/cmdline diff --git a/mkdumprd b/mkdumprd index a4e3d1e..8fab37b 100644 --- a/mkdumprd +++ b/mkdumprd @@ -19,6 +19,20 @@ OVERRIDE_RESETTABLE=0 extra_modules="" dracut_args="--quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode strict -o "plymouth dash resume ifcfg earlykdump""
+readonly MKDUMPRD_TMPDIR="$(mktemp -d -t mkdumprd.XXXXXX)" +[ -d "$MKDUMPRD_TMPDIR" ] || perror_exit "dracut: mktemp -p -d -t dracut.XXXXXX failed." +readonly MKDUMPRD_TMPMNT="$MKDUMPRD_TMPDIR/target"
+trap '
- ret=$?;
- is_mounted $MKDUMPRD_TMPMNT && umount -f $MKDUMPRD_TMPMNT;
- [[ -d $MKDUMPRD_TMPDIR ]] && rm --one-file-system -rf -- "$MKDUMPRD_TMPDIR";
- exit $ret;
- ' EXIT
+# clean up after ourselves no matter how we die. +trap 'exit 1;' SIGINT
is_wdt_addition_needed() { local active
@@ -51,11 +65,12 @@ add_dracut_sshkey() {
# caller should ensure $1 is valid and mounted in 1st kernel to_mount() {
- local _target=$1 _new_mntpoint _fstype _options _mntopts _pdev
- local _target=$1 _fstype=$2 _options=$3 _new_mntpoint _mntopts _pdev
- _fstype=$(get_fs_type_from_target $_target)
- _options=$(get_mntopt_from_target $_target) _new_mntpoint=$(get_kdump_path_from_target $_target)
_fstype="${_fstype:-$(get_fs_type_from_target $_target)}"
_options="${_options:-$(get_mntopt_from_target $_options)}"
_options="${_options:-defaults}"
if [[ "$_fstype" == "nfs"* ]]; then _options=$(echo $_options | sed 's/,addr=[^,]*//')
@@ -172,6 +187,67 @@ check_size() { fi }
+check_save_path_fs() +{
- local _path=$1
- if [ ! -d $_path ]; then
perror_exit "Dump path $_path does not exist."- fi
+}
+check_user_configured_target() +{
- local _target=$1 _cfg_fs_type=$2 _mounted
- local _mnt=$(get_mntpoint_from_target $_target)
- local _opt=$(get_mntopt_from_target $_target)
- local _fstype=$(get_fs_type_from_target $_target)
- if [ -n "$_fstype" ]; then
# In case of nfs4, nfs should be used instead, nfs* options is deprecated in kdump.conf[[ $_fstype = "nfs"* ]] && _fstype=nfsif [ -n "$_cfg_fs_type" ] && [ "$_fstype" != "$_cfg_fs_type" ]; thenperror_exit "\"$_target\" have a wrong type config \"$_cfg_fs_type\", expected \"$_fstype\""fi- else
_fstype="$_cfg_fs_type"_fstype="$_cfg_fs_type"- fi
- # For noauto mount, mount it inplace with default value.
- # Else use the temporary target directory
- if [ -n "$_mnt" ]; then
if ! is_mounted "$_mnt"; thenif [[ $_opt = *",noauto"* ]]; thenmount $_mnt[ $? -ne 0 ] && perror_exit "Failed to mount $_target on $_mnt for kdump preflight check."_mounted=$_mntelseperror_exit "$_target is configured in fstab but not mounted, please check its usability."fifi- else
_mnt=$MKDUMPRD_TMPMNTmkdir -p $_mntmount $_target $_mnt -t $_fstype -o defaults[ $? -ne 0 ] && perror_exit "Failed to mount $_target for kdump preflight check."_mounted=$_mnt- fi
- # For user configured target, use $SAVE_PATH as the dump path within the target
- if [ ! -d "$_mnt/$SAVE_PATH" ]; then
perror_exit "Dump path \"$SAVE_PATH\" does not exist in dump target \"$_target\""- fi
- check_size fs "$_target"
- # Unmount it early, if function is interrupted and didn't reach here, the shell trap will clear it up anyway
- if [ -n "$_mounted" ]; then
umount -f -- $_mounted- fi
+}
# $1: core_collector config value verify_core_collector() { local _cmd="${1%% *}" @@ -199,7 +275,7 @@ verify_core_collector() { }
add_mount() {
- local _mnt=$(to_mount "$1")
local _mnt=$(to_mount $@)
if [ $? -ne 0 ]; then exit 1
@@ -352,14 +428,8 @@ do extra_modules="$extra_modules $config_val" ;; ext[234]|xfs|btrfs|minix|nfs)
if ! is_mounted $config_val; thenperror_exit "Dump target $config_val is probably not mounted."fi# User configured target, use $SAVE_PATH as the dump path within the targetcheck_save_path_user_configured "$config_val" "$SAVE_PATH"check_size fs "$config_val"add_mount "$config_val"
check_user_configured_target "$config_val" "$config_opt" raw) # checking raw disk writableadd_mount "$config_val" "$config_opt" ;;-- 2.24.1 _______________________________________________ kexec mailing list -- kexec@lists.fedoraproject.org To unsubscribe send an email to kexec-leave@lists.fedoraproject.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedoraproject.org/archives/list/kexec@lists.fedoraproject.org
Thanks Dave
On Thu, Apr 9, 2020 at 11:17 AM Dave Young dyoung@redhat.com wrote:
Hi Kairui, On 03/13/20 at 11:03am, Kairui Song wrote:
Currently kexec-tools always depend on dump target to be mounted, which caused some inconvenience for setup.
So for user configured target, allow kdump to start and build initramfs even if target is not mounted.
When a mounted user configured target is used, the behavior is not changed.
When a unmounted user configured target is used, mkdumprd will look for corresponding mount info in fstab, and a entry with noauto option is founded, mkdumprd will try to mount it inplace with optoins specified in fstab and do basic checks on the device, then umount it.
If there is no fstab entry, mkdumprd will try to mount it in temporary path with defaults option, do same basic check and umount it.
If there is a fstab entry but "noauto" option is not used, then there must be some reason that the target device is not mounted, mkdumprd will error out.
When path based target is used, there is no behavior change.
Since the behavior changed, can you also update the documentation? Specific for kdump.conf man page and the howto.txt
OK, I'll update the doc, that way it will be cleaner and easier to understand too.