1*5cabbc6bSPrashanth Sreenivasa#!/bin/ksh -p
2*5cabbc6bSPrashanth Sreenivasa#
3*5cabbc6bSPrashanth Sreenivasa# CDDL HEADER START
4*5cabbc6bSPrashanth Sreenivasa#
5*5cabbc6bSPrashanth Sreenivasa# This file and its contents are supplied under the terms of the
6*5cabbc6bSPrashanth Sreenivasa# Common Development and Distribution License ("CDDL"), version 1.0.
7*5cabbc6bSPrashanth Sreenivasa# You may only use this file in accordance with the terms of version
8*5cabbc6bSPrashanth Sreenivasa# 1.0 of the CDDL.
9*5cabbc6bSPrashanth Sreenivasa#
10*5cabbc6bSPrashanth Sreenivasa# A full copy of the text of the CDDL should have accompanied this
11*5cabbc6bSPrashanth Sreenivasa# source.  A copy of the CDDL is also available via the Internet at
12*5cabbc6bSPrashanth Sreenivasa# http://www.illumos.org/license/CDDL.
13*5cabbc6bSPrashanth Sreenivasa#
14*5cabbc6bSPrashanth Sreenivasa# CDDL HEADER END
15*5cabbc6bSPrashanth Sreenivasa#
16*5cabbc6bSPrashanth Sreenivasa
17*5cabbc6bSPrashanth Sreenivasa#
18*5cabbc6bSPrashanth Sreenivasa# Copyright (c) 2015 by Delphix. All rights reserved.
19*5cabbc6bSPrashanth Sreenivasa#
20*5cabbc6bSPrashanth Sreenivasa
21*5cabbc6bSPrashanth Sreenivasa. $STF_SUITE/include/libtest.shlib
22*5cabbc6bSPrashanth Sreenivasa
23*5cabbc6bSPrashanth Sreenivasa#
24*5cabbc6bSPrashanth Sreenivasa# DESCRIPTION:
25*5cabbc6bSPrashanth Sreenivasa# While remapping all the files in a filesystem, ZFS should be able to
26*5cabbc6bSPrashanth Sreenivasa# concurrently perform ZPL operations (remove files, truncate files, etc).
27*5cabbc6bSPrashanth Sreenivasa#
28*5cabbc6bSPrashanth Sreenivasa# STRATEGY:
29*5cabbc6bSPrashanth Sreenivasa# 1. Create a ZFS filesystem
30*5cabbc6bSPrashanth Sreenivasa# 2. Create many files.
31*5cabbc6bSPrashanth Sreenivasa# 3. Continually remap the filesystem while performing ZPL operations.
32*5cabbc6bSPrashanth Sreenivasa# 4. After the specified time duration, the system should not be panic.
33*5cabbc6bSPrashanth Sreenivasa#
34*5cabbc6bSPrashanth Sreenivasa
35*5cabbc6bSPrashanth Sreenivasaverify_runnable "both"
36*5cabbc6bSPrashanth Sreenivasa
37*5cabbc6bSPrashanth SreenivasaNUMFILES=10000
38*5cabbc6bSPrashanth SreenivasaNUMTHREADS=16
39*5cabbc6bSPrashanth SreenivasaTIMEOUT=500
40*5cabbc6bSPrashanth Sreenivasa
41*5cabbc6bSPrashanth Sreenivasalog_assert "ZFS can handle ZPL operations during a remap."
42*5cabbc6bSPrashanth Sreenivasa
43*5cabbc6bSPrashanth Sreenivasadefault_setup_noexit "$DISKS"
44*5cabbc6bSPrashanth Sreenivasalog_onexit default_cleanup_noexit
45*5cabbc6bSPrashanth Sreenivasa
46*5cabbc6bSPrashanth Sreenivasaseq -f "$TESTDIR/file%g" $NUMFILES | xargs touch || \
47*5cabbc6bSPrashanth Sreenivasa    log_fail "Unable to create test files."
48*5cabbc6bSPrashanth Sreenivasa
49*5cabbc6bSPrashanth Sreenivasafunction remove_random_file
50*5cabbc6bSPrashanth Sreenivasa{
51*5cabbc6bSPrashanth Sreenivasa	typeset target=$TESTDIR/file$((RANDOM % NUMFILES))
52*5cabbc6bSPrashanth Sreenivasa	if rm $target 2>/dev/null; then
53*5cabbc6bSPrashanth Sreenivasa		touch $target || log_note "Failure to re-create $target."
54*5cabbc6bSPrashanth Sreenivasa	fi
55*5cabbc6bSPrashanth Sreenivasa}
56*5cabbc6bSPrashanth Sreenivasa
57*5cabbc6bSPrashanth Sreenivasalog_must touch $TESTDIR/continue
58*5cabbc6bSPrashanth Sreenivasafor thread in $(seq $NUMTHREADS); do
59*5cabbc6bSPrashanth Sreenivasa	(while [[ -f $TESTDIR/continue ]]; do
60*5cabbc6bSPrashanth Sreenivasa		remove_random_file
61*5cabbc6bSPrashanth Sreenivasa	done) &
62*5cabbc6bSPrashanth Sreenivasadone
63*5cabbc6bSPrashanth Sreenivasa
64*5cabbc6bSPrashanth Sreenivasa#
65*5cabbc6bSPrashanth Sreenivasa# Remove the first disk to ensure there is something to remap.
66*5cabbc6bSPrashanth Sreenivasa#
67*5cabbc6bSPrashanth Sreenivasalog_must zpool remove $TESTPOOL ${DISKS/ */}
68*5cabbc6bSPrashanth Sreenivasa
69*5cabbc6bSPrashanth Sreenivasastart=$(current_epoch)
70*5cabbc6bSPrashanth Sreenivasawhile (($(current_epoch) < start + TIMEOUT)); do
71*5cabbc6bSPrashanth Sreenivasa	zfs remap $TESTPOOL/$TESTFS || \
72*5cabbc6bSPrashanth Sreenivasa	    log_fail "Failure to remap $TESTPOOL/$TESTFS"
73*5cabbc6bSPrashanth Sreenivasadone
74*5cabbc6bSPrashanth Sreenivasa
75*5cabbc6bSPrashanth Sreenivasalog_pass "ZFS handles race as expected."
76