Fix dump_fs mount point detection and fallback mount

Simplify the code and fix mount point detection. The code logic is now
much simpler: if $1 is not a mount point, call "mount --target $1" again
to try mount it. "mount --target" cmd itself can handle all the /etc/fstab
parsing job, so drop the buggy and complex bash code.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Pingfan Liu <piliu@redhat.com>
This commit is contained in:
Kairui Song 2021-01-05 00:35:58 +08:00
parent 7f1f8f229f
commit e8ef4db8ff

View File

@ -117,27 +117,16 @@ dump_fs()
{ {
local _exitcode local _exitcode
local _mp=$1 local _mp=$1
local _dev=$(get_mount_info SOURCE target $_mp -f) ddebug "dump_fs _mp=$_mp"
local _op=$(get_mount_info OPTIONS target $_mp -f)
ddebug "_mp=$_mp _dev=$_dev _op=$_op"
# If dump path have a corresponding device entry but not mounted, mount it.
if [ -n "$_dev" ] && [ "$_dev" != "rootfs" ]; then
if ! is_mounted "$_mp"; then if ! is_mounted "$_mp"; then
dinfo "dump target $_dev is not mounted, trying to mount..." dinfo "dump path \"$_mp\" is not mounted, trying to mount..."
mkdir -p $_mp mount --target $_mp
mount -o $_op $_dev $_mp
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
derror "mounting failed (mount point: $_mp, option: $_op)"
return 1
fi
fi
else
derror "failed to dump to \"$_mp\", it's not a mount point!" derror "failed to dump to \"$_mp\", it's not a mount point!"
return 1 return 1
fi fi
fi
# Remove -F in makedumpfile case. We don't want a flat format dump here. # Remove -F in makedumpfile case. We don't want a flat format dump here.
[[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"` [[ $CORE_COLLECTOR = *makedumpfile* ]] && CORE_COLLECTOR=`echo $CORE_COLLECTOR | sed -e "s/-F//g"`