1#!/bin/ksh -p
2#
3# CDDL HEADER START
4#
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.
9#
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.
13#
14# CDDL HEADER END
15#
16
17#
18# Copyright (c) 2015 by Delphix. All rights reserved.
19#
20
21. $STF_SUITE/include/libtest.shlib
22
23#
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).
27#
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.
33#
34
35verify_runnable "both"
36
37NUMFILES=10000
38NUMTHREADS=16
39TIMEOUT=500
40
41log_assert "ZFS can handle ZPL operations during a remap."
42
43default_setup_noexit "$DISKS"
44log_onexit default_cleanup_noexit
45
46seq -f "$TESTDIR/file%g" $NUMFILES | xargs touch || \
47    log_fail "Unable to create test files."
48
49function remove_random_file
50{
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."
54	fi
55}
56
57log_must touch $TESTDIR/continue
58for thread in $(seq $NUMTHREADS); do
59	(while [[ -f $TESTDIR/continue ]]; do
60		remove_random_file
61	done) &
62done
63
64#
65# Remove the first disk to ensure there is something to remap.
66#
67log_must zpool remove $TESTPOOL ${DISKS/ */}
68
69start=$(current_epoch)
70while (($(current_epoch) < start + TIMEOUT)); do
71	zfs remap $TESTPOOL/$TESTFS || \
72	    log_fail "Failure to remap $TESTPOOL/$TESTFS"
73done
74
75log_pass "ZFS handles race as expected."
76