User get_mount_info to replace findmnt calls

Use get_mount_info so that fstab is used as a failback when look for
mount info.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Pingfan Liu <piliu@redhat.com>
This commit is contained in:
Kairui Song 2020-03-12 20:57:08 +08:00
parent be578f6382
commit 61e016939c
4 changed files with 25 additions and 41 deletions

View File

@ -94,19 +94,16 @@ get_kdump_confs()
fi fi
} }
# dump_fs <mount point| device> # dump_fs <mount point>
dump_fs() dump_fs()
{ {
local _dev=$(findmnt -k -f -n -r -o SOURCE $1) local _mp=$1
local _mp=$(findmnt -k -f -n -r -o TARGET $1) local _dev=$(get_mount_info SOURCE target $_mp -f)
local _op=$(findmnt -k -f -n -r -o OPTIONS $1) local _op=$(get_mount_info OPTIONS target $_mp -f)
# If dump path have a corresponding device entry but not mounted, mount it.
if [ -n "$_dev" ]; then
if ! is_mounted "$_mp"; then if ! is_mounted "$_mp"; then
_dev=$(findmnt -s -f -n -r -o SOURCE $1)
_mp=$(findmnt -s -f -n -r -o TARGET $1)
_op=$(findmnt -s -f -n -r -o OPTIONS $1)
if [ -n "$_dev" ] && [ -n "$_mp" ]; then
echo "kdump: dump target $_dev is not mounted, trying to mount..." echo "kdump: dump target $_dev is not mounted, trying to mount..."
mkdir -p $_mp mkdir -p $_mp
mount -o $_op $_dev $_mp mount -o $_op $_dev $_mp
@ -115,11 +112,10 @@ dump_fs()
echo "kdump: mounting failed (mount point: $_mp, option: $_op)" echo "kdump: mounting failed (mount point: $_mp, option: $_op)"
return 1 return 1
fi fi
else
echo "kdump: error: Dump target $_dev is not usable"
fi fi
else else
echo "kdump: dump target is $_dev" echo "kdump: failed to dump to \"$_mp\", it's not a mount point!"
return 1
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.
@ -260,6 +256,7 @@ read_kdump_conf()
[ -n "$config_val" ] && add_dump_code "dump_fs $config_val" [ -n "$config_val" ] && add_dump_code "dump_fs $config_val"
;; ;;
ext[234]|xfs|btrfs|minix|nfs) ext[234]|xfs|btrfs|minix|nfs)
config_val=$(get_mntpoint_from_target "$config_val")
add_dump_code "dump_fs $config_val" add_dump_code "dump_fs $config_val"
;; ;;
raw) raw)

View File

@ -270,7 +270,6 @@ get_mntopt_from_target()
{ {
get_mount_info OPTIONS source $1 -f get_mount_info OPTIONS source $1 -f
} }
# Find the general mount point of a dump target, not the bind mount point # Find the general mount point of a dump target, not the bind mount point
get_mntpoint_from_target() get_mntpoint_from_target()
{ {

View File

@ -907,8 +907,8 @@ path_to_be_relabeled()
_target=$(local_fs_dump_target) _target=$(local_fs_dump_target)
if [[ -n "$_target" ]]; then if [[ -n "$_target" ]]; then
_mnt=$(findmnt -k -f -n -r -o TARGET $_target) _mnt=$(get_mntpoint_from_target $_target)
if [ -z "$_mnt" ]; then if ! is_mounted "$_mnt"; then
return return
fi fi
else else

View File

@ -51,21 +51,18 @@ 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 _new_mntpoint _fstype _options _mntopts _pdev local _target=$1 _new_mntpoint _fstype _options _mntopts _pdev
_source=$(findmnt -k -f -n -r -o SOURCE $_dev) _fstype=$(get_fs_type_from_target $_target)
_fstype=$(findmnt -k -f -n -r -o FSTYPE $_dev) _options=$(get_mntopt_from_target $_target)
_new_mntpoint=$(get_kdump_mntpoint_from_target $_dev) _new_mntpoint=$(get_kdump_mntpoint_from_target $_target)
[[ -e /etc/fstab ]] && _options=$(findmnt --fstab -f -n -r -o OPTIONS $_dev) if [[ "$_fstype" == "nfs"* ]]; then
if [ -z "$_options" ]; then
_options=$(findmnt -k -f -n -r -o OPTIONS $_dev)
if [[ $_fstype == "nfs"* ]]; then
_options=$(echo $_options | sed 's/,addr=[^,]*//') _options=$(echo $_options | sed 's/,addr=[^,]*//')
_options=$(echo $_options | sed 's/,proto=[^,]*//') _options=$(echo $_options | sed 's/,proto=[^,]*//')
_options=$(echo $_options | sed 's/,clientaddr=[^,]*//') _options=$(echo $_options | sed 's/,clientaddr=[^,]*//')
fi fi
fi
# mount fs target as rw in 2nd kernel # mount fs target as rw in 2nd kernel
_options=$(echo $_options | sed 's/\(^\|,\)ro\($\|,\)/\1rw\2/g') _options=$(echo $_options | sed 's/\(^\|,\)ro\($\|,\)/\1rw\2/g')
# with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd # with 'noauto' in fstab nfs and non-root disk mount will fail in 2nd
@ -79,28 +76,19 @@ to_mount() {
_options="$_options,nofail,x-systemd.before=initrd-fs.target" _options="$_options,nofail,x-systemd.before=initrd-fs.target"
_mntopts="$_new_mntpoint $_fstype $_options" _mntopts="$_new_mntpoint $_fstype $_options"
# for non-nfs _dev converting to use udev persistent name # for non-nfs _target converting to use udev persistent name
if [ -b "$_source" ]; then if [ -b "$_target" ]; then
_pdev="$(get_persistent_dev $_source)" _pdev="$(get_persistent_dev $_target)"
if [ -z "$_pdev" ]; then if [ -z "$_pdev" ]; then
return 1 return 1
fi fi
else else
_pdev=$_dev _pdev=$_target
fi fi
echo "$_pdev $_mntopts" echo "$_pdev $_mntopts"
} }
is_readonly_mount() {
local _mnt
_mnt=$(findmnt -k -f -n -r -o OPTIONS $1)
#fs/proc_namespace.c: show_mountinfo():
#seq_puts(m, mnt->mnt_flags & MNT_READONLY ? " ro" : " rw");
[[ "$_mnt" =~ ^ro ]]
}
#Function: get_ssh_size #Function: get_ssh_size
#$1=dump target #$1=dump target
#called from while loop and shouldn't read from stdin, so we're using "ssh -n" #called from while loop and shouldn't read from stdin, so we're using "ssh -n"