common: check if a given rename flag is supported in _require_renameat2
authorkaixuxia <xiakaixu1987@gmail.com>
Wed, 18 Sep 2019 11:47:47 +0000 (19:47 +0800)
committerEryu Guan <guaneryu@gmail.com>
Sat, 21 Sep 2019 14:26:52 +0000 (22:26 +0800)
Some testcases may require a special rename flag, such as
RENAME_WHITEOUT, so add support check for if a given rename flag is
supported in _require_renameat2.

[Eryu: rename the helper to _require_renameat2 while we're at it,
and add 'exchange' check to generic/398 and generic/419]

Signed-off-by: kaixuxia <kaixuxia@tencent.com>
Reviewed-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Eryu Guan <guaneryu@gmail.com>
common/renameat2
tests/generic/023
tests/generic/024
tests/generic/025
tests/generic/078
tests/generic/398
tests/generic/419

index f8d6d4f7a2bd43c5376f661a0bb347a3f51cfd21..2538141caf728da5c04f1b2974c824ba388add11 100644 (file)
@@ -101,12 +101,41 @@ _rename_tests()
 #
 # This checks whether the renameat2 syscall is supported
 #
-_requires_renameat2()
+_require_renameat2()
 {
+       local flags=$1
+       local rename_dir=$TEST_DIR/$$
+       local cmd=""
+
        if test ! -x src/renameat2; then
                _notrun "renameat2 binary not found"
        fi
-       if ! src/renameat2 -t; then
+
+       mkdir $rename_dir
+       touch $rename_dir/foo
+       case $flags in
+       "noreplace")
+               cmd="-n $rename_dir/foo $rename_dir/bar"
+               ;;
+       "exchange")
+               touch $rename_dir/bar
+               cmd="-x $rename_dir/foo $rename_dir/bar"
+               ;;
+       "whiteout")
+               touch $rename_dir/bar
+               cmd="-w $rename_dir/foo $rename_dir/bar"
+               ;;
+       "")
+               cmd=""
+               ;;
+       *)
+               rm -rf $rename_dir
+               _fail "_require_renameat2: only support noreplace,exchange,whiteout rename flags"
+               ;;
+       esac
+       if ! src/renameat2 -t $cmd; then
+               rm -rf $rename_dir
                _notrun "kernel doesn't support renameat2 syscall"
        fi
+       rm -rf $rename_dir
 }
index 67739b1db0944fbebfd6a5789b1c9a93b22b9150..ea40f3d278441321bec8ccc78d370e6668e71841 100755 (executable)
@@ -29,7 +29,7 @@ _supported_fs generic
 _supported_os Linux
 
 _require_test
-_requires_renameat2
+_require_renameat2
 _require_test_symlinks
 
 # real QA test starts here
index 2888c661a2b3ed5cd2a4d9d5354de2bc0f64b6fc..531a515f3add9ecbe0617a128e042d6d5186bd4b 100755 (executable)
@@ -29,20 +29,13 @@ _supported_fs generic
 _supported_os Linux
 
 _require_test
-_requires_renameat2
+_require_renameat2 noreplace
 _require_test_symlinks
 
-rename_dir=$TEST_DIR/$$
-mkdir $rename_dir
-touch $rename_dir/foo
-if ! src/renameat2 -t -n $rename_dir/foo $rename_dir/bar; then
-    rm -f $rename_dir/foo $rename_dir/bar; rmdir $rename_dir
-    _notrun "fs doesn't support RENAME_NOREPLACE"
-fi
-rm -f $rename_dir/foo $rename_dir/bar
-
 # real QA test starts here
 
+rename_dir=$TEST_DIR/$$
+mkdir $rename_dir
 _rename_tests $rename_dir -n
 rmdir $rename_dir
 
index 0310efa5177ccbfb3a6859a9ad64477a4ce1f6be..e69d655f218d1e832e65e9f25e2c4fd7aa91b7af 100755 (executable)
@@ -29,20 +29,13 @@ _supported_fs generic
 _supported_os Linux
 
 _require_test
-_requires_renameat2
+_require_renameat2 exchange
 _require_test_symlinks
 
-rename_dir=$TEST_DIR/$$
-mkdir $rename_dir
-touch $rename_dir/foo $rename_dir/bar
-if ! src/renameat2 -t -x $rename_dir/foo $rename_dir/bar; then
-    rm -f $rename_dir/foo $rename_dir/bar; rmdir $rename_dir
-    _notrun "fs doesn't support RENAME_EXCHANGE"
-fi
-rm -f $rename_dir/foo $rename_dir/bar
-
 # real QA test starts here
 
+rename_dir=$TEST_DIR/$$
+mkdir $rename_dir
 _rename_tests $rename_dir -x
 rmdir $rename_dir
 
index 9608574f3e6dec0a5a3aee34d263ef1cdc385bea..a421a8abb1ddee096d3bf231f2f8abcee1104c27 100755 (executable)
@@ -29,20 +29,13 @@ _supported_fs generic
 _supported_os Linux
 
 _require_test
-_requires_renameat2
+_require_renameat2 whiteout
 _require_test_symlinks
 
-rename_dir=$TEST_DIR/$$
-mkdir $rename_dir
-touch $rename_dir/foo $rename_dir/bar
-if ! src/renameat2 -t -w $rename_dir/foo $rename_dir/bar; then
-    rm -f $rename_dir/foo $rename_dir/bar; rmdir $rename_dir
-    _notrun "fs doesn't support RENAME_WHITEOUT"
-fi
-rm -f $rename_dir/foo $rename_dir/bar
-
 # real QA test starts here
 
+rename_dir=$TEST_DIR/$$
+mkdir $rename_dir
 _rename_tests $rename_dir -w
 rmdir $rename_dir
 
index b1af65e5c6de123050e4e426feae30606a980335..d224e02122483d5700cb3e8ceaf36b6358fb6e6b 100755 (executable)
@@ -56,7 +56,7 @@ rm -f $seqres.full
 _supported_fs generic
 _supported_os Linux
 _require_scratch_encryption
-_requires_renameat2
+_require_renameat2 exchange
 
 _new_session_keyring
 _scratch_mkfs_encrypted &>> $seqres.full
index 2f1d34c6059f8a5fc32a0fda195f7cfc84653e0a..0abbac90ea7aa6a1bf76f3703aea099529feabe0 100755 (executable)
@@ -39,7 +39,7 @@ _supported_fs generic
 _supported_os Linux
 _require_scratch_encryption
 _require_command "$KEYCTL_PROG" keyctl
-_requires_renameat2
+_require_renameat2 exchange
 
 _new_session_keyring