summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAntonio Russo <[email protected]>2018-04-30 13:45:47 -0400
committerBrian Behlendorf <[email protected]>2018-04-30 12:45:47 -0500
commitc83ccb3e72934ea1787cf7ddb0a9960eded82d0e (patch)
tree0d42b537b48de2d4ab25a6d21702e5ad57048c95 /tests
parent964c2d69a90c503f44946f31c5d4a8ac4458176d (diff)
Add test with two kinds of file creation orders
Data loss was identified in #7401 when many small files were copied. This adds a reproducer for this bug and other similar ones: randomly generate N files. Then, listing M of them by `ls -U` order, produce those same files in a directory of the same name. This triggers the bug consistently, provided N and M are large enough. Here, N=2^16 and M=2^13. Reviewed-by: Tony Hutter <[email protected]> Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Antonio Russo <[email protected]> Closes #7411
Diffstat (limited to 'tests')
-rw-r--r--tests/runfiles/linux.run2
-rw-r--r--tests/zfs-tests/tests/functional/mv_files/Makefile.am3
-rw-r--r--tests/zfs-tests/tests/functional/mv_files/mv_files.cfg4
-rwxr-xr-xtests/zfs-tests/tests/functional/mv_files/random_creation.ksh48
4 files changed, 55 insertions, 2 deletions
diff --git a/tests/runfiles/linux.run b/tests/runfiles/linux.run
index cb2c27553..bebb207fc 100644
--- a/tests/runfiles/linux.run
+++ b/tests/runfiles/linux.run
@@ -600,7 +600,7 @@ tests = ['umount_001', 'umountall_001']
tags = ['functional', 'mount']
[tests/functional/mv_files]
-tests = ['mv_files_001_pos', 'mv_files_002_pos']
+tests = ['mv_files_001_pos', 'mv_files_002_pos', 'random_creation']
tags = ['functional', 'mv_files']
[tests/functional/nestedfs]
diff --git a/tests/zfs-tests/tests/functional/mv_files/Makefile.am b/tests/zfs-tests/tests/functional/mv_files/Makefile.am
index 16a9c65eb..cec02140e 100644
--- a/tests/zfs-tests/tests/functional/mv_files/Makefile.am
+++ b/tests/zfs-tests/tests/functional/mv_files/Makefile.am
@@ -3,7 +3,8 @@ dist_pkgdata_SCRIPTS = \
setup.ksh \
cleanup.ksh \
mv_files_001_pos.ksh \
- mv_files_002_pos.ksh
+ mv_files_002_pos.ksh \
+ random_creation.ksh
dist_pkgdata_DATA = \
mv_files.cfg \
diff --git a/tests/zfs-tests/tests/functional/mv_files/mv_files.cfg b/tests/zfs-tests/tests/functional/mv_files/mv_files.cfg
index ac81bd360..ed28ff1ef 100644
--- a/tests/zfs-tests/tests/functional/mv_files/mv_files.cfg
+++ b/tests/zfs-tests/tests/functional/mv_files/mv_files.cfg
@@ -44,3 +44,7 @@ export NEWDIR_ACROSS_FS=$TESTDIR_TGT/newdir
export MVNUMFILES=2000 # <number of files to start>
export MVNUMINCR=1000 # <number of files to be increased to>
export GANGPIDS=50 # <number of limit for parallel background running process>
+
+# controls the "random_creation" test
+export RC_PASS1=65536 # <number of files to create in the first directory>
+export RC_PASS2=8192 # <process this many files into the second directory
diff --git a/tests/zfs-tests/tests/functional/mv_files/random_creation.ksh b/tests/zfs-tests/tests/functional/mv_files/random_creation.ksh
new file mode 100755
index 000000000..45c46f83c
--- /dev/null
+++ b/tests/zfs-tests/tests/functional/mv_files/random_creation.ksh
@@ -0,0 +1,48 @@
+#!/bin/ksh -p
+
+source "${STF_SUITE}/include/libtest.shlib"
+source "${STF_SUITE}/tests/functional/mv_files/mv_files.cfg"
+
+# This will test the #7401 regression.
+log_assert "Check that creating many files quickly is safe"
+
+DIR="${TESTDIR}/RANDOM_SMALL"
+
+log_must mkdir "${DIR}"
+
+count=0
+for i in $(shuf -i 1-"${RC_PASS1}") ; do
+ if ! touch "${DIR}/${i}" ; then
+ log_fail "error creating ${i} after ${count} files"
+ fi
+ count=$((count+1))
+done
+
+visible="$(find "${DIR}" -type f|wc -l)"
+
+log_must [ "${visible}" -eq "${RC_PASS1}" ]
+
+log_assert "Check that creating them in another order is safe"
+
+DIR1="${TESTDIR}/RANDOM2"
+
+log_must mv "${DIR}" "${DIR1}"
+
+log_must mkdir "${DIR}"
+
+count=0
+for i in $(cd "${DIR1}" ; ls -U . ) ; do
+ if ! touch "${DIR}/${i}" ; then
+ log_fail "error creating ${i} after ${count} files"
+ fi
+ count=$((count+1))
+ [ "${count}" -eq "${RC_PASS2}" ] && break
+done
+
+visible="$(find "${DIR}" -type f|wc -l)"
+
+if [ "${visible}" -eq "${RC_PASS2}" ] ; then
+ log_pass "Created all ${RC_PASS2} files"
+else
+ log_fail "Number of created files ${visible} is not ${RC_PASS2}"
+fi