]> git.apps.os.sepia.ceph.com Git - xfstests-dev.git/commitdiff
common: Introduce get_block_size() helper
authorLukas Czerner <lczerner@redhat.com>
Tue, 14 Oct 2014 06:07:52 +0000 (17:07 +1100)
committerDave Chinner <david@fromorbit.com>
Tue, 14 Oct 2014 06:07:52 +0000 (17:07 +1100)
Currently many tests and other functions uses it's own way to get block
size of the file system. Introduce get_block_size(), a generic way to
get block size of mounted file system and use that instead.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
common/attr
common/punch
common/rc
tests/generic/240
tests/generic/256
tests/generic/308
tests/shared/298

index f33166e58862f9d6dd5e59952fbd6e2b784be0e5..48c81ccf7dab8dac6ccac04de1d86b57e11846a7 100644 (file)
@@ -249,7 +249,7 @@ _sort_getfattr_output()
 if [ "$FSTYP" == "xfs" -o "$FSTYP" == "udf" ]; then
        MAX_ATTRS=1000
 else # Assume max ~1 block of attrs
-       BLOCK_SIZE=`stat -f $TEST_DIR | grep "Block size" | cut -d " " -f3`
+       BLOCK_SIZE=`get_block_size $TEST_DIR`
        # user.attribute_XXX="value.XXX" is about 32 bytes; leave some overhead
        let MAX_ATTRS=$BLOCK_SIZE/40
 fi
@@ -260,7 +260,7 @@ export MAX_ATTRS
 if [ "$FSTYP" == "xfs" -o "$FSTYP" == "udf" -o "$FSTYP" == "btrfs" ]; then
        MAX_ATTRVAL_SIZE=64
 else # Assume max ~1 block of attrs
-       BLOCK_SIZE=`stat -f $TEST_DIR | grep "Block size" | cut -d " " -f3`
+       BLOCK_SIZE=`get_block_size $TEST_DIR`
        # leave a little overhead
        let MAX_ATTRVAL_SIZE=$BLOCK_SIZE-256
 fi
index f2d538c1d3e73656ede38c30715f1b77391bea9b..237b4d886fe653841ad6038d449aff6f2081165a 100644 (file)
@@ -557,7 +557,7 @@ _test_generic_punch()
        if [ "$remove_testfile" ]; then
                rm -f $testfile
        fi
-       block_size=`stat -f $TEST_DIR | grep "Block size" | cut -d " " -f3`
+       block_size=`get_block_size $TEST_DIR`
        $XFS_IO_PROG -f -c "truncate $block_size" \
                -c "pwrite 0 $block_size" $sync_cmd \
                -c "$zero_cmd 128 128" \
index 34d7c19b95f81029388100fc3edb74eda7b10472..59ce2dba68e0443556e0ca8961c75669dc5c66c9 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -2542,6 +2542,15 @@ _short_dev()
        echo `basename $(_real_dev $1)`
 }
 
+get_block_size()
+{
+       if [ -z $1 ] || [ ! -d $1 ]; then
+               echo "Missing mount point argument for get_block_size"
+               exit 1
+       fi
+       echo `stat -f -c %S $1`
+}
+
 init_rc
 
 ################################################################################
index c063dd48c2383d9fd53a2aac58b7df30a196d0a8..e32f15ae3435966fc40d32960a720f92cfb56fc1 100755 (executable)
@@ -62,7 +62,7 @@ rm -f $seqres.full
 rm -f $TEST_DIR/aiodio_sparse
 
 logical_block_size=`_min_dio_alignment $TEST_DEV`
-fs_block_size=`stat -f $TEST_DIR | grep "Block size:" | awk '{print $3}'`
+fs_block_size=`get_block_size $TEST_DIR`
 file_size=$((8 * $fs_block_size))
 
 if [ $fs_block_size -le $logical_block_size ]; then
index 8ee8aaccc540b59e038a9e0214b669a2b027e8f0..086c00a14b2b91afdceaa9e1ed68626256e0f352 100755 (executable)
@@ -171,7 +171,7 @@ _scratch_mount
 # Test must be able to write files with non-root permissions
 chmod 777 $SCRATCH_MNT
 
-block_size=`stat -f $SCRATCH_DEV | grep "Block size" | cut -d " " -f3`
+block_size=`get_block_size $SCRATCH_MNT`
 _test_full_fs_punch $(( $block_size * 2 )) $block_size 500 $SCRATCH_MNT/252.$$ $block_size
 
 status=0 ; exit
index 418dbf27a0bc56a94a1d551cc08442294082a1b1..e639da1fc8f1df7e6c7cfa937dfbbe8e98daa240 100755 (executable)
@@ -49,7 +49,7 @@ _require_test
 rm -f $seqres.full
 echo "Silence is golden"
 
-block_size=`stat -f -c %s $TEST_DIR`
+block_size=`get_block_size $TEST_DIR`
 
 # On unpatched ext4, if an extent exists which includes the block right
 # before the maximum file offset, and the block for the maximum file offset
index 2b7fdd1a89ea11a9ee99ff93294f941ef72e75d8..2ed7eabb4dbac129eb2846c1a1ae19340ed18314 100755 (executable)
@@ -165,7 +165,7 @@ echo "done."
 
 echo -n "Comparing holes to the reported space from FS..."
 # Get block size
-block_size=$(stat -f -c "%S" $loop_mnt/)
+block_size=$(get_block_size $loop_mnt/)
 sectors_per_block=`expr $block_size / 512`
 
 # Obtain free space from filesystem