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