1 #! /usr/bin/ksh -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 #
24 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
26 #
27
28 ################################################################################
29 #
30 # __stc_assertion_start
31 #
32 # ID: dir_pos003
33 #
34 # DESCRIPTION:
35 # Concurrently rename directory accross two trees. nfs should be able
36 # to handle race situation.
37 #
38 # STRATEGY:
39 # - Create two dirs 1/2/3/4/5 and a/b/c/d/e
40 # - Looply rename directory to create race situation.
41 # One process rename "a/b/c" to "1/2/3/c" and back again,
42 # another process rename "1" to "a/b/c/d/e/1" and back again.
43 # - The system should be stable to handle race situation.
44 #
45 # TESTABILITY: explicit
46 #
47 # TEST_AUTOMATION_LEVEL: automated
48 #
49 # __stc_assertion_end
50 #
51 ################################################################################
52
53 . ${STF_SUITE}/include/nfsgen.kshlib
54
55 readonly FILE=$(whence -p ${0})
56 readonly NAME=$(basename $0)
57 readonly DIR=$(dirname $0)
58
59 export _NFS_STF_DEBUG=$_NFS_STF_DEBUG:$NFSGEN_DEBUG
60 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
61 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
62
63 # Extract and print assertion information from this source script to journal
64 extract_assertion_info $FILE
65
66 function assert_cleanup {
67 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
68 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
69
70 cd - && rm -rf $testdir
71 cleanup $1
72 }
73
74 function loop_mv {
75 [[ :$NFSGEN_DEBUG: = *:${NAME}:* \
76 || :${NFSGEN_DEBUG}: = *:all:* ]] && set -x
77 src=$1
78 dst=$2
79
80 while true; do
81 mv $src $dst > /dev/null 2>&1
82 mv $dst $src > /dev/null 2>&1
83 done
84 }
85
86 testdir=${MNTDIR}/${NAME}.`hostname`.$$
87 RUN_CHECK mkdir -p $testdir/1/2/3/4/5 $testdir/a/b/c/d/e \
88 || assert_cleanup $STF_UNINITIATED
89 RUN_CHECK cd $testdir || assert_cleanup $STF_UNINITIATED
90
91 #
92 # Rename directory to generate race condition, we don't care
93 # if the rename succeeds or fails. The test just verify if
94 # the system is stable.
95 #
96 loop_mv a/b/c 1/2/3/c &
97 pid1=$!
98 loop_mv a/b/c/d/e/1 1 &
99 pid2=$!
100
101 sleep 30
102 kill -9 $pid1 $pid2
103 assert_cleanup $STF_PASS
104