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 <kasong@redhat.com>
Acked-by: Lianbo Jiang <lijiang@redhat.com>
This commit is contained in:
Kairui Song 2020-03-10 23:52:33 +08:00
parent b5b0b90521
commit bde4b7af3b
3 changed files with 32 additions and 90 deletions

View File

@ -428,19 +428,9 @@ default_dump_target_install_conf()
is_user_configured_dump_target && return is_user_configured_dump_target && return
_save_path=$(get_save_path) _save_path=$(get_bind_mount_source $(get_save_path))
_mntpoint=$(get_mntpoint_from_path $_save_path)
_target=$(get_target_from_path $_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
_fstype=$(get_fs_type_from_target $_target) _fstype=$(get_fs_type_from_target $_target)
if is_fs_type_nfs $_fstype; then if is_fs_type_nfs $_fstype; then
@ -452,8 +442,6 @@ default_dump_target_install_conf()
echo "$_fstype $_target" >> ${initdir}/tmp/$$-kdump.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 # don't touch the path under root mount
if [ "$_mntpoint" != "/" ]; then if [ "$_mntpoint" != "/" ]; then
_save_path=${_save_path##"$_mntpoint"} _save_path=${_save_path##"$_mntpoint"}
@ -466,21 +454,13 @@ default_dump_target_install_conf()
adjust_bind_mount_path() adjust_bind_mount_path()
{ {
local _target=$1
local _save_path=$(get_save_path) 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 /) if [ $_absolute_save_path != $_save_path ]; then
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
sed -i "/^path/d" ${initdir}/tmp/$$-kdump.conf 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 fi
} }
@ -500,9 +480,7 @@ kdump_install_conf() {
ext[234]|xfs|btrfs|minix) ext[234]|xfs|btrfs|minix)
_pdev=$(kdump_get_persistent_dev $_val) _pdev=$(kdump_get_persistent_dev $_val)
sed -i -e "s#^$_opt[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf sed -i -e "s#^$_opt[[:space:]]\+$_val#$_opt $_pdev#" ${initdir}/tmp/$$-kdump.conf
if is_atomic; then adjust_bind_mount_path "$_val"
adjust_bind_mount_path "$_val"
fi
;; ;;
ssh|nfs) ssh|nfs)
kdump_install_net "$_val" kdump_install_net "$_val"

View File

@ -204,44 +204,39 @@ get_kdump_targets()
echo "$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] # findmnt uses the option "-v, --nofsroot" to exclusive the [/dir]
# in the SOURCE column for bind-mounts, then if $_mntpoint equals to # in the SOURCE column for bind-mounts, then if $_mntpoint equals to
# $_mntpoint_nofsroot, the mountpoint is not bind mounted directory. # $_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 # Below is just an example for mount info
# /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the # /dev/mapper/atomicos-root[/ostree/deploy/rhel-atomic-host/var], if the
# directory is bind mounted. The former part represents the device path, rest # directory is bind mounted. The former part represents the device path, rest
# part is the bind mounted directory which quotes by bracket "[]". # 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 _path=$1
local _mntpoint_nofsroot=$(findmnt -v $1 | tail -n 1 | awk '{print $2}') # 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_nofsroot}
_mntpoint=${_mntpoint#[} _mntpoint=${_mntpoint#[}
_mntpoint=${_mntpoint%]} _mntpoint=${_mntpoint%]}
_path=${_path#$_mnt_top}
echo $_mntpoint echo $_mntpoint$_path
}
get_mntpoint_from_path()
{
df $1 | tail -1 | awk '{print $NF}'
} }
# Return the real underlaying device of a path, ignore bind mounts
get_target_from_path() get_target_from_path()
{ {
local _target local _target
@ -256,33 +251,11 @@ get_fs_type_from_target()
findmnt -k -f -n -r -o FSTYPE $1 findmnt -k -f -n -r -o FSTYPE $1
} }
# input: device path # Find the general mount point of a dump target, not the bind mount point
# 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
get_mntpoint_from_target() get_mntpoint_from_target()
{ {
if is_atomic; then # Expcilitly specify --source to findmnt could ensure non-bind mount is returned
for _mnt in $(findmnt -k -n -r -o TARGET $1) findmnt -k -f -n -r -o TARGET --source $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
} }
# get_option_value <option_name> # get_option_value <option_name>

View File

@ -240,20 +240,11 @@ handle_default_dump_target()
check_save_path_fs $SAVE_PATH check_save_path_fs $SAVE_PATH
_mntpoint=$(get_mntpoint_from_path $SAVE_PATH) _save_path=$(get_bind_mount_source $SAVE_PATH)
_target=$(get_target_from_path $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"}
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"}
add_mount "$_target" add_mount "$_target"
check_size fs $_target check_size fs $_target
} }