From bde4b7af3b1517b78bb03f92f9fd7183aa532712 Mon Sep 17 00:00:00 2001 From: Kairui Song Date: Tue, 10 Mar 2020 23:52:33 +0800 Subject: [PATCH] No longer treat atomic/silverblue specially This commit remove almost all special workaround for atomic, and treat all bind mounts in any environment equally. Use a helper get_bind_mount_directory_from_path to get the bind mount source path of given path. is_atomic function now only used to determine the right /boot path for atomic/silverblue environment. And remove get_mntpoint_from_path(), it's the only function that never ignore bind mount, and it have no caller after this clean up. Signed-off-by: Kairui Song Acked-by: Lianbo Jiang --- dracut-module-setup.sh | 36 +++++----------------- kdump-lib.sh | 69 +++++++++++++----------------------------- mkdumprd | 17 +++-------- 3 files changed, 32 insertions(+), 90 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 2c8d714..0f6f1cb 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -428,19 +428,9 @@ default_dump_target_install_conf() is_user_configured_dump_target && return - _save_path=$(get_save_path) - _mntpoint=$(get_mntpoint_from_path $_save_path) + _save_path=$(get_bind_mount_source $(get_save_path)) _target=$(get_target_from_path $_save_path) - - if is_atomic && is_bind_mount $_mntpoint; then - _save_path=${_save_path##"$_mntpoint"} - # the real dump path in the 2nd kernel, if the mount point is bind mounted. - _save_path=$(get_bind_mount_directory $_mntpoint)/$_save_path - _mntpoint=$(get_mntpoint_from_target $_target) - - # the absolute path in the 1st kernel - _save_path=$_mntpoint/$_save_path - fi + _mntpoint=$(get_mntpoint_from_target $_target) _fstype=$(get_fs_type_from_target $_target) if is_fs_type_nfs $_fstype; then @@ -452,8 +442,6 @@ default_dump_target_install_conf() echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.conf - # strip the duplicated "/" - _save_path=$(echo $_save_path | tr -s /) # don't touch the path under root mount if [ "$_mntpoint" != "/" ]; then _save_path=${_save_path##"$_mntpoint"} @@ -466,21 +454,13 @@ default_dump_target_install_conf() adjust_bind_mount_path() { - local _target=$1 local _save_path=$(get_save_path) - local _absolute_save_path=$(get_mntpoint_from_target $_target)/$_save_path + local _mntpoint=$(get_mntpoint_from_target $1) + local _absolute_save_path=$(get_bind_mount_source $_mntpoint$_save_path) - _absolute_save_path=$(echo "$_absolute_save_path" | tr -s /) - local _mntpoint=$(get_mntpoint_from_path $_absolute_save_path) - - if is_bind_mount $_mntpoint; then - _save_path=${_absolute_save_path##"$_mntpoint"} - # the real dump path in the 2nd kernel, if the mount point is bind mounted. - _save_path=$(get_bind_mount_directory $_mntpoint)/$_save_path - - #erase the old path line, then insert the parsed path + if [ $_absolute_save_path != $_save_path ]; then sed -i "/^path/d" ${initdir}/tmp/$$-kdump.conf - echo "path $_save_path" >> ${initdir}/tmp/$$-kdump.conf + echo "path $_absolute_save_path" >> ${initdir}/tmp/$$-kdump.conf fi } @@ -500,9 +480,7 @@ kdump_install_conf() { ext[234]|xfs|btrfs|minix) _pdev=$(kdump_get_persistent_dev $_val) sed -i -e "s#^$_opt[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf - if is_atomic; then - adjust_bind_mount_path "$_val" - fi + adjust_bind_mount_path "$_val" ;; ssh|nfs) kdump_install_net "$_val" diff --git a/kdump-lib.sh b/kdump-lib.sh index 6d421d3..b079f27 100755 --- a/kdump-lib.sh +++ b/kdump-lib.sh @@ -204,44 +204,39 @@ get_kdump_targets() echo "$kdump_targets" } - +# Return the bind mount source path, return the path itself if it's not bind mounted +# Eg. if /path/to/src is bind mounted to /mnt/bind, then: +# /mnt/bind -> /path/to/src, /mnt/bind/dump -> /path/to/src/dump +# # findmnt uses the option "-v, --nofsroot" to exclusive the [/dir] # in the SOURCE column for bind-mounts, then if $_mntpoint equals to # $_mntpoint_nofsroot, the mountpoint is not bind mounted directory. -is_bind_mount() -{ - local _mntpoint=$(findmnt $1 | tail -n 1 | awk '{print $2}') - local _mntpoint_nofsroot=$(findmnt -v $1 | tail -n 1 | awk '{print $2}') - - if [[ $_mntpoint = $_mntpoint_nofsroot ]]; then - return 1 - else - return 0 - fi -} - +# # Below is just an example for mount info # /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the # directory is bind mounted. The former part represents the device path, rest # part is the bind mounted directory which quotes by bracket "[]". -get_bind_mount_directory() +get_bind_mount_source() { - local _mntpoint=$(findmnt $1 | tail -n 1 | awk '{print $2}') - local _mntpoint_nofsroot=$(findmnt -v $1 | tail -n 1 | awk '{print $2}') + local _path=$1 + # In case it's a sub path in a mount point, get the mount point first + local _mnt_top=$(df $_path | tail -1 | awk '{print $NF}') + local _mntpoint=$(findmnt $_mnt_top | tail -n 1 | awk '{print $2}') + local _mntpoint_nofsroot=$(findmnt -v $_mnt_top | tail -n 1 | awk '{print $2}') + + if [[ "$_mntpoint" = $_mntpoint_nofsroot ]]; then + echo $_path && return + fi _mntpoint=${_mntpoint#*$_mntpoint_nofsroot} - _mntpoint=${_mntpoint#[} _mntpoint=${_mntpoint%]} + _path=${_path#$_mnt_top} - echo $_mntpoint -} - -get_mntpoint_from_path() -{ - df $1 | tail -1 | awk '{print $NF}' + echo $_mntpoint$_path } +# Return the real underlaying device of a path, ignore bind mounts get_target_from_path() { local _target @@ -256,33 +251,11 @@ get_fs_type_from_target() findmnt -k -f -n -r -o FSTYPE $1 } -# input: device path -# output: the general mount point -# find the general mount point, not the bind mounted point in atomic -# As general system, Use the previous code -# -# ERROR and EXIT: -# the device can be umounted the general mount point, if one of the mount point is bind mounted -# For example: -# mount /dev/sda /mnt/ -# mount -o bind /mnt/var /var -# umount /mnt +# Find the general mount point of a dump target, not the bind mount point get_mntpoint_from_target() { - if is_atomic; then - for _mnt in $(findmnt -k -n -r -o TARGET $1) - do - if ! is_bind_mount $_mnt; then - echo $_mnt - return - fi - done - - echo "Mount $1 firstly, without the bind mode" >&2 - exit 1 - else - echo $(findmnt -k -f -n -r -o TARGET $1) - fi + # Expcilitly specify --source to findmnt could ensure non-bind mount is returned + findmnt -k -f -n -r -o TARGET --source $1 } # get_option_value diff --git a/mkdumprd b/mkdumprd index 4fcce1c..35f5eed 100644 --- a/mkdumprd +++ b/mkdumprd @@ -240,20 +240,11 @@ handle_default_dump_target() check_save_path_fs $SAVE_PATH - _mntpoint=$(get_mntpoint_from_path $SAVE_PATH) - _target=$(get_target_from_path $SAVE_PATH) + _save_path=$(get_bind_mount_source $SAVE_PATH) + _target=$(get_target_from_path $_save_path) + _mntpoint=$(get_mntpoint_from_target $_target) - if is_atomic && is_bind_mount $_mntpoint; then - SAVE_PATH=${SAVE_PATH##"$_mntpoint"} - # the real dump path in the 2nd kernel, if the mount point is bind mounted. - SAVE_PATH=$(get_bind_mount_directory $_mntpoint)/$SAVE_PATH - _mntpoint=$(get_mntpoint_from_target $_target) - - # the absolute path in the 1st kernel - SAVE_PATH=$_mntpoint/$SAVE_PATH - fi - - SAVE_PATH=${SAVE_PATH##"$_mntpoint"} + SAVE_PATH=${_save_path##"$_mntpoint"} add_mount "$_target" check_size fs $_target }