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