common/rc: factor out _ext4_disable_extent_zeroout() helper
authorXiao Yang <yangx.jy@cn.fujitsu.com>
Mon, 24 Jul 2017 10:44:31 +0000 (18:44 +0800)
committerEryu Guan <eguan@redhat.com>
Fri, 28 Jul 2017 10:53:51 +0000 (18:53 +0800)
1) This pattern is repeated in several seek_data/hole tests
   (e.g. generic/285, generic/436, generic/445 generic/448)
   and generic/009.  A common _ext4_disable_extent_zeroout()
   helper could be added and applied by generic/009 and
   _require_seek_data_hole().

2) On some old kernels(e.g. v3.1-v3.6), when vfs recognizes
   SEEK_DATA/HOLE flag && ext4 has no extent zeroout tunable
   in sysfs, these cases may trigger "sysfs entry not found"
   issue.  We can add check if extent_max_zeroout_kb exists
   on ext4 filesystem.
   The extent_max_zeroout_kb is introduced by:
   '67a5da564f97 ("ext4: make the zero-out chunk size tunable")'

3) Declare several vars as local in _require_seek_data_hole().

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
common/rc
tests/generic/009
tests/generic/285
tests/generic/436
tests/generic/445
tests/generic/448

index f09f5ef328c22f1faac5ffa80dd1a8c464c62280..c7529796ad559eefd93d8558c67ef2e70969c36c 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -2295,16 +2295,31 @@ _require_fail_make_request()
  not found. Seems that CONFIG_FAIL_MAKE_REQUEST kernel config option not enabled"
 }
 
-#
+# Disable extent zeroing for ext4 on the given device
+_ext4_disable_extent_zeroout()
+{
+       local dev=${1:-$TEST_DEV}
+       local sdev=`_short_dev $dev`
+
+       [ -f /sys/fs/ext4/$sdev/extent_max_zeroout_kb ] && \
+               echo 0 >/sys/fs/ext4/$sdev/extent_max_zeroout_kb
+}
+
 # Check if the file system supports seek_data/hole
-#
 _require_seek_data_hole()
 {
-    testfile=$TEST_DIR/$$.seek
-    testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
-    rm -f $testfile &>/dev/null
-    echo $testseek | grep -q "Kernel does not support" && \
-        _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
+       local dev=${1:-$TEST_DEV}
+       local testfile=$TEST_DIR/$$.seek
+       local testseek=`$here/src/seek_sanity_test -t $testfile 2>&1`
+
+       rm -f $testfile &>/dev/null
+       echo $testseek | grep -q "Kernel does not support" && \
+               _notrun "File system does not support llseek(2) SEEK_DATA/HOLE"
+       # Disable extent zeroing for ext4 as that change where holes are
+       # created
+       if [ "$FSTYP" = "ext4" ]; then
+               _ext4_disable_extent_zeroout $dev
+       fi
 }
 
 _require_runas()
index 5902afd323a0228c6896022e6ea1021769a6e6ac..797def5c3f03e90c5bcf869bba0068dbad9688cb 100755 (executable)
@@ -53,8 +53,7 @@ testfile=$TEST_DIR/009.$$
 
 # Disable extent zeroing for ext4 as that change where holes are created
 if [ "$FSTYP" = "ext4" ]; then
-       DEV=`_short_dev $TEST_DEV`
-       echo 0 >/sys/fs/ext4/$DEV/extent_max_zeroout_kb
+       _ext4_disable_extent_zeroout
 fi
 
 # When PAGE_SIZE > 4096 xfs extent layout is different so it would not match
index 16e70b1d75187e9e3ff74f00d356115f4bb9c0a9..3f7d298094e0dd0ba85449aeb8a35b1137378193 100755 (executable)
@@ -47,12 +47,6 @@ BASE_TEST_FILE=$TEST_DIR/seek_sanity_testfile
 
 _require_test_program "seek_sanity_test"
 
-# Disable extent zeroing for ext4 as that change where holes are created
-if [ "$FSTYP" = "ext4" ]; then
-       DEV=`_short_dev $TEST_DEV`
-       echo 0 >/sys/fs/ext4/$DEV/extent_max_zeroout_kb
-fi
-
 _cleanup()
 {
        eval "rm -f $BASE_TEST_FILE.*"
index bcd6ddc87cd56b99279fe89dd755a386a50826e9..6cda008bd83719327b6e7d9894c55080816e25b6 100755 (executable)
@@ -44,12 +44,6 @@ BASE_TEST_FILE=$TEST_DIR/seek_sanity_testfile
 
 _require_test_program "seek_sanity_test"
 
-# Disable extent zeroing for ext4 as that change where holes are created
-if [ "$FSTYP" = "ext4" ]; then
-       DEV=`_short_dev $TEST_DEV`
-       echo 0 >/sys/fs/ext4/$DEV/extent_max_zeroout_kb
-fi
-
 _cleanup()
 {
        rm -f $tmp.* $BASE_TEST_FILE.*
index 81dd916fe3cc0729aa4eae56482fc0e2edbd0e2c..323a0ca8fc29f9c08791fd8db0b74a0aafb14be3 100755 (executable)
@@ -44,12 +44,6 @@ BASE_TEST_FILE=$TEST_DIR/seek_sanity_testfile
 
 _require_test_program "seek_sanity_test"
 
-# Disable extent zeroing for ext4 as that change where holes are created
-if [ "$FSTYP" = "ext4" ]; then
-       DEV=`_short_dev $TEST_DEV`
-       echo 0 >/sys/fs/ext4/$DEV/extent_max_zeroout_kb
-fi
-
 _cleanup()
 {
        rm -f $tmp.* $BASE_TEST_FILE.*
index 87b99d71c1c0a3ca07cd8ddda8b1daebd8a10b03..22656f6c5302c473cc5904b37c835c68a6682061 100755 (executable)
@@ -48,12 +48,6 @@ BASE_TEST_FILE=$TEST_DIR/seek_sanity_testfile_$seq
 
 _require_test_program "seek_sanity_test"
 
-# Disable extent zeroing for ext4 as that change where holes are created
-if [ "$FSTYP" = "ext4" ]; then
-       DEV=`_short_dev $TEST_DEV`
-       echo 0 >/sys/fs/ext4/$DEV/extent_max_zeroout_kb
-fi
-
 $here/src/seek_sanity_test -s 18 -e 18 $BASE_TEST_FILE > $seqres.full 2>&1 ||
        _fail "seek sanity check failed!"