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 # Setup the SERVER for testing remote locking.
29
30 NAME=$(basename $0)
31
32 Usage="Usage: $NAME -s | -c | -r | -f | -u \n
33 -s: to setup this host with mountd/nfsd\n
34 -c: to cleanup the server\n
35 "
36 if (( $# < 1 )); then
37 echo $Usage
38 exit 99
39 fi
40
41 # variables gotten from client system:
42 STF_TMPDIR=STF_TMPDIR_from_client
43 SHAREMNT_DEBUG=${SHAREMNT_DEBUG:-"SHAREMNT_DEBUG_from_client"}
44
45 . $STF_TMPDIR/srv_config.vars
46
47 # Include common STC utility functions
48 if [[ -s $STC_GENUTILS/include/nfs-util.kshlib ]]; then
49 . $STC_GENUTILS/include/nfs-util.kshlib
50 else
51 . $STF_TMPDIR/nfs-util.kshlib
52 fi
53
54 PROG=$STF_TMPDIR/srv_setup
55
56 # Turn on debug info, if requested
57 export STC_GENUTILS_DEBUG=$SHAREMNT_DEBUG
58 [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
59 || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
60
61 # cleanup function on all exit
62 function cleanup {
63 [[ :$SHAREMNT_DEBUG: == *:$NAME:* \
64 || :$SHAREMNT_DEBUG: == *:all:* ]] && set -x
65
66 rm -fr $STF_TMPDIR/*.$$
67 exit $1
68 }
69
70 getopts scr:f:u: opt
71 case $opt in
72 s)
73 # Create few test files/dirs
74 cd $SHRDIR
75 rm -rf dir0777 dir0755 dir0700
76 mkdir -m 0777 dir0777
77 mkdir -m 0755 dir0755
78 mkdir -m 0700 dir0700
79
80 if [[ -z $ZFSPOOL ]]; then
81 F_LOFI=$STF_TMPDIR/lofifile.$(($$+1))
82
83 # cleanup possible stuff which will block the coming setup
84 # a) cleanup quotadir
85 if [[ -d $QUOTADIR ]]; then
86 umount -f $QUOTADIR >/dev/null 2>&1
87 rm -rf $QUOTADIR
88 fi
89 # b) cleanup lofi
90 lofiadm | sed '1,2d' > $STF_TMPDIR/lofiadm.out.$$
91 while read ldev file; do
92 if [[ @$file == @${STF_TMPDIR}* ]]; then
93 # it maybe created by current client but not destroyed
94 lofiadm -d $ldev
95 fi
96 done < $STF_TMPDIR/lofiadm.out.$$
97
98 create_lofi_fs $F_LOFI $QUOTADIR > $STF_TMPDIR/clofi.out.$$ 2>&1
99 if (( $? != 0 )); then
100 echo "$NAME: failed to create_lofi_fs $QUOTADIR"
101 cat $STF_TMPDIR/clofi.out.$$
102 cleanup 1
103 fi
104
105 $PROG -f disable $QUOTA_FMRI | grep Done > /dev/null 2>&1
106 if (( $? != 0 )); then
107 echo "$NAME: unable to disable $QUOTA_FMRI:"
108 cleanup 2
109 fi
110
111 touch $QUOTADIR/quotas
112 quotaoff $QUOTADIR
113 edquota $TUSER01 <<-EOF
114 :s/hard = 0/hard = 10/
115 :s/hard = 0/hard = 5/
116 :wq
117 EOF
118 quotaon $QUOTADIR
119 quota -v $TUSER01 | sed '1,2d' | grep "$QUOTADIR" > /dev/null 2>&1
120 if (( $? != 0 )); then
121 echo "$NAME: setup quota for user<$TUSER01> failed"
122 cleanup 3
123 fi
124
125 $PROG -f enable $QUOTA_FMRI | grep Done > /dev/null 2>&1
126 if (( $? != 0 )); then
127 echo "$NAME: unable to enable $QUOTA_FMRI:"
128 cleanup 4
129 fi
130 else
131 create_zfs_fs $ZFSBASE $QUOTADIR 2m \
132 > $STF_TMPDIR/czfs.out.$$ 2>&1
133 if (( $? != 0 )); then
134 echo "$NAME: failed to create_zfs_fs $QUOTADIR"
135 cat $STF_TMPDIR/czfs.out.$$
136 cleanup 5
137 fi
138 fi
139
140 echo "Done - setup QUOTA."
141 ;;
142
143 c)
144 EXIT_CODE=0
145 $MISCSHARE $TESTGRP unshare $QUOTADIR \
146 > $STF_TMPDIR/unshare.$$ 2>&1
147 if (( $? != 0 )); then
148 echo "WARNING: unshare $QUOTADIR failed"
149 cat $STF_TMPDIR/unshare.$$
150 echo "\t Please clean it up manually."
151 EXIT_CODE=2
152 fi
153
154 if [[ -n $ZFSPOOL ]]; then
155 Zfs=$(zfs list | grep "$QUOTADIR" | nawk '{print $1}')
156 zfs destroy -f $Zfs > $STF_TMPDIR/cleanFS.out.$$ 2>&1
157 if (( $? != 0 )); then
158 echo "WARNING, unable to cleanup [$Zfs];"
159 cat $STF_TMPDIR/cleanFS.out.$$
160 echo "\t Please clean it up manually."
161 EXIT_CODE=2
162 fi
163 else
164 /bin/df -n /dev/lofi/* 2>/dev/null \
165 | grep "$QUOTADIR:" > /dev/null 2>&1
166 if (( $? != 0 )); then
167 umount -f $QUOTADIR > /dev/null 2>&1
168 rm -rf $QUOTADIR
169 else
170 destroy_lofi_fs $QUOTADIR \
171 > $STF_TMPDIR/cleanFS.out.$$ 2>&1
172 if (( $? != 0 )); then
173 echo "WARNING, unable to cleanup [$QUOTADIR];"
174 cat $STF_TMPDIR/cleanFS.out.$$
175 echo "\t Please clean it up manually."
176 EXIT_CODE=2
177 fi
178 fi
179 fi
180 (( EXIT_CODE == 0 )) && echo "Done - cleanup server program."
181 cleanup $EXIT_CODE
182 ;;
183
184 \?)
185 echo $Usage
186 exit 2
187 ;;
188
189 esac
190
191 cleanup 0