Skip to content

Commit

Permalink
lib: Ensure we don't find bind mounts for device target
Browse files Browse the repository at this point in the history
There's comment here that `--source` somehow avoids bind
mounts, but that appears not to be the case in my
testing. I think we just happened to be lucky before
now with the `--first` picking the value we wanted.

Instead of using `--first` and hoping for the best,
parse the mounts and skip ones which are bind mounts
explicitly.

Signed-off-by: Colin Walters <[email protected]>
Reviewed-by: Lichen Liu <[email protected]>
  • Loading branch information
cgwalters authored and licliu committed Aug 23, 2024
1 parent 51d58ee commit 3f9dbcc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions kdump-lib-initramfs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,19 @@ 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
# omit sources that are bind mounts i.e. they contain a [/path/to/subpath].
findmnt -k --pairs -o SOURCE,TARGET "$1" | while read -r _source _target; do
_source="${_source#SOURCE=\"}"
_source="${_source%%\"}"

_target="${_target#*TARGET=\"}"
_target="${_target%%\"}"

if ! expr "X$_source" : 'X.*\[' > /dev/null; then
echo "$_target"
break
fi
done
}

is_ssh_dump_target()
Expand Down
2 changes: 1 addition & 1 deletion kdump-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,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
Expand Down

0 comments on commit 3f9dbcc

Please sign in to comment.