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