mirror of
https://github.com/versity/scoutfs.git
synced 2025-12-23 05:25:18 +00:00
Add renameat2 unit test case
The goal of the test case is to have two mount points with two async calls made to do renameat2. This allows for two calls to race to call renameat2 RENAME_NOREPLACE. When this happens you expect one of them to fail with a -EEXIST. This would validate that the new flag works. Essentially one of the two calls to renameat should hit the new RENAME_NOREPLACE code and exit early. Signed-off-by: Bryant G. Duffy-Ly <bduffyly@versity.com>
This commit is contained in:
2
tests/golden/renameat2-noreplace
Normal file
2
tests/golden/renameat2-noreplace
Normal file
@@ -0,0 +1,2 @@
|
||||
=== renameat2 noreplace flag test
|
||||
=== run two asynchronous calls to renameat2 NOREPLACE
|
||||
@@ -37,4 +37,5 @@ createmany-parallel-mounts.sh
|
||||
archive-light-cycle.sh
|
||||
block-stale-reads.sh
|
||||
inode-deletion.sh
|
||||
renameat2-noreplace.sh
|
||||
xfstests.sh
|
||||
|
||||
37
tests/tests/renameat2-noreplace.sh
Normal file
37
tests/tests/renameat2-noreplace.sh
Normal file
@@ -0,0 +1,37 @@
|
||||
#
|
||||
# simple renameat2 NOREPLACE unit test
|
||||
#
|
||||
|
||||
t_require_commands dumb_renameat2
|
||||
t_require_mounts 2
|
||||
|
||||
echo "=== renameat2 noreplace flag test"
|
||||
|
||||
# give each mount their own dir (lock group) to minimize create contention
|
||||
mkdir $T_M0/dir0
|
||||
mkdir $T_M1/dir1
|
||||
|
||||
echo "=== run two asynchronous calls to renameat2 NOREPLACE"
|
||||
for i in $(seq 0 100); do
|
||||
# prepare inputs in isolation
|
||||
touch "$T_M0/dir0/old0"
|
||||
touch "$T_M1/dir1/old1"
|
||||
|
||||
# race doing noreplace renames, both can't succeed
|
||||
dumb_renameat2 -n "$T_M0/dir0/old0" "$T_M0/dir0/sharednew" 2> /dev/null &
|
||||
pid0=$!
|
||||
dumb_renameat2 -n "$T_M1/dir1/old1" "$T_M1/dir0/sharednew" 2> /dev/null &
|
||||
pid1=$!
|
||||
|
||||
wait $pid0
|
||||
rc0=$?
|
||||
wait $pid1
|
||||
rc1=$?
|
||||
|
||||
test "$rc0" == 0 -a "$rc1" == 0 && t_fail "both renames succeeded"
|
||||
|
||||
# blow away possible files for either race outcome
|
||||
rm -f "$T_M0/dir0/old0" "$T_M1/dir1/old1" "$T_M0/dir0/sharednew" "$T_M1/dir1/sharednew"
|
||||
done
|
||||
|
||||
t_pass
|
||||
Reference in New Issue
Block a user