generic: test mount move semantics
authorZorro Lang <zlang@redhat.com>
Sat, 30 Nov 2019 06:53:24 +0000 (14:53 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sun, 8 Dec 2019 14:15:34 +0000 (22:15 +0800)
This's a functional test case for mount --move operation, it verifies
below semantics:

  ---------------------------------------------------------------------------
  |         MOVE MOUNT OPERATION                                            |
  |**************************************************************************
  |source(A)->| shared       |       private  |       slave    | unbindable |
  | dest(B)  |               |                |                |            |
  |   |      |               |                |                |            |
  |   v      |               |                |                |            |
  |**************************************************************************
  |  shared  | shared        |     shared     | shared & slave |  invalid   |
  |          |               |                |                |            |
  |non-shared| shared        |      private   |      slave     | unbindable |
  ***************************************************************************
  NOTE: moving a mount residing under a shared mount is invalid.

This case uses fsstress to produce a little random load, to make
sure basic operations won't break the the moved mountpoints.

Signed-off-by: Zorro Lang <zlang@redhat.com>
Reviewed-by: Eryu Guan <guaneryu@gmail.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/rc
tests/generic/589 [new file with mode: 0755]
tests/generic/589.out [new file with mode: 0644]
tests/generic/group

index 6943f19f130c520c65ab00e0458d90ab1f321744..74889419b004e18b83803fd559a1989b1fe5534e 100644 (file)
--- a/common/rc
+++ b/common/rc
@@ -189,6 +189,12 @@ _get_mount()
 
        _mount $scratch_opts $*
        if [ $? -eq 0 ]; then
+               # mount --move operation updates the mountpoint, so remove
+               # the old one and insert the new one
+               if [[ "$*" =~ --move|-M ]]; then
+                       MOUNTED_POINT_STACK=`echo $MOUNTED_POINT_STACK | \
+                                               cut -d\  -f2-`
+               fi
                MOUNTED_POINT_STACK="$mnt_point $MOUNTED_POINT_STACK"
        else
                return 1
diff --git a/tests/generic/589 b/tests/generic/589
new file mode 100755 (executable)
index 0000000..cf61e68
--- /dev/null
@@ -0,0 +1,182 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2019 Red Hat Inc.  All Rights Reserved.
+#
+# FS QA Test 589
+#
+# Test mount shared subtrees, verify the move semantics:
+#
+# ---------------------------------------------------------------------------
+# |         MOVE MOUNT OPERATION                                            |
+# |**************************************************************************
+# |source(A)->| shared       |       private  |       slave    | unbindable |
+# | dest(B)  |               |                |                |            |
+# |   |      |               |                |                |            |
+# |   v      |               |                |                |            |
+# |**************************************************************************
+# |  shared  | shared        |     shared     | shared & slave |  invalid   |
+# |          |               |                |                |            |
+# |non-shared| shared        |      private   |      slave     | unbindable |
+# ***************************************************************************
+#   NOTE: moving a mount residing under a shared mount is invalid.
+#
+#-----------------------------------------------------------------------
+#
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1       # failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+       cd /
+       rm -f $tmp.*
+       _clear_mount_stack
+       # make sure there's no bug cause dentry isn't be freed
+       rm -rf $MNTHEAD
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_scratch
+_require_local_device $SCRATCH_DEV
+
+fs_stress()
+{
+       local target=$1
+
+       $FSSTRESS_PROG -n 50 -p 3 -d $target >/dev/null
+       sync
+}
+
+# prepare some mountpoint dir
+SRCHEAD=$TEST_DIR/$seq-src
+DSTHEAD=$TEST_DIR/$seq-dst
+rm -rf $SRCHEAD $DSTHEAD
+mkdir $SRCHEAD $DSTHEAD 2>>$seqres.full
+mpA=$SRCHEAD/"$$"_mpA
+mpB=$SRCHEAD/"$$"_mpB
+mpC=$DSTHEAD/"$$"_mpC
+mpD=$DSTHEAD/"$$"_mpD
+
+find_mnt()
+{
+       echo "------"
+       findmnt -n -o TARGET,SOURCE $SCRATCH_DEV | \
+               sed -e "s;$mpA;mpA;g" \
+                   -e "s;$mpB;mpB;g" \
+                   -e "s;$mpC;mpC;g" \
+                   -e "s;$mpD;mpD;g" | \
+               _filter_spaces | _filter_testdir_and_scratch | sort
+       echo "======"
+}
+
+start_test()
+{
+       local type=$1
+
+       _scratch_mkfs >$seqres.full 2>&1
+
+       _get_mount -t $FSTYP $SCRATCH_DEV $SRCHEAD
+       # make sure $SRCHEAD is private
+       $MOUNT_PROG --make-private $SRCHEAD
+
+       _get_mount -t $FSTYP $SCRATCH_DEV $DSTHEAD
+       # test start with a bind, then make-shared $DSTHEAD
+       _get_mount --bind $DSTHEAD $DSTHEAD
+       $MOUNT_PROG --make-"${type}" $DSTHEAD
+       mkdir $mpA $mpB $mpC $mpD
+}
+
+end_test()
+{
+       _clear_mount_stack
+       rm -rf $mpA $mpB $mpC $mpD
+}
+
+move_run()
+{
+       local source=$1
+       local dest=$2
+
+       start_test $dest
+
+       echo "move $source to $dest"
+       _get_mount -t $FSTYP $SCRATCH_DEV $mpA
+       mkdir -p $mpA/dir 2>/dev/null
+       $MOUNT_PROG --make-shared $mpA
+       # need a peer for slave later
+       _get_mount --bind $mpA $mpB
+       $MOUNT_PROG --make-"$source" $mpB
+       # maybe unbindable at here
+       _get_mount --move $mpB $mpC 2>/dev/null
+       if [ $? -ne 0 ]; then
+               find_mnt
+               end_test
+               return 0
+       fi
+
+       # check mpC after move B to C
+       for m in $mpA $mpC; do
+               _get_mount -t $FSTYP $SCRATCH_DEV $m/dir
+               fs_stress $m/dir
+               find_mnt
+               _put_mount
+       done
+
+       # mpC will be in different parent mount, test moving from different
+       # parent mount, and moving a mount residing under a shared mount is
+       # invalid
+       _get_mount --move $mpC $mpD 2>/dev/null
+       if [ $? -ne 0 ]; then
+               find_mnt
+               end_test
+               return 0
+       fi
+       for m in $mpA $mpD; do
+               _get_mount -t $FSTYP $SCRATCH_DEV $m/dir
+               fs_stress $m/dir
+               find_mnt
+               _put_mount
+       done
+
+       end_test
+}
+
+move_test()
+{
+       #        source     dest
+       move_run shared     shared
+       move_run slave      shared
+       move_run private    shared
+       move_run unbindable shared
+
+       move_run shared     slave
+       move_run slave      slave
+       move_run private    slave
+       move_run unbindable slave
+
+       move_run shared     private
+       move_run slave      private
+       move_run private    private
+       move_run unbindable private
+}
+
+move_test
+
+# success, all done
+status=0
+exit
diff --git a/tests/generic/589.out b/tests/generic/589.out
new file mode 100644 (file)
index 0000000..b0eb1e0
--- /dev/null
@@ -0,0 +1,374 @@
+QA output created by 589
+move shared to shared
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC SCRATCH_DEV
+======
+move slave to shared
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC SCRATCH_DEV
+======
+move private to shared
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC SCRATCH_DEV
+======
+move unbindable to shared
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpB SCRATCH_DEV
+======
+move shared to slave
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+move slave to slave
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+move private to slave
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+move unbindable to slave
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+move shared to private
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+move slave to private
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+move private to private
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
+move unbindable to private
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpC SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpC SCRATCH_DEV
+mpC/dir SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpA/dir SCRATCH_DEV
+mpD SCRATCH_DEV
+======
+------
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-dst SCRATCH_DEV
+TEST_DIR/589-src SCRATCH_DEV
+mpA SCRATCH_DEV
+mpD SCRATCH_DEV
+mpD/dir SCRATCH_DEV
+======
index 87d7441c350813f5349755785d26ffe89a539376..fef8ea124e702b496b5cc2d33bcc28f2a5dc2e3a 100644 (file)
 586 auto quick rw prealloc
 587 auto quick rw prealloc
 588 auto quick log clone
+589 auto mount