linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eryu Guan <eguan@redhat.com>
To: xfs@oss.sgi.com
Cc: Eryu Guan <eguan@redhat.com>
Subject: [PATCH v2] common: new function to get real device path name and basename
Date: Tue, 22 Apr 2014 14:57:13 +0800	[thread overview]
Message-ID: <1398149833-9761-1-git-send-email-eguan@redhat.com> (raw)
In-Reply-To: <20140422051051.GI18672@dastard>

If TEST_DEV or SCRATCH_DEV is symlink(mostly a lvm lv), a simple
basename is not enough, symlink should be followed.

This task is common enough, so introduce new helper functions and
replace all readlink calls in

ext4/305
generic/009
generic/019
generic/285
generic/312

Signed-off-by: Eryu Guan <eguan@redhat.com>
---
v2: rename _basename_dev to _short_dev as Dave suggested

 common/rc         | 16 ++++++++++++++++
 tests/ext4/305    |  2 +-
 tests/generic/009 |  2 +-
 tests/generic/019 |  4 +---
 tests/generic/285 |  2 +-
 tests/generic/312 |  2 +-
 6 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/common/rc b/common/rc
index acf419b..f16328d 100644
--- a/common/rc
+++ b/common/rc
@@ -2302,6 +2302,22 @@ init_rc()
 	export XFS_IO_PROG="$XFS_IO_PROG -F"
 }
 
+# get real device path name by following link
+_real_dev()
+{
+	local _dev=$1
+	if [ -b "$_dev" ] && [ -L "$_dev" ]; then
+		_dev=`readlink -f "$_dev"`
+	fi
+	echo $_dev
+}
+
+# basename of a device
+_short_dev()
+{
+	echo `basename $(_real_dev $1)`
+}
+
 init_rc
 
 ################################################################################
diff --git a/tests/ext4/305 b/tests/ext4/305
index eee461a..860d0a6 100755
--- a/tests/ext4/305
+++ b/tests/ext4/305
@@ -49,7 +49,7 @@ _require_scratch
 rm -f $seqres.full
 echo "Silence is golden"
 
-DEV_BASENAME=$(basename $(readlink -f $SCRATCH_DEV))
+DEV_BASENAME=$(_short_dev $SCRATCH_DEV)
 echo "Start test on device $SCRATCH_DEV, basename $DEV_BASENAME" >$seqres.full
 _scratch_mkfs >>$seqres.full 2>&1
 
diff --git a/tests/generic/009 b/tests/generic/009
index b7b0b3f..aa662b2 100644
--- a/tests/generic/009
+++ b/tests/generic/009
@@ -50,7 +50,7 @@ testfile=$TEST_DIR/009.$$
 
 # Disable extent zeroing for ext4 as that change where holes are created
 if [ "$FSTYP" = "ext4" ]; then
-	DEV=`basename $TEST_DEV`
+	DEV=`_short_dev $TEST_DEV`
 	echo 0 >/sys/fs/ext4/$DEV/extent_max_zeroout_kb
 fi
 
diff --git a/tests/generic/019 b/tests/generic/019
index 1208c49..7a019ad 100755
--- a/tests/generic/019
+++ b/tests/generic/019
@@ -41,9 +41,7 @@ _need_to_be_root
 _require_scratch
 _require_fail_make_request
 
-# TODO: Function are common enough to be moved to common/blkdev
-SCRATCH_REAL_DEV=`readlink -f $SCRATCH_DEV`
-SCRATCH_BDEV=`basename $SCRATCH_REAL_DEV`
+SCRATCH_BDEV=`_short_dev $SCRATCH_DEV`
 
 allow_fail_make_request()
 {
diff --git a/tests/generic/285 b/tests/generic/285
index 8078b1c..ac34d34 100755
--- a/tests/generic/285
+++ b/tests/generic/285
@@ -48,7 +48,7 @@ BASE_TEST_FILE=$TEST_DIR/seek_sanity_testfile
 
 # Disable extent zeroing for ext4 as that change where holes are created
 if [ "$FSTYP" = "ext4" ]; then
-	DEV=`basename $TEST_DEV`
+	DEV=`_short_dev $TEST_DEV`
 	echo 0 >/sys/fs/ext4/$DEV/extent_max_zeroout_kb
 fi
 
diff --git a/tests/generic/312 b/tests/generic/312
index eaec43c..eb6cec9 100755
--- a/tests/generic/312
+++ b/tests/generic/312
@@ -52,7 +52,7 @@ _require_scratch
 # 5G in byte
 fssize=$((2**30 * 5))
 required_blocks=$(($fssize / 1024))
-dev_blocks=$(grep $(basename $(readlink -f $SCRATCH_DEV)) /proc/partitions | $AWK_PROG '{print $3}')
+dev_blocks=$(grep $(_short_dev $SCRATCH_DEV) /proc/partitions | $AWK_PROG '{print $3}')
 if [ $required_blocks -gt $dev_blocks ];then
 	_notrun "this test requires \$SCRATCH_DEV has ${fssize}B space"
 fi
-- 
1.9.0

_______________________________________________
xfs mailing list
xfs@oss.sgi.com
http://oss.sgi.com/mailman/listinfo/xfs

  reply	other threads:[~2014-04-22  6:58 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-04-22  3:27 [PATCH] common: new function to get real device path name and basename Eryu Guan
2014-04-22  5:10 ` Dave Chinner
2014-04-22  6:57   ` Eryu Guan [this message]
2014-04-25  6:30     ` [PATCH v2] " Christoph Hellwig

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1398149833-9761-1-git-send-email-eguan@redhat.com \
    --to=eguan@redhat.com \
    --cc=xfs@oss.sgi.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).