diff mbox

[xfstests,v6,1/8] common/rc: modify mounted check helper

Message ID 20180124073344.31970-2-yi.zhang@huawei.com (mailing list archive)
State New, archived
Headers show

Commit Message

Zhang Yi Jan. 24, 2018, 7:33 a.m. UTC
Modify _is_mounted() to accept a dir and fstype as input, and check
whether this dir is a mount point of specified fstype. This patch also
fix the problem of invalid fstype check and remove invalid error
message.

Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
---
 common/rc | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

Comments

Amir Goldstein Jan. 24, 2018, 9:23 a.m. UTC | #1
On Wed, Jan 24, 2018 at 9:33 AM, zhangyi (F) <yi.zhang@huawei.com> wrote:
> Modify _is_mounted() to accept a dir and fstype as input, and check
> whether this dir is a mount point of specified fstype. This patch also
> fix the problem of invalid fstype check and remove invalid error
> message.
>
> Signed-off-by: zhangyi (F) <yi.zhang@huawei.com>
> ---
>  common/rc | 30 +++++++++++++++---------------
>  1 file changed, 15 insertions(+), 15 deletions(-)
>
> diff --git a/common/rc b/common/rc
> index 77a4eb4..2e7aee5 100644
> --- a/common/rc
> +++ b/common/rc
> @@ -2372,27 +2372,27 @@ _scratch_mkfs_richacl()
>         esac
>  }
>
> -# check that a FS on a device is mounted
> +# check that a FS on a device is mounted or a dir is a mount point
>  # if so, return mount point
>  #
>  _is_mounted()
>  {
> -    if [ $# -ne 1 ]
> -    then
> -       echo "Usage: _is_mounted device" 1>&2
> -       exit 1
> -    fi
> +       local name
> +       local fstype
>
> -    device=$1
> +       if [ $# -eq 2 ]; then
> +               name=$1
> +               fstype=$2
> +       elif [ $# -eq 1 ]; then
> +               name=$1

missing fstype=$FSTYP here?
probably need to check better that this change did not break _is_mounted users

suggesting:

    if [ $# -lt 1 ]
...
       local name=$1
       local fstype=${2-$FSTYP}
--
To unsubscribe from this list: send the line "unsubscribe fstests" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/common/rc b/common/rc
index 77a4eb4..2e7aee5 100644
--- a/common/rc
+++ b/common/rc
@@ -2372,27 +2372,27 @@  _scratch_mkfs_richacl()
 	esac
 }
 
-# check that a FS on a device is mounted
+# check that a FS on a device is mounted or a dir is a mount point
 # if so, return mount point
 #
 _is_mounted()
 {
-    if [ $# -ne 1 ]
-    then
-	echo "Usage: _is_mounted device" 1>&2
-	exit 1
-    fi
+	local name
+	local fstype
 
-    device=$1
+	if [ $# -eq 2 ]; then
+		name=$1
+		fstype=$2
+	elif [ $# -eq 1 ]; then
+		name=$1
+	else
+		echo "Usage: _is_mounted <device|mountpoint> [fstype]" 1>&2
+		exit 1
+	fi
 
-    if _mount | grep "$device " | $AWK_PROG -v pattern="type $FSTYP" '
-        pattern        { print $3 ; exit 0 }
-        END            { exit 1 }
-    '
-    then
-        echo "_is_mounted: $device is not a mounted $FSTYP FS"
-        exit 1
-    fi
+	_mount | grep "$name " | $AWK_PROG -v pattern="type $fstype" '
+		$0 ~ pattern	{ print $3 }
+	'
 }
 
 # remount a FS to a new mode (ro or rw)