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