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