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