Whamcloud - gitweb
6c5748efcde32e7a97de0fa215f5996c57be7cee
[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
4 #   return codes, espcially when most of them are mapped to something
5 #   else anyway.  The combination of test number and return code
6 #   figure out 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 LUSTRE_TESTS_API_DIR=${LUSTRE_TESTS_API_DIR:-${LUSTRE}/tests/clientapi}
53 export MULTIOP=${MULTIOP:-multiop}
54
55 . $LUSTRE/tests/test-framework.sh
56 init_test_env $@
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 MDSSIZE=200000
61 OSTSIZE=200000
62 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
63
64 if ! combined_mgs_mds; then
65     # bug number for skipped test:    23954
66     ALWAYS_EXCEPT="$ALWAYS_EXCEPT       24b"
67 fi
68
69 # STORED_MDSSIZE is used in test_18
70 if [ -n "$MDSSIZE" ]; then
71     STORED_MDSSIZE=$MDSSIZE
72 fi
73
74 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
75 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
76         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
77 fi
78
79 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
80 # bug number for skipped test:        LU-2778 LU-4444
81         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 57b     69"
82
83 init_logging
84
85 #
86 require_dsh_mds || exit 0
87 require_dsh_ost || exit 0
88 #
89 [ "$SLOW" = "no" ] && EXCEPT_SLOW="30a 31 45 69"
90
91
92 assert_DIR
93
94 gen_config() {
95         # The MGS must be started before the OSTs for a new fs, so start
96         # and stop to generate the startup logs.
97         start_mds
98         start_ost
99         wait_osc_import_state mds ost FULL
100         stop_ost
101         stop_mds
102 }
103
104 reformat_and_config() {
105         reformat
106         if ! combined_mgs_mds ; then
107                 start_mgs
108         fi
109         gen_config
110 }
111
112 writeconf_or_reformat() {
113         # There are at most 2 OSTs for write_conf test
114         # who knows if/where $TUNEFS is installed?
115         # Better reformat if it fails...
116         writeconf_all $MDSCOUNT 2 ||
117                 { echo "tunefs failed, reformatting instead" &&
118                   reformat_and_config && return 0; }
119         return 0
120 }
121
122 reformat() {
123         formatall
124 }
125
126 start_mgs () {
127         echo "start mgs"
128         start mgs $MGSDEV $MGS_MOUNT_OPTS
129 }
130
131 start_mdt() {
132         local num=$1
133         local facet=mds$num
134         local dev=$(mdsdevname $num)
135         shift 1
136
137         echo "start mds service on `facet_active_host $facet`"
138         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
139 }
140
141 stop_mdt() {
142         local num=$1
143         local facet=mds$num
144         local dev=$(mdsdevname $num)
145         shift 1
146
147         echo "stop mds service on `facet_active_host $facet`"
148         # These tests all use non-failover stop
149         stop $facet -f  || return 97
150 }
151
152 start_mds() {
153         local num
154
155         for num in $(seq $MDSCOUNT); do
156                 start_mdt $num $@ || return 94
157         done
158 }
159
160 start_mgsmds() {
161         if ! combined_mgs_mds ; then
162                 start_mgs
163         fi
164         start_mds $@
165 }
166
167 stop_mds() {
168         local num
169         for num in $(seq $MDSCOUNT); do
170                 stop_mdt $num || return 97
171         done
172 }
173
174 stop_mgs() {
175        echo "stop mgs service on `facet_active_host mgs`"
176        # These tests all use non-failover stop
177        stop mgs -f  || return 97
178 }
179
180 start_ost() {
181         echo "start ost1 service on `facet_active_host ost1`"
182         start ost1 `ostdevname 1` $OST_MOUNT_OPTS $@ || return 95
183 }
184
185 stop_ost() {
186         echo "stop ost1 service on `facet_active_host ost1`"
187         # These tests all use non-failover stop
188         stop ost1 -f  || return 98
189 }
190
191 start_ost2() {
192         echo "start ost2 service on `facet_active_host ost2`"
193         start ost2 `ostdevname 2` $OST_MOUNT_OPTS $@ || return 92
194 }
195
196 stop_ost2() {
197         echo "stop ost2 service on `facet_active_host ost2`"
198         # These tests all use non-failover stop
199         stop ost2 -f  || return 93
200 }
201
202 mount_client() {
203         local MOUNTPATH=$1
204         echo "mount $FSNAME on ${MOUNTPATH}....."
205         zconf_mount `hostname` $MOUNTPATH  || return 96
206 }
207
208 remount_client() {
209         local mountopt="-o remount,$1"
210         local MOUNTPATH=$2
211         echo "remount '$1' lustre on ${MOUNTPATH}....."
212         zconf_mount `hostname`  $MOUNTPATH "$mountopt"  || return 96
213 }
214
215 umount_client() {
216         local MOUNTPATH=$1
217         echo "umount lustre on ${MOUNTPATH}....."
218         zconf_umount `hostname` $MOUNTPATH || return 97
219 }
220
221 manual_umount_client(){
222         local rc
223         local FORCE=$1
224         echo "manual umount lustre on ${MOUNT}...."
225         do_facet client "umount -d ${FORCE} $MOUNT"
226         rc=$?
227         return $rc
228 }
229
230 setup() {
231         start_mds || error "MDT start failed"
232         start_ost || error "OST start failed"
233         mount_client $MOUNT || error "client start failed"
234         client_up || error "client_up failed"
235 }
236
237 setup_noconfig() {
238         if ! combined_mgs_mds ; then
239                 start_mgs
240         fi
241
242         start_mds
243         start_ost
244         mount_client $MOUNT
245 }
246
247 unload_modules_conf () {
248         if combined_mgs_mds || ! local_mode; then
249                 unload_modules || return 1
250         fi
251 }
252
253 cleanup_nocli() {
254         stop_ost || return 202
255         stop_mds || return 201
256         unload_modules_conf || return 203
257 }
258
259 cleanup() {
260         umount_client $MOUNT || return 200
261         cleanup_nocli || return $?
262 }
263
264 check_mount() {
265         do_facet client "cp /etc/passwd $DIR/a" || return 71
266         do_facet client "rm $DIR/a" || return 72
267         # make sure lustre is actually mounted (touch will block,
268         # but grep won't, so do it after)
269         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
270         echo "setup single mount lustre success"
271 }
272
273 check_mount2() {
274         do_facet client "touch $DIR/a" || return 71
275         do_facet client "rm $DIR/a" || return 72
276         do_facet client "touch $DIR2/a" || return 73
277         do_facet client "rm $DIR2/a" || return 74
278         echo "setup double mount lustre success"
279 }
280
281 build_test_filter
282
283 if [ "$ONLY" == "setup" ]; then
284         setup
285         exit
286 fi
287
288 if [ "$ONLY" == "cleanup" ]; then
289         cleanup
290         exit
291 fi
292
293 init_gss
294
295 #create single point mountpoint
296
297 reformat_and_config
298
299 test_0() {
300         setup
301         check_mount || return 41
302         cleanup || return $?
303 }
304 run_test 0 "single mount setup"
305
306 test_1() {
307         start_mds || error "MDT start failed"
308         start_ost
309         echo "start ost second time..."
310         start_ost && error "2nd OST start should fail"
311         mount_client $MOUNT || error "client start failed"
312         check_mount || return 42
313         cleanup || return $?
314 }
315 run_test 1 "start up ost twice (should return errors)"
316
317 test_2() {
318         start_mdt 1
319         echo "start mds second time.."
320         start_mdt 1 && error "2nd MDT start should fail"
321         start_ost
322         mount_client $MOUNT
323         check_mount || return 43
324         cleanup || return $?
325 }
326 run_test 2 "start up mds twice (should return err)"
327
328 test_3() {
329         setup
330         #mount.lustre returns an error if already in mtab
331         mount_client $MOUNT && error "2nd client mount should fail"
332         check_mount || return 44
333         cleanup || return $?
334 }
335 run_test 3 "mount client twice (should return err)"
336
337 test_4() {
338         setup
339         touch $DIR/$tfile || return 85
340         stop_ost -f
341         cleanup
342         eno=$?
343         # ok for ost to fail shutdown
344         if [ 202 -ne $eno ]; then
345                 return $eno;
346         fi
347         return 0
348 }
349 run_test 4 "force cleanup ost, then cleanup"
350
351 test_5a() {     # was test_5
352         setup
353         touch $DIR/$tfile || return 1
354         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
355
356         stop_mds -f || return 2
357
358         # cleanup may return an error from the failed
359         # disconnects; for now I'll consider this successful
360         # if all the modules have unloaded.
361         umount -d $MOUNT &
362         UMOUNT_PID=$!
363         sleep 6
364         echo "killing umount"
365         kill -TERM $UMOUNT_PID
366         echo "waiting for umount to finish"
367         wait $UMOUNT_PID
368         if grep " $MOUNT " /proc/mounts; then
369                 echo "test 5: /proc/mounts after failed umount"
370                 umount $MOUNT &
371                 UMOUNT_PID=$!
372                 sleep 2
373                 echo "killing umount"
374                 kill -TERM $UMOUNT_PID
375                 echo "waiting for umount to finish"
376                 wait $UMOUNT_PID
377                 grep " $MOUNT " /proc/mounts && echo "test 5: /proc/mounts after second umount" && return 11
378         fi
379
380         manual_umount_client
381         # stop_mds is a no-op here, and should not fail
382         cleanup_nocli || return $?
383         # df may have lingering entry
384         manual_umount_client
385         # mtab may have lingering entry
386         local WAIT=0
387         local MAX_WAIT=20
388         local sleep=1
389         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
390                 sleep $sleep
391                 grep -q $MOUNT" " /etc/mtab || break
392                 echo "Waiting /etc/mtab updated ... "
393                 WAIT=$(( WAIT + sleep))
394         done
395         [ "$WAIT" -eq "$MAX_WAIT" ] && error "/etc/mtab is not updated in $WAIT secs"
396         echo "/etc/mtab updated in $WAIT secs"
397 }
398 run_test 5a "force cleanup mds, then cleanup"
399
400 cleanup_5b () {
401         trap 0
402         start_mgs
403 }
404
405 test_5b() {
406         grep " $MOUNT " /etc/mtab && \
407                 error false "unexpected entry in mtab before mount" && return 10
408
409         local rc=0
410         start_ost
411         if ! combined_mgs_mds ; then
412                 trap cleanup_5b EXIT ERR
413                 start_mds
414                 stop mgs
415         fi
416
417         [ -d $MOUNT ] || mkdir -p $MOUNT
418         mount_client $MOUNT && rc=1
419         grep " $MOUNT " /etc/mtab && \
420                 error "$MOUNT entry in mtab after failed mount" && rc=11
421         umount_client $MOUNT
422         # stop_mds is a no-op here, and should not fail
423         cleanup_nocli || rc=$?
424         if ! combined_mgs_mds ; then
425                 cleanup_5b
426         fi
427         return $rc
428 }
429 run_test 5b "Try to start a client with no MGS (should return errs)"
430
431 test_5c() {
432         grep " $MOUNT " /etc/mtab && \
433                 error false "unexpected entry in mtab before mount" && return 10
434
435         local rc=0
436         start_mds
437         start_ost
438         [ -d $MOUNT ] || mkdir -p $MOUNT
439         local oldfs="${FSNAME}"
440         FSNAME="wrong.${FSNAME}"
441         mount_client $MOUNT || :
442         FSNAME=${oldfs}
443         grep " $MOUNT " /etc/mtab && \
444                 error "$MOUNT entry in mtab after failed mount" && rc=11
445         umount_client $MOUNT
446         cleanup_nocli  || rc=$?
447         return $rc
448 }
449 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
450
451 test_5d() {
452         grep " $MOUNT " /etc/mtab && \
453                 error false "unexpected entry in mtab before mount" && return 10
454
455         local rc=0
456         start_ost
457         start_mds
458         stop_ost -f
459         mount_client $MOUNT || rc=1
460         cleanup  || rc=$?
461         grep " $MOUNT " /etc/mtab && \
462                 error "$MOUNT entry in mtab after unmount" && rc=11
463         return $rc
464 }
465 run_test 5d "mount with ost down"
466
467 test_5e() {
468         grep " $MOUNT " /etc/mtab && \
469                 error false "unexpected entry in mtab before mount" && return 10
470
471         local rc=0
472         start_mds
473         start_ost
474
475 #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
476         do_facet client "lctl set_param fail_loc=0x80000506"
477         mount_client $MOUNT || echo "mount failed (not fatal)"
478         cleanup  || rc=$?
479         grep " $MOUNT " /etc/mtab && \
480                 error "$MOUNT entry in mtab after unmount" && rc=11
481         return $rc
482 }
483 run_test 5e "delayed connect, don't crash (bug 10268)"
484
485 test_5f() {
486         if combined_mgs_mds ; then
487                 skip "combined mgs and mds"
488                 return 0
489         fi
490
491         grep " $MOUNT " /etc/mtab && \
492                 error false "unexpected entry in mtab before mount" && return 10
493
494         local rc=0
495         start_ost
496         [ -d $MOUNT ] || mkdir -p $MOUNT
497         mount_client $MOUNT &
498         local pid=$!
499         echo client_mount pid is $pid
500
501         sleep 5
502
503         if ! ps -f -p $pid >/dev/null; then
504                 wait $pid
505                 rc=$?
506                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
507                 error "mount returns $rc, expected to hang"
508                 rc=11
509                 cleanup || rc=$?
510                 return $rc
511         fi
512
513         # start mds
514         start_mds
515
516         # mount should succeed after start mds
517         wait $pid
518         rc=$?
519         [ $rc -eq 0 ] || error "mount returned $rc"
520         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
521         cleanup || return $?
522         return $rc
523 }
524 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
525
526 test_6() {
527         setup
528         manual_umount_client
529         mount_client ${MOUNT} || return 87
530         touch $DIR/a || return 86
531         cleanup  || return $?
532 }
533 run_test 6 "manual umount, then mount again"
534
535 test_7() {
536         setup
537         manual_umount_client
538         cleanup_nocli || return $?
539 }
540 run_test 7 "manual umount, then cleanup"
541
542 test_8() {
543         setup
544         mount_client $MOUNT2
545         check_mount2 || return 45
546         umount_client $MOUNT2
547         cleanup  || return $?
548 }
549 run_test 8 "double mount setup"
550
551 test_9() {
552         start_ost
553
554         do_facet ost1 lctl set_param debug=\'inode trace\' || return 1
555         do_facet ost1 lctl set_param subsystem_debug=\'mds ost\' || return 1
556
557         CHECK_PTLDEBUG="`do_facet ost1 lctl get_param -n debug`"
558         if [ "$CHECK_PTLDEBUG" ] && { \
559            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
560            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
561            echo "lnet.debug success"
562         else
563            echo "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
564            return 1
565         fi
566         CHECK_SUBSYS="`do_facet ost1 lctl get_param -n subsystem_debug`"
567         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
568            echo "lnet.subsystem_debug success"
569         else
570            echo "lnet.subsystem_debug: want 'mds ost', have '$CHECK_SUBSYS'"
571            return 1
572         fi
573         stop_ost || return $?
574 }
575 run_test 9 "test ptldebug and subsystem for mkfs"
576
577 is_blkdev () {
578         local facet=$1
579         local dev=$2
580         local size=${3:-""}
581
582         local rc=0
583         do_facet $facet "test -b $dev" || rc=1
584         if [[ "$size" ]]; then
585                 local in=$(do_facet $facet "dd if=$dev of=/dev/null bs=1k count=1 skip=$size 2>&1" |\
586                         awk '($3 == "in") { print $1 }')
587                 [[ $in  = "1+0" ]] || rc=1
588         fi
589         return $rc
590 }
591
592 #
593 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
594 # But with new MDS stack we don't care about the mode of local objects
595 # anymore, so this test is removed. See bug 22944 for more details.
596 #
597
598 test_17() {
599         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
600                 skip "Only applicable to ldiskfs-based MDTs"
601                 return
602         fi
603
604         setup
605         check_mount || return 41
606         cleanup || return $?
607
608         echo "Remove mds config log"
609         if ! combined_mgs_mds ; then
610                 stop mgs
611         fi
612
613         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
614                 $(mgsdevname) || return \$?" || return $?
615
616         if ! combined_mgs_mds ; then
617                 start_mgs
618         fi
619
620         start_ost
621         start_mds && return 42
622         reformat_and_config
623 }
624 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
625
626 test_18() {
627         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
628                 skip "Only applicable to ldiskfs-based MDTs"
629                 return
630         fi
631
632         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
633
634         local MIN=2000000
635
636         local OK=
637         # check if current MDSSIZE is large enough
638         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE && \
639                 log "use MDSSIZE=$MDSSIZE"
640
641         # check if the global config has a large enough MDSSIZE
642         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] && [ $STORED_MDSSIZE -ge $MIN ] && \
643                 OK=1 && myMDSSIZE=$STORED_MDSSIZE && \
644                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
645
646         # check if the block device is large enough
647         is_blkdev $SINGLEMDS $MDSDEV $MIN
648         local large_enough=$?
649         if [ -n "$OK" ]; then
650                 [ $large_enough -ne 0 ] && OK=""
651         else
652                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
653                         log "use device $MDSDEV with MIN=$MIN"
654         fi
655
656         # check if a loopback device has enough space for fs metadata (5%)
657
658         if [ -z "$OK" ]; then
659                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
660                         awk '($1 != "Filesystem") {print $4}')
661                 ! [ -z "$SPACE" ]  &&  [ $SPACE -gt $((MIN / 20)) ] && \
662                         OK=1 && myMDSSIZE=$MIN && \
663                         log "use file $MDSDEV with MIN=$MIN"
664         fi
665
666         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS" && return
667
668
669         echo "mount mds with large journal..."
670
671         local OLD_MDSSIZE=$MDSSIZE
672         MDSSIZE=$myMDSSIZE
673
674         reformat_and_config
675         echo "mount lustre system..."
676         setup
677         check_mount || return 41
678
679         echo "check journal size..."
680         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
681         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
682                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
683         else
684                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
685         fi
686
687         cleanup || return $?
688
689         MDSSIZE=$OLD_MDSSIZE
690         reformat_and_config
691 }
692 run_test 18 "check mkfs creates large journals"
693
694 test_19a() {
695         start_mds || return 1
696         stop_mds -f || return 2
697 }
698 run_test 19a "start/stop MDS without OSTs"
699
700 test_19b() {
701         start_ost || return 1
702         stop_ost -f || return 2
703 }
704 run_test 19b "start/stop OSTs without MDS"
705
706 test_20() {
707         # first format the ost/mdt
708         start_mds
709         start_ost
710         mount_client $MOUNT
711         check_mount || return 43
712         rm -f $DIR/$tfile
713         remount_client ro $MOUNT || return 44
714         touch $DIR/$tfile && echo "$DIR/$tfile created incorrectly" && return 45
715         [ -e $DIR/$tfile ] && echo "$DIR/$tfile exists incorrectly" && return 46
716         remount_client rw $MOUNT || return 47
717         touch $DIR/$tfile
718         [ ! -f $DIR/$tfile ] && echo "$DIR/$tfile missing" && return 48
719         MCNT=`grep -c $MOUNT /etc/mtab`
720         [ "$MCNT" -ne 1 ] && echo "$MOUNT in /etc/mtab $MCNT times" && return 49
721         umount_client $MOUNT
722         stop_mds
723         stop_ost
724 }
725 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
726
727 test_21a() {
728         start_mds
729         start_ost
730         wait_osc_import_state mds ost FULL
731         stop_ost
732         stop_mds
733 }
734 run_test 21a "start mds before ost, stop ost first"
735
736 test_21b() {
737         start_ost
738         start_mds
739         wait_osc_import_state mds ost FULL
740         stop_mds
741         stop_ost
742 }
743 run_test 21b "start ost before mds, stop mds first"
744
745 test_21c() {
746         start_ost
747         start_mds
748         start_ost2
749         wait_osc_import_state mds ost2 FULL
750         stop_ost
751         stop_ost2
752         stop_mds
753         #writeconf to remove all ost2 traces for subsequent tests
754         writeconf_or_reformat
755 }
756 run_test 21c "start mds between two osts, stop mds last"
757
758 test_21d() {
759         if combined_mgs_mds ; then
760                 skip "need separate mgs device" && return 0
761         fi
762         stopall
763
764         reformat
765
766         start_mgs
767         start_ost
768         start_ost2
769         start_mds
770         wait_osc_import_state mds ost2 FULL
771
772         stop_ost
773         stop_ost2
774         stop_mds
775         stop_mgs
776         #writeconf to remove all ost2 traces for subsequent tests
777         writeconf_or_reformat
778         start_mgs
779 }
780 run_test 21d "start mgs then ost and then mds"
781
782 test_22() {
783         start_mds
784
785         echo Client mount with ost in logs, but none running
786         start_ost
787         # wait until mds connected to ost and open client connection
788         wait_osc_import_state mds ost FULL
789         stop_ost
790         mount_client $MOUNT
791         # check_mount will block trying to contact ost
792         mcreate $DIR/$tfile || return 40
793         rm -f $DIR/$tfile || return 42
794         umount_client $MOUNT
795         pass
796
797         echo Client mount with a running ost
798         start_ost
799         if $GSS; then
800                 # if gss enabled, wait full time to let connection from
801                 # mds to ost be established, due to the mismatch between
802                 # initial connect timeout and gss context negotiation timeout.
803                 # This perhaps could be remove after AT landed.
804                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
805                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
806         fi
807         mount_client $MOUNT
808         wait_osc_import_state mds ost FULL
809         wait_osc_import_state client ost FULL
810         check_mount || return 41
811         pass
812
813         cleanup
814 }
815 run_test 22 "start a client before osts (should return errs)"
816
817 test_23a() {    # was test_23
818         setup
819         # fail mds
820         stop $SINGLEMDS
821         # force down client so that recovering mds waits for reconnect
822         local running=$(grep -c $MOUNT /proc/mounts) || true
823         if [ $running -ne 0 ]; then
824                 echo "Stopping client $MOUNT (opts: -f)"
825                 umount -f $MOUNT
826         fi
827
828         # enter recovery on mds
829         start_mds
830         # try to start a new client
831         mount_client $MOUNT &
832         sleep 5
833         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
834         MOUNT_LUSTRE_PID=`ps -ef | grep mount.lustre | grep -v grep | awk '{print $2}'`
835         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
836         ps --ppid $MOUNT_PID
837         ps --ppid $MOUNT_LUSTRE_PID
838         echo "waiting for mount to finish"
839         ps -ef | grep mount
840         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
841         # SIGTERM works but it does not spread to offspring processses
842         kill -s TERM $MOUNT_PID
843         kill -s TERM $MOUNT_LUSTRE_PID
844         # we can not wait $MOUNT_PID because it is not a child of this shell
845         local PID1
846         local PID2
847         local WAIT=0
848         local MAX_WAIT=30
849         local sleep=1
850         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
851                 sleep $sleep
852                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
853                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
854                 echo PID1=$PID1
855                 echo PID2=$PID2
856                 [ -z "$PID1" -a -z "$PID2" ] && break
857                 echo "waiting for mount to finish ... "
858                 WAIT=$(( WAIT + sleep))
859         done
860         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
861                 error "MOUNT_PID $MOUNT_PID and "\
862                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
863                 ps -ef | grep mount
864         fi
865         stop_mds || error "stopping MDSes failed"
866         stop_ost || error "stopping OSSes failed"
867 }
868 run_test 23a "interrupt client during recovery mount delay"
869
870 umount_client $MOUNT
871 cleanup_nocli
872
873 test_23b() {    # was test_23
874         start_mds
875         start_ost
876         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
877         lctl set_param fail_loc=0x80000313
878         mount_client $MOUNT
879         cleanup
880 }
881 run_test 23b "Simulate -EINTR during mount"
882
883 fs2mds_HOST=$mds_HOST
884 fs2ost_HOST=$ost_HOST
885
886 MDSDEV1_2=$fs2mds_DEV
887 OSTDEV1_2=$fs2ost_DEV
888 OSTDEV2_2=$fs3ost_DEV
889
890 cleanup_24a() {
891         trap 0
892         echo "umount $MOUNT2 ..."
893         umount $MOUNT2 || true
894         echo "stopping fs2mds ..."
895         stop fs2mds -f || true
896         echo "stopping fs2ost ..."
897         stop fs2ost -f || true
898 }
899
900 test_24a() {
901         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
902
903         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
904                 is_blkdev $SINGLEMDS $MDSDEV && \
905                 skip_env "mixed loopback and real device not working" && return
906         fi
907
908         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
909
910         local fs2mdsdev=$(mdsdevname 1_2)
911         local fs2ostdev=$(ostdevname 1_2)
912         local fs2mdsvdev=$(mdsvdevname 1_2)
913         local fs2ostvdev=$(ostvdevname 1_2)
914
915         # test 8-char fsname as well
916         local FSNAME2=test1234
917
918         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
919                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
920
921         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
922                 --reformat $fs2ostdev $fs2ostvdev || exit 10
923
924         setup
925         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT
926         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
927         mkdir -p $MOUNT2
928         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || return 1
929         # 1 still works
930         check_mount || return 2
931         # files written on 1 should not show up on 2
932         cp /etc/passwd $DIR/$tfile
933         sleep 10
934         [ -e $MOUNT2/$tfile ] && error "File bleed" && return 7
935         # 2 should work
936         sleep 5
937         cp /etc/passwd $MOUNT2/b || return 3
938         rm $MOUNT2/b || return 4
939         # 2 is actually mounted
940         grep $MOUNT2' ' /proc/mounts > /dev/null || return 5
941         # failover
942         facet_failover fs2mds
943         facet_failover fs2ost
944         df
945         umount_client $MOUNT
946         # the MDS must remain up until last MDT
947         stop_mds
948         MDS=$(do_facet $SINGLEMDS "lctl get_param -n devices" | awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
949         [ -z "$MDS" ] && error "No MDT" && return 8
950         cleanup_24a
951         cleanup_nocli || return 6
952 }
953 run_test 24a "Multiple MDTs on a single node"
954
955 test_24b() {
956         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
957
958         if [ -z "$fs2mds_DEV" ]; then
959                 local dev=${SINGLEMDS}_dev
960                 local MDSDEV=${!dev}
961                 is_blkdev $SINGLEMDS $MDSDEV && \
962                 skip_env "mixed loopback and real device not working" && return
963         fi
964
965         local fs2mdsdev=$(mdsdevname 1_2)
966         local fs2mdsvdev=$(mdsvdevname 1_2)
967
968         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
969                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
970         setup
971         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && return 2
972         cleanup || return 6
973 }
974 run_test 24b "Multiple MGSs on a single node (should return err)"
975
976 test_25() {
977         setup
978         check_mount || return 2
979         local MODULES=$($LCTL modules | awk '{ print $2 }')
980         rmmod $MODULES 2>/dev/null || true
981         cleanup || return 6
982 }
983 run_test 25 "Verify modules are referenced"
984
985 test_26() {
986     load_modules
987     # we need modules before mount for sysctl, so make sure...
988     do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
989 #define OBD_FAIL_MDS_FS_SETUP            0x135
990     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000135"
991     start_mds && echo MDS started && return 1
992     lctl get_param -n devices
993     DEVS=$(lctl get_param -n devices | egrep -v MG | wc -l)
994     [ $DEVS -gt 0 ] && return 2
995     # start mds to drop writeconf setting
996     start_mds || return 3
997     stop_mds || return 4
998     unload_modules_conf || return $?
999 }
1000 run_test 26 "MDT startup failure cleans LOV (should return errs)"
1001
1002 test_27a() {
1003         start_ost || return 1
1004         start_mds || return 2
1005         echo "Requeue thread should have started: "
1006         ps -e | grep ll_cfg_requeue
1007         set_conf_param_and_check ost1                                         \
1008            "lctl get_param -n obdfilter.$FSNAME-OST0000.client_cache_seconds" \
1009            "$FSNAME-OST0000.ost.client_cache_seconds" || return 3
1010         cleanup_nocli
1011 }
1012 run_test 27a "Reacquire MGS lock if OST started first"
1013
1014 test_27b() {
1015         # FIXME. ~grev
1016         setup
1017         local device=$(do_facet $SINGLEMDS "lctl get_param -n devices" |
1018                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1019
1020         facet_failover $SINGLEMDS
1021         set_conf_param_and_check $SINGLEMDS                             \
1022                 "lctl get_param -n mdt.$device.identity_acquire_expire" \
1023                 "$device.mdt.identity_acquire_expire" || return 3
1024         set_conf_param_and_check client                                 \
1025                 "lctl get_param -n mdc.$device-mdc-*.max_rpcs_in_flight"\
1026                 "$device.mdc.max_rpcs_in_flight" || return 4
1027         check_mount
1028         cleanup
1029 }
1030 run_test 27b "Reacquire MGS lock after failover"
1031
1032 test_28() {
1033         setup
1034         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1035         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1036         ORIG=$($TEST)
1037         FINAL=$(($ORIG + 1))
1038         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 3
1039         FINAL=$(($FINAL + 1))
1040         set_conf_param_and_check client "$TEST" "$PARAM" $FINAL || return 4
1041         umount_client $MOUNT || return 200
1042         mount_client $MOUNT
1043         RESULT=$($TEST)
1044         if [ $RESULT -ne $FINAL ]; then
1045             echo "New config not seen: wanted $FINAL got $RESULT"
1046             return 4
1047         else
1048             echo "New config success: got $RESULT"
1049         fi
1050         set_conf_param_and_check client "$TEST" "$PARAM" $ORIG || return 5
1051         cleanup
1052 }
1053 run_test 28 "permanent parameter setting"
1054
1055 test_28a() { # LU-4221
1056         [ $(lustre_version_code ost1) -eq $(version_code 2.5.0) -o \
1057                 $(lustre_version_code ost1) -ge $(version_code 2.5.52) ] ||
1058                         { skip "Need OST version >= 2.5.52 or = 2.5.0" &&
1059                                 return 0; }
1060         [ "$(facet_fstype ost1)" = "zfs" ] &&
1061                 skip "LU-4221: no such proc params for ZFS OSTs" && return
1062
1063         local name
1064         local param
1065         local cmd
1066         local old
1067         local new
1068         local device="$FSNAME-OST0000"
1069
1070         setup
1071
1072         # In this test we will set three kinds of proc parameters with
1073         # lctl conf_param:
1074         # 1. the ones moved from the OFD to the OSD, and only their
1075         #    symlinks kept in obdfilter
1076         # 2. non-symlink ones in the OFD
1077         # 3. non-symlink ones in the OSD
1078
1079         # Check 1.
1080         # prepare a symlink parameter in the OFD
1081         name="writethrough_cache_enable"
1082         param="$device.ost.$name"
1083         cmd="$LCTL get_param -n obdfilter.$device.$name"
1084
1085         # conf_param the symlink parameter in the OFD
1086         old=$(do_facet ost1 $cmd)
1087         new=$(((old + 1) % 2))
1088         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1089                 error "lctl conf_param $device.ost.$param=$new failed"
1090
1091         # conf_param the target parameter in the OSD
1092         param="$device.osd.$name"
1093         cmd="$LCTL get_param -n osd-*.$device.$name"
1094         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1095                 error "lctl conf_param $device.osd.$param=$old failed"
1096
1097         # Check 2.
1098         # prepare a non-symlink parameter in the OFD
1099         name="client_cache_seconds"
1100         param="$device.ost.$name"
1101         cmd="$LCTL get_param -n obdfilter.$device.$name"
1102
1103         # conf_param the parameter in the OFD
1104         old=$(do_facet ost1 $cmd)
1105         new=$((old * 2))
1106         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1107                 error "lctl conf_param $device.ost.$param=$new failed"
1108         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1109                 error "lctl conf_param $device.ost.$param=$old failed"
1110
1111         # Check 3.
1112         # prepare a non-symlink parameter in the OSD
1113         name="auto_scrub"
1114         param="$device.osd.$name"
1115         cmd="$LCTL get_param -n osd-*.$device.$name"
1116
1117         # conf_param the parameter in the OSD
1118         old=$(do_facet ost1 $cmd)
1119         new=$(((old + 1) % 2))
1120         set_conf_param_and_check ost1 "$cmd" "$param" $new ||
1121                 error "lctl conf_param $device.osd.$param=$new failed"
1122         set_conf_param_and_check ost1 "$cmd" "$param" $old ||
1123                 error "lctl conf_param $device.osd.$param=$old failed"
1124
1125         cleanup
1126 }
1127 run_test 28a "set symlink parameters permanently with conf_param"
1128
1129 test_29() {
1130         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
1131         setup > /dev/null 2>&1
1132         start_ost2
1133         sleep 10
1134
1135         local PARAM="$FSNAME-OST0001.osc.active"
1136         local PROC_ACT="osc.$FSNAME-OST0001-osc-[^M]*.active"
1137         local PROC_UUID="osc.$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1138
1139         ACTV=$(lctl get_param -n $PROC_ACT)
1140         DEAC=$((1 - $ACTV))
1141         set_conf_param_and_check client \
1142                 "lctl get_param -n $PROC_ACT" "$PARAM" $DEAC || return 2
1143         # also check ost_server_uuid status
1144         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV)
1145         if [ -z "$RESULT" ]; then
1146             echo "Live client not deactivated: $(lctl get_param -n $PROC_UUID)"
1147             return 3
1148         else
1149             echo "Live client success: got $RESULT"
1150         fi
1151
1152         # check MDTs too
1153         for num in $(seq $MDSCOUNT); do
1154                 local mdtosc=$(get_mdtosc_proc_path mds${num} $FSNAME-OST0001)
1155                 local MPROC="osc.$mdtosc.active"
1156                 local MAX=30
1157                 local WAIT=0
1158                 while [ 1 ]; do
1159                         sleep 5
1160                         RESULT=$(do_facet mds${num} " lctl get_param -n $MPROC")
1161                         [ ${PIPESTATUS[0]} = 0 ] || error "Can't read $MPROC"
1162                         if [ $RESULT -eq $DEAC ]; then
1163                                 echo -n "MDT deactivated also after"
1164                                 echo "$WAIT sec (got $RESULT)"
1165                                 break
1166                         fi
1167                         WAIT=$((WAIT + 5))
1168                         if [ $WAIT -eq $MAX ]; then
1169                                 echo -n "MDT not deactivated: wanted $DEAC"
1170                                 echo  "got $RESULT"
1171                                 return 4
1172                         fi
1173                         echo "Waiting $(($MAX - $WAIT))secs for MDT deactivated"
1174                 done
1175         done
1176         # test new client starts deactivated
1177         umount_client $MOUNT || return 200
1178         mount_client $MOUNT
1179         RESULT=$(lctl get_param -n $PROC_UUID | grep DEACTIV | grep NEW)
1180         if [ -z "$RESULT" ]; then
1181             echo "New client not deactivated from start: $(lctl get_param -n $PROC_UUID)"
1182             return 5
1183         else
1184             echo "New client success: got $RESULT"
1185         fi
1186
1187         # make sure it reactivates
1188         set_conf_param_and_check client \
1189                 "lctl get_param -n $PROC_ACT" "$PARAM" $ACTV || return 6
1190
1191         umount_client $MOUNT
1192         stop_ost2
1193         cleanup_nocli
1194         #writeconf to remove all ost2 traces for subsequent tests
1195         writeconf_or_reformat
1196 }
1197 run_test 29 "permanently remove an OST"
1198
1199 test_30a() {
1200         setup
1201
1202         echo Big config llog
1203         TEST="lctl get_param -n llite.$FSNAME-*.max_read_ahead_whole_mb"
1204         ORIG=$($TEST)
1205         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1206         for i in ${LIST[@]}; do
1207                 set_conf_param_and_check client "$TEST" \
1208                         "$FSNAME.llite.max_read_ahead_whole_mb" $i || return 3
1209         done
1210         # make sure client restart still works
1211         umount_client $MOUNT
1212         mount_client $MOUNT || return 4
1213         [ "$($TEST)" -ne "$i" ] && error "Param didn't stick across restart $($TEST) != $i"
1214         pass
1215
1216         echo Erase parameter setting
1217         do_facet mgs "$LCTL conf_param -d $FSNAME.llite.max_read_ahead_whole_mb" || return 6
1218         umount_client $MOUNT
1219         mount_client $MOUNT || return 6
1220         FINAL=$($TEST)
1221         echo "deleted (default) value=$FINAL, orig=$ORIG"
1222         # assumes this parameter started at the default value
1223         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1224
1225         cleanup
1226 }
1227 run_test 30a "Big config llog and conf_param deletion"
1228
1229 test_30b() {
1230         setup
1231
1232         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1233         # numerical part of it. Hopefully that's not already a failover address for
1234         # the server.
1235         OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
1236         ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1237         NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1238         NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1239         echo "Using fake nid $NEW"
1240
1241         TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1242                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1243         set_conf_param_and_check client "$TEST" \
1244                 "$FSNAME-OST0000.failover.node" $NEW ||
1245                 error "didn't add failover nid $NEW"
1246         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1247                 grep failover_nids)
1248         echo $NIDS
1249         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
1250         echo "should have 2 failover nids: $NIDCOUNT"
1251         [ $NIDCOUNT -eq 2 ] || error "Failover nid not added"
1252         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" ||
1253                 error "conf_param delete failed"
1254         umount_client $MOUNT
1255         mount_client $MOUNT || return 3
1256
1257         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1258                 grep failover_nids)
1259         echo $NIDS
1260         NIDCOUNT=$(($(echo "$NIDS" | wc -w) - 3))
1261         echo "only 1 final nid should remain: $NIDCOUNT"
1262         [ $NIDCOUNT -eq 1 ] || error "Failover nids not removed"
1263
1264         cleanup
1265 }
1266 run_test 30b "Remove failover nids"
1267
1268 test_31() { # bug 10734
1269         # ipaddr must not exist
1270         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1271         cleanup
1272 }
1273 run_test 31 "Connect to non-existent node (shouldn't crash)"
1274
1275
1276 T32_QID=60000
1277 T32_BLIMIT=20480 # Kbytes
1278 T32_ILIMIT=2
1279
1280 #
1281 # This is not really a test but a tool to create new disk
1282 # image tarballs for the upgrade tests.
1283 #
1284 # Disk image tarballs should be created on single-node
1285 # clusters by running this test with default configurations
1286 # plus a few mandatory environment settings that are verified
1287 # at the beginning of the test.
1288 #
1289 test_32newtarball() {
1290         local version
1291         local dst=.
1292         local src=/etc/rc.d
1293         local tmp=$TMP/t32_image_create
1294
1295         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1296                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1297                  -z "$OSTDEV1" ]; then
1298                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1299                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1300                           "OSTDEV1=<nonexistent_file>"
1301         fi
1302
1303         mkdir $tmp || {
1304                 echo "Found stale $tmp"
1305                 return 1
1306         }
1307
1308         mkdir $tmp/src
1309         tar cf - -C $src . | tar xf - -C $tmp/src
1310         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1311                 count=$(($T32_BLIMIT / 1024 / 2))
1312         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1313
1314         # format ost with comma-separated NIDs to verify LU-4460
1315         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
1316         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1317
1318         setupall
1319
1320         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1321                 $LFS quotacheck -ug /mnt/$FSNAME
1322         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1323                 /mnt/$FSNAME
1324
1325         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1326         stopall
1327
1328         mkdir $tmp/img
1329
1330         setupall
1331         pushd /mnt/$FSNAME
1332         ls -Rni --time-style=+%s >$tmp/img/list
1333         find . ! -name .lustre -type f -exec sha1sum {} \; |
1334                 sort -k 2 >$tmp/img/sha1sums
1335         popd
1336         $LCTL get_param -n version | head -n 1 |
1337                 sed -e 's/^lustre: *//' >$tmp/img/commit
1338
1339         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1340                 $LFS quotaon -ug /mnt/$FSNAME
1341         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1342         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1343                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1344                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1345                 | tr -d "*" > $tmp/img/bspace
1346         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1347                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1348                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1349                 | tr -d "*" > $tmp/img/ispace
1350
1351         stopall
1352
1353         pushd $tmp/src
1354         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1355         popd
1356
1357         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1358                 echo "Data verification failed"
1359         fi
1360
1361         uname -r >$tmp/img/kernel
1362         uname -m >$tmp/img/arch
1363
1364         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1365         mv $OSTDEV1 $tmp/img
1366
1367         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1368                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1369         dst=$(cd $dst; pwd)
1370         pushd $tmp/img
1371         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1372         popd
1373
1374         rm -r $tmp
1375 }
1376 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1377
1378 #
1379 # The list of applicable tarballs is returned via the caller's
1380 # variable "tarballs".
1381 #
1382 t32_check() {
1383         local node=$(facet_active_host $SINGLEMDS)
1384         local r="do_node $node"
1385
1386         if [ "$CLIENTONLY" ]; then
1387                 skip "Client-only testing"
1388                 exit 0
1389         fi
1390
1391         if ! $r which $TUNEFS; then
1392                 skip_env "tunefs.lustre required on $node"
1393                 exit 0
1394         fi
1395
1396         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1397
1398         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1399
1400         if [ -z "$tarballs" ]; then
1401                 skip "No applicable tarballs found"
1402                 exit 0
1403         fi
1404 }
1405
1406 t32_test_cleanup() {
1407         local tmp=$TMP/t32
1408         local fstype=$(facet_fstype $SINGLEMDS)
1409         local rc=$?
1410
1411         if $shall_cleanup_lustre; then
1412                 umount $tmp/mnt/lustre || rc=$?
1413         fi
1414         if $shall_cleanup_mdt; then
1415                 $r umount -d $tmp/mnt/mdt || rc=$?
1416         fi
1417         if $shall_cleanup_mdt1; then
1418                 $r umount -d $tmp/mnt/mdt1 || rc=$?
1419         fi
1420         if $shall_cleanup_ost; then
1421                 $r umount -d $tmp/mnt/ost || rc=$?
1422         fi
1423
1424         $r rm -rf $tmp
1425         rm -rf $tmp
1426         if [ $fstype == "zfs" ]; then
1427                 $r $ZPOOL destroy t32fs-mdt1 || rc=$?
1428                 $r $ZPOOL destroy t32fs-ost1 || rc=$?
1429         fi
1430         return $rc
1431 }
1432
1433 t32_bits_per_long() {
1434         #
1435         # Yes, this is not meant to be perfect.
1436         #
1437         case $1 in
1438                 ppc64|x86_64)
1439                         echo -n 64;;
1440                 i*86)
1441                         echo -n 32;;
1442         esac
1443 }
1444
1445 t32_reload_modules() {
1446         local node=$1
1447         local all_removed=false
1448         local i=0
1449
1450         while ((i < 20)); do
1451                 echo "Unloading modules on $node: Attempt $i"
1452                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1453                         all_removed=true
1454                 do_rpc_nodes $node check_mem_leak || return 1
1455                 if $all_removed; then
1456                         do_rpc_nodes $node load_modules
1457                         return 0
1458                 fi
1459                 sleep 5
1460                 i=$((i + 1))
1461         done
1462         echo "Unloading modules on $node: Given up"
1463         return 1
1464 }
1465
1466 t32_wait_til_devices_gone() {
1467         local node=$1
1468         local devices
1469         local loops
1470         local i=0
1471
1472         echo wait for devices to go
1473         while ((i < 20)); do
1474                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1475                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1476                 ((devices == 0 && loops == 0)) && return 0
1477                 sleep 5
1478                 i=$((i + 1))
1479         done
1480         echo "waiting for dev on $node: dev $devices loop $loops given up"
1481         do_rpc_nodes $node "losetup -a"
1482         do_rpc_nodes $node "$LCTL devices_list"
1483         return 1
1484 }
1485
1486 t32_verify_quota() {
1487         local node=$1
1488         local fsname=$2
1489         local mnt=$3
1490         local fstype=$(facet_fstype $SINGLEMDS)
1491         local qval
1492         local cmd
1493
1494         $LFS quota -u $T32_QID -v $mnt
1495
1496         qval=$($LFS quota -v -u $T32_QID $mnt |
1497                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1498                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1499                 | tr -d "*")
1500         [ $qval -eq $img_bspace ] || {
1501                 echo "bspace, act:$qval, exp:$img_bspace"
1502                 return 1
1503         }
1504
1505         qval=$($LFS quota -v -u $T32_QID $mnt |
1506                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1507                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1508                 | tr -d "*")
1509         [ $qval -eq $img_ispace ] || {
1510                 echo "ispace, act:$qval, exp:$img_ispace"
1511                 return 1
1512         }
1513
1514         qval=$($LFS quota -v -u $T32_QID $mnt |
1515                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1516                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1517                 | tr -d "*")
1518         [ $qval -eq $T32_BLIMIT ] || {
1519                 echo "blimit, act:$qval, exp:$T32_BLIMIT"
1520                 return 1
1521         }
1522
1523         qval=$($LFS quota -v -u $T32_QID $mnt |
1524                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1525                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1526                 | tr -d "*")
1527         [ $qval -eq $T32_ILIMIT ] || {
1528                 echo "ilimit, act:$qval, exp:$T32_ILIMIT"
1529                 return 1
1530         }
1531
1532         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1533         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1534         cmd=$cmd.quota_slave.enabled
1535         wait_update $node "$cmd" "ug" || {
1536                 echo "Enable mdt quota failed"
1537                 return 1
1538         }
1539
1540         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1541         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1542         cmd=$cmd.quota_slave.enabled
1543         wait_update $node "$cmd" "ug" || {
1544                 echo "Enable ost quota failed"
1545                 return 1
1546         }
1547
1548         chmod 0777 $mnt
1549         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1550                 bs=1M count=$(($T32_BLIMIT / 1024)) oflag=sync && {
1551                 echo "Write succeed, but expect -EDQUOT"
1552                 return 1
1553         }
1554         rm -f $mnt/t32_qf_new
1555
1556         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1557                 $T32_ILIMIT && {
1558                 echo "Create succeed, but expect -EDQUOT"
1559                 return 1
1560         }
1561         unlinkmany $mnt/t32_qf_ $T32_ILIMIT
1562
1563         return 0
1564 }
1565
1566 t32_test() {
1567         local tarball=$1
1568         local writeconf=$2
1569         local dne_upgrade=${dne_upgrade:-"no"}
1570         local ff_convert=${ff_convert:-"no"}
1571         local shall_cleanup_mdt=false
1572         local shall_cleanup_mdt1=false
1573         local shall_cleanup_ost=false
1574         local shall_cleanup_lustre=false
1575         local node=$(facet_active_host $SINGLEMDS)
1576         local r="do_node $node"
1577         local node2=$(facet_active_host mds2)
1578         local tmp=$TMP/t32
1579         local img_commit
1580         local img_kernel
1581         local img_arch
1582         local img_bspace
1583         local img_ispace
1584         local fsname=t32fs
1585         local nid=$($r $LCTL list_nids | head -1)
1586         local mopts
1587         local uuid
1588         local nrpcs_orig
1589         local nrpcs
1590         local list
1591         local fstype=$(facet_fstype $SINGLEMDS)
1592         local mdt_dev=$tmp/mdt
1593         local ost_dev=$tmp/ost
1594
1595         trap 'trap - RETURN; t32_test_cleanup' RETURN
1596
1597         mkdir -p $tmp/mnt/lustre
1598         $r mkdir -p $tmp/mnt/{mdt,ost}
1599         $r tar xjvf $tarball -S -C $tmp || {
1600                 error_noexit "Unpacking the disk image tarball"
1601                 return 1
1602         }
1603         img_commit=$($r cat $tmp/commit)
1604         img_kernel=$($r cat $tmp/kernel)
1605         img_arch=$($r cat $tmp/arch)
1606         img_bspace=$($r cat $tmp/bspace)
1607         img_ispace=$($r cat $tmp/ispace)
1608         echo "Upgrading from $(basename $tarball), created with:"
1609         echo "  Commit: $img_commit"
1610         echo "  Kernel: $img_kernel"
1611         echo "    Arch: $img_arch"
1612         echo "OST version: $(get_lustre_version ost1)"
1613
1614         # The convertion can be made only when both of the following
1615         # conditions are satisfied:
1616         # - client img version < 2.3.64
1617         # - ost server version >= 2.5
1618         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
1619                 $(lustre_version_code ost1) -lt $(version_code 2.5.0) ] &&
1620                         ff_convert="no"
1621
1622         if [ $fstype == "zfs" ]; then
1623                 # import pool first
1624                 $r $ZPOOL import -f -d $tmp t32fs-mdt1
1625                 $r $ZPOOL import -f -d $tmp t32fs-ost1
1626                 mdt_dev=t32fs-mdt1/mdt1
1627                 ost_dev=t32fs-ost1/ost1
1628                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1629                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1630                                 error_noexit "import zfs pool failed"
1631                                 return 1
1632                         }
1633         fi
1634
1635         $r $LCTL set_param debug="$PTLDEBUG"
1636
1637         $r $TUNEFS --dryrun $mdt_dev || {
1638                 $r losetup -a
1639                 error_noexit "tunefs.lustre before mounting the MDT"
1640                 return 1
1641         }
1642         if [ "$writeconf" ]; then
1643                 mopts=writeconf
1644                 if [ $fstype == "ldiskfs" ]; then
1645                         mopts="loop,$mopts"
1646                         $r $TUNEFS --quota $mdt_dev || {
1647                                 $r losetup -a
1648                                 error_noexit "Enable mdt quota feature"
1649                                 return 1
1650                         }
1651                 fi
1652         else
1653                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1654                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1655                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1656                                 "(Need MGS version at least 2.3.59)"; return 0; }
1657
1658                         local osthost=$(facet_active_host ost1)
1659                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1660
1661                         mopts=nosvc
1662                         if [ $fstype == "ldiskfs" ]; then
1663                                 mopts="loop,$mopts"
1664                         fi
1665                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1666                         $r lctl replace_nids $fsname-OST0000 $ostnid
1667                         $r lctl replace_nids $fsname-MDT0000 $nid
1668                         $r umount -d $tmp/mnt/mdt
1669                 fi
1670
1671                 mopts=exclude=$fsname-OST0000
1672                 if [ $fstype == "ldiskfs" ]; then
1673                         mopts="loop,$mopts"
1674                 fi
1675         fi
1676
1677         t32_wait_til_devices_gone $node
1678
1679         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1680                 $r losetup -a
1681                 error_noexit "Mounting the MDT"
1682                 return 1
1683         }
1684         shall_cleanup_mdt=true
1685
1686         if [ "$dne_upgrade" != "no" ]; then
1687                 local fs2mdsdev=$(mdsdevname 1_2)
1688                 local fs2mdsvdev=$(mdsvdevname 1_2)
1689
1690                 echo "mkfs new MDT on ${fs2mdsdev}...."
1691                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1692                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1693                 fi
1694
1695                 add fs2mds $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1696                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1697                         error_noexit "Mkfs new MDT failed"
1698                         return 1
1699                 }
1700
1701                 $r $TUNEFS --dryrun $fs2mdsdev || {
1702                         error_noexit "tunefs.lustre before mounting the MDT"
1703                         return 1
1704                 }
1705
1706                 echo "mount new MDT....$fs2mdsdev"
1707                 $r mkdir -p $tmp/mnt/mdt1
1708                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1709                         error_noexit "mount mdt1 failed"
1710                         return 1
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_24a 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 ost1 ${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         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2417                 skip "Only applicable to ldiskfs-based MDTs"
2418                 return
2419         fi
2420
2421         setup
2422         # like runtests
2423         COUNT=10
2424         SRC="/etc /bin"
2425         FILES=`find $SRC -type f -mtime +1 | head -n $COUNT`
2426         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2427         mkdir -p $DIR/$tdir
2428         tar cf - $FILES | tar xf - -C $DIR/$tdir || \
2429                 error "copying $SRC to $DIR/$tdir"
2430         sync
2431         umount_client $MOUNT
2432         stop_mds
2433         log "rename lov_objid file on MDS"
2434         rm -f $TMP/lov_objid.orig
2435
2436         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2437         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.orig\\\" $MDSDEV"
2438         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2439
2440         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.orig"
2441         # check create in mds_lov_connect
2442         start_mds
2443         mount_client $MOUNT
2444         for f in $FILES; do
2445                 [ $V ] && log "verifying $DIR/$tdir/$f"
2446                 diff -q $f $DIR/$tdir/$f || ERROR=y
2447         done
2448         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new\\\"  $MDSDEV"
2449         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new"
2450         [ "$ERROR" = "y" ] && error "old and new files are different after connect" || true
2451
2452         # check it's updates in sync
2453         umount_client $MOUNT
2454         stop_mds
2455
2456         do_facet $SINGLEMDS dd if=/dev/zero of=$TMP/lov_objid.clear bs=4096 count=1
2457         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"rm lov_objid\\\" $MDSDEV"
2458         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"write $TMP/lov_objid.clear lov_objid\\\" $MDSDEV "
2459
2460         start_mds
2461         mount_client $MOUNT
2462         for f in $FILES; do
2463                 [ $V ] && log "verifying $DIR/$tdir/$f"
2464                 diff -q $f $DIR/$tdir/$f || ERROR=y
2465         done
2466         do_facet $SINGLEMDS "$DEBUGFS -c -R \\\"dump lov_objid $TMP/lov_objid.new1\\\" $MDSDEV"
2467         do_facet $SINGLEMDS "od -Ax -td8 $TMP/lov_objid.new1"
2468         umount_client $MOUNT
2469         stop_mds
2470         [ "$ERROR" = "y" ] && error "old and new files are different after sync" || true
2471
2472         log "files compared the same"
2473         cleanup
2474 }
2475 run_test 38 "MDS recreates missing lov_objid file from OST data"
2476
2477 test_39() {
2478         PTLDEBUG=+malloc
2479         setup
2480         cleanup
2481         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2482                 error "memory leak detected" || true
2483 }
2484 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2485
2486 test_40() { # bug 15759
2487         start_ost
2488         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2489         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2490         start_mds
2491         cleanup
2492 }
2493 run_test 40 "race during service thread startup"
2494
2495 test_41a() { #bug 14134
2496         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2497            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2498                 skip "Loop devices does not work with nosvc option"
2499                 return
2500         fi
2501
2502         local rc
2503         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2504
2505         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2506         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
2507         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2508         mkdir -p $MOUNT
2509         mount_client $MOUNT || return 1
2510         sleep 5
2511
2512         echo "blah blah" > $MOUNT/$tfile
2513         cat $MOUNT/$tfile
2514
2515         umount_client $MOUNT
2516         stop ost1 -f || return 201
2517         stop_mds -f || return 202
2518         stop_mds -f || return 203
2519         unload_modules_conf || return 204
2520         return $rc
2521 }
2522 run_test 41a "mount mds with --nosvc and --nomgs"
2523
2524 test_41b() {
2525         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2526            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2527                 skip "Loop devices does not work with nosvc option"
2528                 return
2529         fi
2530
2531         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2532
2533         stopall
2534         reformat
2535         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2536
2537         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nosvc -n
2538         start_ost
2539         start $SINGLEMDS $MDSDEV $MDS_MOUNT_OPTS -o nomgs,force
2540         mkdir -p $MOUNT
2541         mount_client $MOUNT || return 1
2542         sleep 5
2543
2544         echo "blah blah" > $MOUNT/$tfile
2545         cat $MOUNT/$tfile || return 200
2546
2547         umount_client $MOUNT
2548         stop_ost || return 201
2549         stop_mds -f || return 202
2550         stop_mds -f || return 203
2551
2552 }
2553 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2554
2555 test_41c() {
2556         local server_version=$(lustre_version_code $SINGLEMDS)
2557
2558         [[ $server_version -ge $(version_code 2.6.52) ]] ||
2559         [[ $server_version -ge $(version_code 2.5.26) &&
2560            $server_version -lt $(version_code 2.5.50) ]] ||
2561         [[ $server_version -ge $(version_code 2.5.3) &&
2562            $server_version -lt $(version_code 2.5.11) ]] ||
2563                 { skip "Need MDS version 2.5.4+ or 2.5.26+ or 2.6.52+"; return; }
2564
2565         cleanup
2566         # MDT concurent start
2567         #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
2568         do_facet $SINGLEMDS "lctl set_param fail_loc=0x703"
2569         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
2570         local pid=$!
2571         sleep 2
2572         do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
2573         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
2574         local pid2=$!
2575         wait $pid2
2576         local rc2=$?
2577         wait $pid
2578         local rc=$?
2579         if [ $rc == 0 ] && [ $rc2 == 114 ]; then
2580                 echo "1st MDT start succeed"
2581                 echo "2nd MDT start failed with EALREADY"
2582         elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
2583                 echo "1st MDT start failed with EALREADY"
2584                 echo "2nd MDT start succeed"
2585         else
2586                 stop mds1 -f
2587                 error "unexpected concurent MDT mounts result, rc=$rc rc2=$rc2"
2588         fi
2589
2590         # OST concurent start
2591         #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
2592         do_facet ost1 "lctl set_param fail_loc=0x703"
2593         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
2594         pid=$!
2595         sleep 2
2596         do_facet ost1 "lctl set_param fail_loc=0x0"
2597         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
2598         pid2=$!
2599         wait $pid2
2600         rc2=$?
2601         wait $pid
2602         rc=$?
2603         if [ $rc == 0 ] && [ $rc2 == 114 ]; then
2604                 echo "1st OST start succeed"
2605                 echo "2nd OST start failed with EALREADY"
2606         elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
2607                 echo "1st OST start failed with EALREADY"
2608                 echo "2nd OST start succeed"
2609         else
2610                 stop mds1 -f
2611                 stop ost1 -f
2612                 error "unexpected concurent OST mounts result, rc=$rc rc2=$rc2"
2613         fi
2614         # cleanup
2615         stop mds1 -f
2616         stop ost1 -f
2617
2618         # verify everything ok
2619         start_mds
2620         if [ $? != 0 ]
2621         then
2622                 stop mds1 -f
2623                 error "MDT(s) start failed"
2624         fi
2625
2626         start_ost
2627         if [ $? != 0 ]
2628         then
2629                 stop mds1 -f
2630                 stop ost1 -f
2631                 error "OST(s) start failed"
2632         fi
2633
2634         mount_client $MOUNT
2635         if [ $? != 0 ]
2636         then
2637                 stop mds1 -f
2638                 stop ost1 -f
2639                 error "client start failed"
2640         fi
2641         check_mount
2642         if [ $? != 0 ]
2643         then
2644                 stop mds1 -f
2645                 stop ost1 -f
2646                 error "client mount failed"
2647         fi
2648         cleanup
2649 }
2650 run_test 41c "concurent mounts of MDT/OST should all fail but one"
2651
2652 test_42() { #bug 14693
2653         setup
2654         check_mount || error "client was not mounted"
2655
2656         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
2657         umount_client $MOUNT ||
2658                 error "unmounting client failed with invalid llite param"
2659         mount_client $MOUNT ||
2660                 error "mounting client failed with invalid llite param"
2661
2662         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
2663         cleanup || error "stopping $FSNAME failed with invalid sys param"
2664         load_modules
2665         setup
2666         check_mount || "client was not mounted with invalid sys param"
2667         cleanup || error "stopping $FSNAME failed with invalid sys param"
2668         return 0
2669 }
2670 run_test 42 "allow client/server mount/unmount with invalid config param"
2671
2672 test_43() {
2673         local server_version=$(lustre_version_code $SINGLEMDS)
2674
2675         [[ $server_version -ge $(version_code 2.5.59) ]] ||
2676         [[ $server_version -ge $(version_code 2.5.3) &&
2677            $server_version -lt $(version_code 2.5.11) ]] ||
2678                 { skip "Need MDS version 2.5.4+ or 2.5.59+"; return; }
2679
2680         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2681
2682         ID1=${ID1:-501}
2683         USER1=$(cat /etc/passwd | grep :$ID1:$ID1: | cut -d: -f1)
2684         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
2685                 return
2686
2687         setup
2688         chmod ugo+x $DIR || error "chmod 0 failed"
2689         set_conf_param_and_check mds                                    \
2690                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2691                 "$FSNAME.mdt.root_squash"                               \
2692                 "0:0"
2693         wait_update $HOSTNAME                                           \
2694                 "lctl get_param -n llite.${FSNAME}*.root_squash"        \
2695                 "0:0" ||
2696                 error "check llite root_squash failed!"
2697         set_conf_param_and_check mds                                    \
2698                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2699                 "$FSNAME.mdt.nosquash_nids"                             \
2700                 "NONE"
2701         wait_update $HOSTNAME                                           \
2702                 "lctl get_param -n llite.${FSNAME}*.nosquash_nids"      \
2703                 "NONE" ||
2704                 error "check llite nosquash_nids failed!"
2705
2706     #
2707     # create set of test files
2708     #
2709     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2710     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2711     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2712
2713     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2714     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2715
2716     mkdir $DIR/$tdir-rootdir -p       || error "mkdir failed"
2717     chmod go-rwx $DIR/$tdir-rootdir   || error "chmod 3 failed"
2718     touch $DIR/$tdir-rootdir/tfile-1  || error "touch failed"
2719
2720         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
2721         chmod go-rw $DIR/$tfile-user1file  || error "chmod 7 failed"
2722         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
2723
2724         #
2725         # check root_squash:
2726         #   set root squash UID:GID to RUNAS_ID
2727         #   root should be able to access only files owned by RUNAS_ID
2728         #
2729         set_conf_param_and_check mds                                    \
2730                 "lctl get_param -n mdt.$FSNAME-MDT0000.root_squash"     \
2731                 "$FSNAME.mdt.root_squash"                               \
2732                 "$RUNAS_ID:$RUNAS_ID"
2733         wait_update $HOSTNAME                                           \
2734                 "lctl get_param -n llite.${FSNAME}*.root_squash"        \
2735                 "$RUNAS_ID:$RUNAS_ID" ||
2736                 error "check llite root_squash failed!"
2737
2738     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2739     dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2740         error "$ST: root read permission is denied"
2741     echo "$ST: root read permission is granted - ok"
2742
2743     echo "444" | \
2744     dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null || \
2745         error "$ST: root write permission is denied"
2746     echo "$ST: root write permission is granted - ok"
2747
2748     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2749     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2750         error "$ST: root read permission is granted"
2751     echo "$ST: root read permission is denied - ok"
2752
2753     echo "555" | \
2754     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null && \
2755         error "$ST: root write permission is granted"
2756     echo "$ST: root write permission is denied - ok"
2757
2758     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2759     rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null && \
2760         error "$ST: root unlink permission is granted"
2761     echo "$ST: root unlink permission is denied - ok"
2762
2763     touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null && \
2764         error "$ST: root create permission is granted"
2765     echo "$ST: root create permission is denied - ok"
2766
2767
2768         # LU-1778
2769         # check root_squash is enforced independently
2770         # of client cache content
2771         #
2772         # access file by USER1, keep access open
2773         # root should be denied access to user file
2774
2775         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
2776         pid=$!
2777         sleep 1
2778
2779         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
2780         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2781             { kill $pid; error "$ST: root read permission is granted"; }
2782         echo "$ST: root read permission is denied - ok"
2783
2784         echo "777" | \
2785         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2786             { kill $pid; error "$ST: root write permission is granted"; }
2787         echo "$ST: root write permission is denied - ok"
2788
2789         kill $pid
2790         wait $pid
2791
2792         #
2793         # check nosquash_nids:
2794         #   put client's NID into nosquash_nids list,
2795         #   root should be able to access root file after that
2796         #
2797         local NIDLIST=$(lctl list_nids all | tr '\n' ' ')
2798         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2799         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2800         set_conf_param_and_check mds                                    \
2801                 "lctl get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"   \
2802                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2803                 "$NIDLIST"
2804         wait_update $HOSTNAME                                           \
2805                 "lctl get_param -n llite.${FSNAME}*.nosquash_nids"      \
2806                 "$NIDLIST" ||
2807                 error "check llite nosquash_nids failed!"
2808
2809     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2810     dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2811         error "$ST: root read permission is denied"
2812     echo "$ST: root read permission is granted - ok"
2813
2814     echo "666" | \
2815     dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null || \
2816         error "$ST: root write permission is denied"
2817     echo "$ST: root write permission is granted - ok"
2818
2819     ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2820     rm $DIR/$tdir-rootdir/tfile-1 || \
2821         error "$ST: root unlink permission is denied"
2822     echo "$ST: root unlink permission is granted - ok"
2823     touch $DIR/$tdir-rootdir/tfile-2 || \
2824         error "$ST: root create permission is denied"
2825     echo "$ST: root create permission is granted - ok"
2826
2827     return 0
2828 }
2829 run_test 43 "check root_squash and nosquash_nids"
2830
2831 umount_client $MOUNT
2832 cleanup_nocli
2833
2834 test_44() { # 16317
2835         setup
2836         check_mount || return 2
2837         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2838         STATS_FOUND=no
2839         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2840         for VAL in $UUIDS; do
2841                 NID=$(echo $VAL | cut -d= -f1)
2842                 CLUUID=$(echo $VAL | cut -d= -f2)
2843                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2844         done
2845         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2846         cleanup
2847         return 0
2848 }
2849 run_test 44 "mounted client proc entry exists"
2850
2851 test_45() { #17310
2852         setup
2853         check_mount || return 2
2854         stop_mds
2855         df -h $MOUNT &
2856         log "sleep 60 sec"
2857         sleep 60
2858 #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2859         do_facet client "lctl set_param fail_loc=0x50f"
2860         log "sleep 10 sec"
2861         sleep 10
2862         manual_umount_client --force || return 3
2863         do_facet client "lctl set_param fail_loc=0x0"
2864         start_mds
2865         mount_client $MOUNT || return 4
2866         cleanup
2867         return 0
2868 }
2869 run_test 45 "long unlink handling in ptlrpcd"
2870
2871 cleanup_46a() {
2872         trap 0
2873         local rc=0
2874         local count=$1
2875
2876         umount_client $MOUNT2 || rc=$?
2877         umount_client $MOUNT || rc=$?
2878         while [ $count -gt 0 ]; do
2879                 stop ost${count} -f || rc=$?
2880                 let count=count-1
2881         done    
2882         stop_mds || rc=$?
2883         cleanup_nocli || rc=$?
2884         #writeconf to remove all ost2 traces for subsequent tests
2885         writeconf_or_reformat
2886         return $rc
2887 }
2888
2889 test_46a() {
2890         echo "Testing with $OSTCOUNT OSTs"
2891         reformat_and_config
2892         start_mds || return 1
2893         #first client should see only one ost
2894         start_ost || return 2
2895         wait_osc_import_state mds ost FULL
2896         #start_client
2897         mount_client $MOUNT || return 3
2898         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2899
2900         local i
2901         for (( i=2; i<=$OSTCOUNT; i++ )); do
2902             start ost$i `ostdevname $i` $OST_MOUNT_OPTS || return $((i+2))
2903         done
2904
2905         # wait until osts in sync
2906         for (( i=2; i<=$OSTCOUNT; i++ )); do
2907             wait_osc_import_state mds ost$i FULL
2908             wait_osc_import_state client ost$i FULL
2909         done
2910
2911         #second client see all ost's
2912
2913         mount_client $MOUNT2 || return 8
2914         $LFS setstripe -c -1 $MOUNT2 || return 9
2915         $LFS getstripe $MOUNT2 || return 10
2916
2917         echo "ok" > $MOUNT2/widestripe
2918         $LFS getstripe $MOUNT2/widestripe || return 11
2919         # fill acl buffer for avoid expand lsm to them
2920         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd | while read acl; do
2921             setfacl -m $acl $MOUNT2/widestripe
2922         done
2923
2924         # will be deadlock
2925         stat $MOUNT/widestripe || return 12
2926
2927         cleanup_46a $OSTCOUNT || { echo "cleanup_46a failed!" && return 13; }
2928         return 0
2929 }
2930 run_test 46a "handle ost additional - wide striped file"
2931
2932 test_47() { #17674
2933         reformat
2934         setup_noconfig
2935         check_mount || return 2
2936         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
2937
2938         local lru_size=[]
2939         local count=0
2940         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2941             if echo $ns | grep "MDT[[:digit:]]*"; then
2942                 continue
2943             fi
2944             lrs=$(echo $ns | sed 's/.*lru_size=//')
2945             lru_size[count]=$lrs
2946             let count=count+1
2947         done
2948
2949         facet_failover ost1
2950         facet_failover $SINGLEMDS
2951         client_up || return 3
2952
2953         count=0
2954         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
2955             if echo $ns | grep "MDT[[:digit:]]*"; then
2956                 continue
2957             fi
2958             lrs=$(echo $ns | sed 's/.*lru_size=//')
2959             if ! test "$lrs" -eq "${lru_size[count]}"; then
2960                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
2961                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
2962             fi
2963             let count=count+1
2964         done
2965
2966         cleanup
2967         return 0
2968 }
2969 run_test 47 "server restart does not make client loss lru_resize settings"
2970
2971 cleanup_48() {
2972         trap 0
2973
2974         # reformat after this test is needed - if test will failed
2975         # we will have unkillable file at FS
2976         reformat_and_config
2977 }
2978
2979 test_48() { # bug 17636
2980         reformat
2981         setup_noconfig
2982         check_mount || return 2
2983
2984         $LFS setstripe -c -1 $MOUNT || return 9
2985         $LFS getstripe $MOUNT || return 10
2986
2987         echo "ok" > $MOUNT/widestripe
2988         $LFS getstripe $MOUNT/widestripe || return 11
2989
2990         trap cleanup_48 EXIT ERR
2991
2992         # fill acl buffer for avoid expand lsm to them
2993         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
2994             setfacl -m $acl $MOUNT/widestripe
2995         done
2996
2997         stat $MOUNT/widestripe || return 12
2998
2999         cleanup_48
3000         return 0
3001 }
3002 run_test 48 "too many acls on file"
3003
3004 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
3005 test_49() { # bug 17710
3006         local timeout_orig=$TIMEOUT
3007         local ldlm_timeout_orig=$LDLM_TIMEOUT
3008         local LOCAL_TIMEOUT=20
3009
3010         LDLM_TIMEOUT=$LOCAL_TIMEOUT
3011         TIMEOUT=$LOCAL_TIMEOUT
3012
3013         reformat
3014         setup_noconfig
3015         check_mount || return 1
3016
3017         echo "check ldlm_timout..."
3018         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
3019         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
3020         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
3021
3022         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
3023                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3024         fi
3025
3026         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
3027                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
3028         fi
3029
3030         umount_client $MOUNT
3031         stop_ost || return 2
3032         stop_mds || return 3
3033
3034         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
3035
3036         reformat
3037         setup_noconfig
3038         check_mount || return 7
3039
3040         LDLM_MDS="`do_facet $SINGLEMDS lctl get_param -n ldlm_timeout`"
3041         LDLM_OST1="`do_facet ost1 lctl get_param -n ldlm_timeout`"
3042         LDLM_CLIENT="`do_facet client lctl get_param -n ldlm_timeout`"
3043
3044         if [ $LDLM_MDS -ne $LDLM_OST1 ] || [ $LDLM_MDS -ne $LDLM_CLIENT ]; then
3045                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3046         fi
3047
3048         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
3049                 error "LDLM_TIMEOUT($LDLM_MDS) is not correct"
3050         fi
3051
3052         cleanup || return $?
3053
3054         LDLM_TIMEOUT=$ldlm_timeout_orig
3055         TIMEOUT=$timeout_orig
3056 }
3057 run_test 49 "check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE"
3058
3059 lazystatfs() {
3060         # Test both statfs and lfs df and fail if either one fails
3061         multiop_bg_pause $1 f_
3062         RC1=$?
3063         PID=$!
3064         killall -USR1 multiop
3065         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
3066         wait $PID || { RC1=$?; log "multiop return error "; }
3067
3068         $LFS df &
3069         PID=$!
3070         sleep 5
3071         kill -s 0 $PID
3072         RC2=$?
3073         if [ $RC2 -eq 0 ]; then
3074             kill -s 9 $PID
3075             log "lazystatfs df failed"
3076         fi
3077
3078         RC=0
3079         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
3080         return $RC
3081 }
3082
3083 test_50a() {
3084         setup
3085         lctl set_param llite.$FSNAME-*.lazystatfs=1
3086         touch $DIR/$tfile
3087
3088         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3089
3090         cleanup || return $?
3091 }
3092 run_test 50a "lazystatfs all servers available =========================="
3093
3094 test_50b() {
3095         setup
3096         lctl set_param llite.$FSNAME-*.lazystatfs=1
3097         touch $DIR/$tfile
3098
3099         # Wait for client to detect down OST
3100         stop_ost || error "Unable to stop OST1"
3101         wait_osc_import_state mds ost DISCONN
3102
3103         lazystatfs $MOUNT || error "lazystatfs should don't have returned EIO"
3104
3105         umount_client $MOUNT || error "Unable to unmount client"
3106         stop_mds || error "Unable to stop MDS"
3107 }
3108 run_test 50b "lazystatfs all servers down =========================="
3109
3110 test_50c() {
3111         start_mds || error "Unable to start MDS"
3112         start_ost || error "Unable to start OST1"
3113         start_ost2 || error "Unable to start OST2"
3114         mount_client $MOUNT || error "Unable to mount client"
3115         lctl set_param llite.$FSNAME-*.lazystatfs=1
3116         touch $DIR/$tfile
3117
3118         # Wait for client to detect down OST
3119         stop_ost || error "Unable to stop OST1"
3120         wait_osc_import_state mds ost DISCONN
3121         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3122
3123         umount_client $MOUNT || error "Unable to unmount client"
3124         stop_ost2 || error "Unable to stop OST2"
3125         stop_mds || error "Unable to stop MDS"
3126         #writeconf to remove all ost2 traces for subsequent tests
3127         writeconf_or_reformat
3128 }
3129 run_test 50c "lazystatfs one server down =========================="
3130
3131 test_50d() {
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         # Issue the statfs during the window where the client still
3140         # belives the OST to be available but it is in fact down.
3141         # No failure just a statfs which hangs for a timeout interval.
3142         stop_ost || error "Unable to stop OST1"
3143         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3144
3145         umount_client $MOUNT || error "Unable to unmount client"
3146         stop_ost2 || error "Unable to stop OST2"
3147         stop_mds || error "Unable to stop MDS"
3148         #writeconf to remove all ost2 traces for subsequent tests
3149         writeconf_or_reformat
3150 }
3151 run_test 50d "lazystatfs client/server conn race =========================="
3152
3153 test_50e() {
3154         local RC1
3155         local pid
3156
3157         reformat_and_config
3158         start_mds || return 1
3159         #first client should see only one ost
3160         start_ost || return 2
3161         wait_osc_import_state mds ost FULL
3162
3163         # Wait for client to detect down OST
3164         stop_ost || error "Unable to stop OST1"
3165         wait_osc_import_state mds ost DISCONN
3166
3167         mount_client $MOUNT || error "Unable to mount client"
3168         lctl set_param llite.$FSNAME-*.lazystatfs=0
3169
3170         multiop_bg_pause $MOUNT _f
3171         RC1=$?
3172         pid=$!
3173
3174         if [ $RC1 -ne 0 ]; then
3175                 log "multiop failed $RC1"
3176         else
3177             kill -USR1 $pid
3178             sleep $(( $TIMEOUT+1 ))
3179             kill -0 $pid
3180             [ $? -ne 0 ] && error "process isn't sleep"
3181             start_ost || error "Unable to start OST1"
3182             wait $pid || error "statfs failed"
3183         fi
3184
3185         umount_client $MOUNT || error "Unable to unmount client"
3186         stop_ost || error "Unable to stop OST1"
3187         stop_mds || error "Unable to stop MDS"
3188 }
3189 run_test 50e "normal statfs all servers down =========================="
3190
3191 test_50f() {
3192         local RC1
3193         local pid
3194         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
3195
3196         start_mds || error "Unable to start mds"
3197         #first client should see only one ost
3198         start_ost || error "Unable to start OST1"
3199         wait_osc_import_state mds ost FULL
3200
3201         start_ost2 || error "Unable to start OST2"
3202         wait_osc_import_state mds ost2 FULL
3203
3204         # Wait for client to detect down OST
3205         stop_ost2 || error "Unable to stop OST2"
3206
3207         wait_osc_import_state mds ost2 DISCONN
3208         mount_client $MOUNT || error "Unable to mount client"
3209         lctl set_param llite.$FSNAME-*.lazystatfs=0
3210
3211         multiop_bg_pause $MOUNT _f
3212         RC1=$?
3213         pid=$!
3214
3215         if [ $RC1 -ne 0 ]; then
3216                 log "lazystatfs multiop failed $RC1"
3217         else
3218             kill -USR1 $pid
3219             sleep $(( $TIMEOUT+1 ))
3220             kill -0 $pid
3221             [ $? -ne 0 ] && error "process isn't sleep"
3222             start_ost2 || error "Unable to start OST2"
3223             wait $pid || error "statfs failed"
3224             stop_ost2 || error "Unable to stop OST2"
3225         fi
3226
3227         umount_client $MOUNT || error "Unable to unmount client"
3228         stop_ost || error "Unable to stop OST1"
3229         stop_mds || error "Unable to stop MDS"
3230         #writeconf to remove all ost2 traces for subsequent tests
3231         writeconf_or_reformat
3232 }
3233 run_test 50f "normal statfs one server in down =========================="
3234
3235 test_50g() {
3236         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3237         setup
3238         start_ost2 || error "Unable to start OST2"
3239         wait_osc_import_state mds ost2 FULL
3240         wait_osc_import_state client ost2 FULL
3241
3242         local PARAM="${FSNAME}-OST0001.osc.active"
3243
3244         $LFS setstripe -c -1 $DIR/$tfile || error "Unable to lfs setstripe"
3245         do_facet mgs $LCTL conf_param $PARAM=0 || error "Unable to deactivate OST"
3246
3247         umount_client $MOUNT || error "Unable to unmount client"
3248         mount_client $MOUNT || error "Unable to mount client"
3249         # This df should not cause a panic
3250         df -k $MOUNT
3251
3252         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
3253         rm -f $DIR/$tfile
3254         umount_client $MOUNT || error "Unable to unmount client"
3255         stop_ost2 || error "Unable to stop OST2"
3256         stop_ost || error "Unable to stop OST1"
3257         stop_mds || error "Unable to stop MDS"
3258         #writeconf to remove all ost2 traces for subsequent tests
3259         writeconf_or_reformat
3260 }
3261 run_test 50g "deactivated OST should not cause panic====================="
3262
3263 # LU-642
3264 test_50h() {
3265         # prepare MDT/OST, make OSC inactive for OST1
3266         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3267
3268         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3269         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
3270                 error "tunefs OST1 failed"
3271         start_mds  || error "Unable to start MDT"
3272         start_ost  || error "Unable to start OST1"
3273         start_ost2 || error "Unable to start OST2"
3274         mount_client $MOUNT || error "client start failed"
3275
3276         mkdir -p $DIR/$tdir
3277
3278         # activatate OSC for OST1
3279         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
3280         set_conf_param_and_check client                                 \
3281                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
3282                 error "Unable to activate OST1"
3283
3284         mkdir -p $DIR/$tdir/2
3285         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2
3286         sleep 1 && echo "create a file after OST1 is activated"
3287         # create some file
3288         createmany -o $DIR/$tdir/2/$tfile-%d 1
3289
3290         # check OSC import is working
3291         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3292                 error "some OSC imports are still not connected"
3293
3294         # cleanup
3295         umount_client $MOUNT || error "Unable to umount client"
3296         stop_ost2 || error "Unable to stop OST2"
3297         cleanup_nocli
3298 }
3299 run_test 50h "LU-642: activate deactivated OST  ==="
3300
3301 test_51() {
3302         local LOCAL_TIMEOUT=20
3303
3304         reformat
3305         setup_noconfig
3306         check_mount || return 1
3307
3308         mkdir $MOUNT/d1
3309         $LFS setstripe -c -1 $MOUNT/d1
3310         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3311         do_facet $SINGLEMDS "lctl set_param fail_loc=0x142"
3312         touch $MOUNT/d1/f1 &
3313         local pid=$!
3314         sleep 2
3315         start_ost2 || return 2
3316         wait $pid
3317         stop_ost2 || return 3
3318         cleanup
3319         #writeconf to remove all ost2 traces for subsequent tests
3320         writeconf_or_reformat
3321 }
3322 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3323
3324 copy_files_xattrs()
3325 {
3326         local node=$1
3327         local dest=$2
3328         local xattrs=$3
3329         shift 3
3330
3331         do_node $node mkdir -p $dest
3332         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3333
3334         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3335                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3336         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3337
3338         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3339         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3340 }
3341
3342 diff_files_xattrs()
3343 {
3344         local node=$1
3345         local backup=$2
3346         local xattrs=$3
3347         shift 3
3348
3349         local backup2=${TMP}/backup2
3350
3351         do_node $node mkdir -p $backup2
3352         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3353
3354         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3355                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3356         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3357
3358         do_node $node "diff -rq $backup $backup2"
3359         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3360
3361         local xattrs2=${TMP}/xattrs2
3362         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3363         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3364
3365         do_node $node "diff $xattrs $xattrs2"
3366         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3367
3368         do_node $node "rm -rf $backup2 $xattrs2"
3369         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3370 }
3371
3372 test_52() {
3373         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3374                 skip "Only applicable to ldiskfs-based MDTs"
3375                 return
3376         fi
3377
3378         start_mds
3379         [ $? -eq 0 ] || { error "Unable to start MDS"; return 1; }
3380         start_ost
3381         [ $? -eq 0 ] || { error "Unable to start OST1"; return 2; }
3382         mount_client $MOUNT
3383         [ $? -eq 0 ] || { error "Unable to mount client"; return 3; }
3384
3385         local nrfiles=8
3386         local ost1mnt=$(facet_mntpt ost1)
3387         local ost1node=$(facet_active_host ost1)
3388         local ost1tmp=$TMP/conf52
3389         local loop
3390
3391         mkdir -p $DIR/$tdir
3392         [ $? -eq 0 ] || { error "Unable to create tdir"; return 4; }
3393         touch $TMP/modified_first
3394         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 5; }
3395         local mtime=$(stat -c %Y $TMP/modified_first)
3396         do_node $ost1node "mkdir -p $ost1tmp && touch -m -d @$mtime $ost1tmp/modified_first"
3397
3398         [ $? -eq 0 ] || { error "Unable to create temporary file"; return 6; }
3399         sleep 1
3400
3401         $LFS setstripe -c -1 -S 1M $DIR/$tdir
3402         [ $? -eq 0 ] || { error "lfs setstripe failed"; return 7; }
3403
3404         for (( i=0; i < nrfiles; i++ )); do
3405                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c
3406                 [ $? -eq 0 ] || { error "multiop failed"; return 8; }
3407                 echo -n .
3408         done
3409         echo
3410
3411         # backup files
3412         echo backup files to $TMP/files
3413         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3414         copy_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3415         [ $? -eq 0 ] || { error "Unable to copy files"; return 9; }
3416
3417         umount_client $MOUNT
3418         [ $? -eq 0 ] || { error "Unable to umount client"; return 10; }
3419         stop_ost
3420         [ $? -eq 0 ] || { error "Unable to stop ost1"; return 11; }
3421
3422         echo mount ost1 as ldiskfs
3423         do_node $ost1node mkdir -p $ost1mnt
3424         [ $? -eq 0 ] || { error "Unable to create $ost1mnt"; return 23; }
3425         if ! do_node $ost1node test -b $ost1_dev; then
3426                 loop="-o loop"
3427         fi
3428         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3429                 $ost1mnt
3430         [ $? -eq 0 ] || { error "Unable to mount ost1 as ldiskfs"; return 12; }
3431
3432         # backup objects
3433         echo backup objects to $ost1tmp/objects
3434         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3435                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3436         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3437                         $objects
3438         [ $? -eq 0 ] || { error "Unable to copy objects"; return 13; }
3439
3440         # move objects to lost+found
3441         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3442         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3443
3444         # recover objects
3445         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found"
3446         [ $? -eq 0 ] || { error "ll_recover_lost_found_objs failed"; return 15; }
3447
3448         # compare restored objects against saved ones
3449         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
3450         [ $? -eq 0 ] || { error "Unable to diff objects"; return 16; }
3451
3452         do_node $ost1node "umount $ost1mnt"
3453         [ $? -eq 0 ] || { error "Unable to umount ost1 as ldiskfs"; return 17; }
3454
3455         start_ost
3456         [ $? -eq 0 ] || { error "Unable to start ost1"; return 18; }
3457         mount_client $MOUNT
3458         [ $? -eq 0 ] || { error "Unable to mount client"; return 19; }
3459
3460         # compare files
3461         diff_files_xattrs `hostname` $TMP/files $TMP/file_xattrs $files
3462         [ $? -eq 0 ] || { error "Unable to diff files"; return 20; }
3463
3464         rm -rf $TMP/files $TMP/file_xattrs
3465         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 21; }
3466         do_node $ost1node "rm -rf $ost1tmp"
3467         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 22; }
3468         cleanup
3469 }
3470 run_test 52 "check recovering objects from lost+found"
3471
3472 # Checks threads_min/max/started for some service
3473 #
3474 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3475 # parameter pattern prefix like 'ost.*.ost'.
3476 thread_sanity() {
3477         local modname=$1
3478         local facet=$2
3479         local parampat=$3
3480         local opts=$4
3481         local basethr=$5
3482         local tmin
3483         local tmin2
3484         local tmax
3485         local tmax2
3486         local tstarted
3487         local paramp
3488         local msg="Insane $modname thread counts"
3489         local ncpts=$(check_cpt_number $facet)
3490         local nthrs
3491         shift 4
3492
3493         check_mount || return 41
3494
3495         # We need to expand $parampat, but it may match multiple parameters, so
3496         # we'll pick the first one
3497         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
3498                 error "Couldn't expand ${parampat}.threads_min parameter name"
3499                 return 22
3500         fi
3501
3502         # Remove the .threads_min part
3503         paramp=${paramp%.threads_min}
3504
3505         # Check for sanity in defaults
3506         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3507         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3508         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started" || echo 0)
3509         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' || return $?
3510         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3511         nthrs=$(expr $tmax - $tmin)
3512         if [ $nthrs -lt $ncpts ]; then
3513                 nthrs=0
3514         else
3515                 nthrs=$ncpts
3516         fi
3517
3518         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
3519                 skip_env "module parameter forced $facet thread count" &&
3520                 tmin=3 && tmax=$((3 * tmax))
3521
3522         # Check that we can change min/max
3523         do_facet $facet "lctl set_param ${paramp}.threads_min=$((tmin + nthrs))"
3524         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmax - nthrs))"
3525         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3526         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3527         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) && $tmax2 == ($tmax - $nthrs)))' || return $?
3528
3529         # Check that we can set min/max to the same value
3530         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3531         do_facet $facet "lctl set_param ${paramp}.threads_max=$tmin"
3532         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3533         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3534         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
3535
3536         # Check that we can't set max < min
3537         do_facet $facet "lctl set_param ${paramp}.threads_max=$((tmin - 1))"
3538         tmin2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min" || echo 0)
3539         tmax2=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max" || echo 0)
3540         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
3541
3542         # We need to ensure that we get the module options desired; to do this
3543         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
3544         LOAD_MODULES_REMOTE=true
3545         cleanup
3546         local oldvalue
3547         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
3548         setmodopts -a $modname "$newvalue" oldvalue
3549
3550         load_modules
3551         setup
3552         check_mount || return 41
3553
3554         # Restore previous setting of MODOPTS_*
3555         setmodopts $modname "$oldvalue"
3556
3557         # Check that $opts took
3558         tmin=$(do_facet $facet "lctl get_param -n ${paramp}.threads_min")
3559         tmax=$(do_facet $facet "lctl get_param -n ${paramp}.threads_max")
3560         tstarted=$(do_facet $facet "lctl get_param -n ${paramp}.threads_started")
3561         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' || return $?
3562         cleanup
3563
3564         load_modules
3565         setup
3566 }
3567
3568 test_53a() {
3569         setup
3570         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
3571         cleanup
3572 }
3573 run_test 53a "check OSS thread count params"
3574
3575 test_53b() {
3576         setup
3577         local mds=$(do_facet $SINGLEMDS "lctl get_param -N mds.*.*.threads_max \
3578                     2>/dev/null")
3579         if [ -z "$mds" ]; then
3580                 #running this on an old MDT
3581                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
3582         else
3583                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
3584         fi
3585         cleanup
3586 }
3587 run_test 53b "check MDS thread count params"
3588
3589 test_54a() {
3590         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3591                 skip "Only applicable to ldiskfs-based MDTs"
3592                 return
3593         fi
3594
3595     do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p
3596     [ $? -eq 0 ] || error "llverdev failed!"
3597     reformat_and_config
3598 }
3599 run_test 54a "test llverdev and partial verify of device"
3600
3601 test_54b() {
3602         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3603                 skip "Only applicable to ldiskfs-based MDTs"
3604                 return
3605         fi
3606
3607     setup
3608     run_llverfs $MOUNT -p
3609     [ $? -eq 0 ] || error "llverfs failed!"
3610     cleanup
3611 }
3612 run_test 54b "test llverfs and partial verify of filesystem"
3613
3614 lov_objid_size()
3615 {
3616         local max_ost_index=$1
3617         echo -n $(((max_ost_index + 1) * 8))
3618 }
3619
3620 test_55() {
3621         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3622                 skip "Only applicable to ldiskfs-based MDTs"
3623                 return
3624         fi
3625
3626         local mdsdev=$(mdsdevname 1)
3627         local mdsvdev=$(mdsvdevname 1)
3628
3629         for i in 1023 2048
3630         do
3631                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
3632                         $mdsvdev || exit 10
3633                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
3634                         --reformat $(ostdevname 1) $(ostvdevname 1)
3635                 setup_noconfig
3636                 stopall
3637                 setup_noconfig
3638                 sync
3639
3640                 echo checking size of lov_objid for ost index $i
3641                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
3642                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
3643                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
3644                 else
3645                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3646                 fi
3647                 stopall
3648         done
3649
3650         reformat
3651 }
3652 run_test 55 "check lov_objid size"
3653
3654 test_56() {
3655         local server_version=$(lustre_version_code $SINGLEMDS)
3656         local mds_journal_size_orig=$MDSJOURNALSIZE
3657         local n
3658
3659         MDSJOURNALSIZE=16
3660
3661         for num in $(seq 1 $MDSCOUNT); do
3662                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3663                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3664         done
3665         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
3666                 $(ostdevname 1) $(ostvdevname 1)
3667         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \
3668                 $(ostdevname 2) $(ostvdevname 2)
3669
3670         start_mgsmds
3671         start_ost || error "Unable to start first ost (idx 10000)"
3672         start_ost2 || error "Unable to start second ost (idx 1000)"
3673         mount_client $MOUNT || error "Unable to mount client"
3674         echo ok
3675         $LFS osts
3676
3677         if [[ $server_version -ge $(version_code 2.6.54) ]] ||
3678            [[ $server_version -ge $(version_code 2.5.4) &&
3679               $server_version -lt $(version_code 2.5.11) ]]; then
3680                 wait_osc_import_state mds ost1 FULL
3681                 wait_osc_import_state mds ost2 FULL
3682                 $SETSTRIPE --stripe-count=-1 $DIR/$tfile ||
3683                         error "Unable to setstripe $DIR/$tfile"
3684                 n=$($GETSTRIPE --stripe-count $DIR/$tfile)
3685                 [[ $n -eq 2 ]] || error "Stripe count not two: $n"
3686                 rm $DIR/$tfile
3687         fi
3688
3689         stopall
3690         MDSJOURNALSIZE=$mds_journal_size_orig
3691         reformat
3692 }
3693 run_test 56 "check big OST indexes and out-of-index-order start"
3694
3695 test_57a() { # bug 22656
3696         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3697         writeconf_or_reformat
3698         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3699         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" || error "tunefs failed"
3700         start_mgsmds
3701         start_ost && error "OST registration from failnode should fail"
3702         reformat
3703 }
3704 run_test 57a "initial registration from failnode should fail (should return errs)"
3705
3706 test_57b() {
3707         local NID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | awk '{print $1}')
3708         writeconf_or_reformat
3709         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3710         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" || error "tunefs failed"
3711         start_mgsmds
3712         start_ost || error "OST registration from servicenode should not fail"
3713         reformat
3714 }
3715 run_test 57b "initial registration from servicenode should not fail"
3716
3717 count_osts() {
3718         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3719 }
3720
3721 test_58() { # bug 22658
3722         if [ $(facet_fstype mds) != ldiskfs ]; then
3723                 skip "Only applicable to ldiskfs-based MDTs"
3724                 return
3725         fi
3726         setup_noconfig
3727         mkdir -p $DIR/$tdir
3728         createmany -o $DIR/$tdir/$tfile-%d 100
3729         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3730 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3731         do_facet $SINGLEMDS "lctl set_param fail_loc=0x601"
3732         unlinkmany $DIR/$tdir/$tfile-%d 100
3733         stop_mds
3734
3735         local MNTDIR=$(facet_mntpt $SINGLEMDS)
3736         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3737         local opts=""
3738         if ! do_facet $SINGLEMDS "test -b $devname"; then
3739                 opts="-o loop"
3740         fi
3741
3742         # remove all files from the OBJECTS dir
3743         do_facet $SINGLEMDS "mount -t ldiskfs $opts $devname $MNTDIR"
3744         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
3745         do_facet $SINGLEMDS "umount -d $MNTDIR"
3746         # restart MDS with missing llog files
3747         start_mds
3748         do_facet mds "lctl set_param fail_loc=0"
3749         reformat
3750 }
3751 run_test 58 "missing llog files must not prevent MDT from mounting"
3752
3753 test_59() {
3754         start_mgsmds >> /dev/null
3755         local C1=$(count_osts)
3756         if [ $C1 -eq 0 ]; then
3757                 start_ost >> /dev/null
3758                 C1=$(count_osts)
3759         fi
3760         stopall
3761         echo "original ost count: $C1 (expect > 0)"
3762         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3763         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3764         local C2=$(count_osts)
3765         echo "after mdt writeconf count: $C2 (expect 0)"
3766         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3767         echo "OST start without writeconf should fail:"
3768         start_ost >> /dev/null && error "OST start without writeconf didn't fail"
3769         echo "OST start with writeconf should succeed:"
3770         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3771         local C3=$(count_osts)
3772         echo "after ost writeconf count: $C3 (expect 1)"
3773         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3774         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3775         local C4=$(count_osts)
3776         echo "after ost2 writeconf count: $C4 (expect 2)"
3777         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3778         stop_ost2 >> /dev/null
3779         cleanup_nocli >> /dev/null
3780         #writeconf to remove all ost2 traces for subsequent tests
3781         writeconf_or_reformat
3782 }
3783 run_test 59 "writeconf mount option"
3784
3785 test_60() { # LU-471
3786         local num
3787
3788         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3789                 skip "Only applicable to ldiskfs-based MDTs"
3790                 return
3791         fi
3792
3793         for num in $(seq $MDSCOUNT); do
3794                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3795                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3796                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3797                         exit 10
3798         done
3799
3800         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3801         rc=${PIPESTATUS[0]}
3802         [ $rc -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3803
3804         # MDT default has dirdata feature
3805         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3806         # we disable uninit_bg feature
3807         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3808         # we set stride extended options
3809         echo $dump | grep stride > /dev/null || error "stride is not set"
3810         reformat
3811 }
3812 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3813
3814 test_61() { # LU-80
3815         local reformat=false
3816
3817         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3818                 { skip "Need MDS version at least 2.1.53"; return 0; }
3819
3820         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3821            ! large_xattr_enabled; then
3822                 reformat=true
3823                 LDISKFS_MKFS_OPTS+=" -O large_xattr"
3824
3825                 for num in $(seq $MDSCOUNT); do
3826                         add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
3827                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3828                         error "add mds $num failed"
3829                 done
3830         fi
3831
3832     setup_noconfig || error "setting up the filesystem failed"
3833     client_up || error "starting client failed"
3834
3835     local file=$DIR/$tfile
3836     touch $file
3837
3838     local large_value="$(generate_string $(max_xattr_size))"
3839     local small_value="bar"
3840
3841     local name="trusted.big"
3842     log "save large xattr $name on $file"
3843     setfattr -n $name -v $large_value $file ||
3844         error "saving $name on $file failed"
3845
3846     local new_value=$(get_xattr_value $name $file)
3847     [[ "$new_value" != "$large_value" ]] &&
3848         error "$name different after saving"
3849
3850     log "shrink value of $name on $file"
3851     setfattr -n $name -v $small_value $file ||
3852         error "shrinking value of $name on $file failed"
3853
3854     new_value=$(get_xattr_value $name $file)
3855     [[ "$new_value" != "$small_value" ]] &&
3856         error "$name different after shrinking"
3857
3858     log "grow value of $name on $file"
3859     setfattr -n $name -v $large_value $file ||
3860         error "growing value of $name on $file failed"
3861
3862     new_value=$(get_xattr_value $name $file)
3863     [[ "$new_value" != "$large_value" ]] &&
3864         error "$name different after growing"
3865
3866     log "check value of $name on $file after remounting MDS"
3867     fail $SINGLEMDS
3868     new_value=$(get_xattr_value $name $file)
3869     [[ "$new_value" != "$large_value" ]] &&
3870         error "$name different after remounting MDS"
3871
3872     log "remove large xattr $name from $file"
3873     setfattr -x $name $file || error "removing $name from $file failed"
3874
3875     rm -f $file
3876     stopall
3877         if $reformat; then
3878                 LDISKFS_MKFS_OPTS=${LDISKFS_MKFS_OPTS% -O large_xattr}
3879                 reformat
3880         fi
3881 }
3882 run_test 61 "large xattr"
3883
3884 test_62() {
3885         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3886                 skip "Only applicable to ldiskfs-based MDTs"
3887                 return
3888         fi
3889
3890         # MRP-118
3891         local mdsdev=$(mdsdevname 1)
3892         local ostdev=$(ostdevname 1)
3893
3894         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
3895                 { skip "Need MDS version at least 2.2.51"; return 0; }
3896
3897         echo "disable journal for mds"
3898         do_facet mds tune2fs -O ^has_journal $mdsdev || error "tune2fs failed"
3899         start_mds && error "MDT start should fail"
3900         echo "disable journal for ost"
3901         do_facet ost1 tune2fs -O ^has_journal $ostdev || error "tune2fs failed"
3902         start_ost && error "OST start should fail"
3903         cleanup || return $?
3904         reformat_and_config
3905 }
3906 run_test 62 "start with disabled journal"
3907
3908 test_63() {
3909         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3910                 skip "Only applicable to ldiskfs-based MDTs"
3911                 return
3912         fi
3913
3914         local inode_slab=$(do_facet $SINGLEMDS \
3915                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
3916         if [ -z "$inode_slab" ]; then
3917                 skip "ldiskfs module has not been loaded"
3918                 return
3919         fi
3920
3921         echo "$inode_slab ldisk inodes per page"
3922         [ "$inode_slab" -ge "3" ] ||
3923                 error "ldisk inode size is too big, $inode_slab objs per page"
3924         return
3925 }
3926 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
3927
3928 test_64() {
3929         start_mds
3930         start_ost
3931         start_ost2 || error "Unable to start second ost"
3932         mount_client $MOUNT || error "Unable to mount client"
3933         stop_ost2 || error "Unable to stop second ost"
3934         echo "$LFS df"
3935         $LFS df --lazy || error "lfs df failed"
3936         cleanup || return $?
3937         #writeconf to remove all ost2 traces for subsequent tests
3938         writeconf_or_reformat
3939 }
3940 run_test 64 "check lfs df --lazy "
3941
3942 test_65() { # LU-2237
3943         # Currently, the test is only valid for ldiskfs backend
3944         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
3945                 skip "non-ldiskfs backend" && return
3946
3947         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3948         local brpt=$(facet_mntpt brpt)
3949         local opts=""
3950
3951         if ! do_facet $SINGLEMDS "test -b $devname"; then
3952                 opts="-o loop"
3953         fi
3954
3955         stop_mds
3956         local obj=$(do_facet $SINGLEMDS \
3957                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
3958                     grep Inode)
3959         if [ -z "$obj" ]; then
3960                 # The MDT may be just re-formatted, mount the MDT for the
3961                 # first time to guarantee the "last_rcvd" file is there.
3962                 start_mds || error "fail to mount the MDS for the first time"
3963                 stop_mds
3964         fi
3965
3966         # remove the "last_rcvd" file
3967         do_facet $SINGLEMDS "mkdir -p $brpt"
3968         do_facet $SINGLEMDS \
3969                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
3970         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
3971         do_facet $SINGLEMDS "umount -d $brpt"
3972
3973         # restart MDS, the "last_rcvd" file should be recreated.
3974         start_mds || error "fail to restart the MDS"
3975         stop_mds
3976         obj=$(do_facet $SINGLEMDS \
3977               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
3978         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
3979 }
3980 run_test 65 "re-create the lost last_rcvd file when server mount"
3981
3982 test_66() {
3983         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
3984                 { skip "Need MGS version at least 2.3.59"; return 0; }
3985
3986         setup
3987         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
3988         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
3989
3990         echo "replace_nids should fail if MDS, OSTs and clients are UP"
3991         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3992                 error "replace_nids fail"
3993
3994         umount_client $MOUNT || error "unmounting client failed"
3995         echo "replace_nids should fail if MDS and OSTs are UP"
3996         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
3997                 error "replace_nids fail"
3998
3999         stop_ost
4000         echo "replace_nids should fail if MDS is UP"
4001         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4002                 error "replace_nids fail"
4003
4004         stop_mds || error "stopping mds failed"
4005
4006         if combined_mgs_mds; then
4007                 start_mdt 1 "-o nosvc" ||
4008                         error "starting mds with nosvc option failed"
4009         fi
4010
4011         echo "command should accept two parameters"
4012         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
4013                 error "command should accept two params"
4014
4015         echo "correct device name should be passed"
4016         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
4017                 error "wrong devname"
4018
4019         echo "wrong nids list should not destroy the system"
4020         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
4021                 error "wrong parse"
4022
4023         echo "replace OST nid"
4024         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
4025                 error "replace nids failed"
4026
4027         echo "command should accept two parameters"
4028         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
4029                 error "command should accept two params"
4030
4031         echo "wrong nids list should not destroy the system"
4032         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
4033                 error "wrong parse"
4034
4035         echo "replace MDS nid"
4036         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
4037                 error "replace nids failed"
4038
4039         if ! combined_mgs_mds ; then
4040                 stop_mgs
4041         else
4042                 stop_mds
4043         fi
4044
4045         setup_noconfig
4046         check_mount || error "error after nid replace"
4047         cleanup || error "cleanup failed"
4048         reformat
4049 }
4050 run_test 66 "replace nids"
4051
4052 test_67() { #LU-2950
4053         local legacy="$TMP/legacy_lnet_config"
4054         local new="$TMP/new_routes_test"
4055         local out="$TMP/config_out_file"
4056         local verify="$TMP/conv_verify"
4057         local verify_conf="$TMP/conf_verify"
4058
4059         # Create the legacy file that will be run through the
4060         # lustre_routes_conversion script
4061         cat <<- LEGACY_LNET_CONFIG > $legacy
4062                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
4063                 tcp2 54 10.1.3.2@tcp;
4064                 tcp3 10.3.4.3@tcp:3;
4065                 tcp4 10.3.3.4@tcp;
4066         LEGACY_LNET_CONFIG
4067
4068         # Create the verification file to verify the output of
4069         # lustre_routes_conversion script against.
4070         cat <<- VERIFY_LNET_CONFIG > $verify
4071                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
4072                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
4073                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
4074                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
4075                 tcp4: { gateway: 10.3.3.4@tcp }
4076         VERIFY_LNET_CONFIG
4077
4078         # Create the verification file to verify the output of
4079         # lustre_routes_config script against
4080         cat <<- VERIFY_LNET_CONFIG > $verify_conf
4081                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
4082                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
4083                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
4084                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
4085                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
4086         VERIFY_LNET_CONFIG
4087
4088         lustre_routes_conversion $legacy $new > /dev/null
4089         if [ -f $new ]; then
4090                 # verify the conversion output
4091                 cmp -s $new $verify > /dev/null
4092                 if [ $? -eq 1 ]; then
4093                         error "routes conversion failed"
4094                 fi
4095
4096                 lustre_routes_config --dry-run --verbose $new > $out
4097                 # check that the script succeeded
4098                 cmp -s $out $verify_conf > /dev/null
4099                 if [ $? -eq 1 ]; then
4100                         error "routes config failed"
4101                 fi
4102         else
4103                 error "routes conversion test failed"
4104         fi
4105         # remove generated files
4106         rm -f $new $legacy $verify $verify_conf $out
4107 }
4108 run_test 67 "test routes conversion and configuration"
4109
4110 test_68() {
4111         local fid
4112         local seq
4113         local START
4114         local END
4115
4116         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
4117                 { skip "Need MDS version at least 2.4.53"; return 0; }
4118
4119         umount_client $MOUNT || error "umount client failed"
4120
4121         start_mdt 1 || error "MDT start failed"
4122         start_ost
4123
4124         # START-END - the sequences we'll be reserving
4125         START=$(do_facet $SINGLEMDS \
4126                 lctl get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4127         END=$((START + (1 << 30)))
4128         do_facet $SINGLEMDS \
4129                 lctl set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4130
4131         # reset the sequences MDT0000 has already assigned
4132         do_facet $SINGLEMDS \
4133                 lctl set_param seq.srv*MDT0000.space=clear
4134
4135         # remount to let the client allocate new sequence
4136         mount_client $MOUNT || error "mount client failed"
4137
4138         touch $DIR/$tfile
4139         do_facet $SINGLEMDS \
4140                 lctl get_param seq.srv*MDT0000.space
4141         $LFS path2fid $DIR/$tfile
4142
4143         local old_ifs="$IFS"
4144         IFS='[:]'
4145         fid=($($LFS path2fid $DIR/$tfile))
4146         IFS="$old_ifs"
4147         let seq=${fid[1]}
4148
4149         if [[ $seq < $END ]]; then
4150                 error "used reserved sequence $seq?"
4151         fi
4152         cleanup || return $?
4153 }
4154 run_test 68 "be able to reserve specific sequences in FLDB"
4155
4156 test_69() {
4157         local server_version=$(lustre_version_code $SINGLEMDS)
4158
4159         [[ $server_version -lt $(version_code 2.4.2) ]] &&
4160                 skip "Need MDS version at least 2.4.2" && return
4161
4162         [[ $server_version -ge $(version_code 2.4.50) ]] &&
4163         [[ $server_version -lt $(version_code 2.5.0) ]] &&
4164                 skip "Need MDS version at least 2.5.0" && return
4165
4166         setup
4167
4168         # use OST0000 since it probably has the most creations
4169         local OSTNAME=$(ostname_from_index 0)
4170         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4171         local last_id=$(do_facet mds1 lctl get_param -n \
4172                         osc.$mdtosc_proc1.prealloc_last_id)
4173
4174         # Want to have OST LAST_ID over 1.5 * OST_MAX_PRECREATE to
4175         # verify that the LAST_ID recovery is working properly.  If
4176         # not, then the OST will refuse to allow the MDS connect
4177         # because the LAST_ID value is too different from the MDS
4178         #define OST_MAX_PRECREATE=20000
4179         local num_create=$((20000 * 5))
4180
4181         mkdir -p $DIR/$tdir
4182         $LFS setstripe -i 0 $DIR/$tdir
4183         createmany -o $DIR/$tdir/$tfile- $num_create ||
4184                 error "createmany: failed to create $num_create files: $?"
4185         # delete all of the files with objects on OST0 so the
4186         # filesystem is not inconsistent later on
4187         $LFS find $MOUNT --ost 0 | xargs rm
4188
4189         stop_ost || error "OST0 stop failure"
4190         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
4191                 $(ostdevname 1) $(ostvdevname 1) ||
4192                 error "reformat and replace $ostdev failed"
4193         start_ost || error "OST0 restart failure"
4194         wait_osc_import_state mds ost FULL
4195
4196         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
4197         local idx=$($LFS getstripe -i $DIR/$tdir/$tfile-last)
4198         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
4199
4200         cleanup
4201 }
4202 run_test 69 "replace an OST with the same index"
4203
4204 test_70a() {
4205         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4206         local MDTIDX=1
4207
4208         cleanup
4209
4210         start_mdt 1 || error "MDT0 start fail"
4211
4212         start_ost || error "OST0 start fail"
4213
4214         start_mdt 2 || error "MDT1 start fail"
4215
4216         mount_client $MOUNT || error "mount client fails"
4217
4218         mkdir -p $DIR/$tdir || error "create dir fail"
4219
4220         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4221                                         error "create remote dir fail"
4222
4223         rm -rf $DIR/$tdir || error "delete dir fail"
4224         cleanup || return $?
4225 }
4226 run_test 70a "start MDT0, then OST, then MDT1"
4227
4228 test_70b() {
4229         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4230         local MDTIDX=1
4231
4232         start_ost || error "OST0 start fail"
4233
4234         start_mdt 1 || error "MDT0 start fail"
4235         start_mdt 2 || error "MDT1 start fail"
4236
4237         mount_client $MOUNT || error "mount client fails"
4238
4239         mkdir -p $DIR/$tdir || error "create dir fail"
4240
4241         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4242                                         error "create remote dir fail"
4243
4244         rm -rf $DIR/$tdir || error "delete dir fail"
4245
4246         cleanup || return $?
4247 }
4248 run_test 70b "start OST, MDT1, MDT0"
4249
4250 test_70c() {
4251         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4252         local MDTIDX=1
4253
4254         start_mdt 1 || error "MDT0 start fail"
4255         start_mdt 2 || error "MDT1 start fail"
4256         start_ost || error "OST0 start fail"
4257
4258         mount_client $MOUNT || error "mount client fails"
4259         stop_mdt 1 || error "MDT1 start fail"
4260
4261         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
4262         echo "deactivate $mdc_for_mdt1"
4263         $LCTL --device $mdc_for_mdt1 deactivate || return 1
4264
4265         mkdir -p $DIR/$tdir && error "mkdir succeed"
4266
4267         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4268                                         error "create remote dir succeed"
4269
4270         cleanup || return $?
4271 }
4272 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
4273
4274 test_70d() {
4275         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4276         local MDTIDX=1
4277
4278         start_mdt 1 || error "MDT0 start fail"
4279         start_mdt 2 || error "MDT1 start fail"
4280         start_ost || error "OST0 start fail"
4281
4282         mount_client $MOUNT || error "mount client fails"
4283
4284         stop_mdt 2 || error "MDT1 start fail"
4285
4286         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
4287                              awk '{print $4}')
4288         echo "deactivate $mdc_for_mdt2"
4289         $LCTL --device $mdc_for_mdt2 deactivate ||
4290                         error "set $mdc_for_mdt2 deactivate failed"
4291
4292         mkdir -p $DIR/$tdir || error "mkdir fail"
4293         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4294                         error "create remote dir succeed"
4295
4296         rm -rf $DIR/$tdir || error "delete dir fail"
4297
4298         cleanup || return $?
4299 }
4300 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
4301
4302 test_71a() {
4303         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4304         if combined_mgs_mds; then
4305                 skip "needs separate MGS/MDT" && return
4306         fi
4307         local MDTIDX=1
4308
4309         start_mdt 1 || error "MDT0 start fail"
4310         start_ost || error "OST0 start fail"
4311         start_mdt 2 || error "MDT1 start fail"
4312         start_ost2 || error "OST1 start fail"
4313
4314         mount_client $MOUNT || error "mount client fails"
4315
4316         mkdir -p $DIR/$tdir || error "mkdir fail"
4317         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4318                         error "create remote dir succeed"
4319
4320         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4321         rm -rf $DIR/$tdir || error "delete dir fail"
4322
4323         umount_client $MOUNT
4324         stop_mdt 1 || error "MDT0 stop fail"
4325         stop_mdt 2 || error "MDT1 stop fail"
4326         stop_ost || error "OST0 stop fail"
4327         stop_ost2 || error "OST1 stop fail"
4328 }
4329 run_test 71a "start MDT0 OST0, MDT1, OST1"
4330
4331 test_71b() {
4332         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4333         if combined_mgs_mds; then
4334                 skip "needs separate MGS/MDT" && return
4335         fi
4336         local MDTIDX=1
4337
4338         start_mdt 2 || error "MDT1 start fail"
4339         start_ost || error "OST0 start fail"
4340         start_mdt 1 || error "MDT0 start fail"
4341         start_ost2 || error "OST1 start fail"
4342
4343         mount_client $MOUNT || error "mount client fails"
4344
4345         mkdir -p $DIR/$tdir || error "mkdir fail"
4346         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4347                         error "create remote dir succeed"
4348
4349         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4350         rm -rf $DIR/$tdir || error "delete dir fail"
4351
4352         umount_client $MOUNT
4353         stop_mdt 1 || error "MDT0 stop fail"
4354         stop_mdt 2 || error "MDT1 stop fail"
4355         stop_ost || error "OST0 stop fail"
4356         stop_ost2 || error "OST1 stop fail"
4357 }
4358 run_test 71b "start MDT1, OST0, MDT0, OST1"
4359
4360 test_71c() {
4361         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4362         if combined_mgs_mds; then
4363                 skip "needs separate MGS/MDT" && return
4364         fi
4365         local MDTIDX=1
4366
4367         start_ost || error "OST0 start fail"
4368         start_ost2 || error "OST1 start fail"
4369         start_mdt 2 || error "MDT1 start fail"
4370         start_mdt 1 || error "MDT0 start fail"
4371
4372         mount_client $MOUNT || error "mount client fails"
4373
4374         mkdir -p $DIR/$tdir || error "mkdir fail"
4375         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4376                         error "create remote dir succeed"
4377
4378         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4379         rm -rf $DIR/$tdir || error "delete dir fail"
4380
4381         umount_client $MOUNT
4382         stop_mdt 1 || error "MDT0 stop fail"
4383         stop_mdt 2 || error "MDT1 stop fail"
4384         stop_ost || error "OST0 stop fail"
4385         stop_ost2 || error "OST1 stop fail"
4386
4387 }
4388 run_test 71c "start OST0, OST1, MDT1, MDT0"
4389
4390 test_71d() {
4391         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4392         if combined_mgs_mds; then
4393                 skip "needs separate MGS/MDT" && return
4394         fi
4395         local MDTIDX=1
4396
4397         start_ost || error "OST0 start fail"
4398         start_mdt 2 || error "MDT0 start fail"
4399         start_mdt 1 || error "MDT0 start fail"
4400         start_ost2 || error "OST1 start fail"
4401
4402         mount_client $MOUNT || error "mount client fails"
4403
4404         mkdir -p $DIR/$tdir || error "mkdir fail"
4405         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4406                         error "create remote dir succeed"
4407
4408         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4409         rm -rf $DIR/$tdir || error "delete dir fail"
4410
4411         umount_client $MOUNT
4412         stop_mdt 1 || error "MDT0 stop fail"
4413         stop_mdt 2 || error "MDT1 stop fail"
4414         stop_ost || error "OST0 stop fail"
4415         stop_ost2 || error "OST1 stop fail"
4416
4417 }
4418 run_test 71d "start OST0, MDT1, MDT0, OST1"
4419
4420 test_71e() {
4421         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4422         if combined_mgs_mds; then
4423                 skip "needs separate MGS/MDT" && return
4424         fi
4425         local MDTIDX=1
4426
4427         start_ost || error "OST0 start fail"
4428         start_mdt 2 || error "MDT1 start fail"
4429         start_ost2 || error "OST1 start fail"
4430         start_mdt 1 || error "MDT0 start fail"
4431
4432         mount_client $MOUNT || error "mount client fails"
4433
4434         mkdir -p $DIR/$tdir || error "mkdir fail"
4435         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4436                         error "create remote dir succeed"
4437
4438         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4439         rm -rf $DIR/$tdir || error "delete dir fail"
4440
4441         umount_client $MOUNT
4442         stop_mdt 1 || error "MDT0 stop fail"
4443         stop_mdt 2 || error "MDT1 stop fail"
4444         stop_ost || error "OST0 stop fail"
4445         stop_ost2 || error "OST1 stop fail"
4446
4447 }
4448 run_test 71e "start OST0, MDT1, OST1, MDT0"
4449
4450 test_72() { #LU-2634
4451         local mdsdev=$(mdsdevname 1)
4452         local ostdev=$(ostdevname 1)
4453         local cmd="$E2FSCK -fnvd $mdsdev"
4454         local fn=3
4455
4456         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4457                 skip "ldiskfs only test" && return
4458
4459         #tune MDT with "-O extents"
4460
4461         for num in $(seq $MDSCOUNT); do
4462                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
4463                 --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4464                 error "add mds $num failed"
4465                 $TUNE2FS -O extents $(mdsdevname $num)
4466         done
4467
4468         add ost1 $(mkfs_opts ost1 $ostdev) --reformat $ostdev ||
4469                 error "add $ostdev failed"
4470         start_mgsmds || error "start mds failed"
4471         start_ost || error "start ost failed"
4472         mount_client $MOUNT || error "mount client failed"
4473
4474         #create some short symlinks
4475         mkdir -p $DIR/$tdir
4476         createmany -o $DIR/$tdir/$tfile-%d $fn
4477         echo "create $fn short symlinks"
4478         for i in $(seq -w 1 $fn); do
4479                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
4480         done
4481         ls -al $MOUNT
4482
4483         #umount
4484         umount_client $MOUNT || error "umount client failed"
4485         stop_mds || error "stop mds failed"
4486         stop_ost || error "stop ost failed"
4487
4488         #run e2fsck
4489         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
4490 }
4491 run_test 72 "test fast symlink with extents flag enabled"
4492
4493 test_73() { #LU-3006
4494         load_modules
4495         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4496         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
4497                 error "1st tunefs failed"
4498         start_mgsmds || error "start mds failed"
4499         start_ost || error "start ost failed"
4500         mount_client $MOUNT || error "mount client failed"
4501         lctl get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
4502                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
4503         umount_client $MOUNT || error "umount client failed"
4504         stopall
4505         reformat
4506 }
4507 run_test 73 "failnode to update from mountdata properly"
4508
4509 test_74() { # LU-1606
4510         for TESTPROG in $LUSTRE_TESTS_API_DIR/*.c; do
4511                 gcc -Wall -Werror $LUSTRE_TESTS_API_DIR/simple_test.c \
4512                         -I$LUSTRE/include \
4513                         -L$LUSTRE/utils -llustreapi ||
4514                                 error "client api broken"
4515         done
4516         cleanup || return $?
4517 }
4518 run_test 74 "Lustre client api program can compile and link"
4519
4520 test_75() { # LU-2374
4521         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
4522                         skip "Need MDS version at least 2.4.1" && return
4523
4524         local index=0
4525         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
4526                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
4527         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
4528                 --reformat $(ostdevname 1) $(ostvdevname 1)"
4529
4530         #check with default parameters
4531         add mds1 $opts_mds || error "add mds1 failed for default params"
4532         add ost1 $opts_ost || error "add ost1 failed for default params"
4533
4534         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
4535         opts_mds=$(echo $opts_mds |
4536                    sed -e "s/--index=$index/--index=$index --mdt/")
4537         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
4538         opts_ost=$(echo $opts_ost |
4539                    sed -e "s/--index=$index/--index=$index --ost/")
4540
4541         add mds1 $opts_mds || error "add mds1 failed for new params"
4542         add ost1 $opts_ost || error "add ost1 failed for new params"
4543         return 0
4544 }
4545 run_test 75 "The order of --index should be irrelevant"
4546
4547 test_76a() {
4548         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
4549                 { skip "Need MDS version at least 2.4.52" && return 0; }
4550         setup
4551         local MDMB_PARAM="osc.*.max_dirty_mb"
4552         echo "Change MGS params"
4553         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
4554                 head -1)
4555         echo "max_dirty_mb: $MAX_DIRTY_MB"
4556         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB + MAX_DIRTY_MB))
4557         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
4558         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
4559         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4560                 head -1" $NEW_MAX_DIRTY_MB
4561         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4562         echo "$MAX_DIRTY_MB"
4563         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4564                 error "error while apply max_dirty_mb"
4565
4566         echo "Check the value is stored after remount"
4567         stopall
4568         setupall
4569         wait_update $HOSTNAME "lctl get_param -n $MDMB_PARAM |
4570                 head -1" $NEW_MAX_DIRTY_MB
4571         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4572         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4573                 error "max_dirty_mb is not saved after remount"
4574
4575         echo "Change OST params"
4576         CLIENT_PARAM="obdfilter.*.client_cache_count"
4577         local CLIENT_CACHE_COUNT
4578         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4579                 head -1)
4580         echo "client_cache_count: $CLIENT_CACHE_COUNT"
4581         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
4582         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
4583         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
4584         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4585                 head -1" $NEW_CLIENT_CACHE_COUNT
4586         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4587                 head -1)
4588         echo "$CLIENT_CACHE_COUNT"
4589         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4590                 error "error while apply client_cache_count"
4591
4592         echo "Check the value is stored after remount"
4593         stopall
4594         setupall
4595         wait_update $(facet_host ost1) "lctl get_param -n $CLIENT_PARAM |
4596                 head -1" $NEW_CLIENT_CACHE_COUNT
4597         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4598                 head -1)
4599         echo "$CLIENT_CACHE_COUNT"
4600         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4601                 error "client_cache_count is not saved after remount"
4602         stopall
4603 }
4604 run_test 76a "set permanent params set_param -P"
4605
4606 test_76b() { # LU-4783
4607         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.57) ]] ||
4608                 { skip "Need MGS version at least 2.5.57" && return 0; }
4609         stopall
4610         setupall
4611         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
4612                 error "start params log failed"
4613         stopall
4614 }
4615 run_test 76b "verify params log setup correctly"
4616
4617 test_77() { # LU-3445
4618         local server_version=$(lustre_version_code $SINGLEMDS)
4619
4620         [[ $server_version -ge $(version_code 2.2.60) ]] &&
4621         [[ $server_version -le $(version_code 2.4.0) ]] &&
4622                 skip "Need MDS version < 2.2.60 or > 2.4.0" && return
4623
4624         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
4625                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
4626                 skip_env "mixed loopback and real device not working" && return
4627         fi
4628
4629         local fs2mdsdev=$(mdsdevname 1_2)
4630         local fs2ostdev=$(ostdevname 1_2)
4631         local fs2mdsvdev=$(mdsvdevname 1_2)
4632         local fs2ostvdev=$(ostvdevname 1_2)
4633         local fsname=test1234
4634         local mgsnid
4635         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
4636
4637         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
4638                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
4639         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_24a EXIT INT ||
4640                 error "start fs2mds failed"
4641
4642         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
4643         [[ $mgsnid = *,* ]] || mgsnid+=",$mgsnid"
4644
4645         add fs2ost $(mkfs_opts ost1 $fs2ostdev) --mgsnode=$mgsnid \
4646                 --failnode=$failnid --fsname=$fsname \
4647                 --reformat $fs2ostdev $fs2ostvdev ||
4648                         error "add fs2ost failed"
4649         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
4650
4651         mkdir -p $MOUNT2
4652         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
4653         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
4654         cleanup_24a
4655 }
4656 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
4657
4658 if ! combined_mgs_mds ; then
4659         stop mgs
4660 fi
4661
4662 cleanup_gss
4663
4664 complete $SECONDS
4665 exit_status