Whamcloud - gitweb
* vibnal fixes
[fs/lustre-release.git] / lustre / tests / sanity-fid.sh
1 #!/bin/bash
2 set -e
3
4 ONLY=${ONLY:-"$*"}
5 # bug number for skipped test: 
6 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-""}
7 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
8
9 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
10
11 SRCDIR=`dirname $0`
12 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
13
14 TMP=${TMP:-/tmp}
15 FSTYPE=${FSTYPE:-ext3}
16
17 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
18 CREATETEST=${CREATETEST:-createtest}
19 LFS=${LFS:-lfs}
20 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
21 LFIND=${LFIND:-"$LFS find"}
22 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
23 LCTL=${LCTL:-lctl}
24 MCREATE=${MCREATE:-mcreate}
25 OPENFILE=${OPENFILE:-openfile}
26 OPENUNLINK=${OPENUNLINK:-openunlink}
27 TOEXCL=${TOEXCL:-toexcl}
28 TRUNCATE=${TRUNCATE:-truncate}
29 MUNLINK=${MUNLINK:-munlink}
30 SOCKETSERVER=${SOCKETSERVER:-socketserver}
31 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
32 IOPENTEST1=${IOPENTEST1:-iopentest1}
33 IOPENTEST2=${IOPENTEST2:-iopentest2}
34 PTLDEBUG=${PTLDEBUG:-0}
35 MODE=${MODE:mds}
36
37 if [ $UID -ne 0 ]; then
38         RUNAS_ID="$UID"
39         RUNAS=""
40 else
41         RUNAS_ID=${RUNAS_ID:-500}
42         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
43 fi
44
45 export NAME=${NAME:-local}
46
47 SAVE_PWD=$PWD
48
49 clean() {
50         echo -n "cln.."
51         sh llmountcleanup.sh > /dev/null || exit 20
52         I_MOUNTED=no
53 }
54 CLEAN=${CLEAN:-clean}
55
56 start() {
57         echo -n "mnt.."
58         sh llrmount.sh > /dev/null || exit 10
59         I_MOUNTED=yes
60         echo "done"
61 }
62 START=${START:-start}
63
64 log() {
65         echo "$*"
66         lctl mark "$*" 2> /dev/null || true
67 }
68
69 trace() {
70         log "STARTING: $*"
71         strace -o $TMP/$1.strace -ttt $*
72         RC=$?
73         log "FINISHED: $*: rc $RC"
74         return 1
75 }
76 TRACE=${TRACE:-""}
77
78 check_kernel_version() {
79         VERSION_FILE=/proc/fs/lustre/kernel_version
80         WANT_VER=$1
81         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
82         GOT_VER=`cat $VERSION_FILE`
83         [ $GOT_VER -ge $WANT_VER ] && return 0
84         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
85         return 1
86 }
87
88 run_one() {
89         if ! mount | grep -q $DIR; then
90                 $START
91         fi
92         echo $PTLDEBUG >/proc/sys/portals/debug 
93         log "== test $1: $2"
94         export TESTNAME=test_$1
95         test_$1 || error "test_$1: exit with rc=$?"
96         unset TESTNAME
97         pass
98         cd $SAVE_PWD
99         $CLEAN
100 }
101
102 build_test_filter() {
103         for O in $ONLY; do
104             eval ONLY_${O}=true
105         done
106         for E in $EXCEPT $ALWAYS_EXCEPT; do
107             eval EXCEPT_${E}=true
108         done
109 }
110
111 _basetest() {
112     echo $*
113 }
114
115 basetest() {
116     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
117 }
118
119 run_test() {
120          base=`basetest $1`
121          if [ "$ONLY" ]; then
122                  testname=ONLY_$1
123                  if [ ${!testname}x != x ]; then
124                         run_one $1 "$2"
125                         return $?
126                  fi
127                  testname=ONLY_$base
128                  if [ ${!testname}x != x ]; then
129                          run_one $1 "$2"
130                          return $?
131                  fi
132                  echo -n "."
133                  return 0
134         fi
135         testname=EXCEPT_$1
136         if [ ${!testname}x != x ]; then
137                  echo "skipping excluded test $1"
138                  return 0
139         fi
140         testname=EXCEPT_$base
141         if [ ${!testname}x != x ]; then
142                  echo "skipping excluded test $1 (base $base)"
143                  return 0
144         fi
145         run_one $1 "$2"
146         return $?
147 }
148
149 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
150
151 error() { 
152         log "FAIL: $@"
153         if [ "$SANITYLOG" ]; then
154                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
155         else
156                 exit 1
157         fi
158 }
159
160 pass() { 
161         echo PASS
162 }
163
164 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
165 if [ -z "$MOUNT" ]; then
166         sh llmount.sh
167         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
168         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
169         I_MOUNTED=yes
170 fi
171
172 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
173
174 DIR=${DIR:-$MOUNT}
175 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
176
177 rm -rf $DIR/[Rdfs][1-9]*
178
179 build_test_filter
180
181 echo preparing for tests involving mounts
182 EXT2_DEV=${EXT2_DEV:-/tmp/SANITY.LOOP}
183 touch $EXT2_DEV
184 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
185
186 test_1a() {
187         rm -fr $DIR/1a0 > /dev/null
188         MDS=`find /proc/fs/lustre/mds/* -type d | head -n1 | sed 's/.*\///'`
189         [ -z "$MDS" ] && {
190             echo "no MDS available, skipping test"
191             return 0
192         }
193         count=`find /proc/fs/lustre/mds/* -type d | wc -l`
194         [ $count -gt 1 ] && {
195             echo "more than 1 MDS is found, skipping test"
196             return 0
197         }
198
199         mkdir $DIR/1a0 || error
200         old_last_fid=`cat /proc/fs/lustre/mds/$MDS/last_fid`
201         createmany -o $DIR/1a0/f 5000
202         new_last_fid=`cat /proc/fs/lustre/mds/$MDS/last_fid`
203         
204         diff=$(($new_last_fid-$old_last_fid))
205         [ $diff -ne 5000 ] && {
206             echo "invalid fid management on $MDS: \
207                 old $old_last_fid, new $new_last_fid"
208             error
209         }
210         rm -fr $DIR/1a0 || error
211 }
212 run_test 1a " fid managing correctness ============="
213
214 test_1b() {
215         rm -fr $DIR/1b0 > /dev/null
216         MDS=`find /proc/fs/lustre/mds/* -type d | head -n1 | sed 's/.*\///'`
217         [ -z "$MDS" ] && {
218             echo "no MDS available, skipping test"
219             return 0
220         }
221         count=`find /proc/fs/lustre/mds/* -type d | wc -l`
222         [ $count -gt 1 ] && {
223             echo "more than 1 MDS is found, skipping test"
224             return 0
225         }
226
227         mkdir $DIR/1b0 || error
228         createmany -o $DIR/1b0/f 5000
229         old_last_fid=`cat /proc/fs/lustre/mds/$MDS/last_fid`
230         rm -fr $DIR/1b0/f
231         new_last_fid=`cat /proc/fs/lustre/mds/$MDS/last_fid`
232         
233         [ $new_last_fid -ne $old_last_fid ] && {
234             echo "invalid fid management on $MDS: \
235                 old $old_last_fid, new $new_last_fid"
236             error
237         }
238         rm -fr $DIR/1b0 || error
239 }
240 run_test 1b " fid managing correctness ============="
241
242 TMPDIR=$OLDTMPDIR
243 TMP=$OLDTMP
244 HOME=$OLDHOME
245
246 log "cleanup: ========================================================"
247 if [ "`mount | grep ^$NAME`" ]; then
248         rm -rf $DIR/[Rdfs][1-9]*
249         if [ "$I_MOUNTED" = "yes" ]; then
250                 sh llmountcleanup.sh || error
251         fi
252 fi
253
254 echo "=========================== finished ============================"
255 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true