Whamcloud - gitweb
1971070c2fe98bdde5423e54a4697673b9a2ba92
[fs/lustre-release.git] / lustre / tests / conf-sanity.sh
1 #!/bin/bash
2
3 set -e
4
5 ONLY=${ONLY:-"$*"}
6
7 # bug number for skipped test:
8 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT"
9 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
10
11 # bug number for skipped test:
12 # a tool to create lustre filesystem images
13 ALWAYS_EXCEPT="32newtarball $ALWAYS_EXCEPT"
14 if $SHARED_KEY; then
15 # bug number for skipped tests:         LU-9795 (all below)
16         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   0       31      32a     32d     35a"
17         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   53a     53b     54b     76a     76b"
18         ALWAYS_EXCEPT="$ALWAYS_EXCEPT   76c     76d     78      103"
19 fi
20
21 SRCDIR=$(dirname $0)
22 PATH=$PWD/$SRCDIR:$SRCDIR:$SRCDIR/../utils:$PATH
23
24 PTLDEBUG=${PTLDEBUG:--1}
25 SAVE_PWD=$PWD
26 LUSTRE=${LUSTRE:-$(dirname $0)/..}
27 RLUSTRE=${RLUSTRE:-$LUSTRE}
28 export MULTIOP=${MULTIOP:-multiop}
29
30 . $LUSTRE/tests/test-framework.sh
31 init_test_env $@
32 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
33 get_lustre_env
34
35 # use small MDS + OST size to speed formatting time
36 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
37 # STORED_MDSSIZE is used in test_18
38 STORED_MDSSIZE=$MDSSIZE
39 STORED_OSTSIZE=$OSTSIZE
40 MDSSIZE=200000
41 [ $(facet_fstype $SINGLEMDS) = "zfs" ] && MDSSIZE=400000
42 OSTSIZE=200000
43 [ $(facet_fstype ost1) = "zfs" ] && OSTSIZE=400000
44
45 fs2mds_HOST=$mds_HOST
46 fs2ost_HOST=$ost_HOST
47 fs3ost_HOST=$ost_HOST
48
49 MDSDEV1_2=$fs2mds_DEV
50 OSTDEV1_2=$fs2ost_DEV
51 OSTDEV2_2=$fs3ost_DEV
52
53 if ! combined_mgs_mds; then
54         # bug number for skipped test: LU-9860 LU-9860 LU-9860
55         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  43b     53b     54b"
56         # bug number for skipped test: LU-9875 LU-9879 LU-9879 LU-9879 LU-9879
57         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  70e     80      84      87      100"
58         # bug number for skipped test: LU-8110 LU-9879 LU-9879 LU-9879
59         ALWAYS_EXCEPT="$ALWAYS_EXCEPT  102     104     105     107"
60 fi
61
62 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
63 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
64         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
65 fi
66
67 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
68 # bug number for skipped test:
69         ALWAYS_EXCEPT="$ALWAYS_EXCEPT"
70 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
71
72 [ $MDSCOUNT -ge 2 ] &&
73 # bug number for skipped test: LU-11915
74         ALWAYS_EXCEPT+="       110"
75 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
76
77 init_logging
78
79 #
80 require_dsh_mds || exit 0
81 require_dsh_ost || exit 0
82
83 #                                  8  22  40  165  (min)
84 [ "$SLOW" = "no" ] && EXCEPT_SLOW="45 69 106 111"
85
86 assert_DIR
87
88 gen_config() {
89         # The MGS must be started before the OSTs for a new fs, so start
90         # and stop to generate the startup logs.
91         start_mds
92         start_ost
93         wait_osc_import_state mds ost FULL
94         stop_ost
95         stop_mds
96 }
97
98 reformat_and_config() {
99         reformat
100         if ! combined_mgs_mds ; then
101                 start_mgs
102         fi
103         gen_config
104 }
105
106 writeconf_or_reformat() {
107         # There are at most 2 OSTs for write_conf test
108         # who knows if/where $TUNEFS is installed?
109         # Better reformat if it fails...
110         writeconf_all $MDSCOUNT 2 ||
111                 { echo "tunefs failed, reformatting instead" &&
112                   reformat_and_config && return 0; }
113         return 0
114 }
115
116 reformat() {
117         formatall
118 }
119
120 start_mgs () {
121         echo "start mgs service on $(facet_active_host mgs)"
122         start mgs $(mgsdevname) $MGS_MOUNT_OPTS $@
123 }
124
125 start_mdt() {
126         local num=$1
127         local facet=mds$num
128         local dev=$(mdsdevname $num)
129         shift 1
130
131         echo "start mds service on `facet_active_host $facet`"
132         start $facet ${dev} $MDS_MOUNT_OPTS $@ || return 94
133 }
134
135 stop_mdt() {
136         local num=$1
137         local facet=mds$num
138         local dev=$(mdsdevname $num)
139         shift 1
140
141         echo "stop mds service on `facet_active_host $facet`"
142         # These tests all use non-failover stop
143         stop $facet -f || return 97
144 }
145
146 start_mds() {
147         local num
148
149         for num in $(seq $MDSCOUNT); do
150                 start_mdt $num $@ || return 94
151         done
152 }
153
154 start_mgsmds() {
155         if ! combined_mgs_mds ; then
156                 start_mgs
157         fi
158         start_mds $@
159 }
160
161 stop_mds() {
162         local num
163         for num in $(seq $MDSCOUNT); do
164                 stop_mdt $num || return 97
165         done
166 }
167
168 stop_mgs() {
169        echo "stop mgs service on `facet_active_host mgs`"
170        # These tests all use non-failover stop
171        stop mgs -f  || return 97
172 }
173
174 start_ost() {
175         echo "start ost1 service on `facet_active_host ost1`"
176         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS $@ || return 95
177 }
178
179 stop_ost() {
180         echo "stop ost1 service on `facet_active_host ost1`"
181         # These tests all use non-failover stop
182         stop ost1 -f || return 98
183 }
184
185 start_ost2() {
186         echo "start ost2 service on `facet_active_host ost2`"
187         start ost2 $(ostdevname 2) $OST_MOUNT_OPTS $@ || return 92
188 }
189
190 stop_ost2() {
191         echo "stop ost2 service on `facet_active_host ost2`"
192         # These tests all use non-failover stop
193         stop ost2 -f || return 93
194 }
195
196 mount_client() {
197         local MOUNTPATH=$1
198         echo "mount $FSNAME on ${MOUNTPATH}....."
199         zconf_mount $(hostname) $MOUNTPATH || return 96
200 }
201
202 remount_client() {
203         local mountopt="remount,$1"
204         local MOUNTPATH=$2
205         echo "remount '$1' lustre on ${MOUNTPATH}....."
206         zconf_mount $(hostname) $MOUNTPATH "$mountopt" || return 96
207 }
208
209 umount_client() {
210         local mountpath=$1
211         shift
212         echo "umount lustre on $mountpath....."
213         zconf_umount $HOSTNAME $mountpath $@ || return 97
214 }
215
216 manual_umount_client(){
217         local rc
218         local FORCE=$1
219         echo "manual umount lustre on ${MOUNT}...."
220         do_facet client "umount ${FORCE} $MOUNT"
221         rc=$?
222         return $rc
223 }
224
225 setup() {
226         start_mds || error "MDT start failed"
227         start_ost || error "Unable to start OST1"
228         mount_client $MOUNT || error "client start failed"
229         client_up || error "client_up failed"
230 }
231
232 setup_noconfig() {
233         start_mgsmds
234         start_ost
235         mount_client $MOUNT
236 }
237
238 unload_modules_conf () {
239         if combined_mgs_mds || ! local_mode; then
240                 unload_modules || return 1
241         fi
242 }
243
244 cleanup_nocli() {
245         stop_ost || return 202
246         stop_mds || return 201
247         unload_modules_conf || return 203
248 }
249
250 cleanup() {
251         local force=""
252         [ "x$1" != "x" ] && force='-f'
253         umount_client $MOUNT $force|| return 200
254         cleanup_nocli || return $?
255 }
256
257 cleanup_fs2() {
258         trap 0
259         echo "umount $MOUNT2 ..."
260         umount $MOUNT2 || true
261         echo "stopping fs2mds ..."
262         stop fs2mds -f || true
263         echo "stopping fs2ost ..."
264         stop fs2ost -f || true
265 }
266
267 check_mount() {
268         do_facet client "cp /etc/passwd $DIR/a" || return 71
269         do_facet client "rm $DIR/a" || return 72
270         # make sure lustre is actually mounted (touch will block,
271         # but grep won't, so do it after)
272         do_facet client "grep $MOUNT' ' /proc/mounts > /dev/null" || return 73
273         echo "setup single mount lustre success"
274 }
275
276 check_mount2() {
277         do_facet client "touch $DIR/a" || return 71
278         do_facet client "rm $DIR/a" || return 72
279         do_facet client "touch $DIR2/a" || return 73
280         do_facet client "rm $DIR2/a" || return 74
281         echo "setup double mount lustre success"
282 }
283
284 generate_name() {
285         cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $1 | head -n 1
286 }
287
288 build_test_filter
289
290 if [ "$ONLY" == "setup" ]; then
291         setup
292         exit
293 fi
294
295 if [ "$ONLY" == "cleanup" ]; then
296         cleanup
297         exit
298 fi
299
300 init_gss
301
302 #create single point mountpoint
303
304 reformat_and_config
305
306 test_0() {
307         setup
308         check_mount || error "check_mount failed"
309         cleanup || error "cleanup failed with $?"
310 }
311 run_test 0 "single mount setup"
312
313 test_1() {
314         start_mds || error "MDS start failed"
315         start_ost || error "unable to start OST"
316         echo "start ost second time..."
317         start_ost && error "2nd OST start should fail"
318         mount_client $MOUNT || error "client start failed"
319         check_mount || error "check_mount failed"
320         cleanup || error "cleanup failed with $?"
321 }
322 run_test 1 "start up ost twice (should return errors)"
323
324 test_2() {
325         start_mds || error "MDT start failed"
326         echo "start mds second time.."
327         start_mds && error "2nd MDT start should fail"
328         start_ost || error "OST start failed"
329         mount_client $MOUNT || error "mount_client failed to start client"
330         check_mount || error "check_mount failed"
331         cleanup || error "cleanup failed with $?"
332 }
333 run_test 2 "start up mds twice (should return err)"
334
335 test_3() {
336         setup
337         #mount.lustre returns an error if already in mtab
338         mount_client $MOUNT && error "2nd client mount should fail"
339         check_mount || error "check_mount failed"
340         cleanup || error "cleanup failed with $?"
341 }
342 run_test 3 "mount client twice (should return err)"
343
344 test_4() {
345         setup
346         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
347         stop_ost || error "Unable to stop OST1"
348         umount_client $MOUNT -f || error “unmount $MOUNT failed”
349         cleanup_nocli
350         eno=$?
351         # ok for ost to fail shutdown
352         if [ 202 -ne $eno ] && [ 0 -ne $eno ]; then
353                 error "cleanup failed with $?"
354         fi
355 }
356 run_test 4 "force cleanup ost, then cleanup"
357
358 test_5a() {     # was test_5
359         setup
360         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
361         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
362
363         stop_mds || error "Unable to stop MDS"
364
365         # cleanup may return an error from the failed
366         # disconnects; for now I'll consider this successful
367         # if all the modules have unloaded.
368         $UMOUNT -f $MOUNT &
369         UMOUNT_PID=$!
370         sleep 6
371         echo "killing umount"
372         kill -TERM $UMOUNT_PID
373         echo "waiting for umount to finish"
374         wait $UMOUNT_PID
375         if grep " $MOUNT " /proc/mounts; then
376                 echo "test 5: /proc/mounts after failed umount"
377                 umount -f $MOUNT &
378                 UMOUNT_PID=$!
379                 sleep 2
380                 echo "killing umount"
381                 kill -TERM $UMOUNT_PID
382                 echo "waiting for umount to finish"
383                 wait $UMOUNT_PID
384                 grep " $MOUNT " /proc/mounts &&
385                         error "/proc/mounts after second umount"
386         fi
387
388         # manual_mount_client may fail due to umount succeeding above
389         manual_umount_client
390         # stop_mds is a no-op here, and should not fail
391         cleanup_nocli || error "cleanup_nocli failed with $?"
392         # df may have lingering entry
393         manual_umount_client
394         # mtab may have lingering entry
395         local WAIT=0
396         local MAX_WAIT=20
397         local sleep=1
398         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
399                 sleep $sleep
400                 grep -q $MOUNT" " /etc/mtab || break
401                 echo "Waiting /etc/mtab updated ... "
402                 WAIT=$(( WAIT + sleep))
403         done
404         [ "$WAIT" -eq "$MAX_WAIT" ] &&
405                 error "/etc/mtab is not updated in $WAIT secs"
406         echo "/etc/mtab updated in $WAIT secs"
407 }
408 run_test 5a "force cleanup mds, then cleanup"
409
410 cleanup_5b () {
411         trap 0
412         start_mgs
413 }
414
415 test_5b() {
416         grep " $MOUNT " /etc/mtab &&
417                 error false "unexpected entry in mtab before mount" && return 10
418
419         start_ost || error "OST start failed"
420         if ! combined_mgs_mds ; then
421                 trap cleanup_5b EXIT ERR
422                 start_mds || error "MDS start failed"
423                 stop mgs
424         fi
425
426         mount_client $MOUNT && error "mount_client $MOUNT should fail"
427         grep " $MOUNT " /etc/mtab &&
428                 error "$MOUNT entry in mtab after failed mount"
429         umount_client $MOUNT
430         # stop_mds is a no-op here, and should not fail
431         cleanup_nocli || error "cleanup_nocli failed with $?"
432         if ! combined_mgs_mds ; then
433                 cleanup_5b
434         fi
435 }
436 run_test 5b "Try to start a client with no MGS (should return errs)"
437
438 test_5c() {
439         grep " $MOUNT " /etc/mtab &&
440                 error false "unexpected entry in mtab before mount" && return 10
441
442         start_mds || error "MDS start failed"
443         start_ost || error "OST start failed"
444         local oldfs="${FSNAME}"
445         FSNAME="wrong.${FSNAME}"
446         mount_client $MOUNT || :
447         FSNAME=${oldfs}
448         grep " $MOUNT " /etc/mtab &&
449                 error "$MOUNT entry in mtab after failed mount"
450         umount_client $MOUNT
451         cleanup_nocli || error "cleanup_nocli failed with $?"
452 }
453 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
454
455 test_5d() {
456         grep " $MOUNT " /etc/mtab &&
457                 error "unexpected entry in mtab before mount"
458
459         start_ost || error "OST start failed"
460         start_mds || error "MDS start failed"
461         stop_ost -f || error "Unable to stop OST1"
462         mount_client $MOUNT || error "mount_client $MOUNT failed"
463         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
464         cleanup_nocli || error "cleanup_nocli failed with $?"
465         ! grep " $MOUNT " /etc/mtab ||
466                 error "$MOUNT entry in mtab after unmount"
467 }
468 run_test 5d "mount with ost down"
469
470 test_5e() {
471         grep " $MOUNT " /etc/mtab &&
472                 error false "unexpected entry in mtab before mount" && return 10
473
474         start_mds || error "MDS start failed"
475         start_ost || error "OST start failed"
476
477         #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
478         do_facet client "$LCTL set_param fail_loc=0x80000506"
479         mount_client $MOUNT || echo "mount failed (not fatal)"
480         cleanup || error "cleanup failed with $?"
481         grep " $MOUNT " /etc/mtab &&
482                 error "$MOUNT entry in mtab after unmount"
483         pass
484 }
485 run_test 5e "delayed connect, don't crash (bug 10268)"
486
487 test_5f() {
488         combined_mgs_mds && skip "needs separate mgs and mds"
489
490         grep " $MOUNT " /etc/mtab &&
491                 error false "unexpected entry in mtab before mount" && return 10
492
493         local rc=0
494         start_ost || error "OST start failed"
495         mount_client $MOUNT &
496         local pid=$!
497         echo client_mount pid is $pid
498
499         sleep 5
500
501         if ! ps -f -p $pid >/dev/null; then
502                 wait $pid
503                 rc=$?
504                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
505                 error "mount returns $rc, expected to hang"
506                 rc=11
507                 cleanup || error "cleanup failed with $?"
508                 return $rc
509         fi
510
511         # start mds
512         start_mds || error "start MDS failed"
513
514         # mount should succeed after start mds
515         wait $pid
516         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
517         cleanup || error "final call to cleanup failed with rc $?"
518 }
519 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
520
521 test_5g() {
522         modprobe lustre
523         [ $(lustre_version_code client) -lt $(version_code 2.9.53) ] &&
524                 skip "automount of debugfs missing before 2.9.53"
525         umount /sys/kernel/debug
526         $LCTL get_param -n devices | egrep -v "error" && \
527                 error "lctl can't access debugfs data"
528         grep " debugfs " /etc/mtab || error "debugfs failed to remount"
529 }
530 run_test 5g "handle missing debugfs"
531
532 test_6() {
533         setup
534         manual_umount_client
535         mount_client $MOUNT || error "mount_client $MOUNT failed"
536         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
537         cleanup || error "cleanup failed with rc $?"
538 }
539 run_test 6 "manual umount, then mount again"
540
541 test_7() {
542         setup
543         manual_umount_client
544         cleanup_nocli || error "cleanup_nocli failed with $?"
545 }
546 run_test 7 "manual umount, then cleanup"
547
548 test_8() {
549         setup
550         mount_client $MOUNT2 || error "mount_client $MOUNT2 failed"
551         check_mount2 || error "check_mount2 failed"
552         umount_client $MOUNT2 || error "umount_client $MOUNT2 failed"
553         cleanup || error "cleanup failed with rc $?"
554 }
555 run_test 8 "double mount setup"
556
557 test_9() {
558         start_ost || error "OST start failed"
559
560         do_facet ost1 $LCTL set_param debug=\'inode trace\' ||
561                 error "do_facet ost1 set_param inode trace failed."
562         do_facet ost1 $LCTL set_param subsystem_debug=\'mds ost\' ||
563                 error "do_facet ost1 set_param debug mds ost failed."
564
565         CHECK_PTLDEBUG="`do_facet ost1 $LCTL get_param -n debug`"
566         if [ "$CHECK_PTLDEBUG" ] && { \
567            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
568            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
569                 echo "lnet.debug success"
570         else
571                 error "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
572         fi
573         CHECK_SUBSYS="`do_facet ost1 $LCTL get_param -n subsystem_debug`"
574         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
575                 echo "lnet.subsystem_debug success"
576         else
577                 error "lnet.subsystem_debug: want 'mds ost' got '$CHECK_SUBSYS'"
578         fi
579         stop_ost || error "Unable to stop OST1"
580 }
581 run_test 9 "test ptldebug and subsystem for mkfs"
582
583 #
584 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
585 # But with new MDS stack we don't care about the mode of local objects
586 # anymore, so this test is removed. See bug 22944 for more details.
587 #
588
589 test_17() {
590         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
591                 skip "ldiskfs only test"
592         fi
593
594         setup
595         check_mount || error "check_mount failed"
596         cleanup || error "cleanup failed with rc $?"
597
598         echo "Remove mds config log"
599         if ! combined_mgs_mds ; then
600                 stop mgs
601         fi
602
603         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
604                       $(mgsdevname) || return \$?" ||
605                 error "do_facet mgs failed with $?"
606
607         if ! combined_mgs_mds ; then
608                 start_mgs
609         fi
610
611         start_ost || error "OST start failed"
612         start_mds && error "MDS start succeeded, but should fail"
613         reformat_and_config
614 }
615 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
616
617 test_18() {
618         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
619                 skip "ldiskfs only test"
620         fi
621
622         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
623
624         local MIN=2000000
625
626         local OK=
627         # check if current MDSSIZE is large enough
628         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE &&
629                 log "use MDSSIZE=$MDSSIZE"
630
631         # check if the global config has a large enough MDSSIZE
632         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] &&
633                 [ $STORED_MDSSIZE -ge $MIN ] &&
634                 OK=1 && myMDSSIZE=$STORED_MDSSIZE &&
635                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
636
637         # check if the block device is large enough
638         is_blkdev $SINGLEMDS $MDSDEV $MIN
639         local large_enough=$?
640         if [ -n "$OK" ]; then
641                 [ $large_enough -ne 0 ] && OK=""
642         else
643                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
644                         log "use device $MDSDEV with MIN=$MIN"
645         fi
646
647         # check if a loopback device has enough space for fs metadata (5%)
648
649         if [ -z "$OK" ]; then
650                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! \
651                               -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
652                         awk '($1 != "Filesystem") { print $4 }')
653                 ! [ -z "$SPACE" ] && [ $SPACE -gt $((MIN / 20)) ] &&
654                         OK=1 && myMDSSIZE=$MIN &&
655                         log "use file $MDSDEV with MIN=$MIN"
656         fi
657
658         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS"
659
660         echo "mount mds with large journal..."
661
662         local OLD_MDSSIZE=$MDSSIZE
663         MDSSIZE=$myMDSSIZE
664
665         reformat_and_config
666         echo "mount lustre system..."
667         setup
668         check_mount || error "check_mount failed"
669
670         echo "check journal size..."
671         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
672         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
673                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
674         else
675                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
676         fi
677
678         cleanup || error "cleanup failed with rc $?"
679
680         MDSSIZE=$OLD_MDSSIZE
681         reformat_and_config
682 }
683 run_test 18 "check mkfs creates large journals"
684
685 test_19a() {
686         start_mds || error "MDS start failed"
687         stop_mds || error "Unable to stop MDS"
688 }
689 run_test 19a "start/stop MDS without OSTs"
690
691 test_19b() {
692         start_ost || error "Unable to start OST1"
693         stop_ost -f || error "Unable to stop OST1"
694 }
695 run_test 19b "start/stop OSTs without MDS"
696
697 test_20() {
698         # first format the ost/mdt
699         start_mds || error "MDS start failed"
700         start_ost || error "Unable to start OST1"
701         mount_client $MOUNT || error "mount_client $MOUNT failed"
702         check_mount || error "check_mount failed"
703         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed."
704         remount_client ro $MOUNT || error "remount_client with ro failed"
705         touch $DIR/$tfile && error "$DIR/$tfile created incorrectly"
706         [ -e $DIR/$tfile ] && error "$DIR/$tfile exists incorrectly"
707         remount_client rw $MOUNT || error "remount_client with rw failed"
708         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
709         MCNT=$(grep -c $MOUNT' ' /etc/mtab)
710         [ "$MCNT" -ne 1 ] && error "$MOUNT in /etc/mtab $MCNT times"
711         umount_client $MOUNT
712         stop_mds || error "Unable to stop MDS"
713         stop_ost || error "Unable to stop OST1"
714 }
715 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
716
717 test_21a() {
718         start_mds || error "MDS start failed"
719         start_ost || error "unable to start OST1"
720         wait_osc_import_state mds ost FULL
721         stop_ost || error "unable to stop OST1"
722         stop_mds || error "unable to stop MDS"
723 }
724 run_test 21a "start mds before ost, stop ost first"
725
726 test_21b() {
727         start_ost || error "unable to start OST1"
728         start_mds || error "MDS start failed"
729         wait_osc_import_state mds ost FULL
730         stop_mds || error "unable to stop MDS"
731         stop_ost || error "unable to stop OST1"
732 }
733 run_test 21b "start ost before mds, stop mds first"
734
735 test_21c() {
736         start_ost || error "Unable to start OST1"
737         start_mds || error "MDS start failed"
738         start_ost2 || error "Unable to start OST2"
739         wait_osc_import_state mds ost2 FULL
740         stop_ost || error "Unable to stop OST1"
741         stop_ost2 || error "Unable to stop OST2"
742         stop_mds || error "Unable to stop MDS"
743         #writeconf to remove all ost2 traces for subsequent tests
744         writeconf_or_reformat
745 }
746 run_test 21c "start mds between two osts, stop mds last"
747
748 test_21d() {
749         combined_mgs_mds && skip "need separate mgs device"
750
751         stopall
752         reformat
753
754         start_mgs || error "unable to start MGS"
755         start_ost || error "unable to start OST1"
756         start_ost2 || error "unable to start OST2"
757         start_mds || error "MDS start failed"
758         wait_osc_import_state mds ost2 FULL
759
760         stop_ost || error "Unable to stop OST1"
761         stop_ost2 || error "Unable to stop OST2"
762         stop_mds || error "Unable to stop MDS"
763         stop_mgs
764         #writeconf to remove all ost2 traces for subsequent tests
765         writeconf_or_reformat
766         start_mgs || error "unable to start MGS"
767 }
768 run_test 21d "start mgs then ost and then mds"
769
770 cleanup_21e() {
771         MGSNID="$saved_mgsnid"
772         cleanup_fs2
773         echo "stopping fs2mgs ..."
774         stop $fs2mgs -f || true
775 }
776
777 test_21e() { # LU-5863
778         if [[ -z "$fs3ost_DEV" || -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
779                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
780                 skip_env "mixed loopback and real device not working"
781         fi
782
783         local fs2mdsdev=$(mdsdevname 1_2)
784         local fs2ostdev=$(ostdevname 1_2)
785         local fs3ostdev=$(ostdevname 2_2)
786
787         local fs2mdsvdev=$(mdsvdevname 1_2)
788         local fs2ostvdev=$(ostvdevname 1_2)
789         local fs3ostvdev=$(ostvdevname 2_2)
790
791         # temporarily use fs3ost as fs2mgs
792         local fs2mgs=fs3ost
793         local fs2mgsdev=$fs3ostdev
794         local fs2mgsvdev=$fs3ostvdev
795
796         local fsname=test1234
797
798         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
799                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
800         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS && trap cleanup_21e EXIT INT ||
801                 error "start fs2mgs failed"
802
803         local saved_mgsnid="$MGSNID"
804         MGSNID=$(do_facet $fs2mgs $LCTL list_nids | xargs | tr ' ' ,)
805
806         add fs2mds $(mkfs_opts mds1 $fs2mdsdev $fsname) \
807                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
808         add fs2ost $(mkfs_opts ost1 $fs2ostdev $fsname) \
809                 --reformat $fs2ostdev $fs2ostvdev || error "add fs2ost failed"
810
811         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
812         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS || error "start fs2mds failed"
813
814         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
815         $MOUNT_CMD $MGSNID:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
816         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
817
818         cleanup_21e
819 }
820 run_test 21e "separate MGS and MDS"
821
822 test_22() {
823         start_mds || error "MDS start failed"
824
825         echo "Client mount with ost in logs, but none running"
826         start_ost || error "unable to start OST1"
827         # wait until mds connected to ost and open client connection
828         wait_osc_import_state mds ost FULL
829         stop_ost || error "unable to stop OST1"
830         mount_client $MOUNT || error "mount_client $MOUNT failed"
831         # check_mount will block trying to contact ost
832         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
833         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed"
834         umount_client $MOUNT -f
835         pass
836
837         echo "Client mount with a running ost"
838         start_ost || error "unable to start OST1"
839         if $GSS; then
840                 # if gss enabled, wait full time to let connection from
841                 # mds to ost be established, due to the mismatch between
842                 # initial connect timeout and gss context negotiation timeout.
843                 # This perhaps could be remove after AT landed.
844                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
845                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
846         fi
847         mount_client $MOUNT || error "mount_client $MOUNT failed"
848         wait_osc_import_state mds ost FULL
849         wait_osc_import_ready client ost
850         check_mount || error "check_mount failed"
851         pass
852
853         cleanup || error "cleanup failed with rc $?"
854 }
855 run_test 22 "start a client before osts (should return errs)"
856
857 test_23a() {    # was test_23
858         setup
859         # fail mds
860         stop $SINGLEMDS || error "failed to stop $SINGLEMDS"
861         # force down client so that recovering mds waits for reconnect
862         local running=$(grep -c $MOUNT /proc/mounts) || true
863         if [ $running -ne 0 ]; then
864                 echo "Stopping client $MOUNT (opts: -f)"
865                 umount -f $MOUNT
866         fi
867
868         # enter recovery on failed mds
869         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
870         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "MDS start failed"
871         # try to start a new client
872         mount_client $MOUNT &
873         sleep 5
874         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
875         MOUNT_LUSTRE_PID=$(ps -ef | grep mount.lustre |
876                            grep -v grep | awk '{print $2}')
877         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
878         ps --ppid $MOUNT_PID
879         ps --ppid $MOUNT_LUSTRE_PID
880         echo "waiting for mount to finish"
881         ps -ef | grep mount
882         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
883         # SIGTERM works but it does not spread to offspring processses
884         kill -s TERM $MOUNT_PID
885         kill -s TERM $MOUNT_LUSTRE_PID
886         # we can not wait $MOUNT_PID because it is not a child of this shell
887         local PID1
888         local PID2
889         local WAIT=0
890         local MAX_WAIT=30
891         local sleep=1
892         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
893                 sleep $sleep
894                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
895                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
896                 echo PID1=$PID1
897                 echo PID2=$PID2
898                 [ -z "$PID1" -a -z "$PID2" ] && break
899                 echo "waiting for mount to finish ... "
900                 WAIT=$(( WAIT + sleep))
901         done
902         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
903                 error "MOUNT_PID $MOUNT_PID and "\
904                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
905                 ps -ef | grep mount
906         fi
907         cleanup || error "cleanup failed with rc $?"
908 }
909 run_test 23a "interrupt client during recovery mount delay"
910
911 test_23b() {    # was test_23
912         start_mds || error "MDS start failed"
913         start_ost || error "Unable to start OST1"
914         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
915         $LCTL set_param fail_loc=0x80000313
916         mount_client $MOUNT
917         cleanup || error "cleanup failed with rc $?"
918 }
919 run_test 23b "Simulate -EINTR during mount"
920
921 test_24a() {
922         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
923
924         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
925                 is_blkdev $SINGLEMDS $MDSDEV &&
926                 skip_env "mixed loopback and real device not working"
927         fi
928
929         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
930
931         local fs2mdsdev=$(mdsdevname 1_2)
932         local fs2ostdev=$(ostdevname 1_2)
933         local fs2mdsvdev=$(mdsvdevname 1_2)
934         local fs2ostvdev=$(ostvdevname 1_2)
935         local cl_user
936
937         # LU-9733 test fsname started with numbers as well
938         local FSNAME2=969362ae
939
940         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
941                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
942
943         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
944                 --reformat $fs2ostdev $fs2ostvdev || exit 10
945
946         setup
947         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
948         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
949         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
950         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
951
952         # LU-9733 test fsname started with numbers
953         cl_user=$(do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
954                         changelog_register -n) ||
955                                 error "register changelog failed"
956
957         do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
958                         changelog_deregister $cl_user ||
959                                 error "deregister changelog failed"
960         # 1 still works
961         check_mount || error "check_mount failed"
962         # files written on 1 should not show up on 2
963         cp /etc/passwd $DIR/$tfile
964         sleep 10
965         [ -e $MOUNT2/$tfile ] && error "File bleed"
966         # 2 should work
967         sleep 5
968         cp /etc/passwd $MOUNT2/$tfile ||
969                 error "cp /etc/passwd $MOUNT2/$tfile failed"
970         rm $MOUNT2/$tfile || error "remove $MOUNT2/$tfile failed"
971         # 2 is actually mounted
972         grep $MOUNT2' ' /proc/mounts > /dev/null || error "$MOUNT2 not mounted"
973         # failover
974         facet_failover fs2mds
975         facet_failover fs2ost
976         df
977         umount_client $MOUNT
978         # the MDS must remain up until last MDT
979         stop_mds
980         MDS=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
981               awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
982         [ -z "$MDS" ] && error "No MDT"
983         cleanup_fs2
984         cleanup_nocli || error "cleanup_nocli failed with rc $?"
985 }
986 run_test 24a "Multiple MDTs on a single node"
987
988 test_24b() {
989         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
990
991         if [ -z "$fs2mds_DEV" ]; then
992                 local dev=${SINGLEMDS}_dev
993                 local MDSDEV=${!dev}
994                 is_blkdev $SINGLEMDS $MDSDEV &&
995                 skip_env "mixed loopback and real device not working"
996         fi
997
998         local fs2mdsdev=$(mdsdevname 1_2)
999         local fs2mdsvdev=$(mdsvdevname 1_2)
1000
1001         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
1002                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
1003         setup
1004         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS &&
1005                 error "start MDS should fail"
1006         stop fs2mds -f
1007         cleanup || error "cleanup failed with rc $?"
1008 }
1009 run_test 24b "Multiple MGSs on a single node (should return err)"
1010
1011 test_25() {
1012         setup
1013         check_mount || error "check_mount failed"
1014         local MODULES=$($LCTL modules | awk '{ print $2 }')
1015         rmmod $MODULES 2>/dev/null || true
1016         cleanup || error "cleanup failed with $?"
1017 }
1018 run_test 25 "Verify modules are referenced"
1019
1020 test_26() {
1021         load_modules
1022         # we need modules before mount for sysctl, so make sure...
1023         do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
1024         #define OBD_FAIL_MDS_FS_SETUP            0x135
1025         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000135"
1026         start_mds && error "MDS started but should not have started"
1027         $LCTL get_param -n devices
1028         DEVS=$($LCTL get_param -n devices | egrep -v MG | wc -l)
1029         [ $DEVS -gt 0 ] && error "number of devices is $DEVS, should be zero"
1030         # start mds to drop writeconf setting
1031         start_mds || error "Unable to start MDS"
1032         stop_mds || error "Unable to stop MDS"
1033         unload_modules_conf || error "unload_modules_conf failed with $?"
1034 }
1035 run_test 26 "MDT startup failure cleans LOV (should return errs)"
1036
1037 test_27a() {
1038         start_ost || error "Unable to start OST1"
1039         start_mds || error "Unable to start MDS"
1040         echo "Requeue thread should have started: "
1041         ps -e | grep ll_cfg_requeue
1042         set_persistent_param_and_check ost1                     \
1043            "obdfilter.$FSNAME-OST0000.client_cache_seconds"     \
1044            "$FSNAME-OST0000.ost.client_cache_seconds"
1045         cleanup_nocli || error "cleanup_nocli failed with rc $?"
1046 }
1047 run_test 27a "Reacquire MGS lock if OST started first"
1048
1049 test_27b() {
1050         # FIXME. ~grev
1051         setup
1052         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
1053                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
1054
1055         facet_failover $SINGLEMDS
1056         set_persistent_param_and_check $SINGLEMDS       \
1057                 "mdt.$device.identity_acquire_expire"   \
1058                 "$device.mdt.identity_acquire_expire"
1059         set_persistent_param_and_check client           \
1060                 "mdc.$device-mdc-*.max_rpcs_in_flight"  \
1061                 "$device.mdc.max_rpcs_in_flight"
1062         check_mount
1063         cleanup || error "cleanup failed with $?"
1064 }
1065 run_test 27b "Reacquire MGS lock after failover"
1066
1067 test_28A() { # was test_28
1068         setup
1069         TEST="llite.$FSNAME-*.max_read_ahead_whole_mb"
1070         PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
1071         ORIG=$($LCTL get_param -n $TEST)
1072         FINAL=$(($ORIG + 1))
1073         set_persistent_param_and_check client "$TEST" "$PARAM" $FINAL
1074         FINAL=$(($FINAL + 1))
1075         set_persistent_param_and_check client "$TEST" "$PARAM" $FINAL
1076         umount_client $MOUNT || error "umount_client $MOUNT failed"
1077         mount_client $MOUNT || error "mount_client $MOUNT failed"
1078         RESULT=$($LCTL get_param -n $TEST)
1079         if [ $RESULT -ne $FINAL ]; then
1080                 error "New config not seen: wanted $FINAL got $RESULT"
1081         else
1082                 echo "New config success: got $RESULT"
1083         fi
1084         set_persistent_param_and_check client "$TEST" "$PARAM" $ORIG
1085         cleanup || error "cleanup failed with rc $?"
1086 }
1087 run_test 28A "permanent parameter setting"
1088
1089 test_28a() { # LU-4221
1090         [[ $(lustre_version_code ost1) -ge $(version_code 2.5.52) ]] ||
1091                 skip "Need OST version at least 2.5.52"
1092         [ "$(facet_fstype ost1)" = "zfs" ] &&
1093                 skip "LU-4221: no such proc params for ZFS OSTs"
1094
1095         local name
1096         local param
1097         local cmd
1098         local old
1099         local new
1100         local device="$FSNAME-OST0000"
1101
1102         setup
1103
1104         # In this test we will set three kinds of proc parameters with
1105         # lctl set_param -P or lctl conf_param:
1106         # 1. non-symlink ones in the OFD
1107         # 2. non-symlink ones in the OSD
1108
1109         # Check 1.
1110         # prepare a non-symlink parameter in the OFD
1111         name="client_cache_seconds"
1112         param="$device.ost.$name"
1113         cmd="obdfilter.$device.$name"
1114
1115         # permanently setting the parameter in the OFD
1116         old=$(do_facet ost1 $LCTL get_param -n $cmd)
1117         new=$((old * 2))
1118         set_persistent_param_and_check ost1 "$cmd" "$param" $new
1119         set_persistent_param_and_check ost1 "$cmd" "$param" $old
1120
1121         # Check 2.
1122         # prepare a non-symlink parameter in the OSD
1123         name="auto_scrub"
1124         param="$device.osd.$name"
1125         cmd="osd-*.$device.$name"
1126
1127         # conf_param the parameter in the OSD
1128         old=$(do_facet ost1 $LCTL get_param -n $cmd)
1129         new=$(((old + 1) % 2))
1130         set_persistent_param_and_check ost1 "$cmd" "$param" $new
1131         set_persistent_param_and_check ost1 "$cmd" "$param" $old
1132
1133         cleanup || error "cleanup failed with $?"
1134 }
1135 run_test 28a "set symlink parameters permanently with lctl"
1136
1137 test_29() {
1138         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
1139         setup > /dev/null 2>&1
1140         start_ost2 || error "Unable to start OST2"
1141         sleep 10
1142
1143         local PARAM="$FSNAME-OST0001.osc.active"
1144         # With lctl set_param -P the value $PROC_ACT will be sent to
1145         # all nodes. The [!M] filter out the ability to set active
1146         # on the MDS servers which is tested with wait_osp_* below.
1147         # For ost_server_uuid that only exist on client so filtering
1148         # is safe.
1149         local PROC_ACT="osc.$FSNAME-OST0001-osc-*.active"
1150         local PROC_UUID="osc.$FSNAME-OST0001-osc-[!M]*.ost_server_uuid"
1151
1152         ACTV=$($LCTL get_param -n $PROC_ACT)
1153         DEAC=$((1 - $ACTV))
1154         set_persistent_param_and_check client $PROC_ACT $PARAM $DEAC
1155         # also check ost_server_uuid status
1156         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV)
1157         if [ -z "$RESULT" ]; then
1158                 error "Client not deactivated: $($LCTL get_param \
1159                        -n $PROC_UUID)"
1160         else
1161                 echo "Live client success: got $RESULT"
1162         fi
1163
1164         # check MDTs too
1165         wait_osp_active ost ${FSNAME}-OST0001 1 0
1166
1167         # test new client starts deactivated
1168         umount_client $MOUNT || error "umount_client $MOUNT failed"
1169         mount_client $MOUNT || error "mount_client $MOUNT failed"
1170
1171         # the 2nd and 3rd field of ost_server_uuid do not update at the same
1172         # time when using lctl set_param -P
1173         wait_update_facet client                                        \
1174                 "$LCTL get_param -n $PROC_UUID | awk '{print \\\$3 }'"  \
1175                 "DEACTIVATED" ||
1176                 error "New client start active: $($LCTL get_param -n $PROC_UUID)"
1177
1178         echo "New client success: got '$($LCTL get_param -n $PROC_UUID)'"
1179
1180         # make sure it reactivates
1181         set_persistent_param_and_check client $PROC_ACT $PARAM $ACTV
1182
1183         umount_client $MOUNT
1184         stop_ost2 || error "Unable to stop OST2"
1185         cleanup_nocli || error "cleanup_nocli failed with $?"
1186         #writeconf to remove all ost2 traces for subsequent tests
1187         writeconf_or_reformat
1188 }
1189 run_test 29 "permanently remove an OST"
1190
1191 test_30a() {
1192         setup
1193
1194         echo Big config llog
1195         TEST="llite.$FSNAME-*.max_read_ahead_whole_mb"
1196         ORIG=$($LCTL get_param -n $TEST)
1197         LIST=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1198         for i in ${LIST[@]}; do
1199                 set_persistent_param_and_check client "$TEST" \
1200                         "$FSNAME.llite.max_read_ahead_whole_mb" $i
1201         done
1202         # make sure client restart still works
1203         umount_client $MOUNT
1204         mount_client $MOUNT || error "mount_client $MOUNT failed"
1205         [ "$($LCTL get_param -n $TEST)" -ne "$i" ] &&
1206                 error "Param didn't stick across restart $($TEST) != $i"
1207         pass
1208
1209         echo Erase parameter setting
1210         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1211                 do_facet mgs "$PERM_CMD -d $TEST" ||
1212                         error "Erase param $TEST failed"
1213         else
1214                 do_facet mgs "$PERM_CMD \
1215                               -d $FSNAME.llite.max_read_ahead_whole_mb" ||
1216                         error "Erase param $FSNAME.llite.max_read_ahead_whole_mb failed"
1217         fi
1218         umount_client $MOUNT
1219         mount_client $MOUNT || error "mount_client $MOUNT failed"
1220         FINAL=$($LCTL get_param -n $TEST)
1221         echo "deleted (default) value=$FINAL, orig=$ORIG"
1222         # assumes this parameter started at the default value
1223         [ "$FINAL" -eq "$ORIG" ] || fail "Deleted value=$FINAL, orig=$ORIG"
1224
1225         cleanup || error "cleanup failed with rc $?"
1226 }
1227 run_test 30a "Big config llog and permanent parameter deletion"
1228
1229 test_30b() {
1230         setup
1231
1232         local orignids=$($LCTL get_param -n \
1233                 osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1234
1235         local orignidcount=$(echo "$orignids" | wc -w)
1236
1237         # Make a fake nid.  Use the OST nid, and add 20 to the least significant
1238         # numerical part of it. Hopefully that's not already a failover address
1239         # for the server.
1240         local OSTNID=$(do_facet ost1 "$LCTL get_param nis" | tail -1 | \
1241                 awk '{print $1}')
1242         local ORIGVAL=$(echo $OSTNID | egrep -oi "[0-9]*@")
1243         local NEWVAL=$((($(echo $ORIGVAL | egrep -oi "[0-9]*") + 20) % 256))
1244         local NEW=$(echo $OSTNID | sed "s/$ORIGVAL/$NEWVAL@/")
1245         echo "Using fake nid $NEW"
1246
1247         local TEST="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1248                 grep failover_nids | sed -n 's/.*\($NEW\).*/\1/p'"
1249         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1250                 PARAM="osc.$FSNAME-OST0000-osc-[^M]*.import"
1251                 echo "Setting $PARAM from $TEST to $NEW"
1252                 do_facet mgs "$PERM_CMD $PARAM='connection=$NEW'" ||
1253                         error "$PERM_CMD $PARAM failed"
1254         else
1255                 PARAM="$FSNAME-OST0000.failover.node"
1256                 echo "Setting $PARAM from $TEST to $NEW"
1257                 do_facet mgs "$PERM_CMD $PARAM='$NEW'" ||
1258                         error "$PARAM $PARAM failed"
1259         fi
1260         wait_update_facet client "$TEST" "$NEW" ||
1261                 error "check $PARAM failed!"
1262
1263         local NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1264                 grep failover_nids)
1265         local NIDCOUNT=$(echo "$NIDS" | wc -w)
1266         echo "should have $((orignidcount + 1)) entries \
1267                 in failover nids string, have $NIDCOUNT"
1268         [ $NIDCOUNT -eq $((orignidcount + 1)) ] ||
1269                 error "Failover nid not added"
1270
1271         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1272                 do_facet mgs "$PERM_CMD -d osc.$FSNAME-OST0000-osc-*.import"
1273         else
1274                 do_facet mgs "$PERM_CMD -d $FSNAME-OST0000.failover.node" ||
1275                         error "$PERM_CMD delete failed"
1276         fi
1277         umount_client $MOUNT
1278         mount_client $MOUNT || error "mount_client $MOUNT failed"
1279
1280         NIDS=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1281                 grep failover_nids)
1282         NIDCOUNT=$(echo "$NIDS" | wc -w)
1283         echo "only $orignidcount final entries should remain \
1284                 in failover nids string, have $NIDCOUNT"
1285         [ $NIDCOUNT -eq $orignidcount ] || error "Failover nids not removed"
1286
1287         cleanup || error "cleanup failed with rc $?"
1288 }
1289 run_test 30b "Remove failover nids"
1290
1291 test_31() { # bug 10734
1292         # ipaddr must not exist
1293         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1294         cleanup || error "cleanup failed with rc $?"
1295 }
1296 run_test 31 "Connect to non-existent node (shouldn't crash)"
1297
1298
1299 T32_QID=60000
1300 T32_BLIMIT=40960 # Kbytes
1301 T32_ILIMIT=4
1302
1303 #
1304 # This is not really a test but a tool to create new disk
1305 # image tarballs for the upgrade tests.
1306 #
1307 # Disk image tarballs should be created on single-node
1308 # clusters by running this test with default configurations
1309 # plus a few mandatory environment settings that are verified
1310 # at the beginning of the test.
1311 #
1312 test_32newtarball() {
1313         local version
1314         local dst=.
1315         local src=/etc/rc.d
1316         local tmp=$TMP/t32_image_create
1317         local server_version=$(lustre_version_code $SINGLEMDS)
1318         local remote_dir
1319         local striped_dir
1320         local pushd_dir
1321
1322         if [ $FSNAME != t32fs -o \( -z "$MDSDEV" -a -z "$MDSDEV1" \) -o \
1323              $OSTCOUNT -ne 1 -o -z "$OSTDEV1" ]; then
1324                 error "Needs FSNAME=t32fs MDSCOUNT=2 "                  \
1325                       "MDSDEV1=<nonexistent_file>"                      \
1326                       "MDSDEV2=<nonexistent_file>"                      \
1327                       "(or MDSDEV, in the case of b1_8)"                \
1328                       "OSTCOUNT=1 OSTDEV1=<nonexistent_file>"
1329         fi
1330
1331         mkdir $tmp || {
1332                 echo "Found stale $tmp"
1333                 return 1
1334         }
1335
1336         mkdir $tmp/src || return 1
1337         tar cf - -C $src . | tar xf - -C $tmp/src
1338         dd if=/dev/zero of=$tmp/src/t32_qf_old bs=1M \
1339                 count=$(($T32_BLIMIT / 1024 / 4))
1340         chown $T32_QID.$T32_QID $tmp/src/t32_qf_old
1341
1342         # format ost with comma-separated NIDs to verify LU-4460
1343         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
1344         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1345
1346         setupall
1347
1348         [[ $server_version -ge $(version_code 2.3.50) ]] ||
1349                 $LFS quotacheck -ug /mnt/$FSNAME
1350         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1351                 /mnt/$FSNAME
1352
1353         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1354
1355         if [[ $MDSCOUNT -ge 2 ]]; then
1356                 remote_dir=/mnt/$FSNAME/remote_dir
1357                 $LFS mkdir -i 1 $remote_dir
1358                 tar cf - -C $tmp/src . | tar xf - -C $remote_dir
1359
1360                 if [[ $server_version -ge $(version_code 2.7.0) ]]; then
1361                         striped_dir=/mnt/$FSNAME/striped_dir_old
1362                         $LFS mkdir -i 1 -c 2 $striped_dir
1363                         tar cf - -C $tmp/src . | tar xf - -C $striped_dir
1364                 fi
1365         fi
1366
1367         stopall
1368
1369         mkdir $tmp/img || return 1
1370
1371         setupall
1372
1373         pushd_dir=/mnt/$FSNAME
1374         if [[ $MDSCOUNT -ge 2 ]]; then
1375                 pushd_dir=$remote_dir
1376                 if [[ $server_version -ge $(version_code 2.7.0) ]]; then
1377                         pushd $striped_dir
1378                         ls -Rni --time-style=+%s >$tmp/img/list2
1379                         popd
1380                 fi
1381         fi
1382
1383         pushd $pushd_dir
1384         ls -Rni --time-style=+%s >$tmp/img/list
1385         find ! -name .lustre -type f -exec sha1sum {} \; |
1386                 sort -k 2 >$tmp/img/sha1sums
1387         popd
1388         $LCTL get_param -n version | head -n 1 |
1389                 sed -e 's/^lustre: *//' >$tmp/img/commit
1390
1391         [[ $server_version -ge $(version_code 2.3.50) ]] ||
1392                 $LFS quotaon -ug /mnt/$FSNAME
1393         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1394         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1395                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1396                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1397                 | tr -d "*" > $tmp/img/bspace
1398         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1399                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1400                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1401                 | tr -d "*" > $tmp/img/ispace
1402         echo $T32_BLIMIT > $tmp/img/blimit
1403         echo $T32_ILIMIT > $tmp/img/ilimit
1404
1405         stopall
1406
1407         pushd $tmp/src
1408         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1409         popd
1410
1411         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1412                 echo "Data verification failed"
1413         fi
1414
1415         uname -r >$tmp/img/kernel
1416         uname -m >$tmp/img/arch
1417
1418         mv ${MDSDEV1:-$MDSDEV} $tmp/img
1419         for num in $(seq 2 $MDSCOUNT); do
1420                 local devname=$(mdsdevname $num)
1421                 local facet=mds$num
1422                 [[ $(facet_fstype $facet) != zfs ]] ||
1423                         devname=$(mdsvdevname $num)
1424                 mv $devname $tmp/img
1425         done
1426         mv $OSTDEV1 $tmp/img
1427
1428         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1429                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1430         dst=$(cd $dst; pwd)
1431         pushd $tmp/img
1432         tar cjvf $dst/disk$version-$(facet_fstype $SINGLEMDS).tar.bz2 -S *
1433         popd
1434
1435         rm -r $tmp
1436 }
1437 #run_test 32newtarball "Create a new test_32 disk image tarball for this version"
1438
1439 #
1440 # The list of applicable tarballs is returned via the caller's
1441 # variable "tarballs".
1442 #
1443 t32_check() {
1444         [ "$CLIENTONLY" ] && skip "Client-only testing"
1445
1446         local node=$(facet_active_host $SINGLEMDS)
1447         local r="do_node $node"
1448
1449         ! $r which "$TUNEFS" && skip_env "tunefs.lustre required on $node"
1450
1451         local IMGTYPE=$(facet_fstype $SINGLEMDS)
1452
1453         tarballs=$($r find $RLUSTRE/tests -maxdepth 1 \
1454                    -name \'disk*-$IMGTYPE.tar.bz2\')
1455
1456         [ -z "$tarballs" ] && skip "No applicable tarballs found"
1457 }
1458
1459 t32_test_cleanup() {
1460         local tmp=$TMP/t32
1461         local facet=$SINGLEMDS
1462         local fstype=$(facet_fstype $facet)
1463         local rc=$?
1464
1465         if $shall_cleanup_lustre; then
1466                 umount $tmp/mnt/lustre || rc=$?
1467         fi
1468         if $shall_cleanup_mdt; then
1469                 $r $UMOUNT $tmp/mnt/mdt || rc=$?
1470         fi
1471         if $shall_cleanup_mdt1; then
1472                 $r $UMOUNT $tmp/mnt/mdt1 || rc=$?
1473         fi
1474         if $shall_cleanup_ost; then
1475                 $r $UMOUNT $tmp/mnt/ost || rc=$?
1476         fi
1477
1478         $r rm -rf $tmp
1479         rm -rf $tmp
1480         if [[ $fstype == zfs ]]; then
1481                 local poolname
1482                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1483
1484                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1485
1486                 for poolname in $poolname_list; do
1487                         destroy_zpool $facet $poolname
1488                 done
1489         fi
1490         combined_mgs_mds || start_mgs || rc=$?
1491         return $rc
1492 }
1493
1494 t32_bits_per_long() {
1495         #
1496         # Yes, this is not meant to be perfect.
1497         #
1498         case $1 in
1499                 ppc64|x86_64)
1500                         echo -n 64;;
1501                 i*86)
1502                         echo -n 32;;
1503         esac
1504 }
1505
1506 t32_reload_modules() {
1507         local node=$1
1508         local all_removed=false
1509         local i=0
1510         local fstype=$(facet_fstype $SINGLEMDS)
1511
1512         [ $fstype == "zfs" ] && do_rpc_nodes $node "service zed stop"
1513
1514         while ((i < 20)); do
1515                 echo "Unloading modules on $node: Attempt $i"
1516                 do_rpc_nodes $node $LUSTRE_RMMOD $fstype &&
1517                         all_removed=true
1518                 do_rpc_nodes $node check_mem_leak || return 1
1519                 if $all_removed; then
1520                         do_rpc_nodes $node load_modules
1521                         return 0
1522                 fi
1523                 if [ $fstype == "zfs" ]; then
1524                         do_rpc_nodes $node "$ZPOOL status -v"
1525                 fi
1526                 sleep 5
1527                 i=$((i + 1))
1528         done
1529         echo "Unloading modules on $node: Given up"
1530         return 1
1531 }
1532
1533 t32_wait_til_devices_gone() {
1534         local node=$1
1535         local devices
1536         local loops
1537         local i=0
1538
1539         echo wait for devices to go
1540         while ((i < 20)); do
1541                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1542                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1543                 ((devices == 0 && loops == 0)) && return 0
1544                 sleep 5
1545                 i=$((i + 1))
1546         done
1547         echo "waiting for dev on $node: dev $devices loop $loops given up"
1548         do_rpc_nodes $node "losetup -a"
1549         do_rpc_nodes $node "$LCTL device_list"
1550         return 1
1551 }
1552
1553 t32_verify_quota() {
1554         local facet=$1
1555         local fsname=$2
1556         local mnt=$3
1557         local fstype=$(facet_fstype $SINGLEMDS)
1558         local qval
1559         local cmd
1560
1561         # LU-2435: if the underlying zfs doesn't support userobj_accounting,
1562         # lustre will estimate the object count usage. This fails quota
1563         # verification in 32b. The object quota usage should be accurate after
1564         # zfs-0.7.0 is released.
1565         [ $fstype == "zfs" ] && {
1566                 local zfs_version=$(do_facet $facet cat /sys/module/zfs/version)
1567
1568                 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] && {
1569                         echo "Skip quota verify for zfs: $zfs_version"
1570                         return 0
1571                 }
1572         }
1573
1574         $LFS quota -u $T32_QID -v $mnt
1575
1576         qval=$($LFS quota -v -u $T32_QID $mnt |
1577                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1578                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1579                 | tr -d "*")
1580         [ $qval -eq $img_bspace ] || {
1581                 echo "bspace, act:$qval, exp:$img_bspace"
1582                 return 1
1583         }
1584
1585         qval=$($LFS quota -v -u $T32_QID $mnt |
1586                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1587                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1588                 | tr -d "*")
1589         [ $qval -eq $img_ispace ] || {
1590                 echo "ispace, act:$qval, exp:$img_ispace"
1591                 return 1
1592         }
1593
1594         qval=$($LFS quota -v -u $T32_QID $mnt |
1595                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1596                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1597                 | tr -d "*")
1598         [ $qval -eq $img_blimit ] || {
1599                 echo "blimit, act:$qval, exp:$img_blimit"
1600                 return 1
1601         }
1602
1603         qval=$($LFS quota -v -u $T32_QID $mnt |
1604                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1605                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1606                 | tr -d "*")
1607         [ $qval -eq $img_ilimit ] || {
1608                 echo "ilimit, act:$qval, exp:$img_ilimit"
1609                 return 1
1610         }
1611
1612         set_persistent_param_and_check $facet \
1613                 "osd-$fstype.$fsname-MDT0000.quota_slave.enabled" \
1614                 "$fsname.quota.mdt" ug
1615
1616         set_persistent_param_and_check $facet \
1617                 "osd-$fstype.$fsname-OST0000.quota_slave.enabled" \
1618                 "$fsname.quota.ost" ug
1619
1620         chmod 0777 $mnt
1621         runas -u $T32_QID -g $T32_QID dd if=/dev/zero of=$mnt/t32_qf_new \
1622                 bs=1M count=$((img_blimit / 1024)) oflag=sync && {
1623                 echo "Write succeed, but expect -EDQUOT"
1624                 return 1
1625         }
1626         rm -f $mnt/t32_qf_new
1627
1628         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1629                 $img_ilimit && {
1630                 echo "Create succeed, but expect -EDQUOT"
1631                 return 1
1632         }
1633         unlinkmany $mnt/t32_qf_ $img_ilimit
1634
1635         return 0
1636 }
1637
1638 t32_test() {
1639         local tarball=$1
1640         local writeconf=$2
1641         local dne_upgrade=${dne_upgrade:-"no"}
1642         local dom_upgrade=${dom_upgrade:-"no"}
1643         local ff_convert=${ff_convert:-"no"}
1644         local shall_cleanup_mdt=false
1645         local shall_cleanup_mdt1=false
1646         local shall_cleanup_ost=false
1647         local shall_cleanup_lustre=false
1648         local mdt2_is_available=false
1649         local node=$(facet_active_host $SINGLEMDS)
1650         local r="do_node $node"
1651         local tmp=$TMP/t32
1652         local img_commit
1653         local img_kernel
1654         local img_arch
1655         local img_bspace
1656         local img_ispace
1657         local img_blimit
1658         local img_ilimit
1659         local fsname=t32fs
1660         local nid
1661         local mopts
1662         local uuid
1663         local nrpcs_orig
1664         local nrpcs
1665         local list
1666         local fstype=$(facet_fstype $SINGLEMDS)
1667         local mdt_dev=$tmp/mdt
1668         local mdt2_dev=$tmp/mdt2
1669         local ost_dev=$tmp/ost
1670         local stripe_index
1671         local stripe_count
1672         local dir
1673
1674         combined_mgs_mds || stop_mgs || error "Unable to stop MGS"
1675         trap 'trap - RETURN; t32_test_cleanup' RETURN
1676
1677         load_modules
1678         nid=$($r $LCTL list_nids | head -1)
1679
1680         mkdir -p $tmp/mnt/lustre || error "mkdir $tmp/mnt/lustre failed"
1681         $r mkdir -p $tmp/mnt/{mdt,mdt1,ost}
1682         $r tar xjvf $tarball -S -C $tmp || {
1683                 error_noexit "Unpacking the disk image tarball"
1684                 return 1
1685         }
1686         img_commit=$($r cat $tmp/commit)
1687         img_kernel=$($r cat $tmp/kernel)
1688         img_arch=$($r cat $tmp/arch)
1689         img_bspace=$($r cat $tmp/bspace)
1690         img_ispace=$($r cat $tmp/ispace)
1691
1692         # older images did not have "blimit" and "ilimit" files
1693         # use old values for T32_BLIMIT and T32_ILIMIT
1694         $r test -f $tmp/blimit && img_blimit=$($r cat $tmp/blimit) ||
1695                 img_blimit=20480
1696         $r test -f $tmp/ilimit && img_ilimit=$($r cat $tmp/ilimit) ||
1697                 img_ilimit=2
1698
1699         echo "Upgrading from $(basename $tarball), created with:"
1700         echo "  Commit: $img_commit"
1701         echo "  Kernel: $img_kernel"
1702         echo "    Arch: $img_arch"
1703         echo "OST version: $(lustre_build_version ost1)"
1704
1705         # The conversion can be made only when both of the following
1706         # conditions are satisfied:
1707         # - ost device img version < 2.3.64
1708         # - ost server version >= 2.5
1709         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
1710                 $(lustre_version_code ost1) -lt $(version_code 2.5.0) ] &&
1711                         ff_convert="no"
1712
1713         ! $r test -f $mdt2_dev || mdt2_is_available=true
1714
1715         if [[ $fstype == zfs ]]; then
1716                 # import pool first
1717                 local poolname
1718                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1719
1720                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1721
1722                 for poolname in $poolname_list; do
1723                         $r "modprobe zfs;
1724                                 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
1725                                 $ZPOOL import -f -d $tmp $poolname"
1726                 done
1727
1728                 # upgrade zpool to latest supported features, including
1729                 # dnode quota accounting in 0.7.0
1730                 $r "$ZPOOL upgrade -a"
1731
1732                 mdt_dev=t32fs-mdt1/mdt1
1733                 ost_dev=t32fs-ost1/ost1
1734                 ! $mdt2_is_available || mdt2_dev=t32fs-mdt2/mdt2
1735                 wait_update_facet $SINGLEMDS "$ZPOOL list |
1736                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
1737                                 error_noexit "import zfs pool failed"
1738                                 return 1
1739                         }
1740         fi
1741
1742         $r $LCTL set_param debug="$PTLDEBUG"
1743
1744         $r $TUNEFS --dryrun $mdt_dev || {
1745                 $r losetup -a
1746                 error_noexit "tunefs.lustre before mounting the MDT"
1747                 return 1
1748         }
1749
1750         if $mdt2_is_available; then
1751                 $r $TUNEFS --dryrun $mdt2_dev || {
1752                         $r losetup -a
1753                         error_noexit "tunefs.lustre before mounting the MDT"
1754                         return 1
1755                 }
1756         fi
1757
1758         if [ "$writeconf" ]; then
1759                 mopts=writeconf
1760                 if [ $fstype == "ldiskfs" ]; then
1761                         mopts="loop,$mopts"
1762                         $r $TUNEFS --quota $mdt_dev || {
1763                                 $r losetup -a
1764                                 error_noexit "Enable mdt quota feature"
1765                                 return 1
1766                         }
1767                         if $mdt2_is_available; then
1768                                 $r $TUNEFS --quota $mdt2_dev || {
1769                                         $r losetup -a
1770                                         error_noexit "Enable mdt quota feature"
1771                                         return 1
1772                                 }
1773                         fi
1774                 fi
1775         else
1776                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
1777                         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
1778                         skip "LU-2200: Cannot run over IB w/o lctl replace_nids "
1779                                 "(Need MGS version at least 2.3.59)"
1780
1781                         local osthost=$(facet_active_host ost1)
1782                         local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
1783
1784                         mopts=nosvc
1785                         if [ $fstype == "ldiskfs" ]; then
1786                                 mopts="loop,$mopts"
1787                         fi
1788                         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
1789                         $r $LCTL replace_nids $fsname-OST0000 $ostnid
1790                         $r $LCTL replace_nids $fsname-MDT0000 $nid
1791                         $r $UMOUNT $tmp/mnt/mdt
1792                 fi
1793
1794                 mopts=exclude=$fsname-OST0000
1795                 if [ $fstype == "ldiskfs" ]; then
1796                         mopts="loop,$mopts"
1797                 fi
1798         fi
1799
1800         t32_wait_til_devices_gone $node
1801
1802         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
1803                 $r losetup -a
1804                 error_noexit "Mounting the MDT"
1805                 return 1
1806         }
1807         shall_cleanup_mdt=true
1808
1809         if $mdt2_is_available; then
1810                 mopts=mgsnode=$nid,$mopts
1811                 $r $MOUNT_CMD -o $mopts $mdt2_dev $tmp/mnt/mdt1 || {
1812                         $r losetup -a
1813                         error_noexit "Mounting the MDT"
1814                         return 1
1815                 }
1816
1817                 echo "mount new MDT....$mdt2_dev"
1818                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1819                         error_noexit "enable remote dir create failed"
1820
1821                 shall_cleanup_mdt1=true
1822         elif [ "$dne_upgrade" != "no" ]; then
1823                 local fs2mdsdev=$(mdsdevname 1_2)
1824                 local fs2mdsvdev=$(mdsvdevname 1_2)
1825
1826                 echo "mkfs new MDT on ${fs2mdsdev}...."
1827                 if [ $(facet_fstype mds1) == ldiskfs ]; then
1828                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
1829                 fi
1830
1831                 add $SINGLEMDS $(mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
1832                            $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
1833                         error_noexit "Mkfs new MDT failed"
1834                         return 1
1835                 }
1836
1837                 [[ $(facet_fstype mds1) != zfs ]] || import_zpool mds1
1838
1839                 $r $TUNEFS --dryrun $fs2mdsdev || {
1840                         error_noexit "tunefs.lustre before mounting the MDT"
1841                         return 1
1842                 }
1843
1844                 echo "mount new MDT....$fs2mdsdev"
1845                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
1846                         error_noexit "mount mdt1 failed"
1847                         return 1
1848                 }
1849
1850                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
1851                         error_noexit "enable remote dir create failed"
1852
1853                 shall_cleanup_mdt1=true
1854         fi
1855
1856         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
1857                 error_noexit "Getting MDT UUID"
1858                 return 1
1859         }
1860         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
1861                 error_noexit "Unexpected MDT UUID: \"$uuid\""
1862                 return 1
1863         fi
1864
1865         $r $TUNEFS --dryrun $ost_dev || {
1866                 error_noexit "tunefs.lustre before mounting the OST"
1867                 return 1
1868         }
1869         if [ "$writeconf" ]; then
1870                 mopts=mgsnode=$nid,$writeconf
1871                 if [ $fstype == "ldiskfs" ]; then
1872                         mopts="loop,$mopts"
1873                         $r $TUNEFS --quota $ost_dev || {
1874                                 $r losetup -a
1875                                 error_noexit "Enable ost quota feature"
1876                                 return 1
1877                         }
1878                 fi
1879         else
1880                 mopts=mgsnode=$nid
1881                 if [ $fstype == "ldiskfs" ]; then
1882                         mopts="loop,$mopts"
1883                 fi
1884         fi
1885
1886         $r $MOUNT_CMD -onomgs -o$mopts $ost_dev $tmp/mnt/ost || {
1887                 error_noexit "Mounting the OST"
1888                 return 1
1889         }
1890         shall_cleanup_ost=true
1891
1892         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
1893                 error_noexit "Getting OST UUID"
1894                 return 1
1895         }
1896         if [ "$uuid" != $fsname-OST0000_UUID ]; then
1897                 error_noexit "Unexpected OST UUID: \"$uuid\""
1898                 return 1
1899         fi
1900
1901         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1902                 $r $PERM_CMD osc.$fsname-OST0000*.import=connection=$nid || {
1903                         error_noexit "Setting OST \"failover.node\""
1904                         return 1
1905                 }
1906                 $r $PERM_CMD mdc.$fsname-MDT0000*.import=connection=$nid || {
1907                         error_noexit "Setting MDT \"failover.node\""
1908                         return 1
1909                 }
1910                 $r $PERM_CMD osc.$fsname-OST0000-*.max_dirty_mb=15 || {
1911                         error_noexit "Setting \"max_dirty_mb\""
1912                         return 1
1913                 }
1914                 $r $PERM_CMD mdc.$fsname-MDT0000-*.max_rpcs_in_flight=9 || {
1915                         error_noexit "Setting \"max_rpcs_in_flight\""
1916                         return 1
1917                 }
1918                 $r $PERM_CMD lov.$fsname-MDT0000-*.stripesize=4M || {
1919                         error_noexit "Setting \"lov.stripesize\""
1920                         return 1
1921                 }
1922                 $r $PERM_CMD mdd.$fsname-MDT0000-*.atime_diff=70 || {
1923                         error_noexit "Setting \"mdd.atime_diff\""
1924                         return 1
1925                 }
1926         else
1927                 $r $PERM_CMD $fsname-OST0000.failover.node=$nid || {
1928                         error_noexit "Setting OST \"failover.node\""
1929                         return 1
1930                 }
1931
1932                 $r $PERM_CMD $fsname-MDT0000.failover.node=$nid || {
1933                         error_noexit "Setting MDT \"failover.node\""
1934                         return 1
1935                 }
1936
1937                 $r $PERM_CMD $fsname-OST0000.osc.max_dirty_mb=15 || {
1938                         error_noexit "Setting \"max_dirty_mb\""
1939                         return 1
1940                 }
1941                 $r $PERM_CMD $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
1942                         error_noexit "Setting \"max_rpcs_in_flight\""
1943                         return 1
1944                 }
1945                 $r $PERM_CMD $fsname-MDT0000.lov.stripesize=4M || {
1946                         error_noexit "Setting \"lov.stripesize\""
1947                         return 1
1948                 }
1949                 $r $PERM_CMD $fsname-MDT0000.mdd.atime_diff=70 || {
1950                         error_noexit "Setting \"mdd.atime_diff\""
1951                         return 1
1952                 }
1953         fi
1954
1955         $r $LCTL pool_new $fsname.interop || {
1956                 error_noexit "Setting \"interop\""
1957                 return 1
1958         }
1959
1960         if [ "$ff_convert" != "no" -a $(facet_fstype ost1) == "ldiskfs" ]; then
1961                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
1962                         error_noexit "Start OI scrub on OST0"
1963                         return 1
1964                 }
1965
1966                 # The oi_scrub should be on ost1, but for test_32(),
1967                 # all on the SINGLEMDS.
1968                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
1969                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
1970                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
1971                         error_noexit "Failed to get the expected 'completed'"
1972                         return 1
1973                 }
1974
1975                 local UPDATED=$($r $LCTL get_param -n \
1976                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
1977                                 awk '/^updated/ { print $2 }')
1978                 [ $UPDATED -ge 1 ] || {
1979                         error_noexit "Only $UPDATED objects have been converted"
1980                         return 1
1981                 }
1982         fi
1983
1984         if [ "$dne_upgrade" != "no" ]; then
1985                 if [[ $PERM_CMD == *"set_param -P"* ]]; then
1986                         $r $PERM_CMD mdc.$fsname-MDT0001*.import=connection=$nid || {
1987                                 error_noexit "Setting MDT1 \"failover.node\""
1988                                 return 1
1989                         }
1990
1991                         $r $PERM_CMD mdc.$fsname-MDT0001-*.max_rpcs_in_flight=9 || {
1992                                 error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
1993                                 return 1
1994                         }
1995                         $r $PERM_CMD lov.$fsname-MDT0001-*.stripesize=4M || {
1996                                 error_noexit "Setting MDT1 \"lov.stripesize\""
1997                                 return 1
1998                         }
1999                 else
2000                         $r $PERM_CMD $fsname-MDT0001.failover.node=$nid || {
2001                                 error_noexit "Setting MDT1 \"failover.node\""
2002                                 return 1
2003                         }
2004                         $r $PERM_CMD $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
2005                                 error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
2006                                 return 1
2007                         }
2008                         $r $PERM_CMD $fsname-MDT0001.lov.stripesize=4M || {
2009                                 error_noexit "Setting MDT1 \"lov.stripesize\""
2010                                 return 1
2011                         }
2012                 fi
2013         fi
2014
2015         if [ "$writeconf" ]; then
2016                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
2017                         error_noexit "Mounting the client"
2018                         return 1
2019                 }
2020
2021                 shall_cleanup_lustre=true
2022                 $r $LCTL set_param debug="$PTLDEBUG"
2023
2024                 # Leave re-enabling this to a separate patch for LU-11558
2025                 # t32_verify_quota $SINGLEMDS $fsname $tmp/mnt/lustre || {
2026                 #       error_noexit "verify quota failed"
2027                 #       return 1
2028                 #}
2029
2030                 if $r test -f $tmp/list; then
2031                         #
2032                         # There is not a Test Framework API to copy files to or
2033                         # from a remote node.
2034                         #
2035                         # LU-2393 - do both sorts on same node to ensure locale
2036                         # is identical
2037                         local list_file=$tmp/list
2038
2039                         if $mdt2_is_available; then
2040                                 if [[ -d $tmp/mnt/lustre/striped_dir_old ]] &&
2041                                    $r test -f $tmp/list2; then
2042                                         list_file=$tmp/list2
2043                                         pushd $tmp/mnt/lustre/striped_dir_old
2044                                 else
2045                                         pushd $tmp/mnt/lustre/remote_dir
2046                                 fi
2047                         else
2048                                 pushd $tmp/mnt/lustre
2049                         fi
2050                         $r cat $list_file | sort -k 6 >$tmp/list.orig
2051                         ls -Rni --time-style=+%s | sort -k 6 |
2052                                 sed 's/\. / /' >$tmp/list || {
2053                                 error_noexit "ls"
2054                                 return 1
2055                         }
2056                         popd
2057                         #
2058                         # 32-bit and 64-bit clients use different algorithms to
2059                         # convert FIDs into inode numbers.  Hence, remove the
2060                         # inode numbers from the lists, if the original list was
2061                         # created on an architecture with different number of
2062                         # bits per "long".
2063                         #
2064                         if [ $(t32_bits_per_long $(uname -m)) != \
2065                                 $(t32_bits_per_long $img_arch) ]; then
2066                                 echo "Different number of bits per \"long\"" \
2067                                      "from the disk image"
2068                                 for list in list.orig list; do
2069                                         sed -i -e 's/^[0-9]\+[ \t]\+//' \
2070                                                   $tmp/$list
2071                                 done
2072                         fi
2073                         if ! diff -ub $tmp/list.orig $tmp/list; then
2074                                 error_noexit "list verification failed"
2075                                 return 1
2076                         fi
2077                 else
2078                         echo "list verification skipped"
2079                 fi
2080
2081                 if [ "$dom_upgrade" != "no" ]; then
2082                         echo "Check DoM file can be created"
2083                         $LFS setstripe -E 1M -L mdt -E EOF $tmp/mnt/lustre/dom || {
2084                                 error_noexit "Verify DoM creation"
2085                                 return 1
2086                         }
2087                         [ $($LFS getstripe -L $tmp/mnt/lustre/dom) == "mdt" ] || {
2088                                 error_noexit "Verify a DoM file"
2089                                 return 1
2090                         }
2091                         dd if=/dev/urandom of=$tmp/mnt/lustre/dom bs=4096 \
2092                                 count=1 conv=fsync || {
2093                                 error_noexit "Cannot write to DoM file"
2094                                 return 1
2095                         }
2096                         [ $(stat -c%s $tmp/mnt/lustre/dom) == 4096 ] || {
2097                                 error_noexit "DoM: bad size after write"
2098                                 return 1
2099                         }
2100                         rm $tmp/mnt/lustre/dom
2101
2102                         set_persistent_param_and_check mds \
2103                            "lod.*MDT0000*.dom_stripesize" \
2104                            "$fsname-MDT0000.lod.dom_stripesize" 0 || {
2105                                 error_noexit "Changing \"dom_stripesize\""
2106                                 return 1
2107                         }
2108                 fi
2109
2110                 if [ "$dne_upgrade" != "no" ]; then
2111                         $LFS mkdir -i 1 -c2 $tmp/mnt/lustre/striped_dir || {
2112                                 error_noexit "set striped dir failed"
2113                                 return 1
2114                         }
2115
2116                         $LFS setdirstripe -D -c2 $tmp/mnt/lustre/striped_dir
2117
2118                         pushd $tmp/mnt/lustre
2119                         tar -cf - . --exclude=./striped_dir \
2120                                     --exclude=./striped_dir_old \
2121                                     --exclude=./remote_dir |
2122                                 tar -xvf - -C striped_dir 1>/dev/null || {
2123                                 error_noexit "cp to striped dir failed"
2124                                 return 1
2125                         }
2126                         popd
2127                 fi
2128
2129                 # If it is upgrade from DNE (2.5), then rename the remote dir,
2130                 # which is created in 2.5 to striped dir.
2131                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]]; then
2132                         stripe_index=$($LFS getdirstripe -i     \
2133                                        $tmp/mnt/lustre/remote_dir)
2134
2135                         [[ $stripe_index -eq 1 ]] || {
2136                                 error_noexit "get index \"$stripe_index\"" \
2137                                              "from remote dir failed"
2138                                 return 1
2139                         }
2140                         mv $tmp/mnt/lustre/remote_dir   \
2141                                 $tmp/mnt/lustre/striped_dir/ || {
2142                                 error_noexit "mv remote dir failed"
2143                                 return 1
2144                         }
2145                 fi
2146
2147                 # If it is upgraded from DNE (2.7), then move the striped dir
2148                 # which was created in 2.7 to the new striped dir.
2149                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]] &&
2150                         [[ -d $tmp/mnt/lustre/striped_dir_old ]]; then
2151                         stripe_count=$($LFS getdirstripe -c     \
2152                                        $tmp/mnt/lustre/striped_dir_old)
2153                         [[ $stripe_count -eq 2 ]] || {
2154                                 error_noexit "get count $stripe_count" \
2155                                              "from striped dir failed"
2156                                 return 1
2157                         }
2158                         mv $tmp/mnt/lustre/striped_dir_old      \
2159                                 $tmp/mnt/lustre/striped_dir/ || {
2160                                 error_noexit "mv striped dir failed"
2161                                 return 1
2162                         }
2163                 fi
2164
2165                 sync; sleep 5; sync
2166                 $r $LCTL set_param -n osd*.*.force_sync=1
2167                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
2168                         error_noexit "dd failed"
2169                         return 1
2170                 }
2171                 rm -rf $tmp/mnt/lustre/tmp_file || {
2172                         error_noexit "rm failed"
2173                         return 1
2174                 }
2175
2176                 if $r test -f $tmp/sha1sums; then
2177                         # LU-2393 - do both sorts on same node to ensure locale
2178                         # is identical
2179                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
2180                         if [ "$dne_upgrade" != "no" ]; then
2181                                 pushd $tmp/mnt/lustre/striped_dir
2182                         else
2183                                 pushd $tmp/mnt/lustre
2184                         fi
2185
2186                         find ! -path "*remote_dir*" ! -path "*striped_dir*" \
2187                                 ! -name .lustre -type f -exec sha1sum {} \; |
2188                                 sort -k 2 >$tmp/sha1sums || {
2189                                 popd
2190                                 error_noexit "sha1sum"
2191                                 return 1
2192                         }
2193                         popd
2194                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
2195                                 error_noexit "sha1sum verification failed"
2196                                 return 1
2197                         fi
2198
2199                         # if upgrade from DNE(2.5), then check remote directory
2200                         # if upgrade from DNE(2.7), then check striped directory
2201                         if $mdt2_is_available &&
2202                            [[ "$dne_upgrade" != "no" ]]; then
2203                                 local new_dir="$tmp/mnt/lustre/striped_dir"
2204                                 local striped_dir_old="$new_dir/striped_dir_old"
2205
2206                                 local dir_list="$new_dir/remote_dir"
2207                                 [[ ! -d $triped_dir_old ]] ||
2208                                         dir_list+=" $striped_dir_old"
2209
2210                                 for dir in $dir_list; do
2211                                         pushd $dir
2212                                         find ! -name .lustre -type f    \
2213                                                 -exec sha1sum {} \; |
2214                                                 sort -k 2 >$tmp/sha1sums || {
2215                                                         popd
2216                                                         error_noexit "sha1sum"
2217                                                         return 1
2218                                                 }
2219                                         popd
2220                                         if ! diff -ub $tmp/sha1sums.orig \
2221                                                 $tmp/sha1sums; then
2222                                                 error_noexit "sha1sum $dir" \
2223                                                              "failed"
2224                                                 return 1
2225                                         fi
2226                                 done
2227                         fi
2228                 else
2229                         echo "sha1sum verification skipped"
2230                 fi
2231
2232                 if [ "$dne_upgrade" != "no" ]; then
2233                         rm -rf $tmp/mnt/lustre/striped_dir || {
2234                                 error_noexit "remove remote dir failed"
2235                                 return 1
2236                         }
2237                 fi
2238
2239                 # migrate files/dirs to remote MDT, then move them back
2240                 if [ $(lustre_version_code mds1) -ge $(version_code 2.7.50) -a \
2241                      $dne_upgrade != "no" ]; then
2242                         $r $LCTL set_param -n   \
2243                                 mdt.${fsname}*.enable_remote_dir=1 2>/dev/null
2244
2245                         echo "test migration"
2246                         pushd $tmp/mnt/lustre
2247                         for dir in $(find ! -name .lustre ! -name . -type d); do
2248                                 mdt_index=$($LFS getdirstripe -i $dir)
2249                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2250                                 if [ $mdt_index = 0 -a $stripe_cnt -le 1 ]; then
2251                                         $LFS migrate -m 1 $dir || {
2252                                         popd
2253                                         error_noexit "migrate MDT1 failed"
2254                                         return 1
2255                                 }
2256                                 fi
2257                         done
2258
2259                         for dir in $(find ! -name . ! -name .lustre -type d); do
2260                                 mdt_index=$($LFS getdirstripe -i $dir)
2261                                 stripe_cnt=$($LFS getdirstripe -c $dir)
2262                                 if [ $mdt_index = 1 -a $stripe_cnt -le 1 ]; then
2263                                         $LFS migrate -m 0 $dir || {
2264                                         popd
2265                                         error_noexit "migrate MDT0 failed"
2266                                         return 1
2267                                 }
2268                                 fi
2269                         done
2270                         popd
2271                 fi
2272
2273                 #
2274                 # When adding new data verification tests, please check for
2275                 # the presence of the required reference files first, like
2276                 # the "sha1sums" and "list" tests above, to avoid the need to
2277                 # regenerate every image for each test addition.
2278                 #
2279
2280                 nrpcs_orig=$($LCTL get_param \
2281                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
2282                         error_noexit "Getting \"max_rpcs_in_flight\""
2283                         return 1
2284                 }
2285                 nrpcs=$((nrpcs_orig + 5))
2286
2287                 set_persistent_param_and_check client \
2288                    "mdc.$fsname-MDT0000*.max_rpcs_in_flight" \
2289                    "$fsname-MDT0000.mdc.max_rpcs_in_flight" $nrpcs || {
2290                         error_noexit "Changing \"max_rpcs_in_flight\""
2291                         return 1
2292                 }
2293
2294                 umount $tmp/mnt/lustre || {
2295                         error_noexit "Unmounting the client"
2296                         return 1
2297                 }
2298                 shall_cleanup_lustre=false
2299         else
2300                 if [[ "$dne_upgrade" != "no" ]] || $mdt2_is_available; then
2301                         $r $UMOUNT $tmp/mnt/mdt1 || {
2302                                 error_noexit "Unmounting the MDT2"
2303                                 return 1
2304                         }
2305                         if [[ $fstype == zfs ]]; then
2306                             $r "$ZPOOL export t32fs-mdt2"
2307                         fi
2308                         shall_cleanup_mdt1=false
2309                 fi
2310
2311                 $r $UMOUNT $tmp/mnt/mdt || {
2312                         error_noexit "Unmounting the MDT"
2313                         return 1
2314                 }
2315                 if [[ $fstype == zfs ]]; then
2316                     $r "$ZPOOL export t32fs-mdt1"
2317                 fi
2318                 shall_cleanup_mdt=false
2319
2320                 $r $UMOUNT $tmp/mnt/ost || {
2321                         error_noexit "Unmounting the OST"
2322                         return 1
2323                 }
2324                 if [[ $fstype == zfs ]]; then
2325                     $r "$ZPOOL export t32fs-ost1"
2326                 fi
2327                 shall_cleanup_ost=false
2328
2329                 t32_reload_modules $node || {
2330                         error_noexit "Reloading modules"
2331                         return 1
2332                 }
2333
2334                 if [[ $fstype == zfs ]]; then
2335                         local poolname=t32fs-mdt1
2336                         $r "modprobe zfs;
2337                             $ZPOOL list -H $poolname >/dev/null 2>&1 ||
2338                                 $ZPOOL import -f -d $tmp $poolname"
2339
2340                         # upgrade zpool to latest supported features,
2341                         # including dnode quota accounting in 0.7.0
2342                         $r "$ZPOOL upgrade $poolname"
2343                 fi
2344
2345                 # mount a second time to make sure we didnt leave upgrade flag on
2346                 $r $TUNEFS --dryrun $mdt_dev || {
2347                         $r losetup -a
2348                         error_noexit "tunefs.lustre before remounting the MDT"
2349                         return 1
2350                 }
2351
2352                 mopts=exclude=$fsname-OST0000
2353                 if [ $fstype == "ldiskfs" ]; then
2354                         mopts="loop,$mopts"
2355                 fi
2356                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
2357                         error_noexit "Remounting the MDT"
2358                         return 1
2359                 }
2360                 shall_cleanup_mdt=true
2361         fi
2362 }
2363
2364 test_32a() {
2365         local tarballs
2366         local tarball
2367         local rc=0
2368
2369         t32_check
2370         for tarball in $tarballs; do
2371                 t32_test $tarball || let "rc += $?"
2372         done
2373         return $rc
2374 }
2375 run_test 32a "Upgrade (not live)"
2376
2377 test_32b() {
2378         local tarballs
2379         local tarball
2380         local rc=0
2381
2382         t32_check
2383         for tarball in $tarballs; do
2384                 t32_test $tarball writeconf || let "rc += $?"
2385         done
2386         return $rc
2387 }
2388 run_test 32b "Upgrade with writeconf"
2389
2390 test_32c() {
2391         local tarballs
2392         local tarball
2393         local rc=0
2394
2395         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
2396         t32_check
2397         for tarball in $tarballs; do
2398                 # Do not support 1_8 and 2_1 direct upgrade to DNE2 anymore */
2399                 echo $tarball | grep "1_8" && continue
2400                 echo $tarball | grep "2_1" && continue
2401                 load_modules
2402                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
2403         done
2404         return $rc
2405 }
2406 run_test 32c "dne upgrade test"
2407
2408 test_32d() {
2409         local tarballs
2410         local tarball
2411         local rc=0
2412
2413         t32_check
2414         for tarball in $tarballs; do
2415                 ff_convert=yes t32_test $tarball || rc=$?
2416         done
2417         return $rc
2418 }
2419 run_test 32d "convert ff test"
2420
2421 test_32e() {
2422         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.56) ]] ||
2423                 skip "Need MDS version at least 2.10.56"
2424
2425         local tarballs
2426         local tarball
2427         local rc=0
2428
2429         t32_check
2430         for tarball in $tarballs; do
2431                 echo $tarball | grep "2_9" || continue
2432                 #load_modules
2433                 dom_upgrade=yes t32_test $tarball writeconf || let "rc += $?"
2434         done
2435         return $rc
2436 }
2437 run_test 32e "dom upgrade test"
2438
2439 test_33a() { # bug 12333, was test_33
2440         local FSNAME2=test-123
2441         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2442         local mkfsoptions
2443
2444         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
2445
2446         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
2447                 local dev=${SINGLEMDS}_dev
2448                 local MDSDEV=${!dev}
2449                 is_blkdev $SINGLEMDS $MDSDEV &&
2450                         skip_env "mixed loopback and real device not working"
2451         fi
2452
2453         local fs2mdsdev=$(mdsdevname 1_2)
2454         local fs2ostdev=$(ostdevname 1_2)
2455         local fs2mdsvdev=$(mdsvdevname 1_2)
2456         local fs2ostvdev=$(ostvdevname 1_2)
2457
2458         if [ $(facet_fstype mds1) == ldiskfs ]; then
2459                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
2460         fi
2461
2462         if combined_mgs_mds; then
2463                 local mgs_flag="--mgs"
2464         fi
2465
2466         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --fsname=${FSNAME2} \
2467                 --reformat $mgs_flag $mkfsoptions $fs2mdsdev $fs2mdsvdev ||
2468                 exit 10
2469         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2470                 --fsname=${FSNAME2} --index=8191 --reformat $fs2ostdev \
2471                 $fs2ostvdev || exit 10
2472
2473         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
2474         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2475
2476         if [[ $PERM_CMD == *"set_param -P"* ]]; then
2477                 do_facet mgs "$PERM_CMD timeout=200" ||
2478                         error "$PERM_CMD timeout=200 failed"
2479         else
2480                 do_facet mgs "$PERM_CMD $FSNAME2.sys.timeout=200" ||
2481                         error "$PERM_CMD $FSNAME2.sys.timeout=200 failed"
2482         fi
2483         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2484         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2485         echo "ok."
2486
2487         cp /etc/hosts $MOUNT2/ || error "copy /etc/hosts $MOUNT2/ failed"
2488         $LFS getstripe $MOUNT2/hosts ||
2489                 error "$LFS getstripe $MOUNT2/hosts failed"
2490
2491         umount $MOUNT2
2492         stop fs2ost -f
2493         stop fs2mds -f
2494         cleanup_nocli || error "cleanup_nocli failed with $?"
2495 }
2496 run_test 33a "Mount ost with a large index number"
2497
2498 test_33b() {    # was test_34
2499         setup
2500
2501         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
2502         # Drop lock cancelation reply during umount
2503         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
2504         do_facet client $LCTL set_param fail_loc=0x80000304
2505         #lctl set_param debug=-1
2506         umount_client $MOUNT
2507         cleanup || error "cleanup failed with $?"
2508 }
2509 run_test 33b "Drop cancel during umount"
2510
2511 test_34a() {
2512         setup
2513         do_facet client "sh runmultiop_bg_pause $DIR/file O_c"
2514         manual_umount_client
2515         rc=$?
2516         do_facet client killall -USR1 multiop
2517         if [ $rc -eq 0 ]; then
2518                 error "umount not fail!"
2519         fi
2520         sleep 1
2521         cleanup || error "cleanup failed with rc $?"
2522 }
2523 run_test 34a "umount with opened file should be fail"
2524
2525 test_34b() {
2526         setup
2527         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2528         stop_mds || error "Unable to stop MDS"
2529
2530         manual_umount_client --force || error "mtab after failed umount with $?"
2531
2532         cleanup || error "cleanup failed with $?"
2533 }
2534 run_test 34b "force umount with failed mds should be normal"
2535
2536 test_34c() {
2537         setup
2538         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
2539         stop_ost || error "Unable to stop OST1"
2540
2541         manual_umount_client --force || error "mtab after failed umount with $?"
2542
2543         cleanup || error "cleanup failed with $?"
2544 }
2545 run_test 34c "force umount with failed ost should be normal"
2546
2547 test_35a() { # bug 12459
2548         setup
2549
2550         DBG_SAVE="`$LCTL get_param -n debug`"
2551         $LCTL set_param debug="ha"
2552
2553         log "Set up a fake failnode for the MDS"
2554         FAKENID="127.0.0.2"
2555         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2556                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2557
2558         if [[ $PERM_CMD == *"set_param -P"* ]]; then
2559                 do_facet mgs "$PERM_CMD \
2560                               mdc.*${device}*.import=connection=$(h2nettype $FAKENID)" ||
2561                         error "Setting mdc.*${device}*.import=connection=\
2562                                $(h2nettype $FAKENID) failed."
2563         else
2564                 do_facet mgs "$PERM_CMD \
2565                               ${device}.failover.node=$(h2nettype $FAKENID)" ||
2566                         error "Setting ${device}.failover.node=\
2567                                $(h2nettype $FAKENID) failed."
2568         fi
2569         log "Wait for RECONNECT_INTERVAL seconds (10s)"
2570         sleep 10
2571
2572         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
2573         $LCTL clear
2574         log "$MSG"
2575         log "Stopping the MDT: $device"
2576         stop_mdt 1 || error "MDT0 stop fail"
2577
2578         df $MOUNT > /dev/null 2>&1 &
2579         DFPID=$!
2580         log "Restarting the MDT: $device"
2581         start_mdt 1 || error "MDT0 start fail"
2582         log "Wait for df ($DFPID) ... "
2583         wait $DFPID
2584         log "done"
2585         $LCTL set_param debug="$DBG_SAVE"
2586
2587         # retrieve from the log the first server that the client tried to
2588         # contact after the connection loss
2589         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2590         NEXTCONN=`awk "/${MSG}/ {start = 1;}
2591                        /import_select_connection.*$device-mdc.* using connection/ {
2592                                 if (start) {
2593                                         if (\\\$NF ~ /$FAKENID/)
2594                                                 print \\\$NF;
2595                                         else
2596                                                 print 0;
2597                                         exit;
2598                                 }
2599                        }" $TMP/lustre-log-$TESTNAME.log`
2600         [ "$NEXTCONN" != "0" ] &&
2601                 error "Tried to connect to ${NEXTCONN} not last active server"
2602         cleanup || error "cleanup failed with $?"
2603         # remove nid settings
2604         writeconf_or_reformat
2605 }
2606 run_test 35a "Reconnect to the last active server first"
2607
2608 test_35b() { # bug 18674
2609         remote_mds || skip "local MDS"
2610         setup
2611
2612         debugsave
2613         $LCTL set_param debug="ha"
2614         $LCTL clear
2615         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
2616         log "$MSG"
2617
2618         log "Set up a fake failnode for the MDS"
2619         FAKENID="127.0.0.2"
2620         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
2621                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
2622
2623         if [[ $PERM_CMD == *"set_param -P"* ]]; then
2624                 do_facet mgs "$PERM_CMD \
2625                               mdc.*${device}*.import=connection=$(h2nettype $FAKENID)" ||
2626                         error "Set mdc.*${device}*.import=connection=\
2627                                $(h2nettype $FAKENID) failed"
2628         else
2629                 do_facet mgs "$PERM_CMD \
2630                               ${device}.failover.node=$(h2nettype $FAKENID)" ||
2631                         error "Set ${device}.failover.node=\
2632                                $(h2nettype $FAKENID) failed"
2633         fi
2634
2635         local at_max_saved=0
2636         # adaptive timeouts may prevent seeing the issue
2637         if at_is_enabled; then
2638                 at_max_saved=$(at_max_get mds)
2639                 at_max_set 0 mds client
2640         fi
2641
2642         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
2643
2644         log "Injecting EBUSY on MDS"
2645         # Setting OBD_FAIL_MDS_RESEND=0x136
2646         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" ||
2647                 error "unable to set param fail_loc=0x80000136"
2648
2649         $LCTL set_param mdc.${FSNAME}*.stats=clear
2650
2651         log "Creating a test file and stat it"
2652         touch $MOUNT/$tdir/$tfile || error "touch $MOUNT/$tdir/$tfile failed"
2653         stat $MOUNT/$tdir/$tfile
2654
2655         log "Stop injecting EBUSY on MDS"
2656         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" ||
2657                 error "unable to set param fail_loc=0"
2658         rm -f $MOUNT/$tdir/$tfile || error "remove $MOUNT/$tdir/$tfile failed"
2659
2660         log "done"
2661         # restore adaptive timeout
2662         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
2663
2664         $LCTL dk $TMP/lustre-log-$TESTNAME.log
2665
2666         CONNCNT=$($LCTL get_param mdc.${FSNAME}*.stats |
2667                   awk '/mds_connect/{print $2}')
2668
2669         # retrieve from the log if the client has ever tried to
2670         # contact the fake server after the loss of connection
2671         FAILCONN=`awk "BEGIN {ret = 0;}
2672                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
2673                                 ret = 1;
2674                                 if (\\\$NF ~ /$FAKENID/) {
2675                                         ret = 2;
2676                                         exit;
2677                                 }
2678                        }
2679                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
2680
2681         [ "$FAILCONN" == "0" ] &&
2682                 error "The client reconnection has not been triggered"
2683         [ "$FAILCONN" == "2" ] &&
2684                 error "Primary server busy, client reconnect to failover failed"
2685
2686         # LU-290
2687         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
2688         # Reconnects are supposed to be rate limited to one every 5s
2689         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] &&
2690                 error "Too many reconnects $CONNCNT"
2691
2692         cleanup || error "cleanup failed with $?"
2693         # remove nid settings
2694         writeconf_or_reformat
2695 }
2696 run_test 35b "Continue reconnection retries, if the active server is busy"
2697
2698 test_36() { # 12743
2699         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
2700
2701         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] ||
2702                 skip "remote OST"
2703
2704         local rc=0
2705         local FSNAME2=test1234
2706         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2707
2708         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
2709
2710         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
2711                 is_blkdev $SINGLEMDS $MDSDEV &&
2712                         skip_env "mixed loopback and real device not working"
2713         fi
2714
2715         local fs2mdsdev=$(mdsdevname 1_2)
2716         local fs2ostdev=$(ostdevname 1_2)
2717         local fs3ostdev=$(ostdevname 2_2)
2718         local fs2mdsvdev=$(mdsvdevname 1_2)
2719         local fs2ostvdev=$(ostvdevname 1_2)
2720         local fs3ostvdev=$(ostvdevname 2_2)
2721
2722         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
2723                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
2724         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
2725         #     different one than the default value here.
2726         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
2727                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
2728         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
2729                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
2730
2731         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
2732         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
2733         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
2734         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
2735         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
2736
2737         sleep 5 # until 11778 fixed
2738
2739         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || error "dd failed"
2740
2741         BKTOTAL=$($LCTL get_param -n obdfilter.*.kbytestotal |
2742                   awk 'BEGIN{total=0}; {total+=$1}; END{print total}')
2743         BKFREE=$($LCTL get_param -n obdfilter.*.kbytesfree |
2744                  awk 'BEGIN{free=0}; {free+=$1}; END{print free}')
2745         BKAVAIL=$($LCTL get_param -n obdfilter.*.kbytesavail |
2746                   awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
2747         STRING=$(df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}')
2748         DFTOTAL=$(echo $STRING | cut -d, -f1)
2749         DFUSED=$(echo $STRING  | cut -d, -f2)
2750         DFAVAIL=$(echo $STRING | cut -d, -f3)
2751         DFFREE=$(($DFTOTAL - $DFUSED))
2752
2753         ALLOWANCE=$((64 * $OSTCOUNT))
2754
2755         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
2756            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
2757                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
2758                 rc=1
2759         fi
2760         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
2761            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
2762                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
2763                 rc=2
2764         fi
2765         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
2766            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
2767                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
2768                 rc=3
2769        fi
2770
2771         $UMOUNT $MOUNT2
2772         stop fs3ost -f || error "unable to stop OST3"
2773         stop fs2ost -f || error "unable to stop OST2"
2774         stop fs2mds -f || error "unable to stop second MDS"
2775         unload_modules_conf || error "unable unload modules"
2776         return $rc
2777 }
2778 run_test 36 "df report consistency on OSTs with different block size"
2779
2780 test_37() {
2781         local mntpt=$(facet_mntpt $SINGLEMDS)
2782         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
2783         local mdsdev_sym="$TMP/sym_mdt.img"
2784         local opts=$MDS_MOUNT_OPTS
2785         local rc=0
2786
2787         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
2788                 skip "ldiskfs only test"
2789         fi
2790
2791         echo "MDS :     $mdsdev"
2792         echo "SYMLINK : $mdsdev_sym"
2793         do_facet $SINGLEMDS rm -f $mdsdev_sym
2794
2795         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
2796
2797         echo "mount symlink device - $mdsdev_sym"
2798
2799         if ! do_facet $SINGLEMDS test -b $mdsdev; then
2800                 opts=$(csa_add "$opts" -o loop)
2801         fi
2802         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
2803                 $mdsdev_sym $mntpt 2>&1)
2804         rc=${PIPESTATUS[0]}
2805
2806         echo mount_op=$mount_op
2807
2808         do_facet $SINGLEMDS "$UMOUNT $mntpt && rm -f $mdsdev_sym"
2809
2810         if $(echo $mount_op | grep -q "unable to set tunable"); then
2811                 error "set tunables failed for symlink device"
2812         fi
2813
2814         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
2815 }
2816 run_test 37 "verify set tunables works for symlink device"
2817
2818 test_38() { # bug 14222
2819         local fstype=$(facet_fstype $SINGLEMDS)
2820         local mntpt=$(facet_mntpt $SINGLEMDS)
2821
2822         setup
2823         # like runtests
2824         local COUNT=10
2825         local SRC="/etc /bin"
2826         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
2827         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
2828         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
2829         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
2830                 error "copying $SRC to $DIR/$tdir"
2831         sync
2832         umount_client $MOUNT || error "umount_client $MOUNT failed"
2833         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2834         stop_mds || error "Unable to stop MDS"
2835         log "delete lov_objid file on MDS"
2836
2837         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
2838
2839         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
2840
2841         unmount_fstype $SINGLEMDS || error "umount failed (1)"
2842
2843         # check create in mds_lov_connect
2844         start_mds || error "unable to start MDS"
2845         mount_client $MOUNT || error "mount_client $MOUNT failed"
2846         for f in $FILES; do
2847                 [ $V ] && log "verifying $DIR/$tdir/$f"
2848                 diff -q $f $DIR/$tdir/$f || ERROR=y
2849         done
2850         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2851         if [ "$ERROR" = "y" ]; then
2852                 # check it's updates in sync
2853                 umount_client $MOUNT
2854                 stop_mds
2855                 mount_fstype $SIGNLEMDS
2856                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2857                 unmount_fstype $SINGLEMDS
2858                 error "old and new files are different after connect" || true
2859         fi
2860         touch $DIR/$tdir/f2 || error "f2 file create failed"
2861
2862         # check it's updates in sync
2863         umount_client $MOUNT || error "second umount_client $MOUNT failed"
2864         stop_mds
2865
2866         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
2867
2868         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2869         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
2870
2871         unmount_fstype $SINGLEMDS || error "umount failed (3)"
2872
2873         start_mds || error "unable to start MDS"
2874         mount_client $MOUNT || error "mount_client $MOUNT failed"
2875         for f in $FILES; do
2876                 [ $V ] && log "verifying $DIR/$tdir/$f"
2877                 diff -q $f $DIR/$tdir/$f || ERROR=y
2878         done
2879         touch $DIR/$tdir/f3 || error "f3 file create failed"
2880         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
2881         umount_client $MOUNT || error "third umount_client $MOUNT failed"
2882         stop_mds
2883         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
2884         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
2885         unmount_fstype $SINGLEMDS || error "umount failed (4)"
2886
2887         [ "$ERROR" = "y" ] &&
2888                 error "old and new files are different after sync" || true
2889
2890         log "files compared the same"
2891         cleanup || error "cleanup failed with $?"
2892 }
2893 run_test 38 "MDS recreates missing lov_objid file from OST data"
2894
2895 test_39() {
2896         PTLDEBUG=+malloc
2897         setup
2898         cleanup || error "cleanup failed with $?"
2899         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
2900                 error "memory leak detected" || true
2901 }
2902 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
2903
2904 test_40() { # bug 15759
2905         start_ost || error "Unable to start OST1"
2906         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
2907         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
2908         start_mds
2909         cleanup || error "cleanup failed with rc $?"
2910 }
2911 run_test 40 "race during service thread startup"
2912
2913 test_41a() { #bug 14134
2914         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2915            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2916                 skip "Loop devices does not work with nosvc option"
2917         fi
2918
2919         combined_mgs_mds || skip "needs combined MGT and MDT device"
2920
2921         start_mdt 1 -o nosvc -n
2922         if [ $MDSCOUNT -ge 2 ]; then
2923                 for num in $(seq 2 $MDSCOUNT); do
2924                         start_mdt $num || return
2925                 done
2926         fi
2927         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
2928         start_mdt 1 -o nomgs,force
2929         mount_client $MOUNT || error "mount_client $MOUNT failed"
2930         sleep 5
2931
2932         echo "blah blah" > $MOUNT/$tfile
2933         cat $MOUNT/$tfile
2934
2935         umount_client $MOUNT || error "umount_client $MOUNT failed"
2936         stop ost1 -f || error "unable to stop OST1"
2937         stop_mds || error "Unable to stop MDS"
2938         stop_mds || error "Unable to stop MDS on second try"
2939 }
2940 run_test 41a "mount mds with --nosvc and --nomgs"
2941
2942 test_41b() {
2943         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
2944            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
2945                 skip "Loop devices does not work with nosvc option"
2946         fi
2947
2948         ! combined_mgs_mds && skip "needs combined mgs device"
2949
2950         stopall
2951         reformat
2952         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
2953
2954         start_mdt 1 -o nosvc -n
2955         if [ $MDSCOUNT -ge 2 ]; then
2956                 for num in $(seq 2 $MDSCOUNT); do
2957                         start_mdt $num || return
2958                 done
2959         fi
2960         start_ost || error "Unable to start OST1"
2961         start_mdt 1 -o nomgs,force
2962         mount_client $MOUNT || error "mount_client $MOUNT failed"
2963         sleep 5
2964
2965         echo "blah blah" > $MOUNT/$tfile
2966         cat $MOUNT/$tfile || error "cat $MOUNT/$tfile failed"
2967
2968         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
2969         stop_ost || error "Unable to stop OST1"
2970         stop_mds || error "Unable to stop MDS"
2971         stop_mds || error "Unable to stop MDS on second try"
2972 }
2973 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
2974
2975 test_41c() {
2976         local server_version=$(lustre_version_code $SINGLEMDS)
2977         local oss_list=$(comma_list $(osts_nodes))
2978
2979         [[ $server_version -ge $(version_code 2.6.52) ]] ||
2980         [[ $server_version -ge $(version_code 2.5.26) &&
2981            $server_version -lt $(version_code 2.5.50) ]] ||
2982         [[ $server_version -ge $(version_code 2.5.4) &&
2983            $server_version -lt $(version_code 2.5.11) ]] ||
2984                 skip "Need MDS version 2.5.4+ or 2.5.26+ or 2.6.52+"
2985
2986         # ensure mds1 ost1 have been created even if running sub-test standalone
2987         cleanup
2988         setup
2989         cleanup || error "cleanup failed"
2990
2991         # using directly mount command instead of start() function to avoid
2992         # any side effect of // with others/externals tools/features
2993         # ("zpool import", ...)
2994
2995         # MDT concurrent start
2996
2997         LOAD_MODULES_REMOTE=true load_modules
2998         do_facet $SINGLEMDS "lsmod | grep -q libcfs" ||
2999                 error "MDT concurrent start: libcfs module not loaded"
3000
3001         local mds1dev=$(mdsdevname 1)
3002         local mds1mnt=$(facet_mntpt mds1)
3003         local mds1fstype=$(facet_fstype mds1)
3004         local mds1opts=$MDS_MOUNT_OPTS
3005
3006         if [ $mds1fstype == ldiskfs ] &&
3007            ! do_facet mds1 test -b $mds1dev; then
3008                 mds1opts=$(csa_add "$mds1opts" -o loop)
3009         fi
3010         if [[ $mds1fstype == zfs ]]; then
3011                 import_zpool mds1 || return ${PIPESTATUS[0]}
3012         fi
3013
3014         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
3015         do_facet mds1 "$LCTL set_param fail_loc=0x80000716"
3016
3017         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts &
3018         local pid=$!
3019
3020         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts
3021         local rc2=$?
3022         wait $pid
3023         local rc=$?
3024         do_facet mds1 "$LCTL set_param fail_loc=0x0"
3025         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
3026                 echo "1st MDT start succeed"
3027                 echo "2nd MDT start failed with $rc2"
3028         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
3029                 echo "1st MDT start failed with $rc"
3030                 echo "2nd MDT start succeed"
3031         else
3032                 stop mds1 -f
3033                 error "unexpected concurrent MDT mounts result, rc=$rc rc2=$rc2"
3034         fi
3035
3036         if [ $MDSCOUNT -ge 2 ]; then
3037                 for num in $(seq 2 $MDSCOUNT); do
3038                         start_mdt $num || return
3039                 done
3040         fi
3041
3042         # OST concurrent start
3043
3044         do_rpc_nodes $oss_list "lsmod | grep -q libcfs" ||
3045                 error "OST concurrent start: libcfs module not loaded"
3046
3047         local ost1dev=$(ostdevname 1)
3048         local ost1mnt=$(facet_mntpt ost1)
3049         local ost1fstype=$(facet_fstype ost1)
3050         local ost1opts=$OST_MOUNT_OPTS
3051
3052         if [ $ost1fstype == ldiskfs ] &&
3053            ! do_facet ost1 test -b $ost1dev; then
3054                 ost1opts=$(csa_add "$ost1opts" -o loop)
3055         fi
3056         if [[ $ost1fstype == zfs ]]; then
3057                 import_zpool ost1 || return ${PIPESTATUS[0]}
3058         fi
3059
3060         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
3061         do_facet ost1 "$LCTL set_param fail_loc=0x80000716"
3062
3063         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts &
3064         pid=$!
3065
3066         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts
3067         rc2=$?
3068         wait $pid
3069         rc=$?
3070         do_facet ost1 "$LCTL set_param fail_loc=0x0"
3071         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
3072                 echo "1st OST start succeed"
3073                 echo "2nd OST start failed with $rc2"
3074         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
3075                 echo "1st OST start failed with $rc"
3076                 echo "2nd OST start succeed"
3077         else
3078                 stop_mds -f
3079                 stop ost1 -f
3080                 error "unexpected concurrent OST mounts result, rc=$rc rc2=$rc2"
3081         fi
3082         # cleanup
3083         stop_mds
3084         stop ost1 -f
3085
3086         # verify everything ok
3087         start_mds
3088         if [ $? != 0 ]
3089         then
3090                 stop_mds
3091                 error "MDT(s) start failed"
3092         fi
3093
3094         start_ost
3095         if [ $? != 0 ]
3096         then
3097                 stop_mds
3098                 stop ost1 -f
3099                 error "OST(s) start failed"
3100         fi
3101
3102         mount_client $MOUNT
3103         if [ $? != 0 ]
3104         then
3105                 stop_mds
3106                 stop ost1 -f
3107                 error "client start failed"
3108         fi
3109         check_mount
3110         if [ $? != 0 ]
3111         then
3112                 stop_mds
3113                 stop ost1 -f
3114                 error "client mount failed"
3115         fi
3116         cleanup
3117 }
3118 run_test 41c "concurrent mounts of MDT/OST should all fail but one"
3119
3120 test_42() { #bug 14693
3121         local PARAM
3122
3123         setup
3124         check_mount || error "client was not mounted"
3125
3126         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3127                 PARAM="llite.$FSNAME-*.some_wrong_param"
3128         else
3129                 PARAM="$FSNAME.llite.some_wrong_param"
3130         fi
3131
3132         do_facet mgs $PERM_CMD $PARAM=10
3133         umount_client $MOUNT ||
3134                 error "unmounting client failed with invalid llite param"
3135         mount_client $MOUNT ||
3136                 error "mounting client failed with invalid llite param"
3137
3138         do_facet mgs $PERM_CMD $PARAM=20
3139         cleanup || error "stopping $FSNAME failed with invalid sys param"
3140         setup
3141         check_mount || error "client was not mounted with invalid sys param"
3142         cleanup || error "stopping $FSNAME failed with invalid sys param"
3143 }
3144 run_test 42 "allow client/server mount/unmount with invalid config param"
3145
3146 test_43a() {
3147         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.58) ]] ||
3148                 skip "Need MDS version at least 2.5.58"
3149         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
3150
3151         ID1=${ID1:-501}
3152         USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
3153         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1"
3154
3155         setup
3156         chmod ugo+x $DIR || error "chmod 0 failed"
3157         set_persistent_param_and_check mds1                             \
3158                 "mdt.$FSNAME-MDT0000.root_squash"                       \
3159                 "$FSNAME.mdt.root_squash"                               \
3160                 "0:0"
3161         wait_update $HOSTNAME                                           \
3162                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3163                 "0:0" ||
3164                 error "check llite root_squash failed!"
3165         set_persistent_param_and_check mds1                             \
3166                 "mdt.$FSNAME-MDT0000.nosquash_nids"                     \
3167                 "$FSNAME.mdt.nosquash_nids"                             \
3168                 "NONE"
3169         wait_update $HOSTNAME                                           \
3170                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3171                 "NONE" ||
3172                 error "check llite nosquash_nids failed!"
3173
3174         #
3175         # create set of test files
3176         #
3177         echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
3178         chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
3179         chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
3180
3181         echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
3182         chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
3183
3184         mkdir $DIR/$tdir-rootdir || error "mkdir failed"
3185         chmod go-rwx $DIR/$tdir-rootdir || error "chmod 3 failed"
3186         touch $DIR/$tdir-rootdir/tfile-1 || error "touch failed"
3187
3188         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
3189         chmod go-rw $DIR/$tfile-user1file || error "chmod 7 failed"
3190         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
3191
3192         #
3193         # check root_squash:
3194         #   set root squash UID:GID to RUNAS_ID
3195         #   root should be able to access only files owned by RUNAS_ID
3196         #
3197         set_persistent_param_and_check mds1                             \
3198                 "mdt.$FSNAME-MDT0000.root_squash"                       \
3199                 "$FSNAME.mdt.root_squash"                               \
3200                 "$RUNAS_ID:$RUNAS_ID"
3201         wait_update $HOSTNAME                                           \
3202                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
3203                 "$RUNAS_ID:$RUNAS_ID" ||
3204                 error "check llite root_squash failed!"
3205
3206         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
3207         dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3208                 error "$ST: root read permission is denied"
3209         echo "$ST: root read permission is granted - ok"
3210
3211         echo "444" |
3212         dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
3213                 error "$ST: root write permission is denied"
3214         echo "$ST: root write permission is granted - ok"
3215
3216         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3217         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3218                 error "$ST: root read permission is granted"
3219         echo "$ST: root read permission is denied - ok"
3220
3221         echo "555" |
3222         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
3223                 error "$ST: root write permission is granted"
3224         echo "$ST: root write permission is denied - ok"
3225
3226         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3227                 rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null &&
3228                         error "$ST: root unlink permission is granted"
3229         echo "$ST: root unlink permission is denied - ok"
3230
3231         touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null &&
3232                 error "$ST: root create permission is granted"
3233         echo "$ST: root create permission is denied - ok"
3234
3235         # LU-1778
3236         # check root_squash is enforced independently
3237         # of client cache content
3238         #
3239         # access file by USER1, keep access open
3240         # root should be denied access to user file
3241
3242         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
3243         pid=$!
3244         sleep 1
3245
3246         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
3247         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3248             { kill $pid; error "$ST: root read permission is granted"; }
3249         echo "$ST: root read permission is denied - ok"
3250
3251         echo "777" |
3252         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
3253             { kill $pid; error "$ST: root write permission is granted"; }
3254         echo "$ST: root write permission is denied - ok"
3255
3256         kill $pid
3257         wait $pid
3258
3259         #
3260         # check nosquash_nids:
3261         #   put client's NID into nosquash_nids list,
3262         #   root should be able to access root file after that
3263         #
3264         local NIDLIST=$($LCTL list_nids all | tr '\n' ' ')
3265         NIDLIST="2@gni $NIDLIST 192.168.0.[2,10]@tcp"
3266         NIDLIST=$(echo $NIDLIST | tr -s ' ' ' ')
3267         set_persistent_param_and_check mds1                             \
3268                 "mdt.$FSNAME-MDT0000.nosquash_nids"                     \
3269                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
3270                 "$NIDLIST"
3271         wait_update $HOSTNAME                                           \
3272                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
3273                 "$NIDLIST" ||
3274                 error "check llite nosquash_nids failed!"
3275
3276         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
3277         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3278                 error "$ST: root read permission is denied"
3279         echo "$ST: root read permission is granted - ok"
3280
3281         echo "666" |
3282         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
3283                 error "$ST: root write permission is denied"
3284         echo "$ST: root write permission is granted - ok"
3285
3286         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
3287         rm $DIR/$tdir-rootdir/tfile-1 ||
3288                 error "$ST: root unlink permission is denied"
3289         echo "$ST: root unlink permission is granted - ok"
3290         touch $DIR/$tdir-rootdir/tfile-2 ||
3291                 error "$ST: root create permission is denied"
3292         echo "$ST: root create permission is granted - ok"
3293         cleanup || error "cleanup failed with $?"
3294 }
3295 run_test 43a "check root_squash and nosquash_nids"
3296
3297 test_43b() { # LU-5690
3298         [[ $(lustre_version_code mgs) -ge $(version_code 2.7.62) ]] ||
3299                 skip "Need MGS version 2.7.62+"
3300
3301         if [[ -z "$fs2mds_DEV" ]]; then
3302                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
3303                 skip_env "mixed loopback and real device not working"
3304         fi
3305
3306         local fs2mdsdev=$(mdsdevname 1_2)
3307         local fs2mdsvdev=$(mdsvdevname 1_2)
3308
3309         # temporarily use fs2mds as fs2mgs
3310         local fs2mgs=fs2mds
3311         local fs2mgsdev=$fs2mdsdev
3312         local fs2mgsvdev=$fs2mdsvdev
3313
3314         local fsname=test1234
3315
3316         load_module llite/lustre
3317         local client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
3318         local host=${client_ip//*./}
3319         local net=${client_ip/%$host/}
3320         local nosquash_nids=$(h2nettype $net[$host,$host,$host])
3321
3322         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
3323                 --param mdt.root_squash=$RUNAS_ID:$RUNAS_ID \
3324                 --param mdt.nosquash_nids=$nosquash_nids \
3325                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
3326         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS  || error "start fs2mgs failed"
3327         stop $fs2mgs -f || error "stop fs2mgs failed"
3328         cleanup || error "cleanup failed with $?"
3329 }
3330 run_test 43b "parse nosquash_nids with commas in expr_list"
3331
3332 test_44() { # 16317
3333         setup
3334         check_mount || error "check_mount"
3335         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
3336         STATS_FOUND=no
3337         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
3338         for VAL in $UUIDS; do
3339                 NID=$(echo $VAL | cut -d= -f1)
3340                 CLUUID=$(echo $VAL | cut -d= -f2)
3341                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
3342         done
3343         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
3344         cleanup || error "cleanup failed with $?"
3345 }
3346 run_test 44 "mounted client proc entry exists"
3347
3348 test_45() { #17310
3349         setup
3350         check_mount || error "check_mount"
3351         stop_mds || error "Unable to stop MDS"
3352         df -h $MOUNT &
3353         log "sleep 60 sec"
3354         sleep 60
3355         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK        0x50f
3356         do_facet client "$LCTL set_param fail_loc=0x8000050f"
3357         log "sleep 10 sec"
3358         sleep 10
3359         manual_umount_client --force || error "manual_umount_client failed"
3360         do_facet client "$LCTL set_param fail_loc=0x0"
3361         start_mds || error "unable to start MDS"
3362         mount_client $MOUNT || error "mount_client $MOUNT failed"
3363         cleanup || error "cleanup failed with $?"
3364 }
3365 run_test 45 "long unlink handling in ptlrpcd"
3366
3367 cleanup_46a() {
3368         trap 0
3369         local rc=0
3370         local count=$1
3371
3372         umount_client $MOUNT2 || rc=$?
3373         umount_client $MOUNT || rc=$?
3374         while [ $count -gt 0 ]; do
3375                 stop ost${count} -f || rc=$?
3376                 let count=count-1
3377         done
3378         stop_mds || rc=$?
3379         cleanup_nocli || rc=$?
3380         #writeconf to remove all ost2 traces for subsequent tests
3381         writeconf_or_reformat
3382         return $rc
3383 }
3384
3385 test_46a() {
3386         echo "Testing with $OSTCOUNT OSTs"
3387         reformat_and_config
3388         start_mds || error "unable to start MDS"
3389         #first client should see only one ost
3390         start_ost || error "Unable to start OST1"
3391         wait_osc_import_state mds ost FULL
3392         #start_client
3393         mount_client $MOUNT || error "mount_client $MOUNT failed"
3394         trap "cleanup_46a $OSTCOUNT" EXIT ERR
3395
3396         local i
3397         for (( i=2; i<=$OSTCOUNT; i++ )); do
3398                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
3399                         error "start_ost$i $(ostdevname $i) failed"
3400         done
3401
3402         # wait until osts in sync
3403         for (( i=2; i<=$OSTCOUNT; i++ )); do
3404             wait_osc_import_state mds ost$i FULL
3405             wait_osc_import_ready client ost$i
3406         done
3407
3408         #second client see all ost's
3409
3410         mount_client $MOUNT2 || error "mount_client failed"
3411         $LFS setstripe -c -1 $MOUNT2 ||
3412                 error "$LFS setstripe -c -1 $MOUNT2 failed"
3413         $LFS getstripe $MOUNT2 || error "$LFS getstripe $MOUNT2 failed"
3414
3415         echo "ok" > $MOUNT2/widestripe
3416         $LFS getstripe $MOUNT2/widestripe ||
3417                 error "$LFS getstripe $MOUNT2/widestripe failed"
3418         # fill acl buffer for avoid expand lsm to them
3419         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd |
3420                 while read acl; do
3421             setfacl -m $acl $MOUNT2/widestripe
3422         done
3423
3424         # will be deadlock
3425         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3426
3427         cleanup_46a $OSTCOUNT || error "cleanup_46a failed"
3428 }
3429 run_test 46a "handle ost additional - wide striped file"
3430
3431 test_47() { #17674
3432         reformat
3433         setup_noconfig
3434         check_mount || error "check_mount failed"
3435         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
3436
3437         local lru_size=[]
3438         local count=0
3439         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3440             if echo $ns | grep "MDT[[:digit:]]*"; then
3441                 continue
3442             fi
3443             lrs=$(echo $ns | sed 's/.*lru_size=//')
3444             lru_size[count]=$lrs
3445             let count=count+1
3446         done
3447
3448         facet_failover ost1
3449         facet_failover $SINGLEMDS
3450         client_up || error "client_up failed"
3451
3452         count=0
3453         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
3454             if echo $ns | grep "MDT[[:digit:]]*"; then
3455                 continue
3456             fi
3457             lrs=$(echo $ns | sed 's/.*lru_size=//')
3458             if ! test "$lrs" -eq "${lru_size[count]}"; then
3459                 n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
3460                 error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
3461             fi
3462             let count=count+1
3463         done
3464
3465         cleanup || error "cleanup failed with $?"
3466 }
3467 run_test 47 "server restart does not make client loss lru_resize settings"
3468
3469 cleanup_48() {
3470         trap 0
3471
3472         # reformat after this test is needed - if the test fails,
3473         # we will have unkillable file at FS
3474         reformat_and_config
3475 }
3476
3477 test_48() { # bz-17636 LU-7473
3478         local count
3479
3480         setup_noconfig
3481         check_mount || error "check_mount failed"
3482
3483         $LFS setstripe -c -1 $MOUNT ||
3484                 error "$LFS setstripe -c -1 $MOUNT failed"
3485         $LFS getstripe $MOUNT || error "$LFS getstripe $MOUNT failed"
3486
3487         echo "ok" > $MOUNT/widestripe
3488         $LFS getstripe $MOUNT/widestripe ||
3489                 error "$LFS getstripe $MOUNT/widestripe failed"
3490
3491         # In the future, we may introduce more EAs, such as selinux, enlarged
3492         # LOV EA, and so on. These EA will use some EA space that is shared by
3493         # ACL entries. So here we only check some reasonable ACL entries count,
3494         # instead of the max number that is calculated from the max_ea_size.
3495         if [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.8.57) ];
3496         then
3497                 count=28        # hard coded of RPC protocol
3498         elif [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3499                 count=4000      # max_num 4091 max_ea_size = 32768
3500         elif ! large_xattr_enabled; then
3501                 count=450       # max_num 497 max_ea_size = 4012
3502         else
3503                 count=4500      # max_num 8187 max_ea_size = 1048492
3504                                 # not create too much (>5000) to save test time
3505         fi
3506
3507         echo "It is expected to hold at least $count ACL entries"
3508         trap cleanup_48 EXIT ERR
3509         for ((i = 0; i < $count; i++)) do
3510                 setfacl -m u:$((i + 100)):rw $MOUNT/widestripe ||
3511                         error "Fail to setfacl for $MOUNT/widestripe at $i"
3512         done
3513
3514         cancel_lru_locks mdc
3515         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
3516         local r_count=$(getfacl $MOUNT/widestripe | grep "user:" | wc -l)
3517         count=$((count + 1)) # for the entry "user::rw-"
3518
3519         [ $count -eq $r_count ] ||
3520                 error "Expected ACL entries $count, but got $r_count"
3521
3522         cleanup_48
3523 }
3524 run_test 48 "too many acls on file"
3525
3526 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
3527 test_49a() { # bug 17710
3528         local timeout_orig=$TIMEOUT
3529         local ldlm_timeout_orig=$LDLM_TIMEOUT
3530         local LOCAL_TIMEOUT=20
3531
3532         LDLM_TIMEOUT=$LOCAL_TIMEOUT
3533         TIMEOUT=$LOCAL_TIMEOUT
3534
3535         reformat
3536         setup_noconfig
3537         check_mount || error "client mount failed"
3538
3539         echo "check ldlm_timout..."
3540         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3541         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3542         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3543
3544         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3545                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3546         fi
3547
3548         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
3549                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
3550         fi
3551
3552         umount_client $MOUNT || error "umount_client $MOUNT failed"
3553         stop_ost || error "problem stopping OSS"
3554         stop_mds || error "problem stopping MDS"
3555
3556         LDLM_TIMEOUT=$ldlm_timeout_orig
3557         TIMEOUT=$timeout_orig
3558 }
3559 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3560
3561 test_49b() { # bug 17710
3562         local timeout_orig=$TIMEOUT
3563         local ldlm_timeout_orig=$LDLM_TIMEOUT
3564         local LOCAL_TIMEOUT=20
3565
3566         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
3567         TIMEOUT=$LOCAL_TIMEOUT
3568
3569         reformat
3570         setup_noconfig
3571         check_mount || error "client mount failed"
3572
3573         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
3574         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
3575         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
3576
3577         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
3578                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
3579         fi
3580
3581         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
3582                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
3583         fi
3584
3585         cleanup || error "cleanup failed"
3586
3587         LDLM_TIMEOUT=$ldlm_timeout_orig
3588         TIMEOUT=$timeout_orig
3589 }
3590 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
3591
3592 lazystatfs() {
3593         # wait long enough to exceed OBD_STATFS_CACHE_SECONDS = 1
3594         sleep 2
3595         # Test both statfs and lfs df and fail if either one fails
3596         multiop_bg_pause $1 f_
3597         RC=$?
3598         PID=$!
3599         killall -USR1 multiop
3600         [ $RC -ne 0 ] && log "lazystatfs multiop failed"
3601         wait $PID || { RC=$?; log "multiop return error "; }
3602
3603         # wait long enough to exceed OBD_STATFS_CACHE_SECONDS = 1
3604         sleep 2
3605         $LFS df -l &
3606         PID=$!
3607         sleep 5
3608         if kill -s 0 $PID; then
3609                 RC=1
3610                 kill -s 9 $PID
3611                 log "lazystatfs lfs df failed to complete in 5s"
3612         fi
3613
3614         return $RC
3615 }
3616
3617 test_50a() {
3618         setup
3619         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3620         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3621
3622         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
3623
3624         cleanup || error "cleanup failed with rc $?"
3625 }
3626 run_test 50a "lazystatfs all servers available"
3627
3628 test_50b() {
3629         setup
3630         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3631         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3632
3633         # Wait for client to detect down OST
3634         stop_ost || error "Unable to stop OST1"
3635         wait_osc_import_state client ost DISCONN
3636         $LCTL dl
3637         log "OSCs should all be DISCONN"
3638
3639         lazystatfs $MOUNT || error "lazystatfs should not return EIO"
3640
3641         umount_client $MOUNT || error "Unable to unmount client"
3642         stop_mds || error "Unable to stop MDS"
3643 }
3644 run_test 50b "lazystatfs all servers down"
3645
3646 test_50c() {
3647         start_mds || error "Unable to start MDS"
3648         start_ost || error "Unable to start OST1"
3649         start_ost2 || error "Unable to start OST2"
3650         mount_client $MOUNT || error "Unable to mount client"
3651         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3652         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3653
3654         # Wait for client to detect down OST
3655         stop_ost || error "Unable to stop OST1"
3656         wait_osc_import_state mds ost DISCONN
3657         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3658
3659         umount_client $MOUNT || error "Unable to unmount client"
3660         stop_ost2 || error "Unable to stop OST2"
3661         stop_mds || error "Unable to stop MDS"
3662         #writeconf to remove all ost2 traces for subsequent tests
3663         writeconf_or_reformat
3664 }
3665 run_test 50c "lazystatfs one server down"
3666
3667 test_50d() {
3668         start_mds || error "Unable to start MDS"
3669         start_ost || error "Unable to start OST1"
3670         start_ost2 || error "Unable to start OST2"
3671         mount_client $MOUNT || error "Unable to mount client"
3672         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
3673         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3674
3675         # Issue the statfs during the window where the client still
3676         # belives the OST to be available but it is in fact down.
3677         # No failure just a statfs which hangs for a timeout interval.
3678         stop_ost || error "Unable to stop OST1"
3679         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
3680
3681         umount_client $MOUNT || error "Unable to unmount client"
3682         stop_ost2 || error "Unable to stop OST2"
3683         stop_mds || error "Unable to stop MDS"
3684         #writeconf to remove all ost2 traces for subsequent tests
3685         writeconf_or_reformat
3686 }
3687 run_test 50d "lazystatfs client/server conn race"
3688
3689 test_50e() {
3690         local RC1
3691         local pid
3692
3693         reformat_and_config
3694         start_mds || error "Unable to start MDS"
3695         #first client should see only one ost
3696         start_ost || error "Unable to start OST1"
3697         wait_osc_import_state mds ost FULL
3698
3699         # Wait for client to detect down OST
3700         stop_ost || error "Unable to stop OST1"
3701         wait_osc_import_state mds ost DISCONN
3702
3703         mount_client $MOUNT || error "Unable to mount client"
3704         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3705
3706         multiop_bg_pause $MOUNT _f
3707         RC1=$?
3708         pid=$!
3709
3710         if [ $RC1 -ne 0 ]; then
3711                 log "multiop failed $RC1"
3712         else
3713             kill -USR1 $pid
3714             sleep $(( $TIMEOUT+1 ))
3715             kill -0 $pid
3716             [ $? -ne 0 ] && error "process isn't sleep"
3717             start_ost || error "Unable to start OST1"
3718             wait $pid || error "statfs failed"
3719         fi
3720
3721         umount_client $MOUNT || error "Unable to unmount client"
3722         stop_ost || error "Unable to stop OST1"
3723         stop_mds || error "Unable to stop MDS"
3724 }
3725 run_test 50e "normal statfs all servers down"
3726
3727 test_50f() {
3728         local RC1
3729         local pid
3730         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
3731
3732         start_mds || error "Unable to start mds"
3733         #first client should see only one ost
3734         start_ost || error "Unable to start OST1"
3735         wait_osc_import_state mds ost FULL
3736
3737         start_ost2 || error "Unable to start OST2"
3738         wait_osc_import_state mds ost2 FULL
3739
3740         # Wait for client to detect down OST
3741         stop_ost2 || error "Unable to stop OST2"
3742
3743         wait_osc_import_state mds ost2 DISCONN
3744         mount_client $MOUNT || error "Unable to mount client"
3745         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
3746
3747         multiop_bg_pause $MOUNT _f
3748         RC1=$?
3749         pid=$!
3750
3751         if [ $RC1 -ne 0 ]; then
3752                 log "lazystatfs multiop failed $RC1"
3753         else
3754             kill -USR1 $pid
3755             sleep $(( $TIMEOUT+1 ))
3756             kill -0 $pid
3757             [ $? -ne 0 ] && error "process isn't sleep"
3758             start_ost2 || error "Unable to start OST2"
3759             wait $pid || error "statfs failed"
3760             stop_ost2 || error "Unable to stop OST2"
3761         fi
3762
3763         umount_client $MOUNT -f || error "Unable to unmount client"
3764         stop_ost || error "Unable to stop OST1"
3765         stop_mds || error "Unable to stop MDS"
3766         #writeconf to remove all ost2 traces for subsequent tests
3767         writeconf_or_reformat
3768 }
3769 run_test 50f "normal statfs one server in down"
3770
3771 test_50g() {
3772         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs"
3773         setup
3774         start_ost2 || error "Unable to start OST2"
3775         wait_osc_import_state mds ost2 FULL
3776         wait_osc_import_ready client ost2
3777
3778         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3779                 local PARAM="osc.${FSNAME}-OST0001*.active"
3780         else
3781                 local PARAM="${FSNAME}-OST0001.osc.active"
3782         fi
3783
3784         $LFS setstripe -c -1 $DIR/$tfile || error "$LFS setstripe failed"
3785         do_facet mgs $PERM_CMD $PARAM=0 || error "Unable to deactivate OST"
3786
3787         umount_client $MOUNT || error "Unable to unmount client"
3788         mount_client $MOUNT || error "Unable to mount client"
3789         # This df should not cause a panic
3790         df -k $MOUNT
3791
3792         do_facet mgs $PERM_CMD $PARAM=1 || error "Unable to activate OST"
3793         rm -f $DIR/$tfile || error "unable to remove file $DIR/$tfile"
3794         umount_client $MOUNT || error "Unable to unmount client"
3795         stop_ost2 || error "Unable to stop OST2"
3796         stop_ost || error "Unable to stop OST1"
3797         stop_mds || error "Unable to stop MDS"
3798         #writeconf to remove all ost2 traces for subsequent tests
3799         writeconf_or_reformat
3800 }
3801 run_test 50g "deactivated OST should not cause panic"
3802
3803 # LU-642
3804 test_50h() {
3805         # prepare MDT/OST, make OSC inactive for OST1
3806         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs"
3807
3808         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
3809         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
3810                 error "tunefs OST1 failed"
3811         start_mds  || error "Unable to start MDT"
3812         start_ost  || error "Unable to start OST1"
3813         start_ost2 || error "Unable to start OST2"
3814         mount_client $MOUNT || error "client start failed"
3815
3816         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3817
3818         # activatate OSC for OST1
3819         set_persistent_param_and_check client            \
3820                 "osc.${FSNAME}-OST0000-osc-[!M]*.active" \
3821                 "${FSNAME}-OST0000.osc.active" 1
3822
3823         mkdir $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
3824         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2 ||
3825                 error "$LFS setstripe $DIR/$tdir/2 failed"
3826         sleep 1 && echo "create a file after OST1 is activated"
3827         # doing some io, shouldn't crash
3828         dd if=/dev/zero of=$DIR/$tdir/2/$tfile-io bs=1M count=10
3829
3830         # check OSC import is working
3831         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
3832                 error "some OSC imports are still not connected"
3833
3834         # cleanup
3835         rm -rf $DIR/$tdir
3836         umount_client $MOUNT || error "Unable to umount client"
3837         stop_ost2 || error "Unable to stop OST2"
3838         cleanup_nocli || error "cleanup_nocli failed with $?"
3839 }
3840 run_test 50h "LU-642: activate deactivated OST"
3841
3842 test_50i() {
3843         # prepare MDT/OST, make OSC inactive for OST1
3844         [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
3845
3846         load_modules
3847         [ $(facet_fstype mds2) == zfs ] && import_zpool mds2
3848         do_facet mds2 "$TUNEFS --param mdc.active=0 $(mdsdevname 2)" ||
3849                 error "tunefs MDT2 failed"
3850         start_mds  || error "Unable to start MDT"
3851         start_ost  || error "Unable to start OST1"
3852         start_ost2 || error "Unable to start OST2"
3853         mount_client $MOUNT || error "client start failed"
3854
3855         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3856
3857         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3858                 $PERM_CMD mdc.${FSNAME}-MDT0001-mdc-*.active=0 &&
3859                         error "deactive MDC0 succeeds"
3860         else
3861                 $PERM_CMD ${FSNAME}-MDT0000.mdc.active=0 &&
3862                         error "deactive MDC0 succeeds"
3863         fi
3864
3865         # activate MDC for MDT2
3866         set_persistent_param_and_check client            \
3867                 "mdc.${FSNAME}-MDT0001-mdc-*.active" \
3868                 "${FSNAME}-MDT0001.mdc.active" 1
3869
3870         wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds2 FULL
3871         if [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.60) ]
3872         then
3873                 wait_dne_interconnect
3874         fi
3875         $LFS mkdir -i1 $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
3876         # create some file
3877         createmany -o $DIR/$tdir/2/$tfile-%d 1 || error "create files failed"
3878
3879         rm -rf $DIR/$tdir/2 || error "unlink dir failed"
3880
3881         # deactivate MDC for MDT2
3882         set_persistent_param_and_check client           \
3883                 "mdc.${FSNAME}-MDT0001-mdc-*.active"    \
3884                 "${FSNAME}-MDT0001.mdc.active" 0
3885
3886         wait_osp_active mds ${FSNAME}-MDT0001 1 0
3887
3888         $LFS mkdir -i1 $DIR/$tdir/2 &&
3889                 error "mkdir $DIR/$tdir/2 succeeds after deactive MDT"
3890
3891         $LFS mkdir -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
3892                 error "mkdir $DIR/$tdir/striped_dir fails after deactive MDT2"
3893
3894         local stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
3895         [ $stripe_count -eq $((MDSCOUNT - 1)) ] ||
3896                 error "wrong $stripe_count != $((MDSCOUNT -1)) for striped_dir"
3897
3898         # cleanup
3899         umount_client $MOUNT || error "Unable to umount client"
3900         stop_mds
3901         stop_ost
3902         stop_ost 2
3903 }
3904 run_test 50i "activate deactivated MDT"
3905
3906 test_51() {
3907         local LOCAL_TIMEOUT=20
3908
3909         reformat
3910         setup_noconfig
3911         check_mount || error "check_mount failed"
3912
3913         mkdir $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
3914         $LFS setstripe -c -1 $MOUNT/$tdir ||
3915                 error "$LFS setstripe -c -1 $MOUNT/$tdir failed"
3916         #define OBD_FAIL_MDS_REINT_DELAY         0x142
3917         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x142"
3918         touch $MOUNT/$tdir/$tfile &
3919         local pid=$!
3920         sleep 2
3921         start_ost2 || error "Unable to start OST1"
3922         wait $pid
3923         stop_ost2 || error "Unable to stop OST1"
3924         umount_client $MOUNT -f || error “unmount $MOUNT failed”
3925         cleanup_nocli || error “stop server failed”
3926         #writeconf to remove all ost2 traces for subsequent tests
3927         writeconf_or_reformat
3928 }
3929 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
3930
3931 copy_files_xattrs()
3932 {
3933         local node=$1
3934         local dest=$2
3935         local xattrs=$3
3936         shift 3
3937
3938         do_node $node mkdir -p $dest
3939         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3940
3941         do_node $node  'tar cf - '$@' | tar xf - -C '$dest';
3942                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3943         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
3944
3945         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs
3946         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
3947 }
3948
3949 diff_files_xattrs()
3950 {
3951         local node=$1
3952         local backup=$2
3953         local xattrs=$3
3954         shift 3
3955
3956         local backup2=${TMP}/backup2
3957
3958         do_node $node mkdir -p $backup2
3959         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
3960
3961         do_node $node  'tar cf - '$@' | tar xf - -C '$backup2';
3962                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
3963         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
3964
3965         do_node $node "diff -rq $backup $backup2"
3966         [ $? -eq 0 ] || { error "contents differ"; return 3; }
3967
3968         local xattrs2=${TMP}/xattrs2
3969         do_node $node 'getfattr -d -m "[a-z]*\\." '$@' > '$xattrs2
3970         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
3971
3972         do_node $node "diff $xattrs $xattrs2"
3973         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
3974
3975         do_node $node "rm -rf $backup2 $xattrs2"
3976         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
3977 }
3978
3979 test_52() {
3980         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
3981                 skip "ldiskfs only test"
3982         fi
3983
3984         start_mds || error "Unable to start MDS"
3985         start_ost || error "Unable to start OST1"
3986         mount_client $MOUNT || error "Unable to mount client"
3987
3988         local nrfiles=8
3989         local ost1mnt=$(facet_mntpt ost1)
3990         local ost1node=$(facet_active_host ost1)
3991         local ost1tmp=$TMP/conf52
3992         local loop
3993
3994         mkdir $DIR/$tdir || error "Unable to create $DIR/$tdir"
3995         touch $TMP/modified_first || error "Unable to create temporary file"
3996         local mtime=$(stat -c %Y $TMP/modified_first)
3997         do_node $ost1node "mkdir -p $ost1tmp &&
3998                            touch -m -d @$mtime $ost1tmp/modified_first" ||
3999                 error "Unable to create temporary file"
4000         sleep 1
4001
4002         $LFS setstripe -c -1 -S 1M $DIR/$tdir || error "$LFS setstripe failed"
4003
4004         for (( i=0; i < nrfiles; i++ )); do
4005                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c ||
4006                         error "multiop failed"
4007                 echo -n .
4008         done
4009         echo
4010
4011         # sync all the data and make sure no pending data on the client,
4012         # thus the SOM xattr would not be changed any more.
4013         cancel_lru_locks osc
4014
4015         # backup files
4016         echo backup files to $TMP/$tdir
4017         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
4018         copy_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
4019                 error "Unable to copy files"
4020
4021         umount_client $MOUNT || error "Unable to umount client"
4022         stop_ost || error "Unable to stop ost1"
4023
4024         echo mount ost1 as ldiskfs
4025         do_node $ost1node mkdir -p $ost1mnt || error "Unable to create $ost1mnt"
4026         if ! do_node $ost1node test -b $ost1_dev; then
4027                 loop="-o loop"
4028         fi
4029         do_node $ost1node mount -t $(facet_fstype ost1) $loop $ost1_dev \
4030                 $ost1mnt ||
4031                 error "Unable to mount ost1 as ldiskfs"
4032
4033         # backup objects
4034         echo backup objects to $ost1tmp/objects
4035         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
4036                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
4037         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
4038                         $objects ||
4039                 error "Unable to copy objects"
4040
4041         # move objects to lost+found
4042         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
4043         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
4044
4045         do_node $ost1node "umount $ost1mnt" ||
4046                 error "Unable to umount ost1 as ldiskfs"
4047
4048         start_ost || error "Unable to start OST1"
4049         mount_client $MOUNT || error "Unable to mount client"
4050
4051         local REPAIRED=$(do_node $ost1node "$LCTL get_param \
4052                          -n osd-ldiskfs.$FSNAME-OST0000.oi_scrub" |
4053                          awk '/^lf_repa[ri]*ed/ { print $2 }')
4054         [ $REPAIRED -gt 0 ] ||
4055                 error "Some entry under /lost+found should be repaired"
4056
4057         # compare files
4058         diff_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
4059                 error "Unable to diff files"
4060
4061         rm -rf $TMP/$tdir $TMP/file_xattrs ||
4062                 error "Unable to delete temporary files"
4063         do_node $ost1node "rm -rf $ost1tmp" ||
4064                 error "Unable to delete temporary files"
4065         cleanup || error "cleanup failed with $?"
4066 }
4067 run_test 52 "check recovering objects from lost+found"
4068
4069 # Checks threads_min/max/started for some service
4070 #
4071 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
4072 # parameter pattern prefix like 'ost.*.ost'.
4073 thread_sanity() {
4074         local modname=$1
4075         local facet=$2
4076         local parampat=$3
4077         local opts=$4
4078         local basethr=$5
4079         local tmin
4080         local tmin2
4081         local tmax
4082         local tmax2
4083         local tstarted
4084         local paramp
4085         local msg="Insane $modname thread counts"
4086         local ncpts=$(check_cpt_number $facet)
4087         local nthrs
4088         shift 4
4089
4090         check_mount || return 41
4091
4092         # We need to expand $parampat, but it may match multiple parameters, so
4093         # we'll pick the first one
4094         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
4095                 error "Couldn't expand ${parampat}.threads_min parameter name"
4096                 return 22
4097         fi
4098
4099         # Remove the .threads_min part
4100         paramp=${paramp%.threads_min}
4101
4102         # Check for sanity in defaults
4103         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4104                echo 0)
4105         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4106                echo 0)
4107         tstarted=$(do_facet $facet "$LCTL get_param \
4108                                     -n ${paramp}.threads_started" || echo 0)
4109         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' ||
4110                 return $?
4111         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
4112                 return $?
4113         nthrs=$(expr $tmax - $tmin)
4114         if [ $nthrs -lt $ncpts ]; then
4115                 nthrs=0
4116         else
4117                 nthrs=$ncpts
4118         fi
4119
4120         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
4121                 skip_env "module parameter forced $facet thread count"
4122
4123         # Check that we can change min/max
4124         do_facet $facet "$LCTL set_param \
4125                          ${paramp}.threads_min=$((tmin + nthrs))"
4126         do_facet $facet "$LCTL set_param \
4127                          ${paramp}.threads_max=$((tmax - nthrs))"
4128         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4129                 echo 0)
4130         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4131                 echo 0)
4132         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) &&
4133                             $tmax2 == ($tmax - $nthrs)))' || return $?
4134
4135         # Check that we can set min/max to the same value
4136         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4137                echo 0)
4138         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$tmin"
4139         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4140                 echo 0)
4141         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4142                 echo 0)
4143         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
4144
4145         # Check that we can't set max < min
4146         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$((tmin - 1))"
4147         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4148                 echo 0)
4149         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4150                 echo 0)
4151         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
4152
4153         # We need to ensure that we get the module options desired; to do this
4154         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
4155         LOAD_MODULES_REMOTE=true
4156         cleanup
4157         local oldvalue
4158         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
4159         setmodopts -a $modname "$newvalue" oldvalue
4160
4161         setup
4162         check_mount || return 41
4163
4164         # Restore previous setting of MODOPTS_*
4165         setmodopts $modname "$oldvalue"
4166
4167         # Check that $opts took
4168         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
4169                 echo 0)
4170         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
4171                 echo 0)
4172         tstarted=$(do_facet $facet \
4173                    "$LCTL get_param -n ${paramp}.threads_started" || echo 0)
4174         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
4175                 return $?
4176         cleanup
4177
4178         setup
4179 }
4180
4181 test_53a() {
4182         setup
4183         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
4184         cleanup || error "cleanup failed with rc $?"
4185 }
4186 run_test 53a "check OSS thread count params"
4187
4188 test_53b() {
4189         setup
4190         local mds=$(do_facet $SINGLEMDS "$LCTL get_param \
4191                                          -N mds.*.*.threads_max 2>/dev/null")
4192         if [ -z "$mds" ]; then
4193                 #running this on an old MDT
4194                 thread_sanity MDT $SINGLEMDS 'mdt.*.*.' 'mdt_num_threads' 16
4195         else
4196                 thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
4197         fi
4198         cleanup || error "cleanup failed with $?"
4199 }
4200 run_test 53b "check MDS thread count params"
4201
4202 test_54a() {
4203         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4204                 skip "ldiskfs only test"
4205         fi
4206
4207         do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p ||
4208                 error "llverdev failed with rc=$?"
4209         reformat_and_config
4210 }
4211 run_test 54a "test llverdev and partial verify of device"
4212
4213 test_54b() {
4214         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4215                 skip "ldiskfs only test"
4216         fi
4217
4218         setup
4219         run_llverfs $MOUNT -p || error "llverfs failed with rc=$?"
4220         cleanup || error "cleanup failed with rc=$?"
4221 }
4222 run_test 54b "test llverfs and partial verify of filesystem"
4223
4224 lov_objid_size()
4225 {
4226         local max_ost_index=$1
4227         echo -n $(((max_ost_index + 1) * 8))
4228 }
4229
4230 test_55() {
4231         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4232                 skip "ldiskfs only test"
4233         fi
4234
4235         local mdsdev=$(mdsdevname 1)
4236         local mdsvdev=$(mdsvdevname 1)
4237
4238         for i in 1023 2048
4239         do
4240                 if ! combined_mgs_mds; then
4241                         stop_mgs || error "stopping MGS service failed"
4242                         format_mgs || error "formatting MGT failed"
4243                 fi
4244                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
4245                         $mdsvdev || exit 10
4246                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
4247                         --reformat $(ostdevname 1) $(ostvdevname 1)
4248                 setup_noconfig
4249                 stopall
4250                 setup_noconfig
4251                 sync
4252
4253                 echo checking size of lov_objid for ost index $i
4254                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" |
4255                                  grep ^User | awk -F 'Size: ' '{print $2}')
4256                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
4257                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
4258                 else
4259                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
4260                 fi
4261                 stopall
4262         done
4263
4264         reformat
4265 }
4266 run_test 55 "check lov_objid size"
4267
4268 test_56a() {
4269         local server_version=$(lustre_version_code $SINGLEMDS)
4270         local mds_journal_size_orig=$MDSJOURNALSIZE
4271         local n
4272
4273         MDSJOURNALSIZE=16
4274
4275         formatall
4276         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
4277                 $(ostdevname 1) $(ostvdevname 1)
4278         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \
4279                 $(ostdevname 2) $(ostvdevname 2)
4280
4281         start_mgsmds
4282         start_ost || error "Unable to start first ost (idx 10000)"
4283         start_ost2 || error "Unable to start second ost (idx 1000)"
4284         mount_client $MOUNT || error "Unable to mount client"
4285         echo ok
4286         $LFS osts
4287
4288         if [[ $server_version -ge $(version_code 2.6.54) ]] ||
4289            [[ $server_version -ge $(version_code 2.5.4) &&
4290               $server_version -lt $(version_code 2.5.11) ]]; then
4291                 wait_osc_import_state mds ost1 FULL
4292                 wait_osc_import_state mds ost2 FULL
4293                 $LFS setstripe --stripe-count=-1 $DIR/$tfile ||
4294                         error "Unable to setstripe $DIR/$tfile"
4295                 n=$($LFS getstripe --stripe-count $DIR/$tfile)
4296                 [ "$n" -eq 2 ] || error "Stripe count not two: $n"
4297                 rm $DIR/$tfile
4298         fi
4299
4300         stopall
4301         MDSJOURNALSIZE=$mds_journal_size_orig
4302         reformat
4303 }
4304 run_test 56a "check big OST indexes and out-of-index-order start"
4305
4306 cleanup_56b() {
4307         trap 0
4308
4309         umount_client $MOUNT -f || error "unmount client failed"
4310         stop mds1
4311         stop mds2
4312         stop mds3
4313         stopall
4314         reformat
4315 }
4316
4317 test_56b() {
4318         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs"
4319
4320         trap cleanup_56b EXIT RETURN ERR
4321         stopall
4322
4323         if ! combined_mgs_mds ; then
4324                 format_mgs
4325                 start_mgs
4326         fi
4327
4328         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
4329                 $(mdsdevname 1) $(mdsvdevname 1)
4330         add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
4331                 $(mdsdevname 2) $(mdsvdevname 2)
4332         add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=1000 --reformat \
4333                 $(mdsdevname 3) $(mdsvdevname 3)
4334         format_ost 1
4335         format_ost 2
4336
4337         start_mdt 1 || error "MDT 1 (idx 0) start failed"
4338         start_mdt 2 || error "MDT 2 (idx 1) start failed"
4339         start_mdt 3 || error "MDT 3 (idx 1000) start failed"
4340         start_ost || error "Unable to start first ost"
4341         start_ost2 || error "Unable to start second ost"
4342
4343         do_nodes $(comma_list $(mdts_nodes)) \
4344                 "$LCTL set_param mdt.*.enable_remote_dir=1 \
4345                 mdt.*.enable_remote_dir_gid=-1"
4346
4347         mount_client $MOUNT || error "Unable to mount client"
4348
4349         $LFS mkdir -c3 $MOUNT/$tdir || error "failed to make testdir"
4350
4351         echo "This is test file 1!" > $MOUNT/$tdir/$tfile.1 ||
4352                 error "failed to make test file 1"
4353         echo "This is test file 2!" > $MOUNT/$tdir/$tfile.2 ||
4354                 error "failed to make test file 2"
4355         echo "This is test file 1000!" > $MOUNT/$tdir/$tfile.1000 ||
4356                 error "failed to make test file 1000"
4357
4358         rm -rf $MOUNT/$tdir || error "failed to remove testdir"
4359
4360         $LFS mkdir -i1000 $MOUNT/$tdir.1000 ||
4361                 error "create remote dir at idx 1000 failed"
4362
4363         output=$($LFS df)
4364         echo "=== START lfs df OUTPUT ==="
4365         echo -e "$output"
4366         echo "==== END lfs df OUTPUT ===="
4367
4368         mdtcnt=$(echo -e "$output" | grep $FSNAME-MDT | wc -l)
4369         ostcnt=$(echo -e "$output" | grep $FSNAME-OST | wc -l)
4370
4371         echo "lfs df returned mdt count $mdtcnt and ost count $ostcnt"
4372         [ $mdtcnt -eq 3 ] || error "lfs df returned wrong mdt count"
4373         [ $ostcnt -eq 2 ] || error "lfs df returned wrong ost count"
4374
4375         echo "This is test file 1!" > $MOUNT/$tdir.1000/$tfile.1 ||
4376                 error "failed to make test file 1"
4377         echo "This is test file 2!" > $MOUNT/$tdir.1000/$tfile.2 ||
4378                 error "failed to make test file 2"
4379         echo "This is test file 1000!" > $MOUNT/$tdir.1000/$tfile.1000 ||
4380                 error "failed to make test file 1000"
4381         rm -rf $MOUNT/$tdir.1000 || error "failed to remove remote_dir"
4382
4383         output=$($LFS mdts)
4384         echo "=== START lfs mdts OUTPUT ==="
4385         echo -e "$output"
4386         echo "==== END lfs mdts OUTPUT ===="
4387
4388         echo -e "$output" | grep -v "MDTS:" | awk '{print $1}' |
4389                 sed 's/://g' > $TMP/mdts-actual.txt
4390         sort $TMP/mdts-actual.txt -o $TMP/mdts-actual.txt
4391
4392         echo -e "0\n1\n1000" > $TMP/mdts-expected.txt
4393
4394         diff $TMP/mdts-expected.txt $TMP/mdts-actual.txt
4395         result=$?
4396
4397         rm $TMP/mdts-expected.txt $TMP/mdts-actual.txt
4398
4399         [ $result -eq 0 ] || error "target_obd proc file is incorrect!"
4400 }
4401 run_test 56b "test target_obd correctness with nonconsecutive MDTs"
4402
4403 test_57a() { # bug 22656
4404         do_rpc_nodes $(facet_active_host ost1) load_modules_local
4405         local NID=$(do_facet ost1 "$LCTL get_param nis" |
4406                     tail -1 | awk '{print $1}')
4407         writeconf_or_reformat
4408         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4409         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" ||
4410                 error "tunefs failed"
4411         start_mgsmds
4412         start_ost && error "OST registration from failnode should fail"
4413         reformat
4414 }
4415 run_test 57a "initial registration from failnode should fail (should return errs)"
4416
4417 test_57b() {
4418         do_rpc_nodes $(facet_active_host ost1) load_modules_local
4419         local NID=$(do_facet ost1 "$LCTL get_param nis" |
4420                     tail -1 | awk '{print $1}')
4421         writeconf_or_reformat
4422         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
4423         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" ||
4424                 error "tunefs failed"
4425         start_mgsmds
4426         start_ost || error "OST registration from servicenode should not fail"
4427         reformat
4428 }
4429 run_test 57b "initial registration from servicenode should not fail"
4430
4431 count_osts() {
4432         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
4433 }
4434
4435 test_58() { # bug 22658
4436         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
4437         setup_noconfig
4438         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4439         createmany -o $DIR/$tdir/$tfile-%d 100
4440         unlinkmany $DIR/$tdir/$tfile-%d 100
4441         stop_mds || error "Unable to stop MDS"
4442
4443         local MNTDIR=$(facet_mntpt $SINGLEMDS)
4444         local devname=$(mdsdevname ${SINGLEMDS//mds/})
4445
4446         # remove all files from the OBJECTS dir
4447         mount_fstype $SINGLEMDS
4448
4449         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
4450
4451         unmount_fstype $SINGLEMDS
4452         # restart MDS with missing llog files
4453         start_mds || error "unable to start MDS"
4454         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
4455         reformat
4456 }
4457 run_test 58 "missing llog files must not prevent MDT from mounting"
4458
4459 test_59() {
4460         start_mgsmds >> /dev/null
4461         local C1=$(count_osts)
4462         if [ $C1 -eq 0 ]; then
4463                 start_ost >> /dev/null
4464                 C1=$(count_osts)
4465         fi
4466         stopall
4467         echo "original ost count: $C1 (expect > 0)"
4468         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
4469         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
4470         local C2=$(count_osts)
4471         echo "after mdt writeconf count: $C2 (expect 0)"
4472         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
4473         echo "OST start without writeconf should fail:"
4474         start_ost >> /dev/null &&
4475                 error "OST start without writeconf didn't fail"
4476         echo "OST start with writeconf should succeed:"
4477         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
4478         local C3=$(count_osts)
4479         echo "after ost writeconf count: $C3 (expect 1)"
4480         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
4481         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
4482         local C4=$(count_osts)
4483         echo "after ost2 writeconf count: $C4 (expect 2)"
4484         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
4485         stop_ost2 >> /dev/null
4486         cleanup_nocli >> /dev/null
4487         #writeconf to remove all ost2 traces for subsequent tests
4488         writeconf_or_reformat
4489 }
4490 run_test 59 "writeconf mount option"
4491
4492 test_60() { # LU-471
4493         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4494                 skip "ldiskfs only test"
4495         fi
4496
4497         local num
4498
4499         for num in $(seq $MDSCOUNT); do
4500                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
4501                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
4502                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
4503                         exit 10
4504         done
4505
4506         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
4507         [ ${PIPESTATUS[0]} -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
4508
4509         # MDT default has dirdata feature
4510         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
4511         # we disable uninit_bg feature
4512         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
4513         # we set stride extended options
4514         echo $dump | grep stride > /dev/null || error "stride is not set"
4515         reformat
4516 }
4517 run_test 60 "check mkfs.lustre --mkfsoptions -E -O options setting"
4518
4519 test_61() { # LU-80
4520         local lxattr=false
4521
4522         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.1.53) ] ||
4523                 skip "Need MDS version at least 2.1.53"
4524
4525         if [ $(facet_fstype $SINGLEMDS) == ldiskfs ] &&
4526              ! large_xattr_enabled; then
4527                 lxattr=true
4528
4529                 for num in $(seq $MDSCOUNT); do
4530                         do_facet mds${num} $TUNE2FS -O ea_inode \
4531                                 $(mdsdevname $num) ||
4532                                 error "tune2fs on mds $num failed"
4533                 done
4534         fi
4535
4536         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
4537         setup_noconfig || error "setting up the filesystem failed"
4538         client_up || error "starting client failed"
4539
4540         local file=$DIR/$tfile
4541         touch $file || error "touch $file failed"
4542
4543         local large_value="$(generate_string $(max_xattr_size))"
4544         local small_value="bar"
4545
4546         local name="trusted.big"
4547         log "save large xattr $name on $file"
4548         setfattr -n $name -v $large_value $file ||
4549                 error "saving $name on $file failed"
4550
4551         local new_value=$(get_xattr_value $name $file)
4552         [[ "$new_value" != "$large_value" ]] &&
4553                 error "$name different after saving"
4554
4555         log "shrink value of $name on $file"
4556         setfattr -n $name -v $small_value $file ||
4557                 error "shrinking value of $name on $file failed"
4558
4559         new_value=$(get_xattr_value $name $file)
4560         [[ "$new_value" != "$small_value" ]] &&
4561                 error "$name different after shrinking"
4562
4563         log "grow value of $name on $file"
4564         setfattr -n $name -v $large_value $file ||
4565                 error "growing value of $name on $file failed"
4566
4567         new_value=$(get_xattr_value $name $file)
4568         [[ "$new_value" != "$large_value" ]] &&
4569                 error "$name different after growing"
4570
4571         log "check value of $name on $file after remounting MDS"
4572         fail $SINGLEMDS
4573         new_value=$(get_xattr_value $name $file)
4574         [[ "$new_value" != "$large_value" ]] &&
4575                 error "$name different after remounting MDS"
4576
4577         log "remove large xattr $name from $file"
4578         setfattr -x $name $file || error "removing $name from $file failed"
4579
4580         if $lxattr; then
4581                 stopall || error "stopping for e2fsck run"
4582                 for num in $(seq $MDSCOUNT); do
4583                         run_e2fsck $(facet_active_host mds$num) \
4584                                 $(mdsdevname $num) "-y" ||
4585                                 error "e2fsck MDT$num failed"
4586                 done
4587                 setup_noconfig || error "remounting the filesystem failed"
4588         fi
4589
4590         # need to delete this file to avoid problems in other tests
4591         rm -f $file
4592         stopall || error "stopping systems failed"
4593 }
4594 run_test 61 "large xattr"
4595
4596 test_62() {
4597         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4598                 skip "ldiskfs only test"
4599         fi
4600         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.2.51) ]] ||
4601                 skip "Need MDS version at least 2.2.51"
4602
4603         # MRP-118
4604         local mdsdev=$(mdsdevname 1)
4605         local ostdev=$(ostdevname 1)
4606
4607         echo "disable journal for mds"
4608         do_facet mds1 $TUNE2FS -O ^has_journal $mdsdev || error "tune2fs failed"
4609         start_mds && error "MDT start should fail"
4610         echo "disable journal for ost"
4611         do_facet ost1 $TUNE2FS -O ^has_journal $ostdev || error "tune2fs failed"
4612         start_ost && error "OST start should fail"
4613         cleanup || error "cleanup failed with rc $?"
4614         reformat_and_config
4615 }
4616 run_test 62 "start with disabled journal"
4617
4618 test_63() {
4619         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
4620                 skip "ldiskfs only test"
4621         fi
4622
4623         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_module ldiskfs
4624         local inode_slab=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
4625                            awk '/ldiskfs_inode_cache/ { print $5 / $6 }')
4626         if [ -z "$inode_slab" ]; then
4627                 skip "ldiskfs module has not been loaded"
4628         fi
4629
4630         echo "$inode_slab ldiskfs inodes per page"
4631         [ "${inode_slab%.*}" -ge "3" ] && return 0
4632
4633         # If kmalloc-128 is also 1 per page - this is a debug kernel
4634         # and so this is not an error.
4635         local kmalloc128=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
4636                            awk '/^(dma-kmalloc|size)-128 / { print $5 / $6 }')
4637         # 32 128-byte chunks in 4k
4638         [ "${kmalloc128%.*}" -lt "32" ] ||
4639                 error "ldiskfs inode too big, only $inode_slab objs/page, " \
4640                       "kmalloc128 = $kmalloc128 objs/page"
4641 }
4642 run_test 63 "Verify each page can at least hold 3 ldiskfs inodes"
4643
4644 test_64() {
4645         start_mds || error "unable to start MDS"
4646         start_ost || error "Unable to start OST1"
4647         start_ost2 || error "Unable to start second ost"
4648         mount_client $MOUNT || error "Unable to mount client"
4649         stop_ost2 || error "Unable to stop second ost"
4650         echo "$LFS df"
4651         $LFS df --lazy
4652         umount_client $MOUNT -f || error “unmount $MOUNT failed”
4653         cleanup_nocli || error "cleanup_nocli failed with $?"
4654         #writeconf to remove all ost2 traces for subsequent tests
4655         writeconf_or_reformat
4656 }
4657 run_test 64 "check lfs df --lazy "
4658
4659 test_65() { # LU-2237
4660         # Currently, the test is only valid for ldiskfs backend
4661         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
4662                 skip "ldiskfs only test"
4663
4664         local devname=$(mdsdevname ${SINGLEMDS//mds/})
4665         local brpt=$(facet_mntpt brpt)
4666         local opts=""
4667
4668         if ! do_facet $SINGLEMDS "test -b $devname"; then
4669                 opts="-o loop"
4670         fi
4671
4672         stop_mds || error "Unable to stop MDS"
4673         local obj=$(do_facet $SINGLEMDS \
4674                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
4675                     grep Inode)
4676         if [ -z "$obj" ]; then
4677                 # The MDT may be just re-formatted, mount the MDT for the
4678                 # first time to guarantee the "last_rcvd" file is there.
4679                 start_mds || error "fail to mount the MDS for the first time"
4680                 stop_mds || error "Unable to stop MDS"
4681         fi
4682
4683         # remove the "last_rcvd" file
4684         do_facet $SINGLEMDS "mkdir -p $brpt"
4685         do_facet $SINGLEMDS \
4686                 "mount -t $(facet_fstype $SINGLEMDS) $opts $devname $brpt"
4687         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
4688         do_facet $SINGLEMDS "$UMOUNT $brpt"
4689
4690         # restart MDS, the "last_rcvd" file should be recreated.
4691         start_mds || error "fail to restart the MDS"
4692         stop_mds || error "Unable to stop MDS"
4693         obj=$(do_facet $SINGLEMDS \
4694               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
4695         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
4696 }
4697 run_test 65 "re-create the lost last_rcvd file when server mount"
4698
4699 test_66() {
4700         [[ $(lustre_version_code mgs) -ge $(version_code 2.3.59) ]] ||
4701                 skip "Need MGS version at least 2.3.59"
4702
4703         setup
4704         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
4705         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
4706
4707         # add EXCLUDE records to config log, they are not to be
4708         # removed by lctl replace_nids
4709         set_conf_param_and_check mds                                    \
4710             "$LCTL get_param -n osc.$FSNAME-OST0000-osc-MDT0000.active" \
4711             "$FSNAME-OST0000.osc.active"                                \
4712             "0"
4713
4714         echo "replace_nids should fail if MDS, OSTs and clients are UP"
4715         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4716                 error "replace_nids fail"
4717
4718         umount_client $MOUNT || error "unmounting client failed"
4719         echo "replace_nids should fail if MDS and OSTs are UP"
4720         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4721                 error "replace_nids fail"
4722
4723         stop_ost || error "Unable to stop OST1"
4724         echo "replace_nids should fail if MDS is UP"
4725         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4726                 error "replace_nids fail"
4727
4728         stop_mds || error "stopping mds failed"
4729
4730         if combined_mgs_mds; then
4731                 start_mdt 1 "-o nosvc" ||
4732                         error "starting mds with nosvc option failed"
4733         fi
4734
4735         echo "command should accept two parameters"
4736         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
4737                 error "command should accept two params"
4738
4739         echo "correct device name should be passed"
4740         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
4741                 error "wrong devname"
4742
4743         echo "wrong nids list should not destroy the system"
4744         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
4745                 error "wrong parse"
4746         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "asdfasdf, asdfadf" &&
4747                 error "wrong parse"
4748
4749         echo "replace OST nid"
4750         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
4751                 error "replace nids failed"
4752
4753         echo "command should accept two parameters"
4754         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
4755                 error "command should accept two params"
4756
4757         echo "wrong nids list should not destroy the system"
4758         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
4759                 error "wrong parse"
4760
4761         local FAKE_NIDS="192.168.0.112@tcp1,192.168.0.112@tcp2"
4762         local FAKE_FAILOVER="192.168.0.113@tcp1,192.168.0.113@tcp2"
4763         local NIDS_AND_FAILOVER="$MDS_NID,$FAKE_NIDS:$FAKE_FAILOVER"
4764         echo "set NIDs with failover"
4765         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $NIDS_AND_FAILOVER ||
4766                 error "replace nids failed"
4767
4768
4769         echo "replace MDS nid"
4770         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
4771                 error "replace nids failed"
4772
4773         if ! combined_mgs_mds ; then
4774                 stop_mgs
4775         else
4776                 stop_mds || error "Unable to stop MDS"
4777         fi
4778
4779         start_mgsmds || error "start mgsmds failed"
4780         set_conf_param_and_check mds                                    \
4781             "$LCTL get_param -n osc.$FSNAME-OST0000-osc-MDT0000.active" \
4782             "$FSNAME-OST0000.osc.active"                                \
4783             "1"
4784         start_ost || error "unable to start OST"
4785         mount_client $MOUNT || error "mount client failed"
4786
4787         check_mount || error "error after nid replace"
4788         cleanup || error "cleanup failed"
4789         reformat
4790 }
4791 run_test 66 "replace nids"
4792
4793 test_67() { #LU-2950
4794         local legacy="$TMP/legacy_lnet_config"
4795         local new="$TMP/new_routes_test"
4796         local out="$TMP/config_out_file"
4797         local verify="$TMP/conv_verify"
4798         local verify_conf="$TMP/conf_verify"
4799
4800         # Create the legacy file that will be run through the
4801         # lustre_routes_conversion script
4802         cat <<- LEGACY_LNET_CONFIG > $legacy
4803                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
4804                 tcp2 54 10.1.3.2@tcp;
4805                 tcp3 10.3.4.3@tcp:3;
4806                 tcp4 10.3.3.4@tcp;
4807         LEGACY_LNET_CONFIG
4808
4809         # Create the verification file to verify the output of
4810         # lustre_routes_conversion script against.
4811         cat <<- VERIFY_LNET_CONFIG > $verify
4812                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
4813                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
4814                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
4815                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
4816                 tcp4: { gateway: 10.3.3.4@tcp }
4817         VERIFY_LNET_CONFIG
4818
4819         # Create the verification file to verify the output of
4820         # lustre_routes_config script against
4821         cat <<- VERIFY_LNET_CONFIG > $verify_conf
4822                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
4823                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
4824                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
4825                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
4826                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
4827         VERIFY_LNET_CONFIG
4828
4829         $LUSTRE_ROUTES_CONVERSION $legacy $new > /dev/null
4830         if [ -f $new ]; then
4831                 # verify the conversion output
4832                 cmp -s $new $verify > /dev/null
4833                 if [ $? -eq 1 ]; then
4834                         error "routes conversion failed"
4835                 fi
4836
4837                 lustre_routes_config --dry-run --verbose $new > $out
4838                 # check that the script succeeded
4839                 cmp -s $out $verify_conf > /dev/null
4840                 if [ $? -eq 1 ]; then
4841                         error "routes config failed"
4842                 fi
4843         else
4844                 error "routes conversion test failed"
4845         fi
4846         # remove generated files
4847         rm -f $new $legacy $verify $verify_conf $out
4848 }
4849 run_test 67 "test routes conversion and configuration"
4850
4851 test_68() {
4852         local fid
4853         local seq
4854         local START
4855         local END
4856
4857         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.4.53) ] ||
4858                 skip "Need MDS version at least 2.4.53"
4859
4860         umount_client $MOUNT || error "umount client failed"
4861
4862         if ! combined_mgs_mds; then
4863                 start_mgs || error "start mgs failed"
4864         fi
4865
4866         start_mdt 1 || error "MDT start failed"
4867         start_ost || error "Unable to start OST1"
4868
4869         # START-END - the sequences we'll be reserving
4870         START=$(do_facet $SINGLEMDS \
4871                 $LCTL get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4872         END=$((START + (1 << 30)))
4873         do_facet $SINGLEMDS \
4874                 $LCTL set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4875
4876         # reset the sequences MDT0000 has already assigned
4877         do_facet $SINGLEMDS \
4878                 $LCTL set_param seq.srv*MDT0000.space=clear
4879
4880         # remount to let the client allocate new sequence
4881         mount_client $MOUNT || error "mount client failed"
4882
4883         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4884         do_facet $SINGLEMDS \
4885                 $LCTL get_param seq.srv*MDT0000.space
4886         $LFS path2fid $DIR/$tfile
4887
4888         local old_ifs="$IFS"
4889         IFS='[:]'
4890         fid=($($LFS path2fid $DIR/$tfile))
4891         IFS="$old_ifs"
4892         let seq=${fid[1]}
4893
4894         if [[ $seq < $END ]]; then
4895                 error "used reserved sequence $seq?"
4896         fi
4897         cleanup || error "cleanup failed with $?"
4898 }
4899 run_test 68 "be able to reserve specific sequences in FLDB"
4900
4901 # Test 69: is about the total number of objects ever created on an OST.
4902 # so that when it is reformatted the normal MDS->OST orphan recovery won't
4903 # just "precreate" the missing objects. In the past it might try to recreate
4904 # millions of objects after an OST was reformatted
4905 test_69() {
4906         local server_version=$(lustre_version_code $SINGLEMDS)
4907
4908         [[ $server_version -lt $(version_code 2.4.2) ]] &&
4909                 skip "Need MDS version at least 2.4.2"
4910
4911         [[ $server_version -ge $(version_code 2.4.50) ]] &&
4912         [[ $server_version -lt $(version_code 2.5.0) ]] &&
4913                 skip "Need MDS version at least 2.5.0"
4914
4915         setup
4916         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4917
4918         # use OST0000 since it probably has the most creations
4919         local OSTNAME=$(ostname_from_index 0)
4920         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4921         local last_id=$(do_facet mds1 $LCTL get_param -n \
4922                         osc.$mdtosc_proc1.prealloc_last_id)
4923
4924         # Want to have OST LAST_ID over 5 * OST_MAX_PRECREATE to
4925         # verify that the LAST_ID recovery is working properly. If
4926         # not, then the OST will refuse to allow the MDS connect
4927         # because the LAST_ID value is too different from the MDS
4928         #define OST_MAX_PRECREATE=20000
4929         local ost_max_pre=20000
4930         local num_create=$(( ost_max_pre * 5 + 1 - last_id))
4931
4932         # If the LAST_ID is already over 5 * OST_MAX_PRECREATE, we don't
4933         # need to create any files. So, skip this section.
4934         if [ $num_create -gt 0 ]; then
4935                 # Check the number of inodes available on OST0
4936                 local files=0
4937                 local ifree=$($LFS df -i $MOUNT | awk '/OST0000/ { print $4 }')
4938                 log "On OST0, $ifree inodes available. Want $num_create."
4939
4940                 $LFS setstripe -i 0 $DIR/$tdir ||
4941                         error "$LFS setstripe -i 0 $DIR/$tdir failed"
4942                 if [ $ifree -lt 10000 ]; then
4943                         files=$(( ifree - 50 ))
4944                 else
4945                         files=10000
4946                 fi
4947
4948                 local j=$((num_create / files + 1))
4949                 for i in $(seq 1 $j); do
4950                         createmany -o $DIR/$tdir/$tfile-$i- $files ||
4951                                 error "createmany fail create $files files: $?"
4952                         unlinkmany $DIR/$tdir/$tfile-$i- $files ||
4953                                 error "unlinkmany failed unlink $files files"
4954                 done
4955         fi
4956
4957         # delete all of the files with objects on OST0 so the
4958         # filesystem is not inconsistent later on
4959         $LFS find $MOUNT --ost 0 -print0 | xargs -0 rm
4960
4961         umount_client $MOUNT || error "umount client failed"
4962         stop_ost || error "OST0 stop failure"
4963         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
4964                 $(ostdevname 1) $(ostvdevname 1) ||
4965                 error "reformat and replace $ostdev failed"
4966         start_ost || error "OST0 restart failure"
4967         wait_osc_import_state mds ost FULL
4968
4969         mount_client $MOUNT || error "mount client failed"
4970         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
4971         local idx=$($LFS getstripe -i $DIR/$tdir/$tfile-last)
4972         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
4973
4974         local iused=$($LFS df -i $MOUNT | awk '/OST0000/ { print $3 }')
4975         log "On OST0, $iused used inodes"
4976         [ $iused -ge $((ost_max_pre/2 + 1000)) ] &&
4977                 error "OST replacement created too many inodes; $iused"
4978         cleanup || error "cleanup failed with $?"
4979 }
4980 run_test 69 "replace an OST with the same index"
4981
4982 test_70a() {
4983         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
4984         local MDTIDX=1
4985
4986         cleanup || error "cleanup failed with $?"
4987
4988         start_mdt 1 || error "MDT0 start fail"
4989
4990         start_ost || error "OST0 start fail"
4991         for num in $(seq 2 $MDSCOUNT); do
4992                 start_mdt $num || return
4993         done
4994
4995         mount_client $MOUNT || error "mount client fails"
4996
4997         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
4998
4999         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5000                 error "create remote dir fail"
5001
5002         rm -rf $DIR/$tdir || error "delete dir fail"
5003         cleanup || error "cleanup failed with $?"
5004 }
5005 run_test 70a "start MDT0, then OST, then MDT1"
5006
5007 test_70b() {
5008         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5009         local MDTIDX=1
5010
5011         start_ost || error "OST0 start fail"
5012
5013         start_mds || error "MDS start fail"
5014
5015         mount_client $MOUNT || error "mount client fails"
5016
5017         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
5018
5019         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5020                 error "create remote dir fail"
5021
5022         rm -rf $DIR/$tdir || error "delete dir fail"
5023
5024         cleanup || error "cleanup failed with $?"
5025 }
5026 run_test 70b "start OST, MDT1, MDT0"
5027
5028 test_70c() {
5029         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5030         local MDTIDX=1
5031
5032         start_mds || error "MDS start fail"
5033         start_ost || error "OST0 start fail"
5034
5035         mount_client $MOUNT || error "mount client fails"
5036         stop_mdt 1 || error "MDT1 start fail"
5037
5038         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
5039         echo "deactivate $mdc_for_mdt1"
5040         $LCTL --device $mdc_for_mdt1 deactivate ||
5041                 error "set $mdc_for_mdt1 deactivate failed"
5042
5043         mkdir $DIR/$tdir && error "mkdir succeed"
5044
5045         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
5046                 error "create remote dir succeed"
5047
5048         cleanup || error "cleanup failed with $?"
5049 }
5050 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
5051
5052 test_70d() {
5053         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5054         local MDTIDX=1
5055
5056         start_mds || error "MDS start fail"
5057         start_ost || error "OST0 start fail"
5058
5059         mount_client $MOUNT || error "mount client fails"
5060
5061         stop_mdt 2 || error "MDT1 start fail"
5062
5063         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
5064                              awk '{print $4}')
5065         echo "deactivate $mdc_for_mdt2"
5066         $LCTL --device $mdc_for_mdt2 deactivate ||
5067                 error "set $mdc_for_mdt2 deactivate failed"
5068
5069         mkdir $DIR/$tdir || error "mkdir fail"
5070         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
5071                 error "create remote dir succeed"
5072
5073         rm -rf $DIR/$tdir || error "delete dir fail"
5074
5075         cleanup || error "cleanup failed with $?"
5076 }
5077 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
5078
5079 test_70e() {
5080         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5081
5082         [ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.62) ] ||
5083                 skip "Need MDS version at least 2.7.62"
5084
5085         cleanup || error "cleanup failed with $?"
5086
5087         local mdsdev=$(mdsdevname 1)
5088         local ostdev=$(ostdevname 1)
5089         local mdsvdev=$(mdsvdevname 1)
5090         local ostvdev=$(ostvdevname 1)
5091         local opts_mds="$(mkfs_opts mds1 $mdsdev) --reformat $mdsdev $mdsvdev"
5092         local opts_ost="$(mkfs_opts ost1 $ostdev) --reformat $ostdev $ostvdev"
5093
5094         add mds1 $opts_mds || error "add mds1 failed"
5095         start_mdt 1 || error "start mdt1 failed"
5096         add ost1 $opts_ost || error "add ost1 failed"
5097         start_ost || error "start ost failed"
5098         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
5099
5100         local soc=$(do_facet mds1 "$LCTL get_param -n \
5101                     mdt.*MDT0000.sync_lock_cancel")
5102         [ $soc == "never" ] || error "SoC enabled on single MDS"
5103
5104         for i in $(seq 2 $MDSCOUNT); do
5105                 mdsdev=$(mdsdevname $i)
5106                 mdsvdev=$(mdsvdevname $i)
5107                 opts_mds="$(mkfs_opts mds$i $mdsdev) --reformat $mdsdev \
5108                           $mdsvdev"
5109                 add mds$i $opts_mds || error "add mds$i failed"
5110                 start_mdt $i || error "start mdt$i fail"
5111         done
5112
5113         wait_dne_interconnect
5114
5115         for i in $(seq $MDSCOUNT); do
5116                 soc=$(do_facet mds$i "$LCTL get_param -n \
5117                         mdt.*MDT000$((i - 1)).sync_lock_cancel")
5118                 [ $soc == "blocking" ] || error "SoC not enabled on DNE"
5119         done
5120
5121         for i in $(seq 2 $MDSCOUNT); do
5122                 stop_mdt $i || error "stop mdt$i fail"
5123         done
5124         soc=$(do_facet mds1 "$LCTL get_param -n \
5125                 mdt.*MDT0000.sync_lock_cancel")
5126         [ $soc == "never" ] || error "SoC enabled on single MDS"
5127         umount_client $MOUNT -f > /dev/null
5128
5129         cleanup || error "cleanup failed with $?"
5130 }
5131 run_test 70e "Sync-on-Cancel will be enabled by default on DNE"
5132
5133 test_71a() {
5134         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5135         if combined_mgs_mds; then
5136                 skip "needs separate MGS/MDT"
5137         fi
5138         local MDTIDX=1
5139
5140         start_mdt 1 || error "MDT0 start fail"
5141         start_ost || error "OST0 start fail"
5142         for num in $(seq 2 $MDSCOUNT); do
5143                 start_mdt $num || return
5144         done
5145
5146         start_ost2 || error "OST1 start fail"
5147
5148         mount_client $MOUNT || error "mount client fails"
5149
5150         mkdir $DIR/$tdir || error "mkdir fail"
5151         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5152                 error "create remote dir succeed"
5153
5154         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5155         rm -rf $DIR/$tdir || error "delete dir fail"
5156
5157         umount_client $MOUNT || error "umount_client failed"
5158         stop_mds || error "MDS stop fail"
5159         stop_ost || error "OST0 stop fail"
5160         stop_ost2 || error "OST1 stop fail"
5161 }
5162 run_test 71a "start MDT0 OST0, MDT1, OST1"
5163
5164 test_71b() {
5165         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5166         if combined_mgs_mds; then
5167                 skip "needs separate MGS/MDT"
5168         fi
5169         local MDTIDX=1
5170
5171         for num in $(seq 2 $MDSCOUNT); do
5172                 start_mdt $num || return
5173         done
5174         start_ost || error "OST0 start fail"
5175         start_mdt 1 || error "MDT0 start fail"
5176         start_ost2 || error "OST1 start fail"
5177
5178         mount_client $MOUNT || error "mount client fails"
5179
5180         mkdir $DIR/$tdir || error "mkdir fail"
5181         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5182                 error "create remote dir succeed"
5183
5184         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5185         rm -rf $DIR/$tdir || error "delete dir fail"
5186
5187         umount_client $MOUNT || error "umount_client failed"
5188         stop_mds || error "MDT0 stop fail"
5189         stop_ost || error "OST0 stop fail"
5190         stop_ost2 || error "OST1 stop fail"
5191 }
5192 run_test 71b "start MDT1, OST0, MDT0, OST1"
5193
5194 test_71c() {
5195         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5196         combined_mgs_mds && skip "needs separate MGS/MDT"
5197
5198         local MDTIDX=1
5199
5200         start_ost || error "OST0 start fail"
5201         start_ost2 || error "OST1 start fail"
5202         for num in $(seq 2 $MDSCOUNT); do
5203                 start_mdt $num || return
5204         done
5205         start_mdt 1 || error "MDT0 start fail"
5206
5207         mount_client $MOUNT || error "mount client fails"
5208
5209         mkdir $DIR/$tdir || error "mkdir fail"
5210         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5211                 error "create remote dir succeed"
5212
5213         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5214         rm -rf $DIR/$tdir || error "delete dir fail"
5215
5216         umount_client $MOUNT || error "umount_client failed"
5217         stop_mds || error "MDS stop fail"
5218         stop_ost || error "OST0 stop fail"
5219         stop_ost2 || error "OST1 stop fail"
5220
5221 }
5222 run_test 71c "start OST0, OST1, MDT1, MDT0"
5223
5224 test_71d() {
5225         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5226         combined_mgs_mds && skip "needs separate MGS/MDT"
5227
5228         local MDTIDX=1
5229
5230         start_ost || error "OST0 start fail"
5231         for num in $(seq 2 $MDSCOUNT); do
5232                 start_mdt $num || return
5233         done
5234         start_mdt 1 || error "MDT0 start fail"
5235         start_ost2 || error "OST1 start fail"
5236
5237         mount_client $MOUNT || error "mount client fails"
5238
5239         mkdir $DIR/$tdir || error "mkdir fail"
5240         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5241                         error "create remote dir succeed"
5242
5243         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5244         rm -rf $DIR/$tdir || error "delete dir fail"
5245
5246         umount_client $MOUNT || error "umount_client failed"
5247         stop_mds || error "MDS stop fail"
5248         stop_ost || error "OST0 stop fail"
5249         stop_ost2 || error "OST1 stop fail"
5250
5251 }
5252 run_test 71d "start OST0, MDT1, MDT0, OST1"
5253
5254 test_71e() {
5255         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5256         combined_mgs_mds && skip "needs separate MGS/MDT"
5257
5258         local MDTIDX=1
5259
5260         start_ost || error "OST0 start fail"
5261         for num in $(seq 2 $MDSCOUNT); do
5262                 start_mdt $num || return
5263         done
5264         start_ost2 || error "OST1 start fail"
5265         start_mdt 1 || error "MDT0 start fail"
5266
5267         mount_client $MOUNT || error "mount client fails"
5268
5269         mkdir $DIR/$tdir || error "mkdir fail"
5270         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5271                 error "create remote dir succeed"
5272
5273         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5274         rm -rf $DIR/$tdir || error "delete dir fail"
5275
5276         umount_client $MOUNT || error "umount_client failed"
5277         stop_mds || error "MDS stop fail"
5278         stop_ost || error "OST0 stop fail"
5279         stop_ost2 || error "OST1 stop fail"
5280
5281 }
5282 run_test 71e "start OST0, MDT1, OST1, MDT0"
5283
5284 test_72() { #LU-2634
5285         [ "$(facet_fstype $SINGLEMDS)" != "ldiskfs" ] &&
5286                 skip "ldiskfs only test"
5287
5288         local mdsdev=$(mdsdevname 1)
5289         local ostdev=$(ostdevname 1)
5290         local cmd="$E2FSCK -fnvd $mdsdev"
5291         local fn=3
5292         local add_options
5293
5294         if combined_mgs_mds; then
5295                 add_options='--reformat'
5296         else
5297                 add_options='--reformat --replace'
5298         fi
5299
5300         #tune MDT with "-O extents"
5301
5302         for num in $(seq $MDSCOUNT); do
5303                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
5304                         $add_options $(mdsdevname $num) $(mdsvdevname $num) ||
5305                         error "add mds $num failed"
5306                 do_facet mds${num} "$TUNE2FS -O extents $(mdsdevname $num)" ||
5307                         error "$TUNE2FS failed on mds${num}"
5308         done
5309
5310         add ost1 $(mkfs_opts ost1 $ostdev) $add_options $ostdev ||
5311                 error "add $ostdev failed"
5312         start_mds || error "start mds failed"
5313         start_ost || error "start ost failed"
5314         mount_client $MOUNT || error "mount client failed"
5315
5316         #create some short symlinks
5317         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5318         createmany -o $DIR/$tdir/$tfile-%d $fn
5319         echo "create $fn short symlinks"
5320         for i in $(seq -w 1 $fn); do
5321                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
5322         done
5323         ls -al $MOUNT
5324
5325         #umount
5326         umount_client $MOUNT || error "umount client failed"
5327         stop_mds || error "stop mds failed"
5328         stop_ost || error "stop ost failed"
5329
5330         #run e2fsck
5331         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
5332 }
5333 run_test 72 "test fast symlink with extents flag enabled"
5334
5335 test_73() { #LU-3006
5336         [ $(facet_fstype ost1) == zfs ] && import_zpool ost1
5337         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
5338                 error "1st tunefs failed"
5339         start_mgsmds || error "start mds failed"
5340         start_ost || error "start ost failed"
5341         mount_client $MOUNT || error "mount client failed"
5342         $LCTL get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
5343                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
5344         umount_client $MOUNT || error "umount client failed"
5345         stopall
5346         reformat
5347 }
5348 run_test 73 "failnode to update from mountdata properly"
5349
5350 test_75() { # LU-2374
5351         [[ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.4.1) ]] &&
5352                 skip "Need MDS version at least 2.4.1"
5353
5354         local index=0
5355         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
5356                 --reformat $(mdsdevname 1) $(mdsvdevname 1)"
5357         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
5358                 --reformat $(ostdevname 1) $(ostvdevname 1)"
5359
5360         #check with default parameters
5361         add mds1 $opts_mds || error "add mds1 failed for default params"
5362         add ost1 $opts_ost || error "add ost1 failed for default params"
5363
5364         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
5365         opts_mds=$(echo $opts_mds |
5366                    sed -e "s/--index=$index/--index=$index --mdt/")
5367         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
5368         opts_ost=$(echo $opts_ost |
5369                    sed -e "s/--index=$index/--index=$index --ost/")
5370
5371         add mds1 $opts_mds || error "add mds1 failed for new params"
5372         add ost1 $opts_ost || error "add ost1 failed for new params"
5373         if ! combined_mgs_mds; then
5374                 stop_mgs || error "stop mgs failed"
5375         fi
5376         reformat
5377         return 0
5378 }
5379 run_test 75 "The order of --index should be irrelevant"
5380
5381 test_76a() {
5382         [[ $(lustre_version_code mgs) -ge $(version_code 2.4.52) ]] ||
5383                 skip "Need MDS version at least 2.4.52"
5384
5385         if ! combined_mgs_mds; then
5386                 start_mgs || error "start mgs failed"
5387         fi
5388         setup
5389         local MDMB_PARAM="osc.*.max_dirty_mb"
5390         echo "Change MGS params"
5391         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
5392                 head -1)
5393         echo "max_dirty_mb: $MAX_DIRTY_MB"
5394         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB - 10))
5395         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
5396         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
5397         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
5398                 head -1" $NEW_MAX_DIRTY_MB
5399         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
5400         echo "$MAX_DIRTY_MB"
5401         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
5402                 error "error while apply max_dirty_mb"
5403
5404         echo "Check the value is stored after remount"
5405         stopall
5406         setupall
5407         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
5408                 head -1" $NEW_MAX_DIRTY_MB
5409         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
5410         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
5411                 error "max_dirty_mb is not saved after remount"
5412
5413         echo "Change OST params"
5414         CLIENT_PARAM="obdfilter.*.client_cache_count"
5415         local CLIENT_CACHE_COUNT
5416         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5417                 head -1)
5418         echo "client_cache_count: $CLIENT_CACHE_COUNT"
5419         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
5420         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
5421         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
5422         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
5423                 head -1" $NEW_CLIENT_CACHE_COUNT
5424         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5425                 head -1)
5426         echo "$CLIENT_CACHE_COUNT"
5427         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
5428                 error "error while apply client_cache_count"
5429
5430         echo "Check the value is stored after remount"
5431         stopall
5432         setupall
5433         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
5434                 head -1" $NEW_CLIENT_CACHE_COUNT
5435         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5436                 head -1)
5437         echo "$CLIENT_CACHE_COUNT"
5438         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
5439                 error "client_cache_count is not saved after remount"
5440         stopall
5441 }
5442 run_test 76a "set permanent params with lctl across mounts"
5443
5444 test_76b() { # LU-4783
5445         [[ $(lustre_version_code mgs) -ge $(version_code 2.5.57) ]] ||
5446                 skip "Need MGS version at least 2.5.57"
5447         stopall
5448         setupall
5449         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
5450                 error "start params log failed"
5451         stopall
5452 }
5453 run_test 76b "verify params log setup correctly"
5454
5455 test_76c() {
5456         [[ $(lustre_version_code mgs) -ge $(version_code 2.8.54) ]] ||
5457                 skip "Need MDS version at least 2.4.52"
5458         setupall
5459         local MASK_PARAM="mdd.*.changelog_mask"
5460         echo "Change changelog_mask"
5461         do_facet mgs $LCTL set_param -P $MASK_PARAM=-CLOSE ||
5462                 error "Can't change changlog_mask"
5463         wait_update $(facet_host mds) "$LCTL get_param -n $MASK_PARAM |
5464                 grep 'CLOSE'" ""
5465
5466         echo "Check the value is stored after mds remount"
5467         stop_mds || error "Failed to stop MDS"
5468         start_mds || error "Failed to start MDS"
5469         local CHANGELOG_MASK=$(do_facet mgs $LCTL get_param -n $MASK_PARAM)
5470         echo $CHANGELOG_MASK | grep CLOSE > /dev/null &&
5471                 error "changelog_mask is not changed"
5472
5473         stopall
5474 }
5475 run_test 76c "verify changelog_mask is applied with lctl set_param -P"
5476
5477 test_76d() { #LU-9399
5478         setupall
5479
5480         local xattr_cache="llite.*.xattr_cache"
5481         local cmd="$LCTL get_param -n $xattr_cache | head -1"
5482         local new=$((($(eval $cmd) + 1) % 2))
5483
5484         echo "lctl set_param -P llite.*.xattr_cache=$new"
5485         do_facet mgs $LCTL set_param -P $xattr_cache=$new ||
5486                 error "Can't change xattr_cache"
5487         wait_update $HOSTNAME "$cmd" "$new"
5488
5489         echo "Check $xattr_cache on client $MOUNT"
5490         umount_client $MOUNT || error "umount $MOUNT failed"
5491         mount_client $MOUNT || error "mount $MOUNT failed"
5492         [ $(eval $cmd) -eq $new ] ||
5493                 error "$xattr_cache != $new on client $MOUNT"
5494
5495         echo "Check $xattr_cache on the new client $MOUNT2"
5496         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
5497         [ $(eval $cmd) -eq $new ] ||
5498                 error "$xattr_cache != $new on client $MOUNT2"
5499         umount_client $MOUNT2 || error "umount $MOUNT2 failed"
5500
5501         stopall
5502 }
5503 run_test 76d "verify llite.*.xattr_cache can be set by 'lctl set_param -P' correctly"
5504
5505 test_77() { # LU-3445
5506         local server_version=$(lustre_version_code $SINGLEMDS)
5507         [[ $server_version -ge $(version_code 2.8.55) ]] ||
5508                 skip "Need MDS version 2.8.55+ "
5509
5510         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
5511                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
5512                 skip_env "mixed loopback and real device not working"
5513         fi
5514
5515         local fs2mdsdev=$(mdsdevname 1_2)
5516         local fs2ostdev=$(ostdevname 1_2)
5517         local fs2mdsvdev=$(mdsvdevname 1_2)
5518         local fs2ostvdev=$(ostvdevname 1_2)
5519         local fsname=test1234
5520         local mgsnid
5521         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
5522
5523         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
5524
5525         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
5526                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
5527         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
5528                 error "start fs2mds failed"
5529
5530         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
5531         mgsnid="0.0.0.0@tcp,$mgsnid,$mgsnid:$mgsnid"
5532
5533         add fs2ost --mgsnode=$mgsnid $(mkfs_opts ost1 $fs2ostdev) \
5534                 --failnode=$failnid --fsname=$fsname \
5535                 --reformat $fs2ostdev $fs2ostvdev ||
5536                         error "add fs2ost failed"
5537         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
5538
5539         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
5540         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
5541         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
5542         cleanup_fs2
5543 }
5544 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
5545
5546 test_78() {
5547         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ||
5548            $(facet_fstype ost1) != ldiskfs ]] &&
5549                 skip "ldiskfs only test"
5550
5551         # reformat the Lustre filesystem with a smaller size
5552         local saved_MDSCOUNT=$MDSCOUNT
5553         local saved_MDSSIZE=$MDSSIZE
5554         local saved_OSTCOUNT=$OSTCOUNT
5555         local saved_OSTSIZE=$OSTSIZE
5556         MDSCOUNT=1
5557         OSTCOUNT=1
5558         MDSSIZE=$((MDSSIZE - 20000))
5559         OSTSIZE=$((OSTSIZE - 20000))
5560         reformat || error "(1) reformat Lustre filesystem failed"
5561         MDSSIZE=$saved_MDSSIZE
5562         OSTSIZE=$saved_OSTSIZE
5563
5564         # mount the Lustre filesystem
5565         setup_noconfig || error "(2) setup Lustre filesystem failed"
5566
5567         # create some files
5568         log "create test files"
5569         local i
5570         local file
5571         local num_files=100
5572
5573         mkdir $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
5574         $LFS df; $LFS df -i
5575         for i in $(seq $num_files); do
5576                 file=$MOUNT/$tdir/$tfile-$i
5577                 dd if=/dev/urandom of=$file count=1 bs=1M || {
5578                         $LCTL get_param osc.*.cur*grant*
5579                         $LFS df; $LFS df -i;
5580                         # stop creating files if there is no more space
5581                         if [ ! -e $file ]; then
5582                                 num_files=$((i - 1))
5583                                 break
5584                         fi
5585
5586                         $LFS getstripe -v $file
5587                         local ost_idx=$(LFS getstripe -i $file)
5588                         do_facet ost$((ost_idx + 1)) \
5589                                 $LCTL get_param obdfilter.*.*grant*
5590                         error "(4) create $file failed"
5591                 }
5592         done
5593
5594         # unmount the Lustre filesystem
5595         cleanup || error "(5) cleanup Lustre filesystem failed"
5596
5597         # run e2fsck on the MDT and OST devices
5598         local mds_host=$(facet_active_host $SINGLEMDS)
5599         local ost_host=$(facet_active_host ost1)
5600         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5601         local ost_dev=$(ostdevname 1)
5602
5603         run_e2fsck $mds_host $mds_dev "-y"
5604         run_e2fsck $ost_host $ost_dev "-y"
5605
5606         # get the original block count of the MDT and OST filesystems
5607         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
5608         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
5609
5610         # expand the MDT and OST filesystems to the device size
5611         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
5612         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
5613
5614         # run e2fsck on the MDT and OST devices again
5615         run_e2fsck $mds_host $mds_dev "-y"
5616         run_e2fsck $ost_host $ost_dev "-y"
5617
5618         # mount the Lustre filesystem
5619         setup
5620
5621         # check the files
5622         log "check files after expanding the MDT and OST filesystems"
5623         for i in $(seq $num_files); do
5624                 file=$MOUNT/$tdir/$tfile-$i
5625                 $CHECKSTAT -t file -s 1048576 $file ||
5626                         error "(6) checkstat $file failed"
5627         done
5628
5629         # create more files
5630         log "create more files after expanding the MDT and OST filesystems"
5631         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
5632                 file=$MOUNT/$tdir/$tfile-$i
5633                 dd if=/dev/urandom of=$file count=1 bs=1M ||
5634                         error "(7) create $file failed"
5635         done
5636
5637         # unmount the Lustre filesystem
5638         cleanup || error "(8) cleanup Lustre filesystem failed"
5639
5640         # run e2fsck on the MDT and OST devices
5641         run_e2fsck $mds_host $mds_dev "-y"
5642         run_e2fsck $ost_host $ost_dev "-y"
5643
5644         # get the maximum block count of the MDT and OST filesystems
5645         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
5646         local ost_max_blks=$(get_block_count ost1 $ost_dev)
5647
5648         # get the minimum block count of the MDT and OST filesystems
5649         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
5650                                 grep minimum | sed -e 's/^.*filesystem: //g')
5651         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
5652                                 grep minimum | sed -e 's/^.*filesystem: //g')
5653
5654         # shrink the MDT and OST filesystems to a smaller size
5655         local shrunk=false
5656         local new_blks
5657         local base_blks
5658         if [[ $mds_max_blks -gt $mds_min_blks &&
5659               $mds_max_blks -gt $mds_orig_blks ]]; then
5660                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
5661                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
5662                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
5663                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
5664                         error "shrink $SINGLEMDS to $new_blks failed"
5665                 shrunk=true
5666         fi
5667
5668         if [[ $ost_max_blks -gt $ost_min_blks &&
5669               $ost_max_blks -gt $ost_orig_blks ]]; then
5670                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
5671                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
5672                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
5673                 run_resize2fs ost1 $ost_dev $new_blks ||
5674                         error "shrink ost1 to $new_blks failed"
5675                 shrunk=true
5676         fi
5677
5678         # check whether the MDT or OST filesystem was shrunk or not
5679         if ! $shrunk; then
5680                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
5681                 reformat || error "(10) reformat Lustre filesystem failed"
5682                 return 0
5683         fi
5684
5685         # run e2fsck on the MDT and OST devices again
5686         run_e2fsck $mds_host $mds_dev "-y"
5687         run_e2fsck $ost_host $ost_dev "-y"
5688
5689         # mount the Lustre filesystem again
5690         setup
5691
5692         # check the files
5693         log "check files after shrinking the MDT and OST filesystems"
5694         for i in $(seq $((num_files + 10))); do
5695                 file=$MOUNT/$tdir/$tfile-$i
5696                 $CHECKSTAT -t file -s 1048576 $file ||
5697                         error "(11) checkstat $file failed"
5698         done
5699
5700         # unmount and reformat the Lustre filesystem
5701         cleanup || error "(12) cleanup Lustre filesystem failed"
5702         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
5703
5704         MDSCOUNT=$saved_MDSCOUNT
5705         OSTCOUNT=$saved_OSTCOUNT
5706         reformat || error "(14) reformat Lustre filesystem failed"
5707 }
5708 run_test 78 "run resize2fs on MDT and OST filesystems"
5709
5710 test_79() { # LU-4227
5711         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.5.59) ]] ||
5712                 skip "Need MDS version at least 2.5.59"
5713
5714         local mdsdev1=$(mdsdevname 1)
5715         local mdsvdev1=$(mdsvdevname 1)
5716         local mdsdev2=$(mdsdevname 2)
5717         local mdsvdev2=$(mdsvdevname 2)
5718         local ostdev1=$(ostdevname 1)
5719         local ostvdev1=$(ostvdevname 1)
5720         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
5721         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
5722         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
5723         local mgsnode_opt
5724
5725         # remove --mgs/--mgsnode from mkfs.lustre options
5726         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
5727
5728         mgsnode_opt=$(echo $opts_mds2 |
5729                 awk '{ for ( i = 1; i < NF; i++ )
5730                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
5731         [ -n $mgsnode_opt ] &&
5732                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
5733
5734         mgsnode_opt=$(echo $opts_ost1 |
5735                 awk '{ for ( i = 1; i < NF; i++ )
5736                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
5737         [ -n $mgsnode_opt ] &&
5738                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
5739
5740         # -MGS, format a mdt without --mgs option
5741         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
5742                 error "Must specify --mgs when formatting mdt combined with mgs"
5743
5744         # +MGS, format a mdt/ost without --mgsnode option
5745         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
5746                 > /dev/null || error "start mds1 failed"
5747         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
5748                 error "Must specify --mgsnode when formatting a mdt"
5749         add ost1 $opts_ost1 $ostdev1 $ostvdev2 &&
5750                 error "Must specify --mgsnode when formatting an ost"
5751
5752         reformat
5753 }
5754 run_test 79 "format MDT/OST without mgs option (should return errors)"
5755
5756 test_80() {
5757         start_mds || error "Failed to start MDT"
5758         start_ost || error "Failed to start OST1"
5759         uuid=$(do_facet ost1 $LCTL get_param -n mgc.*.uuid)
5760 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
5761         do_facet ost1 "$LCTL set_param fail_val=10 fail_loc=0x906"
5762         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x906"
5763         do_facet mgs "$LCTL set_param -n mgs/MGS/evict_client $uuid"
5764         sleep 30
5765         start_ost2 || error "Failed to start OST2"
5766
5767         do_facet ost1 "$LCTL set_param fail_loc=0"
5768         stopall
5769 }
5770 run_test 80 "mgc import reconnect race"
5771
5772 #Save the original values of $OSTCOUNT and $OSTINDEX$i.
5773 save_ostindex() {
5774         local new_ostcount=$1
5775         saved_ostcount=$OSTCOUNT
5776         OSTCOUNT=$new_ostcount
5777
5778         local i
5779         local index
5780         for i in $(seq $OSTCOUNT); do
5781                 index=OSTINDEX$i
5782                 eval saved_ostindex$i=${!index}
5783                 eval OSTINDEX$i=""
5784         done
5785 }
5786
5787 # Restore the original values of $OSTCOUNT and $OSTINDEX$i.
5788 restore_ostindex() {
5789         trap 0
5790
5791         local i
5792         local index
5793         for i in $(seq $OSTCOUNT); do
5794                 index=saved_ostindex$i
5795                 eval OSTINDEX$i=${!index}
5796         done
5797         OSTCOUNT=$saved_ostcount
5798
5799         formatall
5800 }
5801
5802 # The main purpose of this test is to ensure the OST_INDEX_LIST functions as
5803 # expected. This test uses OST_INDEX_LIST to format OSTs with a randomly
5804 # assigned index and ensures we can mount such a formatted file system
5805 test_81() { # LU-4665
5806         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5807                 skip "Need MDS version at least 2.6.54"
5808         [[ $OSTCOUNT -ge 3 ]] || skip_env "needs >= 3 OSTs"
5809
5810         stopall
5811
5812         # Each time RANDOM is referenced, a random integer between 0 and 32767
5813         # is generated.
5814         local i
5815         local saved_ostindex1=$OSTINDEX1
5816         for i in 65535 $((RANDOM + 65536)); do
5817                 echo -e "\nFormat ost1 with --index=$i, should fail"
5818                 OSTINDEX1=$i
5819                 if add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat \
5820                    $(ostdevname 1) $(ostvdevname 1); then
5821                         OSTINDEX1=$saved_ostindex1
5822                         error "format ost1 with --index=$i should fail"
5823                 fi
5824         done
5825         OSTINDEX1=$saved_ostindex1
5826
5827         save_ostindex 3
5828
5829         # Format OSTs with random sparse indices.
5830         trap "restore_ostindex" EXIT
5831         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices"
5832         OST_INDEX_LIST=[0,$((RANDOM * 2 % 65533 + 1)),65534] formatall
5833
5834         # Setup and check Lustre filesystem.
5835         start_mgsmds || error "start_mgsmds failed"
5836         for i in $(seq $OSTCOUNT); do
5837                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5838                         error "start ost$i failed"
5839         done
5840
5841         mount_client $MOUNT || error "mount client $MOUNT failed"
5842         check_mount || error "check client $MOUNT failed"
5843
5844         # Check max_easize.
5845         local max_easize=$($LCTL get_param -n llite.*.max_easize)
5846         [[ $max_easize -eq 128 ]] ||
5847                 error "max_easize is $max_easize, should be 128 bytes"
5848
5849         restore_ostindex
5850 }
5851 run_test 81 "sparse OST indexing"
5852
5853 # Here we exercise the stripe placement functionality on a file system that
5854 # has formatted the OST with a random index. With the file system the following
5855 # functionality is tested:
5856 #
5857 # 1. Creating a new file with a specific stripe layout.
5858 #
5859 # 2. Modifiy a existing empty file with a specific stripe layout.
5860 #
5861 # 3. Ensure we fail to set the stripe layout of a file that already has one.
5862 #
5863 # 4. If ost-index is defined we need to ensure it is the first entry in the
5864 #    ost index list returned by lfs getstripe.
5865 #
5866 # 5. Lastly ensure this functionality fails with directories.
5867 test_82a() { # LU-4665
5868         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5869                 skip "Need MDS version at least 2.6.54"
5870         [[ $OSTCOUNT -ge 3 ]] || skip_env "needs >= 3 OSTs"
5871
5872         stopall
5873
5874         save_ostindex 3
5875
5876         # Format OSTs with random sparse indices.
5877         local i
5878         local index
5879         local ost_indices
5880         local LOV_V1_INSANE_STRIPE_COUNT=65532
5881         for i in $(seq $OSTCOUNT); do
5882                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
5883                 ost_indices+=" $index"
5884         done
5885         ost_indices=$(comma_list $ost_indices)
5886
5887         stack_trap "restore_ostindex" EXIT
5888         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5889         OST_INDEX_LIST=[$ost_indices] formatall
5890
5891         # Setup Lustre filesystem.
5892         start_mgsmds || error "start_mgsmds failed"
5893         for i in $(seq $OSTCOUNT); do
5894                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5895                         error "start ost$i failed"
5896         done
5897
5898         # Collect debug information - start of test
5899         do_nodes $(comma_list $(mdts_nodes)) \
5900                    $LCTL get_param osc.*.prealloc_*_id
5901
5902         mount_client $MOUNT || error "mount client $MOUNT failed"
5903         wait_osts_up
5904
5905         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5906         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5907
5908         stack_trap "do_nodes $(comma_list $(mdts_nodes)) \
5909                    $LCTL get_param osc.*.prealloc_*_id" EXIT
5910
5911         # 1. If the file does not exist, new file will be created
5912         #    with specified OSTs.
5913         local file=$DIR/$tdir/$tfile-1
5914         local cmd="$LFS setstripe -o $ost_indices $file"
5915         echo -e "\n$cmd"
5916         eval $cmd || error "$cmd failed"
5917         check_stripe_count $file $OSTCOUNT
5918         check_obdidx $file $ost_indices
5919         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5920                 error "write $file failed"
5921
5922         # 2. If the file already exists and is an empty file, the file
5923         #    will be attached with specified layout.
5924         file=$DIR/$tdir/$tfile-2
5925         mcreate $file || error "mcreate $file failed"
5926         cmd="$LFS setstripe -o $ost_indices $file"
5927         echo -e "\n$cmd"
5928         eval $cmd || error "$cmd failed"
5929         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
5930                 error "write $file failed"
5931         check_stripe_count $file $OSTCOUNT
5932         check_obdidx $file $ost_indices
5933
5934         # 3. If the file already has a valid layout attached, the command
5935         #    should fail with EBUSY.
5936         echo -e "\n$cmd"
5937         eval $cmd && error "stripe is already set on $file, $cmd should fail"
5938
5939         # 4. If [--stripe-index|-i <start_ost_idx>] is used, the index must
5940         #    be in the OST indices list.
5941         local start_ost_idx=${ost_indices##*,}
5942         file=$DIR/$tdir/$tfile-3
5943         cmd="$LFS setstripe -o $ost_indices -i $start_ost_idx $file"
5944         echo -e "\n$cmd"
5945         eval $cmd || error "$cmd failed"
5946         check_stripe_count $file $OSTCOUNT
5947         check_obdidx $file $ost_indices
5948         check_start_ost_idx $file $start_ost_idx
5949
5950         file=$DIR/$tdir/$tfile-4
5951         cmd="$LFS setstripe"
5952         cmd+=" -o $(exclude_items_from_list $ost_indices $start_ost_idx)"
5953         cmd+=" -i $start_ost_idx $file"
5954         echo -e "\n$cmd"
5955         eval $cmd && error "index $start_ost_idx should be in $ost_indices"
5956
5957         # 5. Specifying OST indices for directory should succeed.
5958         local dir=$DIR/$tdir/$tdir
5959         mkdir $dir || error "mkdir $dir failed"
5960         cmd="$LFS setstripe -o $ost_indices $dir"
5961         if [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.11.53) &&
5962            $(lustre_version_code client -gt $(version_code 2.11.53)) ]]; then
5963                 echo -e "\n$cmd"
5964                 eval $cmd || error "unable to specify OST indices on directory"
5965         else
5966                 echo "need MDS+client version at least 2.11.53"
5967         fi
5968
5969         restore_ostindex
5970 }
5971 run_test 82a "specify OSTs for file (succeed) or directory (succeed)"
5972
5973 cleanup_82b() {
5974         trap 0
5975
5976         # Remove OSTs from a pool and destroy the pool.
5977         destroy_pool $ost_pool || true
5978
5979         if ! combined_mgs_mds ; then
5980                 umount_mgs_client
5981         fi
5982         restore_ostindex
5983 }
5984
5985 # Test 82b is run to ensure that if the user supplies a pool with a specific
5986 # stripe layout that it behaves proprerly. It should fail in the case that
5987 # the supplied OST index list points to OSTs not contained in the user
5988 # supplied pool.
5989 test_82b() { # LU-4665
5990         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.6.54) ]] ||
5991                 skip "Need MDS version at least 2.6.54"
5992         [[ $OSTCOUNT -ge 4 ]] || skip_env "needs >= 4 OSTs"
5993
5994         stopall
5995
5996         save_ostindex 4
5997
5998         # Format OSTs with random sparse indices.
5999         local i
6000         local index
6001         local ost_indices
6002         local LOV_V1_INSANE_STRIPE_COUNT=65532
6003         for i in $(seq $OSTCOUNT); do
6004                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
6005                 ost_indices+=" $index"
6006         done
6007         ost_indices=$(comma_list $ost_indices)
6008
6009         trap "restore_ostindex" EXIT
6010         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
6011         OST_INDEX_LIST=[$ost_indices] formatall
6012
6013         # Setup Lustre filesystem.
6014         start_mgsmds || error "start_mgsmds failed"
6015         for i in $(seq $OSTCOUNT); do
6016                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
6017                         error "start ost$i failed"
6018         done
6019
6020         mount_client $MOUNT || error "mount client $MOUNT failed"
6021         if ! combined_mgs_mds ; then
6022                 mount_mgs_client
6023         fi
6024
6025         wait_osts_up
6026         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
6027         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6028
6029         # Create a new pool and add OSTs into it.
6030         local ost_pool=$FSNAME.$TESTNAME
6031         create_pool $ost_pool || error "create OST pool $ost_pool failed"
6032
6033         trap - EXIT
6034         trap "cleanup_82b" EXIT
6035
6036         local ost_idx_in_list=${ost_indices##*,}
6037         local ost_idx_in_pool=$(exclude_items_from_list $ost_indices \
6038                                 $ost_idx_in_list)
6039
6040         local ost_targets="$FSNAME-OST["
6041         for i in ${ost_idx_in_pool//,/ }; do
6042                 ost_targets=$ost_targets$(printf "%04x," $i)
6043         done
6044         ost_targets="${ost_targets%,}]"
6045
6046         local ost_targets_uuid=$(for i in ${ost_idx_in_pool//,/ }; \
6047                                  do printf "$FSNAME-OST%04x_UUID\n" $i; done |
6048                                  sort -u | tr '\n' ' ')
6049
6050         local cmd="$LCTL pool_add $ost_pool $ost_targets"
6051         do_facet mgs $cmd || error "$cmd failed"
6052         wait_update $HOSTNAME "$LCTL get_param -n lov.$FSNAME-*.pools.$TESTNAME|
6053                                sort -u | tr '\n' ' ' " "$ost_targets_uuid" ||
6054                                         error "wait_update $ost_pool failed"
6055         wait_update_facet $SINGLEMDS "$LCTL pool_list $ost_pool | wc -l" 4 ||
6056                                 error "wait_update pool_list $ost_pool failed"
6057
6058         # If [--pool|-p <pool_name>] is set with [--ost-list|-o <ost_indices>],
6059         # then the OSTs must be the members of the pool.
6060         local file=$DIR/$tdir/$tfile
6061         cmd="$LFS setstripe -p $ost_pool -o $ost_idx_in_list $file"
6062         echo -e "\n$cmd"
6063         eval $cmd && error "OST with index $ost_idx_in_list should be" \
6064                            "in OST pool $ost_pool"
6065
6066         # Only select OST $ost_idx_in_list from $ost_pool for file.
6067         ost_idx_in_list=${ost_idx_in_pool#*,}
6068         cmd="$LFS setstripe -p $ost_pool -o $ost_idx_in_list $file"
6069         echo -e "\n$cmd"
6070         eval $cmd || error "$cmd failed"
6071         cmd="$LFS getstripe $file"
6072         echo -e "\n$cmd"
6073         eval $cmd || error "$cmd failed"
6074         check_stripe_count $file 2
6075         check_obdidx $file $ost_idx_in_list
6076         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
6077                 error "write $file failed"
6078
6079         cleanup_82b
6080 }
6081 run_test 82b "specify OSTs for file with --pool and --ost-list options"
6082
6083 test_83() {
6084         [[ $(lustre_version_code ost1) -ge $(version_code 2.6.91) ]] ||
6085                 skip "Need OST version at least 2.6.91"
6086         if [ $(facet_fstype ost1) != ldiskfs ]; then
6087                 skip "ldiskfs only test"
6088         fi
6089
6090         local dev
6091         local ostmnt
6092         local fstype
6093         local mnt_opts
6094
6095         dev=$(ostdevname 1)
6096         ostmnt=$(facet_mntpt ost1)
6097         fstype=$(facet_fstype ost1)
6098
6099         # Mount the OST as an ldiskfs filesystem.
6100         log "mount the OST $dev as a $fstype filesystem"
6101         add ost1 $(mkfs_opts ost1 $dev) $FSTYPE_OPT \
6102                 --reformat $dev > /dev/null ||
6103                 error "format ost1 error"
6104
6105         if ! test -b $dev; then
6106                 mnt_opts=$(csa_add "$OST_MOUNT_OPTS" -o loop)
6107         fi
6108         echo "mnt_opts $mnt_opts"
6109         do_facet ost1 mount -t $fstype $dev \
6110                 $ostmnt $mnt_opts
6111         # Run llverfs on the mounted ldiskfs filesystem.
6112         # It is needed to get ENOSPACE.
6113         log "run llverfs in partial mode on the OST $fstype $ostmnt"
6114         do_rpc_nodes $(facet_host ost1) run_llverfs $ostmnt -vpl \
6115                 "no" || error "run_llverfs error on $fstype"
6116
6117         # Unmount the OST.
6118         log "unmount the OST $dev"
6119         stop ost1
6120
6121         # Delete file IO_scrub. Later osd_scrub_setup will try to
6122         # create "IO_scrub" but will get ENOSPACE.
6123         writeconf_all
6124         echo "start ost1 service on `facet_active_host ost1`"
6125         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
6126
6127         local err
6128         err=$(do_facet ost1 dmesg | grep "VFS: Busy inodes after unmount of")
6129         echo "string err $err"
6130         [ -z "$err" ] || error $err
6131         reformat
6132 }
6133 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
6134 Busy inodes after unmount ..."
6135
6136 test_84() {
6137         local facet=$SINGLEMDS
6138         local num=$(echo $facet | tr -d "mds")
6139         local dev=$(mdsdevname $num)
6140         local time_min=$(recovery_time_min)
6141         local recovery_duration
6142         local completed_clients
6143         local correct_clients
6144         local wrap_up=5
6145
6146         echo "start mds service on $(facet_active_host $facet)"
6147         start_mds \
6148         "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min" $@ ||
6149                 error "start MDS failed"
6150
6151         start_ost || error "start OST0000 failed"
6152         start_ost2 || error "start OST0001 failed"
6153
6154         echo "recovery_time=$time_min, timeout=$TIMEOUT, wrap_up=$wrap_up"
6155
6156         mount_client $MOUNT1 || error "mount $MOUNT1 failed"
6157         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
6158         # make sure new superblock labels are sync'd before disabling writes
6159         sync_all_data
6160         sleep 5
6161
6162         replay_barrier $SINGLEMDS
6163         createmany -o $DIR1/$tfile-%d 1000
6164
6165         # We need to catch the end of recovery window to extend it.
6166         # Skip 5 requests and add delay to request handling.
6167         #define OBD_FAIL_TGT_REPLAY_DELAY  0x709 | FAIL_SKIP
6168         do_facet $SINGLEMDS "lctl set_param fail_loc=0x20000709 fail_val=5"
6169
6170         facet_failover --fsck $SINGLEMDS || error "failover: $?"
6171         client_up
6172
6173         echo "recovery status"
6174         do_facet $SINGLEMDS \
6175                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status"
6176
6177         recovery_duration=$(do_facet $SINGLEMDS \
6178                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
6179                 awk '/recovery_duration/ { print $2 }')
6180         (( $recovery_duration > $time_min + $wrap_up )) &&
6181                 error "recovery_duration > recovery_time_hard + wrap up"
6182         completed_clients=$(do_facet $SINGLEMDS \
6183                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
6184                 awk '/completed_clients/ { print $2 }')
6185
6186         correct_clients="$MDSCOUNT/$((MDSCOUNT+1))"
6187         [ "$completed_clients" = "${correct_clients}" ] ||
6188                 error "$completed_clients != $correct_clients"
6189
6190         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
6191         umount_client $MOUNT1
6192         umount_client $MOUNT2
6193
6194         stop_ost
6195         stop_ost2
6196         stop_mds
6197 }
6198 run_test 84 "check recovery_hard_time"
6199
6200 test_85() {
6201         [[ $(lustre_version_code ost1) -ge $(version_code 2.7.55) ]] ||
6202                 skip "Need OST version at least 2.7.55"
6203 ##define OBD_FAIL_OSD_OST_EA_FID_SET 0x197
6204         do_facet ost1 "lctl set_param fail_loc=0x197"
6205         start_ost
6206         stop_ost
6207 }
6208 run_test 85 "osd_ost init: fail ea_fid_set"
6209
6210 cleanup_86() {
6211         trap 0
6212
6213         # ost1 has already registered to the MGS before the reformat.
6214         # So after reformatting it with option "-G", it could not be
6215         # mounted to the MGS. Cleanup the system for subsequent tests.
6216         reformat_and_config
6217 }
6218
6219 test_86() {
6220         local server_version=$(lustre_version_code $SINGLEMDS)
6221         [ "$(facet_fstype ost1)" = "zfs" ] &&
6222                 skip "LU-6442: no such mkfs params for ZFS OSTs"
6223         [[ $server_version -ge $(version_code 2.7.56) ]] ||
6224                 skip "Need server version newer than 2.7.55"
6225
6226         local OST_OPTS="$(mkfs_opts ost1 $(ostdevname 1)) \
6227                 --reformat $(ostdevname 1) $(ostvdevname 1)"
6228
6229         local NEWSIZE=1024
6230         local OLDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
6231                 awk '/Flex block group size: / { print $NF; exit; }')
6232
6233         local opts=OST_OPTS
6234         if [[ ${!opts} != *mkfsoptions* ]]; then
6235                 eval opts=\"${!opts} \
6236                         --mkfsoptions='\\\"-O flex_bg -G $NEWSIZE\\\"'\"
6237         else
6238                 val=${!opts//--mkfsoptions=\\\"/ \
6239                         --mkfsoptions=\\\"-O flex_bg -G $NEWSIZE }
6240                 eval opts='${val}'
6241         fi
6242
6243         echo "params: $opts"
6244
6245         trap cleanup_86 EXIT ERR
6246
6247         stopall
6248         add ost1 $opts || error "add ost1 failed with new params"
6249
6250         local FOUNDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
6251                 awk '/Flex block group size: / { print $NF; exit; }')
6252
6253         [[ $FOUNDSIZE == $NEWSIZE ]] ||
6254                 error "Flex block group size: $FOUNDSIZE, expected: $NEWSIZE"
6255
6256         cleanup_86
6257 }
6258 run_test 86 "Replacing mkfs.lustre -G option"
6259
6260 test_87() { #LU-6544
6261         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.9.51) ]] ||
6262                 skip "Need MDS version at least 2.9.51"
6263         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ]] &&
6264                 skip "ldiskfs only test"
6265         [[ $OSTCOUNT -gt 59 ]] &&
6266                 skip "Ignore wide striping situation"
6267
6268         local mdsdev=$(mdsdevname 1)
6269         local mdsvdev=$(mdsvdevname 1)
6270         local file=$DIR/$tfile
6271         local mntpt=$(facet_mntpt $SINGLEMDS)
6272         local used_xattr_blk=0
6273         local inode_size=${1:-1024}
6274         local left_size=0
6275         local xtest="trusted.test"
6276         local value
6277         local orig
6278         local i
6279         local stripe_cnt=$(($OSTCOUNT + 2))
6280
6281         #Please see ldiskfs_make_lustre() for MDT inode size calculation
6282         if [ $stripe_cnt -gt 16 ]; then
6283                 inode_size=2048
6284         fi
6285         left_size=$(expr $inode_size - \
6286                         156 - \
6287                         32 - \
6288                         32 - 40 \* 3 - 32 \* 3 - $stripe_cnt \* 24 - 16 - 3 -  \
6289                         24 - 16 - 3 - \
6290                         24 - 18 - $(expr length $tfile) - 16 - 4)
6291         if [ $left_size -le 0 ]; then
6292                 echo "No space($left_size) is expected in inode."
6293                 echo "Try 1-byte xattr instead to verify this."
6294                 left_size=1
6295         else
6296                 echo "Estimate: at most $left_size-byte space left in inode."
6297         fi
6298
6299         unload_modules
6300         reformat
6301
6302         add mds1 $(mkfs_opts mds1 ${mdsdev}) --stripe-count-hint=$stripe_cnt \
6303                 --reformat $mdsdev $mdsvdev || error "add mds1 failed"
6304         start_mdt 1 > /dev/null || error "start mdt1 failed"
6305         for i in $(seq $OSTCOUNT); do
6306                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS > /dev/null ||
6307                         error "start ost$i failed"
6308         done
6309         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
6310         check_mount || error "check client $MOUNT failed"
6311
6312         #set xattr
6313         $LFS setstripe -E 1M -S 1M -c 1 -E 64M -c 1 -E -1 -c -1 $file ||
6314                 error "Create file with 3 components failed"
6315         $TRUNCATE $file $((1024*1024*64+1)) || error "truncate file failed"
6316         i=$($LFS getstripe -I3 -c $file) || error "get 3rd stripe count failed"
6317         if [ $i -ne $OSTCOUNT ]; then
6318                 left_size=$(expr $left_size + $(expr $OSTCOUNT - $i) \* 24)
6319                 echo -n "Since only $i out $OSTCOUNT OSTs are used, "
6320                 echo -n "the expected left space is changed to "
6321                 echo "$left_size bytes at most."
6322         fi
6323         value=$(generate_string $left_size)
6324         setfattr -n $xtest -v $value $file
6325         orig=$(get_xattr_value $xtest $file)
6326         [[ "$orig" != "$value" ]] && error "$xtest changed"
6327
6328         #Verify if inode has some expected space left
6329         umount $MOUNT > /dev/null || error "umount $MOUNT failed"
6330         stop_mdt 1 > /dev/null || error "stop mdt1 failed"
6331         mount_ldiskfs $SINGLEMDS || error "mount -t ldiskfs $SINGLEMDS failed"
6332
6333         do_facet $SINGLEMDS ls -sal $mntpt/ROOT/$tfile
6334         used_xattr_blk=$(do_facet $SINGLEMDS ls -s $mntpt/ROOT/$tfile |
6335                         awk '{ print $1 }')
6336         [[ $used_xattr_blk -eq 0 ]] &&
6337                 error "Please check MDS inode size calculation: \
6338                        more than $left_size-byte space left in inode."
6339         echo "Verified: at most $left_size-byte space left in inode."
6340
6341         stopall
6342 }
6343 run_test 87 "check if MDT inode can hold EAs with N stripes properly"
6344
6345 test_88() {
6346         [ "$(facet_fstype mds1)" == "zfs" ] &&
6347                 skip "LU-6662: no implementation for ZFS"
6348
6349         load_modules
6350
6351         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
6352                 --reformat $(mdsdevname 1) || error "add mds1 failed"
6353
6354         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
6355                 grep -e \".*opts:.*errors=remount-ro.*\"" ||
6356                 error "default mount options is missing"
6357
6358         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
6359                 --mountfsoptions="user_xattr,errors=panic" \
6360                 --reformat $(mdsdevname 1) || error "add mds1 failed"
6361
6362         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
6363                 grep -e \".*opts:.*errors=panic.*\"" ||
6364                 error "user can't override default mount options"
6365 }
6366 run_test 88 "check the default mount options can be overridden"
6367
6368 test_89() { # LU-7131
6369         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.9.54) ]] ||
6370                 skip "Need MDT version at least 2.9.54"
6371
6372         local key=failover.node
6373         local val1=192.0.2.254@tcp0 # Reserved IPs, see RFC 5735
6374         local val2=192.0.2.255@tcp0
6375         local mdsdev=$(mdsdevname 1)
6376         local params
6377
6378         stopall
6379
6380         [ $(facet_fstype mds1) == zfs ] && import_zpool mds1
6381         # Check that parameters are added correctly
6382         echo "tunefs --param $key=$val1"
6383         do_facet mds "$TUNEFS --param $key=$val1 $mdsdev >/dev/null" ||
6384                 error "tunefs --param $key=$val1 failed"
6385         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6386                 error "tunefs --dryrun failed"
6387         params=${params##*Parameters:}
6388         params=${params%%exiting*}
6389         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val1) = "1" ] ||
6390                 error "on-disk parameter not added correctly via tunefs"
6391
6392         # Check that parameters replace existing instances when added
6393         echo "tunefs --param $key=$val2"
6394         do_facet mds "$TUNEFS --param $key=$val2 $mdsdev >/dev/null" ||
6395                 error "tunefs --param $key=$val2 failed"
6396         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6397                 error "tunefs --dryrun failed"
6398         params=${params##*Parameters:}
6399         params=${params%%exiting*}
6400         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "1" ] ||
6401                 error "on-disk parameter not replaced via tunefs"
6402         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val2) = "1" ] ||
6403                 error "on-disk parameter not replaced correctly via tunefs"
6404
6405         # Check that a parameter is erased properly
6406         echo "tunefs --erase-param $key"
6407         do_facet mds "$TUNEFS --erase-param $key $mdsdev >/dev/null" ||
6408                 error "tunefs --erase-param $key failed"
6409         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6410                 error "tunefs --dryrun failed"
6411         params=${params##*Parameters:}
6412         params=${params%%exiting*}
6413         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "0" ] ||
6414                 error "on-disk parameter not erased correctly via tunefs"
6415
6416         # Check that all the parameters are erased
6417         echo "tunefs --erase-params"
6418         do_facet mds "$TUNEFS --erase-params $mdsdev >/dev/null" ||
6419                 error "tunefs --erase-params failed"
6420         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6421                 error "tunefs --dryrun failed"
6422         params=${params##*Parameters:}
6423         params=${params%%exiting*}
6424         [ -z $params ] ||
6425                 error "all on-disk parameters not erased correctly via tunefs"
6426
6427         # Check the order of options --erase-params and --param
6428         echo "tunefs --param $key=$val1 --erase-params"
6429         do_facet mds \
6430                 "$TUNEFS --param $key=$val1 --erase-params $mdsdev >/dev/null"||
6431                 error "tunefs --param $key=$val1 --erase-params failed"
6432         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6433                 error "tunefs --dryrun failed"
6434         params=${params##*Parameters:}
6435         params=${params%%exiting*}
6436         [ $(echo $params | tr ' ' '\n') == "$key=$val1" ] ||
6437                 error "on-disk param not added correctly with --erase-params"
6438
6439         reformat
6440 }
6441 run_test 89 "check tunefs --param and --erase-param{s} options"
6442
6443 # $1 test directory
6444 # $2 (optional) value of max_mod_rpcs_in_flight to set
6445 check_max_mod_rpcs_in_flight() {
6446         local dir="$1"
6447         local mmr="$2"
6448         local idx
6449         local facet
6450         local tmp
6451         local i
6452
6453         idx=$(printf "%04x" $($LFS getdirstripe -i $dir))
6454         facet="mds$((0x$idx + 1))"
6455
6456         if [ -z "$mmr" ]; then
6457                 # get value of max_mod_rcps_in_flight
6458                 mmr=$($LCTL get_param -n \
6459                         mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight) ||
6460                         error "Unable to get max_mod_rpcs_in_flight"
6461                 echo "max_mod_rcps_in_flight is $mmr"
6462         else
6463                 # set value of max_mod_rpcs_in_flight
6464                 $LCTL set_param \
6465                     mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight=$mmr ||
6466                         error "Unable to set max_mod_rpcs_in_flight to $mmr"
6467                 echo "max_mod_rpcs_in_flight set to $mmr"
6468         fi
6469
6470         # create mmr+1 files
6471         echo "creating $((mmr + 1)) files ..."
6472         umask 0022
6473         for i in $(seq $((mmr + 1))); do
6474                 touch $dir/file-$i
6475         done
6476
6477         ### part 1 ###
6478
6479         # consumes mmr-1 modify RPC slots
6480         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6481         # drop requests on MDT so that RPC slots are consumed
6482         # during all the request resend interval
6483         do_facet $facet "$LCTL set_param fail_loc=0x159"
6484         echo "launch $((mmr - 1)) chmod in parallel ..."
6485         for i in $(seq $((mmr - 1))); do
6486                 chmod 0600 $dir/file-$i &
6487         done
6488         sleep 1
6489
6490         # send one additional modify RPC
6491         do_facet $facet "$LCTL set_param fail_loc=0"
6492         echo "launch 1 additional chmod in parallel ..."
6493         chmod 0600 $dir/file-$mmr &
6494         sleep 1
6495
6496         # check this additional modify RPC get a modify RPC slot
6497         # and succeed its operation
6498         checkstat -vp 0600 $dir/file-$mmr ||
6499                 error "Unable to send $mmr modify RPCs in parallel"
6500         wait
6501
6502         ### part 2 ###
6503
6504         # consumes mmr modify RPC slots
6505         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6506         # drop requests on MDT so that RPC slots are consumed
6507         # during all the request resend interval
6508         do_facet $facet "$LCTL set_param fail_loc=0x159"
6509         echo "launch $mmr chmod in parallel ..."
6510         for i in $(seq $mmr); do
6511                 chmod 0666 $dir/file-$i &
6512         done
6513         sleep 1
6514
6515         # send one additional modify RPC
6516         do_facet $facet "$LCTL set_param fail_loc=0"
6517         echo "launch 1 additional chmod in parallel ..."
6518         chmod 0666 $dir/file-$((mmr + 1)) &
6519         sleep 1
6520
6521         # check this additional modify RPC blocked getting a modify RPC slot
6522         checkstat -vp 0644 $dir/file-$((mmr + 1)) ||
6523                 error "Unexpectedly send $(($mmr + 1)) modify RPCs in parallel"
6524         wait
6525 }
6526
6527 test_90a() {
6528         reformat
6529         if ! combined_mgs_mds ; then
6530                 start_mgs
6531         fi
6532         setup
6533
6534         [[ $($LCTL get_param mdc.*.import |
6535              grep "connect_flags:.*multi_mod_rpc") ]] ||
6536                 skip "Need MDC with 'multi_mod_rpcs' feature"
6537
6538         # check default value
6539         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6540         check_max_mod_rpcs_in_flight $DIR/$tdir
6541
6542         cleanup
6543 }
6544 run_test 90a "check max_mod_rpcs_in_flight is enforced"
6545
6546 test_90b() {
6547         local idx
6548         local facet
6549         local tmp
6550         local mmrpc
6551
6552         setup
6553
6554         [[ $($LCTL get_param mdc.*.import |
6555              grep "connect_flags:.*multi_mod_rpc") ]] ||
6556                 skip "Need MDC with 'multi_mod_rpcs' feature"
6557
6558         ### test 1.
6559         # update max_mod_rpcs_in_flight
6560         $LFS mkdir -c1 $DIR/${tdir}1 || error "mkdir $DIR/${tdir}1 failed"
6561         check_max_mod_rpcs_in_flight $DIR/${tdir}1 1
6562
6563         ### test 2.
6564         # check client is able to send multiple modify RPCs in paralell
6565         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
6566                 grep -c "multi_mod_rpcs")
6567         if [ "$tmp" -ne $MDSCOUNT ]; then
6568                 cleanup
6569                 skip "Client not able to send multiple modify RPCs in parallel"
6570         fi
6571
6572         # update max_mod_rpcs_in_flight
6573         $LFS mkdir -c1 $DIR/${tdir}2 || error "mkdir $DIR/${tdir}2 failed"
6574         check_max_mod_rpcs_in_flight $DIR/${tdir}2 5
6575
6576         ### test 3.
6577         $LFS mkdir -c1 $DIR/${tdir}3 || error "mkdir $DIR/${tdir}3 failed"
6578         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/${tdir}3))
6579         facet="mds$((0x$idx + 1))"
6580
6581         # save MDT max_mod_rpcs_per_client
6582         mmrpc=$(do_facet $facet \
6583                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
6584
6585         # update max_mod_rpcs_in_flight
6586         umount_client $MOUNT
6587         do_facet $facet \
6588                 "echo 16 > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6589         mount_client $MOUNT
6590         $LCTL set_param mdc.$FSNAME-MDT$idx-mdc-*.max_rpcs_in_flight=17
6591         check_max_mod_rpcs_in_flight $DIR/${tdir}3 16
6592
6593         # restore MDT max_mod_rpcs_per_client initial value
6594         do_facet $facet \
6595                 "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6596
6597         rm -rf $DIR/${tdir}?
6598         cleanup
6599 }
6600 run_test 90b "check max_mod_rpcs_in_flight is enforced after update"
6601
6602 test_90c() {
6603         local tmp
6604         local mrif
6605         local mmrpc
6606
6607         setup
6608
6609         [[ $($LCTL get_param mdc.*.import |
6610              grep "connect_flags:.*multi_mod_rpc") ]] ||
6611                 skip "Need MDC with 'multi_mod_rpcs' feature"
6612
6613         # check client is able to send multiple modify RPCs in paralell
6614         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
6615                 grep -c "multi_mod_rpcs")
6616         if [ "$tmp" -ne $MDSCOUNT ]; then
6617                 cleanup
6618                 skip "Client not able to send multiple modify RPCs in parallel"
6619         fi
6620
6621         # get max_rpcs_in_flight value
6622         mrif=$($LCTL get_param -n mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
6623         echo "max_rpcs_in_flight is $mrif"
6624
6625         # get MDT max_mod_rpcs_per_client
6626         mmrpc=$(do_facet mds1 \
6627                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
6628         echo "max_mod_rpcs_per_client is $mmrpc"
6629
6630         # testcase 1
6631         # attempt to set max_mod_rpcs_in_flight to max_rpcs_in_flight value
6632         # prerequisite: set max_mod_rpcs_per_client to max_rpcs_in_flight value
6633         umount_client $MOUNT
6634         do_facet mds1 \
6635                 "echo $mrif > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6636         mount_client $MOUNT
6637
6638         $LCTL set_param \
6639             mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif &&
6640             error "set max_mod_rpcs_in_flight to $mrif should fail"
6641
6642         umount_client $MOUNT
6643         do_facet mds1 \
6644                 "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6645         mount_client $MOUNT
6646
6647         # testcase 2
6648         # attempt to set max_mod_rpcs_in_flight to max_mod_rpcs_per_client+1
6649         # prerequisite: set max_rpcs_in_flight to max_mod_rpcs_per_client+2
6650         $LCTL set_param \
6651             mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$((mmrpc + 2))
6652
6653         $LCTL set_param \
6654             mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$((mmrpc + 1)) &&
6655             error "set max_mod_rpcs_in_flight to $((mmrpc + 1)) should fail"
6656
6657         cleanup
6658 }
6659 run_test 90c "check max_mod_rpcs_in_flight update limits"
6660
6661 test_90d() {
6662         local idx
6663         local facet
6664         local mmr
6665         local i
6666         local pid
6667
6668         setup
6669
6670         [[ $($LCTL get_param mdc.*.import |
6671              grep "connect_flags:.*multi_mod_rpc") ]] ||
6672                 skip "Need MDC with 'multi_mod_rpcs' feature"
6673
6674         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6675         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
6676         facet="mds$((0x$idx + 1))"
6677
6678         # check client version supports multislots
6679         tmp=$($LCTL get_param -N \
6680                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
6681         if [ -z "$tmp" ]; then
6682                 cleanup
6683                 skip "Client does not support multiple modify RPCs in flight"
6684         fi
6685
6686         # get current value of max_mod_rcps_in_flight
6687         mmr=$($LCTL get_param -n \
6688                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
6689         echo "max_mod_rcps_in_flight is $mmr"
6690
6691         # create mmr files
6692         echo "creating $mmr files ..."
6693         umask 0022
6694         for i in $(seq $mmr); do
6695                 touch $DIR/$tdir/file-$i
6696         done
6697
6698         # prepare for close RPC
6699         multiop_bg_pause $DIR/$tdir/file-close O_c
6700         pid=$!
6701
6702         # consumes mmr modify RPC slots
6703         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6704         # drop requests on MDT so that RPC slots are consumed
6705         # during all the request resend interval
6706         do_facet $facet "$LCTL set_param fail_loc=0x159"
6707         echo "launch $mmr chmod in parallel ..."
6708         for i in $(seq $mmr); do
6709                 chmod 0600 $DIR/$tdir/file-$i &
6710         done
6711
6712         # send one additional close RPC
6713         do_facet $facet "$LCTL set_param fail_loc=0"
6714         echo "launch 1 additional close in parallel ..."
6715         kill -USR1 $pid
6716         cancel_lru_locks mdc
6717         sleep 1
6718
6719         # check this additional close RPC get a modify RPC slot
6720         # and multiop process completed
6721         [ -d /proc/$pid ] &&
6722                 error "Unable to send the additional close RPC in parallel"
6723         wait
6724         rm -rf $DIR/$tdir
6725         cleanup
6726 }
6727 run_test 90d "check one close RPC is allowed above max_mod_rpcs_in_flight"
6728
6729 check_uuid_on_ost() {
6730         local nid=$1
6731         do_facet ost1 "$LCTL get_param obdfilter.${FSNAME}*.exports.'$nid'.uuid"
6732 }
6733
6734 check_uuid_on_mdt() {
6735         local nid=$1
6736         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
6737 }
6738
6739 test_91() {
6740         local uuid
6741         local nid
6742         local found
6743
6744         [[ $(lustre_version_code ost1) -ge $(version_code 2.7.63) ]] ||
6745                 skip "Need OST version at least 2.7.63"
6746         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.63) ]] ||
6747                 skip "Need MDT version at least 2.7.63"
6748
6749         start_mds || error "MDS start failed"
6750         start_ost || error "unable to start OST"
6751         mount_client $MOUNT || error "client start failed"
6752         check_mount || error "check_mount failed"
6753
6754         if remote_mds; then
6755                 nid=$($LCTL list_nids | head -1 | sed  "s/\./\\\./g")
6756         else
6757                 nid="0@lo"
6758         fi
6759         uuid=$(get_client_uuid $MOUNT)
6760
6761         echo "list nids on mdt:"
6762         do_facet $SINGLEMDS "$LCTL list_param mdt.${FSNAME}*.exports.*"
6763         echo "uuid from $nid:"
6764         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
6765
6766         found=$(check_uuid_on_mdt $nid | grep $uuid)
6767         [ -z "$found" ] && error "can't find $uuid $nid on MDT"
6768         found=$(check_uuid_on_ost $nid | grep $uuid)
6769         [ -z "$found" ] && error "can't find $uuid $nid on OST"
6770
6771         # umount the client so it won't reconnect
6772         manual_umount_client --force || error "failed to umount $?"
6773         # shouldn't disappear on MDS after forced umount
6774         found=$(check_uuid_on_mdt $nid | grep $uuid)
6775         [ -z "$found" ] && error "can't find $uuid $nid"
6776
6777         echo "evict $nid"
6778         do_facet $SINGLEMDS \
6779                 "$LCTL set_param -n mdt.${mds1_svc}.evict_client nid:$nid"
6780
6781         found=$(check_uuid_on_mdt $nid | grep $uuid)
6782         [ -n "$found" ] && error "found $uuid $nid on MDT"
6783         found=$(check_uuid_on_ost $nid | grep $uuid)
6784         [ -n "$found" ] && error "found $uuid $nid on OST"
6785
6786         # check it didn't reconnect (being umounted)
6787         sleep $((TIMEOUT+1))
6788         found=$(check_uuid_on_mdt $nid | grep $uuid)
6789         [ -n "$found" ] && error "found $uuid $nid on MDT"
6790         found=$(check_uuid_on_ost $nid | grep $uuid)
6791         [ -n "$found" ] && error "found $uuid $nid on OST"
6792
6793         cleanup
6794 }
6795 run_test 91 "evict-by-nid support"
6796
6797 generate_ldev_conf() {
6798         # generate an ldev.conf file
6799         local ldevconfpath=$1
6800         local fstype=
6801         local fsldevformat=""
6802         touch $ldevconfpath
6803
6804         fstype=$(facet_fstype mgs)
6805         if [ "$fstype" == "zfs" ]; then
6806                 fsldevformat="$fstype:"
6807         else
6808                 fsldevformat=""
6809         fi
6810
6811         printf "%s\t-\t%s-MGS0000\t%s%s\n" \
6812                 $mgs_HOST \
6813                 $FSNAME \
6814                 $fsldevformat \
6815                 $(mgsdevname) > $ldevconfpath
6816
6817         local mdsfo_host=$mdsfailover_HOST;
6818         if [ -z "$mdsfo_host" ]; then
6819                 mdsfo_host="-"
6820         fi
6821
6822         for num in $(seq $MDSCOUNT); do
6823                 fstype=$(facet_fstype mds$num)
6824                 if [ "$fstype" == "zfs" ]; then
6825                         fsldevformat="$fstype:"
6826                 else
6827                         fsldevformat=""
6828                 fi
6829
6830                 printf "%s\t%s\t%s-MDT%04d\t%s%s\n" \
6831                         $mds_HOST \
6832                         $mdsfo_host \
6833                         $FSNAME \
6834                         $num \
6835                         $fsldevformat \
6836                         $(mdsdevname $num) >> $ldevconfpath
6837         done
6838
6839         local ostfo_host=$ostfailover_HOST;
6840         if [ -z "$ostfo_host" ]; then
6841                 ostfo_host="-"
6842         fi
6843
6844         for num in $(seq $OSTCOUNT); do
6845                 fstype=$(facet_fstype ost$num)
6846                 if [ "$fstype" == "zfs" ]; then
6847                         fsldevformat="$fstype:"
6848                 else
6849                         fsldevformat=""
6850                 fi
6851
6852                 printf "%s\t%s\t%s-OST%04d\t%s%s\n" \
6853                         $ost_HOST \
6854                         $ostfo_host \
6855                         $FSNAME \
6856                         $num \
6857                         $fsldevformat \
6858                         $(ostdevname $num) >> $ldevconfpath
6859         done
6860
6861         echo "----- $ldevconfpath -----"
6862         cat $ldevconfpath
6863         echo "--- END $ldevconfpath ---"
6864
6865 }
6866
6867 generate_nids() {
6868         # generate a nids file (mapping between hostname to nid)
6869         # looks like we only have the MGS nid available to us
6870         # so just echo that to a file
6871         local nidspath=$1
6872         echo -e "${mgs_HOST}\t${MGSNID}" > $nidspath
6873
6874         echo "----- $nidspath -----"
6875         cat $nidspath
6876         echo "--- END $nidspath ---"
6877 }
6878
6879 compare_ldev_output() {
6880         ldev_output=$1
6881         expected_output=$2
6882
6883         sort $expected_output -o $expected_output
6884         sort $ldev_output -o $ldev_output
6885
6886         echo "-- START OF LDEV OUTPUT --"
6887         cat $ldev_output
6888         echo "--- END OF LDEV OUTPUT ---"
6889
6890         echo "-- START OF EXPECTED OUTPUT --"
6891         cat $expected_output
6892         echo "--- END OF EXPECTED OUTPUT ---"
6893
6894         diff $expected_output $ldev_output
6895         return $?
6896 }
6897
6898 test_92() {
6899         if [ -z "$LDEV" ]; then
6900                 error "ldev is missing!"
6901         fi
6902
6903         local LDEVCONFPATH=$TMP/ldev.conf
6904         local NIDSPATH=$TMP/nids
6905
6906         echo "Host is $(hostname)"
6907
6908         generate_ldev_conf $LDEVCONFPATH
6909         generate_nids $NIDSPATH
6910
6911         # echo the mgs nid and compare it to environment variable MGSNID
6912         # also, ldev.conf and nids is a server side thing, use the OSS
6913         # hostname
6914         local output
6915         output=$($LDEV -c $LDEVCONFPATH -H $ost_HOST -n $NIDSPATH echo %m)
6916
6917         echo "-- START OF LDEV OUTPUT --"
6918         echo -e "$output"
6919         echo "--- END OF LDEV OUTPUT ---"
6920
6921         # ldev failed, error
6922         if [ $? -ne 0 ]; then
6923                 rm $LDEVCONFPATH $NIDSPATH
6924                 error "ldev failed to execute!"
6925         fi
6926
6927         # need to process multiple lines because of combined MGS and MDS
6928         echo -e $output | awk '{ print $2 }' | while read -r line ; do
6929                 if [ "$line" != "$MGSNID" ]; then
6930                         rm $LDEVCONFPATH $NIDSPATH
6931                         error "ldev failed mgs nid '$line', expected '$MGSNID'"
6932                 fi
6933         done
6934
6935         rm $LDEVCONFPATH $NIDSPATH
6936 }
6937 run_test 92 "ldev returns MGS NID correctly in command substitution"
6938
6939 test_93() {
6940         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs"
6941
6942         reformat
6943         #start mgs or mgs/mdt0
6944         if ! combined_mgs_mds ; then
6945                 start_mgs
6946                 start_mdt 1
6947         else
6948                 start_mdt 1
6949         fi
6950
6951         start_ost || error "OST0 start fail"
6952
6953         #define OBD_FAIL_MGS_WRITE_TARGET_DELAY  0x90e
6954         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x8000090e"
6955         for num in $(seq 2 $MDSCOUNT); do
6956                 start_mdt $num &
6957         done
6958
6959         mount_client $MOUNT || error "mount client fails"
6960         wait_osc_import_state mds ost FULL
6961         wait_osc_import_ready client ost
6962         check_mount || error "check_mount failed"
6963
6964         cleanup || error "cleanup failed with $?"
6965 }
6966 run_test 93 "register mulitple MDT at the same time"
6967
6968 test_94() {
6969         if [ -z "$LDEV" ]; then
6970                 error "ldev is missing!"
6971         fi
6972
6973         local LDEVCONFPATH=$TMP/ldev.conf
6974         local NIDSPATH=$TMP/nids
6975
6976         generate_ldev_conf $LDEVCONFPATH
6977         generate_nids $NIDSPATH
6978
6979         local LDEV_OUTPUT=$TMP/ldev-output.txt
6980         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME > $LDEV_OUTPUT
6981
6982         # ldev failed, error
6983         if [ $? -ne 0 ]; then
6984                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
6985                 error "ldev failed to execute!"
6986         fi
6987
6988         # expected output
6989         local EXPECTED_OUTPUT=$TMP/ldev-expected.txt
6990
6991         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
6992
6993         for num in $(seq $MDSCOUNT); do
6994                 printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
6995         done
6996
6997         for num in $(seq $OSTCOUNT); do
6998                 printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
6999         done
7000
7001         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7002
7003         if [ $? -ne 0 ]; then
7004                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7005                 error "ldev failed to produce the correct hostlist!"
7006         fi
7007
7008         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7009 }
7010 run_test 94 "ldev outputs correct labels for file system name query"
7011
7012 test_95() {
7013         if [ -z "$LDEV" ]; then
7014                 error "ldev is missing!"
7015         fi
7016
7017         local LDEVCONFPATH=$TMP/ldev.conf
7018         local NIDSPATH=$TMP/nids
7019
7020         generate_ldev_conf $LDEVCONFPATH
7021         generate_nids $NIDSPATH
7022
7023         # SUCCESS CASES
7024         # file sys filter
7025         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME &>/dev/null
7026         if [ $? -ne 0 ]; then
7027                 rm $LDEVCONFPATH $NIDSPATH
7028                 error "ldev label filtering w/ -F failed!"
7029         fi
7030
7031         # local filter
7032         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -l  &>/dev/null
7033         if [ $? -ne 0 ]; then
7034                 rm $LDEVCONFPATH $NIDSPATH
7035                 error "ldev label filtering w/ -l failed!"
7036         fi
7037
7038         # foreign filter
7039         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f &>/dev/null
7040         if [ $? -ne 0 ]; then
7041                 rm $LDEVCONFPATH $NIDSPATH
7042                 error "ldev label filtering w/ -f failed!"
7043         fi
7044
7045         # all filter
7046         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a &>/dev/null
7047         if [ $? -ne 0 ]; then
7048                 rm $LDEVCONFPATH $NIDSPATH
7049                 error "ldev label filtering w/ -a failed!"
7050         fi
7051
7052         # FAILURE CASES
7053         # all & file sys
7054         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -F $FSNAME &>/dev/null
7055         if [ $? -eq 0 ]; then
7056                 rm $LDEVCONFPATH $NIDSPATH
7057                 error "ldev label filtering w/ -a and -F incorrectly succeeded"
7058         fi
7059
7060         # all & foreign
7061         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -f &>/dev/null
7062         if [ $? -eq 0 ]; then
7063                 rm $LDEVCONFPATH $NIDSPATH
7064                 error "ldev label filtering w/ -a and -f incorrectly succeeded"
7065         fi
7066
7067         # all & local
7068         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -l &>/dev/null
7069         if [ $? -eq 0 ]; then
7070                 rm $LDEVCONFPATH $NIDSPATH
7071                 error "ldev label filtering w/ -a and -l incorrectly succeeded"
7072         fi
7073
7074         # foreign & local
7075         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f -l &>/dev/null
7076         if [ $? -eq 0 ]; then
7077                 rm $LDEVCONFPATH $NIDSPATH
7078                 error "ldev label filtering w/ -f and -l incorrectly succeeded"
7079         fi
7080
7081         # file sys & local
7082         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -l &>/dev/null
7083         if [ $? -eq 0 ]; then
7084                 rm $LDEVCONFPATH $NIDSPATH
7085                 error "ldev label filtering w/ -F and -l incorrectly succeeded"
7086         fi
7087
7088         # file sys & foreign
7089         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -f &>/dev/null
7090         if [ $? -eq 0 ]; then
7091                 rm $LDEVCONFPATH $NIDSPATH
7092                 error "ldev label filtering w/ -F and -f incorrectly succeeded"
7093         fi
7094
7095         rm $LDEVCONFPATH $NIDSPATH
7096 }
7097 run_test 95 "ldev should only allow one label filter"
7098
7099 test_96() {
7100         if [ -z "$LDEV" ]; then
7101                 error "ldev is missing!"
7102         fi
7103
7104         local LDEVCONFPATH=$TMP/ldev.conf
7105         local NIDSPATH=$TMP/nids
7106
7107         generate_ldev_conf $LDEVCONFPATH
7108         generate_nids $NIDSPATH
7109
7110         local LDEV_OUTPUT=$TMP/ldev-output.txt
7111         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -H $mgs_HOST \
7112                 echo %H-%b | \
7113                 awk '{print $2}' > $LDEV_OUTPUT
7114
7115         # ldev failed, error
7116         if [ $? -ne 0 ]; then
7117                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7118                 error "ldev failed to execute!"
7119         fi
7120
7121         # expected output
7122         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
7123
7124         echo "$mgs_HOST-$(facet_fstype mgs)" > $EXPECTED_OUTPUT
7125
7126         if [ "$mgs_HOST" == "$mds_HOST" ]; then
7127                 for num in $(seq $MDSCOUNT); do
7128                         echo "$mds_HOST-$(facet_fstype mds$num)" \
7129                         >> $EXPECTED_OUTPUT
7130                 done
7131         fi
7132
7133         if [ "$mgs_HOST" == "$ost_HOST" ]; then
7134                 for num in $(seq $OSTCOUNT); do
7135                         echo "$ost_HOST-$(facet_fstype ost$num)" \
7136                         >> $EXPECTED_OUTPUT
7137                 done
7138         fi
7139
7140         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7141
7142         if [ $? -ne 0 ]; then
7143                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7144                 error "ldev failed to produce the correct output!"
7145         fi
7146
7147         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7148 }
7149 run_test 96 "ldev returns hostname and backend fs correctly in command sub"
7150
7151 test_97() {
7152         if [ -z "$LDEV" ]; then
7153                 error "ldev is missing!"
7154         fi
7155
7156         local LDEVCONFPATH=$TMP/ldev.conf
7157         local NIDSPATH=$TMP/nids
7158
7159         generate_ldev_conf $LDEVCONFPATH
7160         generate_nids $NIDSPATH
7161
7162         local LDEV_OUTPUT=$TMP/ldev-output.txt
7163         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
7164
7165         echo -e "\nMDT role"
7166         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mdt > $LDEV_OUTPUT
7167
7168         if [ $? -ne 0 ]; then
7169                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7170                 error "ldev failed to execute for mdt role!"
7171         fi
7172
7173         for num in $(seq $MDSCOUNT); do
7174                 printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7175         done
7176
7177         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7178
7179         if [ $? -ne 0 ]; then
7180                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7181                 error "ldev failed to produce the correct output for mdt role!"
7182         fi
7183
7184         echo -e "\nOST role"
7185         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R ost > $LDEV_OUTPUT
7186
7187         if [ $? -ne 0 ]; then
7188                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
7189                 error "ldev failed to execute for ost role!"
7190         fi
7191
7192         rm $EXPECTED_OUTPUT
7193         for num in $(seq $OSTCOUNT); do
7194                 printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7195         done
7196
7197         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7198
7199         if [ $? -ne 0 ]; then
7200                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7201                 error "ldev failed to produce the correct output for ost role!"
7202         fi
7203
7204         echo -e "\nMGS role"
7205         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mgs > $LDEV_OUTPUT
7206
7207         if [ $? -ne 0 ]; then
7208                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
7209                 error "ldev failed to execute for mgs role!"
7210         fi
7211
7212         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
7213
7214         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7215
7216         if [ $? -ne 0 ]; then
7217                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7218                 error "ldev failed to produce the correct output for mgs role!"
7219         fi
7220
7221         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7222 }
7223 run_test 97 "ldev returns correct ouput when querying based on role"
7224
7225 test_98()
7226 {
7227         local mountopt
7228         local temp=$MDS_MOUNT_OPTS
7229
7230         setup
7231         check_mount || error "mount failed"
7232         mountopt="user_xattr"
7233         for ((x = 1; x <= 400; x++)); do
7234                 mountopt="$mountopt,user_xattr"
7235         done
7236         remount_client $mountopt $MOUNT  2>&1 | grep "too long" ||
7237                 error "Buffer overflow check failed"
7238         cleanup || error "cleanup failed"
7239 }
7240 run_test 98 "Buffer-overflow check while parsing mount_opts"
7241
7242 test_99()
7243 {
7244         [[ $(facet_fstype ost1) != ldiskfs ]] &&
7245                 skip "ldiskfs only test"
7246         [[ $(lustre_version_code ost1) -ge $(version_code 2.8.57) ]] ||
7247                 skip "Need OST version at least 2.8.57"
7248
7249         local ost_opts="$(mkfs_opts ost1 $(ostdevname 1)) \
7250                 --reformat $(ostdevname 1) $(ostvdevname 1)"
7251         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" &&
7252                 skip "meta_bg already set"
7253
7254         local opts=ost_opts
7255         if [[ ${!opts} != *mkfsoptions* ]]; then
7256                 eval opts=\"${!opts} \
7257                 --mkfsoptions='\\\"-O ^resize_inode,meta_bg\\\"'\"
7258         else
7259                 local val=${!opts//--mkfsoptions=\\\"/ \
7260                 --mkfsoptions=\\\"-O ^resize_inode,meta_bg }
7261                 eval opts='${val}'
7262         fi
7263
7264         echo "params: $opts"
7265
7266         add ost1 $opts || error "add ost1 failed with new params"
7267
7268         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" ||
7269                 error "meta_bg is not set"
7270
7271         reformat
7272 }
7273 run_test 99 "Adding meta_bg option"
7274
7275 test_100() {
7276         reformat
7277         start_mds || error "MDS start failed"
7278         start_ost || error "unable to start OST"
7279         mount_client $MOUNT || error "client start failed"
7280         check_mount || error "check_mount failed"
7281
7282         # Desired output
7283         # MGS:
7284         #     0@lo
7285         # lustre-MDT0000:
7286         #     0@lo
7287         # lustre-OST0000:
7288         #     0@lo
7289         do_facet mgs 'lshowmount -v' | awk 'BEGIN {NR == 0; rc=1} /MGS:/ {rc=0}
7290                 END {exit rc}' || error "lshowmount have no output MGS"
7291
7292         do_facet mds1 'lshowmount -v' | awk 'BEGIN {NR == 2; rc=1} /-MDT0000:/
7293                 {rc=0} END {exit rc}' || error "lshowmount have no output MDT0"
7294
7295         do_facet ost1 'lshowmount -v' | awk 'BEGIN {NR == 4; rc=1} /-OST0000:/
7296                 {rc=0} END {exit rc}' || error "lshowmount have no output OST0"
7297
7298         cleanup || error "cleanup failed with $?"
7299 }
7300 run_test 100 "check lshowmount lists MGS, MDT, OST and 0@lo"
7301
7302 test_101() {
7303         local createmany_pid
7304         local dev=$FSNAME-OST0000-osc-MDT0000
7305         setup
7306
7307         mkdir $DIR1/$tdir
7308         createmany -o $DIR1/$tdir/$tfile-%d 50000 &
7309         createmany_pid=$!
7310         # MDT->OST reconnection causes MDT<->OST last_id synchornisation
7311         # via osp_precreate_cleanup_orphans.
7312         for ((i = 0; i < 100; i++)); do
7313                 for ((k = 0; k < 10; k++)); do
7314                         do_facet $SINGLEMDS "$LCTL --device $dev deactivate;" \
7315                                             "$LCTL --device $dev activate"
7316                 done
7317
7318                 ls -asl $MOUNT | grep '???' &&
7319                         { kill -9 $createmany_pid &>/dev/null;
7320                           error "File has no object on OST"; }
7321
7322                 kill -s 0 $createmany_pid || break
7323         done
7324         wait $createmany_pid
7325
7326         unlinkmany $DIR1/$tdir/$tfile-%d 50000
7327         cleanup
7328 }
7329 run_test 101 "Race MDT->OST reconnection with create"
7330
7331 test_102() {
7332         [[ $(lustre_version_code $SINGLEMDS) -gt $(version_code 2.9.53) ]] ||
7333                 skip "Need server version greater than 2.9.53"
7334         cleanup || error "cleanup failed with $?"
7335
7336         local mds1dev=$(mdsdevname 1)
7337         local mds1mnt=$(facet_mntpt mds1)
7338         local mds1fstype=$(facet_fstype mds1)
7339         local mds1opts=$MDS_MOUNT_OPTS
7340
7341         if [ $mds1fstype == ldiskfs ] &&
7342            ! do_facet mds1 test -b $mds1dev; then
7343                 mds1opts=$(csa_add "$mds1opts" -o loop)
7344         fi
7345         if [[ $mds1fstype == zfs ]]; then
7346                 import_zpool mds1 || return ${PIPESTATUS[0]}
7347         fi
7348
7349         # unload all and only load libcfs to allow fail_loc setting
7350         do_facet mds1 $LUSTRE_RMMOD || error "unable to unload modules"
7351         do_facet mds1 modprobe libcfs || error "libcfs not loaded"
7352         do_facet mds1 lsmod \| grep libcfs || error "libcfs not loaded"
7353
7354         #define OBD_FAIL_OBDCLASS_MODULE_LOAD    0x60a
7355         do_facet mds1 "$LCTL set_param fail_loc=0x8000060a"
7356
7357         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts &&
7358                 error "mdt start must fail"
7359         do_facet mds1 lsmod \| grep  obdclass && error "obdclass must not load"
7360
7361         do_facet mds1 "$LCTL set_param fail_loc=0x0"
7362
7363         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts ||
7364                 error "mdt start must not fail"
7365
7366         cleanup || error "cleanup failed with $?"
7367 }
7368 run_test 102 "obdclass module cleanup upon error"
7369
7370 test_renamefs() {
7371         local newname=$1
7372
7373         echo "rename $FSNAME to $newname"
7374
7375         if ! combined_mgs_mds ; then
7376                 local facet=$(mgsdevname)
7377
7378                 do_facet mgs \
7379                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $facet"||
7380                         error "(7) Fail to rename MGS"
7381                 if [ "$(facet_fstype $facet)" = "zfs" ]; then
7382                         reimport_zpool mgs $newname-mgs
7383                 fi
7384         fi
7385
7386         for num in $(seq $MDSCOUNT); do
7387                 local facet=$(mdsdevname $num)
7388
7389                 do_facet mds${num} \
7390                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $facet"||
7391                         error "(8) Fail to rename MDT $num"
7392                 if [ "$(facet_fstype $facet)" = "zfs" ]; then
7393                         reimport_zpool mds${num} $newname-mdt${num}
7394                 fi
7395         done
7396
7397         for num in $(seq $OSTCOUNT); do
7398                 local facet=$(ostdevname $num)
7399
7400                 do_facet ost${num} \
7401                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $facet"||
7402                         error "(9) Fail to rename OST $num"
7403                 if [ "$(facet_fstype $facet)" = "zfs" ]; then
7404                         reimport_zpool ost${num} $newname-ost${num}
7405                 fi
7406         done
7407 }
7408
7409 test_103_set_pool() {
7410         local pname=$1
7411         local ost_x=$2
7412
7413         do_facet mgs $LCTL pool_add $FSNAME.$pname ${FSNAME}-$ost_x ||
7414                 error "Fail to add $ost_x to $FSNAME.$pname"
7415         wait_update $HOSTNAME \
7416                 "lctl get_param -n lov.$FSNAME-clilov-*.pools.$pname |
7417                  grep $ost_x" "$FSNAME-${ost_x}_UUID" ||
7418                 error "$ost_x is NOT in pool $FSNAME.$pname"
7419 }
7420
7421 test_103_check_pool() {
7422         local save_fsname=$1
7423         local errno=$2
7424
7425         stat $DIR/$tdir/test-framework.sh ||
7426                 error "($errno) Fail to stat"
7427         do_facet mgs $LCTL pool_list $FSNAME.pool1 ||
7428                 error "($errno) Fail to list $FSNAME.pool1"
7429         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname ||
7430                 error "($errno) Fail to list $FSNAME.$save_fsname"
7431         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname |
7432                 grep ${FSNAME}-OST0000 ||
7433                 error "($errno) List $FSNAME.$save_fsname is invalid"
7434
7435         local pname=$($LFS getstripe --pool $DIR/$tdir/d0)
7436         [ "$pname" = "$save_fsname" ] ||
7437                 error "($errno) Unexpected pool name $pname"
7438 }
7439
7440 test_103() {
7441         check_mount_and_prep
7442         rm -rf $DIR/$tdir
7443         mkdir $DIR/$tdir || error "(1) Fail to mkdir $DIR/$tdir"
7444         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir ||
7445                 error "(2) Fail to copy test-framework.sh"
7446
7447         if ! combined_mgs_mds ; then
7448                 mount_mgs_client
7449         fi
7450         do_facet mgs $LCTL pool_new $FSNAME.pool1 ||
7451                 error "(3) Fail to create $FSNAME.pool1"
7452         # name the pool name as the fsname
7453         do_facet mgs $LCTL pool_new $FSNAME.$FSNAME ||
7454                 error "(4) Fail to create $FSNAME.$FSNAME"
7455
7456         test_103_set_pool $FSNAME OST0000
7457
7458         $LFS setstripe -p $FSNAME $DIR/$tdir/d0 ||
7459                 error "(6) Fail to setstripe on $DIR/$tdir/d0"
7460
7461         if ! combined_mgs_mds ; then
7462                 umount_mgs_client
7463         fi
7464         KEEP_ZPOOL=true
7465         stopall
7466
7467         test_renamefs mylustre
7468
7469         local save_fsname=$FSNAME
7470         FSNAME="mylustre"
7471         setupall
7472
7473         if ! combined_mgs_mds ; then
7474                 mount_mgs_client
7475         fi
7476         test_103_check_pool $save_fsname 7
7477
7478         if [ $OSTCOUNT -ge 2 ]; then
7479                 test_103_set_pool $save_fsname OST0001
7480         fi
7481
7482         $LFS setstripe -p $save_fsname $DIR/$tdir/f0 ||
7483                 error "(16) Fail to setstripe on $DIR/$tdir/f0"
7484         if ! combined_mgs_mds ; then
7485                 umount_mgs_client
7486         fi
7487
7488         stopall
7489
7490         test_renamefs tfs
7491
7492         FSNAME="tfs"
7493         setupall
7494
7495         if ! combined_mgs_mds ; then
7496                 mount_mgs_client
7497         fi
7498         test_103_check_pool $save_fsname 17
7499
7500         if ! combined_mgs_mds ; then
7501                 umount_mgs_client
7502         fi
7503         stopall
7504
7505         test_renamefs $save_fsname
7506
7507         FSNAME=$save_fsname
7508         setupall
7509         KEEP_ZPOOL=false
7510 }
7511 run_test 103 "rename filesystem name"
7512
7513 test_104() { # LU-6952
7514         local mds_mountopts=$MDS_MOUNT_OPTS
7515         local ost_mountopts=$OST_MOUNT_OPTS
7516         local mds_mountfsopts=$MDS_MOUNT_FS_OPTS
7517         local lctl_ver=$(do_facet $SINGLEMDS $LCTL --version |
7518                         awk '{ print $2 }')
7519
7520         [[ $(version_code $lctl_ver) -lt $(version_code 2.9.55) ]] &&
7521                 skip "this test needs utils above 2.9.55"
7522
7523         # specify "acl" in mount options used by mkfs.lustre
7524         if [ -z "$MDS_MOUNT_FS_OPTS" ]; then
7525                 MDS_MOUNT_FS_OPTS="acl,user_xattr"
7526         else
7527
7528                 MDS_MOUNT_FS_OPTS="${MDS_MOUNT_FS_OPTS},acl,user_xattr"
7529         fi
7530
7531         echo "mountfsopt: $MDS_MOUNT_FS_OPTS"
7532
7533         #reformat/remount the MDT to apply the MDT_MOUNT_FS_OPT options
7534         formatall
7535         if [ -z "$MDS_MOUNT_OPTS" ]; then
7536                 MDS_MOUNT_OPTS="-o noacl"
7537         else
7538                 MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7539         fi
7540
7541         for num in $(seq $MDSCOUNT); do
7542                 start mds$num $(mdsdevname $num) $MDS_MOUNT_OPTS ||
7543                         error "Failed to start MDS"
7544         done
7545
7546         for num in $(seq $OSTCOUNT); do
7547                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
7548                         error "Failed to start OST"
7549         done
7550
7551         mount_client $MOUNT
7552         setfacl -m "d:$RUNAS_ID:rwx" $MOUNT &&
7553                 error "ACL is applied when FS is mounted with noacl."
7554
7555         MDS_MOUNT_OPTS=$mds_mountopts
7556         OST_MOUNT_OPTS=$ost_mountopts
7557         MDS_MOUNT_FS_OPTS=$mds_mountfsopts
7558
7559         formatall
7560         setupall
7561 }
7562 run_test 104 "Make sure user defined options are reflected in mount"
7563
7564 error_and_umount() {
7565         umount $TMP/$tdir
7566         rmdir $TMP/$tdir
7567         error $*
7568 }
7569
7570 test_105() {
7571         cleanup -f
7572         reformat
7573         setup
7574         mkdir -p $TMP/$tdir
7575         mount --bind $DIR $TMP/$tdir || error "mount bind mnt pt failed"
7576         rm -f $TMP/$tdir/$tfile
7577         rm -f $TMP/$tdir/${tfile}1
7578
7579         # Files should not be created in ro bind mount point
7580         # remounting from rw to ro
7581         mount -o remount,ro $TMP/$tdir ||
7582                 error_and_umount "readonly remount of bind mnt pt failed"
7583         touch $TMP/$tdir/$tfile &&
7584                 error_and_umount "touch succeeds on ro bind mnt pt"
7585         [ -e $TMP/$tdir/$tfile ] &&
7586                 error_and_umount "file created on ro bind mnt pt"
7587
7588         # Files should be created in rw bind mount point
7589         # remounting from ro to rw
7590         mount -o remount,rw $TMP/$tdir ||
7591                 error_and_umount "read-write remount of bind mnt pt failed"
7592         touch $TMP/$tdir/${tfile}1 ||
7593                 error_and_umount "touch fails on rw bind mnt pt"
7594         [ -e $TMP/$tdir/${tfile}1 ] ||
7595                 error_and_umount "file not created on rw bind mnt pt"
7596         umount $TMP/$tdir || error "umount of bind mnt pt failed"
7597         rmdir $TMP/$tdir
7598         cleanup || error "cleanup failed with $?"
7599 }
7600 run_test 105 "check file creation for ro and rw bind mnt pt"
7601
7602 test_106() {
7603         local repeat=5
7604
7605         reformat
7606         setupall
7607         mkdir -p $DIR/$tdir || error "create $tdir failed"
7608         lfs setstripe -c 1 -i 0 $DIR/$tdir
7609 #define OBD_FAIL_CAT_RECORDS                        0x1312
7610         do_facet mds1 $LCTL set_param fail_loc=0x1312 fail_val=$repeat
7611
7612         for ((i = 1; i <= $repeat; i++)); do
7613
7614                 #one full plain llog
7615                 createmany -o $DIR/$tdir/f- 64768
7616
7617                 createmany -u $DIR/$tdir/f- 64768
7618         done
7619         wait_delete_completed $((TIMEOUT * 7))
7620 #ASSERTION osp_sync_thread() ( thread->t_flags != SVC_RUNNING ) failed
7621 #shows that osp code is buggy
7622         do_facet mds1 $LCTL set_param fail_loc=0 fail_val=0
7623
7624         stopall
7625 }
7626 run_test 106 "check osp llog processing when catalog is wrapped"
7627
7628 test_107() {
7629         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.10.50) ]] ||
7630                 skip "Need MDS version > 2.10.50"
7631         local cmd
7632
7633         start_mgsmds || error "start_mgsmds failed"
7634         start_ost || error "unable to start OST"
7635
7636         # add unknown configuration parameter.
7637         if [[ $PERM_CMD == *"set_param -P"* ]]; then
7638                 cmd="$PERM_CMD ost.$FSNAME-OST0000*.unknown_param"
7639         else
7640                 cmd="$PERM_CMD $FSNAME-OST0000*.ost.unknown_param"
7641         fi
7642         do_facet mgs "$cmd=50"
7643         cleanup_nocli || error "cleanup_nocli failed with $?"
7644         load_modules
7645
7646         # unknown param should be ignored while mounting.
7647         start_ost || error "unable to start OST after unknown param set"
7648
7649         cleanup || error "cleanup failed with $?"
7650 }
7651 run_test 107 "Unknown config param should not fail target mounting"
7652
7653 t_108_prep() {
7654         local facet
7655
7656         $rcmd rm -rf $tmp > /dev/null 2>&1
7657         $rcmd mkdir -p $tmp/{mnt,images} || error "failed to mkdir remotely"
7658
7659         for facet in $facets; do
7660                 [ $(facet_fstype $SINGLEMDS) = "zfs" ] &&
7661                         $rcmd $ZPOOL -f export lustre-$facet > /dev/null 2>&1
7662                 $rcmd mkdir $tmp/mnt/$facet ||
7663                         error "failed to mkdir $tmp/mnt/$facet"
7664                 $rcmd dd if=/dev/zero of=$tmp/images/$facet \
7665                         seek=199 bs=1M count=1 ||
7666                         error "failed to create $tmp/images/$facet"
7667         done
7668 }
7669
7670 t_108_mkfs() {
7671         local role=$1
7672         local idx=$2
7673         local bkfs=$3
7674         local mgs=$4
7675         local facet=${role}$((idx + 1))
7676         local pool=""
7677         [ $# -eq 5 ] && pool=$5
7678
7679         do_facet $SINGLEMDS $MKFS --fsname=lustre --$mgs \
7680                 --$role --index=$idx --replace --backfstype=$bkfs \
7681                 --device-size=200000 --reformat $pool $tmp/images/$facet ||
7682                 error "failed to mkfs for $facet"
7683 }
7684
7685 t_108_check() {
7686         echo "mounting client..."
7687         mount -t lustre ${nid}:/lustre $MOUNT ||
7688                 error "failed to mount lustre"
7689
7690         echo "check list"
7691         ls -l $MOUNT/local_dir || error "failed to list"
7692
7693         echo "check truncate && write"
7694         echo "dummmmmmmmmmmmm" > $MOUNT/remote_dir/fsx.c ||
7695                 error "failed to tuncate & write"
7696
7697         echo "check create"
7698         touch $MOUNT/foooo ||
7699                 error "failed to create"
7700
7701         echo "check read && write && append"
7702         sha1sum $MOUNT/conf-sanity.sh |
7703                 awk '{ print $1 }' > $MOUNT/checksum.new ||
7704                 error "failed to read(1)"
7705         sha1sum $MOUNT/remote_dir/unlinkmany.c |
7706                 awk '{ print $1 }' >> $MOUNT/checksum.new ||
7707                 error "failed to read(2)"
7708         sha1sum $MOUNT/striped_dir/lockahead_test.o |
7709                 awk '{ print $1 }' >> $MOUNT/checksum.new ||
7710                 error "failed to read(3)"
7711
7712         echo "verify data"
7713         diff $MOUNT/checksum.new $MOUNT/checksum.src ||
7714                 error "failed to verify data"
7715
7716         echo "done."
7717 }
7718
7719 t_108_cleanup() {
7720         trap 0
7721         local facet
7722
7723         echo "cleanup..."
7724         umount -f $MOUNT || error "failed to umount client"
7725         for facet in $facets; do
7726                 $rcmd umount -f $tmp/mnt/$facet ||
7727                         error "failed to umount $facet"
7728                 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
7729                         $rcmd $ZPOOL export -f lustre-$facet ||
7730                                 error "failed to export lustre-$facet"
7731                 fi
7732         done
7733
7734         $rcmd rm -rf $tmp || error "failed to rm the dir $tmp"
7735 }
7736
7737 test_108a() {
7738         [ "$CLIENTONLY" ] && skip "Client-only testing"
7739         [ $(facet_fstype $SINGLEMDS) != "zfs" ] && skip "zfs only test"
7740         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
7741                 skip "Need server version at least 2.10.58"
7742
7743         stopall
7744         load_modules
7745
7746         local tmp=$TMP/$tdir
7747         local rcmd="do_facet $SINGLEMDS"
7748         local facets="mdt1 mdt2 ost1 ost2"
7749         local nid=$($rcmd $LCTL list_nids | head -1)
7750         local facet
7751
7752         trap t_108_cleanup EXIT ERR
7753         t_108_prep
7754
7755         t_108_mkfs mdt 0 zfs mgs lustre-mdt1/mdt1
7756         t_108_mkfs mdt 1 zfs mgsnode=$nid lustre-mdt2/mdt2
7757         t_108_mkfs ost 0 zfs mgsnode=$nid lustre-ost1/ost1
7758         t_108_mkfs ost 1 zfs mgsnode=$nid lustre-ost2/ost2
7759
7760         for facet in $facets; do
7761                 $rcmd zfs set mountpoint=$tmp/mnt/$facet canmount=on \
7762                         lustre-$facet/$facet ||
7763                         error "failed to zfs set for $facet (1)"
7764                 $rcmd zfs mount lustre-$facet/$facet ||
7765                         error "failed to local mount $facet"
7766                 $rcmd tar jxf $LUSTRE/tests/ldiskfs_${facet}_2_11.tar.bz2 \
7767                         --xattrs --xattrs-include="trusted.*" \
7768                         -C $tmp/mnt/$facet/ > /dev/null 2>&1 ||
7769                         error "failed to untar image for $facet"
7770                 $rcmd "cd $tmp/mnt/$facet && rm -rf oi.* OI_* lfsck_* LFSCK" ||
7771                         error "failed to cleanup for $facet"
7772                 $rcmd zfs umount lustre-$facet/$facet ||
7773                         error "failed to local umount $facet"
7774                 $rcmd zfs set canmount=off lustre-$facet/$facet ||
7775                         error "failed to zfs set $facet (2)"
7776         done
7777
7778         echo "changing server nid..."
7779         $rcmd mount -t lustre -o nosvc lustre-mdt1/mdt1 $tmp/mnt/mdt1
7780         $rcmd lctl replace_nids lustre-MDT0000 $nid
7781         $rcmd lctl replace_nids lustre-MDT0001 $nid
7782         $rcmd lctl replace_nids lustre-OST0000 $nid
7783         $rcmd lctl replace_nids lustre-OST0001 $nid
7784         $rcmd umount $tmp/mnt/mdt1
7785
7786         for facet in $facets; do
7787                 echo "mounting $facet from backup..."
7788                 $rcmd mount -t lustre -o abort_recov lustre-$facet/$facet \
7789                         $tmp/mnt/$facet || error "failed to mount $facet"
7790         done
7791
7792         # ZFS backend can detect migration and trigger OI scrub automatically
7793         # sleep 3 seconds for scrub done
7794         sleep 3
7795
7796         t_108_check
7797         t_108_cleanup
7798 }
7799 run_test 108a "migrate from ldiskfs to ZFS"
7800
7801 test_108b() {
7802         [ "$CLIENTONLY" ] && skip "Client-only testing"
7803         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] && skip "ldiskfs only test"
7804         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.58) ] &&
7805                 skip "Need server version at least 2.10.58"
7806
7807         stopall
7808         load_modules
7809
7810         local tmp=$TMP/$tdir
7811         local rcmd="do_facet $SINGLEMDS"
7812         local facets="mdt1 mdt2 ost1 ost2"
7813         local scrub_list="MDT0000 MDT0001 OST0000 OST0001"
7814         local nid=$($rcmd $LCTL list_nids | head -1)
7815         local facet
7816
7817         trap t_108_cleanup EXIT ERR
7818         t_108_prep
7819
7820         t_108_mkfs mdt 0 ldiskfs mgs
7821         t_108_mkfs mdt 1 ldiskfs mgsnode=$nid
7822         t_108_mkfs ost 0 ldiskfs mgsnode=$nid
7823         t_108_mkfs ost 1 ldiskfs mgsnode=$nid
7824
7825         for facet in $facets; do
7826                 $rcmd mount -t ldiskfs -o loop $tmp/images/$facet \
7827                         $tmp/mnt/$facet ||
7828                         error "failed to local mount $facet"
7829
7830                 $rcmd tar jxf $LUSTRE/tests/zfs_${facet}_2_11.tar.bz2 \
7831                         --xattrs --xattrs-include="*.*" \
7832                         -C $tmp/mnt/$facet/ > /dev/null 2>&1 ||
7833                         error "failed to untar image for $facet"
7834                 $rcmd "cd $tmp/mnt/$facet && rm -rf oi.* OI_* lfsck_* LFSCK" ||
7835                         error "failed to cleanup for $facet"
7836                 $rcmd umount $tmp/mnt/$facet ||
7837                         error "failed to local umount $facet"
7838         done
7839
7840         echo "changing server nid..."
7841         $rcmd mount -t lustre -o nosvc,loop $tmp/images/mdt1 $tmp/mnt/mdt1
7842         $rcmd lctl replace_nids lustre-MDT0000 $nid
7843         $rcmd lctl replace_nids lustre-MDT0001 $nid
7844         $rcmd lctl replace_nids lustre-OST0000 $nid
7845         $rcmd lctl replace_nids lustre-OST0001 $nid
7846         $rcmd umount $tmp/mnt/mdt1
7847
7848         for facet in $facets; do
7849                 echo "mounting $facet from backup..."
7850                 $rcmd mount -t lustre -o loop,abort_recov $tmp/images/$facet \
7851                         $tmp/mnt/$facet || error "failed to mount $facet"
7852         done
7853
7854         for facet in $scrub_list; do
7855                 $rcmd $LCTL lfsck_start -M lustre-$facet -t scrub ||
7856                         error "failed to start OI scrub on $facet"
7857         done
7858
7859         # sleep 3 seconds for scrub done
7860         sleep 3
7861
7862         t_108_check
7863         t_108_cleanup
7864 }
7865 run_test 108b "migrate from ZFS to ldiskfs"
7866
7867
7868 #
7869 # set number of permanent parameters
7870 #
7871 test_109_set_params() {
7872         local fsname=$1
7873
7874         set_persistent_param_and_check mds                          \
7875             "mdd.$fsname-MDT0000.atime_diff"                        \
7876             "$fsname-MDT0000.mdd.atime_diff"                        \
7877             "62"
7878         set_persistent_param_and_check mds                          \
7879             "mdd.$fsname-MDT0000.atime_diff"                        \
7880             "$fsname-MDT0000.mdd.atime_diff"                        \
7881             "63"
7882         set_persistent_param_and_check client                       \
7883             "llite.$fsname*.max_read_ahead_mb"                      \
7884             "$fsname.llite.max_read_ahead_mb"                       \
7885             "32"
7886         set_persistent_param_and_check client                       \
7887             "llite.$fsname*.max_read_ahead_mb"                      \
7888             "$fsname.llite.max_read_ahead_mb"                       \
7889             "64"
7890         create_pool $fsname.pool1 || error "create pool failed"
7891         do_facet mgs $LCTL pool_add $fsname.pool1 OST0000 ||
7892                 error "pool_add failed"
7893         do_facet mgs $LCTL pool_remove $fsname.pool1 OST0000 ||
7894                 error "pool_remove failed"
7895         do_facet mgs $LCTL pool_add $fsname.pool1 OST0000 ||
7896                 error "pool_add failed"
7897 }
7898
7899 #
7900 # check permanent parameters
7901 #
7902 test_109_test_params() {
7903         local fsname=$1
7904
7905         local atime_diff=$(do_facet mds $LCTL \
7906                 get_param -n mdd.$fsname-MDT0000.atime_diff)
7907         [ $atime_diff == 63 ] || error "wrong mdd parameter after clear_conf"
7908         local max_read_ahead_mb=$(do_facet client $LCTL \
7909                 get_param -n llite.$fsname*.max_read_ahead_mb)
7910         [ $max_read_ahead_mb == 64 ] ||
7911                 error "wrong llite parameter after clear_conf"
7912         local ost_in_pool=$(do_facet mds $LCTL pool_list $fsname.pool1 |
7913                 grep -v "^Pool:" | sed 's/_UUID//')
7914         [ $ost_in_pool = "$fsname-OST0000" ] ||
7915                 error "wrong pool after clear_conf"
7916 }
7917
7918 #
7919 # run lctl clear_conf, store CONFIGS before and after that
7920 #
7921 test_109_clear_conf()
7922 {
7923         local clear_conf_arg=$1
7924
7925         local mgsdev
7926         if ! combined_mgs_mds ; then
7927                 mgsdev=$MGSDEV
7928                 stop_mgs || error "stop_mgs failed"
7929                 start_mgs "-o nosvc" || error "start_mgs nosvc failed"
7930         else
7931                 mgsdev=$(mdsdevname 1)
7932                 start_mdt 1 "-o nosvc" || error "start_mdt 1 nosvc failed"
7933         fi
7934
7935         do_facet mgs "rm -rf $TMP/${tdir}/conf1; mkdir -p $TMP/${tdir}/conf1;" \
7936                 "$DEBUGFS -c -R \\\"rdump CONFIGS $TMP/${tdir}/conf1\\\" \
7937                 $mgsdev"
7938
7939         #
7940         # the command being tested
7941         #
7942         do_facet mgs $LCTL clear_conf $clear_conf_arg ||
7943                 error "clear_conf failed"
7944         if ! combined_mgs_mds ; then
7945                 stop_mgs || error "stop_mgs failed"
7946         else
7947                 stop_mdt 1 || error "stop_mdt 1 failed"
7948         fi
7949
7950         do_facet mgs "rm -rf $TMP/${tdir}/conf2; mkdir -p $TMP/${tdir}/conf2;" \
7951                 "$DEBUGFS -c -R \\\"rdump CONFIGS $TMP/${tdir}/conf2\\\" \
7952                 $mgsdev"
7953 }
7954
7955 test_109_file_shortened() {
7956         local file=$1
7957         local sizes=($(do_facet mgs "stat -c %s " \
7958                 "$TMP/${tdir}/conf1/CONFIGS/$file" \
7959                 "$TMP/${tdir}/conf2/CONFIGS/$file"))
7960         [ ${sizes[1]} -lt ${sizes[0]} ] && return 0
7961         return 1
7962 }
7963
7964 test_109a()
7965 {
7966         [ "$(facet_fstype mgs)" == "zfs" ] &&
7967                 skip "LU-8727: no implementation for ZFS"
7968         stopall
7969         reformat
7970         setup_noconfig
7971         client_up || error "client_up failed"
7972
7973         #
7974         # set number of permanent parameters
7975         #
7976         test_109_set_params $FSNAME
7977
7978         umount_client $MOUNT || error "umount_client failed"
7979         stop_ost || error "stop_ost failed"
7980         stop_mds || error "stop_mds failed"
7981
7982         test_109_clear_conf $FSNAME
7983         #
7984         # make sure that all configs are cleared
7985         #
7986         test_109_file_shortened $FSNAME-MDT0000 ||
7987                 error "failed to clear MDT0000 config"
7988         test_109_file_shortened $FSNAME-client ||
7989                 error "failed to clear client config"
7990
7991         setup_noconfig
7992
7993         #
7994         # check that configurations are intact
7995         #
7996         test_109_test_params $FSNAME
7997
7998         #
7999         # Destroy pool.
8000         #
8001         destroy_test_pools || error "destroy test pools failed"
8002
8003         cleanup
8004 }
8005 run_test 109a "test lctl clear_conf fsname"
8006
8007 test_109b()
8008 {
8009         [ "$(facet_fstype mgs)" == "zfs" ] &&
8010                 skip "LU-8727: no implementation for ZFS"
8011         stopall
8012         reformat
8013         setup_noconfig
8014         client_up || error "client_up failed"
8015
8016         #
8017         # set number of permanent parameters
8018         #
8019         test_109_set_params $FSNAME
8020
8021         umount_client $MOUNT || error "umount_client failed"
8022         stop_ost || error "stop_ost failed"
8023         stop_mds || error "stop_mds failed"
8024
8025         test_109_clear_conf $FSNAME-MDT0000
8026         #
8027         # make sure that only one config is cleared
8028         #
8029         test_109_file_shortened $FSNAME-MDT0000 ||
8030                 error "failed to clear MDT0000 config"
8031         test_109_file_shortened $FSNAME-client &&
8032                 error "failed to clear client config"
8033
8034         setup_noconfig
8035
8036         #
8037         # check that configurations are intact
8038         #
8039         test_109_test_params $FSNAME
8040
8041         #
8042         # Destroy pool.
8043         #
8044         destroy_test_pools || error "destroy test pools failed"
8045
8046         cleanup
8047 }
8048 run_test 109b "test lctl clear_conf one config"
8049
8050 test_110()
8051 {
8052         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ]] &&
8053                 skip "Only applicable to ldiskfs-based MDTs"
8054
8055         do_facet $SINGLEMDS $DEBUGFS -w -R supported_features |grep large_dir ||
8056                 skip "large_dir option is not supported on MDS"
8057         do_facet ost1 $DEBUGFS -w -R supported_features | grep large_dir ||
8058                 skip "large_dir option is not supported on OSS"
8059
8060         stopall # stop all targets before modifying the target counts
8061         stack_trap "MDSCOUNT=$MDSCOUNT OSTCOUNT=$OSTCOUNT" EXIT
8062         MDSCOUNT=1
8063         OSTCOUNT=1
8064
8065         # ext4_dir_entry_2 struct size:264
8066         # dx_root struct size:8
8067         # dx_node struct size:8
8068         # dx_entry struct size:8
8069         # For 1024 bytes block size.
8070         # First level directory entries: 126
8071         # Second level directory entries: 127
8072         # Entries in leaf: 3
8073         # For 2 levels limit: 48006
8074         # For 3 levels limit : 6096762
8075         # Create 80000 files to safely exceed 2-level htree limit.
8076         CONF_SANITY_110_LINKS=${CONF_SANITY_110_LINKS:-80000}
8077
8078         # can fit at most 3 filenames per 1KB leaf block, but each
8079         # leaf/index block will only be 3/4 full before split at each level
8080         (( MDSSIZE < CONF_SANITY_110_LINKS / 3 * 4/3 * 4/3 )) &&
8081                 CONF_SANITY_110_LINKS=$((MDSSIZE * 3 * 3/4 * 3/4))
8082
8083         local opts="$(mkfs_opts mds1 $(mdsdevname 1)) \
8084                     --reformat $(mdsdevname 1) $(mdsvdevname 1)"
8085         if [[ $opts != *mkfsoptions* ]]; then
8086                 opts+=" --mkfsoptions=\\\"-O large_dir -b 1024 -i 65536\\\""
8087         else
8088                 opts="${opts//--mkfsoptions=\\\"/ \
8089                         --mkfsoptions=\\\"-O large_dir -b 1024 -i 65536 }"
8090         fi
8091         echo "MDT params: $opts"
8092         add mds1 $opts || error "add mds1 failed with new params"
8093         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
8094
8095         opts="$(mkfs_opts ost1 $(ostdevname 1)) \
8096                 --reformat $(ostdevname 1) $(ostvdevname 1)"
8097
8098         if [[ $opts != *mkfsoptions* ]]; then
8099                 opts+=" --mkfsoptions=\\\"-O large_dir\\\" "
8100         else
8101                 opts="${opts//--mkfsoptions=\\\"/ \
8102                         --mkfsoptions=\\\"-O large_dir }"
8103         fi
8104         echo "OST params: $opts"
8105         add ost1 $opts || error "add ost1 failed with new params"
8106         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
8107
8108         MOUNT_2=yes mountcli || error "mount clients failed"
8109
8110         mkdir -v $DIR/$tdir || error "cannot create $DIR/$tdir"
8111         local pids count=0 group=0
8112
8113         echo "creating $CONF_SANITY_110_LINKS in total"
8114         while (( count < CONF_SANITY_110_LINKS )); do
8115                 local len=$((253 - $(wc -c <<<"$tfile-$group-40000-")))
8116                 local dir=DIR$((group % 2 + 1))
8117                 local target=${!dir}/$tdir/$tfile-$group
8118                 local long=$target-$(generate_name $len)-
8119                 local create=$((CONF_SANITY_110_LINKS - count))
8120
8121                 (( create > 40000 )) && create=40000
8122                 touch $target || error "creating $target failed"
8123                 echo "creating $create hard links to $target"
8124                 createmany -l $target $long $create &
8125                 pids+=" $!"
8126
8127                 count=$((count + create))
8128                 group=$((group + 1))
8129         done
8130         echo "waiting for PIDs$pids to complete"
8131         wait $pids || error "createmany failed after $group groups"
8132
8133         cleanup
8134
8135         run_e2fsck $(facet_active_host mds1) $(mdsdevname 1) -n
8136 }
8137 run_test 110 "Adding large_dir with 3-level htree"
8138
8139 test_111() {
8140         [[ $(facet_fstype $SINGLEMDS) != ldiskfs ]] &&
8141                 skip "Only applicable to ldiskfs-based MDTs"
8142
8143         is_dm_flakey_dev $SINGLEMDS $(mdsdevname 1) &&
8144                 skip "This test can not be executed on flakey dev"
8145
8146         do_facet $SINGLEMDS $DEBUGFS -w -R supported_features |grep large_dir ||
8147                 skip "large_dir option is not supported on MDS"
8148
8149         do_facet ost1 $DEBUGFS -w -R supported_features | grep large_dir ||
8150                 skip "large_dir option is not supported on OSS"
8151
8152         # cleanup before changing target counts
8153         cleanup
8154         stack_trap "MDSSIZE=$MDSSIZE MDSCOUNT=$MDSCOUNT OSTCOUNT=$OSTCOUNT" EXIT
8155         MDSCOUNT=1
8156         OSTCOUNT=1
8157         (( MDSSIZE < 2400000 )) && MDSSIZE=2400000 # need at least 2.4GB
8158
8159         local mdsdev=$(mdsdevname 1)
8160
8161         local opts="$(mkfs_opts mds1 $(mdsdevname 1)) \
8162                     --reformat $(mdsdevname 1) $(mdsvdevname 1)"
8163         if [[ $opts != *mkfsoptions* ]]; then
8164                 opts+=" --mkfsoptions=\\\"-O large_dir -i 1048576 \\\" "
8165         else
8166                 opts="${opts//--mkfsoptions=\\\"/ \
8167                         --mkfsoptions=\\\"-O large_dir -i 1048576 }"
8168         fi
8169         echo "MDT params: $opts"
8170         __touch_device mds 1
8171         add mds1 $opts || error "add mds1 failed with new params"
8172         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
8173
8174         opts="$(mkfs_opts ost1 $(ostdevname 1)) \
8175                 --reformat $(ostdevname 1) $(ostvdevname 1)"
8176         if [[ $opts != *mkfsoptions* ]]; then
8177                 opts+=" --mkfsoptions=\\\"-O large_dir \\\""
8178         else
8179                 opts="${opts//--mkfsoptions=\\\"/ --mkfsoptions=\\\"-O large_dir }"
8180         fi
8181         echo "OST params: $opts"
8182         __touch_device ost 1
8183         add ost1 $opts || error "add ost1 failed with new params"
8184         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
8185
8186         MOUNT_2=yes mountcli
8187         mkdir $DIR/$tdir || error "cannot create $DIR/$tdir"
8188         lfs df $DIR/$tdir
8189         lfs df -i $DIR/$tdir
8190
8191         local group=0
8192
8193         local start=$SECONDS
8194         local dirsize=0
8195         local dirmax=$((2 << 30))
8196         local needskip=0
8197         local taken=0
8198         local rate=0
8199         local left=0
8200         local num=0
8201         while (( !needskip & dirsize < dirmax )); do
8202                 local pids=""
8203
8204                 for cli in ${CLIENTS//,/ }; do
8205                         local len=$((253 - $(wc -c <<<"$cli-$group-60000-")))
8206                         local target=$cli-$group
8207                         local long=$DIR/$tdir/$target-$(generate_name $len)-
8208
8209                         RPWD=$DIR/$tdir do_node $cli touch $target ||
8210                                 error "creating $target failed"
8211                         echo "creating 60000 hardlinks to $target"
8212                         RPWD=$DIR/$tdir do_node $cli createmany -l $target $long 60000 &
8213                         pids+=" $!"
8214
8215                         group=$((group + 1))
8216                         target=$cli-$group
8217                         long=$DIR2/$tdir/$target-$(generate_name $len)-
8218
8219                         RPWD=$DIR2/$tdir do_node $cli touch $target ||
8220                                 error "creating $target failed"
8221                         echo "creating 60000 hardlinks to $target"
8222                         RPWD=$DIR2/$tdir do_node $cli createmany -l $target $long 60000 &
8223                         pids+=" $!"
8224
8225                         group=$((group + 1))
8226                 done
8227                 echo "waiting for PIDs$pids to complete"
8228                 wait $pids || error "createmany failed after $group groups"
8229                 dirsize=$(stat -c %s $DIR/$tdir)
8230                 taken=$((SECONDS - start))
8231                 rate=$((dirsize / taken))
8232                 left=$(((dirmax - dirsize) / rate))
8233                 num=$((group * 60000))
8234                 echo "estimate ${left}s left after $num files / ${taken}s"
8235                 # if the estimated time remaining is too large (it may change
8236                 # over time as the create rate is not constant) then exit
8237                 # without declaring a failure.
8238                 (( left > 1200 )) && needskip=1
8239         done
8240
8241         cleanup
8242
8243         (( $needskip )) && skip "ETA ${left}s after $num files / ${taken}s is too long"
8244
8245         run_e2fsck $(facet_active_host mds1) $(mdsdevname 1) -n
8246 }
8247 run_test 111 "Adding large_dir with over 2GB directory"
8248
8249
8250 cleanup_115()
8251 {
8252         trap 0
8253         stopall
8254         rm -f $TMP/$tdir/lustre-mdt
8255         formatall
8256 }
8257
8258 test_115() {
8259         if [ $(facet_fstype $SINGLEMDS) != ldiskfs ]; then
8260                 skip "Only applicable to ldiskfs-based MDTs"
8261         fi
8262
8263         IMAGESIZE=$((3072 << 30)) # 3072 GiB
8264
8265         stopall
8266         # We need MDT size 3072GB, because it is smallest
8267         # partition that can store 2B inodes
8268         do_facet $SINGLEMDS "mkdir -p $TMP/$tdir"
8269         local mdsimgname=$TMP/$tdir/lustre-mdt
8270         do_facet $SINGLEMDS "rm -f $mdsimgname"
8271         do_facet $SINGLEMDS "touch $mdsimgname"
8272         trap cleanup_115 RETURN EXIT
8273         do_facet $SINGLEMDS "$TRUNCATE $mdsimgname $IMAGESIZE" ||
8274                 skip "Backend FS doesn't support sparse files"
8275         local mdsdev=$(do_facet $SINGLEMDS "losetup -f")
8276         do_facet $SINGLEMDS "losetup $mdsdev $mdsimgname"
8277
8278         local mds_opts="$(mkfs_opts mds1 ${mdsdev}) --device-size=$IMAGESIZE   \
8279                 --mkfsoptions='-O lazy_itable_init,ea_inode,^resize_inode,meta_bg \
8280                 -i 1024'"
8281         add mds1 $mds_opts --mgs --reformat $mdsdev ||
8282                 skip_env "format large MDT failed"
8283         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
8284                         --reformat $(ostdevname 1) $(ostvdevname 1)
8285
8286         start $SINGLEMDS ${mdsdev} $MDS_MOUNT_OPTS || error "start MDS failed"
8287         start_ost || error "start OSS failed"
8288         mount_client $MOUNT || error "mount client failed"
8289
8290         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir fail"
8291         for goal in $(do_facet $SINGLEMDS "ls /sys/fs/ldiskfs/*/inode_goal"); do
8292                 do_facet $SINGLEMDS "echo 2147483947 >> $goal; grep . $goal"
8293         done
8294
8295         touch $DIR/$tdir/$tfile
8296
8297         # Add > 5k bytes to xattr
8298         for i in {1..30}; do
8299                 ln $DIR/$tdir/$tfile $DIR/$tdir/$(printf "link%0250d" $i) ||
8300                         error "Can't make link"
8301         done
8302
8303         sync; sleep 5; sync
8304
8305         local inode_num=$(do_facet $SINGLEMDS \
8306                          "$DEBUGFS -c -R 'stat ROOT/$tdir/$tfile' $mdsimgname" |
8307                          awk '/link =/ { print $4 }' |
8308                          sed -e 's/>//' -e 's/<//' -e 's/\"//')
8309         echo "inode num: $inode_num"
8310         [ $inode_num -ge 2147483947 ] || error "inode $inode_num too small"
8311         do_facet $SINGLEMDS "losetup -d $mdsdev"
8312         cleanup_115
8313 }
8314 run_test 115 "Access large xattr with inodes number over 2TB"
8315
8316 test_116() {
8317         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] && skip "ldiskfs only test"
8318         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.10.59) ] &&
8319                 skip "Need server version at least 2.10.59"
8320         do_facet $SINGLEMDS which mkfs.xfs ||
8321                 skip_env "No mkfs.xfs installed"
8322
8323         stopall
8324         load_modules
8325
8326         local tmpmnt=$TMP/$tdir
8327         local mdtimg=$tfile-mdt0
8328
8329         do_facet $SINGLEMDS mkdir -p $tmpmnt
8330         stack_trap "do_facet $SINGLEMDS rmdir $tmpmnt" EXIT
8331
8332         do_facet $SINGLEMDS touch $TMP/$mdtimg
8333         stack_trap "do_facet $SINGLEMDS rm -f $TMP/$mdtimg" EXIT
8334         do_facet $SINGLEMDS mkfs -t xfs -d file,size=1t,name=$TMP/$mdtimg ||
8335                 error "mkfs temporary xfs image"
8336
8337         do_facet $SINGLEMDS mount $TMP/$mdtimg $tmpmnt ||
8338                 error "mount temporary xfs image"
8339         stack_trap "do_facet $SINGLEMDS umount $tmpmnt" EXIT
8340         local old_mdssize=$MDSSIZE
8341         local old_mdsisize=$MDSISIZE
8342
8343         MDSSIZE=$((17 * 1024 * 1024 * 1024)) # 17T MDT
8344         MDSISIZE=$((16 << 20))
8345         local opts17t="$(mkfs_opts $SINGLEMDS)"
8346
8347         MDSSIZE=$old_mdssize
8348         MDSISIZE=$old_mdsisize
8349         do_facet $SINGLEMDS $MKFS $opts17t $tmpmnt/$mdtimg ||
8350                 error "failed to mkfs for $tmpmnt/$mdtimg"
8351
8352         do_facet $SINGLEMDS $TUNE2FS -l $tmpmnt/$mdtimg |
8353                 grep -qw 'features.*extent' || error "extent should be enabled"
8354 }
8355 run_test 116 "big size MDT support"
8356
8357 test_117() {
8358         setup
8359         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.nrs_policies=fifo"
8360         do_facet ost1 "$LCTL get_param -n ost.OSS.ost_io.nrs_tbf_rule" &&
8361                 error "get_param should fail"
8362         cleanup || error "cleanup failed with rc $?"
8363 }
8364 run_test 117 "lctl get_param return errors properly"
8365
8366 test_120() { # LU-11130
8367         [ "$MDSCOUNT" -lt 2 ] && skip "mdt count < 2"
8368         [ $(facet_fstype $SINGLEMDS) != "ldiskfs" ] &&
8369                 skip "ldiskfs only test"
8370         [ $(lustre_version_code $SINGLEMDS) -lt $(version_code 2.11.56) ] &&
8371                 skip "Need DNE2 capable MD target with LU-11130 fix"
8372
8373         setup
8374
8375         local mds1host=$(facet_active_host mds1)
8376         local mds1dev=$(mdsdevname 1)
8377
8378         $LFS mkdir -i 1 $DIR/$tdir
8379         $LFS mkdir -i 0 $DIR/$tdir/mds1dir
8380
8381         ln -s foo $DIR/$tdir/bar
8382         mv $DIR/$tdir/bar $DIR/$tdir/mds1dir/bar2 ||
8383                 error "cross-target rename failed"
8384
8385         stopall
8386
8387         run_e2fsck $mds1host $mds1dev "-n"
8388 }
8389 run_test 120 "cross-target rename should not create bad symlinks"
8390
8391 test_122() {
8392         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
8393         [[ $(lustre_version_code ost1) -ge $(version_code 2.11.53) ]] ||
8394                 skip "Need OST version at least 2.11.53"
8395
8396         reformat
8397         LOAD_MODULES_REMOTE=true load_modules
8398 #define OBD_FAIL_OFD_SET_OID 0x1e0
8399         do_facet ost1 $LCTL set_param fail_loc=0x00001e0
8400
8401         setupall
8402         $LFS mkdir -i1 -c1 $DIR/$tdir
8403         $LFS setstripe -i0 -c1 $DIR/$tdir
8404         do_facet ost1 $LCTL set_param fail_loc=0
8405         createmany -o $DIR/$tdir/file_ 1000 ||
8406                 error "Fail to create a new sequence"
8407
8408         reformat
8409 }
8410 run_test 122 "Check OST sequence update"
8411
8412 test_123aa() {
8413         remote_mgs_nodsh && skip "remote MGS with nodsh"
8414         [ -d $MOUNT/.lustre ] || setupall
8415
8416         # test old logid format until removal from llog_ioctl.c::str2logid()
8417         if [ $MGS_VERSION -lt $(version_code 3.1.53) ]; then
8418                 do_facet mgs $LCTL dl | grep MGS
8419                 do_facet mgs "$LCTL --device %MGS llog_print \
8420                               \\\\\\\$$FSNAME-client 1 10" ||
8421                         error "old llog_print failed"
8422         fi
8423
8424         # test new logid format
8425         if [ $MGS_VERSION -ge $(version_code 2.9.53) ]; then
8426                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
8427                         error "new llog_print failed"
8428         fi
8429 }
8430 run_test 123aa "llog_print works with FIDs and simple names"
8431
8432 test_123ab() {
8433         remote_mgs_nodsh && skip "remote MGS with nodsh"
8434         [[ $MGS_VERSION -gt $(version_code 2.11.51) ]] ||
8435                 skip "Need server with working llog_print support"
8436
8437         [ -d $MOUNT/.lustre ] || setupall
8438
8439         local yaml
8440         local orig_val
8441
8442         orig_val=$(do_facet mgs $LCTL get_param jobid_name)
8443         do_facet mgs $LCTL set_param -P jobid_name="testname"
8444
8445         yaml=$(do_facet mgs $LCTL --device MGS llog_print params |
8446                grep jobid_name | tail -n 1)
8447
8448         local param=$(awk '{ print $10 }' <<< "$yaml")
8449         local val=$(awk '{ print $12 }' <<< "$yaml")
8450         #return to the default
8451         do_facet mgs $LCTL set_param -P jobid_name=$orig_val
8452         [ $val = "testname" ] || error "bad value: $val"
8453         [ $param = "jobid_name," ] || error "Bad param: $param"
8454 }
8455 run_test 123ab "llog_print params output values from set_param -P"
8456
8457 test_123ac() { # LU-11566
8458         remote_mgs_nodsh && skip "remote MGS with nodsh"
8459         do_facet mgs "$LCTL help llog_print" 2>&1 | grep -q -- --start ||
8460                 skip "Need 'lctl llog_print --start' on MGS"
8461
8462         local start=10
8463         local end=50
8464
8465         [ -d $MOUNT/.lustre ] || setupall
8466
8467         # - { index: 10, event: add_uuid, nid: 192.168.20.1@tcp(0x20000c0a81401,
8468         #     node: 192.168.20.1@tcp }
8469         do_facet mgs $LCTL --device MGS \
8470                 llog_print --start $start --end $end $FSNAME-client | tr -d , |
8471                 while read DASH BRACE INDEX idx EVENT BLAH BLAH BLAH; do
8472                 (( idx >= start )) || error "llog_print index $idx < $start"
8473                 (( idx <= end )) || error "llog_print index $idx > $end"
8474         done
8475 }
8476 run_test 123ac "llog_print with --start and --end"
8477
8478 test_123ad() { # LU-11566
8479         remote_mgs_nodsh && skip "remote MGS with nodsh"
8480         # older versions of lctl may not print all records properly
8481         do_facet mgs "$LCTL help llog_print" 2>&1 | grep -q -- --start ||
8482                 skip "Need 'lctl llog_print --start' on MGS"
8483
8484         [ -d $MOUNT/.lustre ] || setupall
8485
8486         # append a new record, to avoid issues if last record was cancelled
8487         local old=$($LCTL get_param -n osc.*-OST0000-*.max_dirty_mb | head -1)
8488         do_facet mgs $LCTL conf_param $FSNAME-OST0000.osc.max_dirty_mb=$old
8489
8490         # logid:            [0x3:0xa:0x0]:0
8491         # flags:            4 (plain)
8492         # records_count:    72
8493         # last_index:       72
8494         local num=$(do_facet mgs $LCTL --device MGS llog_info $FSNAME-client |
8495                     awk '/last_index:/ { print $2 - 1 }')
8496
8497         # - { index: 71, event: set_timeout, num: 0x14, param: sys.timeout=20 }
8498         local last=$(do_facet mgs $LCTL --device MGS llog_print $FSNAME-client |
8499                      tail -1 | awk '{ print $4 }' | tr -d , )
8500         (( last == num )) || error "llog_print only showed $last/$num records"
8501 }
8502 run_test 123ad "llog_print shows all records"
8503
8504 test_123F() {
8505         setupall
8506         local yaml_file="$TMP/$tfile.yaml"
8507         do_facet mgs rm "$yaml_file"
8508         local cfgfiles=$(do_facet mgs "lctl --device MGS llog_catlist" |
8509                          sed 's/config_log://')
8510
8511         # set jobid_var to a different value for test
8512         local orig_val=$(do_facet mgs $LCTL get_param jobid_var)
8513         do_facet mgs $LCTL set_param -P jobid_var="testname"
8514
8515         for i in $cfgfiles params; do
8516                 do_facet mgs "lctl --device MGS llog_print ${i} >> $yaml_file"
8517         done
8518
8519         echo "Unmounting FS"
8520         stopall
8521         echo "Writeconf"
8522         writeconf_all
8523         echo "Remounting"
8524         mountmgs
8525         mountmds
8526         mountoss
8527         mountcli
8528
8529         # Reapply the config from before
8530         echo "Setting configuration parameters"
8531         do_facet mgs "lctl set_param -F $yaml_file"
8532
8533         local set_val=$(do_facet mgs $LCTL get_param jobid_var)
8534         do_facet mgs $LCTL set_param -P $orig_val
8535
8536         [ $set_val == "jobid_var=testname" ] ||
8537                 error "$set_val is not testname"
8538
8539         do_facet mgs rm "$yaml_file"
8540 }
8541 run_test 123F "clear and reset all parameters using set_param -F"
8542
8543 test_124()
8544 {
8545         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
8546         [ -z $mds2failover_HOST ] && skip "needs MDT failover setup"
8547
8548         setup
8549         cleanup
8550
8551         load_modules
8552         if combined_mgs_mds; then
8553                 start_mdt 1 "-o nosvc" ||
8554                         error "starting mds with nosvc option failed"
8555         fi
8556         local nid=$(do_facet mds2 $LCTL list_nids | head -1)
8557         local failover_nid=$(do_node $mds2failover_HOST $LCTL list_nids | head -1)
8558         do_facet mgs $LCTL replace_nids $FSNAME-MDT0001 $nid:$failover_nid ||
8559                 error "replace_nids execution error"
8560
8561         if combined_mgs_mds; then
8562                 stop_mdt 1
8563         fi
8564
8565         setup
8566         fail mds2
8567         echo "lfs setdirstripe"
8568         $LFS setdirstripe -i 1 $MOUNT/$tdir || error "setdirstirpe error"
8569         echo ok
8570 }
8571 run_test 124 "check failover after replace_nids"
8572
8573 if ! combined_mgs_mds ; then
8574         stop mgs
8575 fi
8576
8577 cleanup_gss
8578
8579 # restore the values of MDSSIZE and OSTSIZE
8580 MDSSIZE=$STORED_MDSSIZE
8581 OSTSIZE=$STORED_OSTSIZE
8582 reformat
8583
8584 complete $SECONDS
8585 check_and_cleanup_lustre
8586 exit_status