common: new function to get real device path name and basename
authorEryu Guan <eguan@redhat.com>
Mon, 12 May 2014 23:05:43 +0000 (09:05 +1000)
committerDave Chinner <david@fromorbit.com>
Mon, 12 May 2014 23:05:43 +0000 (09:05 +1000)
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>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Dave Chinner <david@fromorbit.com>
common/rc
tests/ext4/305
tests/generic/009
tests/generic/019
tests/generic/285
tests/generic/312

index 5c13db5124fa4e0c70b5fbdc4269a36cda682dac..4eb6e2edfb70bf7a16b99cc82da18f46da8f52a5 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -2190,6 +2190,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
 
 ################################################################################
index eee461a5c7cca4196c205d03fe19f9a24685a95d..860d0a6526eda6a6ae6f6f0125505457b3e5ad8b 100755 (executable)
@@ -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
 
index 65abe3c12ba37d1e201088ccd97cae62e461ed38..08eafb90fe0a53229dcba73caca9f10dae2df98d 100644 (file)
@@ -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
 
index 1208c498e954a3ae0ab4b5b832e183e892db59f0..7a019ad6e48eb9798f9a151cc95e9be220199dca 100755 (executable)
@@ -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()
 {
index 8078b1c4e2d4608dd07d31c3fa21416d43e42798..ac34d34e7b7184b7362d62414ddcf08c70a4a8ac 100755 (executable)
@@ -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
 
index 1ed49626be98d124c1e8ede7d406bf1b5c837dbf..7611bb9ae841afa667a34f59654bf4e420af7776 100755 (executable)
@@ -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