Whamcloud - gitweb
- this test shows lmv obj refcounting problem
[fs/lustre-release.git] / lustre / tests / sanity-lmv.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # e.g. ONLY="22 23" or ONLY="`seq 32 39`" or EXCEPT="31"
7 set -e
8
9 ONLY=${ONLY:-"$*"}
10 # bug number for skipped test: 2108
11 ALWAYS_EXCEPT=${ALWAYS_EXCEPT:-""}
12 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
13 #case `uname -r` in
14 #2.6.*) ALWAYS_EXCEPT="$ALWAYS_EXCEPT 54c 55" # bug 3117
15 #esac
16
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] && echo "Skipping tests: $ALWAYS_EXCEPT $EXCEPT"
18
19 SRCDIR=`dirname $0`
20 export PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
21
22 TMP=${TMP:-/tmp}
23 FSTYPE=${FSTYPE:-ext3}
24
25 CHECKSTAT=${CHECKSTAT:-"checkstat -v"}
26 CREATETEST=${CREATETEST:-createtest}
27 LFS=${LFS:-lfs}
28 LSTRIPE=${LSTRIPE:-"$LFS setstripe"}
29 LFIND=${LFIND:-"$LFS find"}
30 LVERIFY=${LVERIFY:-ll_dirstripe_verify}
31 LCTL=${LCTL:-lctl}
32 MCREATE=${MCREATE:-mcreate}
33 OPENFILE=${OPENFILE:-openfile}
34 OPENUNLINK=${OPENUNLINK:-openunlink}
35 TOEXCL=${TOEXCL:-toexcl}
36 TRUNCATE=${TRUNCATE:-truncate}
37 MUNLINK=${MUNLINK:-munlink}
38 SOCKETSERVER=${SOCKETSERVER:-socketserver}
39 SOCKETCLIENT=${SOCKETCLIENT:-socketclient}
40 IOPENTEST1=${IOPENTEST1:-iopentest1}
41 IOPENTEST2=${IOPENTEST2:-iopentest2}
42
43 if [ $UID -ne 0 ]; then
44         RUNAS_ID="$UID"
45         RUNAS=""
46 else
47         RUNAS_ID=${RUNAS_ID:-500}
48         RUNAS=${RUNAS:-"runas -u $RUNAS_ID"}
49 fi
50
51 export NAME=${NAME:-lmv}
52
53 SAVE_PWD=$PWD
54
55 clean() {
56         echo -n "cln.."
57         sh llmountcleanup.sh > /dev/null || exit 20
58         I_MOUNTED=no
59 }
60 CLEAN=${CLEAN:-clean}
61
62 start() {
63         echo -n "mnt.."
64         sh llrmount.sh > /dev/null || exit 10
65         I_MOUNTED=yes
66         echo "done"
67 }
68 START=${START:-start}
69
70 log() {
71         echo "$*"
72         lctl mark "$*" 2> /dev/null || true
73 }
74
75 trace() {
76         log "STARTING: $*"
77         strace -o $TMP/$1.strace -ttt $*
78         RC=$?
79         log "FINISHED: $*: rc $RC"
80         return 1
81 }
82 TRACE=${TRACE:-""}
83
84 check_kernel_version() {
85         VERSION_FILE=/proc/fs/lustre/kernel_version
86         WANT_VER=$1
87         [ ! -f $VERSION_FILE ] && echo "can't find kernel version" && return 1
88         GOT_VER=`cat $VERSION_FILE`
89         [ $GOT_VER -ge $WANT_VER ] && return 0
90         log "test needs at least kernel version $WANT_VER, running $GOT_VER"
91         return 1
92 }
93
94 run_one() {
95         if ! mount | grep -q $DIR; then
96                 $START
97         fi
98         echo -1 >/proc/sys/portals/debug        
99         log "== test $1: $2"
100         export TESTNAME=test_$1
101         test_$1 || error "test_$1: exit with rc=$?"
102         unset TESTNAME
103         pass
104         cd $SAVE_PWD
105         $CLEAN
106 }
107
108 build_test_filter() {
109         for O in $ONLY; do
110             eval ONLY_${O}=true
111         done
112         for E in $EXCEPT $ALWAYS_EXCEPT; do
113             eval EXCEPT_${E}=true
114         done
115 }
116
117 _basetest() {
118     echo $*
119 }
120
121 basetest() {
122     IFS=abcdefghijklmnopqrstuvwxyz _basetest $1
123 }
124
125 run_test() {
126          base=`basetest $1`
127          if [ "$ONLY" ]; then
128                  testname=ONLY_$1
129                  if [ ${!testname}x != x ]; then
130                         run_one $1 "$2"
131                         return $?
132                  fi
133                  testname=ONLY_$base
134                  if [ ${!testname}x != x ]; then
135                          run_one $1 "$2"
136                          return $?
137                  fi
138                  echo -n "."
139                  return 0
140         fi
141         testname=EXCEPT_$1
142         if [ ${!testname}x != x ]; then
143                  echo "skipping excluded test $1"
144                  return 0
145         fi
146         testname=EXCEPT_$base
147         if [ ${!testname}x != x ]; then
148                  echo "skipping excluded test $1 (base $base)"
149                  return 0
150         fi
151         run_one $1 "$2"
152         return $?
153 }
154
155 [ "$SANITYLOG" ] && rm -f $SANITYLOG || true
156
157 error() { 
158         log "FAIL: $@"
159         if [ "$SANITYLOG" ]; then
160                 echo "FAIL: $TESTNAME $@" >> $SANITYLOG
161         else
162                 exit 1
163         fi
164 }
165
166 pass() { 
167         echo PASS
168 }
169
170 MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
171 if [ -z "$MOUNT" ]; then
172         sh llmount.sh
173         MOUNT="`mount | awk '/^'$NAME' .* lustre_lite / { print $3 }'`"
174         [ -z "$MOUNT" ] && error "NAME=$NAME not mounted"
175         I_MOUNTED=yes
176 fi
177
178 [ `echo $MOUNT | wc -w` -gt 1 ] && error "NAME=$NAME mounted more than once"
179
180 DIR=${DIR:-$MOUNT}
181 [ -z "`echo $DIR | grep $MOUNT`" ] && echo "$DIR not in $MOUNT" && exit 99
182
183 LOVNAME=`cat /proc/fs/lustre/llite/fs0/lov/common_name`
184 OSTCOUNT=`cat /proc/fs/lustre/lov/$LOVNAME/numobd`
185 STRIPECOUNT=`cat /proc/fs/lustre/lov/$LOVNAME/stripecount`
186 STRIPESIZE=`cat /proc/fs/lustre/lov/$LOVNAME/stripesize`
187
188 [ -f $DIR/d52a/foo ] && chattr -a $DIR/d52a/foo
189 [ -f $DIR/d52b/foo ] && chattr -i $DIR/d52b/foo
190 rm -rf $DIR/[Rdfs][1-9]*
191
192 build_test_filter
193
194 echo preparing for tests involving mounts
195 EXT2_DEV=${EXT2_DEV:-/tmp/SANITY.LOOP}
196 touch $EXT2_DEV
197 mke2fs -j -F $EXT2_DEV 8000 > /dev/null
198
199 test_1a() {
200         mkdir $DIR/1a0 || error 
201         createmany -o $DIR/1a0/f 4000
202         rmdir $DIR/1a0 && error
203         rm -rf $DIR/1a0 || error
204 }
205 run_test 1a " remove splitted dir ============================="
206
207 test_1b() {
208         mkdir $DIR/1b0 || error
209         createmany -o $DIR/1b0/f 4000
210         find $DIR/1b0 -type f | xargs rm -f
211         NUM=`ls $DIR/1b0 | wc -l`
212         if [ $NUM -ne 0 ] ; then
213                 echo "dir must be empty"
214                 error
215         fi
216         touch $DIR/1b0/file0
217         touch $DIR/1b0/file1
218         touch $DIR/1b0/file2
219
220         echo "3 files left"
221         rmdir $DIR/1b0 && error
222         rm -f $DIR/1b0/file0
223
224         echo "2 files left"
225         rmdir $DIR/1b0 && error
226         rm -f $DIR/1b0/file1
227
228         echo "1 files left"
229         rmdir $DIR/1b0 && error
230         rm -f $DIR/1b0/file2
231
232         echo "0 files left"
233         rmdir $DIR/1b0 || error
234 }
235 run_test 1b " remove splitted dir ============================="
236
237 test_1c() {
238         mkdir $DIR/1b1 || error
239         createmany -o $DIR/1b1/f 4000
240         find $DIR/1b1 -type f | xargs rm -f
241         NUM=`ls $DIR/1b1 | wc -l`
242         if [ $NUM -ne 0 ] ; then
243                 echo "dir must be empty"
244                 error
245         fi
246         touch $DIR/1b1/file0
247         touch $DIR/1b1/file1
248         touch $DIR/1b1/file2
249
250         echo "3 files left"
251         rmdir $DIR/1b1 && error
252         rm -f $DIR/1b1/file0
253
254         echo "2 files left"
255         rmdir $DIR/1b1 && error
256         rm -f $DIR/1b1/file1
257
258         echo "1 files left"
259         rmdir $DIR/1b1 && error
260         rm -f $DIR/1b1/file2
261
262         echo "0 files left"
263         rmdir $DIR/1b1 || error
264 }
265 run_test 1c " remove splitted cross-node dir ============================="
266
267 test_2a() {
268         mkdir $DIR/2a0 || error 
269         createmany -o $DIR/2a0/f 5000
270         NUM=`ls $DIR/2a0 | wc -l`
271         echo "found $NUM files"
272         if [ $NUM -ne 5000 ]; then
273                 echo "wrong number of files: $NUM"
274                 error
275         fi
276         rm -rf $DIR/2a0 || error
277 }
278 run_test 2a " list splitted dir ============================="
279
280 test_2b() {
281         mkdir $DIR/2b1 || error 
282         createmany -o $DIR/2b1/f 5000
283         $CLEAN
284         $START
285         statmany -l $DIR/2b1/f 5000 5000 || error
286         statmany -s $DIR/2b1/f 5000 5000 || error
287         rm -rf $DIR/2b1 || error
288 }
289 run_test 2b " list splitted dir after remount ============================="
290
291 TMPDIR=$OLDTMPDIR
292 TMP=$OLDTMP
293 HOME=$OLDHOME
294
295 log "cleanup: ======================================================"
296 if [ "`mount | grep ^$NAME`" ]; then
297         rm -rf $DIR/[Rdfs][1-9]*
298         if [ "$I_MOUNTED" = "yes" ]; then
299                 sh llmountcleanup.sh || error
300         fi
301 fi
302
303 echo '=========================== finished ==============================='
304 [ -f "$SANITYLOG" ] && cat $SANITYLOG && exit 1 || true