Introduce get_kdump_mntpoint_from_target and fix duplicated /

User a helper to get the path to mount dump target in kdump kernel, and
fix duplicated '/' in the mount path problem.

Fixes: bz1785371
Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
This commit is contained in:
Kairui Song 2020-03-05 23:28:53 +08:00
parent 539bff4083
commit 43ea36b3e8
3 changed files with 25 additions and 21 deletions

View File

@ -258,6 +258,25 @@ get_mntpoint_from_target()
findmnt -k -f -n -r -o TARGET --source $1 findmnt -k -f -n -r -o TARGET --source $1
} }
# Get the path where the target will be mounted in kdump kernel
# $1: kdump target device
get_kdump_mntpoint_from_target()
{
local _mntpoint=$(get_mntpoint_from_target $1)
# mount under /sysroot if dump to root disk or mount under
# /kdumproot/$_mntpoint in other cases in 2nd kernel. systemd
# will be in charge to umount it.
if [ "$_mntpoint" = "/" ];then
_mntpoint="/sysroot"
else
_mntpoint="/kdumproot/$_mntpoint"
fi
# strip duplicated "/"
echo $_mntpoint | tr -s "/"
}
# get_option_value <option_name> # get_option_value <option_name>
# retrieves value of option defined in kdump.conf # retrieves value of option defined in kdump.conf
get_option_value() { get_option_value() {

View File

@ -480,12 +480,7 @@ check_dump_fs_modified()
return 2 return 2
fi fi
if [[ "$_target" = "$(get_root_fs_device)" ]]; then _new_mntpoint="$(get_kdump_mntpoint_from_target $_target)"
_new_mntpoint="/sysroot"
else
_new_mntpoint="/kdumproot/$(get_mntpoint_from_target $_target)"
fi
_dracut_args=$(lsinitrd $TARGET_INITRD -f usr/lib/dracut/build-parameter.txt) _dracut_args=$(lsinitrd $TARGET_INITRD -f usr/lib/dracut/build-parameter.txt)
if [[ -z "$_dracut_args" ]];then if [[ -z "$_dracut_args" ]];then
echo "Warning: No dracut arguments found in initrd" echo "Warning: No dracut arguments found in initrd"

View File

@ -51,21 +51,12 @@ add_dracut_sshkey() {
# caller should ensure $1 is valid and mounted in 1st kernel # caller should ensure $1 is valid and mounted in 1st kernel
to_mount() { to_mount() {
local _dev=$1 _source _target _fstype _options _mntopts _pdev local _dev=$1 _source _new_mntpoint _fstype _options _mntopts _pdev
_source=$(findmnt -k -f -n -r -o SOURCE $_dev) _source=$(findmnt -k -f -n -r -o SOURCE $_dev)
_target=$(get_mntpoint_from_target $_dev)
# mount under /sysroot if dump to root disk or mount under
#/kdumproot/$_target in other cases in 2nd kernel. systemd
#will be in charge to umount it.
if [ "$_target" = "/" ];then
_target="/sysroot"
else
_target="/kdumproot/$_target"
fi
_fstype=$(findmnt -k -f -n -r -o FSTYPE $_dev) _fstype=$(findmnt -k -f -n -r -o FSTYPE $_dev)
_new_mntpoint=$(get_kdump_mntpoint_from_target $_dev)
[[ -e /etc/fstab ]] && _options=$(findmnt --fstab -f -n -r -o OPTIONS $_dev) [[ -e /etc/fstab ]] && _options=$(findmnt --fstab -f -n -r -o OPTIONS $_dev)
if [ -z "$_options" ]; then if [ -z "$_options" ]; then
_options=$(findmnt -k -f -n -r -o OPTIONS $_dev) _options=$(findmnt -k -f -n -r -o OPTIONS $_dev)
@ -87,14 +78,13 @@ to_mount() {
# mount it before kdump starts, this is an attempt to improve robustness # mount it before kdump starts, this is an attempt to improve robustness
_options="$_options,nofail,x-systemd.before=initrd-fs.target" _options="$_options,nofail,x-systemd.before=initrd-fs.target"
_mntopts="$_target $_fstype $_options" _mntopts="$_new_mntpoint $_fstype $_options"
#for non-nfs _dev converting to use udev persistent name # for non-nfs _dev converting to use udev persistent name
if [ -b "$_source" ]; then if [ -b "$_source" ]; then
_pdev="$(get_persistent_dev $_source)" _pdev="$(get_persistent_dev $_source)"
if [ -z "$_pdev" ]; then if [ -z "$_pdev" ]; then
return 1 return 1
fi fi
else else
_pdev=$_dev _pdev=$_dev
fi fi