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