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