Whamcloud - gitweb
57b97c748903b2c4068c88f2aded57ee67654db5
[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         if grep -q "CONFIG_DEBUG_LOCK_ALLOC=y" /boot/config-$(uname -r); then
4707                 skip "test is not compatible with CONFIG_DEBUG_LOCK_ALLOC=y"
4708         fi
4709
4710         echo "$inode_slab ldiskfs inodes per page"
4711         [ "${inode_slab%.*}" -ge "3" ] && return 0
4712
4713         # If kmalloc-128 is also 1 per page - this is a debug kernel
4714         # and so this is not an error.
4715         local kmalloc128=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
4716                            awk '/^(dma-kmalloc|size)-128 / { print $5 / $6 }')
4717         # 32 128-byte chunks in 4k
4718         [ "${kmalloc128%.*}" -lt "32" ] ||
4719                 error "ldiskfs inode too big, only $inode_slab objs/page, " \
4720                       "kmalloc128 = $kmalloc128 objs/page"
4721 }
4722 run_test 63 "Verify each page can at least hold 3 ldiskfs inodes"
4723
4724 test_64() {
4725         start_mds || error "unable to start MDS"
4726         start_ost || error "Unable to start OST1"
4727         start_ost2 || error "Unable to start second ost"
4728         mount_client $MOUNT || error "Unable to mount client"
4729         stop_ost2 || error "Unable to stop second ost"
4730         echo "$LFS df"
4731         $LFS df --lazy
4732         umount_client $MOUNT -f || error “unmount $MOUNT failed”
4733         cleanup_nocli || error "cleanup_nocli failed with $?"
4734         #writeconf to remove all ost2 traces for subsequent tests
4735         writeconf_or_reformat
4736 }
4737 run_test 64 "check lfs df --lazy "
4738
4739 test_65() { # LU-2237
4740         # Currently, the test is only valid for ldiskfs backend
4741         [ "$mds1_FSTYPE" != ldiskfs ] &&
4742                 skip "ldiskfs only test"
4743
4744         local devname=$(mdsdevname ${SINGLEMDS//mds/})
4745         local brpt=$(facet_mntpt brpt)
4746         local opts=""
4747
4748         if ! do_facet $SINGLEMDS "test -b $devname"; then
4749                 opts="-o loop"
4750         fi
4751
4752         stop_mds || error "Unable to stop MDS"
4753         local obj=$(do_facet $SINGLEMDS \
4754                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
4755                     grep Inode)
4756         if [ -z "$obj" ]; then
4757                 # The MDT may be just re-formatted, mount the MDT for the
4758                 # first time to guarantee the "last_rcvd" file is there.
4759                 start_mds || error "fail to mount the MDS for the first time"
4760                 stop_mds || error "Unable to stop MDS"
4761         fi
4762
4763         # remove the "last_rcvd" file
4764         do_facet $SINGLEMDS "mkdir -p $brpt"
4765         do_facet $SINGLEMDS \
4766                 "mount -t $mds1_FSTYPE $opts $devname $brpt"
4767         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
4768         do_facet $SINGLEMDS "$UMOUNT $brpt"
4769
4770         # restart MDS, the "last_rcvd" file should be recreated.
4771         start_mds || error "fail to restart the MDS"
4772         stop_mds || error "Unable to stop MDS"
4773         obj=$(do_facet $SINGLEMDS \
4774               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
4775         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
4776 }
4777 run_test 65 "re-create the lost last_rcvd file when server mount"
4778
4779 test_66() {
4780         [[ "$MGS_VERSION" -ge $(version_code 2.3.59) ]] ||
4781                 skip "Need MGS version at least 2.3.59"
4782
4783         setup
4784         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
4785         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
4786
4787         # add EXCLUDE records to config log, they are not to be
4788         # removed by lctl replace_nids
4789         set_conf_param_and_check mds                                    \
4790             "$LCTL get_param -n osc.$FSNAME-OST0000-osc-MDT0000.active" \
4791             "$FSNAME-OST0000.osc.active"                                \
4792             "0"
4793
4794         echo "replace_nids should fail if MDS, OSTs and clients are UP"
4795         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4796                 error "replace_nids fail"
4797
4798         umount_client $MOUNT || error "unmounting client failed"
4799         echo "replace_nids should fail if MDS and OSTs are UP"
4800         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4801                 error "replace_nids fail"
4802
4803         stop_ost || error "Unable to stop OST1"
4804         echo "replace_nids should fail if MDS is UP"
4805         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
4806                 error "replace_nids fail"
4807
4808         stop_mds || error "stopping mds failed"
4809
4810         if combined_mgs_mds; then
4811                 start_mdt 1 "-o nosvc" ||
4812                         error "starting mds with nosvc option failed"
4813         fi
4814
4815         echo "command should accept two parameters"
4816         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
4817                 error "command should accept two params"
4818
4819         echo "correct device name should be passed"
4820         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
4821                 error "wrong devname"
4822
4823         echo "wrong nids list should not destroy the system"
4824         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
4825                 error "wrong parse"
4826         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "asdfasdf, asdfadf" &&
4827                 error "wrong parse"
4828
4829         echo "replace OST nid"
4830         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
4831                 error "replace nids failed"
4832
4833         echo "command should accept two parameters"
4834         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
4835                 error "command should accept two params"
4836
4837         echo "wrong nids list should not destroy the system"
4838         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
4839                 error "wrong parse"
4840
4841         local FAKE_NIDS="192.168.0.112@tcp1,192.168.0.112@tcp2"
4842         local FAKE_FAILOVER="192.168.0.113@tcp1,192.168.0.113@tcp2"
4843         local NIDS_AND_FAILOVER="$MDS_NID,$FAKE_NIDS:$FAKE_FAILOVER"
4844         echo "set NIDs with failover"
4845         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $NIDS_AND_FAILOVER ||
4846                 error "replace nids failed"
4847
4848
4849         echo "replace MDS nid"
4850         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
4851                 error "replace nids failed"
4852
4853         if ! combined_mgs_mds ; then
4854                 stop_mgs
4855         else
4856                 stop_mds || error "Unable to stop MDS"
4857         fi
4858
4859         start_mgsmds || error "start mgsmds failed"
4860         set_conf_param_and_check mds                                    \
4861             "$LCTL get_param -n osc.$FSNAME-OST0000-osc-MDT0000.active" \
4862             "$FSNAME-OST0000.osc.active"                                \
4863             "1"
4864         start_ost || error "unable to start OST"
4865         mount_client $MOUNT || error "mount client failed"
4866
4867         check_mount || error "error after nid replace"
4868         cleanup || error "cleanup failed"
4869         reformat_and_config
4870 }
4871 run_test 66 "replace nids"
4872
4873 test_67() { #LU-2950
4874         local legacy="$TMP/legacy_lnet_config"
4875         local new="$TMP/new_routes_test"
4876         local out="$TMP/config_out_file"
4877         local verify="$TMP/conv_verify"
4878         local verify_conf="$TMP/conf_verify"
4879
4880         # Create the legacy file that will be run through the
4881         # lustre_routes_conversion script
4882         cat <<- LEGACY_LNET_CONFIG > $legacy
4883                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
4884                 tcp2 54 10.1.3.2@tcp;
4885                 tcp3 10.3.4.3@tcp:3;
4886                 tcp4 10.3.3.4@tcp;
4887         LEGACY_LNET_CONFIG
4888
4889         # Create the verification file to verify the output of
4890         # lustre_routes_conversion script against.
4891         cat <<- VERIFY_LNET_CONFIG > $verify
4892                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
4893                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
4894                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
4895                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
4896                 tcp4: { gateway: 10.3.3.4@tcp }
4897         VERIFY_LNET_CONFIG
4898
4899         # Create the verification file to verify the output of
4900         # lustre_routes_config script against
4901         cat <<- VERIFY_LNET_CONFIG > $verify_conf
4902                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
4903                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
4904                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
4905                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
4906                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
4907         VERIFY_LNET_CONFIG
4908
4909         $LUSTRE_ROUTES_CONVERSION $legacy $new > /dev/null
4910         if [ -f $new ]; then
4911                 # verify the conversion output
4912                 cmp -s $new $verify > /dev/null
4913                 if [ $? -eq 1 ]; then
4914                         error "routes conversion failed"
4915                 fi
4916
4917                 lustre_routes_config --dry-run --verbose $new > $out
4918                 # check that the script succeeded
4919                 cmp -s $out $verify_conf > /dev/null
4920                 if [ $? -eq 1 ]; then
4921                         error "routes config failed"
4922                 fi
4923         else
4924                 error "routes conversion test failed"
4925         fi
4926         # remove generated files
4927         rm -f $new $legacy $verify $verify_conf $out
4928 }
4929 run_test 67 "test routes conversion and configuration"
4930
4931 test_68() {
4932         local fid
4933         local seq
4934         local START
4935         local END
4936
4937         [ "$MDS1_VERSION" -ge $(version_code 2.4.53) ] ||
4938                 skip "Need MDS version at least 2.4.53"
4939
4940         umount_client $MOUNT || error "umount client failed"
4941
4942         start_mgsmds
4943         start_ost
4944
4945         # START-END - the sequences we'll be reserving
4946         START=$(do_facet $SINGLEMDS \
4947                 $LCTL get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
4948         END=$((START + (1 << 30)))
4949         do_facet $SINGLEMDS \
4950                 $LCTL set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
4951
4952         # reset the sequences MDT0000 has already assigned
4953         do_facet $SINGLEMDS \
4954                 $LCTL set_param seq.srv*MDT0000.space=clear
4955
4956         # remount to let the client allocate new sequence
4957         mount_client $MOUNT || error "mount client failed"
4958
4959         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4960         do_facet $SINGLEMDS \
4961                 $LCTL get_param seq.srv*MDT0000.space
4962         $LFS path2fid $DIR/$tfile
4963
4964         local old_ifs="$IFS"
4965         IFS='[:]'
4966         fid=($($LFS path2fid $DIR/$tfile))
4967         IFS="$old_ifs"
4968         let seq=${fid[1]}
4969
4970         if [[ $seq < $END ]]; then
4971                 error "used reserved sequence $seq?"
4972         fi
4973         cleanup || error "cleanup failed with $?"
4974 }
4975 run_test 68 "be able to reserve specific sequences in FLDB"
4976
4977 # Test 69: is about the total number of objects ever created on an OST.
4978 # so that when it is reformatted the normal MDS->OST orphan recovery won't
4979 # just "precreate" the missing objects. In the past it might try to recreate
4980 # millions of objects after an OST was reformatted
4981 test_69() {
4982         [[ "$MDS1_VERSION" -lt $(version_code 2.4.2) ]] &&
4983                 skip "Need MDS version at least 2.4.2"
4984
4985         [[ "$MDS1_VERSION" -ge $(version_code 2.4.50) ]] &&
4986         [[ "$MDS1_VERSION" -lt $(version_code 2.5.0) ]] &&
4987                 skip "Need MDS version at least 2.5.0"
4988
4989         setup
4990         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4991
4992         # use OST0000 since it probably has the most creations
4993         local OSTNAME=$(ostname_from_index 0)
4994         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
4995         local last_id=$(do_facet mds1 $LCTL get_param -n \
4996                         osp.$mdtosc_proc1.prealloc_last_id)
4997
4998         # Want to have OST LAST_ID over 5 * OST_MAX_PRECREATE to
4999         # verify that the LAST_ID recovery is working properly. If
5000         # not, then the OST will refuse to allow the MDS connect
5001         # because the LAST_ID value is too different from the MDS
5002         #define OST_MAX_PRECREATE=20000
5003         local ost_max_pre=20000
5004         local num_create=$(( ost_max_pre * 5 + 1 - last_id))
5005
5006         # If the LAST_ID is already over 5 * OST_MAX_PRECREATE, we don't
5007         # need to create any files. So, skip this section.
5008         if [ $num_create -gt 0 ]; then
5009                 # Check the number of inodes available on OST0
5010                 local files=0
5011                 local ifree=$($LFS df -i $MOUNT | awk '/OST0000/ { print $4 }')
5012                 log "On OST0, $ifree inodes available. Want $num_create."
5013
5014                 $LFS setstripe -i 0 $DIR/$tdir ||
5015                         error "$LFS setstripe -i 0 $DIR/$tdir failed"
5016                 if [ $ifree -lt 10000 ]; then
5017                         files=$(( ifree - 50 ))
5018                 else
5019                         files=10000
5020                 fi
5021
5022                 local j=$((num_create / files + 1))
5023                 for i in $(seq 1 $j); do
5024                         createmany -o $DIR/$tdir/$tfile-$i- $files ||
5025                                 error "createmany fail create $files files: $?"
5026                         unlinkmany $DIR/$tdir/$tfile-$i- $files ||
5027                                 error "unlinkmany failed unlink $files files"
5028                 done
5029         fi
5030
5031         # delete all of the files with objects on OST0 so the
5032         # filesystem is not inconsistent later on
5033         $LFS find $MOUNT --ost 0 -print0 | xargs -0 rm
5034
5035         umount_client $MOUNT || error "umount client failed"
5036         stop_ost || error "OST0 stop failure"
5037         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
5038                 $(ostdevname 1) $(ostvdevname 1) ||
5039                 error "reformat and replace $ostdev failed"
5040         start_ost || error "OST0 restart failure"
5041         wait_osc_import_state mds ost FULL
5042
5043         mount_client $MOUNT || error "mount client failed"
5044         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
5045         local idx=$($LFS getstripe -i $DIR/$tdir/$tfile-last)
5046         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
5047
5048         local iused=$($LFS df -i $MOUNT | awk '/OST0000/ { print $3 }')
5049         log "On OST0, $iused used inodes"
5050         [ $iused -ge $((ost_max_pre/2 + 1000)) ] &&
5051                 error "OST replacement created too many inodes; $iused"
5052         cleanup || error "cleanup failed with $?"
5053 }
5054 run_test 69 "replace an OST with the same index"
5055
5056 test_70a() {
5057         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5058         local MDTIDX=1
5059
5060         cleanup || error "cleanup failed with $?"
5061
5062         start_mdt 1 || error "MDT0 start fail"
5063
5064         start_ost || error "OST0 start fail"
5065         for num in $(seq 2 $MDSCOUNT); do
5066                 start_mdt $num || return
5067         done
5068
5069         mount_client $MOUNT || error "mount client fails"
5070
5071         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
5072
5073         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5074                 error "create remote dir fail"
5075
5076         rm -rf $DIR/$tdir || error "delete dir fail"
5077         cleanup || error "cleanup failed with $?"
5078 }
5079 run_test 70a "start MDT0, then OST, then MDT1"
5080
5081 test_70b() {
5082         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5083         local MDTIDX=1
5084
5085         start_ost || error "OST0 start fail"
5086
5087         start_mds || error "MDS start fail"
5088
5089         mount_client $MOUNT || error "mount client fails"
5090
5091         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
5092
5093         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5094                 error "create remote dir fail"
5095
5096         rm -rf $DIR/$tdir || error "delete dir fail"
5097
5098         cleanup || error "cleanup failed with $?"
5099 }
5100 run_test 70b "start OST, MDT1, MDT0"
5101
5102 test_70c() {
5103         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5104         local MDTIDX=1
5105
5106         start_mds || error "MDS start fail"
5107         start_ost || error "OST0 start fail"
5108
5109         mount_client $MOUNT || error "mount client fails"
5110         stop_mdt 1 || error "MDT1 start fail"
5111
5112         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
5113         echo "deactivate $mdc_for_mdt1"
5114         $LCTL --device $mdc_for_mdt1 deactivate ||
5115                 error "set $mdc_for_mdt1 deactivate failed"
5116
5117         mkdir $DIR/$tdir && error "mkdir succeed"
5118
5119         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
5120                 error "create remote dir succeed"
5121
5122         cleanup || error "cleanup failed with $?"
5123 }
5124 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
5125
5126 test_70d() {
5127         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5128         local MDTIDX=1
5129
5130         start_mds || error "MDS start fail"
5131         start_ost || error "OST0 start fail"
5132
5133         mount_client $MOUNT || error "mount client fails"
5134
5135         stop_mdt 2 || error "MDT1 start fail"
5136
5137         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
5138                              awk '{print $4}')
5139         echo "deactivate $mdc_for_mdt2"
5140         $LCTL --device $mdc_for_mdt2 deactivate ||
5141                 error "set $mdc_for_mdt2 deactivate failed"
5142
5143         mkdir $DIR/$tdir || error "mkdir fail"
5144         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
5145                 error "create remote dir succeed"
5146
5147         rm -rf $DIR/$tdir || error "delete dir fail"
5148
5149         cleanup || error "cleanup failed with $?"
5150 }
5151 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
5152
5153 test_70e() {
5154         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5155
5156         [ "$MDS1_VERSION" -ge $(version_code 2.7.62) ] ||
5157                 skip "Need MDS version at least 2.7.62"
5158
5159         reformat || error "reformat failed with $?"
5160
5161         load_modules
5162
5163         local mdsdev=$(mdsdevname 1)
5164         local ostdev=$(ostdevname 1)
5165         local mdsvdev=$(mdsvdevname 1)
5166         local ostvdev=$(ostvdevname 1)
5167         local opts_mds="$(mkfs_opts mds1 $mdsdev) --reformat $mdsdev $mdsvdev"
5168         local opts_ost="$(mkfs_opts ost1 $ostdev) --reformat $ostdev $ostvdev"
5169
5170         if ! combined_mgs_mds ; then
5171                 start_mgs
5172         fi
5173
5174         add mds1 $opts_mds || error "add mds1 failed"
5175         start_mdt 1 || error "start mdt1 failed"
5176         add ost1 $opts_ost || error "add ost1 failed"
5177         start_ost || error "start ost failed"
5178         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
5179
5180         local soc=$(do_facet mds1 "$LCTL get_param -n \
5181                     mdt.*MDT0000.sync_lock_cancel")
5182         [ $soc == "never" ] || error "SoC enabled on single MDS"
5183
5184         for i in $(seq 2 $MDSCOUNT); do
5185                 mdsdev=$(mdsdevname $i)
5186                 mdsvdev=$(mdsvdevname $i)
5187                 opts_mds="$(mkfs_opts mds$i $mdsdev) --reformat $mdsdev \
5188                           $mdsvdev"
5189                 add mds$i $opts_mds || error "add mds$i failed"
5190                 start_mdt $i || error "start mdt$i fail"
5191         done
5192
5193         wait_dne_interconnect
5194
5195         for i in $(seq $MDSCOUNT); do
5196                 soc=$(do_facet mds$i "$LCTL get_param -n \
5197                         mdt.*MDT000$((i - 1)).sync_lock_cancel")
5198                 [ $soc == "blocking" ] || error "SoC not enabled on DNE"
5199         done
5200
5201         for i in $(seq 2 $MDSCOUNT); do
5202                 stop_mdt $i || error "stop mdt$i fail"
5203         done
5204         soc=$(do_facet mds1 "$LCTL get_param -n \
5205                 mdt.*MDT0000.sync_lock_cancel")
5206         [ $soc == "never" ] || error "SoC enabled on single MDS"
5207         umount_client $MOUNT -f > /dev/null
5208
5209         cleanup || error "cleanup failed with $?"
5210 }
5211 run_test 70e "Sync-on-Cancel will be enabled by default on DNE"
5212
5213 test_71a() {
5214         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5215         if combined_mgs_mds; then
5216                 skip "needs separate MGS/MDT"
5217         fi
5218         local MDTIDX=1
5219
5220         start_mdt 1 || error "MDT0 start fail"
5221         start_ost || error "OST0 start fail"
5222         for num in $(seq 2 $MDSCOUNT); do
5223                 start_mdt $num || return
5224         done
5225
5226         start_ost2 || error "OST1 start fail"
5227
5228         mount_client $MOUNT || error "mount client fails"
5229
5230         mkdir $DIR/$tdir || error "mkdir fail"
5231         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5232                 error "create remote dir succeed"
5233
5234         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5235         rm -rf $DIR/$tdir || error "delete dir fail"
5236
5237         umount_client $MOUNT || error "umount_client failed"
5238         stop_mds || error "MDS stop fail"
5239         stop_ost || error "OST0 stop fail"
5240         stop_ost2 || error "OST1 stop fail"
5241 }
5242 run_test 71a "start MDT0 OST0, MDT1, OST1"
5243
5244 test_71b() {
5245         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5246         if combined_mgs_mds; then
5247                 skip "needs separate MGS/MDT"
5248         fi
5249         local MDTIDX=1
5250
5251         for num in $(seq 2 $MDSCOUNT); do
5252                 start_mdt $num || return
5253         done
5254         start_ost || error "OST0 start fail"
5255         start_mdt 1 || error "MDT0 start fail"
5256         start_ost2 || error "OST1 start fail"
5257
5258         mount_client $MOUNT || error "mount client fails"
5259
5260         mkdir $DIR/$tdir || error "mkdir fail"
5261         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5262                 error "create remote dir succeed"
5263
5264         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5265         rm -rf $DIR/$tdir || error "delete dir fail"
5266
5267         umount_client $MOUNT || error "umount_client failed"
5268         stop_mds || error "MDT0 stop fail"
5269         stop_ost || error "OST0 stop fail"
5270         stop_ost2 || error "OST1 stop fail"
5271 }
5272 run_test 71b "start MDT1, OST0, MDT0, OST1"
5273
5274 test_71c() {
5275         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5276         combined_mgs_mds && skip "needs separate MGS/MDT"
5277
5278         local MDTIDX=1
5279
5280         start_ost || error "OST0 start fail"
5281         start_ost2 || error "OST1 start fail"
5282         for num in $(seq 2 $MDSCOUNT); do
5283                 start_mdt $num || return
5284         done
5285         start_mdt 1 || error "MDT0 start fail"
5286
5287         mount_client $MOUNT || error "mount client fails"
5288
5289         mkdir $DIR/$tdir || error "mkdir fail"
5290         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5291                 error "create remote dir succeed"
5292
5293         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5294         rm -rf $DIR/$tdir || error "delete dir fail"
5295
5296         umount_client $MOUNT || error "umount_client failed"
5297         stop_mds || error "MDS stop fail"
5298         stop_ost || error "OST0 stop fail"
5299         stop_ost2 || error "OST1 stop fail"
5300
5301 }
5302 run_test 71c "start OST0, OST1, MDT1, MDT0"
5303
5304 test_71d() {
5305         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5306         combined_mgs_mds && skip "needs separate MGS/MDT"
5307
5308         local MDTIDX=1
5309
5310         start_ost || error "OST0 start fail"
5311         for num in $(seq 2 $MDSCOUNT); do
5312                 start_mdt $num || return
5313         done
5314         start_mdt 1 || error "MDT0 start fail"
5315         start_ost2 || error "OST1 start fail"
5316
5317         mount_client $MOUNT || error "mount client fails"
5318
5319         mkdir $DIR/$tdir || error "mkdir fail"
5320         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5321                         error "create remote dir succeed"
5322
5323         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5324         rm -rf $DIR/$tdir || error "delete dir fail"
5325
5326         umount_client $MOUNT || error "umount_client failed"
5327         stop_mds || error "MDS stop fail"
5328         stop_ost || error "OST0 stop fail"
5329         stop_ost2 || error "OST1 stop fail"
5330
5331 }
5332 run_test 71d "start OST0, MDT1, MDT0, OST1"
5333
5334 test_71e() {
5335         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
5336         combined_mgs_mds && skip "needs separate MGS/MDT"
5337
5338         local MDTIDX=1
5339
5340         start_ost || error "OST0 start fail"
5341         for num in $(seq 2 $MDSCOUNT); do
5342                 start_mdt $num || return
5343         done
5344         start_ost2 || error "OST1 start fail"
5345         start_mdt 1 || error "MDT0 start fail"
5346
5347         mount_client $MOUNT || error "mount client fails"
5348
5349         mkdir $DIR/$tdir || error "mkdir fail"
5350         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
5351                 error "create remote dir succeed"
5352
5353         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
5354         rm -rf $DIR/$tdir || error "delete dir fail"
5355
5356         umount_client $MOUNT || error "umount_client failed"
5357         stop_mds || error "MDS stop fail"
5358         stop_ost || error "OST0 stop fail"
5359         stop_ost2 || error "OST1 stop fail"
5360
5361 }
5362 run_test 71e "start OST0, MDT1, OST1, MDT0"
5363
5364 test_72() { #LU-2634
5365         [ "$mds1_FSTYPE" != ldiskfs ] &&
5366                 skip "ldiskfs only test"
5367
5368         local mdsdev=$(mdsdevname 1)
5369         local ostdev=$(ostdevname 1)
5370         local cmd="$E2FSCK -fnvd $mdsdev"
5371         local fn=3
5372         local add_options
5373
5374         cleanup
5375         load_modules
5376
5377         if combined_mgs_mds; then
5378                 add_options='--reformat'
5379         else
5380                 add_options='--reformat --replace'
5381         fi
5382
5383         #tune MDT with "-O extents"
5384
5385         for num in $(seq $MDSCOUNT); do
5386                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
5387                         $add_options $(mdsdevname $num) $(mdsvdevname $num) ||
5388                         error "add mds $num failed"
5389                 do_facet mds${num} "$TUNE2FS -O extents $(mdsdevname $num)" ||
5390                         error "$TUNE2FS failed on mds${num}"
5391         done
5392
5393         add ost1 $(mkfs_opts ost1 $ostdev) $add_options $ostdev ||
5394                 error "add $ostdev failed"
5395         start_mds || error "start mds failed"
5396         start_ost || error "start ost failed"
5397         mount_client $MOUNT || error "mount client failed"
5398
5399         #create some short symlinks
5400         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5401         createmany -o $DIR/$tdir/$tfile-%d $fn
5402         echo "create $fn short symlinks"
5403         for i in $(seq -w 1 $fn); do
5404                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
5405         done
5406         ls -al $MOUNT
5407
5408         #umount
5409         umount_client $MOUNT || error "umount client failed"
5410         stop_mds || error "stop mds failed"
5411         stop_ost || error "stop ost failed"
5412
5413         #run e2fsck
5414         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
5415 }
5416 run_test 72 "test fast symlink with extents flag enabled"
5417
5418 test_73() { #LU-3006
5419         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
5420         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $(ostdevname 1)" ||
5421                 error "1st tunefs failed"
5422         start_mgsmds || error "start mds failed"
5423         start_ost || error "start ost failed"
5424         mount_client $MOUNT || error "mount client failed"
5425         $LCTL get_param -n osc.*OST0000-osc-[^M]*.import | grep failover_nids |
5426                 grep 1.2.3.4@$NETTYPE || error "failover nids haven't changed"
5427         umount_client $MOUNT || error "umount client failed"
5428         stop_ost
5429         stop_mds
5430 }
5431 run_test 73 "failnode to update from mountdata properly"
5432
5433 test_75() { # LU-2374
5434         [[ "$MDS1_VERSION" -lt $(version_code 2.4.1) ]] &&
5435                 skip "Need MDS version at least 2.4.1"
5436
5437         local index=0
5438         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
5439                 --replace --reformat $(mdsdevname 1) $(mdsvdevname 1)"
5440         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
5441                 --replace --reformat $(ostdevname 1) $(ostvdevname 1)"
5442
5443         #check with default parameters
5444         add mds1 $opts_mds || error "add mds1 failed for default params"
5445         add ost1 $opts_ost || error "add ost1 failed for default params"
5446
5447         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
5448         opts_mds=$(echo $opts_mds |
5449                    sed -e "s/--index=$index/--index=$index --mdt/")
5450         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
5451         opts_ost=$(echo $opts_ost |
5452                    sed -e "s/--index=$index/--index=$index --ost/")
5453
5454         add mds1 $opts_mds || error "add mds1 failed for new params"
5455         add ost1 $opts_ost || error "add ost1 failed for new params"
5456
5457         reformat_and_config
5458         return 0
5459 }
5460 run_test 75 "The order of --index should be irrelevant"
5461
5462 test_76a() {
5463         [[ "$MGS_VERSION" -ge $(version_code 2.4.52) ]] ||
5464                 skip "Need MDS version at least 2.4.52"
5465
5466         setup
5467         local MDMB_PARAM="osc.*.max_dirty_mb"
5468         echo "Change MGS params"
5469         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
5470                 head -1)
5471         echo "max_dirty_mb: $MAX_DIRTY_MB"
5472         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB - 10))
5473         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
5474         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
5475         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
5476                 head -1" $NEW_MAX_DIRTY_MB
5477         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
5478         echo "$MAX_DIRTY_MB"
5479         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
5480                 error "error while apply max_dirty_mb"
5481
5482         echo "Check the value is stored after remount"
5483         stopall
5484         setupall
5485         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
5486                 head -1" $NEW_MAX_DIRTY_MB
5487         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
5488         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
5489                 error "max_dirty_mb is not saved after remount"
5490
5491         echo "Change OST params"
5492         CLIENT_PARAM="obdfilter.*.client_cache_count"
5493         local CLIENT_CACHE_COUNT
5494         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5495                 head -1)
5496         echo "client_cache_count: $CLIENT_CACHE_COUNT"
5497         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
5498         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
5499         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
5500         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
5501                 head -1" $NEW_CLIENT_CACHE_COUNT
5502         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5503                 head -1)
5504         echo "$CLIENT_CACHE_COUNT"
5505         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
5506                 error "error while apply client_cache_count"
5507
5508         echo "Check the value is stored after remount"
5509         stopall
5510         setupall
5511         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
5512                 head -1" $NEW_CLIENT_CACHE_COUNT
5513         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
5514                 head -1)
5515         echo "$CLIENT_CACHE_COUNT"
5516         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
5517                 error "client_cache_count is not saved after remount"
5518         stopall
5519 }
5520 run_test 76a "set permanent params with lctl across mounts"
5521
5522 test_76b() { # LU-4783
5523         [[ "$MGS_VERSION" -ge $(version_code 2.5.57) ]] ||
5524                 skip "Need MGS version at least 2.5.57"
5525         stopall
5526         setupall
5527         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
5528                 error "start params log failed"
5529         stopall
5530 }
5531 run_test 76b "verify params log setup correctly"
5532
5533 test_76c() {
5534         [[ "$MGS_VERSION" -ge $(version_code 2.8.54) ]] ||
5535                 skip "Need MDS version at least 2.4.52"
5536         setupall
5537         local MASK_PARAM="mdd.*.changelog_mask"
5538         echo "Change changelog_mask"
5539         do_facet mgs $LCTL set_param -P $MASK_PARAM=-CLOSE ||
5540                 error "Can't change changlog_mask"
5541         wait_update $(facet_host mds) "$LCTL get_param -n $MASK_PARAM |
5542                 grep 'CLOSE'" ""
5543
5544         echo "Check the value is stored after mds remount"
5545         stop_mds || error "Failed to stop MDS"
5546         start_mds || error "Failed to start MDS"
5547         local CHANGELOG_MASK=$(do_facet mgs $LCTL get_param -n $MASK_PARAM)
5548         echo $CHANGELOG_MASK | grep CLOSE > /dev/null &&
5549                 error "changelog_mask is not changed"
5550
5551         stopall
5552 }
5553 run_test 76c "verify changelog_mask is applied with lctl set_param -P"
5554
5555 test_76d() { #LU-9399
5556         setupall
5557
5558         local xattr_cache="llite.*.xattr_cache"
5559         local cmd="$LCTL get_param -n $xattr_cache | head -1"
5560         local new=$((($(eval $cmd) + 1) % 2))
5561
5562         echo "lctl set_param -P llite.*.xattr_cache=$new"
5563         do_facet mgs $LCTL set_param -P $xattr_cache=$new ||
5564                 error "Can't change xattr_cache"
5565         wait_update $HOSTNAME "$cmd" "$new"
5566
5567         echo "Check $xattr_cache on client $MOUNT"
5568         umount_client $MOUNT || error "umount $MOUNT failed"
5569         mount_client $MOUNT || error "mount $MOUNT failed"
5570         [ $(eval $cmd) -eq $new ] ||
5571                 error "$xattr_cache != $new on client $MOUNT"
5572
5573         echo "Check $xattr_cache on the new client $MOUNT2"
5574         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
5575         [ $(eval $cmd) -eq $new ] ||
5576                 error "$xattr_cache != $new on client $MOUNT2"
5577         umount_client $MOUNT2 || error "umount $MOUNT2 failed"
5578
5579         stopall
5580 }
5581 run_test 76d "verify llite.*.xattr_cache can be set by 'lctl set_param -P' correctly"
5582
5583 test_77() { # LU-3445
5584         [[ "$MDS1_VERSION" -ge $(version_code 2.8.55) ]] ||
5585                 skip "Need MDS version 2.8.55+ "
5586
5587         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
5588                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
5589                 skip_env "mixed loopback and real device not working"
5590         fi
5591
5592         local fs2mdsdev=$(mdsdevname 1_2)
5593         local fs2ostdev=$(ostdevname 1_2)
5594         local fs2mdsvdev=$(mdsvdevname 1_2)
5595         local fs2ostvdev=$(ostvdevname 1_2)
5596         local fsname=test1234
5597         local mgsnid
5598         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
5599
5600         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
5601
5602         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
5603                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
5604         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
5605                 error "start fs2mds failed"
5606
5607         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
5608         mgsnid="0.0.0.0@tcp,$mgsnid,$mgsnid:$mgsnid"
5609
5610         add fs2ost --mgsnode=$mgsnid $(mkfs_opts ost1 $fs2ostdev) \
5611                 --failnode=$failnid --fsname=$fsname \
5612                 --reformat $fs2ostdev $fs2ostvdev ||
5613                         error "add fs2ost failed"
5614         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
5615
5616         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
5617         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
5618         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
5619         cleanup_fs2
5620 }
5621 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
5622
5623 test_78() {
5624         [[ "$mds1_FSTYPE" != ldiskfs ||
5625            "$ost1_FSTYPE" != ldiskfs ]] &&
5626                 skip "ldiskfs only test"
5627
5628         # reformat the Lustre filesystem with a smaller size
5629         local saved_MDSCOUNT=$MDSCOUNT
5630         local saved_MDSSIZE=$MDSSIZE
5631         local saved_OSTCOUNT=$OSTCOUNT
5632         local saved_OSTSIZE=$OSTSIZE
5633         MDSCOUNT=1
5634         OSTCOUNT=1
5635         MDSSIZE=$((MDSSIZE - 20000))
5636         OSTSIZE=$((OSTSIZE - 20000))
5637         reformat || error "(1) reformat Lustre filesystem failed"
5638         MDSSIZE=$saved_MDSSIZE
5639         OSTSIZE=$saved_OSTSIZE
5640
5641         # mount the Lustre filesystem
5642         setup_noconfig || error "(2) setup Lustre filesystem failed"
5643
5644         # create some files
5645         log "create test files"
5646         local i
5647         local file
5648         local num_files=100
5649
5650         mkdir $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
5651         $LFS df; $LFS df -i
5652         for i in $(seq $num_files); do
5653                 file=$MOUNT/$tdir/$tfile-$i
5654                 dd if=/dev/urandom of=$file count=1 bs=1M || {
5655                         $LCTL get_param osc.*.cur*grant*
5656                         $LFS df; $LFS df -i;
5657                         # stop creating files if there is no more space
5658                         if [ ! -e $file ]; then
5659                                 num_files=$((i - 1))
5660                                 break
5661                         fi
5662
5663                         $LFS getstripe -v $file
5664                         local ost_idx=$(LFS getstripe -i $file)
5665                         do_facet ost$((ost_idx + 1)) \
5666                                 $LCTL get_param obdfilter.*.*grant*
5667                         error "(4) create $file failed"
5668                 }
5669         done
5670
5671         # unmount the Lustre filesystem
5672         cleanup || error "(5) cleanup Lustre filesystem failed"
5673
5674         # run e2fsck on the MDT and OST devices
5675         local mds_host=$(facet_active_host $SINGLEMDS)
5676         local ost_host=$(facet_active_host ost1)
5677         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
5678         local ost_dev=$(ostdevname 1)
5679
5680         run_e2fsck $mds_host $mds_dev "-y"
5681         run_e2fsck $ost_host $ost_dev "-y"
5682
5683         # get the original block count of the MDT and OST filesystems
5684         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
5685         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
5686
5687         # expand the MDT and OST filesystems to the device size
5688         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
5689         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
5690
5691         # run e2fsck on the MDT and OST devices again
5692         run_e2fsck $mds_host $mds_dev "-y"
5693         run_e2fsck $ost_host $ost_dev "-y"
5694
5695         # mount the Lustre filesystem
5696         setup
5697
5698         # check the files
5699         log "check files after expanding the MDT and OST filesystems"
5700         for i in $(seq $num_files); do
5701                 file=$MOUNT/$tdir/$tfile-$i
5702                 $CHECKSTAT -t file -s 1048576 $file ||
5703                         error "(6) checkstat $file failed"
5704         done
5705
5706         # create more files
5707         log "create more files after expanding the MDT and OST filesystems"
5708         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
5709                 file=$MOUNT/$tdir/$tfile-$i
5710                 dd if=/dev/urandom of=$file count=1 bs=1M ||
5711                         error "(7) create $file failed"
5712         done
5713
5714         # unmount the Lustre filesystem
5715         cleanup || error "(8) cleanup Lustre filesystem failed"
5716
5717         # run e2fsck on the MDT and OST devices
5718         run_e2fsck $mds_host $mds_dev "-y"
5719         run_e2fsck $ost_host $ost_dev "-y"
5720
5721         # get the maximum block count of the MDT and OST filesystems
5722         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
5723         local ost_max_blks=$(get_block_count ost1 $ost_dev)
5724
5725         # get the minimum block count of the MDT and OST filesystems
5726         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
5727                                 grep minimum | sed -e 's/^.*filesystem: //g')
5728         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
5729                                 grep minimum | sed -e 's/^.*filesystem: //g')
5730
5731         # shrink the MDT and OST filesystems to a smaller size
5732         local shrunk=false
5733         local new_blks
5734         local base_blks
5735         if [[ $mds_max_blks -gt $mds_min_blks &&
5736               $mds_max_blks -gt $mds_orig_blks ]]; then
5737                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
5738                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
5739                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
5740                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
5741                         error "shrink $SINGLEMDS to $new_blks failed"
5742                 shrunk=true
5743         fi
5744
5745         if [[ $ost_max_blks -gt $ost_min_blks &&
5746               $ost_max_blks -gt $ost_orig_blks ]]; then
5747                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
5748                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
5749                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
5750                 run_resize2fs ost1 $ost_dev $new_blks ||
5751                         error "shrink ost1 to $new_blks failed"
5752                 shrunk=true
5753         fi
5754
5755         # check whether the MDT or OST filesystem was shrunk or not
5756         if ! $shrunk; then
5757                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
5758                 reformat_and_config ||
5759                         error "(10) reformat Lustre filesystem failed"
5760                 return 0
5761         fi
5762
5763         # run e2fsck on the MDT and OST devices again
5764         run_e2fsck $mds_host $mds_dev "-y"
5765         run_e2fsck $ost_host $ost_dev "-y"
5766
5767         # mount the Lustre filesystem again
5768         setup
5769
5770         # check the files
5771         log "check files after shrinking the MDT and OST filesystems"
5772         for i in $(seq $((num_files + 10))); do
5773                 file=$MOUNT/$tdir/$tfile-$i
5774                 $CHECKSTAT -t file -s 1048576 $file ||
5775                         error "(11) checkstat $file failed"
5776         done
5777
5778         # unmount and reformat the Lustre filesystem
5779         cleanup || error "(12) cleanup Lustre filesystem failed"
5780         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
5781
5782         MDSCOUNT=$saved_MDSCOUNT
5783         OSTCOUNT=$saved_OSTCOUNT
5784         reformat_and_config || error "(14) reformat Lustre filesystem failed"
5785 }
5786 run_test 78 "run resize2fs on MDT and OST filesystems"
5787
5788 test_79() { # LU-4227
5789         [[ "$MDS1_VERSION" -ge $(version_code 2.5.59) ]] ||
5790                 skip "Need MDS version at least 2.5.59"
5791
5792         local mdsdev1=$(mdsdevname 1)
5793         local mdsvdev1=$(mdsvdevname 1)
5794         local mdsdev2=$(mdsdevname 2)
5795         local mdsvdev2=$(mdsvdevname 2)
5796         local ostdev1=$(ostdevname 1)
5797         local ostvdev1=$(ostvdevname 1)
5798         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
5799         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
5800         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
5801         local mgsnode_opt
5802
5803         # remove --mgs/--mgsnode from mkfs.lustre options
5804         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
5805
5806         mgsnode_opt=$(echo $opts_mds2 |
5807                 awk '{ for ( i = 1; i < NF; i++ )
5808                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
5809         [ -n "$mgsnode_opt" ] &&
5810                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
5811
5812         mgsnode_opt=$(echo $opts_ost1 |
5813                 awk '{ for ( i = 1; i < NF; i++ )
5814                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
5815         [ -n "$mgsnode_opt" ] &&
5816                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
5817         load_modules
5818         # -MGS, format a mdt without --mgs option
5819         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
5820                 error "Must specify --mgs when formatting mdt combined with mgs"
5821
5822         # +MGS, format a mdt/ost without --mgsnode option
5823         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
5824                 > /dev/null || error "start mds1 failed"
5825         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
5826                 error "Must specify --mgsnode when formatting a mdt"
5827         add ost1 $opts_ost1 $ostdev1 $ostvdev2 &&
5828                 error "Must specify --mgsnode when formatting an ost"
5829
5830         reformat_and_config
5831 }
5832 run_test 79 "format MDT/OST without mgs option (should return errors)"
5833
5834 test_80() {
5835         start_mds || error "Failed to start MDT"
5836         start_ost || error "Failed to start OST1"
5837         uuid=$(do_facet ost1 $LCTL get_param -n mgc.*.uuid)
5838 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
5839         do_facet ost1 "$LCTL set_param fail_val=10 fail_loc=0x906"
5840         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x906"
5841         do_facet mgs "$LCTL set_param -n mgs/MGS/evict_client $uuid"
5842         sleep 30
5843         start_ost2 || error "Failed to start OST2"
5844
5845         do_facet ost1 "$LCTL set_param fail_loc=0"
5846         stop_ost2
5847         stop_ost
5848         stop_mds
5849 }
5850 run_test 80 "mgc import reconnect race"
5851
5852 #Save the original values of $OSTCOUNT and $OSTINDEX$i.
5853 save_ostindex() {
5854         local new_ostcount=$1
5855         saved_ostcount=$OSTCOUNT
5856         OSTCOUNT=$new_ostcount
5857
5858         local i
5859         local index
5860         for i in $(seq $OSTCOUNT); do
5861                 index=OSTINDEX$i
5862                 eval saved_ostindex$i=${!index}
5863                 eval OSTINDEX$i=""
5864         done
5865 }
5866
5867 # Restore the original values of $OSTCOUNT and $OSTINDEX$i.
5868 restore_ostindex() {
5869         trap 0
5870
5871         local i
5872         local index
5873         for i in $(seq $OSTCOUNT); do
5874                 index=saved_ostindex$i
5875                 eval OSTINDEX$i=${!index}
5876         done
5877         OSTCOUNT=$saved_ostcount
5878
5879         reformat
5880         if ! combined_mgs_mds ; then
5881                 start_mgs
5882         fi
5883 }
5884
5885 # The main purpose of this test is to ensure the OST_INDEX_LIST functions as
5886 # expected. This test uses OST_INDEX_LIST to format OSTs with a randomly
5887 # assigned index and ensures we can mount such a formatted file system
5888 test_81() { # LU-4665
5889         [[ "$MDS1_VERSION" -ge $(version_code 2.6.54) ]] ||
5890                 skip "Need MDS version at least 2.6.54"
5891         [[ $OSTCOUNT -ge 3 ]] || skip_env "needs >= 3 OSTs"
5892
5893         stopall
5894
5895         # Each time RANDOM is referenced, a random integer between 0 and 32767
5896         # is generated.
5897         local i
5898         local saved_ostindex1=$OSTINDEX1
5899         for i in 65535 $((RANDOM + 65536)); do
5900                 echo -e "\nFormat ost1 with --index=$i, should fail"
5901                 OSTINDEX1=$i
5902                 if add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat \
5903                    $(ostdevname 1) $(ostvdevname 1); then
5904                         OSTINDEX1=$saved_ostindex1
5905                         error "format ost1 with --index=$i should fail"
5906                 fi
5907         done
5908         OSTINDEX1=$saved_ostindex1
5909
5910         save_ostindex 3
5911
5912         # Format OSTs with random sparse indices.
5913         trap "restore_ostindex" EXIT
5914         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices"
5915         OST_INDEX_LIST=[0,$((RANDOM * 2 % 65533 + 1)),65534] formatall
5916
5917         # Setup and check Lustre filesystem.
5918         start_mgsmds || error "start_mgsmds failed"
5919         for i in $(seq $OSTCOUNT); do
5920                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5921                         error "start ost$i failed"
5922         done
5923
5924         mount_client $MOUNT || error "mount client $MOUNT failed"
5925         check_mount || error "check client $MOUNT failed"
5926
5927         # Check max_easize.
5928         local max_easize=$($LCTL get_param -n llite.*.max_easize)
5929         # 65452 is XATTR_SIZE_MAX less ldiskfs ea overhead
5930         if large_xattr_enabled; then
5931                 [[ $max_easize -ge 65452 ]] ||
5932                         error "max_easize is $max_easize, should be at least 65452 bytes"
5933         else
5934                 # LU-11868
5935                 # 4012 is 4096 less ldiskfs ea overhead
5936                 [[ $max_easize -ge 4012 ]] ||
5937                         error "max_easize is $max_easize, should be at least 4012 bytes"
5938         fi
5939
5940         restore_ostindex
5941 }
5942 run_test 81 "sparse OST indexing"
5943
5944 # Here we exercise the stripe placement functionality on a file system that
5945 # has formatted the OST with a random index. With the file system the following
5946 # functionality is tested:
5947 #
5948 # 1. Creating a new file with a specific stripe layout.
5949 #
5950 # 2. Modifiy a existing empty file with a specific stripe layout.
5951 #
5952 # 3. Ensure we fail to set the stripe layout of a file that already has one.
5953 #
5954 # 4. If ost-index is defined we need to ensure it is the first entry in the
5955 #    ost index list returned by lfs getstripe.
5956 #
5957 # 5. Lastly ensure this functionality fails with directories.
5958 test_82a() { # LU-4665
5959         [[ "$MDS1_VERSION" -ge $(version_code 2.6.54) ]] ||
5960                 skip "Need MDS version at least 2.6.54"
5961         [[ $OSTCOUNT -ge 3 ]] || skip_env "needs >= 3 OSTs"
5962
5963         stopall
5964
5965         save_ostindex 3
5966
5967         # Format OSTs with random sparse indices.
5968         local i
5969         local index
5970         local ost_indices
5971         local LOV_V1_INSANE_STRIPE_COUNT=65532
5972         for i in $(seq $OSTCOUNT); do
5973                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
5974                 ost_indices+=" $index"
5975         done
5976         ost_indices=$(comma_list $ost_indices)
5977
5978         stack_trap "restore_ostindex" EXIT
5979         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
5980         OST_INDEX_LIST=[$ost_indices] formatall
5981
5982         # Setup Lustre filesystem.
5983         start_mgsmds || error "start_mgsmds failed"
5984         for i in $(seq $OSTCOUNT); do
5985                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
5986                         error "start ost$i failed"
5987         done
5988
5989         # Collect debug information - start of test
5990         do_nodes $(comma_list $(mdts_nodes)) \
5991                    $LCTL get_param osp.*.prealloc_*_id
5992
5993         mount_client $MOUNT || error "mount client $MOUNT failed"
5994         wait_osts_up
5995
5996         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
5997         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5998
5999         stack_trap "do_nodes $(comma_list $(mdts_nodes)) \
6000                    $LCTL get_param osp.*.prealloc_*_id" EXIT
6001
6002         # 1. If the file does not exist, new file will be created
6003         #    with specified OSTs.
6004         local file=$DIR/$tdir/$tfile-1
6005         local cmd="$LFS setstripe -o $ost_indices $file"
6006         echo -e "\n$cmd"
6007         eval $cmd || error "$cmd failed"
6008         check_stripe_count $file $OSTCOUNT
6009         check_obdidx $file $ost_indices
6010         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
6011                 error "write $file failed"
6012
6013         # 2. If the file already exists and is an empty file, the file
6014         #    will be attached with specified layout.
6015         file=$DIR/$tdir/$tfile-2
6016         mcreate $file || error "mcreate $file failed"
6017         cmd="$LFS setstripe -o $ost_indices $file"
6018         echo -e "\n$cmd"
6019         eval $cmd || error "$cmd failed"
6020         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
6021                 error "write $file failed"
6022         check_stripe_count $file $OSTCOUNT
6023         check_obdidx $file $ost_indices
6024
6025         # 3. If the file already has a valid layout attached, the command
6026         #    should fail with EBUSY.
6027         echo -e "\n$cmd"
6028         eval $cmd && error "stripe is already set on $file, $cmd should fail"
6029
6030         # 4. If [--stripe-index|-i <start_ost_idx>] is used, the index must
6031         #    be in the OST indices list.
6032         local start_ost_idx=${ost_indices##*,}
6033         file=$DIR/$tdir/$tfile-3
6034         cmd="$LFS setstripe -o $ost_indices -i $start_ost_idx $file"
6035         echo -e "\n$cmd"
6036         eval $cmd || error "$cmd failed"
6037         check_stripe_count $file $OSTCOUNT
6038         check_obdidx $file $ost_indices
6039         check_start_ost_idx $file $start_ost_idx
6040
6041         file=$DIR/$tdir/$tfile-4
6042         cmd="$LFS setstripe"
6043         cmd+=" -o $(exclude_items_from_list $ost_indices $start_ost_idx)"
6044         cmd+=" -i $start_ost_idx $file"
6045         echo -e "\n$cmd"
6046         eval $cmd && error "index $start_ost_idx should be in $ost_indices"
6047
6048         # 5. Specifying OST indices for directory should succeed.
6049         local dir=$DIR/$tdir/$tdir
6050         mkdir $dir || error "mkdir $dir failed"
6051         cmd="$LFS setstripe -o $ost_indices $dir"
6052         if [ "$MDS1_VERSION" -gt $(version_code 2.11.53) ] &&
6053                 [ "$CLIENT_VERSION" -gt $(version_code 2.11.53) ]; then
6054                 echo -e "\n$cmd"
6055                 eval $cmd || error "unable to specify OST indices on directory"
6056         else
6057                 echo "need MDS+client version at least 2.11.53"
6058         fi
6059
6060         restore_ostindex
6061 }
6062 run_test 82a "specify OSTs for file (succeed) or directory (succeed)"
6063
6064 cleanup_82b() {
6065         trap 0
6066
6067         # Remove OSTs from a pool and destroy the pool.
6068         destroy_pool $ost_pool || true
6069
6070         restore_ostindex
6071 }
6072
6073 # Test 82b is run to ensure that if the user supplies a pool with a specific
6074 # stripe layout that it behaves proprerly. It should fail in the case that
6075 # the supplied OST index list points to OSTs not contained in the user
6076 # supplied pool.
6077 test_82b() { # LU-4665
6078         [[ "$MDS1_VERSION" -ge $(version_code 2.6.54) ]] ||
6079                 skip "Need MDS version at least 2.6.54"
6080         [[ $OSTCOUNT -ge 4 ]] || skip_env "needs >= 4 OSTs"
6081
6082         stopall
6083
6084         save_ostindex 4
6085
6086         # Format OSTs with random sparse indices.
6087         local i
6088         local index
6089         local ost_indices
6090         local LOV_V1_INSANE_STRIPE_COUNT=65532
6091         for i in $(seq $OSTCOUNT); do
6092                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_COUNT))
6093                 ost_indices+=" $index"
6094         done
6095         ost_indices=$(comma_list $ost_indices)
6096
6097         trap "restore_ostindex" EXIT
6098         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
6099         OST_INDEX_LIST=[$ost_indices] formatall
6100
6101         # Setup Lustre filesystem.
6102         start_mgsmds || error "start_mgsmds failed"
6103         for i in $(seq $OSTCOUNT); do
6104                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
6105                         error "start ost$i failed"
6106         done
6107
6108         mount_client $MOUNT || error "mount client $MOUNT failed"
6109
6110         wait_osts_up
6111         $LFS df $MOUNT || error "$LFS df $MOUNT failed"
6112         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6113
6114         # Create a new pool and add OSTs into it.
6115         local ost_pool=$FSNAME.$TESTNAME
6116         create_pool $ost_pool || error "create OST pool $ost_pool failed"
6117
6118         trap - EXIT
6119         trap "cleanup_82b" EXIT
6120
6121         local ost_idx_in_list=${ost_indices##*,}
6122         local ost_idx_in_pool=$(exclude_items_from_list $ost_indices \
6123                                 $ost_idx_in_list)
6124
6125         local ost_targets="$FSNAME-OST["
6126         for i in ${ost_idx_in_pool//,/ }; do
6127                 ost_targets=$ost_targets$(printf "%04x," $i)
6128         done
6129         ost_targets="${ost_targets%,}]"
6130
6131         local ost_targets_uuid=$(for i in ${ost_idx_in_pool//,/ }; \
6132                                  do printf "$FSNAME-OST%04x_UUID\n" $i; done |
6133                                  sort -u | tr '\n' ' ')
6134
6135         local cmd="$LCTL pool_add $ost_pool $ost_targets"
6136         do_facet mgs $cmd || error "$cmd failed"
6137         wait_update $HOSTNAME "$LCTL get_param -n lov.$FSNAME-*.pools.$TESTNAME|
6138                                sort -u | tr '\n' ' ' " "$ost_targets_uuid" ||
6139                                         error "wait_update $ost_pool failed"
6140         wait_update_facet $SINGLEMDS "$LCTL pool_list $ost_pool | wc -l" 4 ||
6141                                 error "wait_update pool_list $ost_pool failed"
6142
6143         # If [--pool|-p <pool_name>] is set with [--ost-list|-o <ost_indices>],
6144         # then the OSTs must be the members of the pool.
6145         local file=$DIR/$tdir/$tfile
6146         cmd="$LFS setstripe -p $ost_pool -o $ost_idx_in_list $file"
6147         echo -e "\n$cmd"
6148         eval $cmd && error "OST with index $ost_idx_in_list should be" \
6149                            "in OST pool $ost_pool"
6150
6151         # Only select OST $ost_idx_in_list from $ost_pool for file.
6152         ost_idx_in_list=${ost_idx_in_pool#*,}
6153         cmd="$LFS setstripe -p $ost_pool -o $ost_idx_in_list $file"
6154         echo -e "\n$cmd"
6155         eval $cmd || error "$cmd failed"
6156         cmd="$LFS getstripe $file"
6157         echo -e "\n$cmd"
6158         eval $cmd || error "$cmd failed"
6159         check_stripe_count $file 2
6160         check_obdidx $file $ost_idx_in_list
6161         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
6162                 error "write $file failed"
6163
6164         cleanup_82b
6165 }
6166 run_test 82b "specify OSTs for file with --pool and --ost-list options"
6167
6168 test_83() {
6169         [[ "$OST1_VERSION" -ge $(version_code 2.6.91) ]] ||
6170                 skip "Need OST version at least 2.6.91"
6171         if [ "$ost1_FSTYPE" != ldiskfs ]; then
6172                 skip "ldiskfs only test"
6173         fi
6174
6175         local dev
6176         local ostmnt
6177         local fstype
6178         local mnt_opts
6179
6180         dev=$(ostdevname 1)
6181         ostmnt=$(facet_mntpt ost1)
6182
6183         # Mount the OST as an ldiskfs filesystem.
6184         log "mount the OST $dev as a $ost1_FSTYPE filesystem"
6185         add ost1 $(mkfs_opts ost1 $dev) $FSTYPE_OPT \
6186                 --reformat $dev > /dev/null ||
6187                 error "format ost1 error"
6188
6189         if ! test -b $dev; then
6190                 mnt_opts=$(csa_add "$OST_MOUNT_FS_OPTS" -o loop)
6191         fi
6192         echo "mnt_opts $mnt_opts"
6193         do_facet ost1 mount -t "$ost1_FSTYPE" $dev \
6194                 $ostmnt $mnt_opts
6195         # Run llverfs on the mounted ldiskfs filesystem.
6196         # It is needed to get ENOSPACE.
6197         log "run llverfs in partial mode on the OST $ost1_FSTYPE $ostmnt"
6198         do_rpc_nodes $(facet_host ost1) run_llverfs $ostmnt -vpl \
6199                 "no" || error "run_llverfs error on $ost1_FSTYPE"
6200
6201         # Unmount the OST.
6202         log "unmount the OST $dev"
6203         stop ost1
6204
6205         # Delete file IO_scrub. Later osd_scrub_setup will try to
6206         # create "IO_scrub" but will get ENOSPACE.
6207         writeconf_all
6208         echo "start ost1 service on `facet_active_host ost1`"
6209         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
6210
6211         local err
6212         err=$(do_facet ost1 dmesg | grep "VFS: Busy inodes after unmount of")
6213         echo "string err $err"
6214         [ -z "$err" ] || error $err
6215         reformat_and_config
6216 }
6217 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
6218 Busy inodes after unmount ..."
6219
6220 test_84() {
6221         local facet=$SINGLEMDS
6222         local num=$(echo $facet | tr -d "mds")
6223         local dev=$(mdsdevname $num)
6224         local time_min=$(recovery_time_min)
6225         local recovery_duration
6226         local completed_clients
6227         local correct_clients
6228         local wrap_up=5
6229
6230         echo "start mds service on $(facet_active_host $facet)"
6231         start_mds \
6232         "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min" $@ ||
6233                 error "start MDS failed"
6234
6235         start_ost || error "start OST0000 failed"
6236         start_ost2 || error "start OST0001 failed"
6237
6238         echo "recovery_time=$time_min, timeout=$TIMEOUT, wrap_up=$wrap_up"
6239
6240         mount_client $MOUNT1 || error "mount $MOUNT1 failed"
6241         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
6242         # make sure new superblock labels are sync'd before disabling writes
6243         sync_all_data
6244         sleep 5
6245
6246         replay_barrier $SINGLEMDS
6247         createmany -o $DIR1/$tfile-%d 1000
6248
6249         # We need to catch the end of recovery window to extend it.
6250         # Skip 5 requests and add delay to request handling.
6251         #define OBD_FAIL_TGT_REPLAY_DELAY  0x709 | FAIL_SKIP
6252         do_facet $SINGLEMDS "lctl set_param fail_loc=0x20000709 fail_val=5"
6253
6254         facet_failover --fsck $SINGLEMDS || error "failover: $?"
6255         client_up
6256
6257         echo "recovery status"
6258         do_facet $SINGLEMDS \
6259                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status"
6260
6261         recovery_duration=$(do_facet $SINGLEMDS \
6262                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
6263                 awk '/recovery_duration/ { print $2 }')
6264         (( $recovery_duration > $time_min + $wrap_up )) &&
6265                 error "recovery_duration > recovery_time_hard + wrap up"
6266         completed_clients=$(do_facet $SINGLEMDS \
6267                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
6268                 awk '/completed_clients/ { print $2 }')
6269
6270         correct_clients="$MDSCOUNT/$((MDSCOUNT+1))"
6271         [ "$completed_clients" = "${correct_clients}" ] ||
6272                 error "$completed_clients != $correct_clients"
6273
6274         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
6275         umount_client $MOUNT1
6276         umount_client $MOUNT2
6277
6278         stop_ost
6279         stop_ost2
6280         stop_mds
6281 }
6282 run_test 84 "check recovery_hard_time"
6283
6284 test_85() {
6285         [[ "$OST1_VERSION" -ge $(version_code 2.7.55) ]] ||
6286                 skip "Need OST version at least 2.7.55"
6287 ##define OBD_FAIL_OSD_OST_EA_FID_SET 0x197
6288         do_facet ost1 "lctl set_param fail_loc=0x197"
6289         start_ost
6290         stop_ost
6291 }
6292 run_test 85 "osd_ost init: fail ea_fid_set"
6293
6294 cleanup_86() {
6295         trap 0
6296
6297         # ost1 has already registered to the MGS before the reformat.
6298         # So after reformatting it with option "-G", it could not be
6299         # mounted to the MGS. Cleanup the system for subsequent tests.
6300         reformat_and_config
6301 }
6302
6303 test_86() {
6304         [ "$ost1_FSTYPE" = zfs ] &&
6305                 skip "LU-6442: no such mkfs params for ZFS OSTs"
6306         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
6307                 skip "Need server version newer than 2.7.55"
6308
6309         local OST_OPTS="$(mkfs_opts ost1 $(ostdevname 1)) \
6310                 --reformat $(ostdevname 1) $(ostvdevname 1)"
6311
6312         local NEWSIZE=1024
6313         local OLDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
6314                 awk '/Flex block group size: / { print $NF; exit; }')
6315
6316         local opts=OST_OPTS
6317         if [[ ${!opts} != *mkfsoptions* ]]; then
6318                 eval opts=\"${!opts} \
6319                         --mkfsoptions='\\\"-O flex_bg -G $NEWSIZE\\\"'\"
6320         else
6321                 val=${!opts//--mkfsoptions=\\\"/ \
6322                         --mkfsoptions=\\\"-O flex_bg -G $NEWSIZE }
6323                 eval opts='${val}'
6324         fi
6325
6326         echo "params: $opts"
6327
6328         trap cleanup_86 EXIT ERR
6329
6330         stopall
6331         add ost1 $opts || error "add ost1 failed with new params"
6332
6333         local FOUNDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
6334                 awk '/Flex block group size: / { print $NF; exit; }')
6335
6336         [[ $FOUNDSIZE == $NEWSIZE ]] ||
6337                 error "Flex block group size: $FOUNDSIZE, expected: $NEWSIZE"
6338
6339         cleanup_86
6340 }
6341 run_test 86 "Replacing mkfs.lustre -G option"
6342
6343 test_87() { #LU-6544
6344         [[ "$MDS1_VERSION" -ge $(version_code 2.9.51) ]] ||
6345                 skip "Need MDS version at least 2.9.51"
6346         [[ "$mds1_FSTYPE" != ldiskfs ]] &&
6347                 skip "ldiskfs only test"
6348         [[ $OSTCOUNT -gt 59 ]] &&
6349                 skip "Ignore wide striping situation"
6350         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
6351
6352         local mdsdev=$(mdsdevname 1)
6353         local mdsvdev=$(mdsvdevname 1)
6354         local file=$DIR/$tfile
6355         local mntpt=$(facet_mntpt $SINGLEMDS)
6356         local used_xattr_blk=0
6357         local inode_size=${1:-1024}
6358         local left_size=0
6359         local xtest="trusted.test"
6360         local value
6361         local orig
6362         local i
6363         local stripe_cnt=$(($OSTCOUNT + 2))
6364
6365         #Please see ldiskfs_make_lustre() for MDT inode size calculation
6366         if [ $stripe_cnt -gt 16 ]; then
6367                 inode_size=2048
6368         fi
6369         left_size=$(expr $inode_size - \
6370                         156 - \
6371                         32 - \
6372                         32 - 40 \* 3 - 32 \* 3 - $stripe_cnt \* 24 - 16 - 3 -  \
6373                         24 - 16 - 3 - \
6374                         24 - 18 - $(expr length $tfile) - 16 - 4)
6375         if [ $left_size -le 0 ]; then
6376                 echo "No space($left_size) is expected in inode."
6377                 echo "Try 1-byte xattr instead to verify this."
6378                 left_size=1
6379         else
6380                 echo "Estimate: at most $left_size-byte space left in inode."
6381         fi
6382
6383         unload_modules
6384         reformat
6385
6386         if ! combined_mgs_mds ; then
6387                 start_mgs
6388         fi
6389
6390         add mds1 $(mkfs_opts mds1 ${mdsdev}) --stripe-count-hint=$stripe_cnt \
6391                 --reformat $mdsdev $mdsvdev || error "add mds1 failed"
6392         start_mdt 1 > /dev/null || error "start mdt1 failed"
6393         for i in $(seq $OSTCOUNT); do
6394                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS > /dev/null ||
6395                         error "start ost$i failed"
6396         done
6397         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
6398         check_mount || error "check client $MOUNT failed"
6399
6400         #set xattr
6401         $LFS setstripe -E 1M -S 1M -c 1 -E 64M -c 1 -E -1 -c -1 $file ||
6402                 error "Create file with 3 components failed"
6403         $TRUNCATE $file $((1024*1024*64+1)) || error "truncate file failed"
6404         i=$($LFS getstripe -I3 -c $file) || error "get 3rd stripe count failed"
6405         if [ $i -ne $OSTCOUNT ]; then
6406                 left_size=$(expr $left_size + $(expr $OSTCOUNT - $i) \* 24)
6407                 echo -n "Since only $i out $OSTCOUNT OSTs are used, "
6408                 echo -n "the expected left space is changed to "
6409                 echo "$left_size bytes at most."
6410         fi
6411         value=$(generate_string $left_size)
6412         setfattr -n $xtest -v $value $file
6413         orig=$(get_xattr_value $xtest $file)
6414         [[ "$orig" != "$value" ]] && error "$xtest changed"
6415
6416         #Verify if inode has some expected space left
6417         umount $MOUNT > /dev/null || error "umount $MOUNT failed"
6418         stop_mdt 1 > /dev/null || error "stop mdt1 failed"
6419         mount_ldiskfs $SINGLEMDS || error "mount -t ldiskfs $SINGLEMDS failed"
6420
6421         do_facet $SINGLEMDS ls -sal $mntpt/ROOT/$tfile
6422         used_xattr_blk=$(do_facet $SINGLEMDS ls -s $mntpt/ROOT/$tfile |
6423                         awk '{ print $1 }')
6424         [[ $used_xattr_blk -eq 0 ]] &&
6425                 error "Please check MDS inode size calculation: \
6426                        more than $left_size-byte space left in inode."
6427         echo "Verified: at most $left_size-byte space left in inode."
6428
6429         unmount_ldiskfs $SINGLEMDS
6430
6431         for i in $(seq $OSTCOUNT); do
6432                 stop ost$i -f || error "stop ost$i failed"
6433         done
6434 }
6435 run_test 87 "check if MDT inode can hold EAs with N stripes properly"
6436
6437 test_88() {
6438         [ "$mds1_FSTYPE" == zfs ] &&
6439                 skip "LU-6662: no implementation for ZFS"
6440
6441         load_modules
6442
6443         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
6444                 --reformat $(mdsdevname 1) || error "add mds1 failed"
6445
6446         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
6447                 grep -e \".*opts:.*errors=remount-ro.*\"" ||
6448                 error "default mount options is missing"
6449
6450         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
6451                 --mountfsoptions="user_xattr,errors=panic" \
6452                 --reformat $(mdsdevname 1) || error "add mds1 failed"
6453
6454         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
6455                 grep -e \".*opts:.*errors=panic.*\"" ||
6456                 error "user can't override default mount options"
6457 }
6458 run_test 88 "check the default mount options can be overridden"
6459
6460 test_89() { # LU-7131
6461         [[ "$MDS1_VERSION" -ge $(version_code 2.9.54) ]] ||
6462                 skip "Need MDT version at least 2.9.54"
6463
6464         local key=failover.node
6465         local val1=192.0.2.254@tcp0 # Reserved IPs, see RFC 5735
6466         local val2=192.0.2.255@tcp0
6467         local mdsdev=$(mdsdevname 1)
6468         local params
6469
6470         stopall
6471
6472         [ "$mds1_FSTYPE" == zfs ] && import_zpool mds1
6473         # Check that parameters are added correctly
6474         echo "tunefs --param $key=$val1"
6475         do_facet mds "$TUNEFS --param $key=$val1 $mdsdev >/dev/null" ||
6476                 error "tunefs --param $key=$val1 failed"
6477         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6478                 error "tunefs --dryrun failed"
6479         params=${params##*Parameters:}
6480         params=${params%%exiting*}
6481         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val1) = "1" ] ||
6482                 error "on-disk parameter not added correctly via tunefs"
6483
6484         # Check that parameters replace existing instances when added
6485         echo "tunefs --param $key=$val2"
6486         do_facet mds "$TUNEFS --param $key=$val2 $mdsdev >/dev/null" ||
6487                 error "tunefs --param $key=$val2 failed"
6488         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6489                 error "tunefs --dryrun failed"
6490         params=${params##*Parameters:}
6491         params=${params%%exiting*}
6492         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "1" ] ||
6493                 error "on-disk parameter not replaced via tunefs"
6494         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val2) = "1" ] ||
6495                 error "on-disk parameter not replaced correctly via tunefs"
6496
6497         # Check that a parameter is erased properly
6498         echo "tunefs --erase-param $key"
6499         do_facet mds "$TUNEFS --erase-param $key $mdsdev >/dev/null" ||
6500                 error "tunefs --erase-param $key failed"
6501         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6502                 error "tunefs --dryrun failed"
6503         params=${params##*Parameters:}
6504         params=${params%%exiting*}
6505         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "0" ] ||
6506                 error "on-disk parameter not erased correctly via tunefs"
6507
6508         # Check that all the parameters are erased
6509         echo "tunefs --erase-params"
6510         do_facet mds "$TUNEFS --erase-params $mdsdev >/dev/null" ||
6511                 error "tunefs --erase-params failed"
6512         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6513                 error "tunefs --dryrun failed"
6514         params=${params##*Parameters:}
6515         params=${params%%exiting*}
6516         [ -z $params ] ||
6517                 error "all on-disk parameters not erased correctly via tunefs"
6518
6519         # Check the order of options --erase-params and --param
6520         echo "tunefs --param $key=$val1 --erase-params"
6521         do_facet mds \
6522                 "$TUNEFS --param $key=$val1 --erase-params $mdsdev >/dev/null"||
6523                 error "tunefs --param $key=$val1 --erase-params failed"
6524         params=$(do_facet mds $TUNEFS --dryrun $mdsdev) ||
6525                 error "tunefs --dryrun failed"
6526         params=${params##*Parameters:}
6527         params=${params%%exiting*}
6528         [ $(echo $params | tr ' ' '\n') == "$key=$val1" ] ||
6529                 error "on-disk param not added correctly with --erase-params"
6530
6531         reformat_and_config
6532 }
6533 run_test 89 "check tunefs --param and --erase-param{s} options"
6534
6535 # $1 test directory
6536 # $2 (optional) value of max_mod_rpcs_in_flight to set
6537 check_max_mod_rpcs_in_flight() {
6538         local dir="$1"
6539         local mmr="$2"
6540         local idx
6541         local facet
6542         local tmp
6543         local i
6544
6545         idx=$(printf "%04x" $($LFS getdirstripe -i $dir))
6546         facet="mds$((0x$idx + 1))"
6547
6548         if [ -z "$mmr" ]; then
6549                 # get value of max_mod_rcps_in_flight
6550                 mmr=$($LCTL get_param -n \
6551                         mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight) ||
6552                         error "Unable to get max_mod_rpcs_in_flight"
6553                 echo "max_mod_rcps_in_flight is $mmr"
6554         else
6555                 # set value of max_mod_rpcs_in_flight
6556                 $LCTL set_param \
6557                     mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight=$mmr ||
6558                         error "Unable to set max_mod_rpcs_in_flight to $mmr"
6559                 echo "max_mod_rpcs_in_flight set to $mmr"
6560         fi
6561
6562         # create mmr+1 files
6563         echo "creating $((mmr + 1)) files ..."
6564         umask 0022
6565         for i in $(seq $((mmr + 1))); do
6566                 touch $dir/file-$i
6567         done
6568
6569         ### part 1 ###
6570
6571         # consumes mmr-1 modify RPC slots
6572         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6573         # drop requests on MDT so that RPC slots are consumed
6574         # during all the request resend interval
6575         do_facet $facet "$LCTL set_param fail_loc=0x159"
6576         echo "launch $((mmr - 1)) chmod in parallel ..."
6577         for i in $(seq $((mmr - 1))); do
6578                 chmod 0600 $dir/file-$i &
6579         done
6580         sleep 1
6581
6582         # send one additional modify RPC
6583         do_facet $facet "$LCTL set_param fail_loc=0"
6584         echo "launch 1 additional chmod in parallel ..."
6585         chmod 0600 $dir/file-$mmr &
6586         sleep 1
6587
6588         # check this additional modify RPC get a modify RPC slot
6589         # and succeed its operation
6590         checkstat -vp 0600 $dir/file-$mmr ||
6591                 error "Unable to send $mmr modify RPCs in parallel"
6592         wait
6593
6594         ### part 2 ###
6595
6596         # consumes mmr modify RPC slots
6597         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6598         # drop requests on MDT so that RPC slots are consumed
6599         # during all the request resend interval
6600         do_facet $facet "$LCTL set_param fail_loc=0x159"
6601         echo "launch $mmr chmod in parallel ..."
6602         for i in $(seq $mmr); do
6603                 chmod 0666 $dir/file-$i &
6604         done
6605         sleep 1
6606
6607         # send one additional modify RPC
6608         do_facet $facet "$LCTL set_param fail_loc=0"
6609         echo "launch 1 additional chmod in parallel ..."
6610         chmod 0666 $dir/file-$((mmr + 1)) &
6611         sleep 1
6612
6613         # check this additional modify RPC blocked getting a modify RPC slot
6614         checkstat -vp 0644 $dir/file-$((mmr + 1)) ||
6615                 error "Unexpectedly send $(($mmr + 1)) modify RPCs in parallel"
6616         wait
6617 }
6618
6619 test_90a() {
6620         setup
6621
6622         [[ $($LCTL get_param mdc.*.import |
6623              grep "connect_flags:.*multi_mod_rpc") ]] ||
6624                 skip "Need MDC with 'multi_mod_rpcs' feature"
6625
6626         # check default value
6627         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6628         check_max_mod_rpcs_in_flight $DIR/$tdir
6629
6630         cleanup
6631 }
6632 run_test 90a "check max_mod_rpcs_in_flight is enforced"
6633
6634 test_90b() {
6635         local idx
6636         local facet
6637         local tmp
6638         local mmrpc
6639
6640         setup
6641
6642         [[ $($LCTL get_param mdc.*.import |
6643              grep "connect_flags:.*multi_mod_rpc") ]] ||
6644                 skip "Need MDC with 'multi_mod_rpcs' feature"
6645
6646         ### test 1.
6647         # update max_mod_rpcs_in_flight
6648         $LFS mkdir -c1 $DIR/${tdir}1 || error "mkdir $DIR/${tdir}1 failed"
6649         check_max_mod_rpcs_in_flight $DIR/${tdir}1 1
6650
6651         ### test 2.
6652         # check client is able to send multiple modify RPCs in paralell
6653         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
6654                 grep -c "multi_mod_rpcs")
6655         if [ "$tmp" -ne $MDSCOUNT ]; then
6656                 cleanup
6657                 skip "Client not able to send multiple modify RPCs in parallel"
6658         fi
6659
6660         # update max_mod_rpcs_in_flight
6661         $LFS mkdir -c1 $DIR/${tdir}2 || error "mkdir $DIR/${tdir}2 failed"
6662         check_max_mod_rpcs_in_flight $DIR/${tdir}2 5
6663
6664         ### test 3.
6665         $LFS mkdir -c1 $DIR/${tdir}3 || error "mkdir $DIR/${tdir}3 failed"
6666         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/${tdir}3))
6667         facet="mds$((0x$idx + 1))"
6668
6669         # save MDT max_mod_rpcs_per_client
6670         mmrpc=$(do_facet $facet \
6671                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
6672
6673         # update max_mod_rpcs_in_flight
6674         umount_client $MOUNT
6675         do_facet $facet \
6676                 "echo 16 > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6677         mount_client $MOUNT
6678         $LCTL set_param mdc.$FSNAME-MDT$idx-mdc-*.max_rpcs_in_flight=17
6679         check_max_mod_rpcs_in_flight $DIR/${tdir}3 16
6680
6681         # restore MDT max_mod_rpcs_per_client initial value
6682         do_facet $facet \
6683                 "echo $mmrpc > /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6684
6685         rm -rf $DIR/${tdir}?
6686         cleanup
6687 }
6688 run_test 90b "check max_mod_rpcs_in_flight is enforced after update"
6689
6690 save_params_90c() {
6691         # get max_rpcs_in_flight value
6692         mrif_90c=$($LCTL get_param -n \
6693                    mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
6694         echo "max_rpcs_in_flight is $mrif_90c"
6695
6696         # get max_mod_rpcs_in_flight value
6697         mmrif_90c=$($LCTL get_param -n \
6698                     mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight)
6699         echo "max_mod_rpcs_in_flight is $mmrif_90c"
6700
6701         # get MDT max_mod_rpcs_per_client value
6702         mmrpc_90c=$(do_facet mds1 \
6703                     cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
6704         echo "max_mod_rpcs_per_client is $mmrpc_90c"
6705 }
6706
6707 restore_params_90c() {
6708         trap 0
6709
6710         # restore max_rpcs_in_flight value
6711         do_facet mgs $LCTL set_param -P \
6712                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$mrif_90c
6713
6714         # restore max_mod_rpcs_in_flight value
6715         do_facet mgs $LCTL set_param -P \
6716                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mmrif_90c
6717
6718         # restore MDT max_mod_rpcs_per_client value
6719         do_facet mds1 "echo $mmrpc_90c > \
6720                        /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6721 }
6722
6723 test_90c() {
6724         local tmp
6725
6726         setup
6727
6728         [[ $($LCTL get_param mdc.*.import |
6729              grep "connect_flags:.*multi_mod_rpc") ]] ||
6730                 skip "Need MDC with 'multi_mod_rpcs' feature"
6731
6732         # check client is able to send multiple modify RPCs in paralell
6733         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
6734                 grep -c "multi_mod_rpcs")
6735         if [ "$tmp" -ne $MDSCOUNT ]; then
6736                 cleanup
6737                 skip "Client not able to send multiple modify RPCs in parallel"
6738         fi
6739
6740         save_params_90c
6741         stack_trap restore_params_90c
6742
6743         # testcase 1
6744         # attempt to set max_mod_rpcs_in_flight to max_rpcs_in_flight value
6745         # prerequisite: set max_mod_rpcs_per_client to max_rpcs_in_flight value
6746         do_facet mds1 "echo $mrif_90c > \
6747                        /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6748
6749         # if max_mod_rpcs_in_flight is set to be equal to or larger than
6750         # max_rpcs_in_flight, then max_rpcs_in_flight will be increased
6751         if [[ "$CLIENT_VERSION" -ge $(version_code 2.13.53) ]]; then
6752                 $LCTL set_param \
6753                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif_90c ||
6754                         error "set max_mod_rpcs_in_flight to $mrif_90c failed"
6755
6756                 local new_mrif=$($LCTL get_param -n \
6757                                  mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
6758                 ((new_mrif == mrif_90c + 1)) ||
6759                         error "max_rpcs_in_flight was not increased"
6760         fi
6761
6762         umount_client $MOUNT
6763         do_facet mds1 "echo $mmrpc_90c > \
6764                        /sys/module/mdt/parameters/max_mod_rpcs_per_client"
6765         mount_client $MOUNT
6766
6767         # testcase 2
6768         # attempt to set max_mod_rpcs_in_flight to max_mod_rpcs_per_client+1
6769         # prerequisite: set max_rpcs_in_flight to max_mod_rpcs_per_client+2
6770         $LCTL set_param \
6771                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$((mmrpc_90c + 2))
6772
6773         $LCTL set_param \
6774         mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$((mmrpc_90c + 1)) &&
6775         error "set max_mod_rpcs_in_flight to $((mmrpc_90c + 1)) should fail"
6776
6777         # testcase 3
6778         # attempt to set max_mod_rpcs_in_flight permanently
6779         do_facet mgs $LCTL set_param -P \
6780                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$mrif_90c
6781
6782         do_facet mgs $LCTL set_param -P \
6783                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif_90c
6784
6785         remount_client $MOUNT
6786
6787         wait_update_facet --verbose client "$LCTL get_param -n \
6788                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight" \
6789                 "$((mrif_90c + 1))" ||
6790                 error "expected '$((mrif_90c + 1))' for max_rpcs_in_flight"
6791
6792         wait_update_facet --verbose client "$LCTL get_param -n \
6793                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight" \
6794                 "$mrif_90c" ||
6795                 error "expected '$mrif_90c' for max_mod_rpcs_in_flight"
6796
6797         restore_params_90c
6798         cleanup
6799 }
6800 run_test 90c "check max_mod_rpcs_in_flight update limits"
6801
6802 test_90d() {
6803         local idx
6804         local facet
6805         local mmr
6806         local i
6807         local pid
6808
6809         setup
6810
6811         [[ $($LCTL get_param mdc.*.import |
6812              grep "connect_flags:.*multi_mod_rpc") ]] ||
6813                 skip "Need MDC with 'multi_mod_rpcs' feature"
6814
6815         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6816         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
6817         facet="mds$((0x$idx + 1))"
6818
6819         # check client version supports multislots
6820         tmp=$($LCTL get_param -N \
6821                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
6822         if [ -z "$tmp" ]; then
6823                 cleanup
6824                 skip "Client does not support multiple modify RPCs in flight"
6825         fi
6826
6827         # get current value of max_mod_rcps_in_flight
6828         mmr=$($LCTL get_param -n \
6829                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
6830         echo "max_mod_rcps_in_flight is $mmr"
6831
6832         # create mmr files
6833         echo "creating $mmr files ..."
6834         umask 0022
6835         for i in $(seq $mmr); do
6836                 touch $DIR/$tdir/file-$i
6837         done
6838
6839         # prepare for close RPC
6840         multiop_bg_pause $DIR/$tdir/file-close O_c
6841         pid=$!
6842
6843         # consumes mmr modify RPC slots
6844         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
6845         # drop requests on MDT so that RPC slots are consumed
6846         # during all the request resend interval
6847         do_facet $facet "$LCTL set_param fail_loc=0x159"
6848         echo "launch $mmr chmod in parallel ..."
6849         for i in $(seq $mmr); do
6850                 chmod 0600 $DIR/$tdir/file-$i &
6851         done
6852
6853         # send one additional close RPC
6854         do_facet $facet "$LCTL set_param fail_loc=0"
6855         echo "launch 1 additional close in parallel ..."
6856         kill -USR1 $pid
6857         cancel_lru_locks mdc
6858         sleep 1
6859
6860         # check this additional close RPC get a modify RPC slot
6861         # and multiop process completed
6862         [ -d /proc/$pid ] &&
6863                 error "Unable to send the additional close RPC in parallel"
6864         wait
6865         rm -rf $DIR/$tdir
6866         cleanup
6867 }
6868 run_test 90d "check one close RPC is allowed above max_mod_rpcs_in_flight"
6869
6870 check_uuid_on_ost() {
6871         local nid=$1
6872         do_facet ost1 "$LCTL get_param obdfilter.${FSNAME}*.exports.'$nid'.uuid"
6873 }
6874
6875 check_uuid_on_mdt() {
6876         local nid=$1
6877         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
6878 }
6879
6880 test_91() {
6881         local uuid
6882         local nid
6883         local found
6884
6885         [[ "$OST1_VERSION" -ge $(version_code 2.7.63) ]] ||
6886                 skip "Need OST version at least 2.7.63"
6887         [[ "$MDS1_VERSION" -ge $(version_code 2.7.63) ]] ||
6888                 skip "Need MDT version at least 2.7.63"
6889
6890         start_mds || error "MDS start failed"
6891         start_ost || error "unable to start OST"
6892         mount_client $MOUNT || error "client start failed"
6893         check_mount || error "check_mount failed"
6894
6895         if remote_mds; then
6896                 nid=$($LCTL list_nids | head -1 | sed  "s/\./\\\./g")
6897         else
6898                 nid="0@lo"
6899         fi
6900         uuid=$(get_client_uuid $MOUNT)
6901
6902         echo "list nids on mdt:"
6903         do_facet $SINGLEMDS "$LCTL list_param mdt.${FSNAME}*.exports.*"
6904         echo "uuid from $nid:"
6905         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
6906
6907         found=$(check_uuid_on_mdt $nid | grep $uuid)
6908         [ -z "$found" ] && error "can't find $uuid $nid on MDT"
6909         found=$(check_uuid_on_ost $nid | grep $uuid)
6910         [ -z "$found" ] && error "can't find $uuid $nid on OST"
6911
6912         # umount the client so it won't reconnect
6913         manual_umount_client --force || error "failed to umount $?"
6914         # shouldn't disappear on MDS after forced umount
6915         found=$(check_uuid_on_mdt $nid | grep $uuid)
6916         [ -z "$found" ] && error "can't find $uuid $nid"
6917
6918         echo "evict $nid"
6919         do_facet $SINGLEMDS \
6920                 "$LCTL set_param -n mdt.${mds1_svc}.evict_client nid:$nid"
6921
6922         found=$(check_uuid_on_mdt $nid | grep $uuid)
6923         [ -n "$found" ] && error "found $uuid $nid on MDT"
6924         found=$(check_uuid_on_ost $nid | grep $uuid)
6925         [ -n "$found" ] && error "found $uuid $nid on OST"
6926
6927         # check it didn't reconnect (being umounted)
6928         sleep $((TIMEOUT+1))
6929         found=$(check_uuid_on_mdt $nid | grep $uuid)
6930         [ -n "$found" ] && error "found $uuid $nid on MDT"
6931         found=$(check_uuid_on_ost $nid | grep $uuid)
6932         [ -n "$found" ] && error "found $uuid $nid on OST"
6933
6934         cleanup
6935 }
6936 run_test 91 "evict-by-nid support"
6937
6938 generate_ldev_conf() {
6939         # generate an ldev.conf file
6940         local ldevconfpath=$1
6941         local fstype=
6942         local fsldevformat=""
6943         touch $ldevconfpath
6944
6945         fstype=$(facet_fstype mgs)
6946         if [ "$fstype" == zfs ]; then
6947                 fsldevformat="$fstype:"
6948         else
6949                 fsldevformat=""
6950         fi
6951
6952         printf "%s\t-\t%s-MGS0000\t%s%s\n" \
6953                 $mgs_HOST \
6954                 $FSNAME \
6955                 $fsldevformat \
6956                 $(mgsdevname) > $ldevconfpath
6957
6958         local mdsfo_host=$mdsfailover_HOST;
6959         if [ -z "$mdsfo_host" ]; then
6960                 mdsfo_host="-"
6961         fi
6962
6963         for num in $(seq $MDSCOUNT); do
6964                 fstype=$(facet_fstype mds$num)
6965                 if [ "$fstype" == zfs ]; then
6966                         fsldevformat="$fstype:"
6967                 else
6968                         fsldevformat=""
6969                 fi
6970
6971                 printf "%s\t%s\t%s-MDT%04d\t%s%s\n" \
6972                         $mds_HOST \
6973                         $mdsfo_host \
6974                         $FSNAME \
6975                         $num \
6976                         $fsldevformat \
6977                         $(mdsdevname $num) >> $ldevconfpath
6978         done
6979
6980         local ostfo_host=$ostfailover_HOST;
6981         if [ -z "$ostfo_host" ]; then
6982                 ostfo_host="-"
6983         fi
6984
6985         for num in $(seq $OSTCOUNT); do
6986                 fstype=$(facet_fstype ost$num)
6987                 if [ "$fstype" == zfs ]; then
6988                         fsldevformat="$fstype:"
6989                 else
6990                         fsldevformat=""
6991                 fi
6992
6993                 printf "%s\t%s\t%s-OST%04d\t%s%s\n" \
6994                         $ost_HOST \
6995                         $ostfo_host \
6996                         $FSNAME \
6997                         $num \
6998                         $fsldevformat \
6999                         $(ostdevname $num) >> $ldevconfpath
7000         done
7001
7002         echo "----- $ldevconfpath -----"
7003         cat $ldevconfpath
7004         echo "--- END $ldevconfpath ---"
7005
7006 }
7007
7008 generate_nids() {
7009         # generate a nids file (mapping between hostname to nid)
7010         # looks like we only have the MGS nid available to us
7011         # so just echo that to a file
7012         local nidspath=$1
7013         echo -e "${mgs_HOST}\t${MGSNID}" > $nidspath
7014
7015         echo "----- $nidspath -----"
7016         cat $nidspath
7017         echo "--- END $nidspath ---"
7018 }
7019
7020 compare_ldev_output() {
7021         ldev_output=$1
7022         expected_output=$2
7023
7024         sort $expected_output -o $expected_output
7025         sort $ldev_output -o $ldev_output
7026
7027         echo "-- START OF LDEV OUTPUT --"
7028         cat $ldev_output
7029         echo "--- END OF LDEV OUTPUT ---"
7030
7031         echo "-- START OF EXPECTED OUTPUT --"
7032         cat $expected_output
7033         echo "--- END OF EXPECTED OUTPUT ---"
7034
7035         diff $expected_output $ldev_output
7036         return $?
7037 }
7038
7039 test_92() {
7040         if [ -z "$LDEV" ]; then
7041                 error "ldev is missing!"
7042         fi
7043
7044         local LDEVCONFPATH=$TMP/ldev.conf
7045         local NIDSPATH=$TMP/nids
7046
7047         echo "Host is $(hostname)"
7048
7049         generate_ldev_conf $LDEVCONFPATH
7050         generate_nids $NIDSPATH
7051
7052         # echo the mgs nid and compare it to environment variable MGSNID
7053         # also, ldev.conf and nids is a server side thing, use the OSS
7054         # hostname
7055         local output
7056         output=$($LDEV -c $LDEVCONFPATH -H $ost_HOST -n $NIDSPATH echo %m)
7057
7058         echo "-- START OF LDEV OUTPUT --"
7059         echo -e "$output"
7060         echo "--- END OF LDEV OUTPUT ---"
7061
7062         # ldev failed, error
7063         if [ $? -ne 0 ]; then
7064                 rm $LDEVCONFPATH $NIDSPATH
7065                 error "ldev failed to execute!"
7066         fi
7067
7068         # need to process multiple lines because of combined MGS and MDS
7069         echo -e $output | awk '{ print $2 }' | while read -r line ; do
7070                 if [ "$line" != "$MGSNID" ]; then
7071                         rm $LDEVCONFPATH $NIDSPATH
7072                         error "ldev failed mgs nid '$line', expected '$MGSNID'"
7073                 fi
7074         done
7075
7076         rm $LDEVCONFPATH $NIDSPATH
7077 }
7078 run_test 92 "ldev returns MGS NID correctly in command substitution"
7079
7080 test_93() {
7081         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs"
7082
7083         reformat
7084         #start mgs or mgs/mdt0
7085         if ! combined_mgs_mds ; then
7086                 start_mgs
7087                 start_mdt 1
7088         else
7089                 start_mdt 1
7090         fi
7091
7092         start_ost || error "OST0 start fail"
7093
7094         #define OBD_FAIL_MGS_WRITE_TARGET_DELAY  0x90e
7095         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x8000090e"
7096         for num in $(seq 2 $MDSCOUNT); do
7097                 start_mdt $num &
7098         done
7099
7100         mount_client $MOUNT || error "mount client fails"
7101         wait_osc_import_state mds ost FULL
7102         wait_osc_import_ready client ost
7103         check_mount || error "check_mount failed"
7104
7105         cleanup || error "cleanup failed with $?"
7106 }
7107 run_test 93 "register mulitple MDT at the same time"
7108
7109 test_94() {
7110         if [ -z "$LDEV" ]; then
7111                 error "ldev is missing!"
7112         fi
7113
7114         local LDEVCONFPATH=$TMP/ldev.conf
7115         local NIDSPATH=$TMP/nids
7116
7117         generate_ldev_conf $LDEVCONFPATH
7118         generate_nids $NIDSPATH
7119
7120         local LDEV_OUTPUT=$TMP/ldev-output.txt
7121         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME > $LDEV_OUTPUT
7122
7123         # ldev failed, error
7124         if [ $? -ne 0 ]; then
7125                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7126                 error "ldev failed to execute!"
7127         fi
7128
7129         # expected output
7130         local EXPECTED_OUTPUT=$TMP/ldev-expected.txt
7131
7132         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
7133
7134         for num in $(seq $MDSCOUNT); do
7135                 printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7136         done
7137
7138         for num in $(seq $OSTCOUNT); do
7139                 printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7140         done
7141
7142         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7143
7144         if [ $? -ne 0 ]; then
7145                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7146                 error "ldev failed to produce the correct hostlist!"
7147         fi
7148
7149         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7150 }
7151 run_test 94 "ldev outputs correct labels for file system name query"
7152
7153 test_95() {
7154         if [ -z "$LDEV" ]; then
7155                 error "ldev is missing!"
7156         fi
7157
7158         local LDEVCONFPATH=$TMP/ldev.conf
7159         local NIDSPATH=$TMP/nids
7160
7161         generate_ldev_conf $LDEVCONFPATH
7162         generate_nids $NIDSPATH
7163
7164         # SUCCESS CASES
7165         # file sys filter
7166         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME &>/dev/null
7167         if [ $? -ne 0 ]; then
7168                 rm $LDEVCONFPATH $NIDSPATH
7169                 error "ldev label filtering w/ -F failed!"
7170         fi
7171
7172         # local filter
7173         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -l  &>/dev/null
7174         if [ $? -ne 0 ]; then
7175                 rm $LDEVCONFPATH $NIDSPATH
7176                 error "ldev label filtering w/ -l failed!"
7177         fi
7178
7179         # foreign filter
7180         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f &>/dev/null
7181         if [ $? -ne 0 ]; then
7182                 rm $LDEVCONFPATH $NIDSPATH
7183                 error "ldev label filtering w/ -f failed!"
7184         fi
7185
7186         # all filter
7187         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a &>/dev/null
7188         if [ $? -ne 0 ]; then
7189                 rm $LDEVCONFPATH $NIDSPATH
7190                 error "ldev label filtering w/ -a failed!"
7191         fi
7192
7193         # FAILURE CASES
7194         # all & file sys
7195         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -F $FSNAME &>/dev/null
7196         if [ $? -eq 0 ]; then
7197                 rm $LDEVCONFPATH $NIDSPATH
7198                 error "ldev label filtering w/ -a and -F incorrectly succeeded"
7199         fi
7200
7201         # all & foreign
7202         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -f &>/dev/null
7203         if [ $? -eq 0 ]; then
7204                 rm $LDEVCONFPATH $NIDSPATH
7205                 error "ldev label filtering w/ -a and -f incorrectly succeeded"
7206         fi
7207
7208         # all & local
7209         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -l &>/dev/null
7210         if [ $? -eq 0 ]; then
7211                 rm $LDEVCONFPATH $NIDSPATH
7212                 error "ldev label filtering w/ -a and -l incorrectly succeeded"
7213         fi
7214
7215         # foreign & local
7216         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f -l &>/dev/null
7217         if [ $? -eq 0 ]; then
7218                 rm $LDEVCONFPATH $NIDSPATH
7219                 error "ldev label filtering w/ -f and -l incorrectly succeeded"
7220         fi
7221
7222         # file sys & local
7223         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -l &>/dev/null
7224         if [ $? -eq 0 ]; then
7225                 rm $LDEVCONFPATH $NIDSPATH
7226                 error "ldev label filtering w/ -F and -l incorrectly succeeded"
7227         fi
7228
7229         # file sys & foreign
7230         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -f &>/dev/null
7231         if [ $? -eq 0 ]; then
7232                 rm $LDEVCONFPATH $NIDSPATH
7233                 error "ldev label filtering w/ -F and -f incorrectly succeeded"
7234         fi
7235
7236         rm $LDEVCONFPATH $NIDSPATH
7237 }
7238 run_test 95 "ldev should only allow one label filter"
7239
7240 test_96() {
7241         if [ -z "$LDEV" ]; then
7242                 error "ldev is missing!"
7243         fi
7244
7245         local LDEVCONFPATH=$TMP/ldev.conf
7246         local NIDSPATH=$TMP/nids
7247
7248         generate_ldev_conf $LDEVCONFPATH
7249         generate_nids $NIDSPATH
7250
7251         local LDEV_OUTPUT=$TMP/ldev-output.txt
7252         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -H $mgs_HOST \
7253                 echo %H-%b | \
7254                 awk '{print $2}' > $LDEV_OUTPUT
7255
7256         # ldev failed, error
7257         if [ $? -ne 0 ]; then
7258                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7259                 error "ldev failed to execute!"
7260         fi
7261
7262         # expected output
7263         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
7264
7265         echo "$mgs_HOST-$(facet_fstype mgs)" > $EXPECTED_OUTPUT
7266
7267         if [ "$mgs_HOST" == "$mds_HOST" ]; then
7268                 for num in $(seq $MDSCOUNT); do
7269                         echo "$mds_HOST-$(facet_fstype mds$num)" \
7270                         >> $EXPECTED_OUTPUT
7271                 done
7272         fi
7273
7274         if [ "$mgs_HOST" == "$ost_HOST" ]; then
7275                 for num in $(seq $OSTCOUNT); do
7276                         echo "$ost_HOST-$(facet_fstype ost$num)" \
7277                         >> $EXPECTED_OUTPUT
7278                 done
7279         fi
7280
7281         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7282
7283         if [ $? -ne 0 ]; then
7284                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7285                 error "ldev failed to produce the correct output!"
7286         fi
7287
7288         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7289 }
7290 run_test 96 "ldev returns hostname and backend fs correctly in command sub"
7291
7292 test_97() {
7293         if [ -z "$LDEV" ]; then
7294                 error "ldev is missing!"
7295         fi
7296
7297         local LDEVCONFPATH=$TMP/ldev.conf
7298         local NIDSPATH=$TMP/nids
7299
7300         generate_ldev_conf $LDEVCONFPATH
7301         generate_nids $NIDSPATH
7302
7303         local LDEV_OUTPUT=$TMP/ldev-output.txt
7304         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
7305
7306         echo -e "\nMDT role"
7307         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mdt > $LDEV_OUTPUT
7308
7309         if [ $? -ne 0 ]; then
7310                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
7311                 error "ldev failed to execute for mdt role!"
7312         fi
7313
7314         for num in $(seq $MDSCOUNT); do
7315                 printf "%s-MDT%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7316         done
7317
7318         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7319
7320         if [ $? -ne 0 ]; then
7321                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7322                 error "ldev failed to produce the correct output for mdt role!"
7323         fi
7324
7325         echo -e "\nOST role"
7326         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R ost > $LDEV_OUTPUT
7327
7328         if [ $? -ne 0 ]; then
7329                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
7330                 error "ldev failed to execute for ost role!"
7331         fi
7332
7333         rm $EXPECTED_OUTPUT
7334         for num in $(seq $OSTCOUNT); do
7335                 printf "%s-OST%04d\n" $FSNAME $num >> $EXPECTED_OUTPUT
7336         done
7337
7338         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7339
7340         if [ $? -ne 0 ]; then
7341                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7342                 error "ldev failed to produce the correct output for ost role!"
7343         fi
7344
7345         echo -e "\nMGS role"
7346         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mgs > $LDEV_OUTPUT
7347
7348         if [ $? -ne 0 ]; then
7349                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
7350                 error "ldev failed to execute for mgs role!"
7351         fi
7352
7353         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
7354
7355         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
7356
7357         if [ $? -ne 0 ]; then
7358                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7359                 error "ldev failed to produce the correct output for mgs role!"
7360         fi
7361
7362         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
7363 }
7364 run_test 97 "ldev returns correct ouput when querying based on role"
7365
7366 test_98()
7367 {
7368         local mountopt
7369         local temp=$MDS_MOUNT_OPTS
7370
7371         setup
7372         check_mount || error "mount failed"
7373         mountopt="user_xattr"
7374         for ((x = 1; x <= 400; x++)); do
7375                 mountopt="$mountopt,user_xattr"
7376         done
7377         mount_client $MOUNT remount,$mountopt 2>&1 | grep "too long" ||
7378                 error "Buffer overflow check failed"
7379         cleanup || error "cleanup failed"
7380 }
7381 run_test 98 "Buffer-overflow check while parsing mount_opts"
7382
7383 test_99()
7384 {
7385         [[ "$ost1_FSTYPE" != ldiskfs ]] &&
7386                 skip "ldiskfs only test"
7387         [[ "$OST1_VERSION" -ge $(version_code 2.8.57) ]] ||
7388                 skip "Need OST version at least 2.8.57"
7389
7390         local ost_opts="$(mkfs_opts ost1 $(ostdevname 1)) \
7391                 --reformat $(ostdevname 1) $(ostvdevname 1)"
7392         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" &&
7393                 skip "meta_bg already set"
7394
7395         local opts=ost_opts
7396         if [[ ${!opts} != *mkfsoptions* ]]; then
7397                 eval opts=\"${!opts} \
7398                 --mkfsoptions='\\\"-O ^resize_inode,meta_bg\\\"'\"
7399         else
7400                 local val=${!opts//--mkfsoptions=\\\"/ \
7401                 --mkfsoptions=\\\"-O ^resize_inode,meta_bg }
7402                 eval opts='${val}'
7403         fi
7404
7405         echo "params: $opts"
7406
7407         load_modules
7408         add ost1 $opts || error "add ost1 failed with new params"
7409
7410         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" ||
7411                 error "meta_bg is not set"
7412 }
7413 run_test 99 "Adding meta_bg option"
7414
7415 test_100() {
7416         reformat
7417
7418         start_mgsmds || error "MDS start failed"
7419         start_ost || error "unable to start OST"
7420         mount_client $MOUNT || error "client start failed"
7421         check_mount || error "check_mount failed"
7422
7423         # Desired output
7424         # MGS:
7425         #     0@lo
7426         # $FSNAME-MDT0000:
7427         #     0@lo
7428         # $FSNAME-OST0000:
7429         #     0@lo
7430         do_facet mgs 'lshowmount -v' | awk 'BEGIN {NR == 0; rc=1} /MGS:/ {rc=0}
7431                 END {exit rc}' || error "lshowmount have no output MGS"
7432
7433         do_facet mds1 'lshowmount -v' | awk 'BEGIN {NR == 2; rc=1} /-MDT0000:/
7434                 {rc=0} END {exit rc}' || error "lshowmount have no output MDT0"
7435
7436         do_facet ost1 'lshowmount -v' | awk 'BEGIN {NR == 4; rc=1} /-OST0000:/
7437                 {rc=0} END {exit rc}' || error "lshowmount have no output OST0"
7438
7439         cleanup || error "cleanup failed with $?"
7440 }
7441 run_test 100 "check lshowmount lists MGS, MDT, OST and 0@lo"
7442
7443 test_101() {
7444         local createmany_pid
7445         local dev=$FSNAME-OST0000-osc-MDT0000
7446         setup
7447
7448         mkdir $DIR1/$tdir
7449         createmany -o $DIR1/$tdir/$tfile-%d 50000 &
7450         createmany_pid=$!
7451         # MDT->OST reconnection causes MDT<->OST last_id synchornisation
7452         # via osp_precreate_cleanup_orphans.
7453         for ((i = 0; i < 100; i++)); do
7454                 for ((k = 0; k < 10; k++)); do
7455                         do_facet $SINGLEMDS "$LCTL --device $dev deactivate;" \
7456                                             "$LCTL --device $dev activate"
7457                 done
7458
7459                 ls -asl $MOUNT | grep '???' &&
7460                         { kill -9 $createmany_pid &>/dev/null;
7461                           error "File has no object on OST"; }
7462
7463                 kill -s 0 $createmany_pid || break
7464         done
7465         wait $createmany_pid
7466
7467         unlinkmany $DIR1/$tdir/$tfile-%d 50000
7468         cleanup
7469 }
7470 run_test 101 "Race MDT->OST reconnection with create"
7471
7472 test_102() {
7473         [[ "$MDS1_VERSION" -gt $(version_code 2.9.53) ]] ||
7474                 skip "Need server version greater than 2.9.53"
7475         [[ “$(mdsdevname 1)” != “$(mgsdevname)” ]] &&
7476                 [[ “$(facet_host mds1)” = “$(facet_host mgs)” ]] &&
7477                 skip "MGS must be on different node or combined"
7478
7479         cleanup || error "cleanup failed with $?"
7480
7481         local mds1dev=$(mdsdevname 1)
7482         local mds1mnt=$(facet_mntpt mds1)
7483         local mds1opts=$MDS_MOUNT_OPTS
7484
7485         if [ "$mds1_FSTYPE" == ldiskfs ] &&
7486            ! do_facet mds1 test -b $mds1dev; then
7487                 mds1opts=$(csa_add "$mds1opts" -o loop)
7488         fi
7489         if [[ "$mds1_FSTYPE" == zfs ]]; then
7490                 import_zpool mds1 || return ${PIPESTATUS[0]}
7491         fi
7492
7493         # unload all and only load libcfs to allow fail_loc setting
7494         do_facet mds1 $LUSTRE_RMMOD || error "unable to unload modules"
7495         do_facet mds1 modprobe libcfs || error "libcfs not loaded"
7496         do_facet mds1 lsmod \| grep libcfs || error "libcfs not loaded"
7497
7498         #define OBD_FAIL_OBDCLASS_MODULE_LOAD    0x60a
7499         do_facet mds1 "$LCTL set_param fail_loc=0x8000060a"
7500
7501         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts &&
7502                 error "mdt start must fail"
7503         do_facet mds1 lsmod \| grep  obdclass && error "obdclass must not load"
7504
7505         do_facet mds1 "$LCTL set_param fail_loc=0x0"
7506
7507         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts ||
7508                 error "mdt start must not fail"
7509
7510         cleanup || error "cleanup failed with $?"
7511 }
7512 run_test 102 "obdclass module cleanup upon error"
7513
7514 test_renamefs() {
7515         local newname=$1
7516
7517         echo "rename $FSNAME to $newname"
7518
7519         if ! combined_mgs_mds ; then
7520                 local dev=$(mgsdevname)
7521
7522                 do_facet mgs \
7523                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $dev" ||
7524                                 error "(7) Fail to rename MGS"
7525                 if [ "$(facet_fstype mgs)" = "zfs" ]; then
7526                         reimport_zpool mgs $newname-mgs
7527                 fi
7528         fi
7529
7530         for num in $(seq $MDSCOUNT); do
7531                 local dev=$(mdsdevname $num)
7532
7533                 do_facet mds${num} \
7534                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $dev" ||
7535                                 error "(8) Fail to rename MDT $num"
7536                 if [ "$(facet_fstype mds${num})" = "zfs" ]; then
7537                         reimport_zpool mds${num} $newname-mdt${num}
7538                 fi
7539         done
7540
7541         for num in $(seq $OSTCOUNT); do
7542                 local dev=$(ostdevname $num)
7543
7544                 do_facet ost${num} \
7545                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $dev" ||
7546                                 error "(9) Fail to rename OST $num"
7547                 if [ "$(facet_fstype ost${num})" = "zfs" ]; then
7548                         reimport_zpool ost${num} $newname-ost${num}
7549                 fi
7550         done
7551 }
7552
7553 test_103_set_pool() {
7554         local pname=$1
7555         local ost_x=$2
7556
7557         do_facet mgs $LCTL pool_add $FSNAME.$pname ${FSNAME}-$ost_x ||
7558                 error "Fail to add $ost_x to $FSNAME.$pname"
7559         wait_update $HOSTNAME \
7560                 "lctl get_param -n lov.$FSNAME-clilov-*.pools.$pname |
7561                  grep $ost_x" "$FSNAME-${ost_x}_UUID" ||
7562                 error "$ost_x is NOT in pool $FSNAME.$pname"
7563 }
7564
7565 test_103_check_pool() {
7566         local save_fsname=$1
7567         local errno=$2
7568
7569         stat $DIR/$tdir/test-framework.sh ||
7570                 error "($errno) Fail to stat"
7571         do_facet mgs $LCTL pool_list $FSNAME.pool1 ||
7572                 error "($errno) Fail to list $FSNAME.pool1"
7573         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname ||
7574                 error "($errno) Fail to list $FSNAME.$save_fsname"
7575         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname |
7576                 grep ${FSNAME}-OST0000 ||
7577                 error "($errno) List $FSNAME.$save_fsname is invalid"
7578
7579         local pname=$($LFS getstripe --pool $DIR/$tdir/d0)
7580         [ "$pname" = "$save_fsname" ] ||
7581                 error "($errno) Unexpected pool name $pname"
7582 }
7583
7584 test_103() {
7585         check_mount_and_prep
7586         rm -rf $DIR/$tdir
7587         mkdir $DIR/$tdir || error "(1) Fail to mkdir $DIR/$tdir"
7588         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir ||
7589                 error "(2) Fail to copy test-framework.sh"
7590
7591         do_facet mgs $LCTL pool_new $FSNAME.pool1 ||
7592                 error "(3) Fail to create $FSNAME.pool1"
7593         # name the pool name as the fsname
7594         do_facet mgs $LCTL pool_new $FSNAME.$FSNAME ||
7595                 error "(4) Fail to create $FSNAME.$FSNAME"
7596
7597         test_103_set_pool $FSNAME OST0000
7598
7599         $LFS setstripe -p $FSNAME $DIR/$tdir/d0 ||
7600                 error "(6) Fail to setstripe on $DIR/$tdir/d0"
7601
7602         KEEP_ZPOOL=true
7603         stopall
7604
7605         test_renamefs mylustre
7606
7607         local save_fsname=$FSNAME
7608         FSNAME="mylustre"
7609         setupall
7610
7611         test_103_check_pool $save_fsname 7
7612
7613         if [ $OSTCOUNT -ge 2 ]; then
7614                 test_103_set_pool $save_fsname OST0001
7615         fi
7616
7617         $LFS setstripe -p $save_fsname $DIR/$tdir/f0 ||
7618                 error "(16) Fail to setstripe on $DIR/$tdir/f0"
7619
7620         stopall
7621
7622         test_renamefs tfs
7623
7624         FSNAME="tfs"
7625         setupall
7626
7627         test_103_check_pool $save_fsname 17
7628
7629         stopall
7630
7631         test_renamefs $save_fsname
7632
7633         FSNAME=$save_fsname
7634         setupall
7635         KEEP_ZPOOL=false
7636 }
7637 run_test 103 "rename filesystem name"
7638
7639 test_104a() { # LU-6952
7640         local mds_mountopts=$MDS_MOUNT_OPTS
7641         local ost_mountopts=$OST_MOUNT_OPTS
7642         local mds_mountfsopts=$MDS_MOUNT_FS_OPTS
7643         local lctl_ver=$(do_facet $SINGLEMDS $LCTL --version |
7644                         awk '{ print $2 }')
7645
7646         [[ $(version_code $lctl_ver) -lt $(version_code 2.9.55) ]] &&
7647                 skip "this test needs utils above 2.9.55"
7648
7649         # specify "acl" in mount options used by mkfs.lustre
7650         if [ -z "$MDS_MOUNT_FS_OPTS" ]; then
7651                 MDS_MOUNT_FS_OPTS="acl,user_xattr"
7652         else
7653
7654                 MDS_MOUNT_FS_OPTS="${MDS_MOUNT_FS_OPTS},acl,user_xattr"
7655         fi
7656
7657         echo "mountfsopt: $MDS_MOUNT_FS_OPTS"
7658
7659         #reformat/remount the MDT to apply the MDT_MOUNT_FS_OPT options
7660         formatall
7661         if ! combined_mgs_mds ; then
7662                 start_mgs
7663         fi
7664
7665         if [ -z "$MDS_MOUNT_OPTS" ]; then
7666                 MDS_MOUNT_OPTS="-o noacl"
7667         else
7668                 MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
7669         fi
7670
7671         for num in $(seq $MDSCOUNT); do
7672                 start mds$num $(mdsdevname $num) $MDS_MOUNT_OPTS ||
7673                         error "Failed to start MDS"
7674         done
7675
7676         for num in $(seq $OSTCOUNT); do
7677                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
7678                         error "Failed to start OST"
7679         done
7680
7681         mount_client $MOUNT
7682         setfacl -m "d:$RUNAS_ID:rwx" $MOUNT &&
7683                 error "ACL is applied when FS is mounted with noacl."
7684
7685         MDS_MOUNT_OPTS=$mds_mountopts
7686         OST_MOUNT_OPTS=$ost_mountopts
7687         MDS_MOUNT_FS_OPTS=$mds_mountfsopts
7688 }
7689 run_test 104a "Make sure user defined options are reflected in mount"
7690
7691 test_104b() { # LU-12859
7692         mount_client $MOUNT3 flock,localflock
7693         stack_trap "umount_client $MOUNT3" EXIT
7694         mount | grep "$MOUNT3 .*,flock" && error "flock is still set"
7695         mount | grep "$MOUNT3 .*,localflock" || error "localflock is not set"
7696         umount_client $MOUNT3
7697         mount_client $MOUNT3 localflock,flock
7698         mount | grep "$MOUNT3 .*,localflock" && error "localflock is still set"
7699         mount | grep "$MOUNT3 .*,flock" || error "flock is not set"
7700         umount_client $MOUNT3
7701         mount_client $MOUNT3 localflock,flock,noflock
7702         flock_is_enabled $MOUNT3 && error "some flock is still enabled" || true
7703 }
7704 run_test 104b "Mount uses last flock argument"
7705
7706 error_and_umount() {
7707         umount $TMP/$tdir
7708         rmdir $TMP/$tdir
7709         error $*
7710 }
7711
7712 test_105() {
7713         cleanup -f
7714         reformat
7715         setup_noconfig
7716         mkdir -p $TMP/$tdir
7717         mount --bind $DIR $TMP/$tdir || error "mount bind mnt pt failed"
7718         rm -f $TMP/$tdir/$tfile
7719         rm -f $TMP/$tdir/${tfile}1
7720
7721         # Files should not be created in ro bind mount point
7722         # remounting from rw to ro
7723         mount -o remount,ro $TMP/$tdir ||
7724                 error_and_umount "readonly remount of bind mnt pt failed"
7725         touch $TMP/$tdir/$tfile &&
7726                 error_and_umount "touch succeeds on ro bind mnt pt"
7727         [ -e $TMP/$tdir/$tfile ] &&
7728                 error_and_umount "file created on ro bind mnt pt"
7729
7730         # Files should be created in rw bind mount point
7731         # remounting from ro to rw
7732         mount -o remount,rw $TMP/$tdir ||
7733                 error_and_umount "read-write remount of bind mnt pt failed"
7734         touch $TMP/$tdir/${tfile}1 ||
7735                 error_and_umount "touch fails on rw bind mnt pt"
7736         [ -e $TMP/$tdir/${tfile}1 ] ||
7737                 error_and_umount "file not created on rw bind mnt pt"
7738         umount $TMP/$tdir || error "umount of bind mnt pt failed"
7739         rmdir $TMP/$tdir
7740         cleanup || error "cleanup failed with $?"
7741 }
7742 run_test 105 "check file creation for ro and rw bind mnt pt"
7743
7744 test_106() {
7745         local repeat=5
7746
7747         reformat
7748         setup_noconfig
7749         mkdir -p $DIR/$tdir || error "create $tdir failed"
7750         lfs setstripe -c 1 -i 0 $DIR/$tdir
7751 #define OBD_FAIL_CAT_RECORDS                        0x1312
7752         do_facet mds1 $LCTL set_param fail_loc=0x1312 fail_val=$repeat
7753
7754         for ((i = 1; i <= $repeat; i++)); do
7755
7756                 #one full plain llog
7757                 createmany -o $DIR/$tdir/f- 64768
7758
7759                 createmany -u $DIR/$tdir/f- 64768
7760         done
7761         wait_delete_completed $((TIMEOUT * 7))
7762 #ASSERTION osp_sync_thread() ( thread->t_flags != SVC_RUNNING ) failed
7763 #shows that osp code is buggy
7764         do_facet mds1 $LCTL set_param fail_loc=0 fail_val=0
7765
7766         cleanup
7767 }
7768 run_test 106 "check osp llog processing when catalog is wrapped"
7769
7770 test_107() {
7771         [[ "$MDS1_VERSION" -ge $(version_code 2.10.50) ]] ||
7772                 skip "Need MDS version > 2.10.50"
7773         local cmd
7774
7775         start_mgsmds || error "start_mgsmds failed"
7776         start_ost || error "unable to start OST"
7777
7778         # add unknown configuration parameter.
7779         if [[ $PERM_CMD == *"set_param -P"* ]]; then
7780                 cmd="$PERM_CMD ost.$FSNAME-OST0000*.unknown_param"
7781         else
7782                 cmd="$PERM_CMD $FSNAME-OST0000*.ost.unknown_param"
7783         fi
7784         do_facet mgs "$cmd=50"
7785         cleanup_nocli || error "cleanup_nocli failed with $?"
7786         load_modules
7787
7788         # unknown param should be ignored while mounting.
7789         start_ost || error "unable to start OST after unknown param set"
7790
7791         cleanup || error "cleanup failed with $?"
7792 }
7793 run_test 107 "Unknown config param should not fail target mounting"
7794
7795 t_108_prep() {
7796         local facet
7797
7798         $rcmd rm -rf $tmp > /dev/null 2>&1
7799         $rcmd mkdir -p $tmp/{mnt,images} || error "failed to mkdir remotely"
7800
7801         for facet in $facets; do
7802                 [ "$mds1_FSTYPE" = zfs ] &&
7803                         $rcmd $ZPOOL -f export lustre-$facet > /dev/null 2>&1
7804                 $rcmd mkdir $tmp/mnt/$facet ||
7805                         error "failed to mkdir $tmp/mnt/$facet"
7806                 $rcmd dd if=/dev/zero of=$tmp/images/$facet \
7807                         seek=199 bs=1M count=1 ||
7808                         error "failed to create $tmp/images/$facet"
7809         done
7810 }
7811
7812 t_108_mkfs() {
7813         local role=$1
7814         local idx=$2
7815         local bkfs=$3
7816         local mgs=$4
7817         local facet=${role}$((idx + 1))
7818         local pool=""
7819         [ $# -eq 5 ] && pool=$5
7820
7821         do_facet $SINGLEMDS $MKFS --fsname=lustre --$mgs \
7822                 --$role --index=$idx --replace --backfstype=$bkfs \
7823                 --device-size=200000 --reformat $pool $tmp/images/$facet ||
7824                 error "failed to mkfs for $facet"
7825 }
7826
7827 t_108_check() {
7828         echo "mounting client..."
7829         mount -t lustre ${nid}:/lustre $MOUNT ||
7830                 error "failed to mount lustre"
7831
7832         echo "check list"
7833         ls -l $MOUNT/local_dir || error "failed to list"
7834
7835         echo "check truncate && write"
7836         echo "dummmmmmmmmmmmm" > $MOUNT/remote_dir/fsx.c ||
7837                 error "failed to tuncate & write"
7838
7839         echo "check create"
7840         touch $MOUNT/foooo ||
7841                 error "failed to create"
7842
7843         echo "check read && write && append"
7844         sha1sum $MOUNT/conf-sanity.sh |
7845                 awk '{ print $1 }' > $MOUNT/checksum.new ||
7846                 error "failed to read(1)"
7847         sha1sum $MOUNT/remote_dir/unlinkmany.c |
7848                 awk '{ print $1 }' >> $MOUNT/checksum.new ||
7849                 error "failed to read(2)"
7850         sha1sum $MOUNT/striped_dir/lockahead_test.o |
7851                 awk '{ print $1 }' >> $MOUNT/checksum.new ||
7852                 error "failed to read(3)"
7853
7854         echo "verify data"
7855         diff $MOUNT/checksum.new $MOUNT/checksum.src ||
7856                 error "failed to verify data"
7857
7858         echo "done."
7859 }
7860
7861 t_108_cleanup() {
7862         trap 0
7863         local facet
7864
7865         echo "cleanup..."
7866         umount -f $MOUNT || error "failed to umount client"
7867         for facet in $facets; do
7868                 $rcmd umount -f $tmp/mnt/$facet ||
7869                         error "failed to umount $facet"
7870                 if [ "$mds1_FSTYPE" = zfs ]; then
7871                         $rcmd $ZPOOL export -f lustre-$facet ||
7872                                 error "failed to export lustre-$facet"
7873                 fi
7874         done
7875
7876         $rcmd rm -rf $tmp || error "failed to rm the dir $tmp"
7877 }
7878
7879 test_108a() {
7880         [ "$CLIENTONLY" ] && skip "Client-only testing"
7881         [ "$mds1_FSTYPE" != zfs ] && skip "zfs only test"
7882         [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
7883                 skip "Need server version at least 2.10.58"
7884
7885         stopall
7886         load_modules
7887
7888         local tmp=$TMP/$tdir
7889         local rcmd="do_facet $SINGLEMDS"
7890         local facets="mdt1 mdt2 ost1 ost2"
7891         local nid=$($rcmd $LCTL list_nids | head -1)
7892         local facet
7893
7894         trap t_108_cleanup EXIT ERR
7895         t_108_prep
7896
7897         t_108_mkfs mdt 0 zfs mgs lustre-mdt1/mdt1
7898         t_108_mkfs mdt 1 zfs mgsnode=$nid lustre-mdt2/mdt2
7899         t_108_mkfs ost 0 zfs mgsnode=$nid lustre-ost1/ost1
7900         t_108_mkfs ost 1 zfs mgsnode=$nid lustre-ost2/ost2
7901
7902         for facet in $facets; do
7903                 $rcmd zfs set mountpoint=$tmp/mnt/$facet canmount=on \
7904                         lustre-$facet/$facet ||
7905                         error "failed to zfs set for $facet (1)"
7906                 $rcmd zfs mount lustre-$facet/$facet ||
7907                         error "failed to local mount $facet"
7908                 $rcmd tar jxf $LUSTRE/tests/ldiskfs_${facet}_2_11.tar.bz2 \
7909                         --xattrs --xattrs-include="trusted.*" \
7910                         -C $tmp/mnt/$facet/ > /dev/null 2>&1 ||
7911                         error "failed to untar image for $facet"
7912                 $rcmd "cd $tmp/mnt/$facet && rm -rf oi.* OI_* lfsck_* LFSCK" ||
7913                         error "failed to cleanup for $facet"
7914                 $rcmd zfs umount lustre-$facet/$facet ||
7915                         error "failed to local umount $facet"
7916                 $rcmd zfs set canmount=off lustre-$facet/$facet ||
7917                         error "failed to zfs set $facet (2)"
7918         done
7919
7920         echo "changing server nid..."
7921         $rcmd mount -t lustre -o nosvc lustre-mdt1/mdt1 $tmp/mnt/mdt1
7922         $rcmd lctl replace_nids $FSNAME-MDT0000 $nid
7923         $rcmd lctl replace_nids $FSNAME-MDT0001 $nid
7924         $rcmd lctl replace_nids $FSNAME-OST0000 $nid
7925         $rcmd lctl replace_nids $FSNAME-OST0001 $nid
7926         $rcmd umount $tmp/mnt/mdt1
7927
7928         for facet in $facets; do
7929                 echo "mounting $facet from backup..."
7930                 $rcmd mount -t lustre -o abort_recov lustre-$facet/$facet \
7931                         $tmp/mnt/$facet || error "failed to mount $facet"
7932         done
7933
7934         # ZFS backend can detect migration and trigger OI scrub automatically
7935         # sleep 3 seconds for scrub done
7936         sleep 3
7937
7938         t_108_check
7939         t_108_cleanup
7940 }
7941 run_test 108a "migrate from ldiskfs to ZFS"
7942
7943 test_108b() {
7944         [ "$CLIENTONLY" ] && skip "Client-only testing"
7945         [ "$mds1_FSTYPE" != ldiskfs ] && skip "ldiskfs only test"
7946         [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
7947                 skip "Need server version at least 2.10.58"
7948
7949         stopall
7950         load_modules
7951
7952         local tmp=$TMP/$tdir
7953         local rcmd="do_facet $SINGLEMDS"
7954         local facets="mdt1 mdt2 ost1 ost2"
7955         local scrub_list="MDT0000 MDT0001 OST0000 OST0001"
7956         local nid=$($rcmd $LCTL list_nids | head -1)
7957         local facet
7958
7959         trap t_108_cleanup EXIT ERR
7960         t_108_prep
7961
7962         t_108_mkfs mdt 0 ldiskfs mgs
7963         t_108_mkfs mdt 1 ldiskfs mgsnode=$nid
7964         t_108_mkfs ost 0 ldiskfs mgsnode=$nid
7965         t_108_mkfs ost 1 ldiskfs mgsnode=$nid
7966
7967         for facet in $facets; do
7968                 $rcmd mount -t ldiskfs -o loop $tmp/images/$facet \
7969                         $tmp/mnt/$facet ||
7970                         error "failed to local mount $facet"
7971
7972                 $rcmd tar jxf $LUSTRE/tests/zfs_${facet}_2_11.tar.bz2 \
7973                         --xattrs --xattrs-include="*.*" \
7974                         -C $tmp/mnt/$facet/ > /dev/null 2>&1 ||
7975                         error "failed to untar image for $facet"
7976                 $rcmd "cd $tmp/mnt/$facet && rm -rf oi.* OI_* lfsck_* LFSCK" ||
7977                         error "failed to cleanup for $facet"
7978                 $rcmd umount $tmp/mnt/$facet ||
7979                         error "failed to local umount $facet"
7980         done
7981
7982         echo "changing server nid..."
7983         $rcmd mount -t lustre -o nosvc,loop $tmp/images/mdt1 $tmp/mnt/mdt1
7984         $rcmd lctl replace_nids $FSNAME-MDT0000 $nid
7985         $rcmd lctl replace_nids $FSNAME-MDT0001 $nid
7986         $rcmd lctl replace_nids $FSNAME-OST0000 $nid
7987         $rcmd lctl replace_nids $FSNAME-OST0001 $nid
7988         $rcmd umount $tmp/mnt/mdt1
7989
7990         for facet in $facets; do
7991                 echo "mounting $facet from backup..."
7992                 $rcmd mount -t lustre -o loop,abort_recov $tmp/images/$facet \
7993                         $tmp/mnt/$facet || error "failed to mount $facet"
7994         done
7995
7996         for facet in $scrub_list; do
7997                 $rcmd $LCTL lfsck_start -M $FSNAME-$facet -t scrub ||
7998                         error "failed to start OI scrub on $facet"
7999         done
8000
8001         # sleep 3 seconds for scrub done
8002         sleep 3
8003
8004         t_108_check
8005         t_108_cleanup
8006 }
8007 run_test 108b "migrate from ZFS to ldiskfs"
8008
8009
8010 #
8011 # set number of permanent parameters
8012 #
8013 test_109_set_params() {
8014         local fsname=$1
8015
8016         set_persistent_param_and_check mds                          \
8017             "mdd.$fsname-MDT0000.atime_diff"                        \
8018             "$fsname-MDT0000.mdd.atime_diff"                        \
8019             "62"
8020         set_persistent_param_and_check mds                          \
8021             "mdd.$fsname-MDT0000.atime_diff"                        \
8022             "$fsname-MDT0000.mdd.atime_diff"                        \
8023             "63"
8024         set_persistent_param_and_check client                       \
8025             "llite.$fsname*.max_read_ahead_mb"                      \
8026             "$fsname.llite.max_read_ahead_mb"                       \
8027             "32"
8028         set_persistent_param_and_check client                       \
8029             "llite.$fsname*.max_read_ahead_mb"                      \
8030             "$fsname.llite.max_read_ahead_mb"                       \
8031             "64"
8032         create_pool $fsname.pool1 || error "create pool failed"
8033         do_facet mgs $LCTL pool_add $fsname.pool1 OST0000 ||
8034                 error "pool_add failed"
8035         do_facet mgs $LCTL pool_remove $fsname.pool1 OST0000 ||
8036                 error "pool_remove failed"
8037         do_facet mgs $LCTL pool_add $fsname.pool1 OST0000 ||
8038                 error "pool_add failed"
8039 }
8040
8041 #
8042 # check permanent parameters
8043 #
8044 test_109_test_params() {
8045         local fsname=$1
8046
8047         local atime_diff=$(do_facet mds $LCTL \
8048                 get_param -n mdd.$fsname-MDT0000.atime_diff)
8049         [ $atime_diff == 63 ] || error "wrong mdd parameter after clear_conf"
8050         local max_read_ahead_mb=$(do_facet client $LCTL \
8051                 get_param -n llite.$fsname*.max_read_ahead_mb)
8052         [ $max_read_ahead_mb == 64 ] ||
8053                 error "wrong llite parameter after clear_conf"
8054         local ost_in_pool=$(do_facet mds $LCTL pool_list $fsname.pool1 |
8055                 grep -v "^Pool:" | sed 's/_UUID//')
8056         [ $ost_in_pool = "$fsname-OST0000" ] ||
8057                 error "wrong pool after clear_conf"
8058 }
8059
8060 #
8061 # run lctl clear_conf, store CONFIGS before and after that
8062 #
8063 test_109_clear_conf()
8064 {
8065         local clear_conf_arg=$1
8066
8067         local mgsdev
8068         if ! combined_mgs_mds ; then
8069                 mgsdev=$(mgsdevname)
8070                 stop_mgs || error "stop_mgs failed"
8071                 start_mgs "-o nosvc" || error "start_mgs nosvc failed"
8072         else
8073                 mgsdev=$(mdsdevname 1)
8074                 start_mdt 1 "-o nosvc" || error "start_mdt 1 nosvc failed"
8075         fi
8076
8077         do_facet mgs "rm -rf $TMP/${tdir}/conf1; mkdir -p $TMP/${tdir}/conf1;" \
8078                 "$DEBUGFS -c -R \\\"rdump CONFIGS $TMP/${tdir}/conf1\\\" \
8079                 $mgsdev"
8080
8081         #
8082         # the command being tested
8083         #
8084         do_facet mgs $LCTL clear_conf $clear_conf_arg ||
8085                 error "clear_conf failed"
8086         if ! combined_mgs_mds ; then
8087                 stop_mgs || error "stop_mgs failed"
8088         else
8089                 stop_mdt 1 || error "stop_mdt 1 failed"
8090         fi
8091
8092         do_facet mgs "rm -rf $TMP/${tdir}/conf2; mkdir -p $TMP/${tdir}/conf2;" \
8093                 "$DEBUGFS -c -R \\\"rdump CONFIGS $TMP/${tdir}/conf2\\\" \
8094                 $mgsdev"
8095 }
8096
8097 test_109_file_shortened() {
8098         local file=$1
8099         local sizes=($(do_facet mgs "stat -c %s " \
8100                 "$TMP/${tdir}/conf1/CONFIGS/$file" \
8101                 "$TMP/${tdir}/conf2/CONFIGS/$file"))
8102         [ ${sizes[1]} -lt ${sizes[0]} ] && return 0
8103         return 1
8104 }
8105
8106 test_109a()
8107 {
8108         [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
8109                 skip "Needs MDS version 2.10.59 or later."
8110         [ "$(facet_fstype mgs)" == zfs ] &&
8111                 skip "LU-8727: no implementation for ZFS"
8112
8113         stopall
8114         reformat
8115         setup_noconfig
8116         client_up || error "client_up failed"
8117
8118         #
8119         # set number of permanent parameters
8120         #
8121         test_109_set_params $FSNAME
8122
8123         umount_client $MOUNT || error "umount_client failed"
8124         stop_ost || error "stop_ost failed"
8125         stop_mds || error "stop_mds failed"
8126
8127         test_109_clear_conf $FSNAME
8128         #
8129         # make sure that all configs are cleared
8130         #
8131         test_109_file_shortened $FSNAME-MDT0000 ||
8132                 error "failed to clear MDT0000 config"
8133         test_109_file_shortened $FSNAME-client ||
8134                 error "failed to clear client config"
8135
8136         setup_noconfig
8137
8138         #
8139         # check that configurations are intact
8140         #
8141         test_109_test_params $FSNAME
8142
8143         #
8144         # Destroy pool.
8145         #
8146         destroy_test_pools || error "destroy test pools failed"
8147
8148         cleanup
8149 }
8150 run_test 109a "test lctl clear_conf fsname"
8151
8152 test_109b()
8153 {
8154         [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
8155                 skip "Needs MDS version 2.10.59 or later."
8156         [ "$(facet_fstype mgs)" == zfs ] &&
8157                 skip "LU-8727: no implementation for ZFS"
8158
8159         stopall
8160         reformat
8161         setup_noconfig
8162         client_up || error "client_up failed"
8163
8164         #
8165         # set number of permanent parameters
8166         #
8167         test_109_set_params $FSNAME
8168
8169         umount_client $MOUNT || error "umount_client failed"
8170         stop_ost || error "stop_ost failed"
8171         stop_mds || error "stop_mds failed"
8172
8173         test_109_clear_conf $FSNAME-MDT0000
8174         #
8175         # make sure that only one config is cleared
8176         #
8177         test_109_file_shortened $FSNAME-MDT0000 ||
8178                 error "failed to clear MDT0000 config"
8179         test_109_file_shortened $FSNAME-client &&
8180                 error "failed to clear client config"
8181
8182         setup_noconfig
8183         #
8184         # check that configurations are intact
8185         #
8186         test_109_test_params $FSNAME
8187
8188         #
8189         # Destroy pool.
8190         #
8191         destroy_test_pools || error "destroy test pools failed"
8192
8193         cleanup
8194 }
8195 run_test 109b "test lctl clear_conf one config"
8196
8197 test_110()
8198 {
8199         [[ "$mds1_FSTYPE" != ldiskfs ]] &&
8200                 skip "Only applicable to ldiskfs-based MDTs"
8201
8202         do_facet $SINGLEMDS $DEBUGFS -w -R supported_features |grep large_dir ||
8203                 skip "large_dir option is not supported on MDS"
8204         do_facet ost1 $DEBUGFS -w -R supported_features | grep large_dir ||
8205                 skip "large_dir option is not supported on OSS"
8206
8207         stopall # stop all targets before modifying the target counts
8208         local old_mdscount=$MDSCOUNT
8209         local old_ostcount=$OSTCOUNT
8210         local replace=""
8211         stack_trap "MDSCOUNT=$old_mdscount OSTCOUNT=$old_ostcount" EXIT
8212         MDSCOUNT=1
8213         OSTCOUNT=1
8214
8215         # ext4_dir_entry_2 struct size:264
8216         # dx_root struct size:8
8217         # dx_node struct size:8
8218         # dx_entry struct size:8
8219         # For 1024 bytes block size.
8220         # First level directory entries: 126
8221         # Second level directory entries: 127
8222         # Entries in leaf: 3
8223         # For 2 levels limit: 48006
8224         # For 3 levels limit : 6096762
8225         # Create 80000 files to safely exceed 2-level htree limit.
8226         CONF_SANITY_110_LINKS=${CONF_SANITY_110_LINKS:-80000}
8227
8228         # can fit at most 3 filenames per 1KB leaf block, but each
8229         # leaf/index block will only be 3/4 full before split at each level
8230         (( MDSSIZE < CONF_SANITY_110_LINKS / 3 * 4/3 * 4/3 )) &&
8231                 CONF_SANITY_110_LINKS=$((MDSSIZE * 3 * 3/4 * 3/4))
8232
8233         combined_mgs_mds || replace=" --replace "
8234         local opts="$(mkfs_opts mds1 $(mdsdevname 1)) \
8235                     $replace --reformat $(mdsdevname 1) $(mdsvdevname 1)"
8236         if [[ $opts != *large_dir* ]]; then
8237                 if [[ $opts != *mkfsoptions* ]]; then
8238                         opts+=" --mkfsoptions=\\\"-O large_dir -b 1024 -i 65536\\\""
8239                 else
8240                         opts="${opts//--mkfsoptions=\\\"/ \
8241                                 --mkfsoptions=\\\"-O large_dir -b 1024 -i 65536 }"
8242                 fi
8243         fi
8244         echo "MDT params: $opts"
8245         load_modules
8246         combined_mgs_mds || start_mgs
8247         add mds1 $opts || error "add mds1 failed with new params"
8248         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
8249
8250         opts="$(mkfs_opts ost1 $(ostdevname 1)) \
8251                 $replace --reformat $(ostdevname 1) $(ostvdevname 1)"
8252
8253         if [[ $opts != *large_dir* ]]; then
8254                 if [[ $opts != *mkfsoptions* ]]; then
8255                         opts+=" --mkfsoptions=\\\"-O large_dir\\\" "
8256                 else
8257                         opts="${opts//--mkfsoptions=\\\"/ \
8258                                 --mkfsoptions=\\\"-O large_dir }"
8259                 fi
8260         fi
8261         echo "OST params: $opts"
8262         add ost1 $opts || error "add ost1 failed with new params"
8263         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
8264
8265         MOUNT_2=yes mountcli || error "mount clients failed"
8266
8267         mkdir -v $DIR/$tdir || error "cannot create $DIR/$tdir"
8268         local pids count=0 group=0
8269
8270         echo "creating $CONF_SANITY_110_LINKS in total"
8271         while (( count < CONF_SANITY_110_LINKS )); do
8272                 local len=$((253 - $(wc -c <<<"$tfile-$group-40000-")))
8273                 local dir=DIR$((group % 2 + 1))
8274                 local target=${!dir}/$tdir/$tfile-$group
8275                 local long=$target-$(generate_name $len)-
8276                 local create=$((CONF_SANITY_110_LINKS - count))
8277
8278                 (( create > 40000 )) && create=40000
8279                 touch $target || error "creating $target failed"
8280                 echo "creating $create hard links to $target"
8281                 createmany -l $target $long $create &
8282                 pids+=" $!"
8283
8284                 count=$((count + create))
8285                 group=$((group + 1))
8286         done
8287         echo "waiting for PIDs$pids to complete"
8288         wait $pids || error "createmany failed after $group groups"
8289
8290         umount_client $MOUNT2 -f
8291         cleanup
8292
8293         run_e2fsck $(facet_active_host mds1) $(mdsdevname 1) -n
8294         MDSCOUNT=$old_mdscount
8295         OSTCOUNT=$old_ostcount
8296 }
8297 run_test 110 "Adding large_dir with 3-level htree"
8298
8299 test_111() {
8300         [[ "$mds1_FSTYPE" != ldiskfs ]] &&
8301                 skip "Only applicable to ldiskfs-based MDTs"
8302
8303         is_dm_flakey_dev $SINGLEMDS $(mdsdevname 1) &&
8304                 skip "This test can not be executed on flakey dev"
8305
8306         do_facet $SINGLEMDS $DEBUGFS -w -R supported_features |grep large_dir ||
8307                 skip "large_dir option is not supported on MDS"
8308
8309         do_facet ost1 $DEBUGFS -w -R supported_features | grep large_dir ||
8310                 skip "large_dir option is not supported on OSS"
8311
8312         # cleanup before changing target counts
8313         cleanup
8314         local old_mdscount=$MDSCOUNT
8315         local old_ostcount=$OSTCOUNT
8316         local old_mdssize=$MDSSIZE
8317         local replace=""
8318         stack_trap "MDSSIZE=$MDSSIZE MDSCOUNT=$MDSCOUNT OSTCOUNT=$OSTCOUNT" EXIT
8319         MDSCOUNT=1
8320         OSTCOUNT=1
8321         (( MDSSIZE < 2400000 )) && MDSSIZE=2400000 # need at least 2.4GB
8322
8323         local mdsdev=$(mdsdevname 1)
8324         combined_mgs_mds || replace=" --replace "
8325         local opts="$(mkfs_opts mds1 $(mdsdevname 1)) \
8326                     $replace --reformat $(mdsdevname 1) $(mdsvdevname 1)"
8327         if [[ $opts != *large_dir* ]]; then
8328                 if [[ $opts != *mkfsoptions* ]]; then
8329                         opts+=" --mkfsoptions=\\\"-O large_dir -i 1048576 \\\" "
8330                 else
8331                         opts="${opts//--mkfsoptions=\\\"/ \
8332                                 --mkfsoptions=\\\"-O large_dir -i 1048576 }"
8333                 fi
8334         fi
8335         echo "MDT params: $opts"
8336         load_modules
8337         combined_mgs_mds || start_mgs
8338         __touch_device mds 1
8339         add mds1 $opts || error "add mds1 failed with new params"
8340         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
8341
8342         opts="$(mkfs_opts ost1 $(ostdevname 1)) \
8343                 $replace --reformat $(ostdevname 1) $(ostvdevname 1)"
8344         if [[ $opts != *large_dir* ]]; then
8345                 if [[ $opts != *mkfsoptions* ]]; then
8346                         opts+=" --mkfsoptions=\\\"-O large_dir \\\""
8347                 else
8348                         opts="${opts//--mkfsoptions=\\\"/ --mkfsoptions=\\\"-O large_dir }"
8349                 fi
8350         fi
8351         echo "OST params: $opts"
8352         __touch_device ost 1
8353         add ost1 $opts || error "add ost1 failed with new params"
8354         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
8355
8356         MOUNT_2=yes mountcli
8357         mkdir $DIR/$tdir || error "cannot create $DIR/$tdir"
8358         lfs df $DIR/$tdir
8359         lfs df -i $DIR/$tdir
8360
8361         local group=0
8362
8363         local start=$SECONDS
8364         local dirsize=0
8365         local dirmax=$((2 << 30))
8366         local needskip=0
8367         local taken=0
8368         local rate=0
8369         local left=0
8370         local num=0
8371         while (( !needskip & dirsize < dirmax )); do
8372                 local pids=""
8373
8374                 for cli in ${CLIENTS//,/ }; do
8375                         local len=$((253 - $(wc -c <<<"$cli-$group-60000-")))
8376                         local target=$cli-$group
8377                         local long=$DIR/$tdir/$target-$(generate_name $len)-
8378
8379                         RPWD=$DIR/$tdir do_node $cli touch $target ||
8380                                 error "creating $target failed"
8381                         echo "creating 60000 hardlinks to $target"
8382                         RPWD=$DIR/$tdir do_node $cli createmany -l $target $long 60000 &
8383                         pids+=" $!"
8384
8385                         group=$((group + 1))
8386                         target=$cli-$group
8387                         long=$DIR2/$tdir/$target-$(generate_name $len)-
8388
8389                         RPWD=$DIR2/$tdir do_node $cli touch $target ||
8390                                 error "creating $target failed"
8391                         echo "creating 60000 hardlinks to $target"
8392                         RPWD=$DIR2/$tdir do_node $cli createmany -l $target $long 60000 &
8393                         pids+=" $!"
8394
8395                         group=$((group + 1))
8396                 done
8397                 echo "waiting for PIDs$pids to complete"
8398                 wait $pids || error "createmany failed after $group groups"
8399                 dirsize=$(stat -c %s $DIR/$tdir)
8400                 taken=$((SECONDS - start))
8401                 rate=$((dirsize / taken))
8402                 left=$(((dirmax - dirsize) / rate))
8403                 num=$((group * 60000))
8404                 echo "estimate ${left}s left after $num files / ${taken}s"
8405                 # if the estimated time remaining is too large (it may change
8406                 # over time as the create rate is not constant) then exit
8407                 # without declaring a failure.
8408                 (( left > 1200 )) && needskip=1
8409         done
8410
8411         umount_client $MOUNT2 -f
8412         cleanup
8413
8414         (( $needskip )) && skip "ETA ${left}s after $num files / ${taken}s is too long"
8415
8416         run_e2fsck $(facet_active_host mds1) $(mdsdevname 1) -n
8417         MDSCOUNT=$old_mdscount
8418         OSTCOUNT=$old_ostcount
8419         MDSSIZE=$old_mdssize
8420 }
8421 run_test 111 "Adding large_dir with over 2GB directory"
8422
8423 test_112() {
8424         start_mds || error "MDS start failed"
8425         start_ost || error "OSS start failed"
8426         echo "start ost2 service on $(facet_active_host ost2)"
8427         start ost2 $(ostdevname 2) $(csa_add "$OST_MOUNT_OPTS" -o no_precreate) ||
8428                 error "start ost2 facet failed"
8429         local val=$(do_facet ost2 \
8430                    "$LCTL get_param -n obdfilter.$FSNAME-OST0001*.no_precreate")
8431         (( $val == 1 )) || error "obdfilter.$FSNAME-OST0001*.no_precreate=$val"
8432
8433         mount_client $MOUNT || error "mount client failed"
8434         wait_osc_import_state client ost2 FULL
8435
8436         $LFS setstripe -i 0 $DIR/$tfile.0 ||
8437                 error "problem creating $tfile.0 on OST0000"
8438         $LFS setstripe -i 1 $DIR/$tfile.1 && $LFS getstripe $DIR/$tfile.1 &&
8439                 (( $($LFS getstripe -i $DIR/$tfile.1) == 1 )) &&
8440                 error "allowed to create $tfile.1 on OST0001"
8441         do_facet ost2 $LCTL set_param obdfilter.*.no_precreate=0
8442         sleep_maxage
8443         $LFS setstripe -i 1 $DIR/$tfile.2 ||
8444                 error "failed to create $tfile.2 on ost1 facet"
8445         stop_ost2 || error "stop ost2 facet failed"
8446         cleanup
8447 }
8448 run_test 112 "mount OST with nocreate option"
8449
8450 cleanup_115()
8451 {
8452         trap 0
8453         stopall
8454         rm -f $TMP/$tdir/lustre-mdt
8455 }
8456
8457 test_115() {
8458         if [ "$mds1_FSTYPE" != ldiskfs ]; then
8459                 skip "Only applicable to ldiskfs-based MDTs"
8460         fi
8461         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
8462
8463         local dbfs_ver=$(do_facet $SINGLEMDS $DEBUGFS -V 2>&1)
8464
8465         echo "debugfs version: $dbfs_ver"
8466         echo "$dbfs_ver" | egrep -w "1.44.3.wc1|1.44.5.wc1|1.45.2.wc1" &&
8467                 skip_env "This version of debugfs doesn't show inode number"
8468
8469         is_dm_flakey_dev $SINGLEMDS $(mdsdevname 1) &&
8470                 skip "This test can not be executed on flakey dev"
8471
8472         IMAGESIZE=$((3072 << 30)) # 3072 GiB
8473
8474         stopall
8475
8476         echo "client1: "
8477         lctl dl
8478         mount | grep lustre
8479         echo "mds1: "
8480         do_facet mds1 "hostname; ifconfig; lctl dl; mount"
8481         echo "ost1: "
8482         do_facet ost1 "hostname; ifconfig; lctl dl; mount"
8483         # We need MDT size 3072GB, because it is smallest
8484         # partition that can store 2B inodes
8485         do_facet $SINGLEMDS "mkdir -p $TMP/$tdir"
8486         local mdsimgname=$TMP/$tdir/lustre-mdt
8487         do_facet $SINGLEMDS "rm -f $mdsimgname"
8488         do_facet $SINGLEMDS "touch $mdsimgname"
8489         trap cleanup_115 RETURN EXIT
8490         do_facet $SINGLEMDS "$TRUNCATE $mdsimgname $IMAGESIZE" ||
8491                 skip "Backend FS doesn't support sparse files"
8492         local mdsdev=$(do_facet $SINGLEMDS "losetup -f")
8493         do_facet $SINGLEMDS "losetup $mdsdev $mdsimgname"
8494
8495         local mds_opts="$(mkfs_opts mds1 $(mdsdevname 1))        \
8496                 --mkfsoptions='-O ea_inode,^resize_inode,meta_bg \
8497                 -N 2247484000 -E lazy_itable_init' --device-size=$IMAGESIZE"
8498         add mds1 $mds_opts --mgs --reformat $mdsdev ||
8499                 skip_env "format large MDT failed"
8500         opts="$(mkfs_opts ost1 $(ostdevname 1)) \
8501                 $replace --reformat $(ostdevname 1) $(ostvdevname 1)"
8502         add ost1 $opts || error "add ost1 failed with new params"
8503         start $SINGLEMDS  $mdsdev $MDS_MOUNT_OPTS || error "start MDS failed"
8504         start_ost || error "start OSS failed"
8505         mount_client $MOUNT || error "mount client failed"
8506
8507         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir fail"
8508         goal="/sys/fs/ldiskfs/$(basename $mdsdev)/inode_goal"
8509 echo goal: $goal
8510         # 2147483648 is 0x80000000
8511         do_facet $SINGLEMDS "echo 2147483648 >> $goal; grep . $goal"
8512         touch $DIR/$tdir/$tfile
8513
8514         # attrs from 1 to 15 go to block, 16th - to inode
8515         for i in {1..16}; do
8516                 local nm="trusted.ea$i"
8517                 setfattr -n $nm -v $(printf "xattr%0250d" $i) $DIR/$tdir/$tfile
8518         done
8519
8520         # inode <2147483649> trusted.ea16 (255)
8521         local inode_num=$(do_facet $SINGLEMDS \
8522                         "$DEBUGFS -c -R 'stat ROOT/$tdir/$tfile' $mdsdev" |
8523                          awk '/ea16/ { print $2 }' |
8524                          sed -e 's/>//' -e 's/<//' -e 's/\"//')
8525         echo "inode num: $inode_num"
8526         [ $inode_num -ge 2147483648 ] || error "inode $inode_num too small"
8527         do_facet $SINGLEMDS "losetup -d $mdsdev"
8528         cleanup_115
8529 }
8530 run_test 115 "Access large xattr with inodes number over 2TB"
8531
8532 test_116() {
8533         [ "$mds1_FSTYPE" != ldiskfs ] && skip "ldiskfs only test"
8534         [ "$MDS1_VERSION" -lt $(version_code 2.10.59) ] &&
8535                 skip "Need server version at least 2.10.59"
8536         do_facet $SINGLEMDS which mkfs.xfs ||
8537                 skip_env "No mkfs.xfs installed"
8538
8539         stopall
8540         load_modules
8541
8542         local tmpmnt=$TMP/$tdir
8543         local mdtimg=$tfile-mdt0
8544
8545         do_facet $SINGLEMDS mkdir -p $tmpmnt
8546         stack_trap "do_facet $SINGLEMDS rmdir $tmpmnt" EXIT
8547
8548         do_facet $SINGLEMDS touch $TMP/$mdtimg
8549         stack_trap "do_facet $SINGLEMDS rm -f $TMP/$mdtimg" EXIT
8550         do_facet $SINGLEMDS mkfs -t xfs -d file,size=1t,name=$TMP/$mdtimg ||
8551                 error "mkfs temporary xfs image"
8552
8553         do_facet $SINGLEMDS mount $TMP/$mdtimg $tmpmnt ||
8554                 error "mount temporary xfs image"
8555         stack_trap "do_facet $SINGLEMDS umount $tmpmnt" EXIT
8556         local old_mdssize=$MDSSIZE
8557         local old_mdsisize=$MDSISIZE
8558
8559         MDSSIZE=$((17 * 1024 * 1024 * 1024)) # 17T MDT
8560         MDSISIZE=$((16 << 20))
8561         local opts17t="$(mkfs_opts $SINGLEMDS)"
8562
8563         MDSSIZE=$old_mdssize
8564         MDSISIZE=$old_mdsisize
8565         do_facet $SINGLEMDS $MKFS $opts17t $tmpmnt/$mdtimg ||
8566                 error "failed to mkfs for $tmpmnt/$mdtimg"
8567
8568         do_facet $SINGLEMDS $TUNE2FS -l $tmpmnt/$mdtimg |
8569                 grep -qw 'features.*extent' || error "extent should be enabled"
8570         reformat_and_config
8571 }
8572 run_test 116 "big size MDT support"
8573
8574 test_117() {
8575         setup
8576         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.nrs_policies=fifo"
8577         do_facet ost1 "$LCTL get_param -n ost.OSS.ost_io.nrs_tbf_rule" &&
8578                 error "get_param should fail"
8579         cleanup || error "cleanup failed with rc $?"
8580 }
8581 run_test 117 "lctl get_param return errors properly"
8582
8583 test_120() { # LU-11130
8584         [ "$MDSCOUNT" -lt 2 ] && skip "mdt count < 2"
8585         [ "$mds1_FSTYPE" != ldiskfs ] &&
8586                 skip "ldiskfs only test"
8587         [ "$MDS1_VERSION" -lt $(version_code 2.11.56) ] &&
8588                 skip "Need DNE2 capable MD target with LU-11130 fix"
8589
8590         setup
8591
8592         local mds1host=$(facet_active_host mds1)
8593         local mds1dev=$(mdsdevname 1)
8594
8595         $LFS mkdir -i 1 $DIR/$tdir
8596         $LFS mkdir -i 0 $DIR/$tdir/mds1dir
8597
8598         ln -s foo $DIR/$tdir/bar
8599         mv $DIR/$tdir/bar $DIR/$tdir/mds1dir/bar2 ||
8600                 error "cross-target rename failed"
8601
8602         stopall
8603
8604         run_e2fsck $mds1host $mds1dev "-n"
8605 }
8606 run_test 120 "cross-target rename should not create bad symlinks"
8607
8608 test_122() {
8609         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
8610         [[ "$OST1_VERSION" -ge $(version_code 2.11.53) ]] ||
8611                 skip "Need OST version at least 2.11.53"
8612
8613         reformat
8614         LOAD_MODULES_REMOTE=true load_modules
8615 #define OBD_FAIL_OFD_SET_OID 0x1e0
8616         do_facet ost1 $LCTL set_param fail_loc=0x00001e0
8617
8618         setup_noconfig
8619         $LFS mkdir -i1 -c1 $DIR/$tdir
8620         $LFS setstripe -i0 -c1 $DIR/$tdir
8621         do_facet ost1 $LCTL set_param fail_loc=0
8622         createmany -o $DIR/$tdir/file_ 1000 ||
8623                 error "Fail to create a new sequence"
8624
8625         cleanup
8626 }
8627 run_test 122 "Check OST sequence update"
8628
8629 test_123aa() {
8630         remote_mgs_nodsh && skip "remote MGS with nodsh"
8631         [ -d $MOUNT/.lustre ] || setup
8632
8633         # test old logid format until removal from llog_ioctl.c::str2logid()
8634         if [ $MGS_VERSION -lt $(version_code 3.1.53) ]; then
8635                 do_facet mgs $LCTL dl | grep MGS
8636                 do_facet mgs "$LCTL --device %MGS llog_print \
8637                               \\\\\\\$$FSNAME-client 1 10" ||
8638                         error "old llog_print failed"
8639         fi
8640
8641         # test new logid format
8642         if [ $MGS_VERSION -ge $(version_code 2.9.53) ]; then
8643                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
8644                         error "new llog_print failed"
8645         fi
8646 }
8647 run_test 123aa "llog_print works with FIDs and simple names"
8648
8649 test_123ab() {
8650         remote_mgs_nodsh && skip "remote MGS with nodsh"
8651         [[ $MGS_VERSION -gt $(version_code 2.11.51) ]] ||
8652                 skip "Need server with working llog_print support"
8653
8654         [ -d $MOUNT/.lustre ] || setup
8655
8656         local yaml
8657         local orig_val
8658
8659         orig_val=$(do_facet mgs $LCTL get_param jobid_name)
8660         do_facet mgs $LCTL set_param -P jobid_name="TESTNAME"
8661
8662         yaml=$(do_facet mgs $LCTL --device MGS llog_print params |
8663                grep jobid_name | tail -n 1)
8664
8665         local param=$(awk '{ print $10 }' <<< "$yaml")
8666         local val=$(awk '{ print $12 }' <<< "$yaml")
8667         #return to the default
8668         do_facet mgs $LCTL set_param -P jobid_name=$orig_val
8669         [ $val = "TESTNAME" ] || error "bad value: $val"
8670         [ $param = "jobid_name," ] || error "Bad param: $param"
8671 }
8672 run_test 123ab "llog_print params output values from set_param -P"
8673
8674 test_123ac() { # LU-11566
8675         remote_mgs_nodsh && skip "remote MGS with nodsh"
8676         do_facet mgs "$LCTL help llog_print" 2>&1 | grep -q -- --start ||
8677                 skip "Need 'lctl llog_print --start' on MGS"
8678
8679         local start=10
8680         local end=50
8681
8682         [ -d $MOUNT/.lustre ] || setup
8683
8684         # - { index: 10, event: add_uuid, nid: 192.168.20.1@tcp(0x20000c0a81401,
8685         #     node: 192.168.20.1@tcp }
8686         do_facet mgs $LCTL --device MGS \
8687                 llog_print --start $start --end $end $FSNAME-client | tr -d , |
8688                 while read DASH BRACE INDEX idx EVENT BLAH BLAH BLAH; do
8689                 (( idx >= start )) || error "llog_print index $idx < $start"
8690                 (( idx <= end )) || error "llog_print index $idx > $end"
8691         done
8692 }
8693 run_test 123ac "llog_print with --start and --end"
8694
8695 test_123ad() { # LU-11566
8696         remote_mgs_nodsh && skip "remote MGS with nodsh"
8697         # older versions of lctl may not print all records properly
8698         do_facet mgs "$LCTL help llog_print" 2>&1 | grep -q -- --start ||
8699                 skip "Need 'lctl llog_print --start' on MGS"
8700
8701         [ -d $MOUNT/.lustre ] || setup
8702
8703         # append a new record, to avoid issues if last record was cancelled
8704         local old=$($LCTL get_param -n osc.*-OST0000-*.max_dirty_mb | head -1)
8705         do_facet mgs $LCTL conf_param $FSNAME-OST0000.osc.max_dirty_mb=$old
8706
8707         # logid:            [0x3:0xa:0x0]:0
8708         # flags:            4 (plain)
8709         # records_count:    72
8710         # last_index:       72
8711         local num=$(do_facet mgs $LCTL --device MGS llog_info $FSNAME-client |
8712                     awk '/last_index:/ { print $2 - 1 }')
8713
8714         # - { index: 71, event: set_timeout, num: 0x14, param: sys.timeout=20 }
8715         local last=$(do_facet mgs $LCTL --device MGS llog_print $FSNAME-client |
8716                      tail -1 | awk '{ print $4 }' | tr -d , )
8717         (( last == num )) || error "llog_print only showed $last/$num records"
8718 }
8719 run_test 123ad "llog_print shows all records"
8720
8721 test_123ae() { # LU-11566
8722         remote_mgs_nodsh && skip "remote MGS with nodsh"
8723         [ -d $MOUNT/.lustre ] || setupall
8724
8725         local max=$($LCTL get_param -n osc.*-OST0000-*.max_dirty_mb | head -1)
8726
8727         if do_facet mgs "$LCTL help llog_cancel" 2>&1| grep -q -- --log_id; then
8728                 # save one set_param -P record in case none exist
8729                 do_facet mgs $LCTL set_param -P osc.*.max_dirty_mb=$max
8730
8731                 local log=params
8732                 local orig=$(do_facet mgs $LCTL --device MGS llog_print $log |
8733                              tail -1 | awk '{ print $4 }' | tr -d , )
8734                 do_facet mgs $LCTL set_param -P osc.*.max_dirty_mb=$max
8735                 do_facet mgs $LCTL --device MGS llog_print $log | tail -1 |
8736                         grep "parameter: osc.*.max_dirty_mb" ||
8737                         error "new set_param -P wasn't stored in params log"
8738
8739                 # - { index: 71, event: set_param, device: general,
8740                 #     param: osc.*.max_dirty_mb, value: 256 }
8741                 local id=$(do_facet mgs $LCTL --device MGS llog_print $log |
8742                            tail -1 | awk '{ print $4 }' | tr -d , )
8743
8744                 do_facet mgs $LCTL --device MGS llog_cancel $log --log_idx=$id
8745                 local new=$(do_facet mgs $LCTL --device MGS llog_print $log |
8746                             tail -1 | awk '{ print $4 }' | tr -d , )
8747                 (( new == orig )) ||
8748                         error "new llog_cancel now $new, not at $orig records"
8749         fi
8750
8751         # test old positional parameters for a while still
8752         if [ "$MGS_VERSION" -le $(version_code 3.1.53) ]; then
8753                 log=$FSNAME-client
8754                 orig=$(do_facet mgs $LCTL --device MGS llog_print $log |
8755                        tail -1 | awk '{ print $4 }' | tr -d , )
8756                 do_facet mgs $LCTL conf_param $FSNAME-OST0000.osc.max_dirty_mb=$max
8757                 do_facet mgs $LCTL --device MGS llog_print $log |
8758                         tail -1 | grep "parameter: osc.max_dirty_mb" ||
8759                         error "old conf_param wasn't stored in params log"
8760
8761                 # - { index: 71, event: conf_param, device: testfs-OST0000-osc,
8762                 #     param: osc.max_dirty_mb=256 }
8763                 id=$(do_facet mgs $LCTL --device MGS llog_print $log |
8764                      tail -1 | awk '{ print $4 }' | tr -d , )
8765                 do_facet mgs $LCTL --device MGS llog_cancel $log $id
8766                 new=$(do_facet mgs $LCTL --device MGS llog_print $log |
8767                       tail -1 | awk '{ print $4 }' | tr -d , )
8768                 (( new == orig )) ||
8769                         error "old llog_cancel now $new, not at $orig records"
8770         fi
8771 }
8772 run_test 123ae "llog_cancel can cancel requested record"
8773
8774 test_123af() { #LU-13609
8775         [ "$MGS_VERSION" -ge $(version_code 2.13.54) -a \
8776            "$MDS1_VERSION" -ge $(version_code 2.13.54) ] ||
8777                 skip "Need both MGS and MDS version at least 2.13.54"
8778
8779         [ -d $MOUNT/.lustre ] || setupall
8780         stack_trap "do_facet mds1 $LCTL set_param fail_loc=0" EXIT
8781
8782         local device
8783         local facet
8784         local cmd
8785         local orig_clist
8786         local orig_count
8787         local new_clist
8788         local new_count
8789
8790         for device in "MGS" "$FSNAME-MDT0000"; do
8791                 cmd="--device $device llog_catlist"
8792                 echo "lctl $cmd ..."
8793                 if [ "$device" = "MGS" ]; then
8794                         facet="mgs"
8795                 else
8796                         facet="mds1"
8797                 fi
8798                 orig_clist=($(do_facet $facet $LCTL $cmd | awk '{ print $2 }'))
8799                 orig_count=${#orig_clist[@]}
8800                 echo "orig_clist: ${orig_clist[@]}"
8801
8802                 #define OBD_FAIL_CATLIST 0x131b
8803                 #fetch to llog records from the second one
8804                 do_facet $facet $LCTL set_param fail_loc=0x131b fail_val=2
8805
8806                 new_clist=($(do_facet $facet $LCTL $cmd | awk '{ print $2 }'))
8807                 new_count=${#new_clist[@]}
8808                 echo "new_clist: ${new_clist[@]}"
8809
8810                 [ $new_count -eq $((orig_count - 1)) ] ||
8811                         error "$new_count != $orig_count - 1"
8812                 for i in $(seq 0 $new_count); do
8813                         j=$((i + 1))
8814                         [ "${orig_clist[$j]}" = "${new_clist[$i]}" ] ||
8815                                 error "${orig_clist[$j]} != ${new_clist[$i]}"
8816                 done
8817                 do_facet mds1 $LCTL set_param fail_loc=0
8818                 echo "done"
8819         done
8820 }
8821 run_test 123af "llog_catlist can show all config files correctly"
8822
8823 test_123F() {
8824         remote_mgs_nodsh && skip "remote MGS with nodsh"
8825
8826         [ -d $MOUNT/.lustre ] || setup
8827         local yaml_file="$TMP/$tfile.yaml"
8828         do_facet mgs rm "$yaml_file"
8829         local cfgfiles=$(do_facet mgs "lctl --device MGS llog_catlist" |
8830                          sed 's/config_log://')
8831
8832         # set jobid_var to a different value for test
8833         local orig_val=$(do_facet mgs $LCTL get_param jobid_var)
8834         do_facet mgs $LCTL set_param -P jobid_var="TESTNAME"
8835
8836         for i in $cfgfiles params; do
8837                 do_facet mgs "lctl --device MGS llog_print ${i} >> $yaml_file"
8838         done
8839
8840         echo "Unmounting FS"
8841         stopall
8842         echo "Writeconf"
8843         writeconf_all
8844         echo "Remounting"
8845         mountmgs
8846         mountmds
8847         mountoss
8848         mountcli
8849
8850         # Reapply the config from before
8851         echo "Setting configuration parameters"
8852         do_facet mgs "lctl set_param -F $yaml_file"
8853
8854         local set_val=$(do_facet mgs $LCTL get_param jobid_var)
8855         do_facet mgs $LCTL set_param -P $orig_val
8856
8857         [ $set_val == "jobid_var=TESTNAME" ] ||
8858                 error "$set_val is not TESTNAME"
8859
8860         do_facet mgs rm "$yaml_file"
8861         cleanup
8862 }
8863 run_test 123F "clear and reset all parameters using set_param -F"
8864
8865 test_124()
8866 {
8867         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
8868         [ -z $mds2failover_HOST ] && skip "needs MDT failover setup"
8869
8870         setup
8871         cleanup
8872
8873         load_modules
8874         if combined_mgs_mds; then
8875                 start_mdt 1 "-o nosvc" ||
8876                         error "starting mds with nosvc option failed"
8877         fi
8878         local nid=$(do_facet mds2 $LCTL list_nids | head -1)
8879         local failover_nid=$(do_node $mds2failover_HOST $LCTL list_nids | head -1)
8880         do_facet mgs $LCTL replace_nids $FSNAME-MDT0001 $nid:$failover_nid ||
8881                 error "replace_nids execution error"
8882
8883         if combined_mgs_mds; then
8884                 stop_mdt 1
8885         fi
8886
8887         setup
8888         fail mds2
8889         echo "lfs setdirstripe"
8890         $LFS setdirstripe -i 1 $MOUNT/$tdir || error "setdirstirpe error"
8891         echo ok
8892 }
8893 run_test 124 "check failover after replace_nids"
8894
8895 get_max_sectors_kb() {
8896         local facet="$1"
8897         local device="$2"
8898         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
8899         local max_sectors_path="/sys/block/${dev_base}/queue/max_sectors_kb"
8900
8901         do_facet ${facet} "[[ -e ${max_sectors_path} ]] &&
8902                            cat ${max_sectors_path}"
8903 }
8904
8905 get_max_hw_sectors_kb() {
8906         local facet="$1"
8907         local device="$2"
8908         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
8909         local max_hw_path="/sys/block/${dev_base}/queue/max_hw_sectors_kb"
8910
8911         do_facet ${facet} "[[ -e ${max_hw_path} ]] && cat ${max_hw_path}"
8912 }
8913
8914 set_max_sectors_kb() {
8915         local facet="$1"
8916         local device="$2"
8917         local value="$3"
8918         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
8919         local max_sectors_path="/sys/block/${dev_base}/queue/max_sectors_kb"
8920
8921         do_facet ${facet} "[[ -e ${max_sectors_path} ]] &&
8922                            echo ${value} > ${max_sectors_path}"
8923         rc=$?
8924
8925         [[ $rc -ne 0 ]] && echo "Failed to set ${max_sectors_path} to ${value}"
8926
8927         return $rc
8928 }
8929
8930 # Return 0 if all slave devices have max_sectors_kb == max_hw_sectors_kb
8931 # Otherwise return > 0
8932 check_slaves_max_sectors_kb()
8933 {
8934         local facet="$1"
8935         local device="$2"
8936         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
8937         local slaves_dir=/sys/block/${dev_base}/slaves
8938         local slave_devices=$(do_facet ${facet} "ls ${slaves_dir} 2>/dev/null")
8939         [[ -z ${slave_devices} ]] && return 0
8940
8941         local slave max_sectors new_max_sectors max_hw_sectors path
8942         local rc=0
8943         for slave in ${slave_devices}; do
8944                 path="/dev/${slave}"
8945                 ! is_blkdev ${facet} ${path} && continue
8946                 max_sectors=$(get_max_sectors_kb ${facet} ${path})
8947                 max_hw_sectors=$(get_max_hw_sectors_kb ${facet} ${path})
8948                 new_max_sectors=${max_hw_sectors}
8949                 [[ ${new_max_sectors} -gt ${RQ_SIZE_LIMIT} ]] &&
8950                         new_max_sectors=${RQ_SIZE_LIMIT}
8951
8952                 if [[ ${max_sectors} -ne ${new_max_sectors} ]]; then
8953                         echo "${path} ${max_sectors} ${new_max_sectors}"
8954                         ((rc++))
8955                 fi
8956                 check_slaves_max_sectors_kb ${facet} ${path}
8957                 ((rc + $?))
8958         done
8959
8960         return $rc
8961 }
8962
8963 test_125()
8964 {
8965         local facet_list="mgs mds1 ost1"
8966         combined_mgs_mds && facet_list="mgs ost1"
8967
8968         local facet
8969         for facet in ${facet_list}; do
8970                 [[ $(facet_fstype ${facet}) != ldiskfs ]] &&
8971                         skip "ldiskfs only test" &&
8972                         return 0
8973                 ! is_blkdev ${facet} $(facet_device ${facet}) &&
8974                         skip "requires all real devices" &&
8975                         return 0
8976         done
8977
8978         local rc=0
8979         # We don't increase IO request size limit past 16MB. See comments in
8980         # lustre/utils/libmount_utils_ldiskfs.c:tune_max_sectors_kb()
8981         RQ_SIZE_LIMIT=$((16 * 1024))
8982         local device old_max_sectors new_max_sectors max_hw_sectors
8983         for facet in ${facet_list}; do
8984                 device=$(facet_device ${facet})
8985                 old_max_sectors=$(get_max_sectors_kb ${facet} ${device})
8986                 max_hw_sectors=$(get_max_hw_sectors_kb ${facet} ${device})
8987
8988                 # The expected value after l_tunedisk is executed
8989                 new_max_sectors=$old_max_sectors
8990                 [[ ${new_max_sectors_kb} -gt ${RQ_SIZE_LIMIT} ]] &&
8991                         new_max_sectors_kb=${RQ_SIZE_LIMIT}
8992
8993                 # Ensure the current value of max_sectors_kb does not equal
8994                 # max_hw_sectors_kb, so we can tell whether l_tunedisk did
8995                 # anything
8996                 set_max_sectors_kb ${facet} ${device} $((new_max_sectors - 1))
8997
8998                 # Value before l_tunedisk
8999                 local pre_max_sectors=$(get_max_sectors_kb ${facet} ${device})
9000                 if [[ ${pre_max_sectors} -ne $((new_max_sectors - 1)) ]]; then
9001                         echo "unable to satsify test pre-condition:"
9002                         echo "${pre_max_sectors} != $((new_max_sectors - 1))"
9003                         ((rc++))
9004                         continue
9005                 fi
9006
9007                 echo "Before: ${facet} ${device} ${pre_max_sectors} ${max_hw_sectors}"
9008
9009                 do_facet ${facet} "libtool execute l_tunedisk ${device}"
9010
9011                 # Value after l_tunedisk
9012                 local post_max_sectors=$(get_max_sectors_kb ${facet} ${device})
9013
9014                 echo "After: ${facet} ${device} ${post_max_sectors} ${max_hw_sectors}"
9015
9016                 if [[ ${facet} != ost1 ]]; then
9017                         if [[ ${post_max_sectors} -ne ${pre_max_sectors} ]]; then
9018                                 echo "l_tunedisk modified max_sectors_kb of ${facet}"
9019                                 ((rc++))
9020                         fi
9021
9022                         set_max_sectors_kb ${facet} ${device} ${old_max_sectors}
9023                 else
9024                         if [[ ${post_max_sectors} -eq ${pre_max_sectors} ]]; then
9025                                 echo "l_tunedisk failed to modify max_sectors_kb of ${facet}"
9026                                 ((rc++))
9027                         fi
9028
9029                         check_slaves_max_sectors_kb ${facet} ${device} ||
9030                                 ((rc++))
9031                 fi
9032         done
9033
9034         return $rc
9035 }
9036 run_test 125 "check l_tunedisk only tunes OSTs and their slave devices"
9037
9038 test_126() {
9039         [[ "$MDS1_VERSION" -ge $(version_code 2.13.52) ]] ||
9040                 skip "Need MDS version at least 2.13.52"
9041
9042         cleanup
9043         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_module ../libcfs/libcfs/libcfs
9044         #define OBD_FAIL_OBD_SETUP 0x60d
9045         do_facet mds1 $LCTL set_param fail_loc=0x60d
9046         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules &
9047         for i in {1..40}; do
9048                 do_facet mds1 lsmod | grep -q osd_$mds1_FSTYPE && break
9049                 sleep 1
9050         done
9051         clear_failloc $SINGLEMDS 20 &
9052         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
9053 }
9054 run_test 126 "mount in parallel shouldn't cause a crash"
9055
9056 if ! combined_mgs_mds ; then
9057         stop mgs
9058 fi
9059
9060 cleanup_gss
9061
9062 # restore the values of MDSSIZE and OSTSIZE
9063 MDSSIZE=$STORED_MDSSIZE
9064 OSTSIZE=$STORED_OSTSIZE
9065 reformat
9066
9067 complete $SECONDS
9068 check_and_cleanup_lustre
9069 exit_status