Add a is_mounted helper

Use is_mounted helper instaed of calling findmnt directly or checking if
"mount" value is empty.

If findmnt looks for fstab as well, some non mounted entry will also
return value. Required to support non-mounted target.

Signed-off-by: Kairui Song <kasong@redhat.com>
Acked-by: Pingfan Liu <piliu@redhat.com>
This commit is contained in:
Kairui Song 2020-03-11 21:06:03 +08:00
parent 43ea36b3e8
commit 0624148414
4 changed files with 8 additions and 3 deletions

View File

@ -101,7 +101,7 @@ dump_fs()
local _mp=$(findmnt -k -f -n -r -o TARGET $1)
local _op=$(findmnt -k -f -n -r -o OPTIONS $1)
if [ -z "$_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)

View File

@ -246,6 +246,11 @@ get_target_from_path()
echo $_target
}
is_mounted()
{
findmnt -k -n $1 &>/dev/null
}
get_fs_type_from_target()
{
findmnt -k -f -n -r -o FSTYPE $1

View File

@ -475,7 +475,7 @@ check_dump_fs_modified()
fi
fi
if ! findmnt $_target >/dev/null; then
if ! is_mounted $_target; then
echo "Dump target $_target is probably not mounted."
return 2
fi

View File

@ -366,7 +366,7 @@ do
extra_modules="$extra_modules $config_val"
;;
ext[234]|xfs|btrfs|minix|nfs)
if ! findmnt $config_val >/dev/null; then
if ! is_mounted $config_val; then
perror_exit "Dump target $config_val is probably not mounted."
fi