common/rc: improve dev mounted check helper

There is a problem of missing fstype check in _is_mounted() helper,
it will return the mountpoint if only the device arguments matches.

For example:
  Base mounted filesystem:
    /dev/sda2 on /boot type ext4 (rw,relatime,data=ordered)

  FSTYPE=xfs
  mountpoint=`_is_mounted /dev/sda1`
  echo "$mountpoint"

  Output: /boot

This patch rename _is_mounted to _is_dev_mounted because it check
the given device only (not mount dir), and add an optional "fstype"
parameter, let user specify file system type instead of default
FSTYPE. Finally, use findmnt instead of mount to avoid complex
processing of mount info and fix this problem simply.

Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
This commit is contained in:
zhangyi (F)
2018-03-01 20:13:43 +08:00
committed by Eryu Guan
parent 5e65145233
commit 69f7669ef6
2 changed files with 11 additions and 20 deletions
+10 -19
View File
@@ -2381,27 +2381,18 @@ _scratch_mkfs_richacl()
esac esac
} }
# check that a FS on a device is mounted # check if the given device is mounted, if so, return mount point
# if so, return mount point _is_dev_mounted()
#
_is_mounted()
{ {
if [ $# -ne 1 ] local dev=$1
then local fstype=${2:-$FSTYP}
echo "Usage: _is_mounted device" 1>&2
exit 1
fi
device=$1 if [ $# -lt 1 ]; then
echo "Usage: _is_dev_mounted <device> [fstype]" 1>&2
exit 1
fi
if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" ' findmnt -rncv -S $dev -t $fstype -o TARGET | head -1
pattern { print $3 ; exit 0 }
END { exit 1 }
'
then
echo "_is_mounted: $device is not a mounted $FSTYP FS"
exit 1
fi
} }
# remount a FS to a new mode (ro or rw) # remount a FS to a new mode (ro or rw)
@@ -2441,7 +2432,7 @@ _umount_or_remount_ro()
fi fi
device=$1 device=$1
mountpoint=`_is_mounted $device` mountpoint=`_is_dev_mounted $device`
if [ $USE_REMOUNT -eq 0 ]; then if [ $USE_REMOUNT -eq 0 ]; then
$UMOUNT_PROG $device $UMOUNT_PROG $device
+1 -1
View File
@@ -356,7 +356,7 @@ _check_xfs_filesystem()
ok=1 ok=1
# Run online scrub if we can. # Run online scrub if we can.
mntpt="$(_is_mounted $device)" mntpt="$(_is_dev_mounted $device)"
if [ -n "$mntpt" ] && _supports_xfs_scrub "$mntpt" "$device"; then if [ -n "$mntpt" ] && _supports_xfs_scrub "$mntpt" "$device"; then
"$XFS_SCRUB_PROG" $scrubflag -v -d -n $device > $tmp.scrub 2>&1 "$XFS_SCRUB_PROG" $scrubflag -v -d -n $device > $tmp.scrub 2>&1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then