mkdumprd: Simplify handling of user specified target

For user specified target, the config value is used as the dump target,
and SAVE_PATH (path in kdump.conf) value is used as the dump path within
the dump target, no need to do anything extra with the path value.

Current code logic is not only complicated, it also wrongly generate
an redundantly long path in atomic/silverblue environment.

The right way is only check two things, and do nothing else:

 1. The path exists within the target;
 2. The target is large enough to hold to contain the vmcore.

Currently checking the target still requires it to be mounted so it will
error out if it's not mounted. Will implement some auto mount as next
step.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Lianbo Jiang <lijiang@redhat.com>
This commit is contained in:
Kairui Song 2020-03-08 23:24:50 +08:00
parent fd7e7be483
commit b5b0b90521
2 changed files with 13 additions and 31 deletions

View File

@ -291,26 +291,6 @@ get_option_value() {
strip_comments `grep "^$1[[:space:]]\+" /etc/kdump.conf | tail -1 | cut -d\ -f2-` strip_comments `grep "^$1[[:space:]]\+" /etc/kdump.conf | tail -1 | cut -d\ -f2-`
} }
#This function compose a absolute path with the mount
#point and the relative $SAVE_PATH.
#target is passed in as argument, could be UUID, LABEL,
#block device or even nfs server export of the form of
#"my.server.com:/tmp/export"?
#And possibly this could be used for both default case
#as well as when dump taret is specified. When dump
#target is not specified, then $target would be null.
make_absolute_save_path()
{
local _target=$1
local _mnt
[ -n $_target ] && _mnt=$(get_mntpoint_from_target $1)
_mnt="${_mnt}/$SAVE_PATH"
# strip the duplicated "/"
echo "$_mnt" | tr -s /
}
check_save_path_fs() check_save_path_fs()
{ {
local _path=$1 local _path=$1
@ -320,6 +300,15 @@ check_save_path_fs()
fi fi
} }
# Check if path exists within dump target
check_save_path_user_configured()
{
local _target=$1 _path=$2
local _mnt=$(get_mntpoint_from_target $_target)
check_save_path_fs "$_mnt/$_path"
}
is_atomic() is_atomic()
{ {
grep -q "ostree" /proc/cmdline grep -q "ostree" /proc/cmdline

View File

@ -387,17 +387,10 @@ do
perror_exit "Dump target $config_val is probably not mounted." perror_exit "Dump target $config_val is probably not mounted."
fi fi
_absolute_save_path=$(make_absolute_save_path $config_val) # User configured target, use $SAVE_PATH as the dump path within the target
_mntpoint=$(get_mntpoint_from_path $_absolute_save_path) check_save_path_user_configured "$config_val" "$SAVE_PATH"
if is_atomic && is_bind_mount $_mntpoint; then check_size fs "$config_val"
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
fi
add_mount "$config_val" add_mount "$config_val"
check_save_path_fs $_absolute_save_path
check_size fs $config_val
;; ;;
raw) raw)
# checking raw disk writable # checking raw disk writable