Whamcloud - gitweb
b0a19efbb8961db3beb0e159b298a141a502dd7b
[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:     LU-7005
8 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 50i"
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-4444
82         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 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         local orignids=$($LCTL get_param -n \
1278                 osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1279
1280         local orignidcount=$(echo "$orignids" | wc -w)
1281
1282         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1283         # numerical part of it. Hopefully that's not already a failover address
1284         # for the server.
1285         local OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | \
1286                 awk '{print $1}')
1287         local ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1288         local NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1289         local NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1290         echo "Using fake nid $NEW"
1291
1292         local TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1293                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1294         set_conf_param_and_check client "$TEST" \
1295                 "$FSNAME-OST0000.failover.node" $NEW ||
1296                 error "didn't add failover nid $NEW"
1297         local NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1298                 grep failover_nids)
1299         echo $NIDS
1300         local NIDCOUNT=$(echo "$NIDS" | wc -w)
1301         echo "should have $((orignidcount + 1)) entries \
1302                 in failover nids string, have $NIDCOUNT"
1303         [ $NIDCOUNT -eq $((orignidcount + 1)) ] ||
1304                 error "Failover nid not added"
1305
1306         do_facet mgs "$LCTL conf_param -d $FSNAME-OST0000.failover.node" ||
1307                 error "conf_param delete failed"
1308         umount_client $MOUNT
1309         mount_client $MOUNT || error "mount_client $MOUNT failed"
1310
1311         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1312                 grep failover_nids)
1313         echo $NIDS
1314         NIDCOUNT=$(echo "$NIDS" | wc -w)
1315         echo "only $orignidcount final entries should remain \
1316                 in failover nids string, have $NIDCOUNT"
1317         [ $NIDCOUNT -eq $orignidcount ] || error "Failover nids not removed"
1318
1319         cleanup || error "cleanup failed with rc $?"
1320 }
1321 run_test 30b "Remove failover nids"
1322
1323 test_31() { # bug 10734
1324         # ipaddr must not exist
1325         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1326         cleanup || error "cleanup failed with rc $?"
1327 }
1328 run_test 31 "Connect to non-existent node (shouldn't crash)"
1329
1330
1331 T32_QID=60000
1332 T32_BLIMIT=20480 # Kbytes
1333 T32_ILIMIT=2
1334
1335 #
1336 # This is not really a test but a tool to create new disk
1337 # image tarballs for the upgrade tests.
1338 #
1339 # Disk image tarballs should be created on single-node
1340 # clusters by running this test with default configurations
1341 # plus a few mandatory environment settings that are verified
1342 # at the beginning of the test.
1343 #
1344 test_32newtarball() {
1345         local version
1346         local dst=.
1347         local src=/etc/rc.d
1348         local tmp=$TMP/t32_image_create
1349
1350         if [ $FSNAME != t32fs -o $MDSCOUNT -ne 1 -o                                                             \
1351                  \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o $OSTCOUNT -ne 1 -o                      \
1352                  -z "$OSTDEV1" ]; then
1353                 error "Needs FSNAME=t32fs MDSCOUNT=1 MDSDEV1=<nonexistent_file>"        \
1354                           "(or MDSDEV, in the case of b1_8) OSTCOUNT=1"                                 \
1355                           "OSTDEV1=<nonexistent_file>"
1356         fi
1357
1358         mkdir $tmp || {
1359                 echo "Found stale $tmp"
1360                 return 1
1361         }
1362
1363         mkdir $tmp/src || return 1
1364         tar cf - -C $src . | tar xf - -C $tmp/src
1365         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1366                 count=$(($T32_BLIMIT / 1024 / 2))
1367         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1368
1369         # format ost with comma-separated NIDs to verify LU-4460
1370         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
1371         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1372
1373         setupall
1374
1375         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1376                 $LFS quotacheck -ug /mnt/$FSNAME
1377         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1378                 /mnt/$FSNAME
1379
1380         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1381         stopall
1382
1383         mkdir $tmp/img || return 1
1384
1385         setupall
1386         pushd /mnt/$FSNAME
1387         ls -Rni --time-style=+%s >$tmp/img/list
1388         find . ! -name .lustre -type f -exec sha1sum {} \; |
1389                 sort -k 2 >$tmp/img/sha1sums
1390         popd
1391         $LCTL get_param -n version | head -n 1 |
1392                 sed -e 's/^lustre: *//' >$tmp/img/commit
1393
1394         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.3.50) ] &&
1395                 $LFS quotaon -ug /mnt/$FSNAME
1396         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1397         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1398                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1399                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1400                 | tr -d "*" > $tmp/img/bspace
1401         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1402                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1403                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1404                 | tr -d "*" > $tmp/img/ispace
1405
1406         stopall
1407
1408         pushd $tmp/src
1409         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1410         popd
1411
1412         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1413                 echo "Data verification failed"
1414         fi
1415
1416         uname -r >$tmp/img/kernel
1417         uname -m >$tmp/img/arch
1418
1419         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1420         mv $OSTDEV1 $tmp/img
1421
1422         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1423                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1424         dst=$(cd $dst; pwd)
1425         pushd $tmp/img
1426         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1427         popd
1428
1429         rm -r $tmp
1430 }
1431 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1432
1433 #
1434 # The list of applicable tarballs is returned via the caller's
1435 # variable "tarballs".
1436 #
1437 t32_check() {
1438         local node=$(facet_active_host $SINGLEMDS)
1439         local r="do_node $node"
1440
1441         if [ "$CLIENTONLY" ]; then
1442                 skip "Client-only testing"
1443                 exit 0
1444         fi
1445
1446         if ! $r which $TUNEFS; then
1447                 skip_env "tunefs.lustre required on $node"
1448                 exit 0
1449         fi
1450
1451         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1452
1453         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 -name \'disk*-$IMGTYPE.tar.bz2\')
1454
1455         if [ -z "$tarballs" ]; then
1456                 skip "No applicable tarballs found"
1457                 exit 0
1458         fi
1459 }
1460
1461 t32_test_cleanup() {
1462         local tmp=$TMP/t32
1463         local fstype=$(facet_fstype $SINGLEMDS)
1464         local rc=$?
1465
1466         if $shall_cleanup_lustre; then
1467                 umount $tmp/mnt/lustre || rc=$?
1468         fi
1469         if $shall_cleanup_mdt; then
1470                 $r umount -d $tmp/mnt/mdt || rc=$?
1471         fi
1472         if $shall_cleanup_mdt1; then
1473                 $r umount -d $tmp/mnt/mdt1 || rc=$?
1474         fi
1475         if $shall_cleanup_ost; then
1476                 $r umount -d $tmp/mnt/ost || rc=$?
1477         fi
1478
1479         $r rm -rf $tmp
1480         rm -rf $tmp
1481         if [ $fstype == "zfs" ]; then
1482                 $r $ZPOOL destroy t32fs-mdt1 || rc=$?
1483                 $r $ZPOOL destroy t32fs-ost1 || rc=$?
1484         fi
1485         return $rc
1486 }
1487
1488 t32_bits_per_long() {
1489         #
1490         # Yes, this is not meant to be perfect.
1491         #
1492         case $1 in
1493                 ppc64|x86_64)
1494                         echo -n 64;;
1495                 i*86)
1496                         echo -n 32;;
1497         esac
1498 }
1499
1500 t32_reload_modules() {
1501         local node=$1
1502         local all_removed=false
1503         local i=0
1504
1505         while ((i < 20)); do
1506                 echo "Unloading modules on $node: Attempt $i"
1507                 do_rpc_nodes $node $LUSTRE_RMMOD $(facet_fstype $SINGLEMDS) &&
1508                         all_removed=true
1509                 do_rpc_nodes $node check_mem_leak || return 1
1510                 if $all_removed; then
1511                         do_rpc_nodes $node load_modules
1512                         return 0
1513                 fi
1514                 sleep 5
1515                 i=$((i + 1))
1516         done
1517         echo "Unloading modules on $node: Given up"
1518         return 1
1519 }
1520
1521 t32_wait_til_devices_gone() {
1522         local node=$1
1523         local devices
1524         local loops
1525         local i=0
1526
1527         echo wait for devices to go
1528         while ((i < 20)); do
1529                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1530                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1531                 ((devices == 0 && loops == 0)) && return 0
1532                 sleep 5
1533                 i=$((i + 1))
1534         done
1535         echo "waiting for dev on $node: dev $devices loop $loops given up"
1536         do_rpc_nodes $node "losetup -a"
1537         do_rpc_nodes $node "$LCTL device_list"
1538         return 1
1539 }
1540
1541 t32_verify_quota() {
1542         local node=$1
1543         local fsname=$2
1544         local mnt=$3
1545         local fstype=$(facet_fstype $SINGLEMDS)
1546         local qval
1547         local cmd
1548
1549         $LFS quota -u $T32_QID -v $mnt
1550
1551         qval=$($LFS quota -v -u $T32_QID $mnt |
1552                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1553                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1554                 | tr -d "*")
1555         [ $qval -eq $img_bspace ] || {
1556                 echo "bspace, act:$qval, exp:$img_bspace"
1557                 return 1
1558         }
1559
1560         qval=$($LFS quota -v -u $T32_QID $mnt |
1561                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1562                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1563                 | tr -d "*")
1564         [ $qval -eq $img_ispace ] || {
1565                 echo "ispace, act:$qval, exp:$img_ispace"
1566                 return 1
1567         }
1568
1569         qval=$($LFS quota -v -u $T32_QID $mnt |
1570                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1571                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1572                 | tr -d "*")
1573         [ $qval -eq $T32_BLIMIT ] || {
1574                 echo "blimit, act:$qval, exp:$T32_BLIMIT"
1575                 return 1
1576         }
1577
1578         qval=$($LFS quota -v -u $T32_QID $mnt |
1579                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1580                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1581                 | tr -d "*")
1582         [ $qval -eq $T32_ILIMIT ] || {
1583                 echo "ilimit, act:$qval, exp:$T32_ILIMIT"
1584                 return 1
1585         }
1586
1587         do_node $node $LCTL conf_param $fsname.quota.mdt=ug
1588         cmd="$LCTL get_param -n osd-$fstype.$fsname-MDT0000"
1589         cmd=$cmd.quota_slave.enabled
1590         wait_update $node "$cmd" "ug" || {
1591                 echo "Enable mdt quota failed"
1592                 return 1
1593         }
1594
1595         do_node $node $LCTL conf_param $fsname.quota.ost=ug
1596         cmd="$LCTL get_param -n osd-$fstype.$fsname-OST0000"
1597         cmd=$cmd.quota_slave.enabled
1598         wait_update $node "$cmd" "ug" || {
1599                 echo "Enable ost quota failed"
1600                 return 1
1601         }
1602
1603         chmod 0777 $mnt
1604         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1605                 bs=1M count=$(($T32_BLIMIT / 1024)) oflag=sync && {
1606                 echo "Write succeed, but expect -EDQUOT"
1607                 return 1
1608         }
1609         rm -f $mnt/t32_qf_new
1610
1611         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1612                 $T32_ILIMIT && {
1613                 echo "Create succeed, but expect -EDQUOT"
1614                 return 1
1615         }
1616         unlinkmany $mnt/t32_qf_ $T32_ILIMIT
1617
1618         return 0
1619 }
1620
1621 t32_test() {
1622         local tarball=$1
1623         local writeconf=$2
1624         local dne_upgrade=${dne_upgrade:-"no"}
1625         local ff_convert=${ff_convert:-"no"}
1626         local shall_cleanup_mdt=false
1627         local shall_cleanup_mdt1=false
1628         local shall_cleanup_ost=false
1629         local shall_cleanup_lustre=false
1630         local node=$(facet_active_host $SINGLEMDS)
1631         local r="do_node $node"
1632         local node2=$(facet_active_host mds2)
1633         local tmp=$TMP/t32
1634         local img_commit
1635         local img_kernel
1636         local img_arch
1637         local img_bspace
1638         local img_ispace
1639         local fsname=t32fs
1640         local nid=$($r $LCTL list_nids | head -1)
1641         local mopts
1642         local uuid
1643         local nrpcs_orig
1644         local nrpcs
1645         local list
1646         local fstype=$(facet_fstype $SINGLEMDS)
1647         local mdt_dev=$tmp/mdt
1648         local ost_dev=$tmp/ost
1649
1650         trap 'trap - RETURN; t32_test_cleanup' RETURN
1651
1652         load_modules
1653         mkdir -p $tmp/mnt/lustre || error "mkdir $tmp/mnt/lustre failed"
1654         $r mkdir -p $tmp/mnt/{mdt,ost}
1655         $r tar xjvf $tarball -S -C $tmp || {
1656                 error_noexit "Unpacking the disk image tarball"
1657                 return 1
1658         }
1659         img_commit=$($r cat $tmp/commit)
1660         img_kernel=$($r cat $tmp/kernel)
1661         img_arch=$($r cat $tmp/arch)
1662         img_bspace=$($r cat $tmp/bspace)
1663         img_ispace=$($r cat $tmp/ispace)
1664         echo "Upgrading from $(basename $tarball), created with:"
1665         echo "  Commit: $img_commit"
1666         echo "  Kernel: $img_kernel"
1667         echo "    Arch: $img_arch"
1668         echo "OST version: $(lustre_build_version ost1)"
1669
1670         # The conversion can be made only when both of the following
1671         # conditions are satisfied:
1672         # - ost device img version < 2.3.64
1673         # - ost server version >= 2.5
1674         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
1675                 $(lustre_version_code ost1) -lt $(version_code 2.5.0) ] &&
1676                         ff_convert="no"
1677
1678         if [ $fstype == "zfs" ]; then
1679                 # import pool first
1680                 $r $ZPOOL import -f -d $tmp t32fs-mdt1
1681                 $r $ZPOOL import -f -d $tmp t32fs-ost1
1682                 mdt_dev=t32fs-mdt1/mdt1
1683                 ost_dev=t32fs-ost1/ost1
1684                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1685                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1686                                 error_noexit "import zfs pool failed"
1687                                 return 1
1688                         }
1689         fi
1690
1691         $r $LCTL set_param debug="$PTLDEBUG"
1692
1693         $r $TUNEFS --dryrun $mdt_dev || {
1694                 $r losetup -a
1695                 error_noexit "tunefs.lustre before mounting the MDT"
1696                 return 1
1697         }
1698         if [ "$writeconf" ]; then
1699                 mopts=writeconf
1700                 if [ $fstype == "ldiskfs" ]; then
1701                         mopts="loop,$mopts"
1702                         $r $TUNEFS --quota $mdt_dev || {
1703                                 $r losetup -a
1704                                 error_noexit "Enable mdt quota feature"
1705                                 return 1
1706                         }
1707                 fi
1708         else
1709                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1710                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1711                         { skip "LU-2200: Cannot run over Inifiniband w/o lctl replace_nids "
1712                                 "(Need MGS version at least 2.3.59)"; return 0; }
1713
1714                         local osthost=$(facet_active_host ost1)
1715                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1716
1717                         mopts=nosvc
1718                         if [ $fstype == "ldiskfs" ]; then
1719                                 mopts="loop,$mopts"
1720                         fi
1721                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1722                         $r $LCTL replace_nids $fsname-OST0000 $ostnid
1723                         $r $LCTL replace_nids $fsname-MDT0000 $nid
1724                         $r umount -d $tmp/mnt/mdt
1725                 fi
1726
1727                 mopts=exclude=$fsname-OST0000
1728                 if [ $fstype == "ldiskfs" ]; then
1729                         mopts="loop,$mopts"
1730                 fi
1731         fi
1732
1733         t32_wait_til_devices_gone $node
1734
1735         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1736                 $r losetup -a
1737                 error_noexit "Mounting the MDT"
1738                 return 1
1739         }
1740         shall_cleanup_mdt=true
1741
1742         if [ "$dne_upgrade" != "no" ]; then
1743                 local fs2mdsdev=$(mdsdevname 1_2)
1744                 local fs2mdsvdev=$(mdsvdevname 1_2)
1745
1746                 echo "mkfs new MDT on ${fs2mdsdev}...."
1747                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1748                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1749                 fi
1750
1751                 add fs2mds $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1752                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1753                         error_noexit "Mkfs new MDT failed"
1754                         return 1
1755                 }
1756
1757                 $r $TUNEFS --dryrun $fs2mdsdev || {
1758                         error_noexit "tunefs.lustre before mounting the MDT"
1759                         return 1
1760                 }
1761
1762                 echo "mount new MDT....$fs2mdsdev"
1763                 $r mkdir -p $tmp/mnt/mdt1
1764                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1765                         error_noexit "mount mdt1 failed"
1766                         return 1
1767                 }
1768
1769                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1770                         error_noexit "enable remote dir create failed"
1771
1772                 shall_cleanup_mdt1=true
1773         fi
1774
1775         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1776                 error_noexit "Getting MDT UUID"
1777                 return 1
1778         }
1779         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1780                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1781                 return 1
1782         fi
1783
1784         $r $TUNEFS --dryrun $ost_dev || {
1785                 error_noexit "tunefs.lustre before mounting the OST"
1786                 return 1
1787         }
1788         if [ "$writeconf" ]; then
1789                 mopts=mgsnode=$nid,$writeconf
1790                 if [ $fstype == "ldiskfs" ]; then
1791                         mopts="loop,$mopts"
1792                         $r $TUNEFS --quota $ost_dev || {
1793                                 $r losetup -a
1794                                 error_noexit "Enable ost quota feature"
1795                                 return 1
1796                         }
1797                 fi
1798         else
1799                 mopts=mgsnode=$nid
1800                 if [ $fstype == "ldiskfs" ]; then
1801                         mopts="loop,$mopts"
1802                 fi
1803         fi
1804         $r $MOUNT_CMD -o $mopts $ost_dev $tmp/mnt/ost || {
1805                 error_noexit "Mounting the OST"
1806                 return 1
1807         }
1808         shall_cleanup_ost=true
1809
1810         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1811                 error_noexit "Getting OST UUID"
1812                 return 1
1813         }
1814         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1815                 error_noexit "Unexpected OST UUID: \"$uuid\""
1816                 return 1
1817         fi
1818
1819         $r $LCTL conf_param $fsname-OST0000.osc.max_dirty_mb=15 || {
1820                 error_noexit "Setting \"max_dirty_mb\""
1821                 return 1
1822         }
1823         $r $LCTL conf_param $fsname-OST0000.failover.node=$nid || {
1824                 error_noexit "Setting OST \"failover.node\""
1825                 return 1
1826         }
1827         $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1828                 error_noexit "Setting \"max_rpcs_in_flight\""
1829                 return 1
1830         }
1831         $r $LCTL conf_param $fsname-MDT0000.failover.node=$nid || {
1832                 error_noexit "Setting MDT \"failover.node\""
1833                 return 1
1834         }
1835         $r $LCTL pool_new $fsname.interop || {
1836                 error_noexit "Setting \"interop\""
1837                 return 1
1838         }
1839         $r $LCTL conf_param $fsname-MDT0000.lov.stripesize=4M || {
1840                 error_noexit "Setting \"lov.stripesize\""
1841                 return 1
1842         }
1843         $r $LCTL conf_param $fsname-MDT0000.mdd.atime_diff=70 || {
1844                 error_noexit "Setting \"mdd.atime_diff\""
1845                 return 1
1846         }
1847
1848         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1849                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1850                         error_noexit "Start OI scrub on OST0"
1851                         return 1
1852                 }
1853
1854                 # The oi_scrub should be on ost1, but for test_32(),
1855                 # all on the SINGLEMDS.
1856                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1857                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1858                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1859                         error_noexit "Failed to get the expected 'completed'"
1860                         return 1
1861                 }
1862
1863                 local UPDATED=$($r $LCTL get_param -n \
1864                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
1865                                 awk '/^updated/ { print $2 }')
1866                 [ $UPDATED -ge 1 ] || {
1867                         error_noexit "Only $UPDATED objects have been converted"
1868                         return 1
1869                 }
1870         fi
1871
1872         if [ "$dne_upgrade" != "no" ]; then
1873                 $r $LCTL conf_param \
1874                                 $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
1875                         error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1876                         return 1
1877                 }
1878                 $r $LCTL conf_param $fsname-MDT0001.failover.node=$nid || {
1879                         error_noexit "Setting MDT1 \"failover.node\""
1880                         return 1
1881                 }
1882                 $r $LCTL conf_param $fsname-MDT0001.lov.stripesize=4M || {
1883                         error_noexit "Setting MDT1 \"lov.stripesize\""
1884                         return 1
1885                 }
1886
1887         fi
1888
1889         if [ "$writeconf" ]; then
1890                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
1891                         error_noexit "Mounting the client"
1892                         return 1
1893                 }
1894                 shall_cleanup_lustre=true
1895                 $LCTL set_param debug="$PTLDEBUG"
1896
1897                 t32_verify_quota $node $fsname $tmp/mnt/lustre || {
1898                         error_noexit "verify quota failed"
1899                         return 1
1900                 }
1901
1902                 if [ "$dne_upgrade" != "no" ]; then
1903                         $LFS mkdir -i 1 -c2 $tmp/mnt/lustre/remote_dir || {
1904                                 error_noexit "set remote dir failed"
1905                                 return 1
1906                         }
1907
1908                         $LFS setdirstripe -D -c2 $tmp/mnt/lustre/remote_dir
1909
1910                         pushd $tmp/mnt/lustre
1911                         tar -cf - . --exclude=./remote_dir |
1912                                 tar -xvf - -C remote_dir 1>/dev/null || {
1913                                 error_noexit "cp to remote dir failed"
1914                                 return 1
1915                         }
1916                         popd
1917                 fi
1918
1919                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
1920                         error_noexit "dd failed"
1921                         return 1
1922                 }
1923                 rm -rf $tmp/mnt/lustre/tmp_file || {
1924                         error_noexit "rm failed"
1925                         return 1
1926                 }
1927
1928                 if $r test -f $tmp/sha1sums; then
1929                         # LU-2393 - do both sorts on same node to ensure locale
1930                         # is identical
1931                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
1932                         if [ "$dne_upgrade" != "no" ]; then
1933                                 pushd $tmp/mnt/lustre/remote_dir
1934                         else
1935                                 pushd $tmp/mnt/lustre
1936                         fi
1937
1938                         find ! -name .lustre -type f -exec sha1sum {} \; |
1939                                 sort -k 2 >$tmp/sha1sums || {
1940                                 error_noexit "sha1sum"
1941                                 return 1
1942                         }
1943                         popd
1944                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
1945                                 error_noexit "sha1sum verification failed"
1946                                 return 1
1947                         fi
1948                 else
1949                         echo "sha1sum verification skipped"
1950                 fi
1951
1952                 if [ "$dne_upgrade" != "no" ]; then
1953                         rm -rf $tmp/mnt/lustre/remote_dir || {
1954                                 error_noexit "remove remote dir failed"
1955                                 return 1
1956                         }
1957                 fi
1958
1959                 if $r test -f $tmp/list; then
1960                         #
1961                         # There is not a Test Framework API to copy files to or
1962                         # from a remote node.
1963                         #
1964                         # LU-2393 - do both sorts on same node to ensure locale
1965                         # is identical
1966                         $r cat $tmp/list | sort -k 6 >$tmp/list.orig
1967                         pushd $tmp/mnt/lustre
1968                         ls -Rni --time-style=+%s | sort -k 6 >$tmp/list || {
1969                                 error_noexit "ls"
1970                                 return 1
1971                         }
1972                         popd
1973                         #
1974                         # 32-bit and 64-bit clients use different algorithms to
1975                         # convert FIDs into inode numbers.  Hence, remove the inode
1976                         # numbers from the lists, if the original list was created
1977                         # on an architecture with different number of bits per
1978                         # "long".
1979                         #
1980                         if [ $(t32_bits_per_long $(uname -m)) != \
1981                                 $(t32_bits_per_long $img_arch) ]; then
1982                                 echo "Different number of bits per \"long\" from the disk image"
1983                                 for list in list.orig list; do
1984                                         sed -i -e 's/^[0-9]\+[ \t]\+//' $tmp/$list
1985                                 done
1986                         fi
1987                         if ! diff -ub $tmp/list.orig $tmp/list; then
1988                                 error_noexit "list verification failed"
1989                                 return 1
1990                         fi
1991                 else
1992                         echo "list verification skipped"
1993                 fi
1994
1995                 #
1996                 # When adding new data verification tests, please check for
1997                 # the presence of the required reference files first, like
1998                 # the "sha1sums" and "list" tests above, to avoid the need to
1999                 # regenerate every image for each test addition.
2000                 #
2001
2002                 nrpcs_orig=$($LCTL get_param \
2003                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
2004                         error_noexit "Getting \"max_rpcs_in_flight\""
2005                         return 1
2006                 }
2007                 nrpcs=$((nrpcs_orig + 5))
2008                 $r $LCTL conf_param $fsname-MDT0000.mdc.max_rpcs_in_flight=$nrpcs || {
2009                         error_noexit "Changing \"max_rpcs_in_flight\""
2010                         return 1
2011                 }
2012                 wait_update $HOSTNAME "$LCTL get_param \
2013                         -n mdc.*MDT0000*.max_rpcs_in_flight" $nrpcs || {
2014                         error_noexit "Verifying \"max_rpcs_in_flight\""
2015                         return 1
2016                 }
2017
2018                 umount $tmp/mnt/lustre || {
2019                         error_noexit "Unmounting the client"
2020                         return 1
2021                 }
2022                 shall_cleanup_lustre=false
2023         else
2024                 if [ "$dne_upgrade" != "no" ]; then
2025                         $r umount -d $tmp/mnt/mdt1 || {
2026                                 error_noexit "Unmounting the MDT2"
2027                                 return 1
2028                         }
2029                         shall_cleanup_mdt1=false
2030                 fi
2031
2032                 $r umount -d $tmp/mnt/mdt || {
2033                         error_noexit "Unmounting the MDT"
2034                         return 1
2035                 }
2036                 shall_cleanup_mdt=false
2037
2038                 $r umount -d $tmp/mnt/ost || {
2039                         error_noexit "Unmounting the OST"
2040                         return 1
2041                 }
2042                 shall_cleanup_ost=false
2043
2044                 t32_reload_modules $node || {
2045                         error_noexit "Reloading modules"
2046                         return 1
2047                 }
2048
2049                 # mount a second time to make sure we didnt leave upgrade flag on
2050                 $r $TUNEFS --dryrun $mdt_dev || {
2051                         $r losetup -a
2052                         error_noexit "tunefs.lustre before remounting the MDT"
2053                         return 1
2054                 }
2055
2056                 mopts=exclude=$fsname-OST0000
2057                 if [ $fstype == "ldiskfs" ]; then
2058                         mopts="loop,$mopts"
2059                 fi
2060                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
2061                         error_noexit "Remounting the MDT"
2062                         return 1
2063                 }
2064                 shall_cleanup_mdt=true
2065         fi
2066 }
2067
2068 test_32a() {
2069         local tarballs
2070         local tarball
2071         local rc=0
2072
2073         t32_check
2074         for tarball in $tarballs; do
2075                 t32_test $tarball || let "rc += $?"
2076         done
2077         return $rc
2078 }
2079 run_test 32a "Upgrade (not live)"
2080
2081 test_32b() {
2082         local tarballs
2083         local tarball
2084         local rc=0
2085
2086         t32_check
2087         for tarball in $tarballs; do
2088                 t32_test $tarball writeconf || let "rc += $?"
2089         done
2090         return $rc
2091 }
2092 run_test 32b "Upgrade with writeconf"
2093
2094 test_32c() {
2095         local tarballs
2096         local tarball
2097         local rc=0
2098
2099         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
2100         t32_check
2101         for tarball in $tarballs; do
2102                 # Do not support 1_8 and 2_1 direct upgrade to DNE2 anymore */
2103                 echo $tarball | grep "1_8" && continue
2104                 echo $tarball | grep "2_1" && continue
2105                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2106         done
2107         return $rc
2108 }
2109 run_test 32c "dne upgrade test"
2110
2111 test_32d() {
2112         local tarballs
2113         local tarball
2114         local rc=0
2115
2116         t32_check
2117         for tarball in $tarballs; do
2118                 ff_convert=yes t32_test $tarball || rc=$?
2119         done
2120         return $rc
2121 }
2122 run_test 32d "convert ff test"
2123
2124 test_33a() { # bug 12333, was test_33
2125         local FSNAME2=test-123
2126         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2127         local mkfsoptions
2128
2129         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
2130
2131         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
2132                 local dev=${SINGLEMDS}_dev
2133                 local MDSDEV=${!dev}
2134                 is_blkdev $SINGLEMDS $MDSDEV &&
2135                         skip_env "mixed loopback and real device not working" &&
2136                         return
2137         fi
2138
2139         local fs2mdsdev=$(mdsdevname 1_2)
2140         local fs2ostdev=$(ostdevname 1_2)
2141         local fs2mdsvdev=$(mdsvdevname 1_2)
2142         local fs2ostvdev=$(ostvdevname 1_2)
2143
2144         if [ $(facet_fstype mds1) == ldiskfs ]; then
2145                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
2146         fi
2147
2148         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2149                 --reformat $mkfsoptions $fs2mdsdev $fs2mdsvdev || exit 10
2150         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2151                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
2152                 $fs2ostvdev || exit 10
2153
2154         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
2155         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2156         do_facet $SINGLEMDS "$LCTL conf_param $FSNAME2.sys.timeout=200" ||
2157                 error "$LCTL conf_param $FSNAME2.sys.timeout=200 failed"
2158         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2159         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2160         echo "ok."
2161
2162         cp /etc/hosts $MOUNT2/ || error "copy /etc/hosts $MOUNT2/ failed"
2163         $GETSTRIPE $MOUNT2/hosts || error "$GETSTRIPE $MOUNT2/hosts failed"
2164
2165         umount -d $MOUNT2
2166         stop fs2ost -f
2167         stop fs2mds -f
2168         cleanup_nocli || error "cleanup_nocli failed with $?"
2169 }
2170 run_test 33a "Mount ost with a large index number"
2171
2172 test_33b() {    # was test_34
2173         setup
2174
2175         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
2176         # Drop lock cancelation reply during umount
2177         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
2178         do_facet client $LCTL set_param fail_loc=0x80000304
2179         #lctl set_param debug=-1
2180         umount_client $MOUNT
2181         cleanup || error "cleanup failed with $?"
2182 }
2183 run_test 33b "Drop cancel during umount"
2184
2185 test_34a() {
2186         setup
2187         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2188         manual_umount_client
2189         rc=$?
2190         do_facet client killall -USR1 multiop
2191         if [ $rc -eq 0 ]; then
2192                 error "umount not fail!"
2193         fi
2194         sleep 1
2195         cleanup || error "cleanup failed with rc $?"
2196 }
2197 run_test 34a "umount with opened file should be fail"
2198
2199 test_34b() {
2200         setup
2201         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2202         stop_mds || error "Unable to stop MDS"
2203
2204         manual_umount_client --force || error "mtab after failed umount with $?"
2205
2206         cleanup || error "cleanup failed with $?"
2207 }
2208 run_test 34b "force umount with failed mds should be normal"
2209
2210 test_34c() {
2211         setup
2212         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2213         stop_ost || error "Unable to stop OST1"
2214
2215         manual_umount_client --force || error "mtab after failed umount with $?"
2216
2217         cleanup || error "cleanup failed with $?"
2218 }
2219 run_test 34c "force umount with failed ost should be normal"
2220
2221 test_35a() { # bug 12459
2222         setup
2223
2224         DBG_SAVE="`$LCTL get_param -n debug`"
2225         $LCTL set_param debug="ha"
2226
2227         log "Set up a fake failnode for the MDS"
2228         FAKENID="127.0.0.2"
2229         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2230                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2231         do_facet mgs "$LCTL conf_param \
2232                       ${device}.failover.node=$(h2$NETTYPE $FAKENID)" ||
2233                 error "Setting ${device}.failover.node=\
2234                        $(h2$NETTYPE $FAKENID) failed."
2235
2236         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2237         sleep 10
2238
2239         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2240         $LCTL clear
2241         log "$MSG"
2242         log "Stopping the MDT: $device"
2243         stop_mdt 1 || error "MDT0 stop fail"
2244
2245         df $MOUNT > /dev/null 2>&1 &
2246         DFPID=$!
2247         log "Restarting the MDT: $device"
2248         start_mdt 1 || error "MDT0 start fail"
2249         log "Wait for df ($DFPID) ... "
2250         wait $DFPID
2251         log "done"
2252         $LCTL set_param debug="$DBG_SAVE"
2253
2254         # retrieve from the log the first server that the client tried to
2255         # contact after the connection loss
2256         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2257         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2258                        /import_select_connection.*$device-mdc.* using connection/ {
2259                                 if (start) {
2260                                         if (\\\$NF ~ /$FAKENID/)
2261                                                 print \\\$NF;
2262                                         else
2263                                                 print 0;
2264                                         exit;
2265                                 }
2266                        }" $TMP/lustre-log-$TESTNAME.log`
2267         [ "$NEXTCONN" != "0" ] &&
2268                 error "Tried to connect to ${NEXTCONN} not last active server"
2269         cleanup || error "cleanup failed with $?"
2270         # remove nid settings
2271         writeconf_or_reformat
2272 }
2273 run_test 35a "Reconnect to the last active server first"
2274
2275 test_35b() { # bug 18674
2276         remote_mds || { skip "local MDS" && return 0; }
2277         setup
2278
2279         debugsave
2280         $LCTL set_param debug="ha"
2281         $LCTL clear
2282         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2283         log "$MSG"
2284
2285         log "Set up a fake failnode for the MDS"
2286         FAKENID="127.0.0.2"
2287         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2288                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2289         do_facet mgs "$LCTL conf_param \
2290                       ${device}.failover.node=$(h2$NETTYPE $FAKENID)" ||
2291                 error "Set ${device}.failover.node=\
2292                        $(h2$NETTYPE $FAKENID) failed"
2293
2294         local at_max_saved=0
2295         # adaptive timeouts may prevent seeing the issue
2296         if at_is_enabled; then
2297                 at_max_saved=$(at_max_get mds)
2298                 at_max_set 0 mds client
2299         fi
2300
2301         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
2302
2303         log "Injecting EBUSY on MDS"
2304         # Setting OBD_FAIL_MDS_RESEND=0x136
2305         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" ||
2306                 error "unable to set param fail_loc=0x80000136"
2307
2308         $LCTL set_param mdc.${FSNAME}*.stats=clear
2309
2310         log "Creating a test file and stat it"
2311         touch $MOUNT/$tdir/$tfile || error "touch $MOUNT/$tdir/$tfile failed"
2312         stat $MOUNT/$tdir/$tfile
2313
2314         log "Stop injecting EBUSY on MDS"
2315         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" ||
2316                 error "unable to set param fail_loc=0"
2317         rm -f $MOUNT/$tdir/$tfile || error "remove $MOUNT/$tdir/$tfile failed"
2318
2319         log "done"
2320         # restore adaptive timeout
2321         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2322
2323         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2324
2325         CONNCNT=$($LCTL get_param mdc.${FSNAME}*.stats |
2326                   awk '/mds_connect/{print $2}')
2327
2328         # retrieve from the log if the client has ever tried to
2329         # contact the fake server after the loss of connection
2330         FAILCONN=`awk "BEGIN {ret = 0;}
2331                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2332                                 ret = 1;
2333                                 if (\\\$NF ~ /$FAKENID/) {
2334                                         ret = 2;
2335                                         exit;
2336                                 }
2337                        }
2338                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2339
2340         [ "$FAILCONN" == "0" ] &&
2341                 error "The client reconnection has not been triggered"
2342         [ "$FAILCONN" == "2" ] &&
2343                 error "Primary server busy, client reconnect to failover failed"
2344
2345         # LU-290
2346         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2347         # Reconnects are supposed to be rate limited to one every 5s
2348         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] &&
2349                 error "Too many reconnects $CONNCNT"
2350
2351         cleanup || error "cleanup failed with $?"
2352         # remove nid settings
2353         writeconf_or_reformat
2354 }
2355 run_test 35b "Continue reconnection retries, if the active server is busy"
2356
2357 test_36() { # 12743
2358         [ $OSTCOUNT -lt 2 ] && skip_env "skipping test for single OST" && return
2359
2360         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] ||
2361                 { skip "remote OST" && return 0; }
2362
2363         local rc=0
2364         local FSNAME2=test1234
2365         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2366
2367         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2368
2369         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2370                 is_blkdev $SINGLEMDS $MDSDEV &&
2371                 skip_env "mixed loopback and real device not working" && return
2372         fi
2373
2374         local fs2mdsdev=$(mdsdevname 1_2)
2375         local fs2ostdev=$(ostdevname 1_2)
2376         local fs3ostdev=$(ostdevname 2_2)
2377         local fs2mdsvdev=$(mdsvdevname 1_2)
2378         local fs2ostvdev=$(ostvdevname 1_2)
2379         local fs3ostvdev=$(ostvdevname 2_2)
2380
2381         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2382                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2383         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2384         #     different one than the default value here.
2385         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2386                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2387         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
2388                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2389
2390         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2391         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2392         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2393         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2394         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2395
2396         sleep 5 # until 11778 fixed
2397
2398         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || error "dd failed"
2399
2400         BKTOTAL=$($LCTL get_param -n obdfilter.*.kbytestotal |
2401                   awk 'BEGIN{total=0}; {total+=$1}; END{print total}')
2402         BKFREE=$($LCTL get_param -n obdfilter.*.kbytesfree |
2403                  awk 'BEGIN{free=0}; {free+=$1}; END{print free}')
2404         BKAVAIL=$($LCTL get_param -n obdfilter.*.kbytesavail |
2405                   awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2406         STRING=$(df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}')
2407         DFTOTAL=$(echo $STRING | cut -d, -f1)
2408         DFUSED=$(echo $STRING  | cut -d, -f2)
2409         DFAVAIL=$(echo $STRING | cut -d, -f3)
2410         DFFREE=$(($DFTOTAL - $DFUSED))
2411
2412         ALLOWANCE=$((64 * $OSTCOUNT))
2413
2414         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2415            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2416                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2417                 rc=1
2418         fi
2419         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2420            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2421                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2422                 rc=2
2423         fi
2424         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2425            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2426                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2427                 rc=3
2428        fi
2429
2430         umount -d $MOUNT2
2431         stop fs3ost -f || error "unable to stop OST3"
2432         stop fs2ost -f || error "unable to stop OST2"
2433         stop fs2mds -f || error "unable to stop second MDS"
2434         unload_modules_conf || error "unable unload modules"
2435         return $rc
2436 }
2437 run_test 36 "df report consistency on OSTs with different block size"
2438
2439 test_37() {
2440         local mntpt=$(facet_mntpt $SINGLEMDS)
2441         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2442         local mdsdev_sym="$TMP/sym_mdt.img"
2443         local opts=$MDS_MOUNT_OPTS
2444         local rc=0
2445
2446         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2447                 skip "Currently only applicable to ldiskfs-based MDTs"
2448                 return
2449         fi
2450
2451         echo "MDS :     $mdsdev"
2452         echo "SYMLINK : $mdsdev_sym"
2453         do_facet $SINGLEMDS rm -f $mdsdev_sym
2454
2455         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2456
2457         echo "mount symlink device - $mdsdev_sym"
2458
2459         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2460                 opts=$(csa_add "$opts" -o loop)
2461         fi
2462         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2463                 $mdsdev_sym $mntpt 2>&1)
2464         rc=${PIPESTATUS[0]}
2465
2466         echo mount_op=$mount_op
2467
2468         do_facet $SINGLEMDS "umount -d $mntpt && rm -f $mdsdev_sym"
2469
2470         if $(echo $mount_op | grep -q "unable to set tunable"); then
2471                 error "set tunables failed for symlink device"
2472         fi
2473
2474         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2475 }
2476 run_test 37 "verify set tunables works for symlink device"
2477
2478 test_38() { # bug 14222
2479         local fstype=$(facet_fstype $SINGLEMDS)
2480         local mntpt=$(facet_mntpt $SINGLEMDS)
2481
2482         setup
2483         # like runtests
2484         local COUNT=10
2485         local SRC="/etc /bin"
2486         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
2487         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2488         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2489         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
2490                 error "copying $SRC to $DIR/$tdir"
2491         sync
2492         umount_client $MOUNT || error "umount_client $MOUNT failed"
2493         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2494         stop_mds || error "Unable to stop MDS"
2495         log "delete lov_objid file on MDS"
2496
2497         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
2498
2499         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
2500
2501         unmount_fstype $SINGLEMDS || error "umount failed (1)"
2502
2503         # check create in mds_lov_connect
2504         start_mds || error "unable to start MDS"
2505         mount_client $MOUNT || error "mount_client $MOUNT failed"
2506         for f in $FILES; do
2507                 [ $V ] && log "verifying $DIR/$tdir/$f"
2508                 diff -q $f $DIR/$tdir/$f || ERROR=y
2509         done
2510         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2511         if [ "$ERROR" = "y" ]; then
2512                 # check it's updates in sync
2513                 umount_client $MOUNT
2514                 stop_mds
2515                 mount_fstype $SIGNLEMDS
2516                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2517                 unmount_fstype $SINGLEMDS
2518                 error "old and new files are different after connect" || true
2519         fi
2520         touch $DIR/$tdir/f2 || error "f2 file create failed"
2521
2522         # check it's updates in sync
2523         umount_client $MOUNT || error "second umount_client $MOUNT failed"
2524         stop_mds
2525
2526         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
2527
2528         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2529         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
2530
2531         unmount_fstype $SINGLEMDS || error "umount failed (3)"
2532
2533         start_mds || error "unable to start MDS"
2534         mount_client $MOUNT || error "mount_client $MOUNT failed"
2535         for f in $FILES; do
2536                 [ $V ] && log "verifying $DIR/$tdir/$f"
2537                 diff -q $f $DIR/$tdir/$f || ERROR=y
2538         done
2539         touch $DIR/$tdir/f3 || error "f3 file create failed"
2540         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2541         umount_client $MOUNT || error "third umount_client $MOUNT failed"
2542         stop_mds
2543         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
2544         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2545         unmount_fstype $SINGLEMDS || error "umount failed (4)"
2546
2547         [ "$ERROR" = "y" ] &&
2548                 error "old and new files are different after sync" || true
2549
2550         log "files compared the same"
2551         cleanup || error "cleanup failed with $?"
2552 }
2553 run_test 38 "MDS recreates missing lov_objid file from OST data"
2554
2555 test_39() {
2556         PTLDEBUG=+malloc
2557         setup
2558         cleanup || error "cleanup failed with $?"
2559         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2560                 error "memory leak detected" || true
2561 }
2562 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2563
2564 test_40() { # bug 15759
2565         start_ost || error "Unable to start OST1"
2566         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2567         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2568         start_mds
2569         cleanup || error "cleanup failed with rc $?"
2570 }
2571 run_test 40 "race during service thread startup"
2572
2573 test_41a() { #bug 14134
2574         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2575            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2576                 skip "Loop devices does not work with nosvc option"
2577                 return
2578         fi
2579
2580         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2581
2582         start_mdt 1 -o nosvc -n
2583         if [ $MDSCOUNT -ge 2 ]; then
2584                 for num in $(seq 2 $MDSCOUNT); do
2585                         start_mdt $num || return
2586                 done
2587         fi
2588         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
2589         start_mdt 1 -o nomgs,force
2590         mount_client $MOUNT || error "mount_client $MOUNT failed"
2591         sleep 5
2592
2593         echo "blah blah" > $MOUNT/$tfile
2594         cat $MOUNT/$tfile
2595
2596         umount_client $MOUNT || error "umount_client $MOUNT failed"
2597         stop ost1 -f || error "unable to stop OST1"
2598         stop_mds || error "Unable to stop MDS"
2599         stop_mds || error "Unable to stop MDS on second try"
2600         unload_modules_conf || error "unload_modules_conf failed"
2601 }
2602 run_test 41a "mount mds with --nosvc and --nomgs"
2603
2604 test_41b() {
2605         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2606            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2607                 skip "Loop devices does not work with nosvc option"
2608                 return
2609         fi
2610
2611         ! combined_mgs_mds && skip "needs combined mgs device" && return 0
2612
2613         stopall
2614         reformat
2615         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2616
2617         start_mdt 1 -o nosvc -n
2618         if [ $MDSCOUNT -ge 2 ]; then
2619                 for num in $(seq 2 $MDSCOUNT); do
2620                         start_mdt $num || return
2621                 done
2622         fi
2623         start_ost || error "Unable to start OST1"
2624         start_mdt 1 -o nomgs,force
2625         mount_client $MOUNT || error "mount_client $MOUNT failed"
2626         sleep 5
2627
2628         echo "blah blah" > $MOUNT/$tfile
2629         cat $MOUNT/$tfile || error "cat $MOUNT/$tfile failed"
2630
2631         umount_client $MOUNT || error "umount_client $MOUNT failed"
2632         stop_ost || error "Unable to stop OST1"
2633         stop_mds || error "Unable to stop MDS"
2634         stop_mds || error "Unable to stop MDS on second try"
2635 }
2636 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2637
2638 test_41c() {
2639         local server_version=$(lustre_version_code $SINGLEMDS)
2640
2641         [[ $server_version -ge $(version_code 2.6.52) ]] ||
2642         [[ $server_version -ge $(version_code 2.5.26) &&
2643            $server_version -lt $(version_code 2.5.50) ]] ||
2644         [[ $server_version -ge $(version_code 2.5.4) &&
2645            $server_version -lt $(version_code 2.5.11) ]] ||
2646                 { skip "Need MDS version 2.5.4+ or 2.5.26+ or 2.6.52+"; return; }
2647
2648         cleanup
2649         # MDT concurrent start
2650         #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
2651         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x703"
2652         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
2653         local pid=$!
2654         sleep 2
2655         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x0"
2656         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS &
2657         local pid2=$!
2658         wait $pid2
2659         local rc2=$?
2660         wait $pid
2661         local rc=$?
2662         if [ $rc == 0 ] && [ $rc2 == 114 ]; then
2663                 echo "1st MDT start succeed"
2664                 echo "2nd MDT start failed with EALREADY"
2665         elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
2666                 echo "1st MDT start failed with EALREADY"
2667                 echo "2nd MDT start succeed"
2668         else
2669                 stop mds1 -f
2670                 error "unexpected concurrent MDT mounts result, rc=$rc rc2=$rc2"
2671         fi
2672
2673         if [ $MDSCOUNT -ge 2 ]; then
2674                 for num in $(seq 2 $MDSCOUNT); do
2675                         start_mdt $num || return
2676                 done
2677         fi
2678
2679         # OST concurrent start
2680
2681         #define OBD_FAIL_TGT_DELAY_CONNECT 0x703
2682         do_facet ost1 "$LCTL set_param fail_loc=0x703"
2683         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
2684         pid=$!
2685         sleep 2
2686         do_facet ost1 "$LCTL set_param fail_loc=0x0"
2687         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &
2688         pid2=$!
2689         wait $pid2
2690         rc2=$?
2691         wait $pid
2692         rc=$?
2693         if [ $rc == 0 ] && [ $rc2 == 114 ]; then
2694                 echo "1st OST start succeed"
2695                 echo "2nd OST start failed with EALREADY"
2696         elif [ $rc2 == 0 ] && [ $rc == 114 ]; then
2697                 echo "1st OST start failed with EALREADY"
2698                 echo "2nd OST start succeed"
2699         else
2700                 stop_mds -f
2701                 stop ost1 -f
2702                 error "unexpected concurrent OST mounts result, rc=$rc rc2=$rc2"
2703         fi
2704         # cleanup
2705         stop_mds
2706         stop ost1 -f
2707
2708         # verify everything ok
2709         start_mds
2710         if [ $? != 0 ]
2711         then
2712                 stop_mds
2713                 error "MDT(s) start failed"
2714         fi
2715
2716         start_ost
2717         if [ $? != 0 ]
2718         then
2719                 stop_mds
2720                 stop ost1 -f
2721                 error "OST(s) start failed"
2722         fi
2723
2724         mount_client $MOUNT
2725         if [ $? != 0 ]
2726         then
2727                 stop_mds
2728                 stop ost1 -f
2729                 error "client start failed"
2730         fi
2731         check_mount
2732         if [ $? != 0 ]
2733         then
2734                 stop_mds
2735                 stop ost1 -f
2736                 error "client mount failed"
2737         fi
2738         cleanup
2739 }
2740 run_test 41c "concurrent mounts of MDT/OST should all fail but one"
2741
2742 test_42() { #bug 14693
2743         setup
2744         check_mount || error "client was not mounted"
2745
2746         do_facet mgs $LCTL conf_param $FSNAME.llite.some_wrong_param=10
2747         umount_client $MOUNT ||
2748                 error "unmounting client failed with invalid llite param"
2749         mount_client $MOUNT ||
2750                 error "mounting client failed with invalid llite param"
2751
2752         do_facet mgs $LCTL conf_param $FSNAME.sys.some_wrong_param=20
2753         cleanup || error "stopping $FSNAME failed with invalid sys param"
2754         load_modules
2755         setup
2756         check_mount || error "client was not mounted with invalid sys param"
2757         cleanup || error "stopping $FSNAME failed with invalid sys param"
2758 }
2759 run_test 42 "allow client/server mount/unmount with invalid config param"
2760
2761 test_43() {
2762         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
2763                 { skip "Need MDS version at least 2.5.58" && return 0; }
2764         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
2765
2766         ID1=${ID1:-501}
2767         USER1=$(cat /etc/passwd | grep :$ID1:$ID1: | cut -d: -f1)
2768         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1" &&
2769                 return
2770
2771         setup
2772         chmod ugo+x $DIR || error "chmod 0 failed"
2773         set_conf_param_and_check mds                                    \
2774                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.root_squash"    \
2775                 "$FSNAME.mdt.root_squash"                               \
2776                 "0:0"
2777         wait_update $HOSTNAME                                           \
2778                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
2779                 "0:0" ||
2780                 error "check llite root_squash failed!"
2781         set_conf_param_and_check mds                                    \
2782                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"  \
2783                 "$FSNAME.mdt.nosquash_nids"                             \
2784                 "NONE"
2785         wait_update $HOSTNAME                                           \
2786                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
2787                 "NONE" ||
2788                 error "check llite nosquash_nids failed!"
2789
2790     #
2791     # create set of test files
2792     #
2793     echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
2794     chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
2795     chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
2796
2797     echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
2798     chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
2799
2800         mkdir $DIR/$tdir-rootdir || error "mkdir failed"
2801         chmod go-rwx $DIR/$tdir-rootdir || error "chmod 3 failed"
2802         touch $DIR/$tdir-rootdir/tfile-1 || error "touch failed"
2803
2804         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
2805         chmod go-rw $DIR/$tfile-user1file || error "chmod 7 failed"
2806         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
2807
2808         #
2809         # check root_squash:
2810         #   set root squash UID:GID to RUNAS_ID
2811         #   root should be able to access only files owned by RUNAS_ID
2812         #
2813         set_conf_param_and_check mds                                    \
2814                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.root_squash"    \
2815                 "$FSNAME.mdt.root_squash"                               \
2816                 "$RUNAS_ID:$RUNAS_ID"
2817         wait_update $HOSTNAME                                           \
2818                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
2819                 "$RUNAS_ID:$RUNAS_ID" ||
2820                 error "check llite root_squash failed!"
2821
2822         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
2823         dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
2824                 error "$ST: root read permission is denied"
2825         echo "$ST: root read permission is granted - ok"
2826
2827         echo "444" |
2828         dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
2829                 error "$ST: root write permission is denied"
2830         echo "$ST: root write permission is granted - ok"
2831
2832         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2833         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
2834                 error "$ST: root read permission is granted"
2835         echo "$ST: root read permission is denied - ok"
2836
2837         echo "555" |
2838         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
2839                 error "$ST: root write permission is granted"
2840         echo "$ST: root write permission is denied - ok"
2841
2842         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2843                 rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null &&
2844                         error "$ST: root unlink permission is granted"
2845         echo "$ST: root unlink permission is denied - ok"
2846
2847         touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null &&
2848                 error "$ST: root create permission is granted"
2849         echo "$ST: root create permission is denied - ok"
2850
2851         # LU-1778
2852         # check root_squash is enforced independently
2853         # of client cache content
2854         #
2855         # access file by USER1, keep access open
2856         # root should be denied access to user file
2857
2858         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
2859         pid=$!
2860         sleep 1
2861
2862         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
2863         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2864             { kill $pid; error "$ST: root read permission is granted"; }
2865         echo "$ST: root read permission is denied - ok"
2866
2867         echo "777" |
2868         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
2869             { kill $pid; error "$ST: root write permission is granted"; }
2870         echo "$ST: root write permission is denied - ok"
2871
2872         kill $pid
2873         wait $pid
2874
2875         #
2876         # check nosquash_nids:
2877         #   put client's NID into nosquash_nids list,
2878         #   root should be able to access root file after that
2879         #
2880         local NIDLIST=$($LCTL list_nids all | tr '\n' ' ')
2881         NIDLIST="2@elan $NIDLIST 192.168.0.[2,10]@tcp"
2882         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
2883         set_conf_param_and_check mds                                    \
2884                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.nosquash_nids"  \
2885                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
2886                 "$NIDLIST"
2887         wait_update $HOSTNAME                                           \
2888                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
2889                 "$NIDLIST" ||
2890                 error "check llite nosquash_nids failed!"
2891
2892         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
2893         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
2894                 error "$ST: root read permission is denied"
2895         echo "$ST: root read permission is granted - ok"
2896
2897         echo "666" |
2898         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
2899                 error "$ST: root write permission is denied"
2900         echo "$ST: root write permission is granted - ok"
2901
2902         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
2903         rm $DIR/$tdir-rootdir/tfile-1 ||
2904                 error "$ST: root unlink permission is denied"
2905         echo "$ST: root unlink permission is granted - ok"
2906         touch $DIR/$tdir-rootdir/tfile-2 ||
2907                 error "$ST: root create permission is denied"
2908         echo "$ST: root create permission is granted - ok"
2909 }
2910 run_test 43 "check root_squash and nosquash_nids"
2911
2912 umount_client $MOUNT
2913 cleanup_nocli
2914
2915 test_44() { # 16317
2916         setup
2917         check_mount || error "check_mount"
2918         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
2919         STATS_FOUND=no
2920         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
2921         for VAL in $UUIDS; do
2922                 NID=$(echo $VAL | cut -d= -f1)
2923                 CLUUID=$(echo $VAL | cut -d= -f2)
2924                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
2925         done
2926         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
2927         cleanup || error "cleanup failed with $?"
2928 }
2929 run_test 44 "mounted client proc entry exists"
2930
2931 test_45() { #17310
2932         setup
2933         check_mount || error "check_mount"
2934         stop_mds || error "Unable to stop MDS"
2935         df -h $MOUNT &
2936         log "sleep 60 sec"
2937         sleep 60
2938         #define OBD_FAIL_PTLRPC_LONG_UNLINK   0x50f
2939         do_facet client "$LCTL set_param fail_loc=0x50f"
2940         log "sleep 10 sec"
2941         sleep 10
2942         manual_umount_client --force || error "manual_umount_client failed"
2943         do_facet client "$LCTL set_param fail_loc=0x0"
2944         start_mds || error "unable to start MDS"
2945         mount_client $MOUNT || error "mount_client $MOUNT failed"
2946         cleanup || error "cleanup failed with $?"
2947 }
2948 run_test 45 "long unlink handling in ptlrpcd"
2949
2950 cleanup_46a() {
2951         trap 0
2952         local rc=0
2953         local count=$1
2954
2955         umount_client $MOUNT2 || rc=$?
2956         umount_client $MOUNT || rc=$?
2957         while [ $count -gt 0 ]; do
2958                 stop ost${count} -f || rc=$?
2959                 let count=count-1
2960         done
2961         stop_mds || rc=$?
2962         cleanup_nocli || rc=$?
2963         #writeconf to remove all ost2 traces for subsequent tests
2964         writeconf_or_reformat
2965         return $rc
2966 }
2967
2968 test_46a() {
2969         echo "Testing with $OSTCOUNT OSTs"
2970         reformat_and_config
2971         start_mds || error "unable to start MDS"
2972         #first client should see only one ost
2973         start_ost || error "Unable to start OST1"
2974         wait_osc_import_state mds ost FULL
2975         #start_client
2976         mount_client $MOUNT || error "mount_client $MOUNT failed"
2977         trap "cleanup_46a $OSTCOUNT" EXIT ERR
2978
2979         local i
2980         for (( i=2; i<=$OSTCOUNT; i++ )); do
2981                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
2982                         error "start_ost$i $(ostdevname $i) failed"
2983         done
2984
2985         # wait until osts in sync
2986         for (( i=2; i<=$OSTCOUNT; i++ )); do
2987             wait_osc_import_state mds ost$i FULL
2988             wait_osc_import_state client ost$i FULL
2989         done
2990
2991         #second client see all ost's
2992
2993         mount_client $MOUNT2 || error "mount_client failed"
2994         $SETSTRIPE -c -1 $MOUNT2 || error "$SETSTRIPE -c -1 $MOUNT2 failed"
2995         $GETSTRIPE $MOUNT2 || error "$GETSTRIPE $MOUNT2 failed"
2996
2997         echo "ok" > $MOUNT2/widestripe
2998         $GETSTRIPE $MOUNT2/widestripe ||
2999                 error "$GETSTRIPE $MOUNT2/widestripe failed"
3000         # fill acl buffer for avoid expand lsm to them
3001         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd |
3002                 while read acl; do
3003             setfacl -m $acl $MOUNT2/widestripe
3004         done
3005
3006         # will be deadlock
3007         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3008
3009         cleanup_46a $OSTCOUNT || error "cleanup_46a failed"
3010 }
3011 run_test 46a "handle ost additional - wide striped file"
3012
3013 test_47() { #17674
3014         reformat
3015         setup_noconfig
3016         check_mount || error "check_mount failed"
3017         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
3018
3019         local lru_size=[]
3020         local count=0
3021         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3022             if echo $ns | grep "MDT[[:digit:]]*"; then
3023                 continue
3024             fi
3025             lrs=$(echo $ns | sed 's/.*lru_size=//')
3026             lru_size[count]=$lrs
3027             let count=count+1
3028         done
3029
3030         facet_failover ost1
3031         facet_failover $SINGLEMDS
3032         client_up || error "client_up failed"
3033
3034         count=0
3035         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3036             if echo $ns | grep "MDT[[:digit:]]*"; then
3037                 continue
3038             fi
3039             lrs=$(echo $ns | sed 's/.*lru_size=//')
3040             if ! test "$lrs" -eq "${lru_size[count]}"; then
3041                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
3042                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
3043             fi
3044             let count=count+1
3045         done
3046
3047         cleanup || error "cleanup failed with $?"
3048 }
3049 run_test 47 "server restart does not make client loss lru_resize settings"
3050
3051 cleanup_48() {
3052         trap 0
3053
3054         # reformat after this test is needed - if the test fails,
3055         # we will have unkillable file at FS
3056         reformat_and_config
3057 }
3058
3059 test_48() { # bug 17636
3060         reformat
3061         setup_noconfig
3062         check_mount || error "check_mount failed"
3063
3064         $SETSTRIPE -c -1 $MOUNT || error "$SETSTRIPE -c -1 $MOUNT failed"
3065         $GETSTRIPE $MOUNT || error "$GETSTRIPE $MOUNT failed"
3066
3067         echo "ok" > $MOUNT/widestripe
3068         $GETSTRIPE $MOUNT/widestripe ||
3069                 error "$GETSTRIPE $MOUNT/widestripe failed"
3070
3071         trap cleanup_48 EXIT ERR
3072
3073         # fill acl buffer for avoid expand lsm to them
3074         getent passwd | awk -F : '{ print "u:"$1":rwx" }' |  while read acl; do
3075             setfacl -m $acl $MOUNT/widestripe
3076         done
3077
3078         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3079
3080         cleanup_48
3081 }
3082 run_test 48 "too many acls on file"
3083
3084 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
3085 test_49a() { # bug 17710
3086         local timeout_orig=$TIMEOUT
3087         local ldlm_timeout_orig=$LDLM_TIMEOUT
3088         local LOCAL_TIMEOUT=20
3089
3090         LDLM_TIMEOUT=$LOCAL_TIMEOUT
3091         TIMEOUT=$LOCAL_TIMEOUT
3092
3093         reformat
3094         setup_noconfig
3095         check_mount || error "client mount failed"
3096
3097         echo "check ldlm_timout..."
3098         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3099         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3100         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3101
3102         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3103                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3104         fi
3105
3106         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
3107                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
3108         fi
3109
3110         umount_client $MOUNT || error "umount_client $MOUNT failed"
3111         stop_ost || error "problem stopping OSS"
3112         stop_mds || error "problem stopping MDS"
3113
3114         LDLM_TIMEOUT=$ldlm_timeout_orig
3115         TIMEOUT=$timeout_orig
3116 }
3117 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3118
3119 test_49b() { # bug 17710
3120         local timeout_orig=$TIMEOUT
3121         local ldlm_timeout_orig=$LDLM_TIMEOUT
3122         local LOCAL_TIMEOUT=20
3123
3124         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
3125         TIMEOUT=$LOCAL_TIMEOUT
3126
3127         reformat
3128         setup_noconfig
3129         check_mount || error "client mount failed"
3130
3131         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3132         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3133         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3134
3135         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3136                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3137         fi
3138
3139         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
3140                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
3141         fi
3142
3143         cleanup || error "cleanup failed"
3144
3145         LDLM_TIMEOUT=$ldlm_timeout_orig
3146         TIMEOUT=$timeout_orig
3147 }
3148 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3149
3150 lazystatfs() {
3151         # Test both statfs and lfs df and fail if either one fails
3152         multiop_bg_pause $1 f_
3153         RC1=$?
3154         PID=$!
3155         killall -USR1 multiop
3156         [ $RC1 -ne 0 ] && log "lazystatfs multiop failed"
3157         wait $PID || { RC1=$?; log "multiop return error "; }
3158
3159         $LFS df &
3160         PID=$!
3161         sleep 5
3162         kill -s 0 $PID
3163         RC2=$?
3164         if [ $RC2 -eq 0 ]; then
3165             kill -s 9 $PID
3166             log "lazystatfs df failed"
3167         fi
3168
3169         RC=0
3170         [[ $RC1 -ne 0 || $RC2 -eq 0 ]] && RC=1
3171         return $RC
3172 }
3173
3174 test_50a() {
3175         setup
3176         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3177         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3178
3179         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3180
3181         cleanup || error "cleanup failed with rc $?"
3182 }
3183 run_test 50a "lazystatfs all servers available"
3184
3185 test_50b() {
3186         setup
3187         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3188         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3189
3190         # Wait for client to detect down OST
3191         stop_ost || error "Unable to stop OST1"
3192         wait_osc_import_state mds ost DISCONN
3193
3194         lazystatfs $MOUNT || error "lazystatfs should not return EIO"
3195
3196         umount_client $MOUNT || error "Unable to unmount client"
3197         stop_mds || error "Unable to stop MDS"
3198 }
3199 run_test 50b "lazystatfs all servers down"
3200
3201 test_50c() {
3202         start_mds || error "Unable to start MDS"
3203         start_ost || error "Unable to start OST1"
3204         start_ost2 || error "Unable to start OST2"
3205         mount_client $MOUNT || error "Unable to mount client"
3206         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3207         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3208
3209         # Wait for client to detect down OST
3210         stop_ost || error "Unable to stop OST1"
3211         wait_osc_import_state mds ost DISCONN
3212         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3213
3214         umount_client $MOUNT || error "Unable to unmount client"
3215         stop_ost2 || error "Unable to stop OST2"
3216         stop_mds || error "Unable to stop MDS"
3217         #writeconf to remove all ost2 traces for subsequent tests
3218         writeconf_or_reformat
3219 }
3220 run_test 50c "lazystatfs one server down"
3221
3222 test_50d() {
3223         start_mds || error "Unable to start MDS"
3224         start_ost || error "Unable to start OST1"
3225         start_ost2 || error "Unable to start OST2"
3226         mount_client $MOUNT || error "Unable to mount client"
3227         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3228         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3229
3230         # Issue the statfs during the window where the client still
3231         # belives the OST to be available but it is in fact down.
3232         # No failure just a statfs which hangs for a timeout interval.
3233         stop_ost || error "Unable to stop OST1"
3234         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3235
3236         umount_client $MOUNT || error "Unable to unmount client"
3237         stop_ost2 || error "Unable to stop OST2"
3238         stop_mds || error "Unable to stop MDS"
3239         #writeconf to remove all ost2 traces for subsequent tests
3240         writeconf_or_reformat
3241 }
3242 run_test 50d "lazystatfs client/server conn race"
3243
3244 test_50e() {
3245         local RC1
3246         local pid
3247
3248         reformat_and_config
3249         start_mds || error "Unable to start MDS"
3250         #first client should see only one ost
3251         start_ost || error "Unable to start OST1"
3252         wait_osc_import_state mds ost FULL
3253
3254         # Wait for client to detect down OST
3255         stop_ost || error "Unable to stop OST1"
3256         wait_osc_import_state mds ost DISCONN
3257
3258         mount_client $MOUNT || error "Unable to mount client"
3259         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3260
3261         multiop_bg_pause $MOUNT _f
3262         RC1=$?
3263         pid=$!
3264
3265         if [ $RC1 -ne 0 ]; then
3266                 log "multiop failed $RC1"
3267         else
3268             kill -USR1 $pid
3269             sleep $(( $TIMEOUT+1 ))
3270             kill -0 $pid
3271             [ $? -ne 0 ] && error "process isn't sleep"
3272             start_ost || error "Unable to start OST1"
3273             wait $pid || error "statfs failed"
3274         fi
3275
3276         umount_client $MOUNT || error "Unable to unmount client"
3277         stop_ost || error "Unable to stop OST1"
3278         stop_mds || error "Unable to stop MDS"
3279 }
3280 run_test 50e "normal statfs all servers down"
3281
3282 test_50f() {
3283         local RC1
3284         local pid
3285         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
3286
3287         start_mds || error "Unable to start mds"
3288         #first client should see only one ost
3289         start_ost || error "Unable to start OST1"
3290         wait_osc_import_state mds ost FULL
3291
3292         start_ost2 || error "Unable to start OST2"
3293         wait_osc_import_state mds ost2 FULL
3294
3295         # Wait for client to detect down OST
3296         stop_ost2 || error "Unable to stop OST2"
3297
3298         wait_osc_import_state mds ost2 DISCONN
3299         mount_client $MOUNT || error "Unable to mount client"
3300         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3301
3302         multiop_bg_pause $MOUNT _f
3303         RC1=$?
3304         pid=$!
3305
3306         if [ $RC1 -ne 0 ]; then
3307                 log "lazystatfs multiop failed $RC1"
3308         else
3309             kill -USR1 $pid
3310             sleep $(( $TIMEOUT+1 ))
3311             kill -0 $pid
3312             [ $? -ne 0 ] && error "process isn't sleep"
3313             start_ost2 || error "Unable to start OST2"
3314             wait $pid || error "statfs failed"
3315             stop_ost2 || error "Unable to stop OST2"
3316         fi
3317
3318         umount_client $MOUNT || error "Unable to unmount client"
3319         stop_ost || error "Unable to stop OST1"
3320         stop_mds || error "Unable to stop MDS"
3321         #writeconf to remove all ost2 traces for subsequent tests
3322         writeconf_or_reformat
3323 }
3324 run_test 50f "normal statfs one server in down"
3325
3326 test_50g() {
3327         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3328         setup
3329         start_ost2 || error "Unable to start OST2"
3330         wait_osc_import_state mds ost2 FULL
3331         wait_osc_import_state client ost2 FULL
3332
3333         local PARAM="${FSNAME}-OST0001.osc.active"
3334
3335         $SETSTRIPE -c -1 $DIR/$tfile || error "$SETSTRIPE failed"
3336         do_facet mgs $LCTL conf_param $PARAM=0 ||
3337                 error "Unable to deactivate OST"
3338
3339         umount_client $MOUNT || error "Unable to unmount client"
3340         mount_client $MOUNT || error "Unable to mount client"
3341         # This df should not cause a panic
3342         df -k $MOUNT
3343
3344         do_facet mgs $LCTL conf_param $PARAM=1 || error "Unable to activate OST"
3345         rm -f $DIR/$tfile || error "unable to remove file $DIR/$tfile"
3346         umount_client $MOUNT || error "Unable to unmount client"
3347         stop_ost2 || error "Unable to stop OST2"
3348         stop_ost || error "Unable to stop OST1"
3349         stop_mds || error "Unable to stop MDS"
3350         #writeconf to remove all ost2 traces for subsequent tests
3351         writeconf_or_reformat
3352 }
3353 run_test 50g "deactivated OST should not cause panic"
3354
3355 # LU-642
3356 test_50h() {
3357         # prepare MDT/OST, make OSC inactive for OST1
3358         [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2, skipping" && return
3359
3360         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3361         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
3362                 error "tunefs OST1 failed"
3363         start_mds  || error "Unable to start MDT"
3364         start_ost  || error "Unable to start OST1"
3365         start_ost2 || error "Unable to start OST2"
3366         mount_client $MOUNT || error "client start failed"
3367
3368         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3369
3370         # activatate OSC for OST1
3371         local TEST="$LCTL get_param -n osc.${FSNAME}-OST0000-osc-[!M]*.active"
3372         set_conf_param_and_check client                                 \
3373                 "$TEST" "${FSNAME}-OST0000.osc.active" 1 ||
3374                 error "Unable to activate OST1"
3375
3376         mkdir $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
3377         $SETSTRIPE -c -1 -i 0 $DIR/$tdir/2 ||
3378                 error "$SETSTRIPE $DIR/$tdir/2 failed"
3379         sleep 1 && echo "create a file after OST1 is activated"
3380         # create some file
3381         createmany -o $DIR/$tdir/2/$tfile-%d 1
3382
3383         # check OSC import is working
3384         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3385                 error "some OSC imports are still not connected"
3386
3387         # cleanup
3388         umount_client $MOUNT || error "Unable to umount client"
3389         stop_ost2 || error "Unable to stop OST2"
3390         cleanup_nocli || error "cleanup_nocli failed with $?"
3391 }
3392 run_test 50h "LU-642: activate deactivated OST"
3393
3394 test_50i() {
3395         # prepare MDT/OST, make OSC inactive for OST1
3396         [ "$MDSCOUNT" -lt "2" ] && skip_env "$MDSCOUNT < 2, skipping" && return
3397
3398         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3399         load_modules
3400         do_facet mds2 "$TUNEFS --param mdc.active=0 $(mdsdevname 2)" ||
3401                 error "tunefs MDT2 failed"
3402         start_mds  || error "Unable to start MDT"
3403         start_ost  || error "Unable to start OST1"
3404         start_ost2 || error "Unable to start OST2"
3405         mount_client $MOUNT || error "client start failed"
3406
3407         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3408
3409         $LCTL conf_param ${FSNAME}-MDT0000.mdc.active=0 &&
3410                 error "deactive MDC0 succeeds"
3411         # activate MDC for MDT2
3412         local TEST="$LCTL get_param -n mdc.${FSNAME}-MDT0001-mdc-[!M]*.active"
3413         set_conf_param_and_check client                                 \
3414                 "$TEST" "${FSNAME}-MDT0001.mdc.active" 1 ||
3415                 error "Unable to activate MDT2"
3416
3417         $LFS mkdir -i1 $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
3418         # create some file
3419         createmany -o $DIR/$tdir/2/$tfile-%d 1 || error "create files failed"
3420
3421         rm -rf $DIR/$tdir/2 || error "unlink dir failed"
3422
3423         # deactivate MDC for MDT2
3424         local TEST="$LCTL get_param -n mdc.${FSNAME}-MDT0001-mdc-[!M]*.active"
3425         set_conf_param_and_check client                                 \
3426                 "$TEST" "${FSNAME}-MDT0001.mdc.active" 0 ||
3427                 error "Unable to deactivate MDT2"
3428
3429         $LFS mkdir -i1 $DIR/$tdir/2 &&
3430                 error "mkdir $DIR/$tdir/2 succeeds after deactive MDT"
3431
3432         # cleanup
3433         umount_client $MOUNT || error "Unable to umount client"
3434         stop_mds
3435         stop_ost
3436         stop_ost 2
3437 }
3438 run_test 50i "activate deactivated MDT"
3439
3440 test_51() {
3441         local LOCAL_TIMEOUT=20
3442
3443         reformat
3444         setup_noconfig
3445         check_mount || error "check_mount failed"
3446
3447         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
3448         $SETSTRIPE -c -1 $MOUNT/$tdir ||
3449                 error "$SETSTRIPE -c -1 $MOUNT/$tdir failed"
3450         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3451         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x142"
3452         touch $MOUNT/$tdir/$tfile &
3453         local pid=$!
3454         sleep 2
3455         start_ost2 || error "Unable to start OST1"
3456         wait $pid
3457         stop_ost2 || error "Unable to stop OST1"
3458         cleanup || error "cleanup failed with $?"
3459         #writeconf to remove all ost2 traces for subsequent tests
3460         writeconf_or_reformat
3461 }
3462 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3463
3464 copy_files_xattrs()
3465 {
3466         local node=$1
3467         local dest=$2
3468         local xattrs=$3
3469         shift 3
3470
3471         do_node $node mkdir -p $dest
3472         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3473
3474         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3475                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3476         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3477
3478         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3479         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3480 }
3481
3482 diff_files_xattrs()
3483 {
3484         local node=$1
3485         local backup=$2
3486         local xattrs=$3
3487         shift 3
3488
3489         local backup2=${TMP}/backup2
3490
3491         do_node $node mkdir -p $backup2
3492         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3493
3494         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3495                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3496         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3497
3498         do_node $node "diff -rq $backup $backup2"
3499         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3500
3501         local xattrs2=${TMP}/xattrs2
3502         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3503         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3504
3505         do_node $node "diff $xattrs $xattrs2"
3506         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3507
3508         do_node $node "rm -rf $backup2 $xattrs2"
3509         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3510 }
3511
3512 test_52() {
3513         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3514                 skip "Only applicable to ldiskfs-based MDTs"
3515                 return
3516         fi
3517
3518         start_mds || error "Unable to start MDS"
3519         start_ost || error "Unable to start OST1"
3520         mount_client $MOUNT || error "Unable to mount client"
3521
3522         local nrfiles=8
3523         local ost1mnt=$(facet_mntpt ost1)
3524         local ost1node=$(facet_active_host ost1)
3525         local ost1tmp=$TMP/conf52
3526         local loop
3527
3528         mkdir $DIR/$tdir || error "Unable to create $DIR/$tdir"
3529         touch $TMP/modified_first || error "Unable to create temporary file"
3530         local mtime=$(stat -c %Y $TMP/modified_first)
3531         do_node $ost1node "mkdir -p $ost1tmp &&
3532                            touch -m -d @$mtime $ost1tmp/modified_first" ||
3533                 error "Unable to create temporary file"
3534         sleep 1
3535
3536         $SETSTRIPE -c -1 -S 1M $DIR/$tdir || error "$SETSTRIPE failed"
3537
3538         for (( i=0; i < nrfiles; i++ )); do
3539                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c ||
3540                         error "multiop failed"
3541                 echo -n .
3542         done
3543         echo
3544
3545         # backup files
3546         echo backup files to $TMP/files
3547         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
3548         copy_files_xattrs $(hostname) $TMP/files $TMP/file_xattrs $files ||
3549                 error "Unable to copy files"
3550
3551         umount_client $MOUNT || error "Unable to umount client"
3552         stop_ost || error "Unable to stop ost1"
3553
3554         echo mount ost1 as ldiskfs
3555         do_node $ost1node mkdir -p $ost1mnt || error "Unable to create $ost1mnt"
3556         if ! do_node $ost1node test -b $ost1_dev; then
3557                 loop="-o loop"
3558         fi
3559         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
3560                 $ost1mnt ||
3561                 error "Unable to mount ost1 as ldiskfs"
3562
3563         # backup objects
3564         echo backup objects to $ost1tmp/objects
3565         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
3566                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
3567         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
3568                         $objects ||
3569                 error "Unable to copy objects"
3570
3571         # move objects to lost+found
3572         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
3573         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
3574
3575         # recover objects dry-run
3576         if [ $(lustre_version_code ost1) -ge $(version_code 2.5.56) ]; then
3577                 echo "ll_recover_lost_found_objs dry_run"
3578                 do_node $ost1node \
3579                         "ll_recover_lost_found_objs -n -d $ost1mnt/O" ||
3580                         error "ll_recover_lost_found_objs failed"
3581         fi
3582
3583         # recover objects
3584         echo "ll_recover_lost_found_objs fix run"
3585         do_node $ost1node "ll_recover_lost_found_objs -d $ost1mnt/lost+found" ||
3586                  error "ll_recover_lost_found_objs failed"
3587
3588         # compare restored objects against saved ones
3589         diff_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs $objects
3590         [ $? -eq 0 ] || error "Unable to diff objects"
3591
3592         do_node $ost1node "umount $ost1mnt" ||
3593                 error "Unable to umount ost1 as ldiskfs"
3594
3595         start_ost || error "Unable to start OST1"
3596         mount_client $MOUNT || error "Unable to mount client"
3597
3598         # compare files
3599         diff_files_xattrs $(hostname) $TMP/files $TMP/file_xattrs $files ||
3600                 error "Unable to diff files"
3601
3602         rm -rf $TMP/files $TMP/file_xattrs ||
3603                 error "Unable to delete temporary files"
3604         do_node $ost1node "rm -rf $ost1tmp" ||
3605                 error "Unable to delete temporary files"
3606         cleanup || error "cleanup failed with $?"
3607 }
3608 run_test 52 "check recovering objects from lost+found"
3609
3610 # Checks threads_min/max/started for some service
3611 #
3612 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
3613 # parameter pattern prefix like 'ost.*.ost'.
3614 thread_sanity() {
3615         local modname=$1
3616         local facet=$2
3617         local parampat=$3
3618         local opts=$4
3619         local basethr=$5
3620         local tmin
3621         local tmin2
3622         local tmax
3623         local tmax2
3624         local tstarted
3625         local paramp
3626         local msg="Insane $modname thread counts"
3627         local ncpts=$(check_cpt_number $facet)
3628         local nthrs
3629         shift 4
3630
3631         check_mount || return 41
3632
3633         # We need to expand $parampat, but it may match multiple parameters, so
3634         # we'll pick the first one
3635         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
3636                 error "Couldn't expand ${parampat}.threads_min parameter name"
3637                 return 22
3638         fi
3639
3640         # Remove the .threads_min part
3641         paramp=${paramp%.threads_min}
3642
3643         # Check for sanity in defaults
3644         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3645                echo 0)
3646         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
3647                echo 0)
3648         tstarted=$(do_facet $facet "$LCTL get_param \
3649                                     -n ${paramp}.threads_started" || echo 0)
3650         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' ||
3651                 return $?
3652         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
3653                 return $?
3654         nthrs=$(expr $tmax - $tmin)
3655         if [ $nthrs -lt $ncpts ]; then
3656                 nthrs=0
3657         else
3658                 nthrs=$ncpts
3659         fi
3660
3661         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
3662                 skip_env "module parameter forced $facet thread count" &&
3663                 tmin=3 && tmax=$((3 * tmax))
3664
3665         # Check that we can change min/max
3666         do_facet $facet "$LCTL set_param \
3667                          ${paramp}.threads_min=$((tmin + nthrs))"
3668         do_facet $facet "$LCTL set_param \
3669                          ${paramp}.threads_max=$((tmax - nthrs))"
3670         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3671                 echo 0)
3672         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
3673                 echo 0)
3674         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) &&
3675                             $tmax2 == ($tmax - $nthrs)))' || return $?
3676
3677         # Check that we can set min/max to the same value
3678         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3679                echo 0)
3680         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$tmin"
3681         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3682                 echo 0)
3683         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
3684                 echo 0)
3685         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
3686
3687         # Check that we can't set max < min
3688         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$((tmin - 1))"
3689         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
3690                 echo 0)
3691         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
3692                 echo 0)
3693         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
3694
3695         # We need to ensure that we get the module options desired; to do this
3696         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
3697         LOAD_MODULES_REMOTE=true
3698         cleanup
3699         local oldvalue
3700         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
3701         setmodopts -a $modname "$newvalue" oldvalue
3702
3703         load_modules
3704         setup
3705         check_mount || return 41
3706
3707         # Restore previous setting of MODOPTS_*
3708         setmodopts $modname "$oldvalue"
3709
3710         # Check that $opts took
3711         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min")
3712         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max")
3713         tstarted=$(do_facet $facet \
3714                    "$LCTL get_param -n ${paramp}.threads_started")
3715         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
3716                 return $?
3717         cleanup
3718
3719         load_modules
3720         setup
3721 }
3722
3723 test_53a() {
3724         setup
3725         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
3726         cleanup || error "cleanup failed with rc $?"
3727 }
3728 run_test 53a "check OSS thread count params"
3729
3730 test_53b() {
3731         setup
3732         local mds=$(do_facet $SINGLEMDS "$LCTL get_param \
3733                                          -N mds.*.*.threads_max 2>/dev/null")
3734         if [ -z "$mds" ]; then
3735                 #running this on an old MDT
3736                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
3737         else
3738                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
3739         fi
3740         cleanup || error "cleanup failed with $?"
3741 }
3742 run_test 53b "check MDS thread count params"
3743
3744 test_54a() {
3745         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3746                 skip "Only applicable to ldiskfs-based MDTs"
3747                 return
3748         fi
3749
3750         do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p ||
3751                 error "llverdev failed with rc=$?"
3752         reformat_and_config
3753 }
3754 run_test 54a "test llverdev and partial verify of device"
3755
3756 test_54b() {
3757         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3758                 skip "Only applicable to ldiskfs-based MDTs"
3759                 return
3760         fi
3761
3762         setup
3763         run_llverfs $MOUNT -p || error "llverfs failed with rc=$?"
3764         cleanup || error "cleanup failed with rc=$?"
3765 }
3766 run_test 54b "test llverfs and partial verify of filesystem"
3767
3768 lov_objid_size()
3769 {
3770         local max_ost_index=$1
3771         echo -n $(((max_ost_index + 1) * 8))
3772 }
3773
3774 test_55() {
3775         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3776                 skip "Only applicable to ldiskfs-based MDTs"
3777                 return
3778         fi
3779
3780         local mdsdev=$(mdsdevname 1)
3781         local mdsvdev=$(mdsvdevname 1)
3782
3783         for i in 1023 2048
3784         do
3785                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
3786                         $mdsvdev || exit 10
3787                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
3788                         --reformat $(ostdevname 1) $(ostvdevname 1)
3789                 setup_noconfig
3790                 stopall
3791                 setup_noconfig
3792                 sync
3793
3794                 echo checking size of lov_objid for ost index $i
3795                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" | grep ^User | awk '{print $6}')
3796                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
3797                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
3798                 else
3799                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
3800                 fi
3801                 stopall
3802         done
3803
3804         reformat
3805 }
3806 run_test 55 "check lov_objid size"
3807
3808 test_56() {
3809         local server_version=$(lustre_version_code $SINGLEMDS)
3810         local mds_journal_size_orig=$MDSJOURNALSIZE
3811         local n
3812
3813         MDSJOURNALSIZE=16
3814
3815         for num in $(seq 1 $MDSCOUNT); do
3816                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3817                         --reformat $(mdsdevname $num) $(mdsvdevname $num)
3818         done
3819         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
3820                 $(ostdevname 1) $(ostvdevname 1)
3821         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \
3822                 $(ostdevname 2) $(ostvdevname 2)
3823
3824         start_mgsmds
3825         start_ost || error "Unable to start first ost (idx 10000)"
3826         start_ost2 || error "Unable to start second ost (idx 1000)"
3827         mount_client $MOUNT || error "Unable to mount client"
3828         echo ok
3829         $LFS osts
3830
3831         if [[ $server_version -ge $(version_code 2.6.54) ]] ||
3832            [[ $server_version -ge $(version_code 2.5.4) &&
3833               $server_version -lt $(version_code 2.5.11) ]]; then
3834                 wait_osc_import_state mds ost1 FULL
3835                 wait_osc_import_state mds ost2 FULL
3836                 $SETSTRIPE --stripe-count=-1 $DIR/$tfile ||
3837                         error "Unable to setstripe $DIR/$tfile"
3838                 n=$($LFS getstripe --stripe-count $DIR/$tfile)
3839                 [ "$n" -eq 2 ] || error "Stripe count not two: $n"
3840                 rm $DIR/$tfile
3841         fi
3842
3843         stopall
3844         MDSJOURNALSIZE=$mds_journal_size_orig
3845         reformat
3846 }
3847 run_test 56 "check big OST indexes and out-of-index-order start"
3848
3849 test_57a() { # bug 22656
3850         do_rpc_nodes $(facet_active_host ost1) load_modules_local
3851         local NID=$(do_facet ost1 "$LCTL get_param nis" |
3852                     tail -1 | awk '{print $1}')
3853         writeconf_or_reformat
3854         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3855         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" ||
3856                 error "tunefs failed"
3857         start_mgsmds
3858         start_ost && error "OST registration from failnode should fail"
3859         reformat
3860 }
3861 run_test 57a "initial registration from failnode should fail (should return errs)"
3862
3863 test_57b() {
3864         do_rpc_nodes $(facet_active_host ost1) load_modules_local
3865         local NID=$(do_facet ost1 "$LCTL get_param nis" |
3866                     tail -1 | awk '{print $1}')
3867         writeconf_or_reformat
3868         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3869         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" ||
3870                 error "tunefs failed"
3871         start_mgsmds
3872         start_ost || error "OST registration from servicenode should not fail"
3873         reformat
3874 }
3875 run_test 57b "initial registration from servicenode should not fail"
3876
3877 count_osts() {
3878         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
3879 }
3880
3881 test_58() { # bug 22658
3882         setup_noconfig
3883         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3884         createmany -o $DIR/$tdir/$tfile-%d 100
3885         # make sure that OSTs do not cancel llog cookies before we unmount the MDS
3886 #define OBD_FAIL_OBD_LOG_CANCEL_NET      0x601
3887         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x601"
3888         unlinkmany $DIR/$tdir/$tfile-%d 100
3889         stop_mds || error "Unable to stop MDS"
3890
3891         local MNTDIR=$(facet_mntpt $SINGLEMDS)
3892         local devname=$(mdsdevname ${SINGLEMDS//mds/})
3893
3894         # remove all files from the OBJECTS dir
3895         mount_fstype $SINGLEMDS
3896
3897         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
3898
3899         unmount_fstype $SINGLEMDS
3900         # restart MDS with missing llog files
3901         start_mds || error "unable to start MDS"
3902         do_facet mds "$LCTL set_param fail_loc=0"
3903         reformat
3904 }
3905 run_test 58 "missing llog files must not prevent MDT from mounting"
3906
3907 test_59() {
3908         start_mgsmds >> /dev/null
3909         local C1=$(count_osts)
3910         if [ $C1 -eq 0 ]; then
3911                 start_ost >> /dev/null
3912                 C1=$(count_osts)
3913         fi
3914         stopall
3915         echo "original ost count: $C1 (expect > 0)"
3916         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
3917         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
3918         local C2=$(count_osts)
3919         echo "after mdt writeconf count: $C2 (expect 0)"
3920         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
3921         echo "OST start without writeconf should fail:"
3922         start_ost >> /dev/null &&
3923                 error "OST start without writeconf didn't fail"
3924         echo "OST start with writeconf should succeed:"
3925         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
3926         local C3=$(count_osts)
3927         echo "after ost writeconf count: $C3 (expect 1)"
3928         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
3929         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
3930         local C4=$(count_osts)
3931         echo "after ost2 writeconf count: $C4 (expect 2)"
3932         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
3933         stop_ost2 >> /dev/null
3934         cleanup_nocli >> /dev/null
3935         #writeconf to remove all ost2 traces for subsequent tests
3936         writeconf_or_reformat
3937 }
3938 run_test 59 "writeconf mount option"
3939
3940 test_60() { # LU-471
3941         local num
3942
3943         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3944                 skip "Only applicable to ldiskfs-based MDTs"
3945                 return
3946         fi
3947
3948         for num in $(seq $MDSCOUNT); do
3949                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
3950                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
3951                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
3952                         exit 10
3953         done
3954
3955         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
3956         [ ${PIPESTATUS[0]} -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
3957
3958         # MDT default has dirdata feature
3959         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
3960         # we disable uninit_bg feature
3961         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
3962         # we set stride extended options
3963         echo $dump | grep stride > /dev/null || error "stride is not set"
3964         reformat
3965 }
3966 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
3967
3968 test_61() { # LU-80
3969         local lxattr=false
3970
3971         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
3972                 { skip "Need MDS version at least 2.1.53"; return 0; }
3973
3974         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
3975              ! large_xattr_enabled; then
3976                 lxattr=true
3977
3978                 for num in $(seq $MDSCOUNT); do
3979                         do_facet mds${num} $TUNE2FS -O large_xattr \
3980                                 $(mdsdevname $num) ||
3981                                 error "tune2fs on mds $num failed"
3982                 done
3983         fi
3984
3985         setup_noconfig || error "setting up the filesystem failed"
3986         client_up || error "starting client failed"
3987
3988         local file=$DIR/$tfile
3989         touch $file || error "touch $file failed"
3990
3991         local large_value="$(generate_string $(max_xattr_size))"
3992         local small_value="bar"
3993
3994     local name="trusted.big"
3995     log "save large xattr $name on $file"
3996     setfattr -n $name -v $large_value $file ||
3997         error "saving $name on $file failed"
3998
3999     local new_value=$(get_xattr_value $name $file)
4000     [[ "$new_value" != "$large_value" ]] &&
4001         error "$name different after saving"
4002
4003     log "shrink value of $name on $file"
4004     setfattr -n $name -v $small_value $file ||
4005         error "shrinking value of $name on $file failed"
4006
4007     new_value=$(get_xattr_value $name $file)
4008     [[ "$new_value" != "$small_value" ]] &&
4009         error "$name different after shrinking"
4010
4011     log "grow value of $name on $file"
4012     setfattr -n $name -v $large_value $file ||
4013         error "growing value of $name on $file failed"
4014
4015     new_value=$(get_xattr_value $name $file)
4016     [[ "$new_value" != "$large_value" ]] &&
4017         error "$name different after growing"
4018
4019     log "check value of $name on $file after remounting MDS"
4020     fail $SINGLEMDS
4021     new_value=$(get_xattr_value $name $file)
4022     [[ "$new_value" != "$large_value" ]] &&
4023         error "$name different after remounting MDS"
4024
4025     log "remove large xattr $name from $file"
4026     setfattr -x $name $file || error "removing $name from $file failed"
4027
4028     rm -f $file
4029     stopall
4030         if $lxattr; then
4031                 for num in $(seq $MDSCOUNT); do
4032                         do_facet mds${num} $TUNE2FS -O ^large_xattr \
4033                                 $(mdsdevname $num) ||
4034                                 error "tune2fs on mds $num failed"
4035                 done
4036         fi
4037 }
4038 run_test 61 "large xattr"
4039
4040 test_62() {
4041         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4042                 skip "Only applicable to ldiskfs-based MDTs"
4043                 return
4044         fi
4045
4046         # MRP-118
4047         local mdsdev=$(mdsdevname 1)
4048         local ostdev=$(ostdevname 1)
4049
4050         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
4051                 { skip "Need MDS version at least 2.2.51"; return 0; }
4052
4053         echo "disable journal for mds"
4054         do_facet mds $TUNE2FS -O ^has_journal $mdsdev || error "tune2fs failed"
4055         start_mds && error "MDT start should fail"
4056         echo "disable journal for ost"
4057         do_facet ost1 $TUNE2FS -O ^has_journal $ostdev || error "tune2fs failed"
4058         start_ost && error "OST start should fail"
4059         cleanup || error "cleanup failed with rc $?"
4060         reformat_and_config
4061 }
4062 run_test 62 "start with disabled journal"
4063
4064 test_63() {
4065         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4066                 skip "Only applicable to ldiskfs-based MDTs"
4067                 return
4068         fi
4069
4070         local inode_slab=$(do_facet $SINGLEMDS \
4071                 "awk '/ldiskfs_inode_cache/ { print \\\$5 }' /proc/slabinfo")
4072         if [ -z "$inode_slab" ]; then
4073                 skip "ldiskfs module has not been loaded"
4074                 return
4075         fi
4076
4077         echo "$inode_slab ldisk inodes per page"
4078         [ "$inode_slab" -ge "3" ] ||
4079                 error "ldisk inode size is too big, $inode_slab objs per page"
4080         return
4081 }
4082 run_test 63 "Verify each page can at least hold 3 ldisk inodes"
4083
4084 test_64() {
4085         start_mds || error "unable to start MDS"
4086         start_ost || error "Unable to start OST1"
4087         start_ost2 || error "Unable to start second ost"
4088         mount_client $MOUNT || error "Unable to mount client"
4089         stop_ost2 || error "Unable to stop second ost"
4090         echo "$LFS df"
4091         $LFS df --lazy || error "lfs df failed"
4092         cleanup || error "cleanup failed with $?"
4093         #writeconf to remove all ost2 traces for subsequent tests
4094         writeconf_or_reformat
4095 }
4096 run_test 64 "check lfs df --lazy "
4097
4098 test_65() { # LU-2237
4099         # Currently, the test is only valid for ldiskfs backend
4100         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4101                 skip "non-ldiskfs backend" && return
4102
4103         local devname=$(mdsdevname ${SINGLEMDS//mds/})
4104         local brpt=$(facet_mntpt brpt)
4105         local opts=""
4106
4107         if ! do_facet $SINGLEMDS "test -b $devname"; then
4108                 opts="-o loop"
4109         fi
4110
4111         stop_mds || error "Unable to stop MDS"
4112         local obj=$(do_facet $SINGLEMDS \
4113                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
4114                     grep Inode)
4115         if [ -z "$obj" ]; then
4116                 # The MDT may be just re-formatted, mount the MDT for the
4117                 # first time to guarantee the "last_rcvd" file is there.
4118                 start_mds || error "fail to mount the MDS for the first time"
4119                 stop_mds || error "Unable to stop MDS"
4120         fi
4121
4122         # remove the "last_rcvd" file
4123         do_facet $SINGLEMDS "mkdir -p $brpt"
4124         do_facet $SINGLEMDS \
4125                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
4126         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
4127         do_facet $SINGLEMDS "umount -d $brpt"
4128
4129         # restart MDS, the "last_rcvd" file should be recreated.
4130         start_mds || error "fail to restart the MDS"
4131         stop_mds || error "Unable to stop MDS"
4132         obj=$(do_facet $SINGLEMDS \
4133               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
4134         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
4135 }
4136 run_test 65 "re-create the lost last_rcvd file when server mount"
4137
4138 test_66() {
4139         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
4140                 { skip "Need MGS version at least 2.3.59"; return 0; }
4141
4142         setup
4143         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
4144         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
4145
4146         echo "replace_nids should fail if MDS, OSTs and clients are UP"
4147         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4148                 error "replace_nids fail"
4149
4150         umount_client $MOUNT || error "unmounting client failed"
4151         echo "replace_nids should fail if MDS and OSTs are UP"
4152         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4153                 error "replace_nids fail"
4154
4155         stop_ost || error "Unable to stop OST1"
4156         echo "replace_nids should fail if MDS is UP"
4157         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4158                 error "replace_nids fail"
4159
4160         stop_mds || error "stopping mds failed"
4161
4162         if combined_mgs_mds; then
4163                 start_mdt 1 "-o nosvc" ||
4164                         error "starting mds with nosvc option failed"
4165         fi
4166
4167         echo "command should accept two parameters"
4168         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
4169                 error "command should accept two params"
4170
4171         echo "correct device name should be passed"
4172         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
4173                 error "wrong devname"
4174
4175         echo "wrong nids list should not destroy the system"
4176         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
4177                 error "wrong parse"
4178
4179         echo "replace OST nid"
4180         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
4181                 error "replace nids failed"
4182
4183         echo "command should accept two parameters"
4184         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
4185                 error "command should accept two params"
4186
4187         echo "wrong nids list should not destroy the system"
4188         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
4189                 error "wrong parse"
4190
4191         echo "replace MDS nid"
4192         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
4193                 error "replace nids failed"
4194
4195         if ! combined_mgs_mds ; then
4196                 stop_mgs
4197         else
4198                 stop_mds || error "Unable to stop MDS"
4199         fi
4200
4201         setup_noconfig
4202         check_mount || error "error after nid replace"
4203         cleanup || error "cleanup failed"
4204         reformat
4205 }
4206 run_test 66 "replace nids"
4207
4208 test_67() { #LU-2950
4209         local legacy="$TMP/legacy_lnet_config"
4210         local new="$TMP/new_routes_test"
4211         local out="$TMP/config_out_file"
4212         local verify="$TMP/conv_verify"
4213         local verify_conf="$TMP/conf_verify"
4214
4215         # Create the legacy file that will be run through the
4216         # lustre_routes_conversion script
4217         cat <<- LEGACY_LNET_CONFIG > $legacy
4218                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
4219                 tcp2 54 10.1.3.2@tcp;
4220                 tcp3 10.3.4.3@tcp:3;
4221                 tcp4 10.3.3.4@tcp;
4222         LEGACY_LNET_CONFIG
4223
4224         # Create the verification file to verify the output of
4225         # lustre_routes_conversion script against.
4226         cat <<- VERIFY_LNET_CONFIG > $verify
4227                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
4228                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
4229                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
4230                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
4231                 tcp4: { gateway: 10.3.3.4@tcp }
4232         VERIFY_LNET_CONFIG
4233
4234         # Create the verification file to verify the output of
4235         # lustre_routes_config script against
4236         cat <<- VERIFY_LNET_CONFIG > $verify_conf
4237                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
4238                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
4239                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
4240                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
4241                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
4242         VERIFY_LNET_CONFIG
4243
4244         lustre_routes_conversion $legacy $new > /dev/null
4245         if [ -f $new ]; then
4246                 # verify the conversion output
4247                 cmp -s $new $verify > /dev/null
4248                 if [ $? -eq 1 ]; then
4249                         error "routes conversion failed"
4250                 fi
4251
4252                 lustre_routes_config --dry-run --verbose $new > $out
4253                 # check that the script succeeded
4254                 cmp -s $out $verify_conf > /dev/null
4255                 if [ $? -eq 1 ]; then
4256                         error "routes config failed"
4257                 fi
4258         else
4259                 error "routes conversion test failed"
4260         fi
4261         # remove generated files
4262         rm -f $new $legacy $verify $verify_conf $out
4263 }
4264 run_test 67 "test routes conversion and configuration"
4265
4266 test_68() {
4267         local fid
4268         local seq
4269         local START
4270         local END
4271
4272         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
4273                 { skip "Need MDS version at least 2.4.53"; return 0; }
4274
4275         umount_client $MOUNT || error "umount client failed"
4276
4277         start_mdt 1 || error "MDT start failed"
4278         start_ost || error "Unable to start OST1"
4279
4280         # START-END - the sequences we'll be reserving
4281         START=$(do_facet $SINGLEMDS \
4282                 $LCTL get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4283         END=$((START + (1 << 30)))
4284         do_facet $SINGLEMDS \
4285                 $LCTL set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4286
4287         # reset the sequences MDT0000 has already assigned
4288         do_facet $SINGLEMDS \
4289                 $LCTL set_param seq.srv*MDT0000.space=clear
4290
4291         # remount to let the client allocate new sequence
4292         mount_client $MOUNT || error "mount client failed"
4293
4294         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4295         do_facet $SINGLEMDS \
4296                 $LCTL get_param seq.srv*MDT0000.space
4297         $LFS path2fid $DIR/$tfile
4298
4299         local old_ifs="$IFS"
4300         IFS='[:]'
4301         fid=($($LFS path2fid $DIR/$tfile))
4302         IFS="$old_ifs"
4303         let seq=${fid[1]}
4304
4305         if [[ $seq < $END ]]; then
4306                 error "used reserved sequence $seq?"
4307         fi
4308         cleanup || error "cleanup failed with $?"
4309 }
4310 run_test 68 "be able to reserve specific sequences in FLDB"
4311
4312 test_69() {
4313         local server_version=$(lustre_version_code $SINGLEMDS)
4314
4315         [[ $server_version -lt $(version_code 2.4.2) ]] &&
4316                 skip "Need MDS version at least 2.4.2" && return
4317
4318         [[ $server_version -ge $(version_code 2.4.50) ]] &&
4319         [[ $server_version -lt $(version_code 2.5.0) ]] &&
4320                 skip "Need MDS version at least 2.5.0" && return
4321
4322         setup
4323
4324         # use OST0000 since it probably has the most creations
4325         local OSTNAME=$(ostname_from_index 0)
4326         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4327
4328         # Want to have OST LAST_ID over 1.5 * OST_MAX_PRECREATE to
4329         # verify that the LAST_ID recovery is working properly.  If
4330         # not, then the OST will refuse to allow the MDS connect
4331         # because the LAST_ID value is too different from the MDS
4332         #define OST_MAX_PRECREATE=20000
4333         local num_create=$((20000 * 3))
4334
4335         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4336         $SETSTRIPE -i 0 $DIR/$tdir || error "$SETSTRIPE -i 0 $DIR/$tdir failed"
4337         createmany -o $DIR/$tdir/$tfile- $num_create ||
4338                 error "createmany: failed to create $num_create files: $?"
4339         # delete all of the files with objects on OST0 so the
4340         # filesystem is not inconsistent later on
4341         $LFS find $MOUNT --ost 0 | xargs rm
4342
4343         umount_client $MOUNT || error "umount client failed"
4344         stop_ost || error "OST0 stop failure"
4345         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
4346                 $(ostdevname 1) $(ostvdevname 1) ||
4347                 error "reformat and replace $ostdev failed"
4348         start_ost || error "OST0 restart failure"
4349         wait_osc_import_state mds ost FULL
4350
4351         mount_client $MOUNT || error "mount client failed"
4352         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
4353         local idx=$($GETSTRIPE -i $DIR/$tdir/$tfile-last)
4354         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
4355
4356         cleanup || error "cleanup failed with $?"
4357 }
4358 run_test 69 "replace an OST with the same index"
4359
4360 test_70a() {
4361         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4362         local MDTIDX=1
4363
4364         cleanup || error "cleanup failed with $?"
4365
4366         start_mdt 1 || error "MDT0 start fail"
4367
4368         start_ost || error "OST0 start fail"
4369         for num in $(seq 2 $MDSCOUNT); do
4370                 start_mdt $num || return
4371         done
4372
4373         mount_client $MOUNT || error "mount client fails"
4374
4375         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
4376
4377         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4378                 error "create remote dir fail"
4379
4380         rm -rf $DIR/$tdir || error "delete dir fail"
4381         cleanup || error "cleanup failed with $?"
4382 }
4383 run_test 70a "start MDT0, then OST, then MDT1"
4384
4385 test_70b() {
4386         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4387         local MDTIDX=1
4388
4389         start_ost || error "OST0 start fail"
4390
4391         start_mds || error "MDS start fail"
4392
4393         mount_client $MOUNT || error "mount client fails"
4394
4395         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
4396
4397         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4398                 error "create remote dir fail"
4399
4400         rm -rf $DIR/$tdir || error "delete dir fail"
4401
4402         cleanup || error "cleanup failed with $?"
4403 }
4404 run_test 70b "start OST, MDT1, MDT0"
4405
4406 test_70c() {
4407         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4408         local MDTIDX=1
4409
4410         start_mds || error "MDS start fail"
4411         start_ost || error "OST0 start fail"
4412
4413         mount_client $MOUNT || error "mount client fails"
4414         stop_mdt 1 || error "MDT1 start fail"
4415
4416         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
4417         echo "deactivate $mdc_for_mdt1"
4418         $LCTL --device $mdc_for_mdt1 deactivate ||
4419                 error "set $mdc_for_mdt1 deactivate failed"
4420
4421         mkdir $DIR/$tdir && error "mkdir succeed"
4422
4423         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4424                 error "create remote dir succeed"
4425
4426         cleanup || error "cleanup failed with $?"
4427 }
4428 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
4429
4430 test_70d() {
4431         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4432         local MDTIDX=1
4433
4434         start_mds || error "MDS start fail"
4435         start_ost || error "OST0 start fail"
4436
4437         mount_client $MOUNT || error "mount client fails"
4438
4439         stop_mdt 2 || error "MDT1 start fail"
4440
4441         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
4442                              awk '{print $4}')
4443         echo "deactivate $mdc_for_mdt2"
4444         $LCTL --device $mdc_for_mdt2 deactivate ||
4445                 error "set $mdc_for_mdt2 deactivate failed"
4446
4447         mkdir $DIR/$tdir || error "mkdir fail"
4448         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
4449                 error "create remote dir succeed"
4450
4451         rm -rf $DIR/$tdir || error "delete dir fail"
4452
4453         cleanup || error "cleanup failed with $?"
4454 }
4455 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
4456
4457 test_71a() {
4458         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4459         if combined_mgs_mds; then
4460                 skip "needs separate MGS/MDT" && return
4461         fi
4462         local MDTIDX=1
4463
4464         start_mdt 1 || error "MDT0 start fail"
4465         start_ost || error "OST0 start fail"
4466         for num in $(seq 2 $MDSCOUNT); do
4467                 start_mdt $num || return
4468         done
4469
4470         start_ost2 || error "OST1 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 run_test 71a "start MDT0 OST0, MDT1, OST1"
4487
4488 test_71b() {
4489         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4490         if combined_mgs_mds; then
4491                 skip "needs separate MGS/MDT" && return
4492         fi
4493         local MDTIDX=1
4494
4495         for num in $(seq 2 $MDSCOUNT); do
4496                 start_mdt $num || return
4497         done
4498         start_ost || error "OST0 start fail"
4499         start_mdt 1 || error "MDT0 start fail"
4500         start_ost2 || error "OST1 start fail"
4501
4502         mount_client $MOUNT || error "mount client fails"
4503
4504         mkdir $DIR/$tdir || error "mkdir fail"
4505         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4506                 error "create remote dir succeed"
4507
4508         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4509         rm -rf $DIR/$tdir || error "delete dir fail"
4510
4511         umount_client $MOUNT || error "umount_client failed"
4512         stop_mds || error "MDT0 stop fail"
4513         stop_ost || error "OST0 stop fail"
4514         stop_ost2 || error "OST1 stop fail"
4515 }
4516 run_test 71b "start MDT1, OST0, MDT0, OST1"
4517
4518 test_71c() {
4519         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4520         if combined_mgs_mds; then
4521                 skip "needs separate MGS/MDT" && return
4522         fi
4523         local MDTIDX=1
4524
4525         start_ost || error "OST0 start fail"
4526         start_ost2 || error "OST1 start fail"
4527         for num in $(seq 2 $MDSCOUNT); do
4528                 start_mdt $num || return
4529         done
4530         start_mdt 1 || error "MDT0 start fail"
4531
4532         mount_client $MOUNT || error "mount client fails"
4533
4534         mkdir $DIR/$tdir || error "mkdir fail"
4535         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4536                 error "create remote dir succeed"
4537
4538         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4539         rm -rf $DIR/$tdir || error "delete dir fail"
4540
4541         umount_client $MOUNT || error "umount_client failed"
4542         stop_mds || error "MDS stop fail"
4543         stop_ost || error "OST0 stop fail"
4544         stop_ost2 || error "OST1 stop fail"
4545
4546 }
4547 run_test 71c "start OST0, OST1, MDT1, MDT0"
4548
4549 test_71d() {
4550         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4551         if combined_mgs_mds; then
4552                 skip "needs separate MGS/MDT" && return
4553         fi
4554         local MDTIDX=1
4555
4556         start_ost || error "OST0 start fail"
4557         for num in $(seq 2 $MDSCOUNT); do
4558                 start_mdt $num || return
4559         done
4560         start_mdt 1 || error "MDT0 start fail"
4561         start_ost2 || error "OST1 start fail"
4562
4563         mount_client $MOUNT || error "mount client fails"
4564
4565         mkdir $DIR/$tdir || error "mkdir fail"
4566         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4567                         error "create remote dir succeed"
4568
4569         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4570         rm -rf $DIR/$tdir || error "delete dir fail"
4571
4572         umount_client $MOUNT || error "umount_client failed"
4573         stop_mds || error "MDS stop fail"
4574         stop_ost || error "OST0 stop fail"
4575         stop_ost2 || error "OST1 stop fail"
4576
4577 }
4578 run_test 71d "start OST0, MDT1, MDT0, OST1"
4579
4580 test_71e() {
4581         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return
4582         if combined_mgs_mds; then
4583                 skip "needs separate MGS/MDT" && return
4584         fi
4585         local MDTIDX=1
4586
4587         start_ost || error "OST0 start fail"
4588         for num in $(seq 2 $MDSCOUNT); do
4589                 start_mdt $num || return
4590         done
4591         start_ost2 || error "OST1 start fail"
4592         start_mdt 1 || error "MDT0 start fail"
4593
4594         mount_client $MOUNT || error "mount client fails"
4595
4596         mkdir $DIR/$tdir || error "mkdir fail"
4597         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
4598                 error "create remote dir succeed"
4599
4600         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
4601         rm -rf $DIR/$tdir || error "delete dir fail"
4602
4603         umount_client $MOUNT || error "umount_client failed"
4604         stop_mds || error "MDS stop fail"
4605         stop_ost || error "OST0 stop fail"
4606         stop_ost2 || error "OST1 stop fail"
4607
4608 }
4609 run_test 71e "start OST0, MDT1, OST1, MDT0"
4610
4611 test_72() { #LU-2634
4612         local mdsdev=$(mdsdevname 1)
4613         local ostdev=$(ostdevname 1)
4614         local cmd="$E2FSCK -fnvd $mdsdev"
4615         local fn=3
4616
4617         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4618                 skip "ldiskfs only test" && return
4619
4620         #tune MDT with "-O extents"
4621
4622         for num in $(seq $MDSCOUNT); do
4623                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
4624                 --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4625                 error "add mds $num failed"
4626                 do_facet mds${num} "$TUNE2FS -O extents $(mdsdevname $num)" ||
4627                         error "$TUNE2FS failed on mds${num}"
4628         done
4629
4630         add ost1 $(mkfs_opts ost1 $ostdev) --reformat $ostdev ||
4631                 error "add $ostdev failed"
4632         start_mgsmds || error "start mds failed"
4633         start_ost || error "start ost failed"
4634         mount_client $MOUNT || error "mount client failed"
4635
4636         #create some short symlinks
4637         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4638         createmany -o $DIR/$tdir/$tfile-%d $fn
4639         echo "create $fn short symlinks"
4640         for i in $(seq -w 1 $fn); do
4641                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
4642         done
4643         ls -al $MOUNT
4644
4645         #umount
4646         umount_client $MOUNT || error "umount client failed"
4647         stop_mds || error "stop mds failed"
4648         stop_ost || error "stop ost failed"
4649
4650         #run e2fsck
4651         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
4652 }
4653 run_test 72 "test fast symlink with extents flag enabled"
4654
4655 test_73() { #LU-3006
4656         load_modules
4657         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4658         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
4659                 error "1st tunefs failed"
4660         start_mgsmds || error "start mds failed"
4661         start_ost || error "start ost failed"
4662         mount_client $MOUNT || error "mount client failed"
4663         $LCTL get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
4664                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
4665         umount_client $MOUNT || error "umount client failed"
4666         stopall
4667         reformat
4668 }
4669 run_test 73 "failnode to update from mountdata properly"
4670
4671 test_75() { # LU-2374
4672         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
4673                         skip "Need MDS version at least 2.4.1" && return
4674
4675         local index=0
4676         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
4677                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
4678         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
4679                 --reformat $(ostdevname 1) $(ostvdevname 1)"
4680
4681         #check with default parameters
4682         add mds1 $opts_mds || error "add mds1 failed for default params"
4683         add ost1 $opts_ost || error "add ost1 failed for default params"
4684
4685         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
4686         opts_mds=$(echo $opts_mds |
4687                    sed -e "s/--index=$index/--index=$index --mdt/")
4688         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
4689         opts_ost=$(echo $opts_ost |
4690                    sed -e "s/--index=$index/--index=$index --ost/")
4691
4692         add mds1 $opts_mds || error "add mds1 failed for new params"
4693         add ost1 $opts_ost || error "add ost1 failed for new params"
4694         return 0
4695 }
4696 run_test 75 "The order of --index should be irrelevant"
4697
4698 test_76a() {
4699         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
4700                 { skip "Need MDS version at least 2.4.52" && return 0; }
4701         setup
4702         local MDMB_PARAM="osc.*.max_dirty_mb"
4703         echo "Change MGS params"
4704         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
4705                 head -1)
4706         echo "max_dirty_mb: $MAX_DIRTY_MB"
4707         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB + MAX_DIRTY_MB))
4708         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
4709         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
4710         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
4711                 head -1" $NEW_MAX_DIRTY_MB
4712         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4713         echo "$MAX_DIRTY_MB"
4714         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4715                 error "error while apply max_dirty_mb"
4716
4717         echo "Check the value is stored after remount"
4718         stopall
4719         setupall
4720         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
4721                 head -1" $NEW_MAX_DIRTY_MB
4722         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
4723         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
4724                 error "max_dirty_mb is not saved after remount"
4725
4726         echo "Change OST params"
4727         CLIENT_PARAM="obdfilter.*.client_cache_count"
4728         local CLIENT_CACHE_COUNT
4729         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4730                 head -1)
4731         echo "client_cache_count: $CLIENT_CACHE_COUNT"
4732         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
4733         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
4734         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
4735         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
4736                 head -1" $NEW_CLIENT_CACHE_COUNT
4737         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4738                 head -1)
4739         echo "$CLIENT_CACHE_COUNT"
4740         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4741                 error "error while apply client_cache_count"
4742
4743         echo "Check the value is stored after remount"
4744         stopall
4745         setupall
4746         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
4747                 head -1" $NEW_CLIENT_CACHE_COUNT
4748         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
4749                 head -1)
4750         echo "$CLIENT_CACHE_COUNT"
4751         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
4752                 error "client_cache_count is not saved after remount"
4753         stopall
4754 }
4755 run_test 76a "set permanent params set_param -P"
4756
4757 test_76b() { # LU-4783
4758         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.57) ]] ||
4759                 { skip "Need MGS version at least 2.5.57" && return 0; }
4760         stopall
4761         setupall
4762         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
4763                 error "start params log failed"
4764         stopall
4765 }
4766 run_test 76b "verify params log setup correctly"
4767
4768 test_77() { # LU-3445
4769         local server_version=$(lustre_version_code $SINGLEMDS)
4770
4771         [[ $server_version -ge $(version_code 2.2.60) ]] &&
4772         [[ $server_version -le $(version_code 2.4.0) ]] &&
4773                 skip "Need MDS version < 2.2.60 or > 2.4.0" && return
4774
4775         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
4776                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
4777                 skip_env "mixed loopback and real device not working" && return
4778         fi
4779
4780         local fs2mdsdev=$(mdsdevname 1_2)
4781         local fs2ostdev=$(ostdevname 1_2)
4782         local fs2mdsvdev=$(mdsvdevname 1_2)
4783         local fs2ostvdev=$(ostvdevname 1_2)
4784         local fsname=test1234
4785         local mgsnid
4786         local failnid="$(h2$NETTYPE 1.2.3.4),$(h2$NETTYPE 4.3.2.1)"
4787
4788         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
4789                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
4790         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
4791                 error "start fs2mds failed"
4792
4793         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
4794         [[ $mgsnid = *,* ]] || mgsnid+=",$mgsnid"
4795
4796         add fs2ost $(mkfs_opts ost1 $fs2ostdev) --mgsnode=$mgsnid \
4797                 --failnode=$failnid --fsname=$fsname \
4798                 --reformat $fs2ostdev $fs2ostvdev ||
4799                         error "add fs2ost failed"
4800         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
4801
4802         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
4803         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
4804         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
4805         cleanup_fs2
4806 }
4807 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
4808
4809 test_78() {
4810         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ||
4811            $(facet_fstype ost1) != ldiskfs ]] &&
4812                 skip "only applicable to ldiskfs-based MDTs and OSTs" && return
4813
4814         # reformat the Lustre filesystem with a smaller size
4815         local saved_MDSSIZE=$MDSSIZE
4816         local saved_OSTSIZE=$OSTSIZE
4817         MDSSIZE=$((MDSSIZE - 20000))
4818         OSTSIZE=$((OSTSIZE - 20000))
4819         reformat || error "(1) reformat Lustre filesystem failed"
4820         MDSSIZE=$saved_MDSSIZE
4821         OSTSIZE=$saved_OSTSIZE
4822
4823         # mount the Lustre filesystem
4824         setup_noconfig || error "(2) setup Lustre filesystem failed"
4825
4826         # create some files
4827         log "create test files"
4828         local i
4829         local file
4830         local num_files=100
4831         mkdir $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
4832         for i in $(seq $num_files); do
4833                 file=$MOUNT/$tdir/$tfile-$i
4834                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4835                         error "(4) create $file failed"
4836         done
4837
4838         # unmount the Lustre filesystem
4839         cleanup || error "(5) cleanup Lustre filesystem failed"
4840
4841         # run e2fsck on the MDT and OST devices
4842         local mds_host=$(facet_active_host $SINGLEMDS)
4843         local ost_host=$(facet_active_host ost1)
4844         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
4845         local ost_dev=$(ostdevname 1)
4846
4847         run_e2fsck $mds_host $mds_dev "-y"
4848         run_e2fsck $ost_host $ost_dev "-y"
4849
4850         # get the original block count of the MDT and OST filesystems
4851         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
4852         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
4853
4854         # expand the MDT and OST filesystems to the device size
4855         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
4856         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
4857
4858         # run e2fsck on the MDT and OST devices again
4859         run_e2fsck $mds_host $mds_dev "-y"
4860         run_e2fsck $ost_host $ost_dev "-y"
4861
4862         # mount the Lustre filesystem
4863         setup
4864
4865         # check the files
4866         log "check files after expanding the MDT and OST filesystems"
4867         for i in $(seq $num_files); do
4868                 file=$MOUNT/$tdir/$tfile-$i
4869                 $CHECKSTAT -t file -s 1048576 $file ||
4870                         error "(6) checkstat $file failed"
4871         done
4872
4873         # create more files
4874         log "create more files after expanding the MDT and OST filesystems"
4875         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
4876                 file=$MOUNT/$tdir/$tfile-$i
4877                 dd if=/dev/urandom of=$file count=1 bs=1M ||
4878                         error "(7) create $file failed"
4879         done
4880
4881         # unmount the Lustre filesystem
4882         cleanup || error "(8) cleanup Lustre filesystem failed"
4883
4884         # run e2fsck on the MDT and OST devices
4885         run_e2fsck $mds_host $mds_dev "-y"
4886         run_e2fsck $ost_host $ost_dev "-y"
4887
4888         # get the maximum block count of the MDT and OST filesystems
4889         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
4890         local ost_max_blks=$(get_block_count ost1 $ost_dev)
4891
4892         # get the minimum block count of the MDT and OST filesystems
4893         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
4894                                 grep minimum | sed -e 's/^.*filesystem: //g')
4895         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
4896                                 grep minimum | sed -e 's/^.*filesystem: //g')
4897
4898         # shrink the MDT and OST filesystems to a smaller size
4899         local shrunk=false
4900         local new_blks
4901         local base_blks
4902         if [[ $mds_max_blks -gt $mds_min_blks &&
4903               $mds_max_blks -gt $mds_orig_blks ]]; then
4904                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
4905                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
4906                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
4907                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
4908                         error "shrink $SINGLEMDS to $new_blks failed"
4909                 shrunk=true
4910         fi
4911
4912         if [[ $ost_max_blks -gt $ost_min_blks &&
4913               $ost_max_blks -gt $ost_orig_blks ]]; then
4914                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
4915                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
4916                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
4917                 run_resize2fs ost1 $ost_dev $new_blks ||
4918                         error "shrink ost1 to $new_blks failed"
4919                 shrunk=true
4920         fi
4921
4922         # check whether the MDT or OST filesystem was shrunk or not
4923         if ! $shrunk; then
4924                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
4925                 reformat || error "(10) reformat Lustre filesystem failed"
4926                 return 0
4927         fi
4928
4929         # run e2fsck on the MDT and OST devices again
4930         run_e2fsck $mds_host $mds_dev "-y"
4931         run_e2fsck $ost_host $ost_dev "-y"
4932
4933         # mount the Lustre filesystem again
4934         setup
4935
4936         # check the files
4937         log "check files after shrinking the MDT and OST filesystems"
4938         for i in $(seq $((num_files + 10))); do
4939                 file=$MOUNT/$tdir/$tfile-$i
4940                 $CHECKSTAT -t file -s 1048576 $file ||
4941                         error "(11) checkstat $file failed"
4942         done
4943
4944         # unmount and reformat the Lustre filesystem
4945         cleanup || error "(12) cleanup Lustre filesystem failed"
4946         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
4947         reformat || error "(14) reformat Lustre filesystem failed"
4948 }
4949 run_test 78 "run resize2fs on MDT and OST filesystems"
4950
4951 test_79() { # LU-4227
4952         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.59) ]] ||
4953                 { skip "Need MDS version at least 2.5.59"; return 0; }
4954
4955         local mdsdev1=$(mdsdevname 1)
4956         local mdsvdev1=$(mdsvdevname 1)
4957         local mdsdev2=$(mdsdevname 2)
4958         local mdsvdev2=$(mdsvdevname 2)
4959         local ostdev1=$(ostdevname 1)
4960         local ostvdev1=$(ostvdevname 1)
4961         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
4962         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
4963         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
4964         local mgsnode_opt
4965
4966         # remove --mgs/--mgsnode from mkfs.lustre options
4967         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
4968
4969         mgsnode_opt=$(echo $opts_mds2 |
4970                 awk '{ for ( i = 1; i < NF; i++ )
4971                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4972         [ -n $mgsnode_opt ] &&
4973                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
4974
4975         mgsnode_opt=$(echo $opts_ost1 |
4976                 awk '{ for ( i = 1; i < NF; i++ )
4977                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
4978         [ -n $mgsnode_opt ] &&
4979                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
4980
4981         # -MGS, format a mdt without --mgs option
4982         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
4983                 error "Must specify --mgs when formatting mdt combined with mgs"
4984
4985         # +MGS, format a mdt/ost without --mgsnode option
4986         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
4987                 > /dev/null || error "start mds1 failed"
4988         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
4989                 error "Must specify --mgsnode when formatting a mdt"
4990         add ost1 $opts_ost1 $ostdev1 $ostvdev2 &&
4991                 error "Must specify --mgsnode when formatting an ost"
4992
4993         reformat
4994 }
4995 run_test 79 "format MDT/OST without mgs option (should return errors)"
4996
4997 test_80() {
4998         start_mds || error "Failed to start MDT"
4999         start_ost || error "Failed to start OST1"
5000         uuid=$(do_facet ost1 $LCTL get_param -n mgc.*.uuid)
5001 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
5002         do_facet ost1 "$LCTL set_param fail_val=10 fail_loc=0x906"
5003         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x906"
5004         do_facet mgs "$LCTL set_param -n mgs/MGS/evict_client $uuid"
5005         sleep 30
5006         start_ost2 || error "Failed to start OST2"
5007
5008         do_facet ost1 "$LCTL set_param fail_loc=0"
5009         stopall
5010 }
5011 run_test 80 "mgc import reconnect race"
5012
5013 #Save the original values of $OSTCOUNT and $OSTINDEX$i.
5014 save_ostindex() {
5015         local new_ostcount=$1
5016         saved_ostcount=$OSTCOUNT
5017         OSTCOUNT=$new_ostcount
5018
5019         local i
5020         local index
5021         for i in $(seq $OSTCOUNT); do
5022                 index=OSTINDEX$i
5023                 eval saved_ostindex$i=${!index}
5024                 eval OSTINDEX$i=""
5025         done
5026 }
5027
5028 # Restore the original values of $OSTCOUNT and $OSTINDEX$i.
5029 restore_ostindex() {
5030         trap 0
5031
5032         local i
5033         local index
5034         for i in $(seq $OSTCOUNT); do
5035                 index=saved_ostindex$i
5036                 eval OSTINDEX$i=${!index}
5037         done
5038         OSTCOUNT=$saved_ostcount
5039
5040         formatall
5041 }
5042
5043 # The main purpose of this test is to ensure the OST_INDEX_LIST functions as
5044 # expected. This test uses OST_INDEX_LIST to format OSTs with a randomly
5045 # assigned index and ensures we can mount such a formatted file system
5046 test_81() { # LU-4665
5047         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5048                 { skip "Need MDS version at least 2.6.54" && return; }
5049         [[ $OSTCOUNT -ge 3 ]] || { skip_env "Need at least 3 OSTs" && return; }
5050
5051         stopall
5052
5053         # Each time RANDOM is referenced, a random integer between 0 and 32767
5054         # is generated.
5055         local i
5056         local saved_ostindex1=$OSTINDEX1
5057         for i in 65535 $((RANDOM + 65536)); do
5058                 echo -e "\nFormat ost1 with --index=$i, should fail"
5059                 OSTINDEX1=$i
5060                 if add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat \
5061                    $(ostdevname 1) $(ostvdevname 1); then
5062                         OSTINDEX1=$saved_ostindex1
5063                         error "format ost1 with --index=$i should fail"
5064                 fi
5065         done
5066         OSTINDEX1=$saved_ostindex1
5067
5068         save_ostindex 3
5069
5070         # Format OSTs with random sparse indices.
5071         trap "restore_ostindex" EXIT
5072         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices"
5073         OST_INDEX_LIST=[0,$((RANDOM * 2 % 65533 + 1)),65534] formatall
5074
5075         # Setup and check Lustre filesystem.
5076         start_mgsmds || error "start_mgsmds failed"
5077         for i in $(seq $OSTCOUNT); do
5078                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5079                         error "start ost$i failed"
5080         done
5081
5082         mount_client $MOUNT || error "mount client $MOUNT failed"
5083         check_mount || error "check client $MOUNT failed"
5084
5085         # Check max_easize.
5086         local max_easize=$($LCTL get_param -n llite.*.max_easize)
5087         [[ $max_easize -eq 128 ]] ||
5088                 error "max_easize is $max_easize, should be 128 bytes"
5089
5090         restore_ostindex
5091 }
5092 run_test 81 "sparse OST indexing"
5093
5094 # Wait OSTs to be active on both client and MDT side.
5095 wait_osts_up() {
5096         local cmd="$LCTL get_param -n lov.$FSNAME-clilov-*.target_obd |
5097                 awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
5098         wait_update $HOSTNAME "eval $cmd" $OSTCOUNT ||
5099                 error "wait_update OSTs up on client failed"
5100
5101         cmd="$LCTL get_param -n lod.$FSNAME-MDT*-*.target_obd | sort -u |
5102              awk 'BEGIN {c = 0} /ACTIVE/{c += 1} END {printf \\\"%d\\\", c}'"
5103         wait_update_facet $SINGLEMDS "eval $cmd" $OSTCOUNT ||
5104                 error "wait_update OSTs up on MDT failed"
5105 }
5106
5107 # Here we exercise the stripe placement functionality on a file system that
5108 # has formatted the OST with a random index. With the file system the following
5109 # functionality is tested:
5110 #
5111 # 1. Creating a new file with a specific stripe layout.
5112 #
5113 # 2. Modifiy a existing empty file with a specific stripe layout.
5114 #
5115 # 3. Ensure we fail to set the stripe layout of a file that already has one.
5116 #
5117 # 4. If ost-index is defined we need to ensure it is the first entry in the
5118 #    ost index list returned by lfs getstripe.
5119 #
5120 # 5. Lastly ensure this functionality fails with directories.
5121 test_82a() { # LU-4665
5122         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5123                 { skip "Need MDS version at least 2.6.54" && return; }
5124         [[ $OSTCOUNT -ge 3 ]] || { skip_env "Need at least 3 OSTs" && return; }
5125
5126         stopall
5127
5128         save_ostindex 3
5129
5130         # Format OSTs with random sparse indices.
5131         local i
5132         local index
5133         local ost_indices
5134         for i in $(seq $OSTCOUNT); do
5135                 index=$((RANDOM * 2))
5136                 ost_indices+=" $index"
5137         done
5138         ost_indices=$(comma_list $ost_indices)
5139
5140         trap "restore_ostindex" EXIT
5141         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5142         OST_INDEX_LIST=[$ost_indices] formatall
5143
5144         # Setup Lustre filesystem.
5145         start_mgsmds || error "start_mgsmds failed"
5146         for i in $(seq $OSTCOUNT); do
5147                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5148                         error "start ost$i failed"
5149         done
5150
5151         mount_client $MOUNT || error "mount client $MOUNT failed"
5152         wait_osts_up
5153
5154         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5155         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5156
5157         # 1. If the file does not exist, new file will be created
5158         #    with specified OSTs.
5159         local file=$DIR/$tdir/$tfile-1
5160         local cmd="$SETSTRIPE -o $ost_indices $file"
5161         echo -e "\n$cmd"
5162         eval $cmd || error "$cmd failed"
5163         check_stripe_count $file $OSTCOUNT
5164         check_obdidx $file $ost_indices
5165         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5166                 error "write $file failed"
5167
5168         # 2. If the file already exists and is an empty file, the file
5169         #    will be attached with specified layout.
5170         file=$DIR/$tdir/$tfile-2
5171         mcreate $file || error "mcreate $file failed"
5172         cmd="$SETSTRIPE -o $ost_indices $file"
5173         echo -e "\n$cmd"
5174         eval $cmd || error "$cmd failed"
5175         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5176                 error "write $file failed"
5177         check_stripe_count $file $OSTCOUNT
5178         check_obdidx $file $ost_indices
5179
5180         # 3. If the file already has a valid layout attached, the command
5181         #    should fail with EBUSY.
5182         echo -e "\n$cmd"
5183         eval $cmd && error "stripe is already set on $file, $cmd should fail"
5184
5185         # 4. If [--stripe-index|-i <start_ost_idx>] is used, the index must
5186         #    be in the OST indices list.
5187         local start_ost_idx=${ost_indices##*,}
5188         file=$DIR/$tdir/$tfile-3
5189         cmd="$SETSTRIPE -o $ost_indices -i $start_ost_idx $file"
5190         echo -e "\n$cmd"
5191         eval $cmd || error "$cmd failed"
5192         check_stripe_count $file $OSTCOUNT
5193         check_obdidx $file $ost_indices
5194         check_start_ost_idx $file $start_ost_idx
5195
5196         file=$DIR/$tdir/$tfile-4
5197         cmd="$SETSTRIPE"
5198         cmd+=" -o $(exclude_items_from_list $ost_indices $start_ost_idx)"
5199         cmd+=" -i $start_ost_idx $file"
5200         echo -e "\n$cmd"
5201         eval $cmd && error "index $start_ost_idx should be in $ost_indices"
5202
5203         # 5. Specifying OST indices for directory should fail with ENOSUPP.
5204         local dir=$DIR/$tdir/$tdir
5205         mkdir $dir || error "mkdir $dir failed"
5206         cmd="$SETSTRIPE -o $ost_indices $dir"
5207         echo -e "\n$cmd"
5208         eval $cmd && error "$cmd should fail, specifying OST indices" \
5209                            "for directory is not supported"
5210
5211         restore_ostindex
5212 }
5213 run_test 82a "specify OSTs for file (succeed) or directory (fail)"
5214
5215 cleanup_82b() {
5216         trap 0
5217
5218         # Remove OSTs from a pool and destroy the pool.
5219         destroy_pool $ost_pool || true
5220
5221         restore_ostindex
5222 }
5223
5224 # Test 82b is run to ensure that if the user supplies a pool with a specific
5225 # stripe layout that it behaves proprerly. It should fail in the case that
5226 # the supplied OST index list points to OSTs not contained in the user
5227 # supplied pool.
5228 test_82b() { # LU-4665
5229         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5230                 { skip "Need MDS version at least 2.6.54" && return; }
5231         [[ $OSTCOUNT -ge 4 ]] || { skip_env "Need at least 4 OSTs" && return; }
5232
5233         stopall
5234
5235         save_ostindex 4
5236
5237         # Format OSTs with random sparse indices.
5238         local i
5239         local index
5240         local ost_indices
5241         for i in $(seq $OSTCOUNT); do
5242                 index=$((RANDOM * 2))
5243                 ost_indices+=" $index"
5244         done
5245         ost_indices=$(comma_list $ost_indices)
5246
5247         trap "restore_ostindex" EXIT
5248         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5249         OST_INDEX_LIST=[$ost_indices] formatall
5250
5251         # Setup Lustre filesystem.
5252         start_mgsmds || error "start_mgsmds failed"
5253         for i in $(seq $OSTCOUNT); do
5254                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5255                         error "start ost$i failed"
5256         done
5257
5258         mount_client $MOUNT || error "mount client $MOUNT failed"
5259         wait_osts_up
5260         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5261         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5262
5263         # Create a new pool and add OSTs into it.
5264         local ost_pool=$FSNAME.$TESTNAME
5265         create_pool $ost_pool || error "create OST pool $ost_pool failed"
5266
5267         trap - EXIT
5268         trap "cleanup_82b" EXIT
5269
5270         local ost_idx_in_list=${ost_indices##*,}
5271         local ost_idx_in_pool=$(exclude_items_from_list $ost_indices \
5272                                 $ost_idx_in_list)
5273
5274         local ost_targets="$FSNAME-OST["
5275         for i in ${ost_idx_in_pool//,/ }; do
5276                 ost_targets=$ost_targets$(printf "%04x," $i)
5277         done
5278         ost_targets="${ost_targets%,}]"
5279
5280         local ost_targets_uuid=$(for i in ${ost_idx_in_pool//,/ }; \
5281                                  do printf "$FSNAME-OST%04x_UUID\n" $i; done |
5282                                  sort -u | tr '\n' ' ')
5283
5284         local cmd="$LCTL pool_add $ost_pool $ost_targets"
5285         do_facet mgs $cmd || error "$cmd failed"
5286         wait_update $HOSTNAME "$LCTL get_param -n lov.$FSNAME-*.pools.$TESTNAME|
5287                                sort -u | tr '\n' ' ' " "$ost_targets_uuid" ||
5288                                         error "wait_update $ost_pool failed"
5289         pool_list $ost_pool || error "list OST pool $ost_pool failed"
5290
5291         # If [--pool|-p <pool_name>] is set with [--ost-list|-o <ost_indices>],
5292         # then the OSTs must be the members of the pool.
5293         local file=$DIR/$tdir/$tfile
5294         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5295         echo -e "\n$cmd"
5296         eval $cmd && error "OST with index $ost_idx_in_list should be" \
5297                            "in OST pool $ost_pool"
5298
5299         # Only select OST $ost_idx_in_list from $ost_pool for file.
5300         ost_idx_in_list=${ost_idx_in_pool#*,}
5301         cmd="$SETSTRIPE -p $ost_pool -o $ost_idx_in_list $file"
5302         echo -e "\n$cmd"
5303         eval $cmd || error "$cmd failed"
5304         cmd="$GETSTRIPE $file"
5305         echo -e "\n$cmd"
5306         eval $cmd || error "$cmd failed"
5307         check_stripe_count $file 2
5308         check_obdidx $file $ost_idx_in_list
5309         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5310                 error "write $file failed"
5311
5312         cleanup_82b
5313 }
5314 run_test 82b "specify OSTs for file with --pool and --ost-list options"
5315
5316 test_83() {
5317         [[ $(lustre_version_code ost1) -ge $(version_code 2.6.91) ]] ||
5318                 { skip "Need OST version at least 2.6.91" && return 0; }
5319         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
5320                 skip "Only applicable to ldiskfs-based MDTs"
5321                 return
5322         fi
5323
5324         local dev
5325         local ostmnt
5326         local fstype
5327         local mnt_opts
5328
5329         dev=$(ostdevname 1)
5330         ostmnt=$(facet_mntpt ost1)
5331         fstype=$(facet_fstype ost1)
5332
5333         # Mount the OST as an ldiskfs filesystem.
5334         log "mount the OST $dev as a $fstype filesystem"
5335         add ost1 $(mkfs_opts ost1 $dev) $FSTYPE_OPT \
5336                 --reformat $dev $dev > /dev/null ||
5337                 error "format ost1 error"
5338
5339         if ! test -b $dev; then
5340                 mnt_opts=$(csa_add "$OST_MOUNT_OPTS" -o loop)
5341         fi
5342         echo "mnt_opts $mnt_opts"
5343         do_facet ost1 mount -t $fstype $dev \
5344                 $ostmnt $mnt_opts
5345         # Run llverfs on the mounted ldiskfs filesystem.
5346         # It is needed to get ENOSPACE.
5347         log "run llverfs in partial mode on the OST $fstype $ostmnt"
5348         do_rpc_nodes $(facet_host ost1) run_llverfs $ostmnt -vpl \
5349                 "no" || error "run_llverfs error on $fstype"
5350
5351         # Unmount the OST.
5352         log "unmount the OST $dev"
5353         stop ost1
5354
5355         # Delete file IO_scrub. Later osd_scrub_setup will try to
5356         # create "IO_scrub" but will get ENOSPACE.
5357         writeconf_all
5358         echo "start ost1 service on `facet_active_host ost1`"
5359         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
5360
5361         local err
5362         err=$(do_facet ost1 dmesg | grep "VFS: Busy inodes after unmount of")
5363         echo "string err $err"
5364         [ -z "$err" ] || error $err
5365         reformat
5366 }
5367 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
5368 Busy inodes after unmount ..."
5369
5370 recovery_time_min() {
5371         local CONNECTION_SWITCH_MIN=5
5372         local CONNECTION_SWITCH_INC=5
5373         local CONNECTION_SWITCH_MAX
5374         local RECONNECT_DELAY_MAX
5375         local INITIAL_CONNECT_TIMEOUT
5376         local max
5377         local TO_20
5378
5379         #CONNECTION_SWITCH_MAX=min(50, max($CONNECTION_SWITCH_MIN,$TIMEOUT)
5380         (($CONNECTION_SWITCH_MIN>$TIMEOUT)) && \
5381                 max=$CONNECTION_SWITCH_MIN || max=$TIMEOUT
5382         (($max<50)) && CONNECTION_SWITCH_MAX=$max || CONNECTION_SWITCH_MAX=50
5383
5384         #INITIAL_CONNECT_TIMEOUT = max(CONNECTION_SWITCH_MIN, \
5385         #obd_timeout/20)
5386         TO_20=$(($TIMEOUT/20))
5387         (($CONNECTION_SWITCH_MIN>$TO_20)) && \
5388                 INITIAL_CONNECT_TIMEOUT=$CONNECTION_SWITCH_MIN || \
5389                 INITIAL_CONNECT_TIMEOUT=$TO_20
5390
5391         RECONNECT_DELAY_MAX=$(($CONNECTION_SWITCH_MAX+$CONNECTION_SWITCH_INC+ \
5392                                 $INITIAL_CONNECT_TIMEOUT))
5393         echo $((2*$RECONNECT_DELAY_MAX))
5394 }
5395
5396 test_84() {
5397         local facet=$SINGLEMDS
5398         local num=$(echo $facet | tr -d "mds")
5399         local dev=$(mdsdevname $num)
5400         local time_min=$(recovery_time_min)
5401         local recovery_duration
5402         local completed_clients
5403         local wrap_up=5
5404
5405         echo "start mds service on $(facet_active_host $facet)"
5406         start $facet ${dev} $MDS_MOUNT_OPTS \
5407             "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min" $@ ||
5408                 error "start MDS failed"
5409
5410         start_ost
5411         start_ost2
5412
5413         echo "recovery_time=$time_min, timeout=$TIMEOUT, wrap_up=$wrap_up"
5414
5415         mount_client $MOUNT1 || error "mount failed"
5416         mount_client $MOUNT2 || error "mount failed"
5417
5418         replay_barrier $SINGLEMDS
5419         createmany -o $DIR1/$tfile-%d 1000
5420
5421         # We need to catch the end of recovery window to extend it.
5422         # Skip 5 requests and add delay to request handling.
5423         #define OBD_FAIL_TGT_REPLAY_DELAY  0x709 | FAIL_SKIP
5424         do_facet $SINGLEMDS "lctl set_param fail_loc=0x20000709 fail_val=5"
5425
5426         facet_failover $SINGLEMDS || error "failover: $?"
5427         client_up
5428
5429         echo "recovery status"
5430         do_facet $SINGLEMDS \
5431                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status"
5432
5433         recovery_duration=$(do_facet $SINGLEMDS \
5434                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
5435                 awk '/recovery_duration/ { print $2 }')
5436         (( $recovery_duration > $time_min + $wrap_up )) &&
5437                 error "recovery_duration > recovery_time_hard + wrap up"
5438         completed_clients=$(do_facet $SINGLEMDS \
5439                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
5440                 awk '/completed_clients/ { print $2 }')
5441         [ "$completed_clients" = "1/2" ] ||
5442                 error "completed_clients != 1/2: $completed_clients"
5443
5444         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
5445         umount_client $MOUNT1
5446         umount_client $MOUNT2
5447
5448         stop_ost
5449         stop_ost2
5450         stop_mds
5451 }
5452 run_test 84 "check recovery_hard_time"
5453
5454 test_85() {
5455         [[ $(lustre_version_code ost1) -ge $(version_code 2.7.55) ]] ||
5456                 { skip "Need OST version at least 2.7.55" && return 0; }
5457 ##define OBD_FAIL_OSD_OST_EA_FID_SET 0x197
5458         do_facet ost1 "lctl set_param fail_loc=0x197"
5459         start_ost
5460         stop_ost
5461 }
5462 run_test 85 "osd_ost init: fail ea_fid_set"
5463
5464 test_86() {
5465         [ "$(facet_fstype ost1)" = "zfs" ] &&
5466                 skip "LU-6442: no such mkfs params for ZFS OSTs" && return
5467
5468         local OST_OPTS="$(mkfs_opts ost1 $(ostdevname 1)) \
5469                 --reformat $(ostdevname 1) $(ostvdevname 1)"
5470
5471         local NEWSIZE=1024
5472         local OLDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
5473                 awk '/Flex block group size: / { print $NF; exit; }')
5474
5475         local opts=OST_OPTS
5476         if [[ ${!opts} != *mkfsoptions* ]]; then
5477                 eval opts=\"${!opts} \
5478                         --mkfsoptions='\\\"-O flex_bg -G $NEWSIZE\\\"'\"
5479         else
5480                 val=${!opts//--mkfsoptions=\\\"/ \
5481                         --mkfsoptions=\\\"-O flex_bg -G $NEWSIZE }
5482                 eval opts='${val}'
5483         fi
5484
5485         echo "params: $opts"
5486
5487         add ost1 $opts || error "add ost1 failed with new params"
5488
5489         local FOUNDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
5490                 awk '/Flex block group size: / { print $NF; exit; }')
5491
5492         [[ $FOUNDSIZE == $NEWSIZE ]] ||
5493                 error "Flex block group size: $FOUNDSIZE, expected: $NEWSIZE"
5494         return 0
5495 }
5496 run_test 86 "Replacing mkfs.lustre -G option"
5497
5498 test_87() { #LU-6544
5499         [[ $(lustre_version_code $SINGLEMDS1) -ge $(version_code 2.7.56) ]] ||
5500                 { skip "Need MDS version at least 2.7.56" && return; }
5501         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ]] &&
5502                 { skip "Only applicable to ldiskfs-based MDTs" && return; }
5503         [[ $OSTCOUNT -gt 69 ]] &&
5504                 { skip "Ignore wide striping situation" && return; }
5505
5506         local mdsdev=$(mdsdevname 1)
5507         local mdsvdev=$(mdsvdevname 1)
5508         local file=$DIR/$tfile
5509         local mntpt=$(facet_mntpt $SINGLEMDS)
5510         local used_xattr_blk=0
5511         local inode_size=${1:-512}
5512         local left_size=0
5513         local xtest="trusted.test"
5514         local value
5515         local orig
5516         local i
5517
5518         #Please see LU-6544 for MDT inode size calculation
5519         if [ $OSTCOUNT -gt 26 ]; then
5520                 inode_size=2048
5521         elif [ $OSTCOUNT -gt 5 ]; then
5522                 inode_size=1024
5523         fi
5524         left_size=$(expr $inode_size - \
5525                         156 - \
5526                         32 - \
5527                         32 - $OSTCOUNT \* 24 - 16 - 3 -  \
5528                         24 - 16 - 3 - \
5529                         24 - 18 - $(expr length $tfile) - 16 - 4)
5530         if [ $left_size -le 0 ]; then
5531                 echo "No space($left_size) is expected in inode."
5532                 echo "Try 1-byte xattr instead to verify this."
5533                 left_size=1
5534         else
5535                 echo "Estimate: at most $left_size-byte space left in inode."
5536         fi
5537
5538         unload_modules
5539         reformat
5540
5541         add mds1 $(mkfs_opts mds1 ${mdsdev}) --stripe-count-hint=$OSTCOUNT \
5542                 --reformat $mdsdev $mdsvdev || error "add mds1 failed"
5543         start_mdt 1 > /dev/null || error "start mdt1 failed"
5544         for i in $(seq $OSTCOUNT); do
5545                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS > /dev/null ||
5546                         error "start ost$i failed"
5547         done
5548         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
5549         check_mount || error "check client $MOUNT failed"
5550
5551         #set xattr
5552         $SETSTRIPE -c -1 $file || error "$SETSTRIPE -c -1 $file failed"
5553         $GETSTRIPE $file || error "$GETSTRIPE $file failed"
5554         i=$($GETSTRIPE -c $file)
5555         if [ $i -ne $OSTCOUNT ]; then
5556                 left_size=$(expr $left_size + $(expr $OSTCOUNT - $i) \* 24)
5557                 echo -n "Since only $i out $OSTCOUNT OSTs are used, "
5558                 echo -n "the expected left space is changed to "
5559                 echo "$left_size bytes at most."
5560         fi
5561         value=$(generate_string $left_size)
5562         setfattr -n $xtest -v $value $file
5563         orig=$(get_xattr_value $xtest $file)
5564         [[ "$orig" != "$value" ]] && error "$xtest changed"
5565
5566         #Verify if inode has some expected space left
5567         umount $MOUNT > /dev/null || error "umount $MOUNT failed"
5568         stop_mdt 1 > /dev/null || error "stop mdt1 failed"
5569         mount_ldiskfs $SINGLEMDS || error "mount -t ldiskfs $SINGLEMDS failed"
5570
5571         do_facet $SINGLEMDS ls -sal $mntpt/ROOT/$tfile
5572         used_xattr_blk=$(do_facet $SINGLEMDS ls -s $mntpt/ROOT/$tfile |
5573                         awk '{ print $1 }')
5574         [[ $used_xattr_blk -eq 0 ]] &&
5575                 error "Please check MDS inode size calculation: \
5576                        more than $left_size-byte space left in inode."
5577         echo "Verified: at most $left_size-byte space left in inode."
5578
5579         stopall
5580 }
5581 run_test 87 "check if MDT inode can hold EAs with N stripes properly"
5582
5583 # $1 test directory
5584 # $2 (optional) value of max_mod_rpcs_in_flight to set
5585 check_max_mod_rpcs_in_flight() {
5586         local dir="$1"
5587         local mmr="$2"
5588         local idx
5589         local facet
5590         local tmp
5591         local i
5592
5593         idx=$(printf "%04x" $($LFS getdirstripe -i $dir))
5594         facet="mds$((0x$idx + 1))"
5595
5596         if [ -z "$mmr" ]; then
5597                 # get value of max_mod_rcps_in_flight
5598                 mmr=$($LCTL get_param -n \
5599                         mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight) ||
5600                         error "Unable to get max_mod_rpcs_in_flight"
5601                 echo "max_mod_rcps_in_flight is $mmr"
5602         else
5603                 # set value of max_mod_rpcs_in_flight
5604                 $LCTL set_param \
5605                     mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight=$mmr ||
5606                         error "Unable to set max_mod_rpcs_in_flight to $mmr"
5607                 echo "max_mod_rpcs_in_flight set to $mmr"
5608         fi
5609
5610         # create mmr+1 files
5611         echo "creating $((mmr + 1)) files ..."
5612         umask 0022
5613         for i in $(seq $((mmr + 1))); do
5614                 touch $dir/file-$i
5615         done
5616
5617         ### part 1 ###
5618
5619         # consumes mmr-1 modify RPC slots
5620         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
5621         # drop requests on MDT so that RPC slots are consumed
5622         # during all the request resend interval
5623         do_facet $facet "$LCTL set_param fail_loc=0x159"
5624         echo "launch $((mmr - 1)) chmod in parallel ..."
5625         for i in $(seq $((mmr - 1))); do
5626                 chmod 0600 $dir/file-$i &
5627         done
5628
5629         # send one additional modify RPC
5630         do_facet $facet "$LCTL set_param fail_loc=0"
5631         echo "launch 1 additional chmod in parallel ..."
5632         chmod 0600 $dir/file-$mmr &
5633         sleep 1
5634
5635         # check this additional modify RPC get a modify RPC slot
5636         # and succeed its operation
5637         checkstat -vp 0600 $dir/file-$mmr ||
5638                 error "Unable to send $mmr modify RPCs in parallel"
5639         wait
5640
5641         ### part 2 ###
5642
5643         # consumes mmr modify RPC slots
5644         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
5645         # drop requests on MDT so that RPC slots are consumed
5646         # during all the request resend interval
5647         do_facet $facet "$LCTL set_param fail_loc=0x159"
5648         echo "launch $mmr chmod in parallel ..."
5649         for i in $(seq $mmr); do
5650                 chmod 0666 $dir/file-$i &
5651         done
5652
5653         # send one additional modify RPC
5654         do_facet $facet "$LCTL set_param fail_loc=0"
5655         echo "launch 1 additional chmod in parallel ..."
5656         chmod 0666 $dir/file-$((mmr + 1)) &
5657         sleep 1
5658
5659         # check this additional modify RPC blocked getting a modify RPC slot
5660         checkstat -vp 0644 $dir/file-$((mmr + 1)) ||
5661                 error "Unexpectedly send $mmr modify RPCs in parallel"
5662         wait
5663 }
5664
5665 test_90a() {
5666         reformat
5667         if ! combined_mgs_mds ; then
5668                 start_mgs
5669         fi
5670         setup
5671
5672         [[ $($LCTL get_param mdc.*.import |
5673              grep "connect_flags:.*multi_mod_rpc") ]] ||
5674                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
5675
5676         # check default value
5677         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5678         check_max_mod_rpcs_in_flight $DIR/$tdir
5679
5680         cleanup
5681 }
5682 run_test 90a "check max_mod_rpcs_in_flight is enforced"
5683
5684 test_90b() {
5685         local idx
5686         local facet
5687         local tmp
5688         local mmrpc
5689
5690         setup
5691
5692         [[ $($LCTL get_param mdc.*.import |
5693              grep "connect_flags:.*multi_mod_rpc") ]] ||
5694                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
5695
5696         ### test 1.
5697         # update max_mod_rpcs_in_flight
5698         $LFS mkdir -c1 $DIR/${tdir}1 || error "mkdir $DIR/${tdir}1 failed"
5699         check_max_mod_rpcs_in_flight $DIR/${tdir}1 1
5700
5701         ### test 2.
5702         # check client is able to send multiple modify RPCs in paralell
5703         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
5704                 grep -c "multi_mod_rpcs")
5705         if [ "$tmp" -ne $MDSCOUNT ]; then
5706                 echo "Client not able to send multiple modify RPCs in parallel"
5707                 cleanup
5708                 return
5709         fi
5710
5711         # update max_mod_rpcs_in_flight
5712         $LFS mkdir -c1 $DIR/${tdir}2 || error "mkdir $DIR/${tdir}2 failed"
5713         check_max_mod_rpcs_in_flight $DIR/${tdir}2 5
5714
5715         ### test 3.
5716         $LFS mkdir -c1 $DIR/${tdir}3 || error "mkdir $DIR/${tdir}3 failed"
5717         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/${tdir}3))
5718         facet="mds$((0x$idx + 1))"
5719
5720         # save MDT max_mod_rpcs_per_client
5721         mmrpc=$(do_facet $facet \
5722                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
5723
5724         # update max_mod_rpcs_in_flight
5725         umount_client $MOUNT
5726         do_facet $facet \
5727                 "echo 16 > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
5728         mount_client $MOUNT
5729         $LCTL set_param mdc.$FSNAME-MDT$idx-mdc-*.max_rpcs_in_flight=17
5730         check_max_mod_rpcs_in_flight $DIR/${tdir}3 16
5731
5732         # restore MDT max_mod_rpcs_per_client initial value
5733         do_facet $facet \
5734                 "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
5735
5736         rm -rf $DIR/${tdir}?
5737         cleanup
5738 }
5739 run_test 90b "check max_mod_rpcs_in_flight is enforced after update"
5740
5741 test_90c() {
5742         local tmp
5743         local mrif
5744         local mmrpc
5745
5746         setup
5747
5748         [[ $($LCTL get_param mdc.*.import |
5749              grep "connect_flags:.*multi_mod_rpc") ]] ||
5750                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
5751
5752         # check client is able to send multiple modify RPCs in paralell
5753         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
5754                 grep -c "multi_mod_rpcs")
5755         if [ "$tmp" -ne $MDSCOUNT ]; then
5756                 skip "Client not able to send multiple modify RPCs in parallel"
5757                 cleanup
5758                 return
5759         fi
5760
5761         # get max_rpcs_in_flight value
5762         mrif=$($LCTL get_param -n mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
5763         echo "max_rpcs_in_flight is $mrif"
5764
5765         # get MDT max_mod_rpcs_per_client
5766         mmrpc=$(do_facet mds1 \
5767                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
5768         echo "max_mod_rpcs_per_client is $mmrpc"
5769
5770         # testcase 1
5771         # attempt to set max_mod_rpcs_in_flight to max_rpcs_in_flight value
5772         # prerequisite: set max_mod_rpcs_per_client to max_rpcs_in_flight value
5773         umount_client $MOUNT
5774         do_facet mds1 \
5775                 "echo $mrif > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
5776         mount_client $MOUNT
5777
5778         $LCTL set_param \
5779             mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif &&
5780             error "set max_mod_rpcs_in_flight to $mrif should fail"
5781
5782         umount_client $MOUNT
5783         do_facet mds1 \
5784                 "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
5785         mount_client $MOUNT
5786
5787         # testcase 2
5788         # attempt to set max_mod_rpcs_in_flight to max_mod_rpcs_per_client+1
5789         # prerequisite: set max_rpcs_in_flight to max_mod_rpcs_per_client+2
5790         $LCTL set_param \
5791             mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$((mmrpc + 2))
5792
5793         $LCTL set_param \
5794             mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$((mmrpc + 1)) &&
5795             error "set max_mod_rpcs_in_flight to $((mmrpc + 1)) should fail"
5796
5797         cleanup
5798 }
5799 run_test 90c "check max_mod_rpcs_in_flight update limits"
5800
5801 test_90d() {
5802         local idx
5803         local facet
5804         local mmr
5805         local i
5806         local pid
5807
5808         setup
5809
5810         [[ $($LCTL get_param mdc.*.import |
5811              grep "connect_flags:.*multi_mod_rpc") ]] ||
5812                 { skip "Need MDC with 'multi_mod_rpcs' feature"; return 0; }
5813
5814         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5815         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
5816         facet="mds$((0x$idx + 1))"
5817
5818         # check client version supports multislots
5819         tmp=$($LCTL get_param -N \
5820                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
5821         if [ -z "$tmp" ]; then
5822                 skip "Client does not support multiple modify RPCs in flight"
5823                 cleanup
5824                 return
5825         fi
5826
5827         # get current value of max_mod_rcps_in_flight
5828         mmr=$($LCTL get_param -n \
5829                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
5830         echo "max_mod_rcps_in_flight is $mmr"
5831
5832         # create mmr files
5833         echo "creating $mmr files ..."
5834         umask 0022
5835         for i in $(seq $mmr); do
5836                 touch $DIR/$tdir/file-$i
5837         done
5838
5839         # prepare for close RPC
5840         multiop_bg_pause $DIR/$tdir/file-close O_c
5841         pid=$!
5842
5843         # consumes mmr modify RPC slots
5844         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
5845         # drop requests on MDT so that RPC slots are consumed
5846         # during all the request resend interval
5847         do_facet $facet "$LCTL set_param fail_loc=0x159"
5848         echo "launch $mmr chmod in parallel ..."
5849         for i in $(seq $mmr); do
5850                 chmod 0600 $DIR/$tdir/file-$i &
5851         done
5852
5853         # send one additional close RPC
5854         do_facet $facet "$LCTL set_param fail_loc=0"
5855         echo "launch 1 additional close in parallel ..."
5856         kill -USR1 $pid
5857         cancel_lru_locks mdc
5858         sleep 1
5859
5860         # check this additional close RPC get a modify RPC slot
5861         # and multiop process completed
5862         [ -d /proc/$pid ] &&
5863                 error "Unable to send the additional close RPC in parallel"
5864         wait
5865         rm -rf $DIR/$tdir
5866         cleanup
5867 }
5868 run_test 90d "check one close RPC is allowed above max_mod_rpcs_in_flight"
5869
5870 if ! combined_mgs_mds ; then
5871         stop mgs
5872 fi
5873
5874 cleanup_gss
5875
5876 # restore the values of MDSSIZE and OSTSIZE
5877 MDSSIZE=$STORED_MDSSIZE
5878 OSTSIZE=$STORED_OSTSIZE
5879 reformat
5880
5881 complete $SECONDS
5882 exit_status