Whamcloud - gitweb
e300c28f1c1aa5a1d3b01a1c229bb84f513a76a8
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:autoindent:shiftwidth=4:tabstop=4:
4
5 # FIXME - there is no reason to use all of these different
6 #   return codes, espcially when most of them are mapped to something
7 #   else anyway.  The combination of test number and return code
8 #   figure out what failed.
9
10 set -e
11
12 ONLY=${ONLY:-"$*"}
13
14 # bug number for skipped test:
15 ALWAYS_EXCEPT=" $CONF_SANITY_EXCEPT"
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
17
18 SRCDIR=`dirname $0`
19 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
20
21 PTLDEBUG=${PTLDEBUG:--1}
22 SAVE_PWD=$PWD
23 LUSTRE=${LUSTRE:-`dirname $0`/..}
24 RLUSTRE=${RLUSTRE:-$LUSTRE}
25
26 . $LUSTRE/tests/test-framework.sh
27 init_test_env $@
28 # STORED_MDSSIZE is used in test_18
29 if [ -n "$MDSSIZE" ]; then
30     STORED_MDSSIZE=$MDSSIZE
31 fi
32 # use small MDS + OST size to speed formatting time
33 MDSSIZE=40000
34 OSTSIZE=40000
35 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
36
37 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
38 remote_ost_nodsh && skip "remote OST with nodsh" && exit 0
39
40 #
41 [ "$SLOW" = "no" ] && EXCEPT_SLOW="0 1 2 3 6 7 15 18 24b 25 30 31 32 33 34a 45"
42
43 assert_DIR
44
45 reformat() {
46         formatall
47 }
48
49 writeconf() {
50         local facet=$SINGLEMDS
51         local dev=${facet}_dev
52         shift
53         stop ${facet} -f
54         rm -f ${facet}active
55         # who knows if/where $TUNEFS is installed?  Better reformat if it fails...
56         do_facet ${facet} "$TUNEFS --writeconf ${!dev}" || echo "tunefs failed, reformatting instead" && reformat
57
58         gen_config
59 }
60
61 gen_config() {
62         # The MGS must be started before the OSTs for a new fs, so start
63         # and stop to generate the startup logs.
64         start_mds
65         start_ost
66         wait_osc_import_state mds ost FULL
67         stop_ost
68         stop_mds
69 }
70
71 reformat_and_config() {
72         reformat
73         gen_config
74 }
75
76 start_mds() {
77         local facet=$SINGLEMDS
78         # we can not use MDSDEV1 here because SINGLEMDS could be set not to mds1 only
79         local num=$(echo $facet | tr -d "mds")
80         local dev=$(mdsdevname $num)
81         echo "start mds service on `facet_active_host $facet`"
82         start $facet ${dev} $MDS_MOUNT_OPTS || return 94
83 }
84
85 stop_mds() {
86         echo "stop mds service on `facet_active_host $SINGLEMDS`"
87         # These tests all use non-failover stop
88         stop $SINGLEMDS -f  || return 97
89 }
90
91 start_ost() {
92         echo "start ost1 service on `facet_active_host ost1`"
93         start ost1 `ostdevname 1` $OST_MOUNT_OPTS || return 95
94 }
95
96 stop_ost() {
97         echo "stop ost1 service on `facet_active_host ost1`"
98         # These tests all use non-failover stop
99         stop ost1 -f  || return 98
100 }
101
102 start_ost2() {
103         echo "start ost2 service on `facet_active_host ost2`"
104         start ost2 `ostdevname 2` $OST_MOUNT_OPTS || return 92
105 }
106
107 stop_ost2() {
108         echo "stop ost2 service on `facet_active_host ost2`"
109         # These tests all use non-failover stop
110         stop ost2 -f  || return 93
111 }
112
113 mount_client() {
114         local MOUNTPATH=$1
115         echo "mount $FSNAME on ${MOUNTPATH}....."
116         zconf_mount `hostname` $MOUNTPATH  || return 96
117 }
118
119 remount_client() {
120         local SAVEMOUNTOPT=$MOUNTOPT
121         MOUNTOPT="remount,$1"
122         local MOUNTPATH=$2
123         echo "remount '$1' lustre on ${MOUNTPATH}....."
124         zconf_mount `hostname`  $MOUNTPATH  || return 96
125         MOUNTOPT=$SAVEMOUNTOPT
126 }
127
128 umount_client() {
129         local MOUNTPATH=$1
130         echo "umount lustre on ${MOUNTPATH}....."
131         zconf_umount `hostname` $MOUNTPATH || return 97
132 }
133
134 manual_umount_client(){
135         local rc
136         local FORCE=$1
137         echo "manual umount lustre on ${MOUNT}...."
138         do_facet client "umount -d ${FORCE} $MOUNT"
139         rc=$?
140         return $rc
141 }
142
143 setup() {
144         start_ost
145         start_mds
146         mount_client $MOUNT
147 }
148
149 setup_noconfig() {
150         start_mds
151         start_ost
152         mount_client $MOUNT
153 }
154
155 cleanup_nocli() {
156         stop_mds || return 201
157         stop_ost || return 202
158         unload_modules || return 203
159 }
160
161 cleanup() {
162         umount_client $MOUNT || return 200
163         cleanup_nocli || return $?
164 }
165
166 check_mount() {
167         do_facet client "cp /etc/passwd $DIR/a" || return 71
168         do_facet client "rm $DIR/a" || return 72
169         # make sure lustre is actually mounted (touch will block,
170         # but grep won't, so do it after)
171         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
172         echo "setup single mount lustre success"
173 }
174
175 check_mount2() {
176         do_facet client "touch $DIR/a" || return 71
177         do_facet client "rm $DIR/a" || return 72
178         do_facet client "touch $DIR2/a" || return 73
179         do_facet client "rm $DIR2/a" || return 74
180         echo "setup double mount lustre success"
181 }
182
183 build_test_filter
184
185 if [ "$ONLY" == "setup" ]; then
186         setup
187         exit
188 fi
189
190 if [ "$ONLY" == "cleanup" ]; then
191         cleanup
192         exit
193 fi
194
195 init_gss
196
197 #create single point mountpoint
198
199 reformat_and_config
200
201 test_0() {
202         setup
203         check_mount || return 41
204         cleanup || return $?
205 }
206 run_test 0 "single mount setup"
207
208 test_1() {
209         start_ost
210         echo "start ost second time..."
211         setup
212         check_mount || return 42
213         cleanup || return $?
214 }
215 run_test 1 "start up ost twice (should return errors)"
216
217 test_2() {
218         start_ost
219         start_mds
220         echo "start mds second time.."
221         start_mds
222         mount_client $MOUNT
223         check_mount || return 43
224         cleanup || return $?
225 }
226 run_test 2 "start up mds twice (should return err)"
227
228 test_3() {
229         setup
230         #mount.lustre returns an error if already in mtab
231         mount_client $MOUNT && return $?
232         check_mount || return 44
233         cleanup || return $?
234 }
235 run_test 3 "mount client twice (should return err)"
236
237 test_4() {
238         setup
239         touch $DIR/$tfile || return 85
240         stop_ost -f
241         cleanup
242         eno=$?
243         # ok for ost to fail shutdown
244         if [ 202 -ne $eno ]; then
245                 return $eno;
246         fi
247         return 0
248 }
249 run_test 4 "force cleanup ost, then cleanup"
250
251 test_5a() {     # was test_5
252         setup
253         touch $DIR/$tfile || return 1
254         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
255
256         stop_mds -f || return 2
257
258         # cleanup may return an error from the failed
259         # disconnects; for now I'll consider this successful
260         # if all the modules have unloaded.
261         umount -d $MOUNT &
262         UMOUNT_PID=$!
263         sleep 6
264         echo "killing umount"
265         kill -TERM $UMOUNT_PID
266         echo "waiting for umount to finish"
267         wait $UMOUNT_PID
268         if grep " $MOUNT " /proc/mounts; then
269                 echo "test 5: /proc/mounts after failed umount"
270                 umount $MOUNT &
271                 UMOUNT_PID=$!
272                 sleep 2
273                 echo "killing umount"
274                 kill -TERM $UMOUNT_PID
275                 echo "waiting for umount to finish"
276                 wait $UMOUNT_PID
277                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
278         fi
279
280         manual_umount_client
281         # stop_mds is a no-op here, and should not fail
282         cleanup_nocli || return $?
283         # df may have lingering entry
284         manual_umount_client
285         # mtab may have lingering entry
286         local WAIT=0
287         local MAX_WAIT=20
288         local sleep=1
289         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
290                 sleep $sleep
291                 grep -q $MOUNT" " /etc/mtab || break
292                 echo "Waiting /etc/mtab updated ... "
293                 WAIT=$(( WAIT + sleep))
294         done
295         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
296         echo "/etc/mtab updated in $WAIT secs"
297 }
298 run_test 5a "force cleanup mds, then cleanup"
299
300 test_5b() {
301         start_ost
302         [ -d $MOUNT ] || mkdir -p $MOUNT
303         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab before mount" && return 10
304         mount_client $MOUNT && return 1
305         grep " $MOUNT " /etc/mtab && echo "test 5b: mtab after failed mount" && return 11
306         umount_client $MOUNT
307         # stop_mds is a no-op here, and should not fail
308         cleanup_nocli || return $?
309         return 0
310 }
311 run_test 5b "mds down, cleanup after failed mount (bug 2712) (should return errs)"
312
313 test_5c() {
314         start_ost
315         start_mds
316         [ -d $MOUNT ] || mkdir -p $MOUNT
317         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab before mount" && return 10
318         local oldfs="${FSNAME}"
319         FSNAME="wrong.${FSNAME}"
320         mount_client $MOUNT || :
321         FSNAME=${oldfs}
322         grep " $MOUNT " /etc/mtab && echo "test 5c: mtab after failed mount" && return 11
323         umount_client $MOUNT
324         cleanup_nocli  || return $?
325 }
326 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
327
328 test_5d() {
329         start_ost
330         start_mds
331         stop_ost -f
332         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab before mount" && return 10
333         mount_client $MOUNT || return 1
334         cleanup  || return $?
335         grep " $MOUNT " /etc/mtab && echo "test 5d: mtab after unmount" && return 11
336         return 0
337 }
338 run_test 5d "mount with ost down"
339
340 test_5e() {
341         start_ost
342         start_mds
343
344 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
345         do_facet client "lctl set_param fail_loc=0x80000506"
346         grep " $MOUNT " /etc/mtab && echo "test 5e: mtab before mount" && return 10
347         mount_client $MOUNT || echo "mount failed (not fatal)"
348         cleanup  || return $?
349         grep " $MOUNT " /etc/mtab && echo "test 5e: mtab after unmount" && return 11
350         return 0
351 }
352 run_test 5e "delayed connect, don't crash (bug 10268)"
353
354 test_6() {
355         setup
356         manual_umount_client
357         mount_client ${MOUNT} || return 87
358         touch $DIR/a || return 86
359         cleanup  || return $?
360 }
361 run_test 6 "manual umount, then mount again"
362
363 test_7() {
364         setup
365         manual_umount_client
366         cleanup_nocli || return $?
367 }
368 run_test 7 "manual umount, then cleanup"
369
370 test_8() {
371         setup
372         mount_client $MOUNT2
373         check_mount2 || return 45
374         umount_client $MOUNT2
375         cleanup  || return $?
376 }
377 run_test 8 "double mount setup"
378
379 test_9() {
380         start_ost
381
382         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
383         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
384
385         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
386         if [ "$CHECK_PTLDEBUG" ] && { \
387            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
388            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
389            echo "lnet.debug success"
390         else
391            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
392            return 1
393         fi
394         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
395         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
396            echo "lnet.subsystem_debug success"
397         else
398            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
399            return 1
400         fi
401         stop_ost || return $?
402 }
403
404 run_test 9 "test ptldebug and subsystem for mkfs"
405
406 # LOGS/PENDING do not exist anymore since CMD3
407 test_16() {
408         local TMPMTPT="${TMP}/conf16"
409         local dev=${SINGLEMDS}_dev
410         local MDSDEV=${!dev}
411         if [ ! -e "$MDSDEV" ]; then
412             log "no $MDSDEV existing, so mount Lustre to create one"
413             setup
414             check_mount || return 41
415             cleanup || return $?
416         fi
417
418         [ -f "$MDSDEV" ] && LOOPOPT="-o loop"
419
420         log "change the mode of $MDSDEV/OBJECTS to 555"
421         do_facet $SINGLEMDS "mkdir -p $TMPMTPT &&
422                       mount $LOOPOPT -t $FSTYPE $MDSDEV $TMPMTPT &&
423                       chmod 555 $TMPMTPT/OBJECTS &&
424                       umount $TMPMTPT" || return $?
425
426         log "mount Lustre to change the mode of OBJECTS, then umount Lustre"
427         setup
428         check_mount || return 41
429         cleanup || return $?
430
431         log "read the mode of OBJECTS and check if they has been changed properly"
432         EXPECTEDOBJECTSMODE=`do_facet $SINGLEMDS "$DEBUGFS -R 'stat OBJECTS' $MDSDEV 2> /dev/null" | grep 'Mode: ' | sed -e "s/.*Mode: *//" -e "s/ *Flags:.*//"`
433
434         if [ "$EXPECTEDOBJECTSMODE" = "0777" ]; then
435                 log "Success:Lustre change the mode of OBJECTS correctly"
436         else
437                 error "Lustre does not change mode of OBJECTS properly"
438         fi
439 }
440 run_test 16 "verify that lustre will correct the mode of OBJECTS"
441
442 test_17() {
443         local dev=${SINGLEMDS}_dev
444         local MDSDEV=${!dev}
445
446         if [ ! -e "$MDSDEV" ]; then
447             echo "no $MDSDEV existing, so mount Lustre to create one"
448             setup
449             check_mount || return 41
450             cleanup || return $?
451         fi
452
453         echo "Remove mds config log"
454         do_facet $SINGLEMDS "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' $MDSDEV || return \$?" || return $?
455
456         start_ost
457         start_mds && return 42
458         reformat_and_config
459 }
460 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
461
462 test_18() {
463         [ "$FSTYPE" != "ldiskfs" ] && skip "not needed for FSTYPE=$FSTYPE" && return
464
465         local dev=${SINGLEMDS}_dev
466         local MDSDEV=${!dev}
467
468         local MIN=2000000
469
470         local OK=
471         # check if current MDSSIZE is large enough
472         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
473                 log "use MDSSIZE=$MDSSIZE"
474
475         # check if the global config has a large enough MDSSIZE
476         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
477                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
478                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
479
480         # check if the block device is large enough
481         [ -z "$OK" -a -b $MDSDEV ] && \
482                 [ "$(dd if=$MDSDEV of=/dev/null bs=1k count=1 skip=$MIN 2>&1 |
483                      awk '($3 == "in") { print $1 }')" = "1+0" ] && OK=1 && \
484                 myMDSSIZE=$MIN && log "use device $MDSDEV with MIN=$MIN"
485
486         # check if a loopback device has enough space for fs metadata (5%)
487         [ -z "$OK" ] && [ -f $MDSDEV -o ! -e $MDSDEV ] &&
488                 SPACE=$(df -P $(dirname $MDSDEV) |
489                         awk '($1 != "Filesystem") {print $4}') &&
490                 [ $SPACE -gt $((MIN / 20)) ] && OK=1 && myMDSSIZE=$MIN && \
491                         log "use file $MDSDEV with MIN=$MIN"
492
493         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
494
495
496         echo "mount mds with large journal..."
497         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
498
499         MDS_MKFS_OPTS="--mgs --mdt --fsname=$FSNAME --device-size=$myMDSSIZE --param sys.timeout=$TIMEOUT $MDSOPT"
500
501         reformat_and_config
502         echo "mount lustre system..."
503         setup
504         check_mount || return 41
505
506         echo "check journal size..."
507         local FOUNDSIZE=`do_facet mds "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}'`
508         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
509                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
510         else
511                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
512         fi
513
514         cleanup || return $?
515
516         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
517         reformat_and_config
518 }
519 run_test 18 "check mkfs creates large journals"
520
521 test_19a() {
522         start_mds || return 1
523         stop_mds -f || return 2
524 }
525 run_test 19a "start/stop MDS without OSTs"
526
527 test_19b() {
528         start_ost || return 1
529         stop_ost -f || return 2
530 }
531 run_test 19b "start/stop OSTs without MDS"
532
533 test_20() {
534         # first format the ost/mdt
535         start_ost
536         start_mds
537         mount_client $MOUNT
538         check_mount || return 43
539         rm -f $DIR/$tfile
540         remount_client ro $MOUNT || return 44
541         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
542         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
543         remount_client rw $MOUNT || return 47
544         touch $DIR/$tfile
545         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
546         MCNT=`grep -c $MOUNT /etc/mtab`
547         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
548         umount_client $MOUNT
549         stop_mds
550         stop_ost
551 }
552 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
553
554 test_21a() {
555         start_mds
556         start_ost
557         wait_osc_import_state mds ost FULL
558         stop_ost
559         stop_mds
560 }
561 run_test 21a "start mds before ost, stop ost first"
562
563 test_21b() {
564         start_ost
565         start_mds
566         wait_osc_import_state mds ost FULL
567         stop_mds
568         stop_ost
569 }
570 run_test 21b "start ost before mds, stop mds first"
571
572 test_21c() {
573         start_ost
574         start_mds
575         start_ost2
576         wait_osc_import_state mds ost2 FULL
577         stop_ost
578         stop_ost2
579         stop_mds
580         #writeconf to remove all ost2 traces for subsequent tests
581         writeconf
582 }
583 run_test 21c "start mds between two osts, stop mds last"
584
585 test_22() {
586         start_mds
587
588         echo Client mount with ost in logs, but none running
589         start_ost
590         # wait until mds connected to ost and open client connection
591         wait_osc_import_state mds ost FULL
592         stop_ost
593         mount_client $MOUNT
594         # check_mount will block trying to contact ost
595         mcreate $DIR/$tfile || return 40
596         rm -f $DIR/$tfile || return 42
597         umount_client $MOUNT
598         pass
599
600         echo Client mount with a running ost
601         start_ost
602         if $GSS; then
603                 # if gss enabled, wait full time to let connection from
604                 # mds to ost be established, due to the mismatch between
605                 # initial connect timeout and gss context negotiation timeout.
606                 # This perhaps could be remove after AT landed.
607                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
608                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
609         fi
610         mount_client $MOUNT
611         check_mount || return 41
612         pass
613
614         cleanup
615 }
616 run_test 22 "start a client before osts (should return errs)"
617
618 test_23a() {    # was test_23
619         setup
620         # fail mds
621         stop $SINGLEMDS
622         # force down client so that recovering mds waits for reconnect
623         local running=$(grep -c $MOUNT /proc/mounts) || true
624         if [ $running -ne 0 ]; then
625                 echo "Stopping client $MOUNT (opts: -f)"
626                 umount -f $MOUNT
627         fi
628
629         # enter recovery on mds
630         start_mds
631         # try to start a new client
632         mount_client $MOUNT &
633         sleep 5
634         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
635         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
636         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
637         ps --ppid $MOUNT_PID
638         ps --ppid $MOUNT_LUSTRE_PID
639         # FIXME why o why can't I kill these? Manual "ctrl-c" works...
640         kill -TERM $MOUNT_LUSTRE_PID
641         echo "waiting for mount to finish"
642         ps -ef | grep mount
643         # we can not wait $MOUNT_PID because it is not a child of this shell
644         local PID1
645         local PID2
646         local WAIT=0
647         local MAX_WAIT=20
648         local sleep=1
649         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
650                 sleep $sleep
651                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
652                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
653                 echo PID1=$PID1
654                 echo PID2=$PID2
655                 [ -z "$PID1" -a -z "$PID2" ] && break
656                 echo "waiting for mount to finish ... "
657                 WAIT=$(( WAIT + sleep))
658         done
659         [ "$WAIT" -eq "$MAX_WAIT" ] && error "MOUNT_PID $MOUNT_PID and "\
660                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
661         ps -ef | grep mount
662         stop_mds || error
663         stop_ost || error
664 }
665 run_test 23a "interrupt client during recovery mount delay"
666
667 umount_client $MOUNT
668 cleanup_nocli
669
670 test_23b() {    # was test_23
671         start_ost
672         start_mds
673         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
674         lctl set_param fail_loc=0x80000313
675         mount_client $MOUNT
676         cleanup
677 }
678 run_test 23b "Simulate -EINTR during mount"
679
680 fs2mds_HOST=$mds_HOST
681 fs2ost_HOST=$ost_HOST
682
683 cleanup_24a() {
684         trap 0
685         echo "umount $MOUNT2 ..."
686         umount $MOUNT2 || true
687         echo "stopping fs2mds ..."
688         stop fs2mds -f || true
689         echo "stopping fs2ost ..."
690         stop fs2ost -f || true
691 }
692
693 test_24a() {
694         #set up fs1
695         gen_config
696         #set up fs2
697         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
698         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
699                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
700                 skip_env "mixed loopback and real device not working" && return
701         fi
702
703         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
704         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
705
706         # test 8-char fsname as well
707         local FSNAME2=test1234
708         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --nomgs --mgsnode=$MGSNID --reformat $fs2mdsdev || exit 10
709
710         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2ostdev || exit 10
711
712         setup
713         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
714         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
715         mkdir -p $MOUNT2
716         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
717         # 1 still works
718         check_mount || return 2
719         # files written on 1 should not show up on 2
720         cp /etc/passwd $DIR/$tfile
721         sleep 10
722         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
723         # 2 should work
724         sleep 5
725         cp /etc/passwd $MOUNT2/b || return 3
726         rm $MOUNT2/b || return 4
727         # 2 is actually mounted
728         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
729         # failover
730         facet_failover fs2mds
731         facet_failover fs2ost
732         df
733         umount_client $MOUNT
734         # the MDS must remain up until last MDT
735         stop_mds
736         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
737         [ -z "$MDS" ] && error "No MDT" && return 8
738         cleanup_24a
739         cleanup_nocli || return 6
740 }
741 run_test 24a "Multiple MDTs on a single node"
742
743 test_24b() {
744         if [ -z "$fs2mds_DEV" ]; then
745                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
746                 skip_env "mixed loopback and real device not working" && return
747         fi
748
749         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
750
751         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME}2 --mgs --reformat $fs2mdsdev || exit 10
752         setup
753         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
754         cleanup || return 6
755 }
756 run_test 24b "Multiple MGSs on a single node (should return err)"
757
758 test_25() {
759         setup
760         check_mount || return 2
761         local MODULES=$($LCTL modules | awk '{ print $2 }')
762         rmmod $MODULES 2>/dev/null || true
763         cleanup || return 6
764 }
765 run_test 25 "Verify modules are referenced"
766
767 test_26() {
768     load_modules
769     # we need modules before mount for sysctl, so make sure...
770     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
771 #define OBD_FAIL_MDS_FS_SETUP            0x135
772     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
773     start_mds && echo MDS started && return 1
774     lctl get_param -n devices
775     DEVS=$(lctl get_param -n devices | wc -l)
776     [ $DEVS -gt 0 ] && return 2
777     unload_modules || return 203
778 }
779 run_test 26 "MDT startup failure cleans LOV (should return errs)"
780
781 set_and_check() {
782         local myfacet=$1
783         local TEST=$2
784         local PARAM=$3
785         local ORIG=$(do_facet $myfacet "$TEST")
786         if [ $# -gt 3 ]; then
787             local FINAL=$4
788         else
789             local -i FINAL
790             FINAL=$(($ORIG + 5))
791         fi
792         echo "Setting $PARAM from $ORIG to $FINAL"
793         do_facet $SINGLEMDS "$LCTL conf_param $PARAM='$FINAL'" || error conf_param failed
794
795         wait_update $(facet_host $myfacet) "$TEST" "$FINAL" || error check failed!
796 }
797
798 test_27a() {
799         start_ost || return 1
800         start_mds || return 2
801         echo "Requeue thread should have started: "
802         ps -e | grep ll_cfg_requeue
803         set_and_check ost1 "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
804         cleanup_nocli
805 }
806 run_test 27a "Reacquire MGS lock if OST started first"
807
808 test_27b() {
809         # FIXME. ~grev
810         setup
811         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }')
812
813         facet_failover $SINGLEMDS
814         set_and_check $SINGLEMDS "lctl get_param -n mdt.$device.identity_acquire_expire" "$device.mdt.identity_acquire_expire" || return 3
815         set_and_check client "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight" "$device.mdc.max_rpcs_in_flight" || return 4
816         check_mount
817         cleanup
818 }
819 run_test 27b "Reacquire MGS lock after failover"
820
821 test_28() {
822         setup
823         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
824         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
825         ORIG=$($TEST)
826         FINAL=$(($ORIG + 1))
827         set_and_check client "$TEST" "$PARAM" $FINAL || return 3
828         FINAL=$(($FINAL + 1))
829         set_and_check client "$TEST" "$PARAM" $FINAL || return 4
830         umount_client $MOUNT || return 200
831         mount_client $MOUNT
832         RESULT=$($TEST)
833         if [ $RESULT -ne $FINAL ]; then
834             echo "New config not seen: wanted $FINAL got $RESULT"
835             return 4
836         else
837             echo "New config success: got $RESULT"
838         fi
839         set_and_check client "$TEST" "$PARAM" $ORIG || return 5
840         cleanup
841 }
842 run_test 28 "permanent parameter setting"
843
844 test_29() {
845         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
846         setup > /dev/null 2>&1
847         start_ost2
848         sleep 10
849
850         local PARAM="$FSNAME-OST0001.osc.active"
851         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
852         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
853
854         ACTV=$(lctl get_param -n $PROC_ACT)
855         DEAC=$((1 - $ACTV))
856         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
857         # also check ost_server_uuid status
858         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
859         if [ -z "$RESULT" ]; then
860             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
861             return 3
862         else
863             echo "Live client success: got $RESULT"
864         fi
865
866         # check MDT too
867         local MPROC="osc.$FSNAME-OST0001-osc-[M]*.active"
868         local MAX=30
869         local WAIT=0
870         while [ 1 ]; do
871             sleep 5
872             RESULT=`do_facet $SINGLEMDS " lctl get_param -n $MPROC"`
873             [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
874             if [ $RESULT -eq $DEAC ]; then
875                 echo "MDT deactivated also after $WAIT sec (got $RESULT)"
876                 break
877             fi
878             WAIT=$((WAIT + 5))
879             if [ $WAIT -eq $MAX ]; then
880                 echo "MDT not deactivated: wanted $DEAC got $RESULT"
881                 return 4
882             fi
883             echo "Waiting $(($MAX - $WAIT)) secs for MDT deactivated"
884         done
885
886         # test new client starts deactivated
887         umount_client $MOUNT || return 200
888         mount_client $MOUNT
889         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
890         if [ -z "$RESULT" ]; then
891             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
892             return 5
893         else
894             echo "New client success: got $RESULT"
895         fi
896
897         # make sure it reactivates
898         set_and_check client "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
899
900         umount_client $MOUNT
901         stop_ost2
902         cleanup_nocli
903         #writeconf to remove all ost2 traces for subsequent tests
904         writeconf
905 }
906 run_test 29 "permanently remove an OST"
907
908 test_30() {
909         setup
910
911         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
912         ORIG=$($TEST)
913         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
914         for i in ${LIST[@]}; do
915             set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
916         done
917         # make sure client restart still works
918         umount_client $MOUNT
919         mount_client $MOUNT || return 4
920         [ "$($TEST)" -ne "$i" ] && return 5
921         set_and_check client "$TEST" "$FSNAME.llite.max_read_ahead_whole_mb" $ORIG || return 6
922         cleanup
923 }
924 run_test 30 "Big config llog"
925
926 test_31() { # bug 10734
927         # ipaddr must not exist
928         mount -t lustre 4.3.2.1@tcp:/lustre $MOUNT || true
929         cleanup
930 }
931 run_test 31 "Connect to non-existent node (shouldn't crash)"
932
933 # Use these start32/stop32 fn instead of t-f start/stop fn,
934 # for local devices, to skip global facet vars init
935 stop32 () {
936         local facet=$1
937         shift
938         echo "Stopping local ${MOUNT%/*}/${facet} (opts:$@)"
939         umount -d $@ ${MOUNT%/*}/${facet}
940         losetup -a
941 }
942
943 start32 () {
944         local facet=$1
945         shift
946         local device=$1
947         shift
948         mkdir -p ${MOUNT%/*}/${facet}
949
950         echo "Starting local ${facet}: $@ $device ${MOUNT%/*}/${facet}"
951         mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}
952         local RC=$?
953         if [ $RC -ne 0 ]; then
954                 echo "mount -t lustre $@ ${device} ${MOUNT%/*}/${facet}"
955                 echo "Start of ${device} of local ${facet} failed ${RC}"
956         fi
957         losetup -a
958         return $RC
959 }
960
961 cleanup_nocli32 () {
962         stop32 mds1 -f
963         stop32 ost1 -f
964         wait_exit_ST client
965 }
966
967 cleanup_32() {
968         trap 0
969         echo "Cleanup test_32 umount $MOUNT ..."
970         umount -f $MOUNT || true
971         echo "Cleanup local mds ost1 ..."
972         cleanup_nocli32
973         unload_modules
974 }
975
976 test_32a() {
977         client_only && skip "client only testing" && return 0
978         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
979         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return 0
980
981         local DISK1_8=$LUSTRE/tests/disk1_8.tar.bz2
982         [ ! -r $DISK1_8 ] && skip_env "Cannot find $DISK1_8" && return 0
983         local tmpdir=$TMP/conf32a
984         mkdir -p $tmpdir
985         tar xjvf $DISK1_8 -C $tmpdir || \
986                 { skip_env "Cannot untar $DISK1_8" && return 0; }
987
988         load_modules
989         $LCTL set_param debug=$PTLDEBUG
990
991         $TUNEFS $tmpdir/mds || error "tunefs failed"
992
993         # nids are wrong, so client wont work, but server should start
994         start32 mds1 $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
995                 trap cleanup_32 EXIT INT || return 3
996
997         local UUID=$($LCTL get_param -n mdt.lustre-MDT0000.uuid)
998         echo MDS uuid $UUID
999         [ "$UUID" == "lustre-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1000
1001         $TUNEFS --mgsnode=$HOSTNAME $tmpdir/ost1 || error "tunefs failed"
1002         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1003         UUID=$($LCTL get_param -n obdfilter.lustre-OST0000.uuid)
1004         echo OST uuid $UUID
1005         [ "$UUID" == "lustre-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1006
1007         local NID=$($LCTL list_nids | head -1)
1008
1009         echo "OSC changes should succeed:"
1010         $LCTL conf_param lustre-OST0000.osc.max_dirty_mb=15 || return 7
1011         $LCTL conf_param lustre-OST0000.failover.node=$NID || return 8
1012         echo "ok."
1013
1014         echo "MDC changes should succeed:"
1015         $LCTL conf_param lustre-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1016         $LCTL conf_param lustre-MDT0000.failover.node=$NID || return 10
1017         echo "ok."
1018
1019         echo "LOV changes should succeed:"
1020         $LCTL pool_new lustre.interop || return 11
1021         $LCTL conf_param lustre-MDT0000.lov.stripesize=4M || return 12
1022         echo "ok."
1023
1024         cleanup_32
1025
1026         # mount a second time to make sure we didnt leave upgrade flag on
1027         load_modules
1028         $TUNEFS --dryrun $tmpdir/mds || error "tunefs failed"
1029         start32 mds1 $tmpdir/mds "-o loop,exclude=lustre-OST0000" && \
1030                 trap cleanup_32 EXIT INT || return 12
1031
1032         cleanup_32
1033
1034         rm -rf $tmpdir || true  # true is only for TMP on NFS
1035 }
1036 run_test 32a "Upgrade from 1.8 (not live)"
1037
1038 test_32b() {
1039         client_only && skip "client only testing" && return 0
1040         [ "$NETTYPE" = "tcp" ] || { skip "NETTYPE != tcp" && return 0; }
1041         [ -z "$TUNEFS" ] && skip_env "No tunefs" && return
1042
1043         local DISK1_8=$LUSTRE/tests/disk1_8.tar.bz2
1044         [ ! -r $DISK1_8 ] && skip_env "Cannot find $DISK1_8" && return 0
1045         local tmpdir=$TMP/conf32b
1046         mkdir -p $tmpdir
1047         tar xjvf $DISK1_8 -C $tmpdir || \
1048                 { skip_env "Cannot untar $DISK1_8" && return ; }
1049
1050         load_modules
1051         $LCTL set_param debug="config"
1052         local NEWNAME=lustre
1053
1054         # writeconf will cause servers to register with their current nids
1055         $TUNEFS --writeconf --fsname=$NEWNAME $tmpdir/mds || error "tunefs failed"
1056         start32 mds1 $tmpdir/mds "-o loop" && \
1057                 trap cleanup_32 EXIT INT || return 3
1058
1059         local UUID=$($LCTL get_param -n mdt.${NEWNAME}-MDT0000.uuid)
1060         echo MDS uuid $UUID
1061         [ "$UUID" == "${NEWNAME}-MDT0000_UUID" ] || error "UUID is wrong: $UUID"
1062
1063         $TUNEFS --mgsnode=$HOSTNAME --writeconf --fsname=$NEWNAME $tmpdir/ost1 ||\
1064             error "tunefs failed"
1065         start32 ost1 $tmpdir/ost1 "-o loop" || return 5
1066         UUID=$($LCTL get_param -n obdfilter.${NEWNAME}-OST0000.uuid)
1067         echo OST uuid $UUID
1068         [ "$UUID" == "${NEWNAME}-OST0000_UUID" ] || error "UUID is wrong: $UUID"
1069
1070         local NID=$($LCTL list_nids | head -1)
1071
1072         echo "OSC changes should succeed:"
1073         $LCTL conf_param ${NEWNAME}-OST0000.osc.max_dirty_mb=15 || return 7
1074         $LCTL conf_param ${NEWNAME}-OST0000.failover.node=$NID || return 8
1075         echo "ok."
1076
1077         echo "MDC changes should succeed:"
1078         $LCTL conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=9 || return 9
1079         $LCTL conf_param ${NEWNAME}-MDT0000.failover.node=$NID || return 10
1080         echo "ok."
1081
1082         echo "LOV changes should succeed:"
1083         $LCTL pool_new ${NEWNAME}.interop || return 11
1084         $LCTL conf_param ${NEWNAME}-MDT0000.lov.stripesize=4M || return 12
1085         echo "ok."
1086
1087         # MDT and OST should have registered with new nids, so we should have
1088         # a fully-functioning client
1089         echo "Check client and old fs contents"
1090
1091         local device=`h2$NETTYPE $HOSTNAME`:/$NEWNAME
1092         echo "Starting local client: $HOSTNAME: $device $MOUNT"
1093         mount -t lustre $device $MOUNT || return 1
1094
1095         local old=$($LCTL get_param -n mdc.*.max_rpcs_in_flight)
1096         local new=$((old + 5))
1097         $LCTL conf_param ${NEWNAME}-MDT0000.mdc.max_rpcs_in_flight=$new
1098         wait_update $HOSTNAME "$LCTL get_param -n mdc.*.max_rpcs_in_flight" $new || return 11
1099
1100         [ "$(cksum $MOUNT/passwd | cut -d' ' -f 1,2)" == "94306271 1478" ] || return 12
1101         echo "ok."
1102
1103         cleanup_32
1104
1105         rm -rf $tmpdir || true  # true is only for TMP on NFS
1106 }
1107 run_test 32b "Upgrade from 1.8 with writeconf"
1108
1109 test_33a() { # bug 12333, was test_33
1110         local rc=0
1111         local FSNAME2=test-123
1112         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
1113
1114         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
1115                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
1116                 skip_env "mixed loopback and real device not working" && return
1117         fi
1118
1119         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1120         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1121         add fs2mds $MDS_MKFS_OPTS --mkfsoptions='\"-J size=8\"' --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1122         add fs2ost $OST_MKFS_OPTS --fsname=${FSNAME2} --index=8191 --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1123
1124         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
1125         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1126         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
1127         mkdir -p $MOUNT2
1128         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
1129         echo "ok."
1130
1131         cp /etc/hosts $MOUNT2/ || rc=3
1132         $LFS getstripe $MOUNT2/hosts
1133
1134         umount -d $MOUNT2
1135         stop fs2ost -f
1136         stop fs2mds -f
1137         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev
1138         cleanup_nocli || rc=6
1139         return $rc
1140 }
1141 run_test 33a "Mount ost with a large index number"
1142
1143 test_33b() {    # was test_34
1144         setup
1145
1146         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
1147         # Drop lock cancelation reply during umount
1148         #define OBD_FAIL_LDLM_CANCEL             0x304
1149         do_facet client lctl set_param fail_loc=0x80000304
1150         #lctl set_param debug=-1
1151         umount_client $MOUNT
1152         cleanup
1153 }
1154 run_test 33b "Drop cancel during umount"
1155
1156 test_34a() {
1157         setup
1158         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
1159         manual_umount_client
1160         rc=$?
1161         do_facet client killall -USR1 multiop
1162         if [ $rc -eq 0 ]; then
1163                 error "umount not fail!"
1164         fi
1165         sleep 1
1166         cleanup
1167 }
1168 run_test 34a "umount with opened file should be fail"
1169
1170
1171 test_34b() {
1172         setup
1173         touch $DIR/$tfile || return 1
1174         stop_mds --force || return 2
1175
1176         manual_umount_client --force
1177         rc=$?
1178         if [ $rc -ne 0 ]; then
1179                 error "mtab after failed umount - rc $rc"
1180         fi
1181
1182         cleanup
1183         return 0
1184 }
1185 run_test 34b "force umount with failed mds should be normal"
1186
1187 test_34c() {
1188         setup
1189         touch $DIR/$tfile || return 1
1190         stop_ost --force || return 2
1191
1192         manual_umount_client --force
1193         rc=$?
1194         if [ $rc -ne 0 ]; then
1195                 error "mtab after failed umount - rc $rc"
1196         fi
1197
1198         cleanup
1199         return 0
1200 }
1201 run_test 34c "force umount with failed ost should be normal"
1202
1203 test_35a() { # bug 12459
1204         setup
1205
1206         DBG_SAVE="`lctl get_param -n debug`"
1207         lctl set_param debug="ha"
1208
1209         log "Set up a fake failnode for the MDS"
1210         FAKENID="127.0.0.2"
1211         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1212         do_facet $SINGLEMDS $LCTL conf_param ${device}.failover.node=$FAKENID || return 4
1213
1214         log "Wait for RECONNECT_INTERVAL seconds (10s)"
1215         sleep 10
1216
1217         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
1218         $LCTL clear
1219         log "$MSG"
1220         log "Stopping the MDT:"
1221         stop_mds || return 5
1222
1223         df $MOUNT > /dev/null 2>&1 &
1224         DFPID=$!
1225         log "Restarting the MDT:"
1226         start_mds || return 6
1227         log "Wait for df ($DFPID) ... "
1228         wait $DFPID
1229         log "done"
1230         lctl set_param debug="$DBG_SAVE"
1231
1232         # retrieve from the log the first server that the client tried to
1233         # contact after the connection loss
1234         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1235         NEXTCONN=`awk "/${MSG}/ {start = 1;}
1236                        /import_select_connection.*$device-mdc.* using connection/ {
1237                                 if (start) {
1238                                         if (\\\$NF ~ /$FAKENID/)
1239                                                 print \\\$NF;
1240                                         else
1241                                                 print 0;
1242                                         exit;
1243                                 }
1244                        }" $TMP/lustre-log-$TESTNAME.log`
1245         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
1246         cleanup
1247 }
1248 run_test 35a "Reconnect to the last active server first"
1249
1250 test_35b() { # bug 18674
1251         remote_mds || { skip "local MDS" && return 0; }
1252         setup
1253
1254         debugsave
1255         $LCTL set_param debug="ha"
1256         $LCTL clear
1257         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
1258         log "$MSG"
1259
1260         log "Set up a fake failnode for the MDS"
1261         FAKENID="127.0.0.2"
1262         local device=$(do_facet mds "$LCTL get_param -n devices" | \
1263                         awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
1264         do_facet mds "$LCTL conf_param ${device}.failover.node=$FAKENID" || \
1265                 return 1
1266
1267         local at_max_saved=0
1268         # adaptive timeouts may prevent seeing the issue 
1269         if at_is_enabled; then
1270                 at_max_saved=$(at_max_get mds)
1271                 at_max_set 0 mds client
1272         fi
1273
1274         mkdir -p $MOUNT/testdir
1275         touch $MOUNT/testdir/test
1276
1277         log "Injecting EBUSY on MDS"
1278         # Setting OBD_FAIL_MDS_RESEND=0x136
1279         do_facet mds "$LCTL set_param fail_loc=0x80000136" || return 2
1280
1281         log "Stat on a test file"
1282         stat $MOUNT/testdir/test
1283
1284         log "Stop injecting EBUSY on MDS"
1285         do_facet mds "$LCTL set_param fail_loc=0" || return 3
1286         rm -f $MOUNT/testdir/test
1287
1288         log "done"
1289         # restore adaptive timeout
1290         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
1291
1292         $LCTL dk $TMP/lustre-log-$TESTNAME.log
1293
1294         # retrieve from the log if the client has ever tried to
1295         # contact the fake server after the loss of connection
1296         FAILCONN=`awk "BEGIN {ret = 0;}
1297                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
1298                                 ret = 1;
1299                                 if (\\\$NF ~ /$FAKENID/) {
1300                                         ret = 2;
1301                                         exit;
1302                                 }
1303                        }
1304                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
1305
1306         [ "$FAILCONN" == "0" ] && \
1307                 log "ERROR: The client reconnection has not been triggered" && \
1308                 return 4
1309         [ "$FAILCONN" == "2" ] && \
1310                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
1311                 return 5
1312
1313         cleanup
1314 }
1315 run_test 35b "Continue reconnection retries, if the active server is busy"
1316
1317 test_36() { # 12743
1318         local rc
1319         local FSNAME2=test1234
1320         local fs3ost_HOST=$ost_HOST
1321
1322         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
1323         rc=0
1324
1325         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
1326                 do_facet $SINGLEMDS [ -b "$MDSDEV" ] && \
1327                 skip_env "mixed loopback and real device not working" && return
1328         fi
1329         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
1330
1331         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
1332                 { skip "remote OST" && return 0; }
1333
1334         local fs2mdsdev=${fs2mds_DEV:-${MDSDEV}_2}
1335         local fs2ostdev=${fs2ost_DEV:-$(ostdevname 1)_2}
1336         local fs3ostdev=${fs3ost_DEV:-$(ostdevname 2)_2}
1337         add fs2mds $MDS_MKFS_OPTS --fsname=${FSNAME2} --reformat $fs2mdsdev || exit 10
1338         # XXX after we support non 4K disk blocksize, change following --mkfsoptions with
1339         # other argument
1340         add fs2ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs2ostdev || exit 10
1341         add fs3ost $OST_MKFS_OPTS --mkfsoptions='-b4096' --fsname=${FSNAME2} --mgsnode=$MGSNID --reformat $fs3ostdev || exit 10
1342
1343         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
1344         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
1345         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
1346         mkdir -p $MOUNT2
1347         mount -t lustre $MGSNID:/${FSNAME2} $MOUNT2 || return 1
1348
1349         sleep 5 # until 11778 fixed
1350
1351         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
1352
1353         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
1354         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
1355         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
1356         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
1357         DFTOTAL=`echo $STRING | cut -d, -f1`
1358         DFUSED=`echo $STRING  | cut -d, -f2`
1359         DFAVAIL=`echo $STRING | cut -d, -f3`
1360         DFFREE=$(($DFTOTAL - $DFUSED))
1361
1362         ALLOWANCE=$((64 * $OSTCOUNT))
1363
1364         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
1365            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
1366                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
1367                 rc=1
1368         fi
1369         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
1370            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
1371                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
1372                 rc=2
1373         fi
1374         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
1375            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
1376                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
1377                 rc=3
1378        fi
1379
1380         umount -d $MOUNT2
1381         stop fs3ost -f || return 200
1382         stop fs2ost -f || return 201
1383         stop fs2mds -f || return 202
1384         rm -rf $MOUNT2 $fs2mdsdev $fs2ostdev $fs3ostdev
1385         unload_modules || return 203
1386         return $rc
1387 }
1388 run_test 36 "df report consistency on OSTs with different block size"
1389
1390 test_37() {
1391         client_only && skip "client only testing" && return 0
1392         LOCAL_MDSDEV="$TMP/mdt.img"
1393         SYM_MDSDEV="$TMP/sym_mdt.img"
1394
1395         echo "MDS :     $LOCAL_MDSDEV"
1396         echo "SYMLINK : $SYM_MDSDEV"
1397         rm -f $LOCAL_MDSDEV
1398
1399         touch $LOCAL_MDSDEV
1400         mkfs.lustre --reformat --fsname=lustre --mdt --mgs --device-size=9000 $LOCAL_MDSDEV ||
1401                 error "mkfs.lustre $LOCAL_MDSDEV failed"
1402         ln -s $LOCAL_MDSDEV $SYM_MDSDEV
1403
1404         echo "mount symlink device - $SYM_MDSDEV"
1405
1406         mount_op=`mount -v -t lustre -o loop $SYM_MDSDEV ${MOUNT%/*}/mds 2>&1 | grep "unable to set tunable"`
1407         umount -d ${MOUNT%/*}/mds
1408         rm -f $LOCAL_MDSDEV $SYM_MDSDEV
1409
1410         if [ -n "$mount_op" ]; then
1411                 error "**** FAIL: set tunables failed for symlink device"
1412         fi
1413         return 0
1414 }
1415 run_test 37 "verify set tunables works for symlink device"
1416
1417 test_38() { # bug 14222
1418         setup
1419         # like runtests
1420         COUNT=10
1421         SRC="/etc /bin"
1422         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
1423         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
1424         mkdir -p $DIR/$tdir
1425         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
1426                 error "copying $SRC to $DIR/$tdir"
1427         sync
1428         umount_client $MOUNT
1429         stop_mds
1430         log "rename lov_objid file on MDS"
1431         rm -f $TMP/lov_objid.orig
1432
1433         local dev=${SINGLEMDS}_dev
1434         local MDSDEV=${!dev}
1435         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
1436         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1437
1438         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
1439         # check create in mds_lov_connect
1440         start_mds
1441         mount_client $MOUNT
1442         for f in $FILES; do
1443                 [ $V ] && log "verifying $DIR/$tdir/$f"
1444                 diff -q $f $DIR/$tdir/$f || ERROR=y
1445         done
1446         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
1447         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
1448         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
1449
1450         # check it's updates in sync
1451         umount_client $MOUNT
1452         stop_mds
1453
1454         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
1455         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
1456         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
1457
1458         start_mds
1459         mount_client $MOUNT
1460         for f in $FILES; do
1461                 [ $V ] && log "verifying $DIR/$tdir/$f"
1462                 diff -q $f $DIR/$tdir/$f || ERROR=y
1463         done
1464         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
1465         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
1466         umount_client $MOUNT
1467         stop_mds
1468         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
1469
1470         log "files compared the same"
1471         cleanup
1472 }
1473 run_test 38 "MDS recreates missing lov_objid file from OST data"
1474
1475 test_39() {
1476         PTLDEBUG=+malloc
1477         setup
1478         cleanup
1479         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
1480                 error "memory leak detected" || true
1481 }
1482 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
1483
1484 test_40() { # bug 15759
1485         start_ost
1486         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
1487         do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000706"
1488         start_mds
1489         cleanup
1490 }
1491 run_test 40 "race during service thread startup"
1492
1493 test_41() { #bug 14134
1494         local rc
1495         local dev=${SINGLEMDS}_dev
1496         local MDSDEV=${!dev}
1497
1498         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
1499         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
1500         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
1501         mkdir -p $MOUNT
1502         mount_client $MOUNT || return 1
1503         sleep 5
1504
1505         echo "blah blah" > $MOUNT/$tfile
1506         cat $MOUNT/$tfile
1507
1508         umount_client $MOUNT
1509         stop ost1 -f || return 201
1510         stop_mds -f || return 202
1511         stop_mds -f || return 203
1512         unload_modules || return 204
1513         return $rc
1514 }
1515 run_test 41 "mount mds with --nosvc and --nomgs"
1516
1517 test_42() { #bug 14693
1518         setup
1519         check_mount || return 2
1520         do_facet client lctl conf_param lustre.llite.some_wrong_param=10
1521         umount_client $MOUNT
1522         mount_client $MOUNT || return 1
1523         cleanup
1524         return 0
1525 }
1526 run_test 42 "invalid config param should not prevent client from mounting"
1527
1528 test_43() {
1529     [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
1530     setup
1531     chmod ugo+x $DIR || error "chmod 0 failed"
1532     set_and_check mds                                        \
1533         "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"  \
1534         "$FSNAME.mdt.root_squash"                            \
1535         "0:0"
1536     set_and_check mds                                        \
1537        "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids" \
1538        "$FSNAME.mdt.nosquash_nids"                           \
1539        "NONE"
1540
1541     #
1542     # create set of test files
1543     #
1544     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
1545     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
1546     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
1547
1548     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
1549     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
1550
1551     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
1552     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
1553     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
1554
1555     #
1556     # check root_squash:
1557     #   set root squash UID:GID to RUNAS_ID
1558     #   root should be able to access only files owned by RUNAS_ID
1559     #
1560     set_and_check mds                                        \
1561        "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"   \
1562        "$FSNAME.mdt.root_squash"                             \
1563        "$RUNAS_ID:$RUNAS_ID"
1564
1565     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
1566     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
1567         error "$ST: root read permission is denied"
1568     echo "$ST: root read permission is granted - ok"
1569
1570     echo "444" | \
1571     dd conv=notrunc if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
1572         error "$ST: root write permission is denied"
1573     echo "$ST: root write permission is granted - ok"
1574
1575     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
1576     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
1577         error "$ST: root read permission is granted"
1578     echo "$ST: root read permission is denied - ok"
1579
1580     echo "555" | \
1581     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
1582         error "$ST: root write permission is granted"
1583     echo "$ST: root write permission is denied - ok"
1584
1585     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
1586     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
1587         error "$ST: root unlink permission is granted"
1588     echo "$ST: root unlink permission is denied - ok"
1589
1590     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
1591         error "$ST: root create permission is granted"
1592     echo "$ST: root create permission is denied - ok"
1593
1594     #
1595     # check nosquash_nids:
1596     #   put client's NID into nosquash_nids list,
1597     #   root should be able to access root file after that
1598     #
1599     local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
1600     NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
1601     NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
1602     set_and_check mds                                        \
1603        "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids" \
1604        "$FSNAME-MDTall.mdt.nosquash_nids"                    \
1605        "$NIDLIST"
1606
1607     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
1608     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
1609         error "$ST: root read permission is denied"
1610     echo "$ST: root read permission is granted - ok"
1611
1612     echo "666" | \
1613     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
1614         error "$ST: root write permission is denied"
1615     echo "$ST: root write permission is granted - ok"
1616
1617     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
1618     rm $DIR/$tdir-rootdir/tfile-1 || \
1619         error "$ST: root unlink permission is denied"
1620     echo "$ST: root unlink permission is granted - ok"
1621     touch $DIR/$tdir-rootdir/tfile-2 || \
1622         error "$ST: root create permission is denied"
1623     echo "$ST: root create permission is granted - ok"
1624
1625     return 0
1626 }
1627 run_test 43 "check root_squash and nosquash_nids"
1628
1629 umount_client $MOUNT
1630 cleanup_nocli
1631
1632 test_44() { # 16317
1633         setup
1634         check_mount || return 2
1635         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
1636         STATS_FOUND=no
1637         UUIDS=$(do_facet mds "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
1638         for VAL in $UUIDS; do
1639                 NID=$(echo $VAL | cut -d= -f1)
1640                 CLUUID=$(echo $VAL | cut -d= -f2)
1641                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
1642         done
1643         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
1644         cleanup
1645         return 0
1646 }
1647 run_test 44 "mounted client proc entry exists"
1648
1649 test_45() { #17310
1650         setup
1651         check_mount || return 2
1652         stop_mds
1653         df -h $MOUNT &
1654         log "sleep 60 sec"
1655         sleep 60
1656 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
1657         do_facet client "lctl set_param fail_loc=0x50f"
1658         log "sleep 10 sec"
1659         sleep 10
1660         manual_umount_client --force || return 3
1661         do_facet client "lctl set_param fail_loc=0x0"
1662         start_mds
1663         mount_client $MOUNT || return 4
1664         cleanup
1665         return 0
1666 }
1667 run_test 45 "long unlink handling in ptlrpcd"
1668
1669 cleanup_46a() {
1670         trap 0
1671         local rc=0
1672         local count=$1
1673
1674         umount_client $MOUNT2 || rc=$?
1675         umount_client $MOUNT || rc=$?
1676         while [ $count -gt 0 ]; do
1677                 stop ost${count} -f || rc=$?
1678                 let count=count-1
1679         done    
1680         stop_mds || rc=$? 
1681         # writeconf is needed after the test, otherwise,
1682         # we might end up with extra OSTs
1683         writeconf || rc=$?
1684         cleanup_nocli || rc=$?
1685         return $rc
1686 }
1687
1688 test_46a() {
1689         echo "Testing with $OSTCOUNT OSTs"
1690         reformat
1691         start_mds || return 1
1692         #first client should see only one ost
1693         start_ost || return 2
1694         wait_osc_import_state mds ost FULL
1695         #start_client
1696         mount_client $MOUNT || return 3
1697         trap "cleanup_46a $OSTCOUNT" EXIT ERR
1698
1699         local i 
1700         for (( i=2; i<=$OSTCOUNT; i++ )); do
1701             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
1702         done
1703
1704         # wait until osts in sync
1705         for (( i=2; i<=$OSTCOUNT; i++ )); do
1706             wait_osc_import_state mds ost$i FULL
1707         done
1708
1709
1710         #second client see all ost's
1711
1712         mount_client $MOUNT2 || return 8
1713         $LFS setstripe $MOUNT2 -c -1 || return 9
1714         $LFS getstripe $MOUNT2 || return 10
1715
1716         echo "ok" > $MOUNT2/widestripe
1717         $LFS getstripe $MOUNT2/widestripe || return 11
1718         # fill acl buffer for avoid expand lsm to them
1719         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
1720             setfacl -m $acl $MOUNT2/widestripe
1721         done
1722
1723         # will be deadlock
1724         stat $MOUNT/widestripe || return 12
1725
1726         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
1727         return 0
1728 }
1729 run_test 46a "handle ost additional - wide striped file"
1730
1731 test_47() { #17674
1732         reformat
1733         setup_noconfig
1734         check_mount || return 2
1735         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
1736
1737         local lru_size=[]
1738         local count=0
1739         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1740             if echo $ns | grep "MDT[[:digit:]]*"; then
1741                 continue
1742             fi
1743             lrs=$(echo $ns | sed 's/.*lru_size=//')
1744             lru_size[count]=$lrs
1745             let count=count+1
1746         done
1747
1748         facet_failover ost1
1749         facet_failover $SINGLEMDS
1750         df -h $MOUNT || return 3
1751
1752         count=0
1753         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
1754             if echo $ns | grep "MDT[[:digit:]]*"; then
1755                 continue
1756             fi
1757             lrs=$(echo $ns | sed 's/.*lru_size=//')
1758             if ! test "$lrs" -eq "${lru_size[count]}"; then
1759                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
1760                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
1761             fi
1762             let count=count+1
1763         done
1764
1765         cleanup
1766         return 0
1767 }
1768 run_test 47 "server restart does not make client loss lru_resize settings"
1769
1770 cleanup_48() {
1771         trap 0
1772
1773         # reformat after this test is needed - if test will failed
1774         # we will have unkillable file at FS
1775         reformat_and_config
1776 }
1777
1778 test_48() { # bug 17636
1779         reformat
1780         setup_noconfig
1781         check_mount || return 2
1782
1783         $LFS setstripe $MOUNT -c -1 || return 9
1784         $LFS getstripe $MOUNT || return 10
1785
1786         echo "ok" > $MOUNT/widestripe
1787         $LFS getstripe $MOUNT/widestripe || return 11
1788
1789         trap cleanup_48 EXIT ERR
1790
1791         # fill acl buffer for avoid expand lsm to them
1792         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
1793             setfacl -m $acl $MOUNT/widestripe
1794         done
1795
1796         stat $MOUNT/widestripe || return 12
1797
1798         cleanup_48
1799         return 0
1800 }
1801 run_test 48 "too many acls on file"
1802
1803 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
1804 test_49() { # bug 17710
1805         local OLD_MDS_MKFS_OPTS=$MDS_MKFS_OPTS
1806         local OLD_OST_MKFS_OPTS=$OST_MKFS_OPTS
1807         local LOCAL_TIMEOUT=20
1808
1809
1810         OST_MKFS_OPTS="--ost --fsname=$FSNAME --device-size=$OSTSIZE --mgsnode=$MGSNID --param sys.timeout=$LOCAL_TIMEOUT --param sys.ldlm_timeout=$LOCAL_TIMEOUT $MKFSOPT $OSTOPT"
1811
1812         reformat
1813         start_mds
1814         start_ost
1815         mount_client $MOUNT
1816         check_mount || return 1
1817
1818         echo "check ldlm_timout..."
1819         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
1820         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
1821         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
1822
1823         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
1824                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
1825         fi
1826
1827         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
1828                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
1829         fi
1830
1831         umount_client $MOUNT
1832         stop_ost || return 2
1833         stop_mds || return 3
1834
1835         OST_MKFS_OPTS="--ost --fsname=$FSNAME --device-size=$OSTSIZE --mgsnode=$MGSNID --param sys.timeout=$LOCAL_TIMEOUT --param sys.ldlm_timeout=$((LOCAL_TIMEOUT - 1)) $MKFSOPT $OSTOPT"
1836
1837         reformat
1838         start_mds || return 4
1839         start_ost || return 5
1840         mount_client $MOUNT || return 6
1841         check_mount || return 7
1842
1843         LDLM_MDS="`do_facet mds lctl get_param -n ldlm_timeout`"
1844         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
1845         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
1846
1847         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
1848                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
1849         fi
1850
1851         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
1852                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
1853         fi
1854
1855         cleanup || return $?
1856
1857         MDS_MKFS_OPTS=$OLD_MDS_MKFS_OPTS
1858         OST_MKFS_OPTS=$OLD_OST_MKFS_OPTS
1859 }
1860 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
1861
1862 lazystatfs() {
1863         # Test both statfs and lfs df and fail if either one fails
1864         multiop_bg_pause $1 f_
1865         RC1=$?
1866         PID=$!
1867         killall -USR1 multiop
1868         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
1869         wait $PID || { RC1=$?; log "multiop return error "; }
1870
1871         $LFS df &
1872         PID=$!
1873         sleep 5
1874         kill -s 0 $PID
1875         RC2=$?
1876         if [ $RC2 -eq 0 ]; then
1877             kill -s 9 $PID
1878             log "lazystatfs df failed"
1879         fi
1880
1881         RC=0
1882         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
1883         return $RC
1884 }
1885
1886 test_50a() {
1887         setup
1888         lctl set_param llite.$FSNAME-*.lazystatfs=1
1889         touch $DIR/$tfile
1890
1891         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
1892
1893         cleanup || return $?
1894 }
1895 run_test 50a "lazystatfs all servers available =========================="
1896
1897 test_50b() {
1898         setup
1899         lctl set_param llite.$FSNAME-*.lazystatfs=1
1900         touch $DIR/$tfile
1901
1902         # Wait for client to detect down OST
1903         stop_ost || error "Unable to stop OST1"
1904         wait_osc_import_state mds ost DISCONN
1905
1906         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
1907
1908         umount_client $MOUNT || error "Unable to unmount client"
1909         stop_mds || error "Unable to stop MDS"
1910 }
1911 run_test 50b "lazystatfs all servers down =========================="
1912
1913 test_50c() {
1914         start_mds || error "Unable to start MDS"
1915         start_ost || error "Unable to start OST1"
1916         start_ost2 || error "Unable to start OST2"
1917         mount_client $MOUNT || error "Unable to mount client"
1918         lctl set_param llite.$FSNAME-*.lazystatfs=1
1919         touch $DIR/$tfile
1920
1921         # Wait for client to detect down OST
1922         stop_ost || error "Unable to stop OST1"
1923         wait_osc_import_state mds ost DISCONN
1924         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
1925
1926         umount_client $MOUNT || error "Unable to unmount client"
1927         stop_ost2 || error "Unable to stop OST2"
1928         stop_mds || error "Unable to stop MDS"
1929 }
1930 run_test 50c "lazystatfs one server down =========================="
1931
1932 test_50d() {
1933         start_mds || error "Unable to start MDS"
1934         start_ost || error "Unable to start OST1"
1935         start_ost2 || error "Unable to start OST2"
1936         mount_client $MOUNT || error "Unable to mount client"
1937         lctl set_param llite.$FSNAME-*.lazystatfs=1
1938         touch $DIR/$tfile
1939
1940         # Issue the statfs during the window where the client still
1941         # belives the OST to be available but it is in fact down.
1942         # No failure just a statfs which hangs for a timeout interval.
1943         stop_ost || error "Unable to stop OST1"
1944         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
1945
1946         umount_client $MOUNT || error "Unable to unmount client"
1947         stop_ost2 || error "Unable to stop OST2"
1948         stop_mds || error "Unable to stop MDS"
1949 }
1950 run_test 50d "lazystatfs client/server conn race =========================="
1951
1952 test_50e() {
1953         local RC1
1954         local pid
1955
1956         reformat_and_config
1957         start_mds || return 1
1958         #first client should see only one ost
1959         start_ost || return 2
1960         wait_osc_import_state mds ost FULL
1961
1962         # Wait for client to detect down OST
1963         stop_ost || error "Unable to stop OST1"
1964         wait_osc_import_state mds ost DISCONN
1965
1966         mount_client $MOUNT || error "Unable to mount client"
1967         lctl set_param llite.$FSNAME-*.lazystatfs=0
1968
1969         multiop_bg_pause $MOUNT _f
1970         RC1=$?
1971         pid=$!
1972
1973         if [ $RC1 -ne 0 ]; then
1974                 log "multiop failed $RC1"
1975         else
1976             kill -USR1 $pid
1977             sleep $(( $TIMEOUT+1 ))
1978             kill -0 $pid
1979             [ $? -ne 0 ] && error "process isn't sleep"
1980             start_ost || error "Unable to start OST1"
1981             wait $pid || error "statfs failed"
1982         fi
1983
1984         umount_client $MOUNT || error "Unable to unmount client"
1985         stop_ost || error "Unable to stop OST1"
1986         stop_mds || error "Unable to stop MDS"
1987 }
1988 run_test 50e "normal statfs all servers down =========================="
1989
1990 test_50f() {
1991         local RC1
1992         local pid
1993         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
1994
1995         start_mds || error "Unable to start mds"
1996         #first client should see only one ost
1997         start_ost || error "Unable to start OST1"
1998         wait_osc_import_state mds ost FULL
1999
2000         start_ost2 || error "Unable to start OST2"
2001         wait_osc_import_state mds ost2 FULL
2002
2003         # Wait for client to detect down OST
2004         stop_ost2 || error "Unable to stop OST2"
2005
2006         wait_osc_import_state mds ost2 DISCONN
2007         mount_client $MOUNT || error "Unable to mount client"
2008         lctl set_param llite.$FSNAME-*.lazystatfs=0
2009
2010         multiop_bg_pause $MOUNT _f
2011         RC1=$?
2012         pid=$!
2013
2014         if [ $RC1 -ne 0 ]; then
2015                 log "lazystatfs multiop failed $RC1"
2016         else
2017             kill -USR1 $pid
2018             sleep $(( $TIMEOUT+1 ))
2019             kill -0 $pid
2020             [ $? -ne 0 ] && error "process isn't sleep"
2021             start_ost2 || error "Unable to start OST2"
2022             wait $pid || error "statfs failed"
2023             stop_ost2 || error "Unable to stop OST2"
2024         fi
2025
2026         umount_client $MOUNT || error "Unable to unmount client"
2027         stop_ost || error "Unable to stop OST1"
2028         stop_mds || error "Unable to stop MDS"
2029         writeconf
2030 }
2031 run_test 50f "normal statfs one server in down =========================="
2032
2033 test_50g() {
2034         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
2035         setup
2036         start_ost2 || error "Unable to start OST2"
2037
2038         local PARAM="${FSNAME}-OST0001.osc.active"
2039
2040         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
2041         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
2042
2043         umount_client $MOUNT || error "Unable to unmount client"
2044         mount_client $MOUNT || error "Unable to mount client"
2045         # This df should not cause a panic
2046         df -k $MOUNT
2047
2048         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
2049         rm -f $DIR/$tfile
2050         umount_client $MOUNT || error "Unable to unmount client"
2051         stop_ost2 || error "Unable to stop OST2"
2052         stop_ost || error "Unable to stop OST1"
2053         stop_mds || error "Unable to stop MDS"
2054         writeconf
2055 }
2056 run_test 50g "deactivated OST should not cause panic====================="
2057
2058 test_51() {
2059         local LOCAL_TIMEOUT=20
2060
2061         reformat
2062         start_mds
2063         start_ost
2064         mount_client $MOUNT
2065         check_mount || return 1
2066
2067         mkdir $MOUNT/d1
2068         $LFS setstripe -c -1 $MOUNT/d1
2069         #define OBD_FAIL_MDS_REINT_DELAY         0x142
2070         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
2071         touch $MOUNT/d1/f1 &
2072         local pid=$!
2073         sleep 2
2074         start_ost2 || return 2
2075         wait $pid
2076         stop_ost2 || return 3
2077         cleanup
2078 }
2079 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
2080
2081 copy_files_xattrs()
2082 {
2083         local node=$1
2084         local dest=$2
2085         local xattrs=$3
2086         shift 3
2087
2088         do_node $node mkdir -p $dest
2089         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2090
2091         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
2092                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2093         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
2094
2095         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
2096         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
2097 }
2098
2099 diff_files_xattrs()
2100 {
2101         local node=$1
2102         local backup=$2
2103         local xattrs=$3
2104         shift 3
2105
2106         local backup2=${TMP}/backup2
2107
2108         do_node $node mkdir -p $backup2
2109         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
2110
2111         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
2112                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
2113         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
2114
2115         do_node $node "diff -rq $backup $backup2"
2116         [ $? -eq 0 ] || { error "contents differ"; return 3; }
2117
2118         local xattrs2=${TMP}/xattrs2
2119         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
2120         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
2121
2122         do_node $node "diff $xattrs $xattrs2"
2123         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
2124
2125         do_node $node "rm -rf $backup2 $xattrs2"
2126         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
2127 }
2128
2129 test_52() {
2130         start_mds
2131         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
2132         start_ost
2133         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
2134         mount_client $MOUNT
2135         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
2136
2137         local nrfiles=8
2138         local ost1mnt=${MOUNT%/*}/ost1
2139         local ost1node=$(facet_active_host ost1)
2140         local ost1tmp=$TMP/conf52
2141
2142         mkdir -p $DIR/$tdir
2143         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
2144         touch $TMP/modified_first
2145         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
2146         do_node $ost1node "mkdir -p $ost1tmp && touch $ost1tmp/modified_first"
2147         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
2148         sleep 1
2149
2150         $LFS setstripe $DIR/$tdir -c -1 -s 1M
2151         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
2152
2153         for (( i=0; i < nrfiles; i++ )); do
2154                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
2155                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
2156                 echo -n .
2157         done
2158         echo
2159
2160         # backup files
2161         echo backup files to $TMP/files
2162         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
2163         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2164         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
2165
2166         umount_client $MOUNT
2167         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
2168         stop_ost
2169         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
2170
2171         echo mount ost1 as ldiskfs
2172         do_node $ost1node mount -t $FSTYPE $ost1_dev $ost1mnt $OST_MOUNT_OPTS
2173         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
2174
2175         # backup objects
2176         echo backup objects to $ost1tmp/objects
2177         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/0 -type f -size +0'\
2178                         '-newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
2179         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2180         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
2181
2182         # move objects to lost+found
2183         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
2184         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
2185
2186         # recover objects
2187         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
2188         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
2189
2190         # compare restored objects against saved ones
2191         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
2192         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
2193
2194         do_node $ost1node "umount $ost1_dev"
2195         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
2196
2197         start_ost
2198         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
2199         mount_client $MOUNT
2200         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
2201
2202         # compare files
2203         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
2204         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
2205
2206         rm -rf $TMP/files $TMP/file_xattrs
2207         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
2208         do_node $ost1node "rm -rf $ost1tmp"
2209         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
2210         cleanup
2211 }
2212 run_test 52 "check recovering objects from lost+found"
2213
2214 cleanup_gss
2215 equals_msg `basename $0`: test complete
2216 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true