1#! /usr/local/bin/ksh93 -p
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License (the "License").
7# You may not use this file except in compliance with the License.
8#
9# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10# or http://www.opensolaris.org/os/licensing.
11# See the License for the specific language governing permissions
12# and limitations under the License.
13#
14# When distributing Covered Code, include this CDDL HEADER in each
15# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16# If applicable, add the following below this CDDL HEADER, with the
17# fields enclosed by brackets "[]" replaced with your own identifying
18# information: Portions Copyright [yyyy] [name of copyright owner]
19#
20# CDDL HEADER END
21#
22
23# $FreeBSD$
24
25#
26# Copyright 2013 Spectra Logic.  All rights reserved.
27# Use is subject to license terms.
28#
29#
30. $STF_SUITE/include/libtest.kshlib
31
32################################################################################
33#
34# __stc_assertion_start
35#
36# ID: snapshot_019_pos
37#
38# DESCRIPTION:
39#	Accessing snapshots and unmounting them in parallel does not panic.
40#	FreeBSD PR kern/184677
41#
42# STRATEGY:
43#	1. Create a dataset
44#	2. Set the snapdir property to visible
45#	3. Do the following in parallel
46#	   a. Repeatedly access the snapshot
47#	   b. Repeatedly unmount the snapshot
48#	4. Verify that the system does not panic
49#
50# TESTABILITY: explicit
51#
52# TEST_AUTOMATION_LEVEL: automated
53#
54# CODING_STATUS: COMPLETED (2013-12-23)
55#
56# __stc_assertion_end
57#
58################################################################################
59
60verify_runnable "both"
61
62KILL_SWITCH=${PWD}/kill_switch
63
64function stat_snapshot
65{
66	while [ ! -f ${KILL_SWITCH} ]; do
67		cd $SNAPDIR # Exercise forced unmount
68		stat "$SNAPDIR" > /dev/null 2>&1
69	done
70}
71
72function ls_snapshot
73{
74	# Pre-generate the argument list.
75	ls_args=""
76	for ((num=0; $num<100; num=$num+1)); do
77		ls_args="$ls_args $SNAPDIR/.."
78	done
79
80	while [ ! -f ${KILL_SWITCH} ]; do
81		ls $ls_args >/dev/null 2>&1
82	done
83}
84
85log_assert "Accessing snapshots and unmounting them in parallel does not panic"
86
87log_must dataset_setprop $TESTPOOL "snapdir" "visible"
88
89# Take snapshots
90log_must $ZFS snapshot "$TESTPOOL/$TESTFS@$TESTSNAP"
91
92# Repeatedly access the snapshot directory
93stat_snapshot &
94stat_pid="$!"
95ls_snapshot &
96ls_pid="$!"
97
98# Repeatedly unmount the snapshot directory
99for ((i=0; $i<100; i=$i+1)); do
100	umount "$SNAPDIR" >/dev/null 2>&1
101	log_note "$i non-forced done"
102	# Sleep just long enough for the other "threads" to remount.
103	sleep 0.1
104	umount -f "$SNAPDIR" >/dev/null 2>&1
105	log_note "$i forced done"
106	sleep 0.1
107done
108
109# Kill the other "threads" and wait for them to die.
110touch $KILL_SWITCH
111log_note "Waiting for all child processes to die..."
112wait
113
114# Test that no reference leaks occurred and we can cleanup without forcing.
115log_must $ZFS unmount $TESTPOOL/$TESTFS
116log_must $ZFS destroy -r $TESTPOOL/$TESTFS
117
118# If we get here, we managed to not panic, deadlock, or leak references.
119log_pass
120