1 #
2 # CDDL HEADER START
3 #
4 # The contents of this file are subject to the terms of the
5 # Common Development and Distribution License (the "License").
6 # You may not use this file except in compliance with the License.
7 #
8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 # or http://www.opensolaris.org/os/licensing.
10 # See the License for the specific language governing permissions
11 # and limitations under the License.
12 #
13 # When distributing Covered Code, include this CDDL HEADER in each
14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 # If applicable, add the following below this CDDL HEADER, with the
16 # fields enclosed by brackets "[]" replaced with your own identifying
17 # information: Portions Copyright [yyyy] [name of copyright owner]
18 #
19 # CDDL HEADER END
20 #
21
22 #
23 # Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 # Use is subject to license terms.
25 #
26
27 . ${STF_TOOLS}/include/stf.kshlib
28 . ${STF_SUITE}/include/nfs-util.kshlib
29 . ${STF_TOOLS}/contrib/include/libsmf.shlib
30 . ${STF_TOOLS}/contrib/include/nfs-tx.kshlib
31 . ${STF_TOOLS}/contrib/include/logapi.kshlib
32
33 NAME=$(basename $0)
34 CDIR=$(dirname $0)
35
36 export _NFS_STF_DEBUG=${_NFS_STF_DEBUG:-$NFSGEN_DEBUG}
37
38 # Description:
39 # A function to do cleanup, printing related messages and
40 # remove files if provided
41 # Usage:
42 # cleanup [result] [cat_file] [rm_files]
43 # Return:
44 # The function returns <result>; and if the <cat_file> is provided
45 # and not empty, cat the file; if <rm_files> is provided, then
46 # remove these files.
47 #
48
49 function cleanup {
50 FNAME=cleanup
51 [[ :$NFSGEN_DEBUG: = *:${FNAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
52 && set -x
53
54 # cleanup for acl tests
55 # Current working directory may be a subdir of $TESTDIR,
56 # need to exit before removing $TESTDIR/*.
57 cd $MNTDIR
58 if [[ -d $TESTDIR ]]; then
59 rm -rf $TESTDIR/*
60 # The tests create $TESTDIR1 only if $TESTDIR is available.
61 [[ -d $TESTDIR1 ]] && rm -rf $TESTDIR1
62 fi
63
64 [[ -n $2 ]] && cat $2
65 rm -rf $STF_TMPDIR/*.$$ $3
66
67 [[ -n $1 ]] && exit ${1}
68 }
69
70 #
71 # Description:
72 # A function to count if the file number in specified directory
73 # is equal to the expected number.
74 # Usage:
75 # count_files dir number
76 # Return:
77 # 0 : success
78 # 1 : failure
79 #
80 function count_files
81 {
82 FNAME=count_files
83 [[ :$NFSGEN_DEBUG: = *:${FNAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
84 && set -x
85
86 typeset -i file_num
87 file_num=`find $1 -type f -print | wc -l`
88 if (( $file_num != $2 )); then
89 echo "\tFailed -the file number($file_num) in the directory($1)"
90 echo "\tis not equal to expected number($2)"
91 return 1
92 fi
93 return 0
94 }
95
96 #
97 # Description
98 # A function to create a large amount of small files.
99 # Usage:
100 # create_small_files dir count
101 # Return:
102 # 0 : success
103 # 1 : failure
104 #
105 function create_small_files
106 {
107 FNAME=create_small_files
108 [[ :$NFSGEN_DEBUG: = *:${FNAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
109 && set -x
110
111 typeset num=1
112 typeset pids=""
113
114 while (($num <= $2)); do
115 cp /etc/passwd $1/file_$num > /dev/null 2>&1 &
116 pids="$pids $!"
117 ((num = num + 1))
118 done
119
120 # wait to finish creating these files.
121 for pid in $pids; do
122 ps -p $pid > /dev/null 2>&1
123 (($? == 0)) && wait $pid
124 done
125
126 # check all files are created.
127 count_files $1 $2 || return 1
128 typeset -i num=1
129 while (($num <= $2)); do
130 diff /etc/passwd $1/file_$num
131 if (($? != 0)); then
132 echo "\tFailed - the newly created file($1/file_$num)"
133 echo "\tis different from /etc/passwd"
134 return 1
135 fi
136 ((num = num + 1))
137 done
138
139 return 0
140 }
141
142 # Description:
143 # A function to do get the real NFS mount point
144 # Usage:
145 # get_realMNT curr_MNT
146 # Return:
147 # The function prints the real NFS mount point from the given curr_MNT
148 # and returns 0 if the attend is successful
149 # or returns 1 if any error occurs.
150 #
151
152 function get_realMNT {
153 FNAME=get_realMNT
154 [[ :$NFSGEN_DEBUG: = *:${FNAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
155 && set -x
156
157 typeset curr_MNT=$1
158 [[ -z $curr_MNT ]] && \
159 print -u2 "get_realMNT: curr_MNT=<$curr_MNT>" && \
160 return 1
161
162 typeset realMNT=$(/bin/df $curr_MNT | awk '{print $1}')
163 # filter out if the name of the mount point is long (from df)
164 echo $realMNT | grep '):' > /dev/null 2>&1
165 (( $? == 0 )) && \
166 realMNT=$(echo $realMNT | awk -F\( '{print $1}')
167 [[ -z $realMNT ]] && \
168 print -u2 "get_realMNT: realMNT=<$realMNT>" && return 1
169
170 nfsstat -m $realMNT | grep "vers=" > /dev/null 2>&1
171 if (( $? != 0 )); then
172 # this is NOT a valid NFS mount point
173 print -u2 "get_realMNT: realMNT=<$realMNT> is not NFS/mnt"
174 return 1
175 fi
176
177 echo $realMNT
178 return 0
179 }
180
181 #
182 # A wrapper function of c program
183 #
184 # $1 legal login name
185 # $2-n commands and options
186 #
187 function chgusr_exec #<login_name> <commands> [...]
188 {
189 FNAME=chgusr_exec
190 [[ :$NFSGEN_DEBUG: = *:${FNAME}:* || :${NFSGEN_DEBUG}: = *:all:* ]] \
191 && set -x
192
193 user=$1
194 shift
195 cmd=$@
196 if [[ $IS_KRB5 == 1 ]] && [[ $user != root ]]; then
197 chg_usr_exec -k $KPASSWORD $user $cmd
198 else
199 chg_usr_exec $user $cmd
200 fi
201
202 return $?
203 }
204
205