common/rc: add scratch shutdown support for overlayfs
authorChengguang Xu <cgxu519@icloud.com>
Fri, 15 Dec 2017 07:47:33 +0000 (15:47 +0800)
committerEryu Guan <eguan@redhat.com>
Sun, 24 Dec 2017 13:30:58 +0000 (21:30 +0800)
Enable shutdown tests on overlayfs. This requires configuring
overlayfs with TEST|SCRATCH_DEV pointing to block device, which act
as base fs of overlay. The legacy config (pointing TEST|SCRATCH_DEV
to existing directories) won't support shutdown.

Extend _require_scratch_shutdown() to deal with overlay by checking
shutdown support on $OVL_BASE_SCRATCH_MNT instead of $SCRATCH_MNT,
so we check shutdown support status against the underlying upper fs
of overlay.

Introduce new _scratch_shutdown() helper to do the actual shutdown
work and shutdown upper fs in the case of overlay. Also converting
existing bare 'src/godown' calls to use this helper to avoid false
failures when testing overlayfs.

generic/042 and generic/050 assume $SCRATCH_DEV to be a local
device, so add _require_local_device $SCRATCH_DEV rule.

[eguan: rewrite commit log]

Signed-off-by: Chengguang Xu <cgxu519@icloud.com>
Reviewed-by: Eryu Guan <eguan@redhat.com>
Signed-off-by: Eryu Guan <eguan@redhat.com>
19 files changed:
common/rc
tests/generic/042
tests/generic/043
tests/generic/044
tests/generic/045
tests/generic/046
tests/generic/047
tests/generic/048
tests/generic/049
tests/generic/050
tests/generic/051
tests/generic/052
tests/generic/054
tests/generic/055
tests/generic/388
tests/generic/392
tests/generic/417
tests/generic/461
tests/generic/468

index cbfc85c5805063b07077ba89c9d6279ffa9a6d8a..cebd36347ecea47d08226eeec835f55dac4b9ee2 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -382,6 +382,23 @@ _scratch_cycle_mount()
     _scratch_mount "$opts"
 }
 
+_scratch_shutdown()
+{
+       if [ $FSTYP = "overlay" ]; then
+               # In lagacy overlay usage, it may specify directory as
+               # SCRATCH_DEV, in this case OVL_BASE_SCRATCH_DEV
+               # will be null, so check OVL_BASE_SCRATCH_DEV before
+               # running shutdown to avoid shutting down base fs accidently.
+               if [ -z $OVL_BASE_SCRATCH_DEV ]; then
+                       _fail "_scratch_shutdown: call _require_scratch_shutdown first in test"
+               else
+                       src/godown $* $OVL_BASE_SCRATCH_MNT
+               fi
+       else
+               src/godown $* $SCRATCH_MNT
+       fi
+}
+
 _test_mount()
 {
     if [ "$FSTYP" == "overlay" ]; then
@@ -2915,10 +2932,25 @@ _require_scratch_shutdown()
 {
        [ -x src/godown ] || _notrun "src/godown executable not found"
 
-       _scratch_mkfs > /dev/null 2>&1
-       _scratch_mount
-       src/godown -f $SCRATCH_MNT 2>&1 \
-               || _notrun "$FSTYP does not support shutdown"
+       _scratch_mkfs > /dev/null 2>&1 || _notrun "_scratch_mkfs failed on $SCRATCH_DEV"
+       _scratch_mount || _notrun "_scratch_mount failed on $SCRATCH_MNT"
+
+       if [ $FSTYP = "overlay" ]; then
+               if [ -z $OVL_BASE_SCRATCH_DEV ]; then
+                       # In lagacy overlay usage, it may specify directory as
+                       # SCRATCH_DEV, in this case OVL_BASE_SCRATCH_DEV
+                       # will be null, so check OVL_BASE_SCRATCH_DEV before
+                       # running shutdown to avoid shutting down base fs accidently.
+                       _notrun "$SCRATCH_DEV is not a block device"
+               else
+                       src/godown -f $OVL_BASE_SCRATCH_MNT 2>&1 \
+                       || _notrun "Underlying filesystem does not support shutdown"
+               fi
+       else
+               src/godown -f $SCRATCH_MNT 2>&1 \
+                       || _notrun "$FSTYP does not support shutdown"
+       fi
+
        _scratch_unmount
 }
 
index 68ff03c65580396939769252e8110921251d7933..00b3a3463651d947df9d9943672319cd592184ad 100755 (executable)
@@ -92,6 +92,7 @@ _require_xfs_io_command "fpunch"
 _require_xfs_io_command "fzero"
 
 _scratch_mkfs >/dev/null 2>&1
+_require_local_device $SCRATCH_DEV
 _require_metadata_journaling $SCRATCH_DEV
 _scratch_mount
 
index 5dadab32bbd9ffe07b7be291af7c4dc0501384df..f61222ce3d7e4b8dd95951fb7a3b517adaf4cddc 100755 (executable)
@@ -63,7 +63,7 @@ done
 # give the system a chance to write something out
 sleep 10
 
-src/godown $SCRATCH_MNT
+_scratch_shutdown
 
 _scratch_unmount
 _scratch_mount
index 804b1b17c2c180c57e0bd0ebad197b4c5ca34106..f327ee0bf2812eb8fb041308d6c377fa425e8322 100755 (executable)
@@ -69,7 +69,7 @@ done
 # give the system a chance to write something out
 sleep 10
 
-src/godown $SCRATCH_MNT
+_scratch_shutdown
 
 _scratch_unmount
 _scratch_mount
index 5fa7b09f99e53070bd28f7e50002894438ef47d3..53489108cfaca178bd4c2a7aafabed100771b376 100755 (executable)
@@ -69,7 +69,7 @@ done
 # give the system a chance to write something out
 sleep 10
 
-src/godown $SCRATCH_MNT
+_scratch_shutdown
 
 _scratch_unmount
 _scratch_mount
index bf38d53abe35b41ea7e77ae3c10c5170651092cb..1155ee9877a5df419f2fd89ab06fa1baed5d0e65 100755 (executable)
@@ -69,7 +69,7 @@ done
 # give the system a chance to write something out
 sleep 10
 
-src/godown $SCRATCH_MNT
+_scratch_shutdown
 
 _scratch_unmount
 _scratch_mount
index 7d09b04c69bb17c6fa98d64893a72b7f4bcf825a..66965f25ca26ce7a5051b5e9d7e435caaa7f634d 100755 (executable)
@@ -92,7 +92,7 @@ do
 done
 
 # shutdown immediately after, then remount and test
-src/godown $SCRATCH_MNT
+_scratch_shutdown
 _scratch_unmount
 _scratch_mount
 _scratch_unmount
index ae561fcabceca05d0e8003cc8c0e038abbd472e1..fd9fcd9291502943fbebfff2ba771078bbc03919 100755 (executable)
@@ -96,7 +96,7 @@ done
 
 # sync, then shutdown immediately after, then remount and test
 sync
-src/godown $SCRATCH_MNT
+_scratch_shutdown
 _scratch_unmount
 _scratch_mount
 _scratch_unmount
index ef2b44c46aeccfdda3e8342eda0180c9a8ce8494..0003046bbc6499c154eb74390e73344520eb06ed 100755 (executable)
@@ -93,7 +93,7 @@ done
 
 # sync, then shutdown immediately after, then remount and test
 sync
-src/godown $SCRATCH_MNT
+_scratch_shutdown
 _scratch_unmount
 _scratch_mount
 _scratch_unmount
index efa45f04825b999cf393660ba2947fc3cae4e465..dbf0ac5cd1853a05f1206a785df7fd52e184b4b4 100755 (executable)
@@ -44,6 +44,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
 _supported_fs generic
 _supported_os Linux
 
+_require_local_device $SCRATCH_DEV
 _require_scratch_nocheck
 _require_scratch_shutdown
 _require_norecovery
index 29ac61b600c5fb1c5d8524a134caf1a7c2ba2c2d..129a4668aa8b37a141f6cbd54f17e2d303c1f77a 100755 (executable)
@@ -80,7 +80,7 @@ sync
 
 # now shutdown and unmount
 sleep 5
-$here/src/godown $load_dir
+_scratch_shutdown
 $KILLALL_PROG -q $FSSTRESS_PROG
 wait
 
index cf0f45680002f1ba0a1784c8b1ea6da6e2b6339e..126f08e633113358228c140665ff2ad09fde98de 100755 (executable)
@@ -63,7 +63,7 @@ echo "touch files"
 touch $SCRATCH_MNT/{0,1,2,3,4,5,6,7,8,9}{0,1,2,3,4,5,6,7,8,9}
 
 echo "godown"
-src/godown -v -f $SCRATCH_MNT >> $seqres.full
+_scratch_shutdown -v -f >> $seqres.full
 
 echo "unmount"
 _scratch_unmount
index db4150094bd998d26eec4794bf1bbdfa1393b92e..12f471a19090d81ca81c932a7670d7d31b18d51d 100755 (executable)
@@ -108,7 +108,7 @@ for s in sync nosync ; do
        ls $SCRATCH_MNT | _filter_lostfound
 
        _echofull "godown"
-       src/godown -v -f $SCRATCH_MNT >> $seqres.full
+       _scratch_shutdown -v -f >> $seqres.full
 
        _echofull "unmount"
        _scratch_unmount >>$seqres.full 2>&1 \
index 1bbe3108c41614caab3e78dc918c8dd2b8192f58..c543e75179409e659a8f65088afb850f27a0fab3 100755 (executable)
@@ -118,7 +118,7 @@ do
     ls -RF $SCRATCH_MNT >$tmp.ls1
 
     _echofull "godown"
-    src/godown -v -f $SCRATCH_MNT >> $seqres.full
+    _scratch_shutdown -v -f >> $seqres.full
 
     _echofull "unmount"
     _scratch_unmount >>$seqres.full 2>&1 \
index 4f5a63b98fe4b35edd268269ea727aa46c902e9b..e0f4821822991f89db88cbc99d2c5b2d33af31fb 100755 (executable)
@@ -54,6 +54,7 @@ _supported_fs generic
 _supported_os Linux
 
 _require_scratch
+_require_local_device $SCRATCH_DEV
 _require_scratch_shutdown
 _require_command "$KILLALL_PROG" "killall"
 
@@ -72,7 +73,7 @@ for i in $(seq 1 $((50 * TIME_FACTOR)) ); do
        # purposely include 0 second sleeps to test shutdown immediately after
        # recovery
        sleep $((RANDOM % 3))
-       ./src/godown $SCRATCH_MNT
+       _scratch_shutdown
 
        ps -e | grep fsstress > /dev/null 2>&1
        while [ $? -eq 0 ]; do
index 6922f7d2a887f59080ced27530b96f1d08d7df83..9d534138927fc2453af17905be4fd2fc88196dec 100755 (executable)
@@ -73,7 +73,7 @@ check_inode_metadata()
        before=`stat "$stat_opt" $testfile`
 
        $XFS_IO_PROG -c "$sync_mode" $testfile | _filter_xfs_io
-       src/godown $SCRATCH_MNT | tee -a $seqres.full
+       _scratch_shutdown | tee -a $seqres.full
        _scratch_cycle_mount
 
        after=`stat "$stat_opt" $testfile`
index 690ceb5d161de8e41f9cfc1f3d52a51d1e72d6a9..e66e0aeb7a435f0c95d35ddd34def97a1c1f292b 100755 (executable)
@@ -75,7 +75,7 @@ function create_dirty_orphans() {
        sleep 3
 
        echo "godown"
-       src/godown -v -f $SCRATCH_MNT >> $seqres.full
+       _scratch_shutdown -v -f >> $seqres.full
 
        # kill the multi_open_unlink
        kill $pid 2>/dev/null
index 2f851149488b4f617fd5adae19d992d53cb42e26..50b9c6d4fb6292a9236b0d110b752251327331d2 100755 (executable)
@@ -68,7 +68,7 @@ sync
 
 # now shutdown and unmount
 sleep 5
-$here/src/godown $load_dir
+_scratch_shutdown
 $KILLALL_PROG -q $FSSTRESS_PROG
 wait
 
index b97a8d6348394aa37d01c5e28d7f35cfbc36f4a4..30c41744ba9be3608141b741da6687ac41d63155 100755 (executable)
@@ -84,7 +84,7 @@ check_inode_metadata()
        before=`stat "$stat_opt" $testfile`
 
        $XFS_IO_PROG -c "$sync_mode" $testfile | _filter_xfs_io
-       $here/src/godown $SCRATCH_MNT | tee -a $seqres.full
+       _scratch_shutdown | tee -a $seqres.full
        _scratch_cycle_mount
 
        after=`stat "$stat_opt" $testfile`