lib: Ensure we don't find bind mounts for device target

Resolves: RHEL-35885

commit 9252d6b1b492016aa11a73340f286822e6d545f2
Author: Colin Walters <walters@verbum.org>
Date:   Fri Jul 19 11:44:09 2024 -0400

    lib: Ensure we don't find bind mounts for device target

    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 <walters@verbum.org>

Signed-off-by: Lichen Liu <lichliu@redhat.com>
This commit is contained in:
Lichen Liu 2024-07-23 11:01:57 +08:00 committed by Tao Liu
parent be56205d06
commit 099aead590
2 changed files with 10 additions and 3 deletions

View File

@ -101,8 +101,15 @@ get_fs_type_from_target()
get_mntpoint_from_target() get_mntpoint_from_target()
{ {
# --source is applied to ensure non-bind mount is returned local SOURCE TARGET
get_mount_info TARGET source "$1" -f findmnt -k --pairs -o SOURCE,TARGET "$1" | while read line; do
eval "$line"
# omit sources that are bind mounts i.e. they contain a [/path/to/subpath].
if [[ ! "$SOURCE" =~ \[ ]]; then
echo $TARGET
break
fi
done
} }
is_ssh_dump_target() is_ssh_dump_target()

View File

@ -213,7 +213,7 @@ get_bind_mount_source()
_fsroot=${_src#${_src_nofsroot}[} _fsroot=${_src#${_src_nofsroot}[}
_fsroot=${_fsroot%]} _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 # for btrfs, _fsroot will also contain the subvol value as well, strip it
if [[ $_fstype == btrfs ]]; then if [[ $_fstype == btrfs ]]; then