Whamcloud - gitweb
LU-5729 osd: iput in case of error in osd_scrub_setup
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2
3 # FIXME - there is no reason to use all of these different return codes,
4 #   espcially when most of them are mapped to something else anyway.
5 #   The tests should use error() to describe the failure more clearly,
6 #   and reduce the need to look into the tests to see what failed.
7
8 set -e
9
10 ONLY=${ONLY:-"$*"}
11
12 # bug number for skipped test:     LU-2828
13 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 59 64"
14 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
15
16 is_sles11()                                             # LU-2181
17 {
18         if [ -r /etc/SuSE-release ]
19         then
20                 local vers=`grep VERSION /etc/SuSE-release | awk '{print $3}'`
21                 local patchlev=`grep PATCHLEVEL /etc/SuSE-release \
22                         | awk '{print $3}'`
23                 if [ $vers -eq 11 ] && [ $patchlev -eq 2 ]
24                 then
25                         return 0
26                 fi
27         fi
28         return 1
29 }
30
31 if is_sles11; then                                      # LU-2181
32         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 23a 34b"
33 fi
34
35 if [ "$FAILURE_MODE" = "HARD" ]; then
36         CONFIG_EXCEPTIONS="24a " && \
37         echo "Except the tests: $CONFIG_EXCEPTIONS for FAILURE_MODE=$FAILURE_MODE, bug 23573" && \
38         ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
39 fi
40
41 # bug number for skipped test:
42 # a tool to create lustre filesystem images
43 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
44
45 SRCDIR=`dirname $0`
46 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
47
48 PTLDEBUG=${PTLDEBUG:--1}
49 SAVE_PWD=$PWD
50 LUSTRE=${LUSTRE:-`dirname $0`/..}
51 RLUSTRE=${RLUSTRE:-$LUSTRE}
52 export MULTIOP=${MULTIOP:-multiop}
53
54 . $LUSTRE/tests/test-framework.sh
55 init_test_env $@
56 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
57
58 # use small MDS + OST size to speed formatting time
59 # do not use too small MDSSIZE/OSTSIZE, which affect the default jouranl size
60 # STORED_MDSSIZE is used in test_18
61 STORED_MDSSIZE=$MDSSIZE
62 STORED_OSTSIZE=$OSTSIZE
63 MDSSIZE=200000
64 OSTSIZE=200000
65
66 if ! combined_mgs_mds; then
67     # bug number for skipped test:    23954
68     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
69 fi
70
71 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
72 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
73         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
74 fi
75
76 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
77 # bug number for skipped test:        LU-2778 LU-4444
78         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 57b     69"
79
80 init_logging
81
82 #
83 require_dsh_mds || exit 0
84 require_dsh_ost || exit 0
85 #
86 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30a 31 45 69"
87
88
89 assert_DIR
90
91 gen_config() {
92         # The MGS must be started before the OSTs for a new fs, so start
93         # and stop to generate the startup logs.
94         start_mds
95         start_ost
96         wait_osc_import_state mds ost FULL
97         stop_ost
98         stop_mds
99 }
100
101 reformat_and_config() {
102         reformat
103         if ! combined_mgs_mds ; then
104                 start_mgs
105         fi
106         gen_config
107 }
108
109 writeconf_or_reformat() {
110         # There are at most 2 OSTs for write_conf test
111         # who knows if/where $TUNEFS is installed?
112         # Better reformat if it fails...
113         writeconf_all $MDSCOUNT 2 ||
114                 { echo "tunefs failed, reformatting instead" &&
115                   reformat_and_config && return 0; }
116         return 0
117 }
118
119 reformat() {
120         formatall
121 }
122
123 start_mgs () {
124         echo "start mgs"
125         start mgs $(mgsdevname) $MGS_MOUNT_OPTS
126 }
127
128 start_mdt() {
129         local num=$1
130         local facet=mds$num
131         local dev=$(mdsdevname $num)
132         shift 1
133
134         echo "start mds service on `facet_active_host $facet`"
135         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
136 }
137
138 stop_mdt() {
139         local num=$1
140         local facet=mds$num
141         local dev=$(mdsdevname $num)
142         shift 1
143
144         echo "stop mds service on `facet_active_host $facet`"
145         # These tests all use non-failover stop
146         stop $facet -f  || return 97
147 }
148
149 start_mds() {
150         local num
151
152         for num in $(seq $MDSCOUNT); do
153                 start_mdt $num $@ || return 94
154         done
155 }
156
157 start_mgsmds() {
158         if ! combined_mgs_mds ; then
159                 start_mgs
160         fi
161         start_mds $@
162 }
163
164 stop_mds() {
165         local num
166         for num in $(seq $MDSCOUNT); do
167                 stop_mdt $num || return 97
168         done
169 }
170
171 stop_mgs() {
172        echo "stop mgs service on `facet_active_host mgs`"
173        # These tests all use non-failover stop
174        stop mgs -f  || return 97
175 }
176
177 start_ost() {
178         echo "start ost1 service on `facet_active_host ost1`"
179         start ost1 `ostdevname 1` $OST_MOUNT_OPTS $@ || return 95
180 }
181
182 stop_ost() {
183         echo "stop ost1 service on `facet_active_host ost1`"
184         # These tests all use non-failover stop
185         stop ost1 -f  || return 98
186 }
187
188 start_ost2() {
189         echo "start ost2 service on `facet_active_host ost2`"
190         start ost2 `ostdevname 2` $OST_MOUNT_OPTS $@ || return 92
191 }
192
193 stop_ost2() {
194         echo "stop ost2 service on `facet_active_host ost2`"
195         # These tests all use non-failover stop
196         stop ost2 -f  || return 93
197 }
198
199 mount_client() {
200         local MOUNTPATH=$1
201         echo "mount $FSNAME on ${MOUNTPATH}....."
202         zconf_mount `hostname` $MOUNTPATH  || return 96
203 }
204
205 remount_client() {
206         local mountopt="remount,$1"
207         local MOUNTPATH=$2
208         echo "remount '$1' lustre on ${MOUNTPATH}....."
209         zconf_mount `hostname`  $MOUNTPATH "$mountopt"  || return 96
210 }
211
212 umount_client() {
213         local MOUNTPATH=$1
214         echo "umount lustre on ${MOUNTPATH}....."
215         zconf_umount `hostname` $MOUNTPATH || return 97
216 }
217
218 manual_umount_client(){
219         local rc
220         local FORCE=$1
221         echo "manual umount lustre on ${MOUNT}...."
222         do_facet client "umount -d ${FORCE} $MOUNT"
223         rc=$?
224         return $rc
225 }
226
227 setup() {
228         start_mds || error "MDT start failed"
229         start_ost || error "OST start failed"
230         mount_client $MOUNT || error "client start failed"
231         client_up || error "client_up failed"
232 }
233
234 setup_noconfig() {
235         start_mgsmds
236         start_ost
237         mount_client $MOUNT
238 }
239
240 unload_modules_conf () {
241         if combined_mgs_mds || ! local_mode; then
242                 unload_modules || return 1
243         fi
244 }
245
246 cleanup_nocli() {
247         stop_ost || return 202
248         stop_mds || return 201
249         unload_modules_conf || return 203
250 }
251
252 cleanup() {
253         umount_client $MOUNT || return 200
254         cleanup_nocli || return $?
255 }
256
257 check_mount() {
258         do_facet client "cp /etc/passwd $DIR/a" || return 71
259         do_facet client "rm $DIR/a" || return 72
260         # make sure lustre is actually mounted (touch will block,
261         # but grep won't, so do it after)
262         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
263         echo "setup single mount lustre success"
264 }
265
266 check_mount2() {
267         do_facet client "touch $DIR/a" || return 71
268         do_facet client "rm $DIR/a" || return 72
269         do_facet client "touch $DIR2/a" || return 73
270         do_facet client "rm $DIR2/a" || return 74
271         echo "setup double mount lustre success"
272 }
273
274 build_test_filter
275
276 if [ "$ONLY" == "setup" ]; then
277         setup
278         exit
279 fi
280
281 if [ "$ONLY" == "cleanup" ]; then
282         cleanup
283         exit
284 fi
285
286 init_gss
287
288 #create single point mountpoint
289
290 reformat_and_config
291
292 test_0() {
293         setup
294         check_mount || return 41
295         cleanup || return $?
296 }
297 run_test 0 "single mount setup"
298
299 test_1() {
300         start_mds || error "MDT start failed"
301         start_ost
302         echo "start ost second time..."
303         start_ost && error "2nd OST start should fail"
304         mount_client $MOUNT || error "client start failed"
305         check_mount || return 42
306         cleanup || return $?
307 }
308 run_test 1 "start up ost twice (should return errors)"
309
310 test_2() {
311         start_mdt 1
312         echo "start mds second time.."
313         start_mdt 1 && error "2nd MDT start should fail"
314         start_ost
315         mount_client $MOUNT
316         check_mount || return 43
317         cleanup || return $?
318 }
319 run_test 2 "start up mds twice (should return err)"
320
321 test_3() {
322         setup
323         #mount.lustre returns an error if already in mtab
324         mount_client $MOUNT && error "2nd client mount should fail"
325         check_mount || return 44
326         cleanup || return $?
327 }
328 run_test 3 "mount client twice (should return err)"
329
330 test_4() {
331         setup
332         touch $DIR/$tfile || return 85
333         stop_ost -f
334         cleanup
335         eno=$?
336         # ok for ost to fail shutdown
337         if [ 202 -ne $eno ]; then
338                 return $eno;
339         fi
340         return 0
341 }
342 run_test 4 "force cleanup ost, then cleanup"
343
344 test_5a() {     # was test_5
345         setup
346         touch $DIR/$tfile || return 1
347         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
348
349         stop_mds -f || return 2
350
351         # cleanup may return an error from the failed
352         # disconnects; for now I'll consider this successful
353         # if all the modules have unloaded.
354         umount -d $MOUNT &
355         UMOUNT_PID=$!
356         sleep 6
357         echo "killing umount"
358         kill -TERM $UMOUNT_PID
359         echo "waiting for umount to finish"
360         wait $UMOUNT_PID
361         if grep " $MOUNT " /proc/mounts; then
362                 echo "test 5: /proc/mounts after failed umount"
363                 umount -f $MOUNT &
364                 UMOUNT_PID=$!
365                 sleep 2
366                 echo "killing umount"
367                 kill -TERM $UMOUNT_PID
368                 echo "waiting for umount to finish"
369                 wait $UMOUNT_PID
370                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
371         fi
372
373         manual_umount_client
374         # stop_mds is a no-op here, and should not fail
375         cleanup_nocli || return $?
376         # df may have lingering entry
377         manual_umount_client
378         # mtab may have lingering entry
379         local WAIT=0
380         local MAX_WAIT=20
381         local sleep=1
382         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
383                 sleep $sleep
384                 grep -q $MOUNT" " /etc/mtab || break
385                 echo "Waiting /etc/mtab updated ... "
386                 WAIT=$(( WAIT + sleep))
387         done
388         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
389         echo "/etc/mtab updated in $WAIT secs"
390 }
391 run_test 5a "force cleanup mds, then cleanup"
392
393 cleanup_5b () {
394         trap 0
395         start_mgs
396 }
397
398 test_5b() {
399         grep " $MOUNT " /etc/mtab && \
400                 error false "unexpected entry in mtab before mount" && return 10
401
402         local rc=0
403         start_ost
404         if ! combined_mgs_mds ; then
405                 trap cleanup_5b EXIT ERR
406                 start_mds
407                 stop mgs
408         fi
409
410         [ -d $MOUNT ] || mkdir -p $MOUNT
411         mount_client $MOUNT && rc=1
412         grep " $MOUNT " /etc/mtab && \
413                 error "$MOUNT entry in mtab after failed mount" && rc=11
414         umount_client $MOUNT
415         # stop_mds is a no-op here, and should not fail
416         cleanup_nocli || rc=$?
417         if ! combined_mgs_mds ; then
418                 cleanup_5b
419         fi
420         return $rc
421 }
422 run_test 5b "Try to start a client with no MGS (should return errs)"
423
424 test_5c() {
425         grep " $MOUNT " /etc/mtab && \
426                 error false "unexpected entry in mtab before mount" && return 10
427
428         local rc=0
429         start_mds
430         start_ost
431         [ -d $MOUNT ] || mkdir -p $MOUNT
432         local oldfs="${FSNAME}"
433         FSNAME="wrong.${FSNAME}"
434         mount_client $MOUNT || :
435         FSNAME=${oldfs}
436         grep " $MOUNT " /etc/mtab && \
437                 error "$MOUNT entry in mtab after failed mount" && rc=11
438         umount_client $MOUNT
439         cleanup_nocli  || rc=$?
440         return $rc
441 }
442 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
443
444 test_5d() {
445         grep " $MOUNT " /etc/mtab && \
446                 error false "unexpected entry in mtab before mount" && return 10
447
448         local rc=0
449         start_ost
450         start_mds
451         stop_ost -f
452         mount_client $MOUNT || rc=1
453         cleanup  || rc=$?
454         grep " $MOUNT " /etc/mtab && \
455                 error "$MOUNT entry in mtab after unmount" && rc=11
456         return $rc
457 }
458 run_test 5d "mount with ost down"
459
460 test_5e() {
461         grep " $MOUNT " /etc/mtab && \
462                 error false "unexpected entry in mtab before mount" && return 10
463
464         local rc=0
465         start_mds
466         start_ost
467
468 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
469         do_facet client "lctl set_param fail_loc=0x80000506"
470         mount_client $MOUNT || echo "mount failed (not fatal)"
471         cleanup  || rc=$?
472         grep " $MOUNT " /etc/mtab && \
473                 error "$MOUNT entry in mtab after unmount" && rc=11
474         return $rc
475 }
476 run_test 5e "delayed connect, don't crash (bug 10268)"
477
478 test_5f() {
479         if combined_mgs_mds ; then
480                 skip "combined mgs and mds"
481                 return 0
482         fi
483
484         grep " $MOUNT " /etc/mtab && \
485                 error false "unexpected entry in mtab before mount" && return 10
486
487         local rc=0
488         start_ost
489         [ -d $MOUNT ] || mkdir -p $MOUNT
490         mount_client $MOUNT &
491         local pid=$!
492         echo client_mount pid is $pid
493
494         sleep 5
495
496         if ! ps -f -p $pid >/dev/null; then
497                 wait $pid
498                 rc=$?
499                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
500                 error "mount returns $rc, expected to hang"
501                 rc=11
502                 cleanup || rc=$?
503                 return $rc
504         fi
505
506         # start mds
507         start_mds
508
509         # mount should succeed after start mds
510         wait $pid
511         rc=$?
512         [ $rc -eq 0 ] || error "mount returned $rc"
513         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
514         cleanup || return $?
515         return $rc
516 }
517 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
518
519 test_6() {
520         setup
521         manual_umount_client
522         mount_client ${MOUNT} || return 87
523         touch $DIR/a || return 86
524         cleanup  || return $?
525 }
526 run_test 6 "manual umount, then mount again"
527
528 test_7() {
529         setup
530         manual_umount_client
531         cleanup_nocli || return $?
532 }
533 run_test 7 "manual umount, then cleanup"
534
535 test_8() {
536         setup
537         mount_client $MOUNT2
538         check_mount2 || return 45
539         umount_client $MOUNT2
540         cleanup  || return $?
541 }
542 run_test 8 "double mount setup"
543
544 test_9() {
545         start_ost
546
547         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
548         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
549
550         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
551         if [ "$CHECK_PTLDEBUG" ] && { \
552            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
553            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
554            echo "lnet.debug success"
555         else
556            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
557            return 1
558         fi
559         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
560         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
561            echo "lnet.subsystem_debug success"
562         else
563            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
564            return 1
565         fi
566         stop_ost || return $?
567 }
568 run_test 9 "test ptldebug and subsystem for mkfs"
569
570 is_blkdev () {
571         local facet=$1
572         local dev=$2
573         local size=${3:-""}
574
575         local rc=0
576         do_facet $facet "test -b $dev" || rc=1
577         if [[ "$size" ]]; then
578                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
579                         awk '($3 == "in") { print $1 }')
580                 [[ $in  = "1+0" ]] || rc=1
581         fi
582         return $rc
583 }
584
585 #
586 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
587 # But with new MDS stack we don't care about the mode of local objects
588 # anymore, so this test is removed. See bug 22944 for more details.
589 #
590
591 test_17() {
592         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
593                 skip "Only applicable to ldiskfs-based MDTs"
594                 return
595         fi
596
597         setup
598         check_mount || return 41
599         cleanup || return $?
600
601         echo "Remove mds config log"
602         if ! combined_mgs_mds ; then
603                 stop mgs
604         fi
605
606         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
607                 $(mgsdevname) || return \$?" || return $?
608
609         if ! combined_mgs_mds ; then
610                 start_mgs
611         fi
612
613         start_ost
614         start_mds && return 42
615         reformat_and_config
616 }
617 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
618
619 test_18() {
620         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
621                 skip "Only applicable to ldiskfs-based MDTs"
622                 return
623         fi
624
625         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
626
627         local MIN=2000000
628
629         local OK=
630         # check if current MDSSIZE is large enough
631         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
632                 log "use MDSSIZE=$MDSSIZE"
633
634         # check if the global config has a large enough MDSSIZE
635         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
636                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
637                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
638
639         # check if the block device is large enough
640         is_blkdev $SINGLEMDS $MDSDEV $MIN
641         local large_enough=$?
642         if [ -n "$OK" ]; then
643                 [ $large_enough -ne 0 ] && OK=""
644         else
645                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
646                         log "use device $MDSDEV with MIN=$MIN"
647         fi
648
649         # check if a loopback device has enough space for fs metadata (5%)
650
651         if [ -z "$OK" ]; then
652                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
653                         awk '($1 != "Filesystem") {print $4}')
654                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
655                         OK=1 && myMDSSIZE=$MIN && \
656                         log "use file $MDSDEV with MIN=$MIN"
657         fi
658
659         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
660
661
662         echo "mount mds with large journal..."
663
664         local OLD_MDSSIZE=$MDSSIZE
665         MDSSIZE=$myMDSSIZE
666
667         reformat_and_config
668         echo "mount lustre system..."
669         setup
670         check_mount || return 41
671
672         echo "check journal size..."
673         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
674         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
675                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
676         else
677                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
678         fi
679
680         cleanup || return $?
681
682         MDSSIZE=$OLD_MDSSIZE
683         reformat_and_config
684 }
685 run_test 18 "check mkfs creates large journals"
686
687 test_19a() {
688         start_mds || return 1
689         stop_mds -f || return 2
690 }
691 run_test 19a "start/stop MDS without OSTs"
692
693 test_19b() {
694         start_ost || return 1
695         stop_ost -f || return 2
696 }
697 run_test 19b "start/stop OSTs without MDS"
698
699 test_20() {
700         # first format the ost/mdt
701         start_mds
702         start_ost
703         mount_client $MOUNT
704         check_mount || return 43
705         rm -f $DIR/$tfile
706         remount_client ro $MOUNT || return 44
707         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
708         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
709         remount_client rw $MOUNT || return 47
710         touch $DIR/$tfile
711         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
712         MCNT=`grep -c $MOUNT /etc/mtab`
713         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
714         umount_client $MOUNT
715         stop_mds
716         stop_ost
717 }
718 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
719
720 test_21a() {
721         start_mds
722         start_ost
723         wait_osc_import_state mds ost FULL
724         stop_ost
725         stop_mds
726 }
727 run_test 21a "start mds before ost, stop ost first"
728
729 test_21b() {
730         start_ost
731         start_mds
732         wait_osc_import_state mds ost FULL
733         stop_mds
734         stop_ost
735 }
736 run_test 21b "start ost before mds, stop mds first"
737
738 test_21c() {
739         start_ost
740         start_mds
741         start_ost2
742         wait_osc_import_state mds ost2 FULL
743         stop_ost
744         stop_ost2
745         stop_mds
746         #writeconf to remove all ost2 traces for subsequent tests
747         writeconf_or_reformat
748 }
749 run_test 21c "start mds between two osts, stop mds last"
750
751 test_21d() {
752         if combined_mgs_mds ; then
753                 skip "need separate mgs device" && return 0
754         fi
755         stopall
756
757         reformat
758
759         start_mgs
760         start_ost
761         start_ost2
762         start_mds
763         wait_osc_import_state mds ost2 FULL
764
765         stop_ost
766         stop_ost2
767         stop_mds
768         stop_mgs
769         #writeconf to remove all ost2 traces for subsequent tests
770         writeconf_or_reformat
771         start_mgs
772 }
773 run_test 21d "start mgs then ost and then mds"
774
775 test_22() {
776         start_mds
777
778         echo Client mount with ost in logs, but none running
779         start_ost
780         # wait until mds connected to ost and open client connection
781         wait_osc_import_state mds ost FULL
782         stop_ost
783         mount_client $MOUNT
784         # check_mount will block trying to contact ost
785         mcreate $DIR/$tfile || return 40
786         rm -f $DIR/$tfile || return 42
787         umount_client $MOUNT
788         pass
789
790         echo Client mount with a running ost
791         start_ost
792         if $GSS; then
793                 # if gss enabled, wait full time to let connection from
794                 # mds to ost be established, due to the mismatch between
795                 # initial connect timeout and gss context negotiation timeout.
796                 # This perhaps could be remove after AT landed.
797                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
798                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
799         fi
800         mount_client $MOUNT
801         wait_osc_import_state mds ost FULL
802         wait_osc_import_state client ost FULL
803         check_mount || return 41
804         pass
805
806         cleanup
807 }
808 run_test 22 "start a client before osts (should return errs)"
809
810 test_23a() {    # was test_23
811         setup
812         # fail mds
813         stop $SINGLEMDS
814         # force down client so that recovering mds waits for reconnect
815         local running=$(grep -c $MOUNT /proc/mounts) || true
816         if [ $running -ne 0 ]; then
817                 echo "Stopping client $MOUNT (opts: -f)"
818                 umount -f $MOUNT
819         fi
820
821         # enter recovery on mds
822         start_mds
823         # try to start a new client
824         mount_client $MOUNT &
825         sleep 5
826         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
827         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
828         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
829         ps --ppid $MOUNT_PID
830         ps --ppid $MOUNT_LUSTRE_PID
831         echo "waiting for mount to finish"
832         ps -ef | grep mount
833         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
834         # SIGTERM works but it does not spread to offspring processses
835         kill -s TERM $MOUNT_PID
836         kill -s TERM $MOUNT_LUSTRE_PID
837         # we can not wait $MOUNT_PID because it is not a child of this shell
838         local PID1
839         local PID2
840         local WAIT=0
841         local MAX_WAIT=30
842         local sleep=1
843         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
844                 sleep $sleep
845                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
846                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
847                 echo PID1=$PID1
848                 echo PID2=$PID2
849                 [ -z "$PID1" -a -z "$PID2" ] && break
850                 echo "waiting for mount to finish ... "
851                 WAIT=$(( WAIT + sleep))
852         done
853         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
854                 error "MOUNT_PID $MOUNT_PID and "\
855                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
856                 ps -ef | grep mount
857         fi
858         stop_mds || error "stopping MDSes failed"
859         stop_ost || error "stopping OSSes failed"
860 }
861 run_test 23a "interrupt client during recovery mount delay"
862
863 umount_client $MOUNT
864 cleanup_nocli
865
866 test_23b() {    # was test_23
867         start_mds
868         start_ost
869         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
870         lctl set_param fail_loc=0x80000313
871         mount_client $MOUNT
872         cleanup
873 }
874 run_test 23b "Simulate -EINTR during mount"
875
876 fs2mds_HOST=$mds_HOST
877 fs2ost_HOST=$ost_HOST
878
879 MDSDEV1_2=$fs2mds_DEV
880 OSTDEV1_2=$fs2ost_DEV
881 OSTDEV2_2=$fs3ost_DEV
882
883 cleanup_fs2() {
884         trap 0
885         echo "umount $MOUNT2 ..."
886         umount $MOUNT2 || true
887         echo "stopping fs2mds ..."
888         stop fs2mds -f || true
889         echo "stopping fs2ost ..."
890         stop fs2ost -f || true
891 }
892
893 test_24a() {
894         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
895
896         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
897                 is_blkdev $SINGLEMDS $MDSDEV && \
898                 skip_env "mixed loopback and real device not working" && return
899         fi
900
901         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
902
903         local fs2mdsdev=$(mdsdevname 1_2)
904         local fs2ostdev=$(ostdevname 1_2)
905         local fs2mdsvdev=$(mdsvdevname 1_2)
906         local fs2ostvdev=$(ostvdevname 1_2)
907
908         # test 8-char fsname as well
909         local FSNAME2=test1234
910
911         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
912                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
913
914         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
915                 --reformat $fs2ostdev $fs2ostvdev || exit 10
916
917         setup
918         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
919         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
920         mkdir -p $MOUNT2
921         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || return 1
922         # 1 still works
923         check_mount || return 2
924         # files written on 1 should not show up on 2
925         cp /etc/passwd $DIR/$tfile
926         sleep 10
927         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
928         # 2 should work
929         sleep 5
930         cp /etc/passwd $MOUNT2/b || return 3
931         rm $MOUNT2/b || return 4
932         # 2 is actually mounted
933         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
934         # failover
935         facet_failover fs2mds
936         facet_failover fs2ost
937         df
938         umount_client $MOUNT
939         # the MDS must remain up until last MDT
940         stop_mds
941         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
942         [ -z "$MDS" ] && error "No MDT" && return 8
943         cleanup_fs2
944         cleanup_nocli || return 6
945 }
946 run_test 24a "Multiple MDTs on a single node"
947
948 test_24b() {
949         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
950
951         if [ -z "$fs2mds_DEV" ]; then
952                 local dev=${SINGLEMDS}_dev
953                 local MDSDEV=${!dev}
954                 is_blkdev $SINGLEMDS $MDSDEV && \
955                 skip_env "mixed loopback and real device not working" && return
956         fi
957
958         local fs2mdsdev=$(mdsdevname 1_2)
959         local fs2mdsvdev=$(mdsvdevname 1_2)
960
961         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
962                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
963         setup
964         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
965         stop fs2mds -f
966         cleanup || return 6
967 }
968 run_test 24b "Multiple MGSs on a single node (should return err)"
969
970 test_25() {
971         setup
972         check_mount || return 2
973         local MODULES=$($LCTL modules | awk '{ print $2 }')
974         rmmod $MODULES 2>/dev/null || true
975         cleanup || return 6
976 }
977 run_test 25 "Verify modules are referenced"
978
979 test_26() {
980     load_modules
981     # we need modules before mount for sysctl, so make sure...
982     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
983 #define OBD_FAIL_MDS_FS_SETUP            0x135
984     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
985     start_mds && echo MDS started && return 1
986     lctl get_param -n devices
987     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
988     [ $DEVS -gt 0 ] && return 2
989     # start mds to drop writeconf setting
990     start_mds || return 3
991     stop_mds || return 4
992     unload_modules_conf || return $?
993 }
994 run_test 26 "MDT startup failure cleans LOV (should return errs)"
995
996 test_27a() {
997         start_ost || return 1
998         start_mds || return 2
999         echo "Requeue thread should have started: "
1000         ps -e | grep ll_cfg_requeue
1001         set_conf_param_and_check ost1                                         \
1002            "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
1003            "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
1004         cleanup_nocli
1005 }
1006 run_test 27a "Reacquire MGS lock if OST started first"
1007
1008 test_27b() {
1009         # FIXME. ~grev
1010         setup
1011         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
1012                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1013
1014         facet_failover $SINGLEMDS
1015         set_conf_param_and_check $SINGLEMDS                             \
1016                 "lctl get_param -n mdt.$device.identity_acquire_expire" \
1017                 "$device.mdt.identity_acquire_expire" || return 3
1018         set_conf_param_and_check client                                 \
1019                 "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1020                 "$device.mdc.max_rpcs_in_flight" || return 4
1021         check_mount
1022         cleanup
1023 }
1024 run_test 27b "Reacquire MGS lock after failover"
1025
1026 test_28() {
1027         setup
1028         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1029         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1030         ORIG=$($TEST)
1031         FINAL=$(($ORIG + 1))
1032         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 3
1033         FINAL=$(($FINAL + 1))
1034         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 4
1035         umount_client $MOUNT || return 200
1036         mount_client $MOUNT
1037         RESULT=$($TEST)
1038         if [ $RESULT -ne $FINAL ]; then
1039             echo "New config not seen: wanted $FINAL got $RESULT"
1040             return 4
1041         else
1042             echo "New config success: got $RESULT"
1043         fi
1044         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG || return 5
1045         cleanup
1046 }
1047 run_test 28 "permanent parameter setting"
1048
1049 test_28a() { # LU-4221
1050         [[ $(lustre_version_code ost1) -ge $(version_code 2.5.52) ]] ||
1051                 { skip "Need OST version at least 2.5.52" && return 0; }
1052         [ "$(facet_fstype ost1)" = "zfs" ] &&
1053                 skip "LU-4221: no such proc params for ZFS OSTs" && return
1054
1055         local name
1056         local param
1057         local cmd
1058         local old
1059         local new
1060         local device="$FSNAME-OST0000"
1061
1062         setup
1063
1064         # In this test we will set three kinds of proc parameters with
1065         # lctl conf_param:
1066         # 1. the ones moved from the OFD to the OSD, and only their
1067         #    symlinks kept in obdfilter
1068         # 2. non-symlink ones in the OFD
1069         # 3. non-symlink ones in the OSD
1070
1071         # Check 1.
1072         # prepare a symlink parameter in the OFD
1073         name="writethrough_cache_enable"
1074         param="$device.ost.$name"
1075         cmd="$LCTL get_param -n obdfilter.$device.$name"
1076
1077         # conf_param the symlink parameter in the OFD
1078         old=$(do_facet ost1 $cmd)
1079         new=$(((old + 1) % 2))
1080         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1081                 error "lctl conf_param $device.ost.$param=$new failed"
1082
1083         # conf_param the target parameter in the OSD
1084         param="$device.osd.$name"
1085         cmd="$LCTL get_param -n osd-*.$device.$name"
1086         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1087                 error "lctl conf_param $device.osd.$param=$old failed"
1088
1089         # Check 2.
1090         # prepare a non-symlink parameter in the OFD
1091         name="client_cache_seconds"
1092         param="$device.ost.$name"
1093         cmd="$LCTL get_param -n obdfilter.$device.$name"
1094
1095         # conf_param the parameter in the OFD
1096         old=$(do_facet ost1 $cmd)
1097         new=$((old * 2))
1098         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1099                 error "lctl conf_param $device.ost.$param=$new failed"
1100         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1101                 error "lctl conf_param $device.ost.$param=$old failed"
1102
1103         # Check 3.
1104         # prepare a non-symlink parameter in the OSD
1105         name="lma_self_repair"
1106         param="$device.osd.$name"
1107         cmd="$LCTL get_param -n osd-*.$device.$name"
1108
1109         # conf_param the parameter in the OSD
1110         old=$(do_facet ost1 $cmd)
1111         new=$(((old + 1) % 2))
1112         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1113                 error "lctl conf_param $device.osd.$param=$new failed"
1114         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1115                 error "lctl conf_param $device.osd.$param=$old failed"
1116
1117         cleanup
1118 }
1119 run_test 28a "set symlink parameters permanently with conf_param"
1120
1121 test_29() {
1122         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1123         setup > /dev/null 2>&1
1124         start_ost2
1125         sleep 10
1126
1127         local PARAM="$FSNAME-OST0001.osc.active"
1128         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1129         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1130
1131         ACTV=$(lctl get_param -n $PROC_ACT)
1132         DEAC=$((1 - $ACTV))
1133         set_conf_param_and_check client \
1134                 "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1135         # also check ost_server_uuid status
1136         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1137         if [ -z "$RESULT" ]; then
1138             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1139             return 3
1140         else
1141             echo "Live client success: got $RESULT"
1142         fi
1143
1144         # check MDTs too
1145         for num in $(seq $MDSCOUNT); do
1146                 local mdtosc=$(get_mdtosc_proc_path mds${num} $FSNAME-OST0001)
1147                 local MPROC="osc.$mdtosc.active"
1148                 local MAX=30
1149                 local WAIT=0
1150                 while [ 1 ]; do
1151                         sleep 5
1152                         RESULT=$(do_facet mds${num} " lctl get_param -n $MPROC")
1153                         [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1154                         if [ $RESULT -eq $DEAC ]; then
1155                                 echo -n "MDT deactivated also after"
1156                                 echo "$WAIT sec (got $RESULT)"
1157                                 break
1158                         fi
1159                         WAIT=$((WAIT + 5))
1160                         if [ $WAIT -eq $MAX ]; then
1161                                 echo -n "MDT not deactivated: wanted $DEAC"
1162                                 echo  "got $RESULT"
1163                                 return 4
1164                         fi
1165                         echo "Waiting $(($MAX - $WAIT))secs for MDT deactivated"
1166                 done
1167         done
1168         # test new client starts deactivated
1169         umount_client $MOUNT || return 200
1170         mount_client $MOUNT
1171         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1172         if [ -z "$RESULT" ]; then
1173             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1174             return 5
1175         else
1176             echo "New client success: got $RESULT"
1177         fi
1178
1179         # make sure it reactivates
1180         set_conf_param_and_check client \
1181                 "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1182
1183         umount_client $MOUNT
1184         stop_ost2
1185         cleanup_nocli
1186         #writeconf to remove all ost2 traces for subsequent tests
1187         writeconf_or_reformat
1188 }
1189 run_test 29 "permanently remove an OST"
1190
1191 test_30a() {
1192         setup
1193
1194         echo Big config llog
1195         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1196         ORIG=$($TEST)
1197         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1198         for i in ${LIST[@]}; do
1199                 set_conf_param_and_check client "$TEST" \
1200                         "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1201         done
1202         # make sure client restart still works
1203         umount_client $MOUNT
1204         mount_client $MOUNT || return 4
1205         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1206         pass
1207
1208         echo Erase parameter setting
1209         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1210         umount_client $MOUNT
1211         mount_client $MOUNT || return 6
1212         FINAL=$($TEST)
1213         echo "deleted (default) value=$FINAL, orig=$ORIG"
1214         # assumes this parameter started at the default value
1215         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1216
1217         cleanup
1218 }
1219 run_test 30a "Big config llog and conf_param deletion"
1220
1221 test_30b() {
1222         setup
1223
1224         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1225         # numerical part of it. Hopefully that's not already a failover address for
1226         # the server.
1227         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1228         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1229         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1230         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1231         echo "Using fake nid $NEW"
1232
1233         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1234                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1235         set_conf_param_and_check client "$TEST" \
1236                 "$FSNAME-OST0000.failover.node" $NEW ||
1237                 error "didn't add failover nid $NEW"
1238         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1239                 grep failover_nids)
1240         echo $NIDS
1241         # The NIDS value is the failover nid strings and "[" and "]". So
1242         # we need to subtract the space taken by the delimiters. This has
1243         # changed from earlier version of Lustre but this test is run only
1244         # locally so this change will not break interop. See LU-3386
1245         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
1246         echo "should have 2 failover nids: $NIDCOUNT"
1247         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1248         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" ||
1249                 error "conf_param delete failed"
1250         umount_client $MOUNT
1251         mount_client $MOUNT || return 3
1252
1253         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1254                 grep failover_nids)
1255         echo $NIDS
1256         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
1257         echo "only 1 final nid should remain: $NIDCOUNT"
1258         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1259
1260         cleanup
1261 }
1262 run_test 30b "Remove failover nids"
1263
1264 test_31() { # bug 10734
1265         # ipaddr must not exist
1266         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1267         cleanup
1268 }
1269 run_test 31 "Connect to non-existent node (shouldn't crash)"
1270
1271
1272 T32_QID=60000
1273 T32_BLIMIT=20480 # Kbytes
1274 T32_ILIMIT=2
1275
1276 #
1277 # This is not really a test but a tool to create new disk
1278 # image tarballs for the upgrade tests.
1279 #
1280 # Disk image tarballs should be created on single-node
1281 # clusters by running this test with default configurations
1282 # plus a few mandatory environment settings that are verified
1283 # at the beginning of the test.
1284 #
1285 test_32newtarball() {
1286         local version
1287         local dst=.
1288         local src=/etc/rc.d
1289         local tmp=$TMP/t32_image_create
1290
1291         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1292                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1293                  -z "$OSTDEV1" ]; then
1294                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1295                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1296                           "OSTDEV1=<nonexistent_file>"
1297         fi
1298
1299         mkdir $tmp || {
1300                 echo "Found stale $tmp"
1301                 return 1
1302         }
1303
1304         mkdir $tmp/src
1305         tar cf - -C $src . | tar xf - -C $tmp/src
1306         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1307                 count=$(($T32_BLIMIT / 1024 / 2))
1308         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1309
1310         # format ost with comma-separated NIDs to verify LU-4460
1311         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
1312         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1313
1314         setupall
1315
1316         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1317                 $LFS quotacheck -ug /mnt/$FSNAME
1318         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1319                 /mnt/$FSNAME
1320
1321         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1322         stopall
1323
1324         mkdir $tmp/img
1325
1326         setupall
1327         pushd /mnt/$FSNAME
1328         ls -Rni --time-style=+%s >$tmp/img/list
1329         find . ! -name .lustre -type f -exec sha1sum {} \; |
1330                 sort -k 2 >$tmp/img/sha1sums
1331         popd
1332         $LCTL get_param -n version | head -n 1 |
1333                 sed -e 's/^lustre: *//' >$tmp/img/commit
1334
1335         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1336                 $LFS quotaon -ug /mnt/$FSNAME
1337         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1338         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1339                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1340                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1341                 | tr -d "*" > $tmp/img/bspace
1342         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1343                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1344                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1345                 | tr -d "*" > $tmp/img/ispace
1346
1347         stopall
1348
1349         pushd $tmp/src
1350         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1351         popd
1352
1353         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1354                 echo "Data verification failed"
1355         fi
1356
1357         uname -r >$tmp/img/kernel
1358         uname -m >$tmp/img/arch
1359
1360         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1361         mv $OSTDEV1 $tmp/img
1362
1363         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1364                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1365         dst=$(cd $dst; pwd)
1366         pushd $tmp/img
1367         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1368         popd
1369
1370         rm -r $tmp
1371 }
1372 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1373
1374 #
1375 # The list of applicable tarballs is returned via the caller's
1376 # variable "tarballs".
1377 #
1378 t32_check() {
1379         local node=$(facet_active_host $SINGLEMDS)
1380         local r="do_node $node"
1381
1382         if [ "$CLIENTONLY" ]; then
1383                 skip "Client-only testing"
1384                 exit 0
1385         fi
1386
1387         if ! $r which $TUNEFS; then
1388                 skip_env "tunefs.lustre required on $node"
1389                 exit 0
1390         fi
1391
1392         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1393
1394         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1395
1396         if [ -z "$tarballs" ]; then
1397                 skip "No applicable tarballs found"
1398                 exit 0
1399         fi
1400 }
1401
1402 t32_test_cleanup() {
1403         local tmp=$TMP/t32
1404         local fstype=$(facet_fstype $SINGLEMDS)
1405         local rc=$?
1406
1407         if $shall_cleanup_lustre; then
1408                 umount $tmp/mnt/lustre || rc=$?
1409         fi
1410         if $shall_cleanup_mdt; then
1411                 $r umount -d $tmp/mnt/mdt || rc=$?
1412         fi
1413         if $shall_cleanup_mdt1; then
1414                 $r umount -d $tmp/mnt/mdt1 || rc=$?
1415         fi
1416         if $shall_cleanup_ost; then
1417                 $r umount -d $tmp/mnt/ost || rc=$?
1418         fi
1419
1420         $r rm -rf $tmp
1421         rm -rf $tmp
1422         if [ $fstype == "zfs" ]; then
1423                 $r $ZPOOL destroy t32fs-mdt1 || rc=$?
1424                 $r $ZPOOL destroy t32fs-ost1 || rc=$?
1425         fi
1426         return $rc
1427 }
1428
1429 t32_bits_per_long() {
1430         #
1431         # Yes, this is not meant to be perfect.
1432         #
1433         case $1 in
1434                 ppc64|x86_64)
1435                         echo -n 64;;
1436                 i*86)
1437                         echo -n 32;;
1438         esac
1439 }
1440
1441 t32_reload_modules() {
1442         local node=$1
1443         local all_removed=false
1444         local i=0
1445
1446         while ((i < 20)); do
1447                 echo "Unloading modules on $node: Attempt $i"
1448                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1449                         all_removed=true
1450                 do_rpc_nodes $node check_mem_leak || return 1
1451                 if $all_removed; then
1452                         do_rpc_nodes $node load_modules
1453                         return 0
1454                 fi
1455                 sleep 5
1456                 i=$((i + 1))
1457         done
1458         echo "Unloading modules on $node: Given up"
1459         return 1
1460 }
1461
1462 t32_wait_til_devices_gone() {
1463         local node=$1
1464         local devices
1465         local loops
1466         local i=0
1467
1468         echo wait for devices to go
1469         while ((i < 20)); do
1470                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1471                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1472                 ((devices == 0 && loops == 0)) && return 0
1473                 sleep 5
1474                 i=$((i + 1))
1475         done
1476         echo "waiting for dev on $node: dev $devices loop $loops given up"
1477         do_rpc_nodes $node "losetup -a"
1478         do_rpc_nodes $node "$LCTL devices_list"
1479         return 1
1480 }
1481
1482 t32_verify_quota() {
1483         local node=$1
1484         local fsname=$2
1485         local mnt=$3
1486         local fstype=$(facet_fstype $SINGLEMDS)
1487         local qval
1488         local cmd
1489
1490         $LFS quota -u $T32_QID -v $mnt
1491
1492         qval=$($LFS quota -v -u $T32_QID $mnt |
1493                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1494                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1495                 | tr -d "*")
1496         [ $qval -eq $img_bspace ] || {
1497                 echo "bspace, act:$qval, exp:$img_bspace"
1498                 return 1
1499         }
1500
1501         qval=$($LFS quota -v -u $T32_QID $mnt |
1502                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1503                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1504                 | tr -d "*")
1505         [ $qval -eq $img_ispace ] || {
1506                 echo "ispace, act:$qval, exp:$img_ispace"
1507                 return 1
1508         }
1509
1510         qval=$($LFS quota -v -u $T32_QID $mnt |
1511                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1512                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1513                 | tr -d "*")
1514         [ $qval -eq $T32_BLIMIT ] || {
1515                 echo "blimit, act:$qval, exp:$T32_BLIMIT"
1516                 return 1
1517         }
1518
1519         qval=$($LFS quota -v -u $T32_QID $mnt |
1520                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1521                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1522                 | tr -d "*")
1523         [ $qval -eq $T32_ILIMIT ] || {
1524                 echo "ilimit, act:$qval, exp:$T32_ILIMIT"
1525                 return 1
1526         }
1527
1528         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1529         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1530         cmd=$cmd.quota_slave.enabled
1531         wait_update $node "$cmd" "ug" || {
1532                 echo "Enable mdt quota failed"
1533                 return 1
1534         }
1535
1536         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1537         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1538         cmd=$cmd.quota_slave.enabled
1539         wait_update $node "$cmd" "ug" || {
1540                 echo "Enable ost quota failed"
1541                 return 1
1542         }
1543
1544         chmod 0777 $mnt
1545         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1546                 bs=1M count=$(($T32_BLIMIT / 1024)) oflag=sync && {
1547                 echo "Write succeed, but expect -EDQUOT"
1548                 return 1
1549         }
1550         rm -f $mnt/t32_qf_new
1551
1552         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1553                 $T32_ILIMIT && {
1554                 echo "Create succeed, but expect -EDQUOT"
1555                 return 1
1556         }
1557         unlinkmany $mnt/t32_qf_ $T32_ILIMIT
1558
1559         return 0
1560 }
1561
1562 t32_test() {
1563         local tarball=$1
1564         local writeconf=$2
1565         local dne_upgrade=${dne_upgrade:-"no"}
1566         local ff_convert=${ff_convert:-"no"}
1567         local shall_cleanup_mdt=false
1568         local shall_cleanup_mdt1=false
1569         local shall_cleanup_ost=false
1570         local shall_cleanup_lustre=false
1571         local node=$(facet_active_host $SINGLEMDS)
1572         local r="do_node $node"
1573         local node2=$(facet_active_host mds2)
1574         local tmp=$TMP/t32
1575         local img_commit
1576         local img_kernel
1577         local img_arch
1578         local img_bspace
1579         local img_ispace
1580         local fsname=t32fs
1581         local nid=$($r $LCTL list_nids | head -1)
1582         local mopts
1583         local uuid
1584         local nrpcs_orig
1585         local nrpcs
1586         local list
1587         local fstype=$(facet_fstype $SINGLEMDS)
1588         local mdt_dev=$tmp/mdt
1589         local ost_dev=$tmp/ost
1590
1591         trap 'trap - RETURN; t32_test_cleanup' RETURN
1592
1593         mkdir -p $tmp/mnt/lustre
1594         $r mkdir -p $tmp/mnt/{mdt,ost}
1595         $r tar xjvf $tarball -S -C $tmp || {
1596                 error_noexit "Unpacking the disk image tarball"
1597                 return 1
1598         }
1599         img_commit=$($r cat $tmp/commit)
1600         img_kernel=$($r cat $tmp/kernel)
1601         img_arch=$($r cat $tmp/arch)
1602         img_bspace=$($r cat $tmp/bspace)
1603         img_ispace=$($r cat $tmp/ispace)
1604         echo "Upgrading from $(basename $tarball), created with:"
1605         echo "  Commit: $img_commit"
1606         echo "  Kernel: $img_kernel"
1607         echo "    Arch: $img_arch"
1608         echo "OST version: $(get_lustre_version ost1)"
1609
1610         # The convertion can be made only when both of the following
1611         # conditions are satisfied:
1612         # - ost device img version < 2.3.64
1613         # - ost server version >= 2.5
1614         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
1615                 $(lustre_version_code ost1) -lt $(version_code 2.5.0) ] &&
1616                         ff_convert="no"
1617
1618         if [ $fstype == "zfs" ]; then
1619                 # import pool first
1620                 $r $ZPOOL import -f -d $tmp t32fs-mdt1
1621                 $r $ZPOOL import -f -d $tmp t32fs-ost1
1622                 mdt_dev=t32fs-mdt1/mdt1
1623                 ost_dev=t32fs-ost1/ost1
1624                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1625                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1626                                 error_noexit "import zfs pool failed"
1627                                 return 1
1628                         }
1629         fi
1630
1631         $r $LCTL set_param debug="$PTLDEBUG"
1632
1633         $r $TUNEFS --dryrun $mdt_dev || {
1634                 $r losetup -a
1635                 error_noexit "tunefs.lustre before mounting the MDT"
1636                 return 1
1637         }
1638         if [ "$writeconf" ]; then
1639                 mopts=writeconf
1640                 if [ $fstype == "ldiskfs" ]; then
1641                         mopts="loop,$mopts"
1642                         $r $TUNEFS --quota $mdt_dev || {
1643                                 $r losetup -a
1644                                 error_noexit "Enable mdt quota feature"
1645                                 return 1
1646                         }
1647                 fi
1648         else
1649                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1650                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1651                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1652                                 "(Need MGS version at least 2.3.59)"; return 0; }
1653
1654                         local osthost=$(facet_active_host ost1)
1655                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1656
1657                         mopts=nosvc
1658                         if [ $fstype == "ldiskfs" ]; then
1659                                 mopts="loop,$mopts"
1660                         fi
1661                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1662                         $r lctl replace_nids $fsname-OST0000 $ostnid
1663                         $r lctl replace_nids $fsname-MDT0000 $nid
1664                         $r umount -d $tmp/mnt/mdt
1665                 fi
1666
1667                 mopts=exclude=$fsname-OST0000
1668                 if [ $fstype == "ldiskfs" ]; then
1669                         mopts="loop,$mopts"
1670                 fi
1671         fi
1672
1673         t32_wait_til_devices_gone $node
1674
1675         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1676                 $r losetup -a
1677                 error_noexit "Mounting the MDT"
1678                 return 1
1679         }
1680         shall_cleanup_mdt=true
1681
1682         if [ "$dne_upgrade" != "no" ]; then
1683                 local fs2mdsdev=$(mdsdevname 1_2)
1684                 local fs2mdsvdev=$(mdsvdevname 1_2)
1685
1686                 echo "mkfs new MDT on ${fs2mdsdev}...."
1687                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1688                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1689                 fi
1690
1691                 add fs2mds $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1692                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1693                         error_noexit "Mkfs new MDT failed"
1694                         return 1
1695                 }
1696
1697                 $r $TUNEFS --dryrun $fs2mdsdev || {
1698                         error_noexit "tunefs.lustre before mounting the MDT"
1699                         return 1
1700                 }
1701
1702                 echo "mount new MDT....$fs2mdsdev"
1703                 $r mkdir -p $tmp/mnt/mdt1
1704                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1705                         error_noexit "mount mdt1 failed"
1706                         return 1
1707                 }
1708
1709                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1710                         error_noexit "enable remote dir create failed"
1711
1712                 shall_cleanup_mdt1=true
1713         fi
1714
1715         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1716                 error_noexit "Getting MDT UUID"
1717                 return 1
1718         }
1719         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1720                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1721                 return 1
1722         fi
1723
1724         $r $TUNEFS --dryrun $ost_dev || {
1725                 error_noexit "tunefs.lustre before mounting the OST"
1726                 return 1
1727         }
1728         if [ "$writeconf" ]; then
1729                 mopts=mgsnode=$nid,$writeconf
1730                 if [ $fstype == "ldiskfs" ]; then
1731                         mopts="loop,$mopts"
1732                         $r $TUNEFS --quota $ost_dev || {
1733                                 $r losetup -a
1734                                 error_noexit "Enable ost quota feature"
1735                                 return 1
1736                         }
1737                 fi
1738         else
1739                 mopts=mgsnode=$nid
1740                 if [ $fstype == "ldiskfs" ]; then
1741                         mopts="loop,$mopts"
1742                 fi
1743         fi
1744         $r $MOUNT_CMD -o $mopts $ost_dev $tmp/mnt/ost || {
1745                 error_noexit "Mounting the OST"
1746                 return 1
1747         }
1748         shall_cleanup_ost=true
1749
1750         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1751                 error_noexit "Getting OST UUID"
1752                 return 1
1753         }
1754         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1755                 error_noexit "Unexpected OST UUID: \"$uuid\""
1756                 return 1
1757         fi
1758
1759         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1760                 error_noexit "Setting \"max_dirty_mb\""
1761                 return 1
1762         }
1763         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1764                 error_noexit "Setting OST \"failover.node\""
1765                 return 1
1766         }
1767         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1768                 error_noexit "Setting \"max_rpcs_in_flight\""
1769                 return 1
1770         }
1771         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1772                 error_noexit "Setting MDT \"failover.node\""
1773                 return 1
1774         }
1775         $r $LCTL pool_new $fsname.interop || {
1776                 error_noexit "Setting \"interop\""
1777                 return 1
1778         }
1779         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1780                 error_noexit "Setting \"lov.stripesize\""
1781                 return 1
1782         }
1783
1784         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1785                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1786                         error_noexit "Start OI scrub on OST0"
1787                         return 1
1788                 }
1789
1790                 # The oi_scrub should be on ost1, but for test_32(),
1791                 # all on the SINGLEMDS.
1792                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1793                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1794                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1795                         error_noexit "Failed to get the expected 'completed'"
1796                         return 1
1797                 }
1798
1799                 local UPDATED=$($r $LCTL get_param -n \
1800                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
1801                                 awk '/^updated/ { print $2 }')
1802                 [ $UPDATED -ge 1 ] || {
1803                         error_noexit "Only $UPDATED objects have been converted"
1804                         return 1
1805                 }
1806         fi
1807
1808         if [ "$dne_upgrade" != "no" ]; then
1809                 $r $LCTL conf_param \
1810                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
1811                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1812                         return 1
1813                 }
1814                 $r $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
1815                         error_noexit "Setting MDT1 \"failover.node\""
1816                         return 1
1817                 }
1818                 $r $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
1819                         error_noexit "Setting MDT1 \"lov.stripesize\""
1820                         return 1
1821                 }
1822
1823         fi
1824
1825         if [ "$writeconf" ]; then
1826                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
1827                         error_noexit "Mounting the client"
1828                         return 1
1829                 }
1830                 shall_cleanup_lustre=true
1831                 $LCTL set_param debug="$PTLDEBUG"
1832
1833                 t32_verify_quota $node $fsname $tmp/mnt/lustre || {
1834                         error_noexit "verify quota failed"
1835                         return 1
1836                 }
1837
1838                 if [ "$dne_upgrade" != "no" ]; then
1839                         $LFS mkdir -i 1 $tmp/mnt/lustre/remote_dir || {
1840                                 error_noexit "set remote dir failed"
1841                                 return 1
1842                         }
1843
1844                         pushd $tmp/mnt/lustre
1845                         tar -cf - . --exclude=./remote_dir |
1846                                 tar -xvf - -C remote_dir 1>/dev/null || {
1847                                 error_noexit "cp to remote dir failed"
1848                                 return 1
1849                         }
1850                         popd
1851                 fi
1852
1853                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
1854                         error_noexit "dd failed"
1855                         return 1
1856                 }
1857                 rm -rf $tmp/mnt/lustre/tmp_file || {
1858                         error_noexit "rm failed"
1859                         return 1
1860                 }
1861
1862                 if $r test -f $tmp/sha1sums; then
1863                         # LU-2393 - do both sorts on same node to ensure locale
1864                         # is identical
1865                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
1866                         if [ "$dne_upgrade" != "no" ]; then
1867                                 pushd $tmp/mnt/lustre/remote_dir
1868                         else
1869                                 pushd $tmp/mnt/lustre
1870                         fi
1871
1872                         find ! -name .lustre -type f -exec sha1sum {} \; |
1873                                 sort -k 2 >$tmp/sha1sums || {
1874                                 error_noexit "sha1sum"
1875                                 return 1
1876                         }
1877                         popd
1878                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1879                                 error_noexit "sha1sum verification failed"
1880                                 return 1
1881                         fi
1882                 else
1883                         echo "sha1sum verification skipped"
1884                 fi
1885
1886                 if [ "$dne_upgrade" != "no" ]; then
1887                         rm -rf $tmp/mnt/lustre/remote_dir || {
1888                                 error_noexit "remove remote dir failed"
1889                                 return 1
1890                         }
1891                 fi
1892
1893                 if $r test -f $tmp/list; then
1894                         #
1895                         # There is not a Test Framework API to copy files to or
1896                         # from a remote node.
1897                         #
1898                         # LU-2393 - do both sorts on same node to ensure locale
1899                         # is identical
1900                         $r cat $tmp/list | sort -k 6 >$tmp/list.orig
1901                         pushd $tmp/mnt/lustre
1902                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1903                                 error_noexit "ls"
1904                                 return 1
1905                         }
1906                         popd
1907                         #
1908                         # 32-bit and 64-bit clients use different algorithms to
1909                         # convert FIDs into inode numbers.  Hence, remove the inode
1910                         # numbers from the lists, if the original list was created
1911                         # on an architecture with different number of bits per
1912                         # "long".
1913                         #
1914                         if [ $(t32_bits_per_long $(uname -m)) != \
1915                                 $(t32_bits_per_long $img_arch) ]; then
1916                                 echo "Different number of bits per \"long\" from the disk image"
1917                                 for list in list.orig list; do
1918                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1919                                 done
1920                         fi
1921                         if ! diff -ub $tmp/list.orig $tmp/list; then
1922                                 error_noexit "list verification failed"
1923                                 return 1
1924                         fi
1925                 else
1926                         echo "list verification skipped"
1927                 fi
1928
1929                 #
1930                 # When adding new data verification tests, please check for
1931                 # the presence of the required reference files first, like
1932                 # the "sha1sums" and "list" tests above, to avoid the need to
1933                 # regenerate every image for each test addition.
1934                 #
1935
1936                 nrpcs_orig=$($LCTL get_param \
1937                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
1938                         error_noexit "Getting \"max_rpcs_in_flight\""
1939                         return 1
1940                 }
1941                 nrpcs=$((nrpcs_orig + 5))
1942                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
1943                         error_noexit "Changing \"max_rpcs_in_flight\""
1944                         return 1
1945                 }
1946                 wait_update $HOSTNAME "$LCTL get_param \
1947                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
1948                         error_noexit "Verifying \"max_rpcs_in_flight\""
1949                         return 1
1950                 }
1951
1952                 umount $tmp/mnt/lustre || {
1953                         error_noexit "Unmounting the client"
1954                         return 1
1955                 }
1956                 shall_cleanup_lustre=false
1957         else
1958                 if [ "$dne_upgrade" != "no" ]; then
1959                         $r umount -d $tmp/mnt/mdt1 || {
1960                                 error_noexit "Unmounting the MDT2"
1961                                 return 1
1962                         }
1963                         shall_cleanup_mdt1=false
1964                 fi
1965
1966                 $r umount -d $tmp/mnt/mdt || {
1967                         error_noexit "Unmounting the MDT"
1968                         return 1
1969                 }
1970                 shall_cleanup_mdt=false
1971
1972                 $r umount -d $tmp/mnt/ost || {
1973                         error_noexit "Unmounting the OST"
1974                         return 1
1975                 }
1976                 shall_cleanup_ost=false
1977
1978                 t32_reload_modules $node || {
1979                         error_noexit "Reloading modules"
1980                         return 1
1981                 }
1982
1983                 # mount a second time to make sure we didnt leave upgrade flag on
1984                 $r $TUNEFS --dryrun $mdt_dev || {
1985                         $r losetup -a
1986                         error_noexit "tunefs.lustre before remounting the MDT"
1987                         return 1
1988                 }
1989
1990                 mopts=exclude=$fsname-OST0000
1991                 if [ $fstype == "ldiskfs" ]; then
1992                         mopts="loop,$mopts"
1993                 fi
1994                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1995                         error_noexit "Remounting the MDT"
1996                         return 1
1997                 }
1998                 shall_cleanup_mdt=true
1999         fi
2000 }
2001
2002 test_32a() {
2003         local tarballs
2004         local tarball
2005         local rc=0
2006
2007         t32_check
2008         for tarball in $tarballs; do
2009                 t32_test $tarball || let "rc += $?"
2010         done
2011         return $rc
2012 }
2013 run_test 32a "Upgrade (not live)"
2014
2015 test_32b() {
2016         local tarballs
2017         local tarball
2018         local rc=0
2019
2020         t32_check
2021         for tarball in $tarballs; do
2022                 t32_test $tarball writeconf || let "rc += $?"
2023         done
2024         return $rc
2025 }
2026 run_test 32b "Upgrade with writeconf"
2027
2028 test_32c() {
2029         local tarballs
2030         local tarball
2031         local rc=0
2032
2033         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2034         t32_check
2035         for tarball in $tarballs; do
2036                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2037         done
2038         return $rc
2039 }
2040 run_test 32c "dne upgrade test"
2041
2042 test_32d() {
2043         local tarballs
2044         local tarball
2045         local rc=0
2046
2047         t32_check
2048         for tarball in $tarballs; do
2049                 ff_convert=yes t32_test $tarball || rc=$?
2050         done
2051         return $rc
2052 }
2053 run_test 32d "convert ff test"
2054
2055 test_33a() { # bug 12333, was test_33
2056         local rc=0
2057         local FSNAME2=test-123
2058         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2059         local mkfsoptions
2060
2061         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
2062
2063         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
2064                 local dev=${SINGLEMDS}_dev
2065                 local MDSDEV=${!dev}
2066                 is_blkdev $SINGLEMDS $MDSDEV && \
2067                 skip_env "mixed loopback and real device not working" && return
2068         fi
2069
2070         local fs2mdsdev=$(mdsdevname 1_2)
2071         local fs2ostdev=$(ostdevname 1_2)
2072         local fs2mdsvdev=$(mdsvdevname 1_2)
2073         local fs2ostvdev=$(ostvdevname 1_2)
2074
2075         if [ $(facet_fstype mds1) == ldiskfs ]; then
2076                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
2077         fi
2078
2079         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2080                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
2081         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2082                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
2083                 $fs2ostvdev || exit 10
2084
2085         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
2086         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2087         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" || rc=1
2088         mkdir -p $MOUNT2
2089         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || rc=2
2090         echo "ok."
2091
2092         cp /etc/hosts $MOUNT2/ || rc=3
2093         $LFS getstripe $MOUNT2/hosts
2094
2095         umount -d $MOUNT2
2096         stop fs2ost -f
2097         stop fs2mds -f
2098         cleanup_nocli || rc=6
2099         return $rc
2100 }
2101 run_test 33a "Mount ost with a large index number"
2102
2103 test_33b() {    # was test_34
2104         setup
2105
2106         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
2107         # Drop lock cancelation reply during umount
2108         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
2109         do_facet client lctl set_param fail_loc=0x80000304
2110         #lctl set_param debug=-1
2111         umount_client $MOUNT
2112         cleanup
2113 }
2114 run_test 33b "Drop cancel during umount"
2115
2116 test_34a() {
2117         setup
2118         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2119         manual_umount_client
2120         rc=$?
2121         do_facet client killall -USR1 multiop
2122         if [ $rc -eq 0 ]; then
2123                 error "umount not fail!"
2124         fi
2125         sleep 1
2126         cleanup
2127 }
2128 run_test 34a "umount with opened file should be fail"
2129
2130
2131 test_34b() {
2132         setup
2133         touch $DIR/$tfile || return 1
2134         stop_mds --force || return 2
2135
2136         manual_umount_client --force
2137         rc=$?
2138         if [ $rc -ne 0 ]; then
2139                 error "mtab after failed umount - rc $rc"
2140         fi
2141
2142         cleanup
2143         return 0
2144 }
2145 run_test 34b "force umount with failed mds should be normal"
2146
2147 test_34c() {
2148         setup
2149         touch $DIR/$tfile || return 1
2150         stop_ost --force || return 2
2151
2152         manual_umount_client --force
2153         rc=$?
2154         if [ $rc -ne 0 ]; then
2155                 error "mtab after failed umount - rc $rc"
2156         fi
2157
2158         cleanup
2159         return 0
2160 }
2161 run_test 34c "force umount with failed ost should be normal"
2162
2163 test_35a() { # bug 12459
2164         setup
2165
2166         DBG_SAVE="`lctl get_param -n debug`"
2167         lctl set_param debug="ha"
2168
2169         log "Set up a fake failnode for the MDS"
2170         FAKENID="127.0.0.2"
2171         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
2172                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2173         do_facet mgs "$LCTL conf_param \
2174                 ${device}.failover.node=$(h2$NETTYPE $FAKENID)" || return 4
2175
2176         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2177         sleep 10
2178
2179         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2180         $LCTL clear
2181         log "$MSG"
2182         log "Stopping the MDT: $device"
2183         stop_mdt 1 || return 5
2184
2185         df $MOUNT > /dev/null 2>&1 &
2186         DFPID=$!
2187         log "Restarting the MDT: $device"
2188         start_mdt 1 || return 6
2189         log "Wait for df ($DFPID) ... "
2190         wait $DFPID
2191         log "done"
2192         lctl set_param debug="$DBG_SAVE"
2193
2194         # retrieve from the log the first server that the client tried to
2195         # contact after the connection loss
2196         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2197         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2198                        /import_select_connection.*$device-mdc.* using connection/ {
2199                                 if (start) {
2200                                         if (\\\$NF ~ /$FAKENID/)
2201                                                 print \\\$NF;
2202                                         else
2203                                                 print 0;
2204                                         exit;
2205                                 }
2206                        }" $TMP/lustre-log-$TESTNAME.log`
2207         [ "$NEXTCONN" != "0" ] && log "The client didn't try to reconnect to the last active server (tried ${NEXTCONN} instead)" && return 7
2208         cleanup
2209         # remove nid settings
2210         writeconf_or_reformat
2211 }
2212 run_test 35a "Reconnect to the last active server first"
2213
2214 test_35b() { # bug 18674
2215         remote_mds || { skip "local MDS" && return 0; }
2216         setup
2217
2218         debugsave
2219         $LCTL set_param debug="ha"
2220         $LCTL clear
2221         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2222         log "$MSG"
2223
2224         log "Set up a fake failnode for the MDS"
2225         FAKENID="127.0.0.2"
2226         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2227                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2228         do_facet mgs "$LCTL conf_param \
2229                 ${device}.failover.node=$(h2$NETTYPE $FAKENID)" || return 1
2230
2231         local at_max_saved=0
2232         # adaptive timeouts may prevent seeing the issue
2233         if at_is_enabled; then
2234                 at_max_saved=$(at_max_get mds)
2235                 at_max_set 0 mds client
2236         fi
2237
2238         mkdir -p $MOUNT/$tdir
2239
2240         log "Injecting EBUSY on MDS"
2241         # Setting OBD_FAIL_MDS_RESEND=0x136
2242         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" || return 2
2243
2244         $LCTL set_param mdc.${FSNAME}*.stats=clear
2245
2246         log "Creating a test file and stat it"
2247         touch $MOUNT/$tdir/$tfile
2248         stat $MOUNT/$tdir/$tfile
2249
2250         log "Stop injecting EBUSY on MDS"
2251         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" || return 3
2252         rm -f $MOUNT/$tdir/$tfile
2253
2254         log "done"
2255         # restore adaptive timeout
2256         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2257
2258         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2259
2260         CONNCNT=`$LCTL get_param mdc.${FSNAME}*.stats | awk '/mds_connect/{print $2}'`
2261
2262         # retrieve from the log if the client has ever tried to
2263         # contact the fake server after the loss of connection
2264         FAILCONN=`awk "BEGIN {ret = 0;}
2265                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2266                                 ret = 1;
2267                                 if (\\\$NF ~ /$FAKENID/) {
2268                                         ret = 2;
2269                                         exit;
2270                                 }
2271                        }
2272                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2273
2274         [ "$FAILCONN" == "0" ] && \
2275                 log "ERROR: The client reconnection has not been triggered" && \
2276                 return 4
2277         [ "$FAILCONN" == "2" ] && \
2278                 log "ERROR: The client tried to reconnect to the failover server while the primary was busy" && \
2279                 return 5
2280
2281         # LU-290
2282         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2283         # Reconnects are supposed to be rate limited to one every 5s
2284         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] && \
2285                 log "ERROR: Too many reconnects $CONNCNT" && \
2286                 return 6
2287
2288         cleanup
2289         # remove nid settings
2290         writeconf_or_reformat
2291 }
2292 run_test 35b "Continue reconnection retries, if the active server is busy"
2293
2294 test_36() { # 12743
2295         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
2296
2297         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] || \
2298                 { skip "remote OST" && return 0; }
2299
2300         local rc=0
2301         local FSNAME2=test1234
2302         local fs3ost_HOST=$ost_HOST
2303         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2304
2305         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2306
2307         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2308                 is_blkdev $SINGLEMDS $MDSDEV && \
2309                 skip_env "mixed loopback and real device not working" && return
2310         fi
2311
2312         local fs2mdsdev=$(mdsdevname 1_2)
2313         local fs2ostdev=$(ostdevname 1_2)
2314         local fs3ostdev=$(ostdevname 2_2)
2315         local fs2mdsvdev=$(mdsvdevname 1_2)
2316         local fs2ostvdev=$(ostvdevname 1_2)
2317         local fs3ostvdev=$(ostvdevname 2_2)
2318
2319         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2320                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2321         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2322         #     different one than the default value here.
2323         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2324                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2325         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
2326                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2327
2328         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2329         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2330         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2331         mkdir -p $MOUNT2
2332         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || return 1
2333
2334         sleep 5 # until 11778 fixed
2335
2336         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || return 2
2337
2338         BKTOTAL=`lctl get_param -n obdfilter.*.kbytestotal | awk 'BEGIN{total=0}; {total+=$1}; END{print total}'`
2339         BKFREE=`lctl get_param -n obdfilter.*.kbytesfree | awk 'BEGIN{free=0}; {free+=$1}; END{print free}'`
2340         BKAVAIL=`lctl get_param -n obdfilter.*.kbytesavail | awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}'`
2341         STRING=`df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}'`
2342         DFTOTAL=`echo $STRING | cut -d, -f1`
2343         DFUSED=`echo $STRING  | cut -d, -f2`
2344         DFAVAIL=`echo $STRING | cut -d, -f3`
2345         DFFREE=$(($DFTOTAL - $DFUSED))
2346
2347         ALLOWANCE=$((64 * $OSTCOUNT))
2348
2349         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2350            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2351                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2352                 rc=1
2353         fi
2354         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2355            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2356                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2357                 rc=2
2358         fi
2359         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2360            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2361                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2362                 rc=3
2363        fi
2364
2365         umount -d $MOUNT2
2366         stop fs3ost -f || return 200
2367         stop fs2ost -f || return 201
2368         stop fs2mds -f || return 202
2369         unload_modules_conf || return 203
2370         return $rc
2371 }
2372 run_test 36 "df report consistency on OSTs with different block size"
2373
2374 test_37() {
2375         local mntpt=$(facet_mntpt $SINGLEMDS)
2376         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2377         local mdsdev_sym="$TMP/sym_mdt.img"
2378         local opts=$MDS_MOUNT_OPTS
2379         local rc=0
2380
2381         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2382                 skip "Currently only applicable to ldiskfs-based MDTs"
2383                 return
2384         fi
2385
2386         echo "MDS :     $mdsdev"
2387         echo "SYMLINK : $mdsdev_sym"
2388         do_facet $SINGLEMDS rm -f $mdsdev_sym
2389
2390         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2391
2392         echo "mount symlink device - $mdsdev_sym"
2393
2394         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2395                 opts=$(csa_add "$opts" -o loop)
2396         fi
2397         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2398                 $mdsdev_sym $mntpt 2>&1)
2399         rc=${PIPESTATUS[0]}
2400
2401         echo mount_op=$mount_op
2402
2403         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
2404
2405         if $(echo $mount_op | grep -q "unable to set tunable"); then
2406                 error "set tunables failed for symlink device"
2407         fi
2408
2409         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2410
2411         return 0
2412 }
2413 run_test 37 "verify set tunables works for symlink device"
2414
2415 test_38() { # bug 14222
2416         local fstype=$(facet_fstype $SINGLEMDS)
2417         local mntpt=$(facet_mntpt $SINGLEMDS)
2418
2419         setup
2420         # like runtests
2421         local COUNT=10
2422         local SRC="/etc /bin"
2423         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
2424         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2425         mkdir -p $DIR/$tdir
2426         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
2427                 error "copying $SRC to $DIR/$tdir"
2428         sync
2429         umount_client $MOUNT
2430         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2431         stop_mds
2432         log "delete lov_objid file on MDS"
2433
2434         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
2435
2436         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
2437
2438         unmount_fstype $SINGLEMDS || error "umount failed (1)"
2439
2440         # check create in mds_lov_connect
2441         start_mds
2442         mount_client $MOUNT
2443         for f in $FILES; do
2444                 [ $V ] && log "verifying $DIR/$tdir/$f"
2445                 diff -q $f $DIR/$tdir/$f || ERROR=y
2446         done
2447         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2448         if [ "$ERROR" = "y" ]; then
2449                 # check it's updates in sync
2450                 umount_client $MOUNT
2451                 stop_mds
2452                 mount_fstype $SIGNLEMDS
2453                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2454                 unmount_fstype $SINGLEMDS
2455                 error "old and new files are different after connect" || true
2456         fi
2457         touch $DIR/$tdir/f2 || error "f2 file create failed"
2458
2459         # check it's updates in sync
2460         umount_client $MOUNT
2461         stop_mds
2462
2463         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
2464
2465         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2466         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
2467
2468         unmount_fstype $SINGLEMDS || error "umount failed (3)"
2469
2470         start_mds
2471         mount_client $MOUNT
2472         for f in $FILES; do
2473                 [ $V ] && log "verifying $DIR/$tdir/$f"
2474                 diff -q $f $DIR/$tdir/$f || ERROR=y
2475         done
2476         touch $DIR/$tdir/f3 || error "f3 file create failed"
2477         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2478         umount_client $MOUNT
2479         stop_mds
2480         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
2481         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2482         unmount_fstype $SINGLEMDS || error "umount failed (4)"
2483
2484         [ "$ERROR" = "y" ] &&
2485                 error "old and new files are different after sync" || true
2486
2487         log "files compared the same"
2488         cleanup
2489 }
2490 run_test 38 "MDS recreates missing lov_objid file from OST data"
2491
2492 test_39() {
2493         PTLDEBUG=+malloc
2494         setup
2495         cleanup
2496         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2497                 error "memory leak detected" || true
2498 }
2499 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2500
2501 test_40() { # bug 15759
2502         start_ost
2503         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2504         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2505         start_mds
2506         cleanup
2507 }
2508 run_test 40 "race during service thread startup"
2509
2510 test_41a() { #bug 14134
2511         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2512            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2513                 skip "Loop devices does not work with nosvc option"
2514                 return
2515         fi
2516
2517         local rc
2518         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2519
2520         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2521         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2522         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2523         mkdir -p $MOUNT
2524         mount_client $MOUNT || return 1
2525         sleep 5
2526
2527         echo "blah blah" > $MOUNT/$tfile
2528         cat $MOUNT/$tfile
2529
2530         umount_client $MOUNT
2531         stop ost1 -f || return 201
2532         stop_mds -f || return 202
2533         stop_mds -f || return 203
2534         unload_modules_conf || return 204
2535         return $rc
2536 }
2537 run_test 41a "mount mds with --nosvc and --nomgs"
2538
2539 test_41b() {
2540         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2541            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2542                 skip "Loop devices does not work with nosvc option"
2543                 return
2544         fi
2545
2546         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2547
2548         stopall
2549         reformat
2550         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2551
2552         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2553         start_ost
2554         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2555         mkdir -p $MOUNT
2556         mount_client $MOUNT || return 1
2557         sleep 5
2558
2559         echo "blah blah" > $MOUNT/$tfile
2560         cat $MOUNT/$tfile || return 200
2561
2562         umount_client $MOUNT
2563         stop_ost || return 201
2564         stop_mds -f || return 202
2565         stop_mds -f || return 203
2566
2567 }
2568 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2569
2570 test_41c() {
2571         local server_version=$(lustre_version_code $SINGLEMDS)
2572
2573         [[ $server_version -ge $(version_code 2.6.52) ]] ||
2574         [[ $server_version -ge $(version_code 2.5.26) &&
2575            $server_version -lt $(version_code 2.5.50) ]] ||
2576         [[ $server_version -ge $(version_code 2.5.4) &&
2577            $server_version -lt $(version_code 2.5.11) ]] ||
2578                 { skip "Need MDS version 2.5.4+ or 2.5.26+ or 2.6.52+"; return; }
2579
2580         cleanup
2581         # MDT concurent start
2582         #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
2583         do_facet $SINGLEMDS "lctl set_param fail_loc=0x703"
2584         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
2585         local pid=$!
2586         sleep 2
2587         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
2588         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
2589         local pid2=$!
2590         wait $pid2
2591         local rc2=$?
2592         wait $pid
2593         local rc=$?
2594         if [ $rc == 0 ] && [ $rc2 == 114 ]; then
2595                 echo "1st MDT start succeed"
2596                 echo "2nd MDT start failed with EALREADY"
2597         elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
2598                 echo "1st MDT start failed with EALREADY"
2599                 echo "2nd MDT start succeed"
2600         else
2601                 stop mds1 -f
2602                 error "unexpected concurent MDT mounts result, rc=$rc rc2=$rc2"
2603         fi
2604
2605         # OST concurent start
2606         #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
2607         do_facet ost1 "lctl set_param fail_loc=0x703"
2608         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
2609         pid=$!
2610         sleep 2
2611         do_facet ost1 "lctl set_param fail_loc=0x0"
2612         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
2613         pid2=$!
2614         wait $pid2
2615         rc2=$?
2616         wait $pid
2617         rc=$?
2618         if [ $rc == 0 ] && [ $rc2 == 114 ]; then
2619                 echo "1st OST start succeed"
2620                 echo "2nd OST start failed with EALREADY"
2621         elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
2622                 echo "1st OST start failed with EALREADY"
2623                 echo "2nd OST start succeed"
2624         else
2625                 stop mds1 -f
2626                 stop ost1 -f
2627                 error "unexpected concurent OST mounts result, rc=$rc rc2=$rc2"
2628         fi
2629         # cleanup
2630         stop mds1 -f
2631         stop ost1 -f
2632
2633         # verify everything ok
2634         start_mds
2635         if [ $? != 0 ]
2636         then
2637                 stop mds1 -f
2638                 error "MDT(s) start failed"
2639         fi
2640
2641         start_ost
2642         if [ $? != 0 ]
2643         then
2644                 stop mds1 -f
2645                 stop ost1 -f
2646                 error "OST(s) start failed"
2647         fi
2648
2649         mount_client $MOUNT
2650         if [ $? != 0 ]
2651         then
2652                 stop mds1 -f
2653                 stop ost1 -f
2654                 error "client start failed"
2655         fi
2656         check_mount
2657         if [ $? != 0 ]
2658         then
2659                 stop mds1 -f
2660                 stop ost1 -f
2661                 error "client mount failed"
2662         fi
2663         cleanup
2664 }
2665 run_test 41c "concurent mounts of MDT/OST should all fail but one"
2666
2667 test_42() { #bug 14693
2668         setup
2669         check_mount || error "client was not mounted"
2670
2671         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
2672         umount_client $MOUNT ||
2673                 error "unmounting client failed with invalid llite param"
2674         mount_client $MOUNT ||
2675                 error "mounting client failed with invalid llite param"
2676
2677         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
2678         cleanup || error "stopping $FSNAME failed with invalid sys param"
2679         load_modules
2680         setup
2681         check_mount || "client was not mounted with invalid sys param"
2682         cleanup || error "stopping $FSNAME failed with invalid sys param"
2683         return 0
2684 }
2685 run_test 42 "allow client/server mount/unmount with invalid config param"
2686
2687 test_43() {
2688         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
2689                 { skip "Need MDS version at least 2.5.58" && return 0; }
2690         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2691
2692         ID1=${ID1:-501}
2693         USER1=$(cat /etc/passwd | grep :$ID1:$ID1: | cut -d: -f1)
2694         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
2695                 return
2696
2697         setup
2698         chmod ugo+x $DIR || error "chmod 0 failed"
2699         set_conf_param_and_check mds                                    \
2700                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2701                 "$FSNAME.mdt.root_squash"                               \
2702                 "0:0"
2703         wait_update $HOSTNAME                                           \
2704                 "lctl get_param -n llite.${FSNAME}*.root_squash"        \
2705                 "0:0" ||
2706                 error "check llite root_squash failed!"
2707         set_conf_param_and_check mds                                    \
2708                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2709                 "$FSNAME.mdt.nosquash_nids"                             \
2710                 "NONE"
2711         wait_update $HOSTNAME                                           \
2712                 "lctl get_param -n llite.${FSNAME}*.nosquash_nids"      \
2713                 "NONE" ||
2714                 error "check llite nosquash_nids failed!"
2715
2716     #
2717     # create set of test files
2718     #
2719     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2720     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2721     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2722
2723     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2724     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2725
2726     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2727     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2728     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2729
2730         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
2731         chmod go-rw $DIR/$tfile-user1file  || error "chmod 7 failed"
2732         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
2733
2734         #
2735         # check root_squash:
2736         #   set root squash UID:GID to RUNAS_ID
2737         #   root should be able to access only files owned by RUNAS_ID
2738         #
2739         set_conf_param_and_check mds                                    \
2740                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2741                 "$FSNAME.mdt.root_squash"                               \
2742                 "$RUNAS_ID:$RUNAS_ID"
2743         wait_update $HOSTNAME                                           \
2744                 "lctl get_param -n llite.${FSNAME}*.root_squash"        \
2745                 "$RUNAS_ID:$RUNAS_ID" ||
2746                 error "check llite root_squash failed!"
2747
2748     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2749     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2750         error "$ST: root read permission is denied"
2751     echo "$ST: root read permission is granted - ok"
2752
2753     echo "444" | \
2754     dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2755         error "$ST: root write permission is denied"
2756     echo "$ST: root write permission is granted - ok"
2757
2758     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2759     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2760         error "$ST: root read permission is granted"
2761     echo "$ST: root read permission is denied - ok"
2762
2763     echo "555" | \
2764     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2765         error "$ST: root write permission is granted"
2766     echo "$ST: root write permission is denied - ok"
2767
2768     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2769     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2770         error "$ST: root unlink permission is granted"
2771     echo "$ST: root unlink permission is denied - ok"
2772
2773     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2774         error "$ST: root create permission is granted"
2775     echo "$ST: root create permission is denied - ok"
2776
2777
2778         # LU-1778
2779         # check root_squash is enforced independently
2780         # of client cache content
2781         #
2782         # access file by USER1, keep access open
2783         # root should be denied access to user file
2784
2785         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
2786         pid=$!
2787         sleep 1
2788
2789         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
2790         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2791             { kill $pid; error "$ST: root read permission is granted"; }
2792         echo "$ST: root read permission is denied - ok"
2793
2794         echo "777" | \
2795         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2796             { kill $pid; error "$ST: root write permission is granted"; }
2797         echo "$ST: root write permission is denied - ok"
2798
2799         kill $pid
2800         wait $pid
2801
2802         #
2803         # check nosquash_nids:
2804         #   put client's NID into nosquash_nids list,
2805         #   root should be able to access root file after that
2806         #
2807         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2808         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2809         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2810         set_conf_param_and_check mds                                    \
2811                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2812                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2813                 "$NIDLIST"
2814         wait_update $HOSTNAME                                           \
2815                 "lctl get_param -n llite.${FSNAME}*.nosquash_nids"      \
2816                 "$NIDLIST" ||
2817                 error "check llite nosquash_nids failed!"
2818
2819     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2820     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2821         error "$ST: root read permission is denied"
2822     echo "$ST: root read permission is granted - ok"
2823
2824     echo "666" | \
2825     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2826         error "$ST: root write permission is denied"
2827     echo "$ST: root write permission is granted - ok"
2828
2829     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2830     rm $DIR/$tdir-rootdir/tfile-1 || \
2831         error "$ST: root unlink permission is denied"
2832     echo "$ST: root unlink permission is granted - ok"
2833     touch $DIR/$tdir-rootdir/tfile-2 || \
2834         error "$ST: root create permission is denied"
2835     echo "$ST: root create permission is granted - ok"
2836
2837     return 0
2838 }
2839 run_test 43 "check root_squash and nosquash_nids"
2840
2841 umount_client $MOUNT
2842 cleanup_nocli
2843
2844 test_44() { # 16317
2845         setup
2846         check_mount || return 2
2847         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2848         STATS_FOUND=no
2849         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2850         for VAL in $UUIDS; do
2851                 NID=$(echo $VAL | cut -d= -f1)
2852                 CLUUID=$(echo $VAL | cut -d= -f2)
2853                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2854         done
2855         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2856         cleanup
2857         return 0
2858 }
2859 run_test 44 "mounted client proc entry exists"
2860
2861 test_45() { #17310
2862         setup
2863         check_mount || return 2
2864         stop_mds
2865         df -h $MOUNT &
2866         log "sleep 60 sec"
2867         sleep 60
2868 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2869         do_facet client "lctl set_param fail_loc=0x50f"
2870         log "sleep 10 sec"
2871         sleep 10
2872         manual_umount_client --force || return 3
2873         do_facet client "lctl set_param fail_loc=0x0"
2874         start_mds
2875         mount_client $MOUNT || return 4
2876         cleanup
2877         return 0
2878 }
2879 run_test 45 "long unlink handling in ptlrpcd"
2880
2881 cleanup_46a() {
2882         trap 0
2883         local rc=0
2884         local count=$1
2885
2886         umount_client $MOUNT2 || rc=$?
2887         umount_client $MOUNT || rc=$?
2888         while [ $count -gt 0 ]; do
2889                 stop ost${count} -f || rc=$?
2890                 let count=count-1
2891         done    
2892         stop_mds || rc=$?
2893         cleanup_nocli || rc=$?
2894         #writeconf to remove all ost2 traces for subsequent tests
2895         writeconf_or_reformat
2896         return $rc
2897 }
2898
2899 test_46a() {
2900         echo "Testing with $OSTCOUNT OSTs"
2901         reformat_and_config
2902         start_mds || return 1
2903         #first client should see only one ost
2904         start_ost || return 2
2905         wait_osc_import_state mds ost FULL
2906         #start_client
2907         mount_client $MOUNT || return 3
2908         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2909
2910         local i
2911         for (( i=2; i<=$OSTCOUNT; i++ )); do
2912             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2913         done
2914
2915         # wait until osts in sync
2916         for (( i=2; i<=$OSTCOUNT; i++ )); do
2917             wait_osc_import_state mds ost$i FULL
2918             wait_osc_import_state client ost$i FULL
2919         done
2920
2921         #second client see all ost's
2922
2923         mount_client $MOUNT2 || return 8
2924         $LFS setstripe -c -1 $MOUNT2 || return 9
2925         $LFS getstripe $MOUNT2 || return 10
2926
2927         echo "ok" > $MOUNT2/widestripe
2928         $LFS getstripe $MOUNT2/widestripe || return 11
2929         # fill acl buffer for avoid expand lsm to them
2930         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2931             setfacl -m $acl $MOUNT2/widestripe
2932         done
2933
2934         # will be deadlock
2935         stat $MOUNT/widestripe || return 12
2936
2937         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2938         return 0
2939 }
2940 run_test 46a "handle ost additional - wide striped file"
2941
2942 test_47() { #17674
2943         reformat
2944         setup_noconfig
2945         check_mount || return 2
2946         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2947
2948         local lru_size=[]
2949         local count=0
2950         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2951             if echo $ns | grep "MDT[[:digit:]]*"; then
2952                 continue
2953             fi
2954             lrs=$(echo $ns | sed 's/.*lru_size=//')
2955             lru_size[count]=$lrs
2956             let count=count+1
2957         done
2958
2959         facet_failover ost1
2960         facet_failover $SINGLEMDS
2961         client_up || return 3
2962
2963         count=0
2964         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2965             if echo $ns | grep "MDT[[:digit:]]*"; then
2966                 continue
2967             fi
2968             lrs=$(echo $ns | sed 's/.*lru_size=//')
2969             if ! test "$lrs" -eq "${lru_size[count]}"; then
2970                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2971                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2972             fi
2973             let count=count+1
2974         done
2975
2976         cleanup
2977         return 0
2978 }
2979 run_test 47 "server restart does not make client loss lru_resize settings"
2980
2981 cleanup_48() {
2982         trap 0
2983
2984         # reformat after this test is needed - if test will failed
2985         # we will have unkillable file at FS
2986         reformat_and_config
2987 }
2988
2989 test_48() { # bug 17636
2990         reformat
2991         setup_noconfig
2992         check_mount || return 2
2993
2994         $LFS setstripe -c -1 $MOUNT || return 9
2995         $LFS getstripe $MOUNT || return 10
2996
2997         echo "ok" > $MOUNT/widestripe
2998         $LFS getstripe $MOUNT/widestripe || return 11
2999
3000         trap cleanup_48 EXIT ERR
3001
3002         # fill acl buffer for avoid expand lsm to them
3003         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
3004             setfacl -m $acl $MOUNT/widestripe
3005         done
3006
3007         stat $MOUNT/widestripe || return 12
3008
3009         cleanup_48
3010         return 0
3011 }
3012 run_test 48 "too many acls on file"
3013
3014 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
3015 test_49a() { # bug 17710
3016         local timeout_orig=$TIMEOUT
3017         local ldlm_timeout_orig=$LDLM_TIMEOUT
3018         local LOCAL_TIMEOUT=20
3019
3020         LDLM_TIMEOUT=$LOCAL_TIMEOUT
3021         TIMEOUT=$LOCAL_TIMEOUT
3022
3023         reformat
3024         setup_noconfig
3025         check_mount || error "client mount failed"
3026
3027         echo "check ldlm_timout..."
3028         local LDLM_MDS="$(do_facet $SINGLEMDS lctl get_param -n ldlm_timeout)"
3029         local LDLM_OST1="$(do_facet ost1 lctl get_param -n ldlm_timeout)"
3030         local LDLM_CLIENT="$(do_facet client lctl get_param -n ldlm_timeout)"
3031
3032         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3033                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3034         fi
3035
3036         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
3037                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
3038         fi
3039
3040         umount_client $MOUNT
3041         stop_ost || error "problem stopping OSS"
3042         stop_mds || error "problem stopping MDS"
3043
3044         LDLM_TIMEOUT=$ldlm_timeout_orig
3045         TIMEOUT=$timeout_orig
3046 }
3047 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3048
3049 test_49b() { # bug 17710
3050         local timeout_orig=$TIMEOUT
3051         local ldlm_timeout_orig=$LDLM_TIMEOUT
3052         local LOCAL_TIMEOUT=20
3053
3054         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
3055         TIMEOUT=$LOCAL_TIMEOUT
3056
3057         reformat
3058         setup_noconfig
3059         check_mount || error "client mount failed"
3060
3061         local LDLM_MDS="$(do_facet $SINGLEMDS lctl get_param -n ldlm_timeout)"
3062         local LDLM_OST1="$(do_facet ost1 lctl get_param -n ldlm_timeout)"
3063         local LDLM_CLIENT="$(do_facet client lctl get_param -n ldlm_timeout)"
3064
3065         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3066                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3067         fi
3068
3069         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
3070                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
3071         fi
3072
3073         cleanup || error "cleanup failed"
3074
3075         LDLM_TIMEOUT=$ldlm_timeout_orig
3076         TIMEOUT=$timeout_orig
3077 }
3078 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3079
3080 lazystatfs() {
3081         # Test both statfs and lfs df and fail if either one fails
3082         multiop_bg_pause $1 f_
3083         RC1=$?
3084         PID=$!
3085         killall -USR1 multiop
3086         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
3087         wait $PID || { RC1=$?; log "multiop return error "; }
3088
3089         $LFS df &
3090         PID=$!
3091         sleep 5
3092         kill -s 0 $PID
3093         RC2=$?
3094         if [ $RC2 -eq 0 ]; then
3095             kill -s 9 $PID
3096             log "lazystatfs df failed"
3097         fi
3098
3099         RC=0
3100         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
3101         return $RC
3102 }
3103
3104 test_50a() {
3105         setup
3106         lctl set_param llite.$FSNAME-*.lazystatfs=1
3107         touch $DIR/$tfile
3108
3109         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3110
3111         cleanup || return $?
3112 }
3113 run_test 50a "lazystatfs all servers available =========================="
3114
3115 test_50b() {
3116         setup
3117         lctl set_param llite.$FSNAME-*.lazystatfs=1
3118         touch $DIR/$tfile
3119
3120         # Wait for client to detect down OST
3121         stop_ost || error "Unable to stop OST1"
3122         wait_osc_import_state mds ost DISCONN
3123
3124         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
3125
3126         umount_client $MOUNT || error "Unable to unmount client"
3127         stop_mds || error "Unable to stop MDS"
3128 }
3129 run_test 50b "lazystatfs all servers down =========================="
3130
3131 test_50c() {
3132         start_mds || error "Unable to start MDS"
3133         start_ost || error "Unable to start OST1"
3134         start_ost2 || error "Unable to start OST2"
3135         mount_client $MOUNT || error "Unable to mount client"
3136         lctl set_param llite.$FSNAME-*.lazystatfs=1
3137         touch $DIR/$tfile
3138
3139         # Wait for client to detect down OST
3140         stop_ost || error "Unable to stop OST1"
3141         wait_osc_import_state mds ost DISCONN
3142         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3143
3144         umount_client $MOUNT || error "Unable to unmount client"
3145         stop_ost2 || error "Unable to stop OST2"
3146         stop_mds || error "Unable to stop MDS"
3147         #writeconf to remove all ost2 traces for subsequent tests
3148         writeconf_or_reformat
3149 }
3150 run_test 50c "lazystatfs one server down =========================="
3151
3152 test_50d() {
3153         start_mds || error "Unable to start MDS"
3154         start_ost || error "Unable to start OST1"
3155         start_ost2 || error "Unable to start OST2"
3156         mount_client $MOUNT || error "Unable to mount client"
3157         lctl set_param llite.$FSNAME-*.lazystatfs=1
3158         touch $DIR/$tfile
3159
3160         # Issue the statfs during the window where the client still
3161         # belives the OST to be available but it is in fact down.
3162         # No failure just a statfs which hangs for a timeout interval.
3163         stop_ost || error "Unable to stop OST1"
3164         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3165
3166         umount_client $MOUNT || error "Unable to unmount client"
3167         stop_ost2 || error "Unable to stop OST2"
3168         stop_mds || error "Unable to stop MDS"
3169         #writeconf to remove all ost2 traces for subsequent tests
3170         writeconf_or_reformat
3171 }
3172 run_test 50d "lazystatfs client/server conn race =========================="
3173
3174 test_50e() {
3175         local RC1
3176         local pid
3177
3178         reformat_and_config
3179         start_mds || return 1
3180         #first client should see only one ost
3181         start_ost || return 2
3182         wait_osc_import_state mds ost FULL
3183
3184         # Wait for client to detect down OST
3185         stop_ost || error "Unable to stop OST1"
3186         wait_osc_import_state mds ost DISCONN
3187
3188         mount_client $MOUNT || error "Unable to mount client"
3189         lctl set_param llite.$FSNAME-*.lazystatfs=0
3190
3191         multiop_bg_pause $MOUNT _f
3192         RC1=$?
3193         pid=$!
3194
3195         if [ $RC1 -ne 0 ]; then
3196                 log "multiop failed $RC1"
3197         else
3198             kill -USR1 $pid
3199             sleep $(( $TIMEOUT+1 ))
3200             kill -0 $pid
3201             [ $? -ne 0 ] && error "process isn't sleep"
3202             start_ost || error "Unable to start OST1"
3203             wait $pid || error "statfs failed"
3204         fi
3205
3206         umount_client $MOUNT || error "Unable to unmount client"
3207         stop_ost || error "Unable to stop OST1"
3208         stop_mds || error "Unable to stop MDS"
3209 }
3210 run_test 50e "normal statfs all servers down =========================="
3211
3212 test_50f() {
3213         local RC1
3214         local pid
3215         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
3216
3217         start_mds || error "Unable to start mds"
3218         #first client should see only one ost
3219         start_ost || error "Unable to start OST1"
3220         wait_osc_import_state mds ost FULL
3221
3222         start_ost2 || error "Unable to start OST2"
3223         wait_osc_import_state mds ost2 FULL
3224
3225         # Wait for client to detect down OST
3226         stop_ost2 || error "Unable to stop OST2"
3227
3228         wait_osc_import_state mds ost2 DISCONN
3229         mount_client $MOUNT || error "Unable to mount client"
3230         lctl set_param llite.$FSNAME-*.lazystatfs=0
3231
3232         multiop_bg_pause $MOUNT _f
3233         RC1=$?
3234         pid=$!
3235
3236         if [ $RC1 -ne 0 ]; then
3237                 log "lazystatfs multiop failed $RC1"
3238         else
3239             kill -USR1 $pid
3240             sleep $(( $TIMEOUT+1 ))
3241             kill -0 $pid
3242             [ $? -ne 0 ] && error "process isn't sleep"
3243             start_ost2 || error "Unable to start OST2"
3244             wait $pid || error "statfs failed"
3245             stop_ost2 || error "Unable to stop OST2"
3246         fi
3247
3248         umount_client $MOUNT || error "Unable to unmount client"
3249         stop_ost || error "Unable to stop OST1"
3250         stop_mds || error "Unable to stop MDS"
3251         #writeconf to remove all ost2 traces for subsequent tests
3252         writeconf_or_reformat
3253 }
3254 run_test 50f "normal statfs one server in down =========================="
3255
3256 test_50g() {
3257         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3258         setup
3259         start_ost2 || error "Unable to start OST2"
3260         wait_osc_import_state mds ost2 FULL
3261         wait_osc_import_state client ost2 FULL
3262
3263         local PARAM="${FSNAME}-OST0001.osc.active"
3264
3265         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
3266         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
3267
3268         umount_client $MOUNT || error "Unable to unmount client"
3269         mount_client $MOUNT || error "Unable to mount client"
3270         # This df should not cause a panic
3271         df -k $MOUNT
3272
3273         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
3274         rm -f $DIR/$tfile
3275         umount_client $MOUNT || error "Unable to unmount client"
3276         stop_ost2 || error "Unable to stop OST2"
3277         stop_ost || error "Unable to stop OST1"
3278         stop_mds || error "Unable to stop MDS"
3279         #writeconf to remove all ost2 traces for subsequent tests
3280         writeconf_or_reformat
3281 }
3282 run_test 50g "deactivated OST should not cause panic====================="
3283
3284 # LU-642
3285 test_50h() {
3286         # prepare MDT/OST, make OSC inactive for OST1
3287         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3288
3289         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3290         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
3291                 error "tunefs OST1 failed"
3292         start_mds  || error "Unable to start MDT"
3293         start_ost  || error "Unable to start OST1"
3294         start_ost2 || error "Unable to start OST2"
3295         mount_client $MOUNT || error "client start failed"
3296
3297         mkdir -p $DIR/$tdir
3298
3299         # activatate OSC for OST1
3300         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
3301         set_conf_param_and_check client                                 \
3302                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
3303                 error "Unable to activate OST1"
3304
3305         mkdir -p $DIR/$tdir/2
3306         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2
3307         sleep 1 && echo "create a file after OST1 is activated"
3308         # create some file
3309         createmany -o $DIR/$tdir/2/$tfile-%d 1
3310
3311         # check OSC import is working
3312         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3313                 error "some OSC imports are still not connected"
3314
3315         # cleanup
3316         umount_client $MOUNT || error "Unable to umount client"
3317         stop_ost2 || error "Unable to stop OST2"
3318         cleanup_nocli
3319 }
3320 run_test 50h "LU-642: activate deactivated OST  ==="
3321
3322 test_51() {
3323         local LOCAL_TIMEOUT=20
3324
3325         reformat
3326         setup_noconfig
3327         check_mount || return 1
3328
3329         mkdir $MOUNT/d1
3330         $LFS setstripe -c -1 $MOUNT/d1
3331         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3332         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
3333         touch $MOUNT/d1/f1 &
3334         local pid=$!
3335         sleep 2
3336         start_ost2 || return 2
3337         wait $pid
3338         stop_ost2 || return 3
3339         cleanup
3340         #writeconf to remove all ost2 traces for subsequent tests
3341         writeconf_or_reformat
3342 }
3343 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3344
3345 copy_files_xattrs()
3346 {
3347         local node=$1
3348         local dest=$2
3349         local xattrs=$3
3350         shift 3
3351
3352         do_node $node mkdir -p $dest
3353         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3354
3355         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3356                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3357         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3358
3359         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3360         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3361 }
3362
3363 diff_files_xattrs()
3364 {
3365         local node=$1
3366         local backup=$2
3367         local xattrs=$3
3368         shift 3
3369
3370         local backup2=${TMP}/backup2
3371
3372         do_node $node mkdir -p $backup2
3373         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3374
3375         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3376                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3377         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3378
3379         do_node $node "diff -rq $backup $backup2"
3380         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3381
3382         local xattrs2=${TMP}/xattrs2
3383         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3384         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3385
3386         do_node $node "diff $xattrs $xattrs2"
3387         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3388
3389         do_node $node "rm -rf $backup2 $xattrs2"
3390         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3391 }
3392
3393 test_52() {
3394         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3395                 skip "Only applicable to ldiskfs-based MDTs"
3396                 return
3397         fi
3398
3399         start_mds
3400         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
3401         start_ost
3402         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
3403         mount_client $MOUNT
3404         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
3405
3406         local nrfiles=8
3407         local ost1mnt=$(facet_mntpt ost1)
3408         local ost1node=$(facet_active_host ost1)
3409         local ost1tmp=$TMP/conf52
3410         local loop
3411
3412         mkdir -p $DIR/$tdir
3413         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
3414         touch $TMP/modified_first
3415         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
3416         local mtime=$(stat -c %Y $TMP/modified_first)
3417         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
3418
3419         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
3420         sleep 1
3421
3422         $LFS setstripe -c -1 -S 1M $DIR/$tdir
3423         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
3424
3425         for (( i=0; i < nrfiles; i++ )); do
3426                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
3427                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
3428                 echo -n .
3429         done
3430         echo
3431
3432         # backup files
3433         echo backup files to $TMP/files
3434         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3435         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3436         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
3437
3438         umount_client $MOUNT
3439         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
3440         stop_ost
3441         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
3442
3443         echo mount ost1 as ldiskfs
3444         do_node $ost1node mkdir -p $ost1mnt
3445         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
3446         if ! do_node $ost1node test -b $ost1_dev; then
3447                 loop="-o loop"
3448         fi
3449         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3450                 $ost1mnt
3451         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
3452
3453         # backup objects
3454         echo backup objects to $ost1tmp/objects
3455         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3456                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3457         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3458                         $objects
3459         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
3460
3461         # move objects to lost+found
3462         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3463         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3464
3465         # recover objects dry-run
3466         echo "ll_recover_lost_found_objs dry_run"
3467         do_node $ost1node "ll_recover_lost_found_objs -n -d $ost1mnt/O"
3468         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
3469
3470         # recover objects
3471         echo "ll_recover_lost_found_objs fix run"
3472         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
3473         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
3474
3475         # compare restored objects against saved ones
3476         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
3477         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
3478
3479         do_node $ost1node "umount $ost1mnt"
3480         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
3481
3482         start_ost
3483         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
3484         mount_client $MOUNT
3485         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
3486
3487         # compare files
3488         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3489         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
3490
3491         rm -rf $TMP/files $TMP/file_xattrs
3492         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
3493         do_node $ost1node "rm -rf $ost1tmp"
3494         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
3495         cleanup
3496 }
3497 run_test 52 "check recovering objects from lost+found"
3498
3499 # Checks threads_min/max/started for some service
3500 #
3501 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3502 # parameter pattern prefix like 'ost.*.ost'.
3503 thread_sanity() {
3504         local modname=$1
3505         local facet=$2
3506         local parampat=$3
3507         local opts=$4
3508         local basethr=$5
3509         local tmin
3510         local tmin2
3511         local tmax
3512         local tmax2
3513         local tstarted
3514         local paramp
3515         local msg="Insane $modname thread counts"
3516         local ncpts=$(check_cpt_number $facet)
3517         local nthrs
3518         shift 4
3519
3520         check_mount || return 41
3521
3522         # We need to expand $parampat, but it may match multiple parameters, so
3523         # we'll pick the first one
3524         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
3525                 error "Couldn't expand ${parampat}.threads_min parameter name"
3526                 return 22
3527         fi
3528
3529         # Remove the .threads_min part
3530         paramp=${paramp%.threads_min}
3531
3532         # Check for sanity in defaults
3533         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3534         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3535         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
3536         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
3537         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3538         nthrs=$(expr $tmax - $tmin)
3539         if [ $nthrs -lt $ncpts ]; then
3540                 nthrs=0
3541         else
3542                 nthrs=$ncpts
3543         fi
3544
3545         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
3546                 skip_env "module parameter forced $facet thread count" &&
3547                 tmin=3 && tmax=$((3 * tmax))
3548
3549         # Check that we can change min/max
3550         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
3551         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
3552         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3553         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3554         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
3555
3556         # Check that we can set min/max to the same value
3557         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3558         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
3559         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3560         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3561         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
3562
3563         # Check that we can't set max < min
3564         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
3565         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3566         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3567         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
3568
3569         # We need to ensure that we get the module options desired; to do this
3570         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
3571         LOAD_MODULES_REMOTE=true
3572         cleanup
3573         local oldvalue
3574         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
3575         setmodopts -a $modname "$newvalue" oldvalue
3576
3577         load_modules
3578         setup
3579         check_mount || return 41
3580
3581         # Restore previous setting of MODOPTS_*
3582         setmodopts $modname "$oldvalue"
3583
3584         # Check that $opts took
3585         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
3586         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
3587         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
3588         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3589         cleanup
3590
3591         load_modules
3592         setup
3593 }
3594
3595 test_53a() {
3596         setup
3597         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
3598         cleanup
3599 }
3600 run_test 53a "check OSS thread count params"
3601
3602 test_53b() {
3603         setup
3604         local mds=$(do_facet $SINGLEMDS "lctl get_param -N mds.*.*.threads_max \
3605                     2>/dev/null")
3606         if [ -z "$mds" ]; then
3607                 #running this on an old MDT
3608                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
3609         else
3610                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
3611         fi
3612         cleanup
3613 }
3614 run_test 53b "check MDS thread count params"
3615
3616 test_54a() {
3617         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3618                 skip "Only applicable to ldiskfs-based MDTs"
3619                 return
3620         fi
3621
3622     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
3623     [ $? -eq 0 ] || error "llverdev failed!"
3624     reformat_and_config
3625 }
3626 run_test 54a "test llverdev and partial verify of device"
3627
3628 test_54b() {
3629         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3630                 skip "Only applicable to ldiskfs-based MDTs"
3631                 return
3632         fi
3633
3634     setup
3635     run_llverfs $MOUNT -p
3636     [ $? -eq 0 ] || error "llverfs failed!"
3637     cleanup
3638 }
3639 run_test 54b "test llverfs and partial verify of filesystem"
3640
3641 lov_objid_size()
3642 {
3643         local max_ost_index=$1
3644         echo -n $(((max_ost_index + 1) * 8))
3645 }
3646
3647 test_55() {
3648         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3649                 skip "Only applicable to ldiskfs-based MDTs"
3650                 return
3651         fi
3652
3653         local mdsdev=$(mdsdevname 1)
3654         local mdsvdev=$(mdsvdevname 1)
3655
3656         for i in 1023 2048
3657         do
3658                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
3659                         $mdsvdev || exit 10
3660                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
3661                         --reformat $(ostdevname 1) $(ostvdevname 1)
3662                 setup_noconfig
3663                 stopall
3664                 setup_noconfig
3665                 sync
3666
3667                 echo checking size of lov_objid for ost index $i
3668                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
3669                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
3670                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
3671                 else
3672                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3673                 fi
3674                 stopall
3675         done
3676
3677         reformat
3678 }
3679 run_test 55 "check lov_objid size"
3680
3681 test_56() {
3682         local mds_journal_size_orig=$MDSJOURNALSIZE
3683         local n
3684
3685         MDSJOURNALSIZE=16
3686
3687         for num in $(seq 1 $MDSCOUNT); do
3688                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3689                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3690         done
3691         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
3692                 $(ostdevname 1) $(ostvdevname 1)
3693         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \
3694                 $(ostdevname 2) $(ostvdevname 2)
3695
3696         start_mgsmds
3697         start_ost || error "Unable to start first ost (idx 10000)"
3698         start_ost2 || error "Unable to start second ost (idx 1000)"
3699         mount_client $MOUNT || error "Unable to mount client"
3700         echo ok
3701         $LFS osts
3702         wait_osc_import_state mds ost1 FULL
3703         wait_osc_import_state mds ost2 FULL
3704         $LFS setstripe --stripe-count=-1 $DIR/$tfile || error "Unable to create"
3705         n=$($LFS getstripe --stripe-count $DIR/$tfile)
3706         [ "$n" -eq 2 ] || error "Stripe count not two: $n"
3707         rm $DIR/$tfile
3708         stopall
3709         MDSJOURNALSIZE=$mds_journal_size_orig
3710         reformat
3711 }
3712 run_test 56 "check big OST indexes and out-of-index-order start"
3713
3714 test_57a() { # bug 22656
3715         do_rpc_nodes $(facet_active_host ost1) load_modules_local
3716         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3717         writeconf_or_reformat
3718         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3719         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3720         start_mgsmds
3721         start_ost && error "OST registration from failnode should fail"
3722         reformat
3723 }
3724 run_test 57a "initial registration from failnode should fail (should return errs)"
3725
3726 test_57b() {
3727         do_rpc_nodes $(facet_active_host ost1) load_modules_local
3728         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3729         writeconf_or_reformat
3730         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3731         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3732         start_mgsmds
3733         start_ost || error "OST registration from servicenode should not fail"
3734         reformat
3735 }
3736 run_test 57b "initial registration from servicenode should not fail"
3737
3738 count_osts() {
3739         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3740 }
3741
3742 test_58() { # bug 22658
3743         setup_noconfig
3744         mkdir -p $DIR/$tdir
3745         createmany -o $DIR/$tdir/$tfile-%d 100
3746         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3747 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3748         do_facet $SINGLEMDS "lctl set_param fail_loc=0x601"
3749         unlinkmany $DIR/$tdir/$tfile-%d 100
3750         stop_mds
3751
3752         local MNTDIR=$(facet_mntpt $SINGLEMDS)
3753         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3754
3755         # remove all files from the OBJECTS dir
3756         mount_fstype $SINGLEMDS
3757
3758         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
3759
3760         unmount_fstype $SINGLEMDS
3761         # restart MDS with missing llog files
3762         start_mds
3763         do_facet mds "lctl set_param fail_loc=0"
3764         reformat
3765 }
3766 run_test 58 "missing llog files must not prevent MDT from mounting"
3767
3768 test_59() {
3769         start_mgsmds >> /dev/null
3770         local C1=$(count_osts)
3771         if [ $C1 -eq 0 ]; then
3772                 start_ost >> /dev/null
3773                 C1=$(count_osts)
3774         fi
3775         stopall
3776         echo "original ost count: $C1 (expect > 0)"
3777         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3778         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3779         local C2=$(count_osts)
3780         echo "after mdt writeconf count: $C2 (expect 0)"
3781         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3782         echo "OST start without writeconf should fail:"
3783         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3784         echo "OST start with writeconf should succeed:"
3785         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3786         local C3=$(count_osts)
3787         echo "after ost writeconf count: $C3 (expect 1)"
3788         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3789         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3790         local C4=$(count_osts)
3791         echo "after ost2 writeconf count: $C4 (expect 2)"
3792         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3793         stop_ost2 >> /dev/null
3794         cleanup_nocli >> /dev/null
3795         #writeconf to remove all ost2 traces for subsequent tests
3796         writeconf_or_reformat
3797 }
3798 run_test 59 "writeconf mount option"
3799
3800 test_60() { # LU-471
3801         local num
3802
3803         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3804                 skip "Only applicable to ldiskfs-based MDTs"
3805                 return
3806         fi
3807
3808         for num in $(seq $MDSCOUNT); do
3809                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3810                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3811                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3812                         exit 10
3813         done
3814
3815         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3816         rc=${PIPESTATUS[0]}
3817         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3818
3819         # MDT default has dirdata feature
3820         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3821         # we disable uninit_bg feature
3822         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3823         # we set stride extended options
3824         echo $dump | grep stride > /dev/null || error "stride is not set"
3825         reformat
3826 }
3827 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3828
3829 test_61() { # LU-80
3830         local reformat=false
3831
3832         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3833                 { skip "Need MDS version at least 2.1.53"; return 0; }
3834
3835         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3836            ! large_xattr_enabled; then
3837                 reformat=true
3838                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3839
3840                 for num in $(seq $MDSCOUNT); do
3841                         add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
3842                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3843                         error "add mds $num failed"
3844                 done
3845         fi
3846
3847     setup_noconfig || error "setting up the filesystem failed"
3848     client_up || error "starting client failed"
3849
3850     local file=$DIR/$tfile
3851     touch $file
3852
3853     local large_value="$(generate_string $(max_xattr_size))"
3854     local small_value="bar"
3855
3856     local name="trusted.big"
3857     log "save large xattr $name on $file"
3858     setfattr -n $name -v $large_value $file ||
3859         error "saving $name on $file failed"
3860
3861     local new_value=$(get_xattr_value $name $file)
3862     [[ "$new_value" != "$large_value" ]] &&
3863         error "$name different after saving"
3864
3865     log "shrink value of $name on $file"
3866     setfattr -n $name -v $small_value $file ||
3867         error "shrinking value of $name on $file failed"
3868
3869     new_value=$(get_xattr_value $name $file)
3870     [[ "$new_value" != "$small_value" ]] &&
3871         error "$name different after shrinking"
3872
3873     log "grow value of $name on $file"
3874     setfattr -n $name -v $large_value $file ||
3875         error "growing value of $name on $file failed"
3876
3877     new_value=$(get_xattr_value $name $file)
3878     [[ "$new_value" != "$large_value" ]] &&
3879         error "$name different after growing"
3880
3881     log "check value of $name on $file after remounting MDS"
3882     fail $SINGLEMDS
3883     new_value=$(get_xattr_value $name $file)
3884     [[ "$new_value" != "$large_value" ]] &&
3885         error "$name different after remounting MDS"
3886
3887     log "remove large xattr $name from $file"
3888     setfattr -x $name $file || error "removing $name from $file failed"
3889
3890     rm -f $file
3891     stopall
3892         if $reformat; then
3893                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3894                 reformat
3895         fi
3896 }
3897 run_test 61 "large xattr"
3898
3899 test_62() {
3900         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3901                 skip "Only applicable to ldiskfs-based MDTs"
3902                 return
3903         fi
3904
3905         # MRP-118
3906         local mdsdev=$(mdsdevname 1)
3907         local ostdev=$(ostdevname 1)
3908
3909         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3910                 { skip "Need MDS version at least 2.2.51"; return 0; }
3911
3912         echo "disable journal for mds"
3913         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3914         start_mds && error "MDT start should fail"
3915         echo "disable journal for ost"
3916         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3917         start_ost && error "OST start should fail"
3918         cleanup || return $?
3919         reformat_and_config
3920 }
3921 run_test 62 "start with disabled journal"
3922
3923 test_63() {
3924         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3925                 skip "Only applicable to ldiskfs-based MDTs"
3926                 return
3927         fi
3928
3929         local inode_slab=$(do_facet $SINGLEMDS \
3930                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3931         if [ -z "$inode_slab" ]; then
3932                 skip "ldiskfs module has not been loaded"
3933                 return
3934         fi
3935
3936         echo "$inode_slab ldisk inodes per page"
3937         [ "$inode_slab" -ge "3" ] ||
3938                 error "ldisk inode size is too big, $inode_slab objs per page"
3939         return
3940 }
3941 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3942
3943 test_64() {
3944         start_mds
3945         start_ost
3946         start_ost2 || error "Unable to start second ost"
3947         mount_client $MOUNT || error "Unable to mount client"
3948         stop_ost2 || error "Unable to stop second ost"
3949         echo "$LFS df"
3950         $LFS df --lazy || error "lfs df failed"
3951         cleanup || return $?
3952         #writeconf to remove all ost2 traces for subsequent tests
3953         writeconf_or_reformat
3954 }
3955 run_test 64 "check lfs df --lazy "
3956
3957 test_65() { # LU-2237
3958         # Currently, the test is only valid for ldiskfs backend
3959         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3960                 skip "non-ldiskfs backend" && return
3961
3962         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3963         local brpt=$(facet_mntpt brpt)
3964         local opts=""
3965
3966         if ! do_facet $SINGLEMDS "test -b $devname"; then
3967                 opts="-o loop"
3968         fi
3969
3970         stop_mds
3971         local obj=$(do_facet $SINGLEMDS \
3972                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
3973                     grep Inode)
3974         if [ -z "$obj" ]; then
3975                 # The MDT may be just re-formatted, mount the MDT for the
3976                 # first time to guarantee the "last_rcvd" file is there.
3977                 start_mds || error "fail to mount the MDS for the first time"
3978                 stop_mds
3979         fi
3980
3981         # remove the "last_rcvd" file
3982         do_facet $SINGLEMDS "mkdir -p $brpt"
3983         do_facet $SINGLEMDS \
3984                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
3985         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
3986         do_facet $SINGLEMDS "umount -d $brpt"
3987
3988         # restart MDS, the "last_rcvd" file should be recreated.
3989         start_mds || error "fail to restart the MDS"
3990         stop_mds
3991         obj=$(do_facet $SINGLEMDS \
3992               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
3993         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
3994 }
3995 run_test 65 "re-create the lost last_rcvd file when server mount"
3996
3997 test_66() {
3998         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
3999                 { skip "Need MGS version at least 2.3.59"; return 0; }
4000
4001         setup
4002         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
4003         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
4004
4005         echo "replace_nids should fail if MDS, OSTs and clients are UP"
4006         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4007                 error "replace_nids fail"
4008
4009         umount_client $MOUNT || error "unmounting client failed"
4010         echo "replace_nids should fail if MDS and OSTs are UP"
4011         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4012                 error "replace_nids fail"
4013
4014         stop_ost
4015         echo "replace_nids should fail if MDS is UP"
4016         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4017                 error "replace_nids fail"
4018
4019         stop_mds || error "stopping mds failed"
4020
4021         if combined_mgs_mds; then
4022                 start_mdt 1 "-o nosvc" ||
4023                         error "starting mds with nosvc option failed"
4024         fi
4025
4026         echo "command should accept two parameters"
4027         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
4028                 error "command should accept two params"
4029
4030         echo "correct device name should be passed"
4031         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
4032                 error "wrong devname"
4033
4034         echo "wrong nids list should not destroy the system"
4035         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
4036                 error "wrong parse"
4037
4038         echo "replace OST nid"
4039         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
4040                 error "replace nids failed"
4041
4042         echo "command should accept two parameters"
4043         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
4044                 error "command should accept two params"
4045
4046         echo "wrong nids list should not destroy the system"
4047         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
4048                 error "wrong parse"
4049
4050         echo "replace MDS nid"
4051         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
4052                 error "replace nids failed"
4053
4054         if ! combined_mgs_mds ; then
4055                 stop_mgs
4056         else
4057                 stop_mds
4058         fi
4059
4060         setup_noconfig
4061         check_mount || error "error after nid replace"
4062         cleanup || error "cleanup failed"
4063         reformat
4064 }
4065 run_test 66 "replace nids"
4066
4067 test_67() { #LU-2950
4068         local legacy="$TMP/legacy_lnet_config"
4069         local new="$TMP/new_routes_test"
4070         local out="$TMP/config_out_file"
4071         local verify="$TMP/conv_verify"
4072         local verify_conf="$TMP/conf_verify"
4073
4074         # Create the legacy file that will be run through the
4075         # lustre_routes_conversion script
4076         cat <<- LEGACY_LNET_CONFIG > $legacy
4077                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
4078                 tcp2 54 10.1.3.2@tcp;
4079                 tcp3 10.3.4.3@tcp:3;
4080                 tcp4 10.3.3.4@tcp;
4081         LEGACY_LNET_CONFIG
4082
4083         # Create the verification file to verify the output of
4084         # lustre_routes_conversion script against.
4085         cat <<- VERIFY_LNET_CONFIG > $verify
4086                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
4087                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
4088                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
4089                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
4090                 tcp4: { gateway: 10.3.3.4@tcp }
4091         VERIFY_LNET_CONFIG
4092
4093         # Create the verification file to verify the output of
4094         # lustre_routes_config script against
4095         cat <<- VERIFY_LNET_CONFIG > $verify_conf
4096                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
4097                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
4098                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
4099                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
4100                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
4101         VERIFY_LNET_CONFIG
4102
4103         lustre_routes_conversion $legacy $new > /dev/null
4104         if [ -f $new ]; then
4105                 # verify the conversion output
4106                 cmp -s $new $verify > /dev/null
4107                 if [ $? -eq 1 ]; then
4108                         error "routes conversion failed"
4109                 fi
4110
4111                 lustre_routes_config --dry-run --verbose $new > $out
4112                 # check that the script succeeded
4113                 cmp -s $out $verify_conf > /dev/null
4114                 if [ $? -eq 1 ]; then
4115                         error "routes config failed"
4116                 fi
4117         else
4118                 error "routes conversion test failed"
4119         fi
4120         # remove generated files
4121         rm -f $new $legacy $verify $verify_conf $out
4122 }
4123 run_test 67 "test routes conversion and configuration"
4124
4125 test_68() {
4126         local fid
4127         local seq
4128         local START
4129         local END
4130
4131         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
4132                 { skip "Need MDS version at least 2.4.53"; return 0; }
4133
4134         umount_client $MOUNT || error "umount client failed"
4135
4136         start_mdt 1 || error "MDT start failed"
4137         start_ost
4138
4139         # START-END - the sequences we'll be reserving
4140         START=$(do_facet $SINGLEMDS \
4141                 lctl get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4142         END=$((START + (1 << 30)))
4143         do_facet $SINGLEMDS \
4144                 lctl set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4145
4146         # reset the sequences MDT0000 has already assigned
4147         do_facet $SINGLEMDS \
4148                 lctl set_param seq.srv*MDT0000.space=clear
4149
4150         # remount to let the client allocate new sequence
4151         mount_client $MOUNT || error "mount client failed"
4152
4153         touch $DIR/$tfile
4154         do_facet $SINGLEMDS \
4155                 lctl get_param seq.srv*MDT0000.space
4156         $LFS path2fid $DIR/$tfile
4157
4158         local old_ifs="$IFS"
4159         IFS='[:]'
4160         fid=($($LFS path2fid $DIR/$tfile))
4161         IFS="$old_ifs"
4162         let seq=${fid[1]}
4163
4164         if [[ $seq < $END ]]; then
4165                 error "used reserved sequence $seq?"
4166         fi
4167         cleanup || return $?
4168 }
4169 run_test 68 "be able to reserve specific sequences in FLDB"
4170
4171 test_69() {
4172         local server_version=$(lustre_version_code $SINGLEMDS)
4173
4174         [[ $server_version -lt $(version_code 2.4.2) ]] &&
4175                 skip "Need MDS version at least 2.4.2" && return
4176
4177         [[ $server_version -ge $(version_code 2.4.50) ]] &&
4178         [[ $server_version -lt $(version_code 2.5.0) ]] &&
4179                 skip "Need MDS version at least 2.5.0" && return
4180
4181         setup
4182
4183         # use OST0000 since it probably has the most creations
4184         local OSTNAME=$(ostname_from_index 0)
4185         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4186         local last_id=$(do_facet mds1 lctl get_param -n \
4187                         osc.$mdtosc_proc1.prealloc_last_id)
4188
4189         # Want to have OST LAST_ID over 1.5 * OST_MAX_PRECREATE to
4190         # verify that the LAST_ID recovery is working properly.  If
4191         # not, then the OST will refuse to allow the MDS connect
4192         # because the LAST_ID value is too different from the MDS
4193         #define OST_MAX_PRECREATE=20000
4194         local num_create=$((20000 * 5))
4195
4196         mkdir -p $DIR/$tdir
4197         $LFS setstripe -i 0 $DIR/$tdir
4198         createmany -o $DIR/$tdir/$tfile- $num_create ||
4199                 error "createmany: failed to create $num_create files: $?"
4200         # delete all of the files with objects on OST0 so the
4201         # filesystem is not inconsistent later on
4202         $LFS find $MOUNT --ost 0 | xargs rm
4203
4204         stop_ost || error "OST0 stop failure"
4205         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
4206                 $(ostdevname 1) $(ostvdevname 1) ||
4207                 error "reformat and replace $ostdev failed"
4208         start_ost || error "OST0 restart failure"
4209         wait_osc_import_state mds ost FULL
4210
4211         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
4212         local idx=$($LFS getstripe -i $DIR/$tdir/$tfile-last)
4213         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
4214
4215         cleanup
4216 }
4217 run_test 69 "replace an OST with the same index"
4218
4219 test_70a() {
4220         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4221         local MDTIDX=1
4222
4223         cleanup
4224
4225         start_mdt 1 || error "MDT0 start fail"
4226
4227         start_ost || error "OST0 start fail"
4228
4229         start_mdt 2 || error "MDT1 start fail"
4230
4231         mount_client $MOUNT || error "mount client fails"
4232
4233         mkdir -p $DIR/$tdir || error "create dir fail"
4234
4235         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4236                                         error "create remote dir fail"
4237
4238         rm -rf $DIR/$tdir || error "delete dir fail"
4239         cleanup || return $?
4240 }
4241 run_test 70a "start MDT0, then OST, then MDT1"
4242
4243 test_70b() {
4244         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4245         local MDTIDX=1
4246
4247         start_ost || error "OST0 start fail"
4248
4249         start_mdt 1 || error "MDT0 start fail"
4250         start_mdt 2 || error "MDT1 start fail"
4251
4252         mount_client $MOUNT || error "mount client fails"
4253
4254         mkdir -p $DIR/$tdir || error "create dir fail"
4255
4256         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4257                                         error "create remote dir fail"
4258
4259         rm -rf $DIR/$tdir || error "delete dir fail"
4260
4261         cleanup || return $?
4262 }
4263 run_test 70b "start OST, MDT1, MDT0"
4264
4265 test_70c() {
4266         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4267         local MDTIDX=1
4268
4269         start_mdt 1 || error "MDT0 start fail"
4270         start_mdt 2 || error "MDT1 start fail"
4271         start_ost || error "OST0 start fail"
4272
4273         mount_client $MOUNT || error "mount client fails"
4274         stop_mdt 1 || error "MDT1 start fail"
4275
4276         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
4277         echo "deactivate $mdc_for_mdt1"
4278         $LCTL --device $mdc_for_mdt1 deactivate || return 1
4279
4280         mkdir -p $DIR/$tdir && error "mkdir succeed"
4281
4282         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4283                                         error "create remote dir succeed"
4284
4285         cleanup || return $?
4286 }
4287 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
4288
4289 test_70d() {
4290         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4291         local MDTIDX=1
4292
4293         start_mdt 1 || error "MDT0 start fail"
4294         start_mdt 2 || error "MDT1 start fail"
4295         start_ost || error "OST0 start fail"
4296
4297         mount_client $MOUNT || error "mount client fails"
4298
4299         stop_mdt 2 || error "MDT1 start fail"
4300
4301         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
4302                              awk '{print $4}')
4303         echo "deactivate $mdc_for_mdt2"
4304         $LCTL --device $mdc_for_mdt2 deactivate ||
4305                         error "set $mdc_for_mdt2 deactivate failed"
4306
4307         mkdir -p $DIR/$tdir || error "mkdir fail"
4308         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4309                         error "create remote dir succeed"
4310
4311         rm -rf $DIR/$tdir || error "delete dir fail"
4312
4313         cleanup || return $?
4314 }
4315 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
4316
4317 test_71a() {
4318         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4319         if combined_mgs_mds; then
4320                 skip "needs separate MGS/MDT" && return
4321         fi
4322         local MDTIDX=1
4323
4324         start_mdt 1 || error "MDT0 start fail"
4325         start_ost || error "OST0 start fail"
4326         start_mdt 2 || error "MDT1 start fail"
4327         start_ost2 || error "OST1 start fail"
4328
4329         mount_client $MOUNT || error "mount client fails"
4330
4331         mkdir -p $DIR/$tdir || error "mkdir fail"
4332         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4333                         error "create remote dir succeed"
4334
4335         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4336         rm -rf $DIR/$tdir || error "delete dir fail"
4337
4338         umount_client $MOUNT
4339         stop_mdt 1 || error "MDT0 stop fail"
4340         stop_mdt 2 || error "MDT1 stop fail"
4341         stop_ost || error "OST0 stop fail"
4342         stop_ost2 || error "OST1 stop fail"
4343 }
4344 run_test 71a "start MDT0 OST0, MDT1, OST1"
4345
4346 test_71b() {
4347         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4348         if combined_mgs_mds; then
4349                 skip "needs separate MGS/MDT" && return
4350         fi
4351         local MDTIDX=1
4352
4353         start_mdt 2 || error "MDT1 start fail"
4354         start_ost || error "OST0 start fail"
4355         start_mdt 1 || error "MDT0 start fail"
4356         start_ost2 || error "OST1 start fail"
4357
4358         mount_client $MOUNT || error "mount client fails"
4359
4360         mkdir -p $DIR/$tdir || error "mkdir fail"
4361         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4362                         error "create remote dir succeed"
4363
4364         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4365         rm -rf $DIR/$tdir || error "delete dir fail"
4366
4367         umount_client $MOUNT
4368         stop_mdt 1 || error "MDT0 stop fail"
4369         stop_mdt 2 || error "MDT1 stop fail"
4370         stop_ost || error "OST0 stop fail"
4371         stop_ost2 || error "OST1 stop fail"
4372 }
4373 run_test 71b "start MDT1, OST0, MDT0, OST1"
4374
4375 test_71c() {
4376         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4377         if combined_mgs_mds; then
4378                 skip "needs separate MGS/MDT" && return
4379         fi
4380         local MDTIDX=1
4381
4382         start_ost || error "OST0 start fail"
4383         start_ost2 || error "OST1 start fail"
4384         start_mdt 2 || error "MDT1 start fail"
4385         start_mdt 1 || error "MDT0 start fail"
4386
4387         mount_client $MOUNT || error "mount client fails"
4388
4389         mkdir -p $DIR/$tdir || error "mkdir fail"
4390         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4391                         error "create remote dir succeed"
4392
4393         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4394         rm -rf $DIR/$tdir || error "delete dir fail"
4395
4396         umount_client $MOUNT
4397         stop_mdt 1 || error "MDT0 stop fail"
4398         stop_mdt 2 || error "MDT1 stop fail"
4399         stop_ost || error "OST0 stop fail"
4400         stop_ost2 || error "OST1 stop fail"
4401
4402 }
4403 run_test 71c "start OST0, OST1, MDT1, MDT0"
4404
4405 test_71d() {
4406         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4407         if combined_mgs_mds; then
4408                 skip "needs separate MGS/MDT" && return
4409         fi
4410         local MDTIDX=1
4411
4412         start_ost || error "OST0 start fail"
4413         start_mdt 2 || error "MDT0 start fail"
4414         start_mdt 1 || error "MDT0 start fail"
4415         start_ost2 || error "OST1 start fail"
4416
4417         mount_client $MOUNT || error "mount client fails"
4418
4419         mkdir -p $DIR/$tdir || error "mkdir fail"
4420         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4421                         error "create remote dir succeed"
4422
4423         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4424         rm -rf $DIR/$tdir || error "delete dir fail"
4425
4426         umount_client $MOUNT
4427         stop_mdt 1 || error "MDT0 stop fail"
4428         stop_mdt 2 || error "MDT1 stop fail"
4429         stop_ost || error "OST0 stop fail"
4430         stop_ost2 || error "OST1 stop fail"
4431
4432 }
4433 run_test 71d "start OST0, MDT1, MDT0, OST1"
4434
4435 test_71e() {
4436         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4437         if combined_mgs_mds; then
4438                 skip "needs separate MGS/MDT" && return
4439         fi
4440         local MDTIDX=1
4441
4442         start_ost || error "OST0 start fail"
4443         start_mdt 2 || error "MDT1 start fail"
4444         start_ost2 || error "OST1 start fail"
4445         start_mdt 1 || error "MDT0 start fail"
4446
4447         mount_client $MOUNT || error "mount client fails"
4448
4449         mkdir -p $DIR/$tdir || error "mkdir fail"
4450         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4451                         error "create remote dir succeed"
4452
4453         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4454         rm -rf $DIR/$tdir || error "delete dir fail"
4455
4456         umount_client $MOUNT
4457         stop_mdt 1 || error "MDT0 stop fail"
4458         stop_mdt 2 || error "MDT1 stop fail"
4459         stop_ost || error "OST0 stop fail"
4460         stop_ost2 || error "OST1 stop fail"
4461
4462 }
4463 run_test 71e "start OST0, MDT1, OST1, MDT0"
4464
4465 test_72() { #LU-2634
4466         local mdsdev=$(mdsdevname 1)
4467         local ostdev=$(ostdevname 1)
4468         local cmd="$E2FSCK -fnvd $mdsdev"
4469         local fn=3
4470
4471         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4472                 skip "ldiskfs only test" && return
4473
4474         #tune MDT with "-O extents"
4475
4476         for num in $(seq $MDSCOUNT); do
4477                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
4478                 --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4479                 error "add mds $num failed"
4480                 $TUNE2FS -O extents $(mdsdevname $num)
4481         done
4482
4483         add ost1 $(mkfs_opts ost1 $ostdev) --reformat $ostdev ||
4484                 error "add $ostdev failed"
4485         start_mgsmds || error "start mds failed"
4486         start_ost || error "start ost failed"
4487         mount_client $MOUNT || error "mount client failed"
4488
4489         #create some short symlinks
4490         mkdir -p $DIR/$tdir
4491         createmany -o $DIR/$tdir/$tfile-%d $fn
4492         echo "create $fn short symlinks"
4493         for i in $(seq -w 1 $fn); do
4494                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
4495         done
4496         ls -al $MOUNT
4497
4498         #umount
4499         umount_client $MOUNT || error "umount client failed"
4500         stop_mds || error "stop mds failed"
4501         stop_ost || error "stop ost failed"
4502
4503         #run e2fsck
4504         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
4505 }
4506 run_test 72 "test fast symlink with extents flag enabled"
4507
4508 test_73() { #LU-3006
4509         load_modules
4510         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4511         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
4512                 error "1st tunefs failed"
4513         start_mgsmds || error "start mds failed"
4514         start_ost || error "start ost failed"
4515         mount_client $MOUNT || error "mount client failed"
4516         lctl get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
4517                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
4518         umount_client $MOUNT || error "umount client failed"
4519         stopall
4520         reformat
4521 }
4522 run_test 73 "failnode to update from mountdata properly"
4523
4524 test_75() { # LU-2374
4525         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
4526                         skip "Need MDS version at least 2.4.1" && return
4527
4528         local index=0
4529         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
4530                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
4531         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
4532                 --reformat $(ostdevname 1) $(ostvdevname 1)"
4533
4534         #check with default parameters
4535         add mds1 $opts_mds || error "add mds1 failed for default params"
4536         add ost1 $opts_ost || error "add ost1 failed for default params"
4537
4538         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
4539         opts_mds=$(echo $opts_mds |
4540                    sed -e "s/--index=$index/--index=$index --mdt/")
4541         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
4542         opts_ost=$(echo $opts_ost |
4543                    sed -e "s/--index=$index/--index=$index --ost/")
4544
4545         add mds1 $opts_mds || error "add mds1 failed for new params"
4546         add ost1 $opts_ost || error "add ost1 failed for new params"
4547         return 0
4548 }
4549 run_test 75 "The order of --index should be irrelevant"
4550
4551 test_76a() {
4552         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
4553                 { skip "Need MDS version at least 2.4.52" && return 0; }
4554         setup
4555         local MDMB_PARAM="osc.*.max_dirty_mb"
4556         echo "Change MGS params"
4557         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
4558                 head -1)
4559         echo "max_dirty_mb: $MAX_DIRTY_MB"
4560         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB + MAX_DIRTY_MB))
4561         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
4562         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
4563         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4564                 head -1" $NEW_MAX_DIRTY_MB
4565         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4566         echo "$MAX_DIRTY_MB"
4567         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4568                 error "error while apply max_dirty_mb"
4569
4570         echo "Check the value is stored after remount"
4571         stopall
4572         setupall
4573         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4574                 head -1" $NEW_MAX_DIRTY_MB
4575         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4576         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4577                 error "max_dirty_mb is not saved after remount"
4578
4579         echo "Change OST params"
4580         CLIENT_PARAM="obdfilter.*.client_cache_count"
4581         local CLIENT_CACHE_COUNT
4582         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4583                 head -1)
4584         echo "client_cache_count: $CLIENT_CACHE_COUNT"
4585         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
4586         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
4587         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
4588         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4589                 head -1" $NEW_CLIENT_CACHE_COUNT
4590         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4591                 head -1)
4592         echo "$CLIENT_CACHE_COUNT"
4593         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4594                 error "error while apply client_cache_count"
4595
4596         echo "Check the value is stored after remount"
4597         stopall
4598         setupall
4599         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4600                 head -1" $NEW_CLIENT_CACHE_COUNT
4601         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4602                 head -1)
4603         echo "$CLIENT_CACHE_COUNT"
4604         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4605                 error "client_cache_count is not saved after remount"
4606         stopall
4607 }
4608 run_test 76a "set permanent params set_param -P"
4609
4610 test_76b() { # LU-4783
4611         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.57) ]] ||
4612                 { skip "Need MGS version at least 2.5.57" && return 0; }
4613         stopall
4614         setupall
4615         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
4616                 error "start params log failed"
4617         stopall
4618 }
4619 run_test 76b "verify params log setup correctly"
4620
4621 test_77() { # LU-3445
4622         local server_version=$(lustre_version_code $SINGLEMDS)
4623
4624         [[ $server_version -ge $(version_code 2.2.60) ]] &&
4625         [[ $server_version -le $(version_code 2.4.0) ]] &&
4626                 skip "Need MDS version < 2.2.60 or > 2.4.0" && return
4627
4628         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
4629                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
4630                 skip_env "mixed loopback and real device not working" && return
4631         fi
4632
4633         local fs2mdsdev=$(mdsdevname 1_2)
4634         local fs2ostdev=$(ostdevname 1_2)
4635         local fs2mdsvdev=$(mdsvdevname 1_2)
4636         local fs2ostvdev=$(ostvdevname 1_2)
4637         local fsname=test1234
4638         local mgsnid
4639         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
4640
4641         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
4642                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
4643         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
4644                 error "start fs2mds failed"
4645
4646         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
4647         [[ $mgsnid = *,* ]] || mgsnid+=",$mgsnid"
4648
4649         add fs2ost $(mkfs_opts ost1 $fs2ostdev) --mgsnode=$mgsnid \
4650                 --failnode=$failnid --fsname=$fsname \
4651                 --reformat $fs2ostdev $fs2ostvdev ||
4652                         error "add fs2ost failed"
4653         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
4654
4655         mkdir -p $MOUNT2
4656         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
4657         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
4658         cleanup_fs2
4659 }
4660 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
4661
4662 test_78() {
4663         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ||
4664            $(facet_fstype ost1) != ldiskfs ]] &&
4665                 skip "only applicable to ldiskfs-based MDTs and OSTs" && return
4666
4667         # reformat the Lustre filesystem with a smaller size
4668         local saved_MDSSIZE=$MDSSIZE
4669         local saved_OSTSIZE=$OSTSIZE
4670         MDSSIZE=$((MDSSIZE - 20000))
4671         OSTSIZE=$((OSTSIZE - 20000))
4672         reformat || error "(1) reformat Lustre filesystem failed"
4673         MDSSIZE=$saved_MDSSIZE
4674         OSTSIZE=$saved_OSTSIZE
4675
4676         # mount the Lustre filesystem
4677         setup_noconfig || error "(2) setup Lustre filesystem failed"
4678
4679         # create some files
4680         log "create test files"
4681         local i
4682         local file
4683         local num_files=100
4684         mkdir -p $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
4685         for i in $(seq $num_files); do
4686                 file=$MOUNT/$tdir/$tfile-$i
4687                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4688                         error "(4) create $file failed"
4689         done
4690
4691         # unmount the Lustre filesystem
4692         cleanup || error "(5) cleanup Lustre filesystem failed"
4693
4694         # run e2fsck on the MDT and OST devices
4695         local mds_host=$(facet_active_host $SINGLEMDS)
4696         local ost_host=$(facet_active_host ost1)
4697         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4698         local ost_dev=$(ostdevname 1)
4699
4700         run_e2fsck $mds_host $mds_dev "-y"
4701         run_e2fsck $ost_host $ost_dev "-y"
4702
4703         # get the original block count of the MDT and OST filesystems
4704         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
4705         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
4706
4707         # expand the MDT and OST filesystems to the device size
4708         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
4709         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
4710
4711         # run e2fsck on the MDT and OST devices again
4712         run_e2fsck $mds_host $mds_dev "-y"
4713         run_e2fsck $ost_host $ost_dev "-y"
4714
4715         # mount the Lustre filesystem
4716         setup
4717
4718         # check the files
4719         log "check files after expanding the MDT and OST filesystems"
4720         for i in $(seq $num_files); do
4721                 file=$MOUNT/$tdir/$tfile-$i
4722                 $CHECKSTAT -t file -s 1048576 $file ||
4723                         error "(6) checkstat $file failed"
4724         done
4725
4726         # create more files
4727         log "create more files after expanding the MDT and OST filesystems"
4728         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
4729                 file=$MOUNT/$tdir/$tfile-$i
4730                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4731                         error "(7) create $file failed"
4732         done
4733
4734         # unmount the Lustre filesystem
4735         cleanup || error "(8) cleanup Lustre filesystem failed"
4736
4737         # run e2fsck on the MDT and OST devices
4738         run_e2fsck $mds_host $mds_dev "-y"
4739         run_e2fsck $ost_host $ost_dev "-y"
4740
4741         # get the maximum block count of the MDT and OST filesystems
4742         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
4743         local ost_max_blks=$(get_block_count ost1 $ost_dev)
4744
4745         # get the minimum block count of the MDT and OST filesystems
4746         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
4747                                 grep minimum | sed -e 's/^.*filesystem: //g')
4748         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
4749                                 grep minimum | sed -e 's/^.*filesystem: //g')
4750
4751         # shrink the MDT and OST filesystems to a smaller size
4752         local shrunk=false
4753         local new_blks
4754         local base_blks
4755         if [[ $mds_max_blks -gt $mds_min_blks &&
4756               $mds_max_blks -gt $mds_orig_blks ]]; then
4757                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
4758                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
4759                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
4760                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
4761                         error "shrink $SINGLEMDS to $new_blks failed"
4762                 shrunk=true
4763         fi
4764
4765         if [[ $ost_max_blks -gt $ost_min_blks &&
4766               $ost_max_blks -gt $ost_orig_blks ]]; then
4767                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
4768                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
4769                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
4770                 run_resize2fs ost1 $ost_dev $new_blks ||
4771                         error "shrink ost1 to $new_blks failed"
4772                 shrunk=true
4773         fi
4774
4775         # check whether the MDT or OST filesystem was shrunk or not
4776         if ! $shrunk; then
4777                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
4778                 reformat || error "(10) reformat Lustre filesystem failed"
4779                 return 0
4780         fi
4781
4782         # run e2fsck on the MDT and OST devices again
4783         run_e2fsck $mds_host $mds_dev "-y"
4784         run_e2fsck $ost_host $ost_dev "-y"
4785
4786         # mount the Lustre filesystem again
4787         setup
4788
4789         # check the files
4790         log "check files after shrinking the MDT and OST filesystems"
4791         for i in $(seq $((num_files + 10))); do
4792                 file=$MOUNT/$tdir/$tfile-$i
4793                 $CHECKSTAT -t file -s 1048576 $file ||
4794                         error "(11) checkstat $file failed"
4795         done
4796
4797         # unmount and reformat the Lustre filesystem
4798         cleanup || error "(12) cleanup Lustre filesystem failed"
4799         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
4800         reformat || error "(14) reformat Lustre filesystem failed"
4801 }
4802 run_test 78 "run resize2fs on MDT and OST filesystems"
4803
4804 test_79() { # LU-4227
4805         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.59) ]] ||
4806                 { skip "Need MDS version at least 2.5.59"; return 0; }
4807
4808         local mdsdev1=$(mdsdevname 1)
4809         local mdsvdev1=$(mdsvdevname 1)
4810         local mdsdev2=$(mdsdevname 2)
4811         local mdsvdev2=$(mdsvdevname 2)
4812         local ostdev1=$(ostdevname 1)
4813         local ostvdev1=$(ostvdevname 1)
4814         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
4815         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
4816         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
4817         local mgsnode_opt
4818
4819         # remove --mgs/--mgsnode from mkfs.lustre options
4820         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
4821
4822         mgsnode_opt=$(echo $opts_mds2 |
4823                 awk '{ for ( i = 1; i < NF; i++ )
4824                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4825         [ -n $mgsnode_opt ] &&
4826                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
4827
4828         mgsnode_opt=$(echo $opts_ost1 |
4829                 awk '{ for ( i = 1; i < NF; i++ )
4830                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4831         [ -n $mgsnode_opt ] &&
4832                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
4833
4834         # -MGS, format a mdt without --mgs option
4835         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
4836                 error "Must specify --mgs when formatting mdt combined with mgs"
4837
4838         # +MGS, format a mdt/ost without --mgsnode option
4839         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
4840                 > /dev/null || error "start mds1 failed"
4841         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
4842                 error "Must specify --mgsnode when formatting a mdt"
4843         add ost1 $opts_ost1 $ostdev1 $ostvdev2 &&
4844                 error "Must specify --mgsnode when formatting an ost"
4845
4846         return 0
4847 }
4848 run_test 79 "format MDT/OST without mgs option (should return errors)"
4849
4850 test_80() {
4851         start_mds
4852         start_ost
4853         uuid=$(do_facet ost1 lctl get_param -n mgc.*.uuid)
4854 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
4855         do_facet ost1 "lctl set_param fail_val=10 fail_loc=0x906"
4856         do_facet mgs "lctl set_param fail_val=10 fail_loc=0x906"
4857         do_facet mgs "lctl set_param -n mgs/MGS/evict_client $uuid"
4858         sleep 30
4859         start_ost2
4860
4861         do_facet ost1 "lctl set_param fail_loc=0"
4862         stopall
4863 }
4864 run_test 80 "mgc import reconnect race"
4865
4866 # Save the original values of $OSTCOUNT and $OSTINDEX$i.
4867 save_ostindex() {
4868         local new_ostcount=$1
4869         saved_ostcount=$OSTCOUNT
4870         OSTCOUNT=$new_ostcount
4871
4872         local i
4873         local index
4874         for i in $(seq $OSTCOUNT); do
4875                 index=OSTINDEX$i
4876                 eval saved_ostindex$i=${!index}
4877                 eval OSTINDEX$i=""
4878         done
4879 }
4880
4881 # Restore the original values of $OSTCOUNT and $OSTINDEX$i.
4882 restore_ostindex() {
4883         trap 0
4884
4885         local i
4886         local index
4887         for i in $(seq $OSTCOUNT); do
4888                 index=saved_ostindex$i
4889                 eval OSTINDEX$i=${!index}
4890         done
4891         OSTCOUNT=$saved_ostcount
4892
4893         formatall
4894 }
4895
4896 # The main purpose of this test is to ensure the OST_INDEX_LIST functions as
4897 # expected. This test uses OST_INDEX_LIST to format OSTs with a randomly
4898 # assigned index and ensures we can mount such a formatted file system
4899 test_81() { # LU-4665
4900         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
4901                 { skip "Need MDS version at least 2.6.54" && return; }
4902         [[ $OSTCOUNT -ge 3 ]] || { skip_env "Need at least 3 OSTs" && return; }
4903
4904         stopall
4905
4906         # Each time RANDOM is referenced, a random integer between 0 and 32767
4907         # is generated.
4908         local i
4909         local saved_ostindex1=$OSTINDEX1
4910         for i in 65535 $((RANDOM + 65536)); do
4911                 echo -e "\nFormat ost1 with --index=$i, should fail"
4912                 OSTINDEX1=$i
4913                 if add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat \
4914                    $(ostdevname 1) $(ostvdevname 1); then
4915                         OSTINDEX1=$saved_ostindex1
4916                         error "format ost1 with --index=$i should fail"
4917                 fi
4918         done
4919         OSTINDEX1=$saved_ostindex1
4920
4921         save_ostindex 3
4922
4923         # Format OSTs with random sparse indices.
4924         trap "restore_ostindex" EXIT
4925         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices"
4926         OST_INDEX_LIST=[0,$((RANDOM * 2 % 65533 + 1)),65534] formatall
4927
4928         # Setup and check Lustre filesystem.
4929         start_mgsmds || error "start_mgsmds failed"
4930         for i in $(seq $OSTCOUNT); do
4931                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
4932                         error "start ost$i failed"
4933         done
4934
4935         mount_client $MOUNT || error "mount client $MOUNT failed"
4936         check_mount || error "check client $MOUNT failed"
4937
4938         # Check max_easize.
4939         local max_easize=$($LCTL get_param -n llite.*.max_easize)
4940         [[ $max_easize -eq 128 ]] ||
4941                 error "max_easize is $max_easize, should be 128 bytes"
4942
4943         restore_ostindex
4944 }
4945 run_test 81 "sparse OST indexing"
4946
4947 # Wait OSTs to be active on both client and MDT side.
4948 wait_osts_up() {
4949         local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
4950                 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
4951         wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
4952                 error "wait_update OSTs up on client failed"
4953
4954         cmd="$LCTL get_param -n lod.$FSNAME-MDT*-*.target_obd | sort -u |
4955              awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
4956         wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
4957                 error "wait_update OSTs up on MDT failed"
4958 }
4959
4960 # Here we exercise the stripe placement functionality on a file system that
4961 # has formatted the OST with a random index. With the file system the following
4962 # functionality is tested:
4963 #
4964 # 1. Creating a new file with a specific stripe layout.
4965 #
4966 # 2. Modifiy a existing empty file with a specific stripe layout.
4967 #
4968 # 3. Ensure we fail to set the stripe layout of a file that already has one.
4969 #
4970 # 4. If ost-index is defined we need to ensure it is the first entry in the
4971 #    ost index list returned by lfs getstripe.
4972 #
4973 # 5. Lastly ensure this functionality fails with directories.
4974 test_82a() { # LU-4665
4975         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
4976                 { skip "Need MDS version at least 2.6.54" && return; }
4977         [[ $OSTCOUNT -ge 3 ]] || { skip_env "Need at least 3 OSTs" && return; }
4978
4979         stopall
4980
4981         save_ostindex 3
4982
4983         # Format OSTs with random sparse indices.
4984         local i
4985         local index
4986         local ost_indices
4987         for i in $(seq $OSTCOUNT); do
4988                 index=$((RANDOM * 2))
4989                 ost_indices+=" $index"
4990         done
4991         ost_indices=$(comma_list $ost_indices)
4992
4993         trap "restore_ostindex" EXIT
4994         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
4995         OST_INDEX_LIST=[$ost_indices] formatall
4996
4997         # Setup Lustre filesystem.
4998         start_mgsmds || error "start_mgsmds failed"
4999         for i in $(seq $OSTCOUNT); do
5000                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5001                         error "start ost$i failed"
5002         done
5003
5004         mount_client $MOUNT || error "mount client $MOUNT failed"
5005         wait_osts_up
5006
5007         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5008         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5009
5010         # 1. If the file does not exist, new file will be created
5011         #    with specified OSTs.
5012         local file=$DIR/$tdir/$tfile-1
5013         local cmd="$SETSTRIPE -o $ost_indices $file"
5014         echo -e "\n$cmd"
5015         eval $cmd || error "$cmd failed"
5016         check_stripe_count $file $OSTCOUNT
5017         check_obdidx $file $ost_indices
5018         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5019                 error "write $file failed"
5020
5021         # 2. If the file already exists and is an empty file, the file
5022         #    will be attached with specified layout.
5023         file=$DIR/$tdir/$tfile-2
5024         mcreate $file || error "mcreate $file failed"
5025         cmd="$SETSTRIPE -o $ost_indices $file"
5026         echo -e "\n$cmd"
5027         eval $cmd || error "$cmd failed"
5028         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5029                 error "write $file failed"
5030         check_stripe_count $file $OSTCOUNT
5031         check_obdidx $file $ost_indices
5032
5033         # 3. If the file already has a valid layout attached, the command
5034         #    should fail with EBUSY.
5035         echo -e "\n$cmd"
5036         eval $cmd && error "stripe is already set on $file, $cmd should fail"
5037
5038         # 4. If [--stripe-index|-i <start_ost_idx>] is used, the index must
5039         #    be in the OST indices list.
5040         local start_ost_idx=${ost_indices##*,}
5041         file=$DIR/$tdir/$tfile-3
5042         cmd="$SETSTRIPE -o $ost_indices -i $start_ost_idx $file"
5043         echo -e "\n$cmd"
5044         eval $cmd || error "$cmd failed"
5045         check_stripe_count $file $OSTCOUNT
5046         check_obdidx $file $ost_indices
5047         check_start_ost_idx $file $start_ost_idx
5048
5049         file=$DIR/$tdir/$tfile-4
5050         cmd="$SETSTRIPE"
5051         cmd+=" -o $(exclude_items_from_list $ost_indices $start_ost_idx)"
5052         cmd+=" -i $start_ost_idx $file"
5053         echo -e "\n$cmd"
5054         eval $cmd && error "index $start_ost_idx should be in $ost_indices"
5055
5056         # 5. Specifying OST indices for directory should fail with ENOSUPP.
5057         local dir=$DIR/$tdir/$tdir
5058         mkdir $dir || error "mkdir $dir failed"
5059         cmd="$SETSTRIPE -o $ost_indices $dir"
5060         echo -e "\n$cmd"
5061         eval $cmd && error "$cmd should fail, specifying OST indices" \
5062                            "for directory is not supported"
5063
5064         restore_ostindex
5065 }
5066 run_test 82a "specify OSTs for file (succeed) or directory (fail)"
5067
5068 cleanup_82b() {
5069         trap 0
5070
5071         # Remove OSTs from a pool and destroy the pool.
5072         destroy_pool $ost_pool || true
5073
5074         restore_ostindex
5075 }
5076
5077 # Test 82b is run to ensure that if the user supplies a pool with a specific
5078 # stripe layout that it behaves proprerly. It should fail in the case that
5079 # the supplied OST index list points to OSTs not contained in the user
5080 # supplied pool.
5081 test_82b() { # LU-4665
5082         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5083                 { skip "Need MDS version at least 2.6.54" && return; }
5084         [[ $OSTCOUNT -ge 4 ]] || { skip_env "Need at least 4 OSTs" && return; }
5085
5086         stopall
5087
5088         save_ostindex 4
5089
5090         # Format OSTs with random sparse indices.
5091         local i
5092         local index
5093         local ost_indices
5094         for i in $(seq $OSTCOUNT); do
5095                 index=$((RANDOM * 2))
5096                 ost_indices+=" $index"
5097         done
5098         ost_indices=$(comma_list $ost_indices)
5099
5100         trap "restore_ostindex" EXIT
5101         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5102         OST_INDEX_LIST=[$ost_indices] formatall
5103
5104         # Setup Lustre filesystem.
5105         start_mgsmds || error "start_mgsmds failed"
5106         for i in $(seq $OSTCOUNT); do
5107                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5108                         error "start ost$i failed"
5109         done
5110
5111         mount_client $MOUNT || error "mount client $MOUNT failed"
5112         wait_osts_up
5113         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5114         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5115
5116         # Create a new pool and add OSTs into it.
5117         local ost_pool=$FSNAME.$TESTNAME
5118         create_pool $ost_pool || error "create OST pool $ost_pool failed"
5119
5120         trap - EXIT
5121         trap "cleanup_82b" EXIT
5122
5123         local ost_idx_in_list=${ost_indices##*,}
5124         local ost_idx_in_pool=$(exclude_items_from_list $ost_indices \
5125                                 $ost_idx_in_list)
5126
5127         local ost_targets="$FSNAME-OST["
5128         for i in ${ost_idx_in_pool//,/ }; do
5129                 ost_targets=$ost_targets$(printf "%04x," $i)
5130         done
5131         ost_targets="${ost_targets%,}]"
5132
5133         local ost_targets_uuid=$(for i in ${ost_idx_in_pool//,/ }; \
5134                                  do printf "$FSNAME-OST%04x_UUID\n" $i; done |
5135                                  sort -u | tr '\n' ' ')
5136
5137         local cmd="$LCTL pool_add $ost_pool $ost_targets"
5138         do_facet mgs $cmd || error "$cmd failed"
5139         wait_update $HOSTNAME "$LCTL get_param -n lov.$FSNAME-*.pools.$TESTNAME|
5140                                sort -u | tr '\n' ' ' " "$ost_targets_uuid" ||
5141                                         error "wait_update $ost_pool failed"
5142         pool_list $ost_pool || error "list OST pool $ost_pool failed"
5143
5144         # If [--pool|-p <pool_name>] is set with [--ost-list|-o <ost_indices>],
5145         # then the OSTs must be the members of the pool.
5146         local file=$DIR/$tdir/$tfile
5147         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5148         echo -e "\n$cmd"
5149         eval $cmd && error "OST with index $ost_idx_in_list should be" \
5150                            "in OST pool $ost_pool"
5151
5152         # Only select OST $ost_idx_in_list from $ost_pool for file.
5153         ost_idx_in_list=${ost_idx_in_pool#*,}
5154         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5155         echo -e "\n$cmd"
5156         eval $cmd || error "$cmd failed"
5157         cmd="$GETSTRIPE $file"
5158         echo -e "\n$cmd"
5159         eval $cmd || error "$cmd failed"
5160         check_stripe_count $file 2
5161         check_obdidx $file $ost_idx_in_list
5162         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5163                 error "write $file failed"
5164
5165         cleanup_82b
5166 }
5167 run_test 82b "specify OSTs for file with --pool and --ost-list options"
5168
5169 test_83() {
5170         local dev
5171         local ostmnt
5172         local fstype
5173         local mnt_opts
5174
5175         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
5176                 skip "Only applicable to ldiskfs-based MDTs"
5177                 return
5178         fi
5179
5180         dev=$(ostdevname 1)
5181         ostmnt=$(facet_mntpt ost1)
5182         fstype=$(facet_fstype ost1)
5183
5184         # Mount the OST as an ldiskfs filesystem.
5185         log "mount the OST $dev as a $fstype filesystem"
5186         add ost1 $(mkfs_opts ost1 $dev) $FSTYPE_OPT \
5187                 --reformat $dev $dev > /dev/null ||
5188                 error "format ost1 error"
5189
5190         if ! test -b $dev; then
5191                 mnt_opts=$(csa_add "$OST_MOUNT_OPTS" -o loop)
5192         fi
5193         echo "mnt_opts $mnt_opts"
5194         do_facet ost1 mount -t $fstype $dev \
5195                 $ostmnt $mnt_opts
5196         # Run llverfs on the mounted ldiskfs filesystem.
5197         # It is needed to get ENOSPACE.
5198         log "run llverfs in partial mode on the OST $fstype $ostmnt"
5199         do_rpc_nodes $(facet_host ost1) run_llverfs $ostmnt -vpl \
5200                 "no" || error "run_llverfs error on $fstype"
5201
5202         # Unmount the OST.
5203         log "unmount the OST $dev"
5204         stop ost1
5205
5206         # Delete file IO_scrub. Later osd_scrub_setup will try to
5207         # create "IO_scrub" but will get ENOSPACE.
5208         writeconf_all
5209         echo "start ost1 service on `facet_active_host ost1`"
5210         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
5211
5212         local err
5213         err=$(do_facet ost1 dmesg | grep "VFS: Busy inodes after unmount of")
5214         echo "string err $err"
5215         [ -z "$err" ] || error $err
5216         reformat
5217 }
5218 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
5219 Busy inodes after unmount ..."
5220
5221 if ! combined_mgs_mds ; then
5222         stop mgs
5223 fi
5224
5225 cleanup_gss
5226
5227 # restore the values of MDSSIZE and OSTSIZE
5228 MDSSIZE=$STORED_MDSSIZE
5229 OSTSIZE=$STORED_OSTSIZE
5230 reformat
5231
5232 complete $SECONDS
5233 exit_status