7614 zfs device evacuation/removal
[unleashed.git] / usr / src / test / zfs-tests / tests / stress / races / remove_file_while_remap.ksh
blobc0e36ee84fe03a645f772ea86dee034fcc65f48f
1 #!/bin/ksh -p
3 # CDDL HEADER START
5 # This file and its contents are supplied under the terms of the
6 # Common Development and Distribution License ("CDDL"), version 1.0.
7 # You may only use this file in accordance with the terms of version
8 # 1.0 of the CDDL.
10 # A full copy of the text of the CDDL should have accompanied this
11 # source. A copy of the CDDL is also available via the Internet at
12 # http://www.illumos.org/license/CDDL.
14 # CDDL HEADER END
18 # Copyright (c) 2015 by Delphix. All rights reserved.
21 . $STF_SUITE/include/libtest.shlib
24 # DESCRIPTION:
25 # While remapping all the files in a filesystem, ZFS should be able to
26 # concurrently perform ZPL operations (remove files, truncate files, etc).
28 # STRATEGY:
29 # 1. Create a ZFS filesystem
30 # 2. Create many files.
31 # 3. Continually remap the filesystem while performing ZPL operations.
32 # 4. After the specified time duration, the system should not be panic.
35 verify_runnable "both"
37 NUMFILES=10000
38 NUMTHREADS=16
39 TIMEOUT=500
41 log_assert "ZFS can handle ZPL operations during a remap."
43 default_setup_noexit "$DISKS"
44 log_onexit default_cleanup_noexit
46 seq -f "$TESTDIR/file%g" $NUMFILES | xargs touch || \
47 log_fail "Unable to create test files."
49 function remove_random_file
51 typeset target=$TESTDIR/file$((RANDOM % NUMFILES))
52 if rm $target 2>/dev/null; then
53 touch $target || log_note "Failure to re-create $target."
57 log_must touch $TESTDIR/continue
58 for thread in $(seq $NUMTHREADS); do
59 (while [[ -f $TESTDIR/continue ]]; do
60 remove_random_file
61 done) &
62 done
65 # Remove the first disk to ensure there is something to remap.
67 log_must zpool remove $TESTPOOL ${DISKS/ */}
69 start=$(current_epoch)
70 while (($(current_epoch) < start + TIMEOUT)); do
71 zfs remap $TESTPOOL/$TESTFS || \
72 log_fail "Failure to remap $TESTPOOL/$TESTFS"
73 done
75 log_pass "ZFS handles race as expected."