common/rc: use findmnt to check mounted device
authorEryu Guan <eguan@redhat.com>
Fri, 10 Mar 2017 04:26:34 +0000 (12:26 +0800)
committerEryu Guan <eguan@redhat.com>
Fri, 10 Mar 2017 08:53:41 +0000 (16:53 +0800)
commit5e6892dd8be6cd55e5f4615f1b1dbe9651535a1c
treeb4157cc0aace2a4076a3765a5a3179df8233276b
parentf947088198740826affb7250e0dbf26bed30cfd8
common/rc: use findmnt to check mounted device

Doing 'grep -F "$dev on "' to find the mounted device is not
always accurate, e.g.

 SCRATCH_DEV=/vda6 is mounted but not on SCRATCH_MNT=/vda6/ovl-mnt - aborting
 Already mounted result:
 /dev/vda6 on /vda6 type xfs (rw,relatime,context=system_u:object_r:nfs_t:s0,attr2,inode64,noquota)

Fix it by using findmnt command and specifying the $dev as mount
source, print the result in "$dev $mnt" format. This works for local
filesystems, network filesystems and overlayfs, avoids all kinds of
tricky and error-prone grep pattern/regex.

Also fixed the if-then-fi format in _check_mounted_on() while we're
at it.

Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/rc