From 27a9d1dc85283239ee0b0b29ce5a00597d3f965f Mon Sep 17 00:00:00 2001 From: Lichen Liu Date: Sun, 29 Sep 2024 16:02:04 +0800 Subject: [PATCH] kdump-lib-initramfs: Improve mount point retrieval logic We use findmnt to find the real mount point by mount source, however, when there is a bind mount target, findmnt will give more than one results and what we actually want is the one without fsroot. Will fallback to previous method if the $_mntpoint is empty. Signed-off-by: Lichen Liu --- kdump-lib-initramfs.sh | 10 ++++++++-- kdump-lib.sh | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/kdump-lib-initramfs.sh b/kdump-lib-initramfs.sh index 67c87ba2..cafa8a62 100755 --- a/kdump-lib-initramfs.sh +++ b/kdump-lib-initramfs.sh @@ -103,8 +103,14 @@ get_fs_type_from_target() get_mntpoint_from_target() { - # --source is applied to ensure non-bind mount is returned - get_mount_info TARGET source "$1" -f + local _mntpoint + # get the first TARGET when SOURCE doesn't end with ]. + # In most cases, a SOURCE ends with ] when fsroot or subvol exists. + _mntpoint=$(get_mount_info TARGET,SOURCE source "$1" | grep -v "\]$" | awk 'NR==1 { print $1 }') + + # fallback to the old way when _mntpoint is empty. + [[ -n "$_mntpoint" ]] || _mntpoint=$(get_mount_info TARGET source "$1" -f ) + echo $_mntpoint } is_ssh_dump_target() diff --git a/kdump-lib.sh b/kdump-lib.sh index c14e75e8..5157ea84 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -205,7 +205,7 @@ get_bind_mount_source() _fsroot=${_src#"${_src_nofsroot}"[} _fsroot=${_fsroot%]} - _mnt=$(get_mount_info TARGET source "$_src_nofsroot" -f) + _mnt=$(get_mntpoint_from_target "$_src_nofsroot") # for btrfs, _fsroot will also contain the subvol value as well, strip it if [[ $_fstype == btrfs ]]; then