Whamcloud - gitweb
LU-17000 utils: handle_yaml_no_op() has wrong signature
[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 export FORCE_TEST_111=${FORCE_TEST_111:-false}
10
11 LUSTRE=${LUSTRE:-$(dirname $0)/..}
12 . $LUSTRE/tests/test-framework.sh
13 init_test_env "$@"
14 . $LUSTRE/tests/conf-sanity-framework.sh
15
16 init_logging
17
18 #                                  tool to create lustre filesystem images
19 ALWAYS_EXCEPT="$CONF_SANITY_EXCEPT 32newtarball"
20
21 if $SHARED_KEY; then
22         always_except LU-9795 84 86 103
23 fi
24
25 if ! combined_mgs_mds; then
26         always_except LU-11991 32a 32b 32c 32d 32e
27         always_except LU-9897 84
28         always_except LU-12032 123F
29 fi
30
31 #                                     8  22  40 165  (min)
32 [ "$SLOW" = "no" ] && EXCEPT_SLOW="45 69 106 111 114"
33
34 if [[ "$mds1_FSTYPE" == "zfs" ]]; then
35         always_except LU-18652 108a 112a 112b 113 117 119 121 122a
36         always_except LU-18652 123aa 123ab 123ac 123ad 123ae 123af 123ag 123ah 123ahi
37         always_except LU-18652 123F 123G 123H 126 129 132 133 135 136 137 150 152 153a 153b 153c 155 802a
38 fi
39
40 build_test_filter
41
42 # use small MDS + OST size to speed formatting time
43 # do not use too small MDSSIZE/OSTSIZE, which affect the default journal size
44 # STORED_MDSSIZE is used in test_18
45
46 fs2mds_HOST=$mds_HOST
47 fs2ost_HOST=$ost_HOST
48 fs3ost_HOST=$ost_HOST
49
50 MDSDEV1_2=$fs2mds_DEV
51 OSTDEV1_2=$fs2ost_DEV
52 OSTDEV2_2=$fs3ost_DEV
53
54 # pass "-E lazy_itable_init" to mke2fs to speed up the formatting time
55 if [[ "$LDISKFS_MKFS_OPTS" != *lazy_itable_init* ]]; then
56         LDISKFS_MKFS_OPTS=$(csa_add "$LDISKFS_MKFS_OPTS" -E lazy_itable_init)
57 fi
58
59 #
60 require_dsh_mds || exit 0
61 require_dsh_ost || exit 0
62
63 assert_DIR
64
65 if [ "$ONLY" == "setup" ]; then
66         setup
67         exit
68 fi
69
70 if [ "$ONLY" == "cleanup" ]; then
71         cleanup
72         exit
73 fi
74
75 init_gss
76
77 #create single point mountpoint
78
79 reformat_and_config
80
81 test_0() {
82         setup
83         check_mount || error "check_mount failed"
84         cleanup || error "cleanup failed with $?"
85 }
86 run_test 0 "single mount setup"
87
88 test_1() {
89         start_mds || error "MDS start failed"
90         start_ost || error "unable to start OST"
91         echo "start ost second time..."
92         start_ost && error "2nd OST start should fail"
93         mount_client $MOUNT || error "client start failed"
94         check_mount || error "check_mount failed"
95         cleanup || error "cleanup failed with $?"
96 }
97 run_test 1 "start up ost twice (should return errors)"
98
99 test_2() {
100         start_mds || error "MDT start failed"
101         echo "start mds second time.."
102         start_mds && error "2nd MDT start should fail"
103         start_ost || error "OST start failed"
104         mount_client $MOUNT || error "mount_client failed to start client"
105         check_mount || error "check_mount failed"
106         cleanup || error "cleanup failed with $?"
107 }
108 run_test 2 "start up mds twice (should return err)"
109
110 test_3() {
111         setup
112         #mount.lustre returns an error if already in mtab
113         mount_client $MOUNT && error "2nd client mount should fail"
114         check_mount || error "check_mount failed"
115         cleanup || error "cleanup failed with $?"
116 }
117 run_test 3 "mount client twice (should return err)"
118
119 test_4() {
120         setup
121         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
122         stop_ost || error "Unable to stop OST1"
123         umount_client $MOUNT -f || error "unmount $MOUNT failed"
124         cleanup_nocli
125         eno=$?
126         # ok for ost to fail shutdown
127         if [ 202 -ne $eno ] && [ 0 -ne $eno ]; then
128                 error "cleanup failed with $?"
129         fi
130 }
131 run_test 4 "force cleanup ost, then cleanup"
132
133 test_5a() {     # was test_5
134         setup
135         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
136         fuser -m -v $MOUNT && echo "$MOUNT is in use by user space process."
137
138         stop_mds || error "Unable to stop MDS"
139
140         # cleanup may return an error from the failed
141         # disconnects; for now I'll consider this successful
142         # if all the modules have unloaded.
143         $UMOUNT -f $MOUNT &
144         UMOUNT_PID=$!
145         sleep 6
146         echo "killing umount"
147         kill -TERM $UMOUNT_PID
148         echo "waiting for umount to finish"
149         wait $UMOUNT_PID
150         if grep " $MOUNT " /proc/mounts; then
151                 echo "test 5: /proc/mounts after failed umount"
152                 umount -f $MOUNT &
153                 UMOUNT_PID=$!
154                 sleep 2
155                 echo "killing umount"
156                 kill -TERM $UMOUNT_PID
157                 echo "waiting for umount to finish"
158                 wait $UMOUNT_PID
159                 grep " $MOUNT " /proc/mounts &&
160                         error "/proc/mounts after second umount"
161         fi
162
163         # manual_mount_client may fail due to umount succeeding above
164         manual_umount_client
165         # stop_mds is a no-op here, and should not fail
166         cleanup_nocli || error "cleanup_nocli failed with $?"
167         # df may have lingering entry
168         manual_umount_client
169         # mtab may have lingering entry
170         local WAIT=0
171         local MAX_WAIT=20
172         local sleep=1
173         while [ "$WAIT" -ne "$MAX_WAIT" ]; do
174                 sleep $sleep
175                 grep -q $MOUNT" " /etc/mtab || break
176                 echo "Waiting /etc/mtab updated ... "
177                 WAIT=$(( WAIT + sleep))
178         done
179         [ "$WAIT" -eq "$MAX_WAIT" ] &&
180                 error "/etc/mtab is not updated in $WAIT secs"
181         echo "/etc/mtab updated in $WAIT secs"
182 }
183 run_test 5a "force cleanup mds, then cleanup"
184
185 cleanup_5b () {
186         trap 0
187         start_mgs
188 }
189
190 test_5b() {
191         grep " $MOUNT " /etc/mtab &&
192                 error false "unexpected entry in mtab before mount" && return 10
193
194         start_ost || error "OST start failed"
195         if ! combined_mgs_mds ; then
196                 trap cleanup_5b EXIT ERR
197                 start_mds || error "MDS start failed"
198                 stop mgs
199         fi
200
201         mount_client $MOUNT && error "mount_client $MOUNT should fail"
202         grep " $MOUNT " /etc/mtab &&
203                 error "$MOUNT entry in mtab after failed mount"
204         umount_client $MOUNT
205         # stop_mds is a no-op here, and should not fail
206         cleanup_nocli || error "cleanup_nocli failed with $?"
207         if ! combined_mgs_mds ; then
208                 cleanup_5b
209         fi
210 }
211 run_test 5b "Try to start a client with no MGS (should return errs)"
212
213 test_5c() {
214         grep " $MOUNT " /etc/mtab &&
215                 error false "unexpected entry in mtab before mount" && return 10
216
217         start_mds || error "MDS start failed"
218         start_ost || error "OST start failed"
219         local oldfs="${FSNAME}"
220         FSNAME="wrong.${FSNAME}"
221         mount_client $MOUNT || :
222         FSNAME=${oldfs}
223         grep " $MOUNT " /etc/mtab &&
224                 error "$MOUNT entry in mtab after failed mount"
225         umount_client $MOUNT
226         cleanup_nocli || error "cleanup_nocli failed with $?"
227 }
228 run_test 5c "cleanup after failed mount (bug 2712) (should return errs)"
229
230 test_5d() {
231         grep " $MOUNT " /etc/mtab &&
232                 error "unexpected entry in mtab before mount"
233
234         start_ost || error "OST start failed"
235         start_mds || error "MDS start failed"
236         stop_ost -f || error "Unable to stop OST1"
237         mount_client $MOUNT || error "mount_client $MOUNT failed"
238         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
239         cleanup_nocli || error "cleanup_nocli failed with $?"
240         ! grep " $MOUNT " /etc/mtab ||
241                 error "$MOUNT entry in mtab after unmount"
242 }
243 run_test 5d "mount with ost down"
244
245 test_5e() {
246         grep " $MOUNT " /etc/mtab &&
247                 error false "unexpected entry in mtab before mount" && return 10
248
249         start_mds || error "MDS start failed"
250         start_ost || error "OST start failed"
251
252         #define OBD_FAIL_PTLRPC_DELAY_SEND       0x506
253         do_facet client "$LCTL set_param fail_loc=0x80000506"
254         mount_client $MOUNT || echo "mount failed (not fatal)"
255         cleanup || error "cleanup failed with $?"
256         grep " $MOUNT " /etc/mtab &&
257                 error "$MOUNT entry in mtab after unmount"
258         pass
259 }
260 run_test 5e "delayed connect, don't crash (bug 10268)"
261
262 test_5f() {
263         combined_mgs_mds && skip "needs separate mgs and mds"
264
265         grep " $MOUNT " /etc/mtab &&
266                 error false "unexpected entry in mtab before mount" && return 10
267
268         local rc=0
269         start_ost || error "OST start failed"
270         mount_client $MOUNT &
271         local pid=$!
272         echo client_mount pid is $pid
273
274         sleep 5
275
276         if ! ps -f -p $pid >/dev/null; then
277                 wait $pid
278                 rc=$?
279                 grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
280                 error "mount returns $rc, expected to hang"
281                 rc=11
282                 cleanup || error "cleanup failed with $?"
283                 return $rc
284         fi
285
286         # start mds
287         start_mds || error "start MDS failed"
288
289         # mount should succeed after start mds
290         wait $pid
291         grep " $MOUNT " /etc/mtab && echo "test 5f: mtab after mount"
292         cleanup || error "final call to cleanup failed with rc $?"
293 }
294 run_test 5f "mds down, cleanup after failed mount (bug 2712)"
295
296 test_5g() {
297         modprobe lustre
298         [ "$CLIENT_VERSION" -lt $(version_code 2.9.53) ] &&
299                 skip "automount of debugfs missing before 2.9.53"
300         umount /sys/kernel/debug
301         $LCTL get_param -n devices | egrep -v "error" && \
302                 error "lctl can't access debugfs data"
303         grep " debugfs " /etc/mtab || error "debugfs failed to remount"
304 }
305 run_test 5g "handle missing debugfs"
306
307 test_5h() {
308         (( $MDS1_VERSION >= $(version_code 2.12.54) )) ||
309                 skip "Need MDS version at least 2.12.54"
310
311         setup
312
313         stop mds1
314         #define OBD_FAIL_MDS_FS_SETUP            0x135
315         do_facet mds1 "$LCTL set_param fail_loc=0x80000135"
316         start_mdt 1 && error "start mdt should fail"
317         start_mdt 1 || error "start mdt failed"
318         client_up || error "client_up failed"
319         cleanup
320 }
321 run_test 5h "start mdt failure at mdt_fs_setup()"
322
323 test_5i() {
324         (( $MDS1_VERSION >= $(version_code 2.12.54) )) ||
325                 skip "Need MDS version at least 2.12.54"
326
327         setup
328
329         stop mds1
330         #define OBD_FAIL_QUOTA_INIT              0xA05
331         do_facet mds1 "$LCTL set_param fail_loc=0x80000A05"
332         start_mdt 1 && error "start mdt should fail"
333         start_mdt 1 || error "start mdt failed"
334         client_up || error "client_up failed"
335         cleanup
336 }
337 run_test 5i "start mdt failure at mdt_quota_init()"
338
339 test_5j() {
340         unload_modules
341         load_module ../libcfs/libcfs/libcfs ||
342                 error "Failed to load modules libcfs rc = $?"
343         $LCTL set_param debug=all
344         rmmod -v libcfs
345 }
346 run_test 5j "verify libcfs doesn't crash when setting debug flags"
347
348 test_6() {
349         setup
350         manual_umount_client
351         mount_client $MOUNT || error "mount_client $MOUNT failed"
352         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
353         cleanup || error "cleanup failed with rc $?"
354 }
355 run_test 6 "manual umount, then mount again"
356
357 test_7() {
358         setup
359         manual_umount_client
360         cleanup_nocli || error "cleanup_nocli failed with $?"
361 }
362 run_test 7 "manual umount, then cleanup"
363
364 test_8() {
365         setup
366         mount_client $MOUNT2 || error "mount_client $MOUNT2 failed"
367         check_mount2 || error "check_mount2 failed"
368         umount_client $MOUNT2 || error "umount_client $MOUNT2 failed"
369         cleanup || error "cleanup failed with rc $?"
370 }
371 run_test 8 "double mount setup"
372
373 test_9() {
374         start_ost || error "OST start failed"
375
376         do_facet ost1 $LCTL set_param debug=\'inode trace\' ||
377                 error "do_facet ost1 set_param inode trace failed."
378         do_facet ost1 $LCTL set_param subsystem_debug=\'mds ost\' ||
379                 error "do_facet ost1 set_param debug mds ost failed."
380
381         CHECK_PTLDEBUG="`do_facet ost1 $LCTL get_param -n debug`"
382         if [ "$CHECK_PTLDEBUG" ] && { \
383            [ "$CHECK_PTLDEBUG" = "trace inode warning error emerg console" ] ||
384            [ "$CHECK_PTLDEBUG" = "trace inode" ]; }; then
385                 echo "lnet.debug success"
386         else
387                 error "lnet.debug: want 'trace inode', have '$CHECK_PTLDEBUG'"
388         fi
389         CHECK_SUBSYS="`do_facet ost1 $LCTL get_param -n subsystem_debug`"
390         if [ "$CHECK_SUBSYS" ] && [ "$CHECK_SUBSYS" = "mds ost" ]; then
391                 echo "lnet.subsystem_debug success"
392         else
393                 error "lnet.subsystem_debug: want 'mds ost' got '$CHECK_SUBSYS'"
394         fi
395         stop_ost || error "Unable to stop OST1"
396 }
397 run_test 9 "test ptldebug and subsystem for mkfs"
398
399 test_10a() {
400         setup
401
402         if ! combined_mgs_mds; then
403                 files=$(do_facet mgs "find /{proc/fs,sys/fs,sys/kernel/debug}/lustre -type l -exec test ! -e {} \; -print")
404                 [ -z $files ] || echo "MGS $files is a broken symlink"
405         fi
406
407         files=$(do_facet mds1 "find /{proc/fs,sys/fs,sys/kernel/debug}/lustre -type l -exec test ! -e {} \; -print")
408         [ -z $files ] || echo "MDS $files is a broken symlink"
409
410         files=$(do_facet ost1 "find /{proc/fs,sys/fs,sys/kernel/debug}/lustre -type l -exec test ! -e {} \; -print")
411         [ -z $files ] || echo "OSS $files is a broken symlink"
412
413         files=$(do_facet client "find /{proc/fs,sys/fs,sys/kernel/debug}/lustre -type l -exec test ! -e {} \; -print")
414         [ -z $files ] || echo "clients $files is a broken symlink"
415
416         cleanup || error "cleanup failed with rc $?"
417 }
418 run_test 10a "find lctl param broken symlinks"
419
420 #
421 # Test 16 was to "verify that lustre will correct the mode of OBJECTS".
422 # But with new MDS stack we don't care about the mode of local objects
423 # anymore, so this test is removed. See bug 22944 for more details.
424 #
425
426 test_17() {
427         if [ "$mds1_FSTYPE" != ldiskfs ]; then
428                 skip "ldiskfs only test"
429         fi
430
431         setup
432         check_mount || error "check_mount failed"
433         cleanup || error "cleanup failed with rc $?"
434
435         echo "Remove mds config log"
436         if ! combined_mgs_mds ; then
437                 stop mgs
438         fi
439
440         do_facet mgs "$DEBUGFS -w -R 'unlink CONFIGS/$FSNAME-MDT0000' \
441                       $(mgsdevname) || return \$?" ||
442                 error "do_facet mgs failed with $?"
443
444         if ! combined_mgs_mds ; then
445                 start_mgs
446         fi
447
448         start_ost || error "OST start failed"
449         start_mds && error "MDS start succeeded, but should fail"
450         reformat_and_config
451 }
452 run_test 17 "Verify failed mds_postsetup won't fail assertion (2936) (should return errs)"
453
454 test_18() {
455         if [ "$mds1_FSTYPE" != ldiskfs ]; then
456                 skip "ldiskfs only test"
457         fi
458
459         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
460
461         local MIN=2000000
462
463         local OK=
464         # check if current MDSSIZE is large enough
465         [ $MDSSIZE -ge $MIN ] && OK=1 && myMDSSIZE=$MDSSIZE &&
466                 log "use MDSSIZE=$MDSSIZE"
467
468         # check if the global config has a large enough MDSSIZE
469         [ -z "$OK" -a ! -z "$STORED_MDSSIZE" ] &&
470                 [ $STORED_MDSSIZE -ge $MIN ] &&
471                 OK=1 && myMDSSIZE=$STORED_MDSSIZE &&
472                 log "use STORED_MDSSIZE=$STORED_MDSSIZE"
473
474         # check if the block device is large enough
475         is_blkdev $SINGLEMDS $MDSDEV $MIN
476         local large_enough=$?
477         if [ -n "$OK" ]; then
478                 [ $large_enough -ne 0 ] && OK=""
479         else
480                 [ $large_enough -eq 0 ] && OK=1 && myMDSSIZE=$MIN &&
481                         log "use device $MDSDEV with MIN=$MIN"
482         fi
483
484         # check if a loopback device has enough space for fs metadata (5%)
485
486         if [ -z "$OK" ]; then
487                 local SPACE=$(do_facet $SINGLEMDS "[ -f $MDSDEV -o ! \
488                               -e $MDSDEV ] && df -P \\\$(dirname $MDSDEV)" |
489                         awk '($1 != "Filesystem") { print $4 }')
490                 ! [ -z "$SPACE" ] && [ $SPACE -gt $((MIN / 20)) ] &&
491                         OK=1 && myMDSSIZE=$MIN &&
492                         log "use file $MDSDEV with MIN=$MIN"
493         fi
494
495         [ -z "$OK" ] && skip_env "$MDSDEV too small for ${MIN}kB MDS"
496
497         echo "mount mds with large journal..."
498
499         local OLD_MDSSIZE=$MDSSIZE
500         MDSSIZE=$myMDSSIZE
501
502         reformat_and_config
503         echo "mount lustre system..."
504         setup
505         check_mount || error "check_mount failed"
506
507         echo "check journal size..."
508         local FOUNDSIZE=$(do_facet $SINGLEMDS "$DEBUGFS -c -R 'stat <8>' $MDSDEV" | awk '/Size: / { print $NF; exit;}')
509         if [ $FOUNDSIZE -gt $((32 * 1024 * 1024)) ]; then
510                 log "Success: mkfs creates large journals. Size: $((FOUNDSIZE >> 20))M"
511         else
512                 error "expected journal size > 32M, found $((FOUNDSIZE >> 20))M"
513         fi
514
515         cleanup || error "cleanup failed with rc $?"
516
517         MDSSIZE=$OLD_MDSSIZE
518         reformat_and_config
519 }
520 run_test 18 "check mkfs creates large journals"
521
522 test_19a() {
523         start_mds || error "MDS start failed"
524         stop_mds || error "Unable to stop MDS"
525 }
526 run_test 19a "start/stop MDS without OSTs"
527
528 test_19b() {
529         start_ost || error "Unable to start OST1"
530         stop_ost -f || error "Unable to stop OST1"
531 }
532 run_test 19b "start/stop OSTs without MDS"
533
534 test_20() {
535         # first format the ost/mdt
536         start_mds || error "MDS start failed"
537         start_ost || error "Unable to start OST1"
538         mount_client $MOUNT || error "mount_client $MOUNT failed"
539         check_mount || error "check_mount failed"
540         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed."
541         mount_client $MOUNT remount,ro || error "remount client with ro failed"
542         touch $DIR/$tfile && error "$DIR/$tfile created incorrectly"
543         [ -e $DIR/$tfile ] && error "$DIR/$tfile exists incorrectly"
544         mount_client $MOUNT remount,rw || error "remount client with rw failed"
545         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
546         MCNT=$(grep -c $MOUNT' ' /etc/mtab)
547         [ "$MCNT" -ne 1 ] && error "$MOUNT in /etc/mtab $MCNT times"
548         umount_client $MOUNT
549         stop_mds || error "Unable to stop MDS"
550         stop_ost || error "Unable to stop OST1"
551 }
552 run_test 20 "remount ro,rw mounts work and doesn't break /etc/mtab"
553
554 test_21a() {
555         start_mds || error "MDS start failed"
556         start_ost || error "unable to start OST1"
557         wait_osc_import_state mds ost FULL
558         stop_ost || error "unable to stop OST1"
559         stop_mds || error "unable to stop MDS"
560 }
561 run_test 21a "start mds before ost, stop ost first"
562
563 test_21b() {
564         start_ost || error "unable to start OST1"
565         start_mds || error "MDS start failed"
566         wait_osc_import_state mds ost FULL
567         stop_mds || error "unable to stop MDS"
568         stop_ost || error "unable to stop OST1"
569 }
570 run_test 21b "start ost before mds, stop mds first"
571
572 test_21c() {
573         start_ost || error "Unable to start OST1"
574         start_mds || error "MDS start failed"
575         start_ost2 || error "Unable to start OST2"
576         wait_osc_import_state mds ost2 FULL
577         stop_ost || error "Unable to stop OST1"
578         stop_ost2 || error "Unable to stop OST2"
579         stop_mds || error "Unable to stop MDS"
580         #writeconf to remove all ost2 traces for subsequent tests
581         writeconf_or_reformat
582 }
583 run_test 21c "start mds between two osts, stop mds last"
584
585 test_21d() {
586         combined_mgs_mds && skip "need separate mgs device"
587
588         stopall
589         reformat
590
591         start_mgs || error "unable to start MGS"
592         start_ost || error "unable to start OST1"
593         start_ost2 || error "unable to start OST2"
594         start_mds || error "MDS start failed"
595         wait_osc_import_state mds ost2 FULL
596
597         local zkeeper=${KEEP_ZPOOL}
598         stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
599         KEEP_ZPOOL="true"
600
601         stop_ost || error "Unable to stop OST1"
602         stop_ost2 || error "Unable to stop OST2"
603         stop_mds || error "Unable to stop MDS"
604         stop_mgs
605         #writeconf to remove all ost2 traces for subsequent tests
606         writeconf_or_reformat
607         KEEP_ZPOOL="${zkeeper}"
608
609         start_mgs || error "unable to start MGS"
610 }
611 run_test 21d "start mgs then ost and then mds"
612
613 cleanup_21e() {
614         MGSNID="$saved_mgsnid"
615         cleanup_fs2
616         echo "stopping fs2mgs ..."
617         stop $fs2mgs -f || true
618 }
619
620 test_21e() { # LU-5863
621         if [[ -z "$fs3ost_DEV" || -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
622                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
623                 skip_env "mixed loopback and real device not working"
624         fi
625
626         local fs2mdsdev=$(mdsdevname 1_2)
627         local fs2ostdev=$(ostdevname 1_2)
628         local fs3ostdev=$(ostdevname 2_2)
629
630         local fs2mdsvdev=$(mdsvdevname 1_2)
631         local fs2ostvdev=$(ostvdevname 1_2)
632         local fs3ostvdev=$(ostvdevname 2_2)
633
634         # temporarily use fs3ost as fs2mgs
635         local fs2mgs=fs3ost
636         local fs2mgsdev=$fs3ostdev
637         local fs2mgsvdev=$fs3ostvdev
638
639         local fsname=test1234
640
641         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
642                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
643         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS && trap cleanup_21e EXIT INT ||
644                 error "start fs2mgs failed"
645
646         local saved_mgsnid="$MGSNID"
647         MGSNID=$(do_facet $fs2mgs $LCTL list_nids | xargs | tr ' ' ,)
648
649         add fs2mds $(mkfs_opts mds1 $fs2mdsdev $fsname) \
650                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
651         add fs2ost $(mkfs_opts ost1 $fs2ostdev $fsname) \
652                 --reformat $fs2ostdev $fs2ostvdev || error "add fs2ost failed"
653
654         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
655         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS || error "start fs2mds failed"
656
657         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
658         $MOUNT_CMD $MGSNID:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
659         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
660
661         cleanup_21e
662 }
663 run_test 21e "separate MGS and MDS"
664
665 test_22() {
666         start_mds || error "MDS start failed"
667
668         echo "Client mount with ost in logs, but none running"
669         start_ost || error "unable to start OST1"
670         # wait until mds connected to ost and open client connection
671         wait_osc_import_state mds ost FULL
672         stop_ost || error "unable to stop OST1"
673         mount_client $MOUNT || error "mount_client $MOUNT failed"
674         # check_mount will block trying to contact ost
675         mcreate $DIR/$tfile || error "mcreate $DIR/$tfile failed"
676         rm -f $DIR/$tfile || error "remove $DIR/$tfile failed"
677         umount_client $MOUNT -f
678         pass
679
680         echo "Client mount with a running ost"
681         start_ost || error "unable to start OST1"
682         if $GSS; then
683                 # if gss enabled, wait full time to let connection from
684                 # mds to ost be established, due to the mismatch between
685                 # initial connect timeout and gss context negotiation timeout.
686                 # This perhaps could be remove after AT landed.
687                 echo "sleep $((TIMEOUT + TIMEOUT + TIMEOUT))s"
688                 sleep $((TIMEOUT + TIMEOUT + TIMEOUT))
689         fi
690         mount_client $MOUNT || error "mount_client $MOUNT failed"
691         wait_osc_import_state mds ost FULL
692         wait_osc_import_ready client ost
693         check_mount || error "check_mount failed"
694         pass
695
696         cleanup || error "cleanup failed with rc $?"
697 }
698 run_test 22 "start a client before osts (should return errs)"
699
700 test_23a() {    # was test_23
701         setup
702         # fail mds
703         stop $SINGLEMDS || error "failed to stop $SINGLEMDS"
704         # force down client so that recovering mds waits for reconnect
705         local running=$(grep -c $MOUNT /proc/mounts) || true
706         if [ $running -ne 0 ]; then
707                 echo "Stopping client $MOUNT (opts: -f)"
708                 umount -f $MOUNT
709         fi
710
711         # enter recovery on failed mds
712         local MDT_DEV=$(mdsdevname ${SINGLEMDS//mds/})
713         start $SINGLEMDS $MDT_DEV $MDS_MOUNT_OPTS || error "MDS start failed"
714         # try to start a new client
715         mount_client $MOUNT &
716         sleep 5
717         MOUNT_PID=$(ps -ef | grep "t lustre" | grep -v grep | awk '{print $2}')
718         MOUNT_LUSTRE_PID=$(ps -ef | grep mount.lustre |
719                            grep -v grep | awk '{print $2}')
720         echo mount pid is ${MOUNT_PID}, mount.lustre pid is ${MOUNT_LUSTRE_PID}
721         ps --ppid $MOUNT_PID
722         ps --ppid $MOUNT_LUSTRE_PID
723         echo "waiting for mount to finish"
724         ps -ef | grep mount
725         # "ctrl-c" sends SIGINT but it usually (in script) does not work on child process
726         # SIGTERM works but it does not spread to offspring processses
727         kill -s TERM $MOUNT_PID
728         kill -s TERM $MOUNT_LUSTRE_PID
729         # we can not wait $MOUNT_PID because it is not a child of this shell
730         local PID1
731         local PID2
732         local WAIT=0
733         local MAX_WAIT=30
734         local sleep=1
735         while [ "$WAIT" -lt "$MAX_WAIT" ]; do
736                 sleep $sleep
737                 PID1=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_PID)
738                 PID2=$(ps -ef | awk '{print $2}' | grep -w $MOUNT_LUSTRE_PID)
739                 echo PID1=$PID1
740                 echo PID2=$PID2
741                 [ -z "$PID1" -a -z "$PID2" ] && break
742                 echo "waiting for mount to finish ... "
743                 WAIT=$(( WAIT + sleep))
744         done
745         if [ "$WAIT" -eq "$MAX_WAIT" ]; then
746                 error "MOUNT_PID $MOUNT_PID and "\
747                 "MOUNT_LUSTRE_PID $MOUNT_LUSTRE_PID still not killed in $WAIT secs"
748                 ps -ef | grep mount
749         fi
750         cleanup || error "cleanup failed with rc $?"
751 }
752 run_test 23a "interrupt client during recovery mount delay"
753
754 test_23b() {    # was test_23
755         start_mds || error "MDS start failed"
756         start_ost || error "Unable to start OST1"
757         # Simulate -EINTR during mount OBD_FAIL_LDLM_CLOSE_THREAD
758         $LCTL set_param fail_loc=0x80000313
759         mount_client $MOUNT
760         cleanup || error "cleanup failed with rc $?"
761 }
762 run_test 23b "Simulate -EINTR during mount"
763
764 test_24a() {
765         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
766
767         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
768                 is_blkdev $SINGLEMDS $MDSDEV &&
769                 skip_env "mixed loopback and real device not working"
770         fi
771
772         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
773
774         local fs2mdsdev=$(mdsdevname 1_2)
775         local fs2ostdev=$(ostdevname 1_2)
776         local fs2mdsvdev=$(mdsvdevname 1_2)
777         local fs2ostvdev=$(ostvdevname 1_2)
778         local cl_user
779
780         # LU-9733 test fsname started with numbers as well
781         local FSNAME2=969362ae
782
783         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --nomgs --mgsnode=$MGSNID \
784                 --fsname=${FSNAME2} --reformat $fs2mdsdev $fs2mdsvdev || exit 10
785
786         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --fsname=${FSNAME2} \
787                 --reformat $fs2ostdev $fs2ostvdev || exit 10
788
789         setup
790         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
791         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
792         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
793         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
794
795         # LU-9733 test fsname started with numbers
796         cl_user=$(do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
797                         changelog_register -n) ||
798                                 error "register changelog failed"
799
800         do_facet $SINGLEMDS lctl --device $FSNAME2-MDT0000 \
801                         changelog_deregister $cl_user ||
802                                 error "deregister changelog failed"
803         # 1 still works
804         check_mount || error "check_mount failed"
805         # files written on 1 should not show up on 2
806         cp /etc/passwd $DIR/$tfile
807         sleep 10
808         [ -e $MOUNT2/$tfile ] && error "File bleed"
809         # 2 should work
810         sleep 5
811         cp /etc/passwd $MOUNT2/$tfile ||
812                 error "cp /etc/passwd $MOUNT2/$tfile failed"
813         rm $MOUNT2/$tfile || error "remove $MOUNT2/$tfile failed"
814         # 2 is actually mounted
815         grep $MOUNT2' ' /proc/mounts > /dev/null || error "$MOUNT2 not mounted"
816         # failover
817         facet_failover fs2mds
818         facet_failover fs2ost
819         df
820         umount_client $MOUNT
821         # the MDS must remain up until last MDT
822         stop_mds
823         MDS=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
824               awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
825         [ -z "$MDS" ] && error "No MDT"
826         cleanup_fs2
827         cleanup_nocli || error "cleanup_nocli failed with rc $?"
828 }
829 run_test 24a "Multiple MDTs on a single node"
830
831 test_24b() {
832         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
833         combined_mgs_mds ||
834                 skip "needs combined MGT and MDT device"
835
836         if [ -z "$fs2mds_DEV" ]; then
837                 local dev=${SINGLEMDS}_dev
838                 local MDSDEV=${!dev}
839                 is_blkdev $SINGLEMDS $MDSDEV &&
840                 skip_env "mixed loopback and real device not working"
841         fi
842
843         local fs2mdsdev=$(mdsdevname 1_2)
844         local fs2mdsvdev=$(mdsvdevname 1_2)
845
846         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev} ) --mgs --fsname=${FSNAME}2 \
847                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
848         setup
849         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && {
850                 cleanup
851                 error "start MDS should fail"
852         }
853         stop fs2mds -f
854         cleanup || error "cleanup failed with rc $?"
855 }
856 run_test 24b "Multiple MGSs on a single node (should return err)"
857
858 test_25() {
859         setup_noconfig
860         check_mount || error "check_mount failed"
861         local MODULES=$($LCTL modules | awk '{ print $2 }')
862         rmmod $MODULES 2>/dev/null || true
863         cleanup || error "cleanup failed with $?"
864 }
865 run_test 25 "Verify modules are referenced"
866
867 test_26() {
868         load_modules
869         # we need modules before mount for sysctl, so make sure...
870         do_facet $SINGLEMDS "lsmod | grep -q lustre || modprobe lustre"
871         #define OBD_FAIL_MDS_FS_SETUP            0x135
872         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000135"
873         start_mds && error "MDS started but should not have started"
874         $LCTL get_param -n devices
875         DEVS=$($LCTL get_param -n devices | egrep -v MG | wc -l)
876         [ $DEVS -gt 0 ] && error "number of devices is $DEVS, should be zero"
877         # start mds to drop writeconf setting
878         start_mds || error "Unable to start MDS"
879         stop_mds || error "Unable to stop MDS"
880         unload_modules_conf || error "unload_modules_conf failed with $?"
881 }
882 run_test 26 "MDT startup failure cleans LOV (should return errs)"
883
884 test_27a() {
885         cleanup
886         start_ost || error "Unable to start OST1"
887         start_mds || error "Unable to start MDS"
888         echo "Requeue thread should have started: "
889         ps -e | grep ll_cfg_requeue
890         set_persistent_param_and_check ost1                     \
891            "obdfilter.$FSNAME-OST0000.client_cache_seconds"     \
892            "$FSNAME-OST0000.ost.client_cache_seconds"
893         cleanup_nocli || error "cleanup_nocli failed with rc $?"
894 }
895 run_test 27a "Reacquire MGS lock if OST started first"
896
897 test_27b() {
898         # FIXME. ~grev
899         setup_noconfig
900         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
901                         awk '($3 ~ "mdt" && $4 ~ "MDT0000") { print $4 }')
902
903         facet_failover $SINGLEMDS
904         set_persistent_param_and_check $SINGLEMDS       \
905                 "mdt.$device.identity_acquire_expire"   \
906                 "$device.mdt.identity_acquire_expire"
907         set_persistent_param_and_check client           \
908                 "mdc.$device-mdc-*.max_rpcs_in_flight"  \
909                 "$device.mdc.max_rpcs_in_flight"
910         check_mount
911         cleanup || error "cleanup failed with $?"
912 }
913 run_test 27b "Reacquire MGS lock after failover"
914
915 test_28A() { # was test_28
916         setup_noconfig
917
918         local TEST="llite.$FSNAME-*.max_read_ahead_whole_mb"
919         local PARAM="$FSNAME.llite.max_read_ahead_whole_mb"
920         local orig=$($LCTL get_param -n $TEST)
921         local max=$($LCTL get_param -n \
922                         llite.$FSNAME-*.max_read_ahead_per_file_mb)
923
924         orig=${orig%%.[0-9]*}
925         max=${max%%.[0-9]*}
926         echo "ORIG:$orig MAX:$max"
927         [[ $max -le $orig ]] && orig=$((max - 3))
928         echo "ORIG:$orig MAX:$max"
929
930         local final=$((orig + 1))
931
932         set_persistent_param_and_check client "$TEST" "$PARAM" $final
933         final=$((final + 1))
934         set_persistent_param_and_check client "$TEST" "$PARAM" $final
935         umount_client $MOUNT || error "umount_client $MOUNT failed"
936         mount_client $MOUNT || error "mount_client $MOUNT failed"
937
938         local result=$($LCTL get_param -n $TEST)
939
940         if [ $result -ne $final ]; then
941                 error "New config not seen: wanted $final got $result"
942         else
943                 echo "New config success: got $result"
944         fi
945         set_persistent_param_and_check client "$TEST" "$PARAM" $orig
946         cleanup || error "cleanup failed with rc $?"
947 }
948 run_test 28A "permanent parameter setting"
949
950 test_28a() { # LU-4221
951         [[ "$OST1_VERSION" -ge $(version_code 2.5.52) ]] ||
952                 skip "Need OST version at least 2.5.52"
953         [ "$ost1_FSTYPE" = zfs ] &&
954                 skip "LU-4221: no such proc params for ZFS OSTs"
955
956         local name
957         local param
958         local cmd
959         local old
960         local new
961         local device="$FSNAME-OST0000"
962
963         setup_noconfig
964
965         # In this test we will set three kinds of proc parameters with
966         # lctl set_param -P or lctl conf_param:
967         # 1. non-symlink ones in the OFD
968         # 2. non-symlink ones in the OSD
969
970         # Check 1.
971         # prepare a non-symlink parameter in the OFD
972         name="client_cache_seconds"
973         param="$device.ost.$name"
974         cmd="obdfilter.$device.$name"
975
976         # permanently setting the parameter in the OFD
977         old=$(do_facet ost1 $LCTL get_param -n $cmd)
978         new=$((old * 2))
979         set_persistent_param_and_check ost1 "$cmd" "$param" $new
980         set_persistent_param_and_check ost1 "$cmd" "$param" $old
981
982         # Check 2.
983         # prepare a non-symlink parameter in the OSD
984         name="auto_scrub"
985         param="$device.osd.$name"
986         cmd="osd-*.$device.$name"
987
988         # conf_param the parameter in the OSD
989         old=$(do_facet ost1 $LCTL get_param -n $cmd)
990         new=$(((old + 1) % 2))
991         set_persistent_param_and_check ost1 "$cmd" "$param" $new
992         set_persistent_param_and_check ost1 "$cmd" "$param" $old
993
994         cleanup || error "cleanup failed with $?"
995 }
996 run_test 28a "set symlink parameters permanently with lctl"
997
998 test_28b() {
999         setup_noconfig
1000         stack_trap "cleanup"
1001
1002         # jobid_this_session is not available so use jobid_name when possible
1003         if $LCTL list_param jobid_name &> /dev/null; then
1004                 local jobvarname=jobid_name test_val="$TESTNAME-$RANDOM%p"
1005         else
1006                 local jobvarname=jobid_var test_val=$TESTNAME-$RANDOM
1007         fi
1008
1009         local jobid_var_new
1010         local jobid_var_old=$($LCTL get_param -n $jobvarname)
1011         local paramdir=/etc/lustre
1012         local paramfile=$paramdir/mount.client.params
1013
1014         [[ -d $paramdir ]] || mkdir $paramdir
1015
1016         stack_trap "$LCTL set_param $jobvarname=$jobid_var_old"
1017
1018         if [[ -e $paramfile ]]; then
1019                 mv $paramfile $paramfile.$TESTNAME
1020                 stack_trap "mv $paramfile.$TESTNAME $paramfile"
1021         else
1022                 # leave no traces behind
1023                 stack_trap "rm $paramfile"
1024         fi
1025
1026         # if the test param is set in the filesystem params file
1027         # it will override the more general client params
1028         if [[ -e $paramdir/mount.$FSNAME.params ]]; then
1029                 echo "disabling $FSNAME specific params file"
1030                 local clientfile=$paramdir/mount.$FSNAME.params
1031
1032                 mv $clientfile $clientfile.disabled
1033                 stack_trap "mv $clientfile.disabled $clientfile"
1034         fi
1035         echo "$jobvarname=$test_val" > $paramfile
1036
1037         remount_client $MOUNT
1038
1039         jobid_var_new=$($LCTL get_param -n $jobvarname)
1040
1041         echo "before mount: $jobid_var_old"
1042         echo "after mount:  $jobid_var_new"
1043         [[ "$jobid_var_new" == "$test_val" ]] ||
1044                 error "$jobvarname was not $test_val: got $jobid_var_new"
1045 }
1046 run_test 28b "verify client-side parameters are set upon mount"
1047
1048 test_28c() {
1049         setup_noconfig
1050         stack_trap "cleanup"
1051
1052         # jobid_this_session is not available so use jobid_name when possible
1053         if $LCTL list_param jobid_name > /dev/null 2>&1; then
1054                 local jobvarname=jobid_name test_val="$TESTNAME-$RANDOM%p"
1055         else
1056                 local jobvarname=jobid_var test_val=$TESTNAME-$RANDOM
1057         fi
1058
1059         local jobid_var_new
1060         local jobid_var_old=$($LCTL get_param -n $jobvarname)
1061         local paramdir=/etc/lustre
1062         local paramfile=$paramdir/mount.$FSNAME.params
1063
1064         [[ -d $paramdir ]] || mkdir $paramdir
1065
1066         stack_trap "$LCTL set_param $jobvarname=$jobid_var_old"
1067
1068         if [[ -e $paramfile ]]; then
1069                 mv $paramfile $paramfile.$testname
1070                 stack_trap "mv $paramfile.$testname $paramfile"
1071         else
1072                 # leave no traces behind
1073                 stack_trap "rm $paramfile"
1074         fi
1075         echo "$jobvarname=$test_val" > $paramfile
1076
1077         remount_client $MOUNT
1078
1079         jobid_var_new=$($LCTL get_param -n $jobvarname)
1080
1081         echo "before mount: $jobid_var_old"
1082         echo "after mount:  $jobid_var_new"
1083         [[ "$jobid_var_new" == "$test_val" ]] ||
1084                 error "$jobvarname was not $test_val: got $jobid_var_new"
1085 }
1086 run_test 28c "verify filesystem parameters are set upon mount"
1087
1088 test_29() {
1089         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >= 2 OSTs"
1090         setup_noconfig > /dev/null 2>&1
1091         start_ost2 || error "Unable to start OST2"
1092         sleep 10
1093
1094         local PARAM="$FSNAME-OST0001.osc.active"
1095         # With lctl set_param -P the value $PROC_ACT will be sent to
1096         # all nodes. The [!M] filter out the ability to set active
1097         # on the MDS servers which is tested with wait_osp_* below.
1098         # For ost_server_uuid that only exist on client so filtering
1099         # is safe.
1100         local PROC_ACT="os[cp].$FSNAME-OST0001-osc-[^M]*.active"
1101         local PROC_UUID="os[cp].$FSNAME-OST0001-osc-[^M]*.ost_server_uuid"
1102
1103         ACTV=$($LCTL get_param -n $PROC_ACT)
1104         DEAC=$((1 - $ACTV))
1105         set_persistent_param_and_check client $PROC_ACT $PARAM $DEAC
1106         # also check ost_server_uuid status
1107         RESULT=$($LCTL get_param -n $PROC_UUID | grep DEACTIV)
1108         if [ -z "$RESULT" ]; then
1109                 error "Client not deactivated: $($LCTL get_param \
1110                        -n $PROC_UUID)"
1111         else
1112                 echo "Live client success: got $RESULT"
1113         fi
1114
1115         # check MDTs too
1116         wait_osp_active ost ${FSNAME}-OST0001 1 0
1117
1118         # test new client starts deactivated
1119         umount_client $MOUNT || error "umount_client $MOUNT failed"
1120         mount_client $MOUNT || error "mount_client $MOUNT failed"
1121
1122         # the 2nd and 3rd field of ost_server_uuid do not update at the same
1123         # time when using lctl set_param -P
1124         wait_update_facet client                                        \
1125                 "$LCTL get_param -n $PROC_UUID | awk '{print \\\$3 }'"  \
1126                 "DEACTIVATED" ||
1127                 error "New client start active: $($LCTL get_param -n $PROC_UUID)"
1128
1129         echo "New client success: got '$($LCTL get_param -n $PROC_UUID)'"
1130
1131         # make sure it reactivates
1132         set_persistent_param_and_check client $PROC_ACT $PARAM $ACTV
1133
1134         umount_client $MOUNT
1135         stop_ost2 || error "Unable to stop OST2"
1136         cleanup_nocli || error "cleanup_nocli failed with $?"
1137         #writeconf to remove all ost2 traces for subsequent tests
1138         writeconf_or_reformat
1139 }
1140 run_test 29 "permanently remove an OST"
1141
1142 test_30a() {
1143         setup_noconfig
1144
1145         echo Big config llog
1146         local path="llite.$FSNAME-*"
1147         local cpath="$FSNAME.llite"
1148         local param="max_read_ahead_whole_mb"
1149
1150         local test="${path}.$param"
1151         local conf="${cpath}.$param"
1152
1153         local orig=$($LCTL get_param -n $test)
1154         local list=(1 2 3 4 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5)
1155         for i in ${list[*]}; do
1156                 set_persistent_param_and_check client $test $conf $i
1157         done
1158         # make sure client restart still works
1159         umount_client $MOUNT
1160         mount_client $MOUNT || error "mount_client $MOUNT failed"
1161         [ "$($LCTL get_param -n $test)" -ne "$i" ] &&
1162                 error "Param didn't stick across restart $($test) != $i"
1163         pass
1164
1165         echo Erase parameter setting
1166         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1167                 do_facet mgs "$PERM_CMD -d $test" ||
1168                         error "Erase param $test failed"
1169         else
1170                 do_facet mgs "$PERM_CMD -d $conf" ||
1171                         error "Erase param $conf failed"
1172         fi
1173         umount_client $MOUNT
1174         mount_client $MOUNT || error "mount_client $MOUNT failed"
1175         local final=$($LCTL get_param -n $test)
1176         echo "deleted (default) value=$final, orig=$orig"
1177         orig=${orig%%.[0-9]*}
1178         final=${final%%.[0-9]*}
1179         # assumes this parameter started at the default value
1180         [ "$final" -eq "$orig" ] ||
1181                 error "Deleted value=$final -ne orig=$orig"
1182
1183         cleanup || error "cleanup failed with rc $?"
1184 }
1185 run_test 30a "Big config llog and permanent parameter deletion"
1186
1187 test_30b() {
1188         setup_noconfig
1189
1190         local orignids=$($LCTL get_param -n \
1191                 osc.$FSNAME-OST0000-osc-[^M]*.import | grep failover_nids)
1192         local orignidcount=$(echo "$orignids" | wc -w)
1193
1194         # Make a fake NID.  Use the OST NID, and increase the least significant
1195         # field. Hopefully that's not already a failover address for an existing
1196         # node, but if so try again until it is an unused NID for this cluster.
1197         local ostnid=$(do_facet ost1 "$LCTL list_nids | tail -1")
1198         local origval=$(echo $ostnid | egrep -oi "[0-9a-f]*@")
1199         # this will match on first loop, but keeps fake NID logic in one place
1200         local newnid=$ostnid
1201
1202         echo "Checking peer and local NIDs:"
1203         while { $LNETCTL peer show | awk '/nid/{print $NF}' | sort -u
1204                 $LCTL list_nids; } | grep -w $newnid; do
1205                 local newval=$(((0x${origval%@} + $RANDOM) % 256))
1206                 newnid=${ostnid/$origval/$newval@}
1207         done
1208
1209         echo "Changing $ostnid to fake NID $newnid"
1210
1211         local test="$LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1212                     grep failover_nids | sed -n 's/.*\($newnid\).*/\1/p'"
1213         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1214                 param="osc.$FSNAME-OST0000-osc-[^M]*.import"
1215                 echo "Setting $param from $ostnid to $newnid"
1216                 do_facet mgs "$PERM_CMD $param='connection=$newnid'" ||
1217                         error "$PERM_CMD $param failed"
1218         else
1219                 param="$FSNAME-OST0000.failover.node"
1220                 echo "Setting $param from $ostnid to $newnid"
1221                 do_facet mgs "$PERM_CMD $param='$newnid'" ||
1222                         error "$PERM_CMD $param failed"
1223         fi
1224         wait_update_facet client "$test" "$newnid" || {
1225                 $LCTL get_param  osc.$FSNAME-OST0000-osc-[^M]*.import
1226                 error "check $param for '$newnid' failed!"
1227         }
1228
1229         local nids=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1230                      grep failover_nids)
1231         local nidcount=$(echo "$nids" | wc -w)
1232         echo "should have $((orignidcount + 1)) failover NIDs, have $nidcount"
1233         (( $nidcount == $((orignidcount + 1)) )) || {
1234                 echo $nids
1235                 error "Failover NID '$newnid' not added"
1236         }
1237
1238         if [[ $PERM_CMD == *"set_param -P"* ]]; then
1239                 do_facet mgs "$PERM_CMD -d osc.$FSNAME-OST0000-osc-*.import"
1240         else
1241                 do_facet mgs "$PERM_CMD -d $FSNAME-OST0000.failover.node" ||
1242                         error "$PERM_CMD delete failed"
1243         fi
1244         umount_client $MOUNT || error "umount_client $MOUNT failed"
1245         mount_client $MOUNT || error "mount_client $MOUNT failed"
1246
1247         nids=$($LCTL get_param -n osc.$FSNAME-OST0000-osc-[^M]*.import |
1248                grep failover_nids)
1249         nidcount=$(echo "$nids" | wc -w)
1250         echo "only $orignidcount failover NIDs should be left, have $nidcount"
1251         (( $nidcount == $orignidcount )) || {
1252                 echo "$nids"
1253                 error "Failover NID '$newnid' not removed"
1254         }
1255
1256         cleanup || error "cleanup failed with rc $?"
1257 }
1258 run_test 30b "Remove failover nids"
1259
1260 test_31() { # bug 10734
1261         # ipaddr must not exist
1262         $MOUNT_CMD 4.3.2.1@tcp:/lustre $MOUNT || true
1263         cleanup || error "cleanup failed with rc $?"
1264 }
1265 run_test 31 "Connect to non-existent node (shouldn't crash)"
1266
1267
1268 T32_QID=60000
1269 T32_BLIMIT=40960 # Kbytes
1270 T32_ILIMIT=4
1271 T32_PRJID=1000
1272 T32_PROLIMIT=$((T32_BLIMIT/10))
1273 T32_POOLLIMIT=$((T32_BLIMIT/2))
1274 #
1275 # This is not really a test but a tool to create new disk
1276 # image tarballs for the upgrade tests.
1277 #
1278 # Disk image tarballs should be created on single-node
1279 # clusters by running this test with default configurations
1280 # plus a few mandatory environment settings that are verified
1281 # at the beginning of the test.
1282 #
1283 test_32newtarball() {
1284         local version
1285         local dst=.
1286         local src=/etc/rc.d
1287         local tmp=$TMP/t32_image_create
1288         local remote_dir
1289         local striped_dir
1290         local pushd_dir
1291         local pfl_dir
1292         local pfl_file
1293         local dom_dir
1294         local dom_file
1295         local flr_dir
1296         local flr_file
1297         local pj_quota_dir
1298         local pj_quota_file_old
1299         local target_dir
1300
1301         [[ "$FSNAME" == "t32fs" && ( -n "$MDSDEV" || -n "$MDSDEV1" ) &&
1302            -n "$OSTDEV1" ]] && (( $OSTCOUNT == 2 )) ||
1303                 error   "Needs FSNAME=t32fs MDSCOUNT=2 "                \
1304                         "MDSDEV1=<nonexistent_file> "                   \
1305                         "MDSDEV2=<nonexistent_file> "                   \
1306                         "(or MDSDEV, in the case of b1_8) "             \
1307                         "OSTCOUNT=2 OSTDEV1=<nonexistent_file> "        \
1308                         "OSTDEV2=<nonexistent_file>"
1309
1310         mkdir $tmp || error "Found stale $tmp"
1311
1312         mkdir $tmp/src || return 1
1313         tar cf - -C $src . | tar xf - -C $tmp/src
1314
1315         # format ost with comma-separated NIDs to verify LU-4460
1316         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
1317         MGSNID="$MGSNID,$MGSNID" OSTOPT="--failnode=$failnid" formatall
1318
1319         setupall
1320
1321         (( "$MDS1_VERSION" >= $(version_code 2.3.50) )) ||
1322                 $LFS quotacheck -ug /mnt/$FSNAME
1323         $LFS setquota -u $T32_QID -b 0 -B $T32_BLIMIT -i 0 -I $T32_ILIMIT \
1324                 /mnt/$FSNAME
1325
1326         if (( $MDSCOUNT >= 2 )); then
1327                 remote_dir=/mnt/$FSNAME/remote_dir
1328                 $LFS mkdir -i 1 $remote_dir
1329                 tar cf - -C $tmp/src . | tar xf - -C $remote_dir
1330
1331                 target_dir=$remote_dir
1332                 if (( $MDS1_VERSION >= $(version_code 2.7.0) )); then
1333                         striped_dir=/mnt/$FSNAME/striped_dir_old
1334                         $LFS mkdir -i 1 -c 2 $striped_dir
1335                         tar cf - -C $tmp/src . | tar xf - -C $striped_dir
1336                 fi
1337         else
1338                 tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1339                 target_dir=/mnt/$FSNAME
1340         fi
1341
1342         # add project quota #
1343         [[ $mds1_FSTYPE == "ldiskfs" &&
1344                 $MDS1_VERSION -gt $(version_code 2.9.55) ]] ||
1345         [[ $mds1_FSTYPE == "zfs" &&
1346                 $MDS1_VERSION -gt $(version_code 2.10.53) ]] && {
1347                 pj_quota_dir=$target_dir/project_quota_dir
1348                 pj_quota_file_old=$pj_quota_dir/pj_quota_file_old
1349
1350                 enable_project_quota
1351                 set_mdt_qtype ugp ||
1352                         error "enable mdt quota failed"
1353
1354                 set_ost_qtype ugp ||
1355                         error "enable ost quota failed"
1356
1357                 mkdir -p $pj_quota_dir
1358                 $LFS setquota -p $T32_PRJID -b 0 -B $T32_PROLIMIT -i 0 \
1359                         -I $T32_ILIMIT $pj_quota_dir ||
1360                         error "setquota -p $T32_PRJID failed"
1361
1362                 $LFS setstripe $pj_quota_file_old -c 1 ||
1363                         error "setstripe $pj_quota_file_old failed"
1364
1365                 chown $T32_QID:$T32_QID $pj_quota_file_old ||
1366                         error "chown $pj_quota_file_old failed"
1367
1368                 change_project -p $T32_PRJID $pj_quota_file_old
1369
1370                 mkdir -p $tmp/src/project_quota_dir
1371                 cp $pj_quota_file_old $tmp/src/project_quota_dir/
1372         }
1373
1374         #####################
1375
1376         # PFL file #
1377         if (( $MDS1_VERSION >= $(version_code 2.9.51) )); then
1378                 pfl_dir=$target_dir/pfl_dir
1379                 pfl_file=$pfl_dir/pfl_file
1380                 mkdir -p $pfl_dir
1381                 $LFS setstripe -E 2M -c1 -o0 -E -1 -S2M -c1 -o1 $pfl_dir ||
1382                         error "Create PFL file failed"
1383
1384                 dd if=/dev/urandom of=$pfl_file bs=1M count=3
1385                 mkdir -p $tmp/src/pfl_dir
1386                 cp $pfl_file $tmp/src/pfl_dir/
1387         fi
1388
1389         ############
1390         # DoM / FLR file #
1391         if (( $MDS1_VERSION >= $(version_code 2.10.56) )); then
1392                 dom_dir=$target_dir/dom_dir
1393                 dom_file=$dom_dir/dom_file
1394                 flr_dir=$target_dir/flr_dir
1395                 flr_file=$flr_dir/flr_file
1396
1397                 mkdir -p $dom_dir
1398                 $LFS setstripe -E 1M -L mdt -E -1 -S 4M $dom_dir
1399                 dd if=/dev/urandom of=$dom_file bs=1M count=2 ||
1400                         error "create $dom_file failed"
1401                 mkdir -p $tmp/src/dom_dir
1402                 cp $dom_file $tmp/src/dom_dir
1403         # FLR #
1404                 mkdir -p $flr_dir
1405                 $LFS mirror create -N2 $flr_file
1406                 dd if=/dev/urandom of=$flr_file bs=1k count=1 ||
1407                         error "create $flr_file failed"
1408                 mkdir -p $tmp/src/flr_dir
1409                 cp $flr_file $tmp/src/flr_dir
1410         fi
1411         ############
1412
1413         ############
1414         # OST pool quota #
1415         if (( $MDS1_VERSION >= $(version_code 2.13.56) )); then
1416                 local qpool=testpool
1417                 local pool_name=$FSNAME.$qpool
1418                 local pool_dir=$target_dir/pool_dir
1419                 local pool_list=$pool_dir/pool_list
1420                 local pool_file=$pool_dir/pool_file
1421
1422                 $LCTL pool_new $pool_name || error "pool_new $pool_name failed"
1423                 $LCTL pool_add $pool_name $FSNAME-OST[0-1/1] ||
1424                         error "pool_add $pool_name failed"
1425
1426                 mkdir_on_mdt0 $pool_dir || error "mkdir $pool_dir failed"
1427                 chmod 0777 $pool_dir || error "chmod $pool_dir failed"
1428                 $LFS setstripe -E 1M -c 1 --pool $qpool -E eof -c 2 $pool_dir ||
1429                         error "setstripe $pool_dir failed"
1430                 touch $pool_file || error "touch $pool_file failed"
1431                 chown $T32_QID:$T32_QID $pool_file ||
1432                         error "chown $pool_file failed"
1433
1434                 $LCTL pool_list $pool_name > $pool_list ||
1435                         error "create $pool_list failed"
1436
1437                 set_ost_qtype ugp ||
1438                         error "enable ost quota failed"
1439
1440                 $LFS setquota -u $T32_QID -B $T32_POOLLIMIT --pool $qpool \
1441                         $pool_dir || error "set user quota on $pool_dir failed"
1442
1443                 mkdir -p $tmp/src/pool_dir
1444                 cp -t $tmp/src/pool_dir $pool_file $pool_list
1445         fi
1446         ############
1447
1448         ############
1449         # fscrypt file data #
1450         if (( $MDS1_VERSION >= $(version_code 2.13.55) )) &&
1451                 which fscrypt; then
1452                 local fscrypt_data_pass=$target_dir/fscrypt_data_pass
1453                 local fscrypt_data_dir=$target_dir/fscrypt_data_dir
1454                 local fscrypt_data_file=$fscrypt_data_dir/fscrypt_data_file
1455                 local fscrypt_data_dom=$fscrypt_data_dir/fscrypt_data_dom
1456                 local my_pass="mypass"
1457
1458                 yes | fscrypt setup --force --verbose ||
1459                         error "fscrypt global setup failed"
1460                 sed -i 's/\(.*\)policy_version\(.*\):\(.*\)\"[0-9]*\"\(.*\)/\1policy_version\2:\3"2"\4/' \
1461                         /etc/fscrypt.conf
1462                 yes | fscrypt setup --verbose /mnt/$FSNAME ||
1463                         error "fscrypt setup /mnt/$FSNAME failed"
1464
1465                 mkdir_on_mdt0 $fscrypt_data_dir ||
1466                         error "mkdir $fscrypt_data_dir failed"
1467
1468                 echo -e 'mypass\nmypass' |
1469                         fscrypt encrypt --verbose --source=custom_passphrase \
1470                         --name=protector $fscrypt_data_dir ||
1471                         error "fscrypt encrypt $fscrypt_data_dir failed"
1472
1473                 echo "$my_pass" > $fscrypt_data_pass ||
1474                         error "save $fscrypt_data_pass failed"
1475
1476                 dd if=/dev/urandom of=$fscrypt_data_file bs=128k count=1 ||
1477                         error "write $fscrypt_data_file failed"
1478
1479                 $LFS setstripe -E 64K -L mdt -E eof -c 1 $fscrypt_data_dom ||
1480                         error "setstripe $fscrypt_data_dom failed"
1481                 dd if=/dev/urandom of=$fscrypt_data_dom bs=128k count=1 ||
1482                         error "write $fscrypt_data_dom failed"
1483
1484                 ls -R $fscrypt_data_dir ||
1485                         error "ls -R $fscrypt_data_dir failed"
1486                 local filecount=$(find $fscrypt_data_dir -type f | wc -l)
1487                 (( filecount == 2 )) || error "found $filecount files"
1488
1489                 mkdir -p $tmp/src/fscrypt_data_dir
1490                 cp -t $tmp/src/fscrypt_data_dir \
1491                         $fscrypt_data_file $fscrypt_data_dom
1492                 cp $fscrypt_data_pass $tmp/src
1493         fi
1494         ############
1495
1496         ############
1497         # fscrypt file name #
1498         if (( $MDS1_VERSION >= $(version_code 2.14.57) )) &&
1499                 which fscrypt; then
1500                 local fscrypt_name_pass=$target_dir/fscrypt_name_pass
1501                 local fscrypt_name_dir=$target_dir/fscrypt_name_dir
1502                 local fscrypt_name_file=$fscrypt_name_dir/fscrypt_name_file
1503                 local fscrypt_name_dom=$fscrypt_name_dir/fscrypt_name_dom
1504
1505                 [[ -s $fscrypt_data_pass ]] &&
1506                         my_pass=$(cat $fscrypt_data_pass) ||
1507                         my_pass="mypass"
1508
1509                 mkdir_on_mdt0 $fscrypt_name_dir ||
1510                         error "mkdir $fscrypt_name_dir failed"
1511
1512                 $LCTL set_param -P llite.*.enable_filename_encryption=1 ||
1513                         error "enable filename encryption failed"
1514
1515                 wait_update_facet --verbose client \
1516                         "$LCTL get_param -n llite.*.enable_filename_encryption \
1517                         | head -n1" 1 30 ||
1518                         error "enable_filename_encryption not set on client"
1519
1520                 echo -e 'mypass\nmypass' |
1521                         fscrypt encrypt --verbose --source=custom_passphrase \
1522                         --name=protector2 $fscrypt_name_dir ||
1523                         error "fscrypt encrypt $fscrypt_name_dir failed"
1524
1525                 echo "$my_pass" > $fscrypt_name_pass ||
1526                         error "save $fscrypt_name_pass failed"
1527
1528                 dd if=/dev/urandom of=$fscrypt_name_file bs=128k count=1 ||
1529                         error "write $fscrypt_name_file failed"
1530
1531                 $LFS setstripe -E 64K -L mdt -E eof -c 1 $fscrypt_name_dom ||
1532                         error "setstripe $fscrypt_name_dom failed"
1533                 dd if=/dev/urandom of=$fscrypt_name_dom bs=128k count=1 ||
1534                         error "write $fscrypt_name_dom failed"
1535
1536                 ls -R $fscrypt_name_dir ||
1537                         error "ls -R $fscrypt_name_dir failed"
1538                 local filecount=$(find $fscrypt_name_dir -type f | wc -l)
1539                 (( filecount == 2 )) || error "found $filecount files"
1540
1541                 mkdir -p $tmp/src/fscrypt_name_dir
1542                 cp -t $tmp/src/fscrypt_name_dir \
1543                         $fscrypt_name_file $fscrypt_name_dom
1544                 cp $fscrypt_name_pass $tmp/src
1545         fi
1546         ############
1547
1548         local large_xattr_dir=/mnt/$FSNAME/large_xattr_test_dir
1549         local xattr_file=$large_xattr_dir/large_xattr_file
1550
1551         mkdir $large_xattr_dir
1552         touch $xattr_file
1553         setfattr -n user.fooattr -v $(printf "%c" {1..4096} ) $xattr_file ||
1554                 rm -f $xattr_file
1555
1556         tar cf - -C $tmp/src . | tar xf - -C /mnt/$FSNAME
1557
1558         stopall
1559
1560         mkdir $tmp/img || return 1
1561
1562         setupall
1563
1564         if [[ -n $fscrypt_data_pass ]]; then
1565                 local unlock_status=$(fscrypt status $fscrypt_data_dir |
1566                                       awk '/Unlocked:/{print $2}')
1567                 [[ $unlock_status == Yes ]] ||
1568                         cat $fscrypt_data_pass |
1569                         fscrypt unlock --verbose $fscrypt_data_dir ||
1570                                 error "unlock $fscrypt_data_dir failed"
1571         fi
1572
1573         if [[ -n $fscrypt_name_pass ]]; then
1574                 local unlock_status=$(fscrypt status $fscrypt_name_dir |
1575                                       awk '/Unlocked:/{print $2}')
1576                 [[ $unlock_status == Yes ]] ||
1577                         cat $fscrypt_name_pass |
1578                         fscrypt unlock --verbose $fscrypt_name_dir ||
1579                                 error "unlock $fscrypt_name_dir failed"
1580         fi
1581
1582         pushd_dir=/mnt/$FSNAME
1583         if [[ $MDSCOUNT -ge 2 ]]; then
1584                 pushd_dir=$remote_dir
1585                 if [[ "$MDS1_VERSION" -ge $(version_code 2.7.0) ]]; then
1586                         pushd $striped_dir
1587                         BLOCKSIZE=1024 ls -Rni --time-style=+%s >$tmp/img/list2
1588                         popd
1589                 fi
1590         fi
1591
1592         pushd $pushd_dir
1593         BLOCKSIZE=1024 ls -Rni --time-style=+%s >$tmp/img/list
1594         find ! -name .lustre -type f -exec sha1sum {} \; |
1595                 sort -k 2 >$tmp/img/sha1sums
1596         popd
1597         $LCTL get_param -n version | head -n 1 |
1598                 sed -e 's/^lustre: *//' >$tmp/img/commit
1599
1600         [[ "$MDS1_VERSION" -ge $(version_code 2.3.50) ]] ||
1601                 $LFS quotaon -ug /mnt/$FSNAME
1602         $LFS quota -u $T32_QID -v /mnt/$FSNAME
1603         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1604                 awk 'BEGIN { num='1' } { if ($1 == "'/mnt/$FSNAME'") \
1605                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1606                 | tr -d "*" > $tmp/img/bspace
1607         $LFS quota -v -u $T32_QID /mnt/$FSNAME |
1608                 awk 'BEGIN { num='5' } { if ($1 == "'/mnt/$FSNAME'") \
1609                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1610                 | tr -d "*" > $tmp/img/ispace
1611         echo $T32_BLIMIT > $tmp/img/blimit
1612         echo $T32_ILIMIT > $tmp/img/ilimit
1613
1614         # OST pool quota #
1615         if (( $MDS1_VERSION >= $(version_code 2.13.56) )); then
1616                 $LFS quota -v -u $T32_QID --pool $qpool $pool_dir
1617                 DIR=$pool_dir getquota -u $T32_QID global curspace $qpool \
1618                         > $tmp/img/bspace_pool
1619                 echo $T32_POOLLIMIT > $tmp/img/blimit_pool
1620         fi
1621
1622         # fscrypt file data #
1623         if [[ -n $fscrypt_data_pass ]]; then
1624                 unlock_status=$(fscrypt status $fscrypt_data_dir |
1625                                 awk '/Unlocked:/{print $2}')
1626
1627                 if [[ $unlock_status == Yes ]]; then
1628                         fscrypt lock --verbose $fscrypt_data_dir ||
1629                                 error "fscrypt lock $fscrypt_data_dir failed"
1630                 fi
1631
1632                 ls -l $fscrypt_data_dir ||
1633                         error "ls -l $fscrypt_data_dir failed"
1634                 ls $fscrypt_data_file || error "ls $fscrypt_data_file failed"
1635                 ls $fscrypt_data_dom || error "ls $fscrypt_data_dom failed"
1636         fi
1637
1638         # fscrypt file name #
1639         if [[ -n $fscrypt_name_pass ]]; then
1640                 unlock_status=$(fscrypt status $fscrypt_name_dir |
1641                                 awk '/Unlocked:/{print $2}')
1642
1643                 if [[ $unlock_status == Yes ]]; then
1644                         fscrypt lock --verbose $fscrypt_name_dir ||
1645                                 error "fscrypt lock $fscrypt_name_dir failed"
1646                 fi
1647
1648                 ls -l $fscrypt_name_dir ||
1649                         error "ls -l $fscrypt_name_dir failed"
1650                 ! ls $fscrypt_name_file ||
1651                         error "ls $fscrypt_name_file should fail"
1652                 ! ls $fscrypt_name_dom ||
1653                         error "ls $fscrypt_name_dom should fail"
1654         fi
1655
1656         $MULTIOP /mnt/$FSNAME/orph_file Ouw_c&
1657         pid=$!
1658         sync
1659         stop_mdt_no_force 1
1660         debugfs -R "ls /PENDING" ${MDSDEV1:-$MDSDEV}
1661         start_mdt 1
1662         kill -s USR1 $pid
1663         wait $pid
1664
1665         #################
1666         stopall
1667
1668         pushd $tmp/src
1669         find -type f -exec sha1sum {} \; | sort -k 2 >$tmp/sha1sums.src
1670         popd
1671
1672         if ! diff -u $tmp/sha1sums.src $tmp/img/sha1sums; then
1673                 echo "Data verification failed"
1674         fi
1675
1676         uname -r >$tmp/img/kernel
1677         uname -m >$tmp/img/arch
1678
1679         for ((num=1; num <= $MDSCOUNT; num++)); do
1680                 local devname=$(mdsdevname $num)
1681                 local facet=mds$num
1682                 local image_name
1683
1684                 [[ num -eq 1 ]] && image_name=mdt || image_name=mdt$num
1685                 [[ $(facet_fstype $facet) != zfs ]] ||
1686                         devname=$(mdsvdevname $num)
1687                 dd conv=sparse bs=4k if=$devname of=$tmp/img/$image_name
1688         done
1689
1690         for ((num=1; num <= $OSTCOUNT; num++)); do
1691                 local devname=$(ostdevname $num)
1692                 local facet=oss$num
1693                 local image_name
1694
1695                 [[ num -eq 1 ]] && image_name=ost || image_name=ost$num
1696                 [[ $(facet_fstype $facet) != zfs ]] ||
1697                         devname=$(ostvdevname $num)
1698                 dd conv=sparse bs=4k if=$devname of=$tmp/img/$image_name
1699         done
1700
1701         version=$(sed -e 's/\(^[0-9]\+\.[0-9]\+\)\(.*$\)/\1/' $tmp/img/commit |
1702                           sed -e 's/\./_/g')    # E.g., "1.8.7" -> "1_8"
1703         dst=$(cd $dst; pwd)
1704         pushd $tmp/img
1705         tar cjvf $dst/disk$version-"$mds1_FSTYPE".tar.bz2 -S *
1706         popd
1707
1708         rm -r $tmp
1709 }
1710 # run_test 32newtarball "Create new test_32 disk image tarball for this version"
1711
1712 #
1713 # The list of applicable tarballs is returned via the caller's
1714 # variable "tarballs".
1715 #
1716 t32_check() {
1717         [ "$CLIENTONLY" ] && skip "Client-only testing"
1718
1719         check_versions || skip "do not upgrade with mismatched client/server"
1720
1721         local node=$(facet_active_host $SINGLEMDS)
1722         local r="do_node $node"
1723
1724         ! $r which "$TUNEFS" && skip_env "tunefs.lustre required on $node"
1725
1726         local IMGTYPE="$mds1_FSTYPE"
1727
1728         [[ -n "$T32IMAGE" ]] && tarballs=$T32IMAGE ||
1729                 tarballs=$($r find $RLUSTRE/tests -maxdepth 1 \
1730                            -name \'disk*-$IMGTYPE.tar.bz2\')
1731
1732         [ -z "$tarballs" ] && skip "No applicable tarballs found"
1733 }
1734
1735 t32_test_cleanup() {
1736         local tmp=$TMP/t32
1737         local facet=$SINGLEMDS
1738         local rc=$?
1739
1740         echo "== cleanup with rc=$rc =="
1741         if $shall_cleanup_lustre; then
1742                 umount $tmp/mnt/lustre || rc=$?
1743         fi
1744         if $shall_cleanup_mdt; then
1745                 $r $UMOUNT $tmp/mnt/mdt || rc=$?
1746         fi
1747         if $shall_cleanup_mdt1; then
1748                 $r $UMOUNT $tmp/mnt/mdt1 || rc=$?
1749         fi
1750         if $shall_cleanup_ost; then
1751                 $r $UMOUNT $tmp/mnt/ost || rc=$?
1752         fi
1753         if $shall_cleanup_ost1; then
1754                 $r $UMOUNT $tmp/mnt/ost1 || rc=$?
1755         fi
1756
1757         $r rm -rf $tmp
1758         rm -rf $tmp
1759         if [[ "$mds1_FSTYPE" == zfs ]]; then
1760                 local poolname
1761                 local poolname_list="t32fs-mdt1 t32fs-ost1"
1762
1763                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
1764
1765                 for poolname in $poolname_list; do
1766                         destroy_zpool $facet $poolname
1767                 done
1768         fi
1769         combined_mgs_mds || start_mgs || rc=$?
1770         return $rc
1771 }
1772
1773 t32_bits_per_long() {
1774         #
1775         # Yes, this is not meant to be perfect.
1776         #
1777         case $1 in
1778                 ppc64|x86_64)
1779                         echo -n 64;;
1780                 i*86)
1781                         echo -n 32;;
1782         esac
1783 }
1784
1785 t32_reload_modules() {
1786         local node=$1
1787         local all_removed=false
1788         local i=0
1789
1790         [ "$mds1_FSTYPE" == zfs ] && do_rpc_nodes $node "service zed stop"
1791
1792         while ((i < 20)); do
1793                 echo "Unloading modules on $node: Attempt $i"
1794                 do_rpc_nodes $node $LUSTRE_RMMOD "$mds1_FSTYPE" &&
1795                         all_removed=true
1796                 do_rpc_nodes $node check_mem_leak || return 1
1797                 if $all_removed; then
1798                         do_rpc_nodes $node load_modules
1799                         return 0
1800                 fi
1801                 if [ "$mds1_FSTYPE" == zfs ]; then
1802                         do_rpc_nodes $node "$ZPOOL status -v"
1803                 fi
1804                 sleep 5
1805                 i=$((i + 1))
1806         done
1807         echo "Unloading modules on $node: Given up"
1808         return 1
1809 }
1810
1811 t32_wait_til_devices_gone() {
1812         local node=$1
1813         local devices
1814         local loops
1815         local i=0
1816
1817         echo wait for devices to go
1818         while ((i < 20)); do
1819                 devices=$(do_rpc_nodes $node $LCTL device_list | wc -l)
1820                 loops=$(do_rpc_nodes $node losetup -a | grep -c t32)
1821                 ((devices == 0 && loops == 0)) && return 0
1822                 sleep 5
1823                 i=$((i + 1))
1824         done
1825         echo "waiting for dev on $node: dev $devices loop $loops given up"
1826         do_rpc_nodes $node "losetup -a"
1827         do_rpc_nodes $node "$LCTL device_list"
1828         return 1
1829 }
1830
1831 t32_verify_quota() {
1832         local facet=$1
1833         local fsname=$2
1834         local mnt=$3
1835         local qval
1836         local cmd
1837
1838         # LU-2435: if the underlying zfs doesn't support userobj_accounting,
1839         # lustre will estimate the object count usage. This fails quota
1840         # verification in 32b. The object quota usage should be accurate after
1841         # zfs-0.7.0 is released.
1842         [ "$mds1_FSTYPE" == zfs ] && {
1843                 local zfs_version=$(do_facet $facet cat /sys/module/zfs/version)
1844
1845                 [ $(version_code $zfs_version) -lt $(version_code 0.7.0) ] && {
1846                         echo "Skip quota verify for zfs: $zfs_version"
1847                         return 0
1848                 }
1849         }
1850
1851         $LFS quota -u $T32_QID -v $mnt
1852
1853         qval=$($LFS quota -v -u $T32_QID $mnt |
1854                 awk 'BEGIN { num='1' } { if ($1 == "'$mnt'") \
1855                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1856                 | tr -d "*")
1857         [ $qval -eq $img_bspace ] || {
1858                 echo "bspace, act:$qval, exp:$img_bspace"
1859                 return 1
1860         }
1861
1862         qval=$($LFS quota -v -u $T32_QID $mnt |
1863                 awk 'BEGIN { num='5' } { if ($1 == "'$mnt'") \
1864                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1865                 | tr -d "*")
1866         [ $qval -eq $img_ispace ] || {
1867                 echo "ispace, act:$qval, exp:$img_ispace"
1868                 return 1
1869         }
1870
1871         qval=$($LFS quota -v -u $T32_QID $mnt |
1872                 awk 'BEGIN { num='3' } { if ($1 == "'$mnt'") \
1873                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1874                 | tr -d "*")
1875         [ $qval -eq $img_blimit ] || {
1876                 echo "blimit, act:$qval, exp:$img_blimit"
1877                 return 1
1878         }
1879
1880         qval=$($LFS quota -v -u $T32_QID $mnt |
1881                 awk 'BEGIN { num='7' } { if ($1 == "'$mnt'") \
1882                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1883                 | tr -d "*")
1884         [ $qval -eq $img_ilimit ] || {
1885                 echo "ilimit, act:$qval, exp:$img_ilimit"
1886                 return 1
1887         }
1888
1889         set_persistent_param_and_check $facet \
1890                 "osd-$mds1_FSTYPE.$fsname-MDT0000.quota_slave.enabled" \
1891                 "$fsname.quota.mdt" ug
1892
1893         set_persistent_param_and_check $facet \
1894                 "osd-$mds1_FSTYPE.$fsname-OST0000.quota_slave.enabled" \
1895                 "$fsname.quota.ost" ug
1896
1897         chmod 0777 $mnt
1898         runas -u $T32_QID -g $T32_QID $DD of=$mnt/t32_qf_new \
1899                 count=$((img_blimit / 1024)) oflag=sync && {
1900                 echo "Write succeed, but expect -EDQUOT"
1901                 return 1
1902         }
1903         rm -f $mnt/t32_qf_new
1904
1905         runas -u $T32_QID -g $T32_QID createmany -m $mnt/t32_qf_ \
1906                 $img_ilimit && {
1907                 echo "Create succeed, but expect -EDQUOT"
1908                 return 1
1909         }
1910         unlinkmany $mnt/t32_qf_ $img_ilimit
1911
1912         # OST pool quota #
1913         if (( $(version_code $img_commit) >= $(version_code 2.13.56) )) &&
1914                 [[ "$pool_quota_upgrade" == "yes" ]]; then
1915                 $mdt2_is_available || pool_dir=$mnt/pool_dir
1916                 local pool_file_new=$pool_dir/pool_file_new
1917
1918                 local qpool=$($LFS getstripe -p $pool_dir)
1919                 [[ -n "$qpool" ]] || {
1920                         echo "no OST pool on $pool_dir"
1921                         return 1
1922                 }
1923
1924                 $LFS quota -v -u $T32_QID --pool $qpool $pool_dir
1925
1926                 qval=$(DIR=$pool_dir getquota -u $T32_QID \
1927                        global curspace $qpool)
1928                 [[ $qval == $img_bspace_pool ]] || {
1929                         echo "bspace_pool, act:$qval, exp:$img_bspace_pool"
1930                         return 1
1931                 }
1932
1933                 qval=$(DIR=$pool_dir getquota -u $T32_QID \
1934                        global bhardlimit $qpool)
1935                 [[ $qval == $img_blimit_pool ]] || {
1936                         echo "blimit_pool, act:$qval, exp:$img_blimit_pool"
1937                         return 1
1938                 }
1939
1940                 touch $pool_file_new || {
1941                         echo "touch $pool_file_new failed"
1942                         return 1
1943                 }
1944
1945                 chown $T32_QID:$T32_QID $pool_file_new || {
1946                         echo "chown $pool_file_new failed"
1947                         return 1
1948                 }
1949
1950                 runas -u $T32_QID -g $T32_QID $DD of=$pool_file_new \
1951                         count=$((img_blimit_pool / 1024)) oflag=sync && {
1952                         echo "Write $pool_file_new succeed, but expect -EDQUOT"
1953                         return 1
1954                 }
1955                 rm -f $pool_file_new
1956         fi
1957
1958         return 0
1959 }
1960
1961 get_project_quota() {
1962         local spec=$4
1963         local uuid=$3
1964         local mnt=$5
1965
1966         sync_all_data > /dev/null 2>&1 || true
1967
1968         [ "$uuid" != "global" ] || uuid=$mnt
1969
1970         $LFS quota -v "$1" "$2" $mnt |
1971                 awk 'BEGIN { num='$spec' } { if ($1 == "'$uuid'") \
1972                 { if (NF == 1) { getline } else { num++ } ; print $num;} }' \
1973                 | tr -d "*"
1974 }
1975
1976 t32_test() {
1977         local tarball=$1
1978         local writeconf=$2
1979         local dne_upgrade=${dne_upgrade:-"no"}
1980         local dom_upgrade=${dom_upgrade:-"no"}
1981         local project_upgrade=${project_upgrade:-"no"}
1982         local ff_convert=${ff_convert:-"no"}
1983         local pfl_upgrade=${pfl_upgrade:-"no"}
1984         local project_quota_upgrade=${project_quota_upgrade:-"no"}
1985         local dom_new_upgrade=${dom_new_upgrade:-"no"}
1986         local flr_upgrade=${flr_upgrade:-"no"}
1987         local pool_quota_upgrade=${pool_quota_upgrade:-"no"}
1988         local fscrypt_data_upgrade=${fscrypt_data_upgrade:-"no"}
1989         local fscrypt_name_upgrade=${fscrypt_name_upgrade:-"no"}
1990         local shall_cleanup_mdt=false
1991         local shall_cleanup_mdt1=false
1992         local shall_cleanup_ost=false
1993         local shall_cleanup_ost1=false
1994         local shall_cleanup_lustre=false
1995         local mdt2_is_available=false
1996         local ost2_is_available=false
1997         local node=$(facet_active_host $SINGLEMDS)
1998         local r="do_node $node"
1999         local tmp=$TMP/t32
2000         local img_commit
2001         local img_kernel
2002         local img_arch
2003         local img_bspace
2004         local img_bspace_pool
2005         local img_ispace
2006         local img_blimit
2007         local img_blimit_pool
2008         local img_ilimit
2009         local fsname=t32fs
2010         local nid
2011         local mopts
2012         local uuid
2013         local nrpcs_orig
2014         local nrpcs
2015         local list
2016         local mdt_dev=$tmp/mdt
2017         local mdt2_dev=$tmp/mdt2
2018         local ost_dev=$tmp/ost
2019         local ost2_dev=$tmp/ost2
2020         local stripe_index
2021         local stripe_count
2022         local dir
2023         local pfl_file=$tmp/mnt/lustre/remote_dir/pfl_dir/pfl_file
2024         local flr_file=$tmp/mnt/lustre/remote_dir/flr_dir/flr_file
2025         local dom_file=$tmp/mnt/lustre/remote_dir/dom_dir/dom_file
2026         local quota_dir=$tmp/mnt/lustre/remote_dir/project_quota_dir
2027         local pool_dir=$tmp/mnt/lustre/remote_dir/pool_dir
2028         local fscrypt_data_dir=$tmp/mnt/lustre/remote_dir/fscrypt_data_dir
2029         local fscrypt_data_pass=$tmp/mnt/lustre/remote_dir/fscrypt_data_pass
2030         local fscrypt_name_dir=$tmp/mnt/lustre/remote_dir/fscrypt_name_dir
2031         local fscrypt_name_pass=$tmp/mnt/lustre/remote_dir/fscrypt_name_pass
2032
2033         combined_mgs_mds || stop_mgs || error "Unable to stop MGS"
2034         trap 'trap - RETURN; t32_test_cleanup' RETURN
2035
2036         load_modules
2037         nid=$($r $LCTL list_nids | head -1)
2038
2039         mkdir -p $tmp/mnt/lustre || error "mkdir $tmp/mnt/lustre failed"
2040         $r mkdir -p $tmp/mnt/{mdt,mdt1,ost,ost1}
2041         $r tar xjvf $tarball -S -C $tmp || {
2042                 error_noexit "Unpacking the disk image tarball"
2043                 return 1
2044         }
2045         img_commit=$($r cat $tmp/commit)
2046         img_kernel=$($r cat $tmp/kernel)
2047         img_arch=$($r cat $tmp/arch)
2048         img_bspace=$($r cat $tmp/bspace)
2049         img_ispace=$($r cat $tmp/ispace)
2050
2051         if (( $(version_code $img_commit) >= $(version_code 2.13.56) )); then
2052                 img_bspace_pool=$($r cat $tmp/bspace_pool)
2053                 img_blimit_pool=$($r cat $tmp/blimit_pool)
2054         else
2055                 pool_quota_upgrade="no"
2056         fi
2057
2058         # older images did not have "blimit" and "ilimit" files
2059         # use old values for T32_BLIMIT and T32_ILIMIT
2060         $r test -f $tmp/blimit && img_blimit=$($r cat $tmp/blimit) ||
2061                 img_blimit=20480
2062         $r test -f $tmp/ilimit && img_ilimit=$($r cat $tmp/ilimit) ||
2063                 img_ilimit=2
2064
2065         echo "Upgrading from $(basename $tarball), created with:"
2066         echo "  Commit: $img_commit"
2067         echo "  Kernel: $img_kernel"
2068         echo "    Arch: $img_arch"
2069         echo "OST version: $(lustre_build_version ost1)"
2070
2071         # The conversion can be made only when both of the following
2072         # conditions are satisfied:
2073         # - ost device img version < 2.3.64
2074         # - ost server version >= 2.5
2075         [ $(version_code $img_commit) -ge $(version_code 2.3.64) -o \
2076                 "$OST1_VERSION" -lt $(version_code 2.5.0) ] &&
2077                         ff_convert="no"
2078
2079         ! $r test -f $mdt2_dev || mdt2_is_available=true
2080         ! $r test -f $ost2_dev || ost2_is_available=true
2081
2082         if [[ "$mds1_FSTYPE" == zfs ]]; then
2083                 echo "== fstype is zfs =="
2084                 # import pool first
2085                 local poolname
2086                 local poolname_list="t32fs-mdt1 t32fs-ost1"
2087
2088                 ! $mdt2_is_available || poolname_list+=" t32fs-mdt2"
2089                 ! $ost2_is_available || poolname_list+=" t32fs-ost2"
2090
2091                 for poolname in $poolname_list; do
2092                         $r "modprobe zfs;
2093                                 $ZPOOL list -H $poolname >/dev/null 2>&1 ||
2094                                 $ZPOOL import -f -d $tmp $poolname"
2095                 done
2096
2097                 # upgrade zpool to latest supported features, including
2098                 # dnode quota accounting in 0.7.0
2099                 $r "$ZPOOL upgrade -a"
2100
2101                 mdt_dev=t32fs-mdt1/mdt1
2102                 ost_dev=t32fs-ost1/ost1
2103                 ! $mdt2_is_available || mdt2_dev=t32fs-mdt2/mdt2
2104                 ! $ost2_is_available || ost2_dev=t32fs-ost2/ost2
2105                 wait_update_facet $SINGLEMDS "$ZPOOL list |
2106                         awk '/^t32fs-mdt1/ { print \\\$1 }'" "t32fs-mdt1" || {
2107                                 error_noexit "import zfs pool failed"
2108                                 return 1
2109                         }
2110         elif [ "$project_upgrade" != "no" ]; then
2111                 echo "== project upgrade =="
2112                 ! $r tune2fs -O project $mdt_dev &&
2113                         error_noexit "enable project on mdt0 failed" &&
2114                                 return 1
2115                 $mdt2_is_available && ! $r tune2fs "-O project" $mdt2_dev &&
2116                         error_noexit "enable project on mdt failed" &&
2117                                 return 1
2118                 ! $r tune2fs -O project $ost_dev &&
2119                         error_noexit "enable project on ost failed" &&
2120                                 return 1
2121                 $ost2_is_available && ! $r tune2fs -O project $ost2_dev &&
2122                         error_noexit "enable project on ost2 failed" &&
2123                                 return 1
2124         fi
2125
2126         $r $LCTL set_param debug="$PTLDEBUG"
2127
2128         $r $TUNEFS --dryrun $mdt_dev || {
2129                 $r losetup -a
2130                 error_noexit "tunefs.lustre before mounting the MDT"
2131                 return 1
2132         }
2133
2134         if $mdt2_is_available; then
2135                 $r $TUNEFS --dryrun $mdt2_dev || {
2136                         $r losetup -a
2137                         error_noexit "tunefs.lustre before mounting the MDT"
2138                         return 1
2139                 }
2140         fi
2141
2142         if [ "$writeconf" ]; then
2143                 echo "== writeconf mdt tunefs and quota =="
2144                 mopts=writeconf
2145                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2146                         mopts="loop,$mopts"
2147                         $r $TUNEFS --quota $mdt_dev || {
2148                                 $r losetup -a
2149                                 error_noexit "Enable mdt quota feature"
2150                                 return 1
2151                         }
2152
2153                         if [ "$project_quota_upgrade" != "no" ]; then
2154                                 echo "== enable mdt2 project quota =="
2155                                 $r $TUNE2FS -O project $mdt_dev || {
2156                                         $r losetup -a
2157                                         error_noexit "tune2fs $mdt_dev failed"
2158                                         return 1
2159                                 }
2160                         fi
2161
2162                         if $mdt2_is_available; then
2163                                 $r $TUNEFS --quota $mdt2_dev || {
2164                                         $r losetup -a
2165                                         error_noexit "Enable mdt2 quota feature"
2166                                         return 1
2167                                 }
2168                                 if [ "$project_quota_upgrade" != "no" ]; then
2169                                         echo "== enable mdt2 project quota =="
2170                                         $r $TUNE2FS -O project $mdt2_dev || {
2171                                                 $r losetup -a
2172                                                 error_noexit \
2173                                                     "tune2fs $mdt2_dev failed"
2174                                                 return 1
2175                                         }
2176                                 fi
2177                         fi
2178                 fi
2179         else
2180                 echo "== replace nids =="
2181                 if [ -n "$($LCTL list_nids | grep -v '\(tcp\|lo\)[[:digit:]]*$')" ]; then
2182                         [[ "$MGS_VERSION" -ge $(version_code 2.3.59) ]] ||
2183                         skip "LU-2200: Cannot run over IB w/o lctl replace_nids "
2184                                 "(Need MGS version at least 2.3.59)"
2185                 fi
2186
2187                 local osthost=$(facet_active_host ost1)
2188                 local ostnid=$(do_node $osthost $LCTL list_nids | head -1)
2189
2190                 mopts=nosvc
2191                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2192                         mopts="loop,$mopts"
2193                 fi
2194                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt
2195                 $r $LCTL replace_nids $fsname-OST0000 $ostnid || {
2196                         $r $LCTL dl
2197                         error_noexit "replace_nids $fsname-OST0000 $ostnid failed"
2198                         return 1
2199                 }
2200                 if $ost2_is_available; then
2201                         $r $LCTL replace_nids $fsname-OST0001 $ostnid || {
2202                                 $r $LCTL dl
2203                                 error_noexit "replace_nids $fsname-OST0001 $ostnid failed"
2204                                 return 1
2205                         }
2206                 fi
2207                 $r $LCTL replace_nids $fsname-MDT0000 $nid || {
2208                         $r $LCTL dl
2209                         error_noexit "replace_nids $fsname-MDT0000 $nid failed"
2210                         return 1
2211                 }
2212                 if $mdt2_is_available; then
2213                         $r $LCTL replace_nids $fsname-MDT0001 $nid || {
2214                                 $r $LCTL dl
2215                                 error_noexit "replace_nids $fsname-MDT0001 $nid failed"
2216                                 return 1
2217                         }
2218                 fi
2219                 $r $UMOUNT $tmp/mnt/mdt
2220
2221                 mopts=exclude=$fsname-OST0000
2222                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2223                         mopts="loop,$mopts"
2224                 fi
2225         fi
2226
2227         t32_wait_til_devices_gone $node
2228
2229         $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
2230                 $r losetup -a
2231                 error_noexit "Mounting the MDT"
2232                 return 1
2233         }
2234         shall_cleanup_mdt=true
2235
2236         if $mdt2_is_available; then
2237                 echo "== mdt2 available =="
2238                 mopts=mgsnode=$nid,$mopts
2239                 $r $MOUNT_CMD -o $mopts $mdt2_dev $tmp/mnt/mdt1 || {
2240                         $r losetup -a
2241                         error_noexit "Mounting the MDT"
2242                         return 1
2243                 }
2244                 shall_cleanup_mdt1=true
2245                 echo "== mount new MDT $mdt2_dev =="
2246
2247                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 || {
2248                         error_noexit "enable remote dir create failed"
2249                         return 1
2250                 }
2251
2252         elif [ "$dne_upgrade" != "no" ]; then
2253                 local fs2mdsdev=$(mdsdevname 1_2)
2254                 local fs2mdsvdev=$(mdsvdevname 1_2)
2255
2256                 echo "== mkfs new MDT on ${fs2mdsdev} =="
2257                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2258                         mkfsoptions="--mkfsoptions=\\\"-J size=8\\\""
2259                 fi
2260
2261                 add $SINGLEMDS $(mds2failover_HOST="" \
2262                         mkfs_opts mds2 $fs2mdsdev $fsname) --reformat \
2263                         $mkfsoptions $fs2mdsdev $fs2mdsvdev > /dev/null || {
2264                         error_noexit "Mkfs new MDT failed"
2265                         return 1
2266                 }
2267
2268                 [[ "$mds1_FSTYPE" != zfs ]] || import_zpool mds1
2269
2270                 $r $TUNEFS --dryrun $fs2mdsdev || {
2271                         error_noexit "tunefs.lustre before mounting the MDT"
2272                         return 1
2273                 }
2274
2275                 echo "== mount new MDT....$fs2mdsdev =="
2276                 $r $MOUNT_CMD -o $mopts $fs2mdsdev $tmp/mnt/mdt1 || {
2277                         error_noexit "mount mdt1 failed"
2278                         return 1
2279                 }
2280
2281                 $r $LCTL set_param -n mdt.${fsname}*.enable_remote_dir=1 ||
2282                         error_noexit "enable remote dir create failed"
2283
2284                 shall_cleanup_mdt1=true
2285         fi
2286
2287         uuid=$($r $LCTL get_param -n mdt.$fsname-MDT0000.uuid) || {
2288                 error_noexit "Getting MDT UUID"
2289                 return 1
2290         }
2291         if [ "$uuid" != $fsname-MDT0000_UUID ]; then
2292                 error_noexit "Unexpected MDT UUID: \"$uuid\""
2293                 return 1
2294         fi
2295
2296         $r $TUNEFS --dryrun $ost_dev || {
2297                 error_noexit "tunefs.lustre before mounting the OST"
2298                 return 1
2299         }
2300
2301         if $ost2_is_available; then
2302                 $r $TUNEFS --dryrun $ost2_dev || {
2303                         error_noexit "tunefs.lustre before mounting the OST"
2304                         return 1
2305                 }
2306         fi
2307
2308         if [ "$writeconf" ]; then
2309                 echo "== writeconf and ost quota tunefs =="
2310                 mopts=mgsnode=$nid,$writeconf
2311                 if [ "$ost1_FSTYPE" == ldiskfs ]; then
2312                         mopts="loop,$mopts"
2313                         $r $TUNEFS --quota $ost_dev || {
2314                                 $r losetup -a
2315                                 error_noexit "Enable ost quota feature"
2316                                 return 1
2317                         }
2318
2319                         if [ "$project_quota_upgrade" != "no" ]; then
2320                                 echo "== enable ost project quota =="
2321                                 $r $TUNE2FS -O project $ost_dev || {
2322                                         $r losetup -a
2323                                         error_noexit "tune2fs $ost_dev failed"
2324                                         return 1
2325                                 }
2326                         fi
2327
2328                         if $ost2_is_available; then
2329                                 $r $TUNEFS --quota $ost2_dev || {
2330                                         $r losetup -a
2331                                         error_noexit "Enable ost2 quota feature"
2332                                         return 1
2333                                 }
2334                                 if [ "$project_quota_upgrade" != "no" ]; then
2335                                         echo "== enable ost2 project quota =="
2336                                         $r $TUNE2FS -O project $ost2_dev || {
2337                                                 $r losetup -a
2338                                                 error_noexit \
2339                                                 "tune2fs $ost2_dev failed"
2340                                                 return 1
2341                                         }
2342                                 fi
2343                         fi
2344                 fi
2345         else
2346                 mopts=mgsnode=$nid
2347                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
2348                         mopts="loop,$mopts"
2349                 fi
2350         fi
2351
2352         $r $MOUNT_CMD -onomgs -o$mopts $ost_dev $tmp/mnt/ost || {
2353                 error_noexit "Mounting the OST"
2354                 return 1
2355         }
2356
2357         if $ost2_is_available; then
2358                 $r $MOUNT_CMD -onomgs -o$mopts $ost2_dev $tmp/mnt/ost1 || {
2359                         error_noexit "Mounting the OST2"
2360                         return 1
2361                 }
2362                 shall_cleanup_ost1=true
2363         fi
2364
2365         shall_cleanup_ost=true
2366
2367         uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0000.uuid) || {
2368                 error_noexit "Getting OST UUID"
2369                 return 1
2370         }
2371         if [ "$uuid" != $fsname-OST0000_UUID ]; then
2372                 error_noexit "Unexpected OST UUID: \"$uuid\""
2373                 return 1
2374         fi
2375
2376         if $ost2_is_available; then
2377                 uuid=$($r $LCTL get_param -n obdfilter.$fsname-OST0001.uuid) ||{
2378                         error_noexit "Getting OST1 UUID"
2379                         return 1
2380                 }
2381                 if [ "$uuid" != $fsname-OST0001_UUID ]; then
2382                         error_noexit "Unexpected OST1 UUID: \"$uuid\""
2383                         return 1
2384                 fi
2385         fi
2386
2387         if [[ $PERM_CMD =~ "set_param" ]]; then
2388                 echo "== perm cmd = '$PERM_CMD' =="
2389                 $r $PERM_CMD osc.$fsname-OST0000*.import=connection=$nid || {
2390                         error_noexit "Setting OST \"failover.node\""
2391                         return 1
2392                 }
2393                 $r $PERM_CMD mdc.$fsname-MDT0000*.import=connection=$nid || {
2394                         error_noexit "Setting MDT \"failover.node\""
2395                         return 1
2396                 }
2397                 $r $PERM_CMD osc.$fsname-OST0000-*.max_dirty_mb=15 || {
2398                         error_noexit "Setting \"max_dirty_mb\""
2399                         return 1
2400                 }
2401                 $r $PERM_CMD mdc.$fsname-MDT0000-*.max_rpcs_in_flight=9 || {
2402                         error_noexit "Setting \"max_rpcs_in_flight\""
2403                         return 1
2404                 }
2405                 $r $PERM_CMD lov.$fsname-MDT0000-*.stripesize=4M || {
2406                         error_noexit "Setting \"lov.stripesize\""
2407                         return 1
2408                 }
2409                 $r $PERM_CMD mdd.$fsname-MDT0000-*.atime_diff=70 || {
2410                         error_noexit "Setting \"mdd.atime_diff\""
2411                         return 1
2412                 }
2413         else
2414                 echo "== perm cmd = '$PERM_CMD' =="
2415                 $r $PERM_CMD $fsname-OST0000.failover.node=$nid || {
2416                         error_noexit "Setting OST \"failover.node\""
2417                         return 1
2418                 }
2419
2420                 $r $PERM_CMD $fsname-MDT0000.failover.node=$nid || {
2421                         error_noexit "Setting MDT \"failover.node\""
2422                         return 1
2423                 }
2424
2425                 $r $PERM_CMD $fsname-OST0000.osc.max_dirty_mb=15 || {
2426                         error_noexit "Setting \"max_dirty_mb\""
2427                         return 1
2428                 }
2429                 $r $PERM_CMD $fsname-MDT0000.mdc.max_rpcs_in_flight=9 || {
2430                         error_noexit "Setting \"max_rpcs_in_flight\""
2431                         return 1
2432                 }
2433                 $r $PERM_CMD $fsname-MDT0000.lov.stripesize=4M || {
2434                         error_noexit "Setting \"lov.stripesize\""
2435                         return 1
2436                 }
2437                 $r $PERM_CMD $fsname-MDT0000.mdd.atime_diff=70 || {
2438                         error_noexit "Setting \"mdd.atime_diff\""
2439                         return 1
2440                 }
2441         fi
2442
2443         $r $LCTL pool_new $fsname.interop || {
2444                 error_noexit "Setting \"interop\""
2445                 return 1
2446         }
2447
2448         if [ "$ff_convert" != "no" -a "$ost1_FSTYPE" == ldiskfs ]; then
2449                 echo "== ff convert ($ff_convert) =="
2450                 $r $LCTL lfsck_start -M $fsname-OST0000 || {
2451                         error_noexit "Start OI scrub on OST0"
2452                         return 1
2453                 }
2454
2455                 # The oi_scrub should be on ost1, but for test_32(),
2456                 # all on the SINGLEMDS.
2457                 wait_update_facet $SINGLEMDS "$LCTL get_param -n \
2458                         osd-ldiskfs.$fsname-OST0000.oi_scrub |
2459                         awk '/^status/ { print \\\$2 }'" "completed" 30 || {
2460                         error_noexit "Failed to get the expected 'completed'"
2461                         return 1
2462                 }
2463
2464                 local UPDATED=$($r $LCTL get_param -n \
2465                                 osd-ldiskfs.$fsname-OST0000.oi_scrub |
2466                                 awk '/^updated/ { print $2 }')
2467                 [ $UPDATED -ge 1 ] || {
2468                         error_noexit "Only $UPDATED objects have been converted"
2469                         return 1
2470                 }
2471         fi
2472
2473         if [[ "$dne_upgrade" != "no" ]] || $mdt2_is_available; then
2474                 echo "== dne upgrate ($dne_upgrade) or mdt2 available =="
2475                 if [[ $PERM_CMD =~ "set_param" ]]; then
2476                         $r $PERM_CMD mdc.$fsname-MDT0001*.import=connection=$nid || {
2477                                 error_noexit "Setting MDT1 \"failover.node\""
2478                                 return 1
2479                         }
2480
2481                         $r $PERM_CMD mdc.$fsname-MDT0001-*.max_rpcs_in_flight=9 || {
2482                                 error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
2483                                 return 1
2484                         }
2485                         $r $PERM_CMD lov.$fsname-MDT0001-*.stripesize=4M || {
2486                                 error_noexit "Setting MDT1 \"lov.stripesize\""
2487                                 return 1
2488                         }
2489                 else
2490                         $r $PERM_CMD $fsname-MDT0001.failover.node=$nid || {
2491                                 error_noexit "Setting MDT1 \"failover.node\""
2492                                 return 1
2493                         }
2494                         $r $PERM_CMD $fsname-MDT0001.mdc.max_rpcs_in_flight=9 || {
2495                                 error_noexit "Setting MDT1 \"max_rpcs_in_flight\""
2496                                 return 1
2497                         }
2498                         $r $PERM_CMD $fsname-MDT0001.lov.stripesize=4M || {
2499                                 error_noexit "Setting MDT1 \"lov.stripesize\""
2500                                 return 1
2501                         }
2502                 fi
2503         fi
2504
2505         if [ "$writeconf" ]; then
2506                 echo "== writeconf and client mount =="
2507                 $MOUNT_CMD $nid:/$fsname -o user_xattr $tmp/mnt/lustre || {
2508                         error_noexit "Mounting the client"
2509                         return 1
2510                 }
2511
2512                 shall_cleanup_lustre=true
2513                 $r $LCTL set_param debug="$PTLDEBUG"
2514
2515                 # OST pool quota #
2516                 $mdt2_is_available || pool_dir=$tmp/mnt/lustre/pool_dir
2517                 local pool_list=$pool_dir/pool_list
2518                 if (( $(version_code $img_commit) >=
2519                       $(version_code 2.13.56) )) &&
2520                    [[ "$pool_quota_upgrade" == "yes" ]] &&
2521                    [[ -s $pool_list ]]; then
2522                         local pool_name=$(head -1 $pool_list | awk '{print $2}')
2523
2524                         $r $LCTL pool_new $pool_name || {
2525                                 error_noexit "create $pool_name failed"
2526                                 return 1
2527                         }
2528
2529                         $r $LCTL pool_add $pool_name $fsname-OST[0-1/1] || {
2530                                 error_noexit "add $pool_name failed"
2531                                 return 1
2532                         }
2533
2534                         $r $LCTL pool_list $pool_name || {
2535                                 error_noexit "list $pool_name failed"
2536                                 return 1
2537                         }
2538                 fi
2539
2540                 t32_verify_quota $SINGLEMDS $fsname $tmp/mnt/lustre || {
2541                         error_noexit "verify quota failed"
2542                         return 1
2543                 }
2544
2545                 # fscrypt file data #
2546                 if ! $mdt2_is_available; then
2547                         fscrypt_data_dir=$tmp/mnt/lustre/fscrypt_data_dir
2548                         fscrypt_data_pass=$tmp/mnt/lustre/fscrypt_data_pass
2549                 fi
2550                 if (( $MDS1_VERSION >= $(version_code 2.13.55) )) &&
2551                         which fscrypt && [[ -s $fscrypt_data_pass ]]; then
2552
2553                         yes | fscrypt setup --force --verbose ||
2554                                 error "fscrypt global setup failed"
2555                         sed -i 's/\(.*\)policy_version\(.*\):\(.*\)\"[0-9]*\"\(.*\)/\1policy_version\2:\3"2"\4/' \
2556                                 /etc/fscrypt.conf
2557
2558                         local unlock_status=$(fscrypt status $fscrypt_data_dir |
2559                                               awk '/Unlocked:/{print $2}')
2560
2561                         if [[ $unlock_status == No ]]; then
2562                                 local lockedfiles=( $(find $fscrypt_data_dir/ \
2563                                                       -maxdepth 1 -type f) )
2564
2565                                 for ((i = 0; i < ${#lockedfiles[@]}; i++)); do
2566                                         ! md5sum ${lockedfiles[i]} ||
2567                                                 error "read ${lockedfiles[i]} should fail without key"
2568                                 done
2569
2570                                 ! touch $fscrypt_data_dir/nokey ||
2571                                         error "touch $fscrypt_data_dir/nokey should fail without key"
2572
2573                                 cat $fscrypt_data_pass |
2574                                 fscrypt unlock --verbose $fscrypt_data_dir ||
2575                                         error "unlock $fscrypt_data_dir failed"
2576
2577                                 for ((i = 0; i < ${#lockedfiles[@]}; i++)); do
2578                                         md5sum ${lockedfiles[i]} ||
2579                                                 error "read ${lockedfiles[i]} failed"
2580                                 done
2581                         fi
2582                 fi
2583
2584                 # fscrypt file name #
2585                 if ! $mdt2_is_available; then
2586                         fscrypt_name_dir=$tmp/mnt/lustre/fscrypt_name_dir
2587                         fscrypt_name_pass=$tmp/mnt/lustre/fscrypt_name_pass
2588                 fi
2589                 if (( $MDS1_VERSION >= $(version_code 2.14.57) )) &&
2590                         which fscrypt && [[ -s $fscrypt_name_pass ]]; then
2591
2592                         local unlock_status=$(fscrypt status $fscrypt_name_dir |
2593                                               awk '/Unlocked:/{print $2}')
2594
2595                         if [[ $unlock_status == No ]]; then
2596                                 ls -l $fscrypt_name_dir ||
2597                                         error "ls $fscrypt_name_dir failed"
2598                                 ! ls $fscrypt_name_dir/fscrypt_name_file ||
2599                                         error "ls $fscrypt_name_dir/fscrypt_name_file should fail"
2600                                 ! ls $fscrypt_name_dir/fscrypt_name_dom ||
2601                                         error "ls $fscrypt_name_dir/fscrypt_name_dom should fail"
2602
2603                                 cat $fscrypt_name_pass |
2604                                 fscrypt unlock --verbose $fscrypt_name_dir ||
2605                                         error "unlock $fscrypt_name_dir failed"
2606
2607                                 ls $fscrypt_name_dir/fscrypt_name_file ||
2608                                         error "ls $fscrypt_name_dir/fscrypt_name_file failed"
2609                                 ls $fscrypt_name_dir/fscrypt_name_dom ||
2610                                         error "ls $fscrypt_name_dir/fscrypt_name_dom failed"
2611                         fi
2612                 fi
2613
2614                 if $r test -f $tmp/list; then
2615                         echo "== list verification =="
2616                         #
2617                         # There is not a Test Framework API to copy files to or
2618                         # from a remote node.
2619                         #
2620                         # LU-2393 - do both sorts on same node to ensure locale
2621                         # is identical
2622                         local list_file=$tmp/list
2623
2624                         if $mdt2_is_available; then
2625                                 if [[ -d $tmp/mnt/lustre/striped_dir_old ]] &&
2626                                    $r test -f $tmp/list2; then
2627                                         list_file=$tmp/list2
2628                                         pushd $tmp/mnt/lustre/striped_dir_old
2629                                 else
2630                                         pushd $tmp/mnt/lustre/remote_dir
2631                                 fi
2632                         else
2633                                 pushd $tmp/mnt/lustre
2634                         fi
2635                         $r cat $list_file | sort -k 6 >$tmp/list.orig
2636                         BLOCKSIZE=1024 ls -Rni --time-style=+%s | sort -k 6 |
2637                                 sed 's/\. / /' >$tmp/list || {
2638                                 error_noexit "ls"
2639                                 return 1
2640                         }
2641                         popd
2642                         #
2643                         # 32-bit and 64-bit clients use different algorithms to
2644                         # convert FIDs into inode numbers.  Hence, remove the
2645                         # inode numbers from the lists, if the original list was
2646                         # created on an architecture with different number of
2647                         # bits per "long".
2648                         #
2649                         if [ $(t32_bits_per_long $(uname -m)) != \
2650                                 $(t32_bits_per_long $img_arch) ]; then
2651                                 echo "Different number of bits per \"long\"" \
2652                                      "from the disk image"
2653                                 for list in list.orig list; do
2654                                         sed -i -e 's/^[0-9]\+[ \t]\+//' \
2655                                                   $tmp/$list
2656                                 done
2657                         fi
2658                         if ! diff -ub $tmp/list.orig $tmp/list; then
2659                                 error_noexit "list verification failed"
2660                                 return 1
2661                         fi
2662                 else
2663                         echo "== list verification skipped =="
2664                 fi
2665
2666                 #non-dom upgrade to dom
2667                 if [ "$dom_upgrade" != "no" ]; then
2668                         echo "== dom upgrade =="
2669                         $LFS setstripe -E 1M -L mdt -E EOF $tmp/mnt/lustre/dom || {
2670                                 error_noexit "Verify DoM creation"
2671                                 return 1
2672                         }
2673                         [ $($LFS getstripe -L $tmp/mnt/lustre/dom) == "mdt" ] || {
2674                                 error_noexit "Verify a DoM file"
2675                                 return 1
2676                         }
2677                         dd if=/dev/urandom of=$tmp/mnt/lustre/dom bs=4096 \
2678                                 count=1 conv=fsync || {
2679                                 error_noexit "Cannot write to DoM file"
2680                                 return 1
2681                         }
2682                         [ $(stat -c%s $tmp/mnt/lustre/dom) == 4096 ] || {
2683                                 error_noexit "DoM: bad size after write"
2684                                 return 1
2685                         }
2686                         rm $tmp/mnt/lustre/dom
2687
2688                         set_persistent_param_and_check mds \
2689                            "lod.*MDT0000*.dom_stripesize" \
2690                            "$fsname-MDT0000.lod.dom_stripesize" 0 || {
2691                                 error_noexit "Changing \"dom_stripesize\""
2692                                 return 1
2693                         }
2694                 fi
2695
2696                 #dom upgrade
2697                 #$LFS setstripe -E 1M -L mdt -E -1 -S 4M $dom_file
2698                 if [ "$dom_new_upgrade" != "no" ]; then
2699                         if ! $mdt2_is_available; then
2700                                 dom_file=$tmp/mnt/lustre/dom_dir/dom_file
2701                         fi
2702                         echo "== check DoM file can be accessed =="
2703                         [ $($LFS getstripe -I1 -L $dom_file) == "mdt" ] || {
2704                                 error_noexit "Verify a DoM file"
2705                                 return 1
2706                         }
2707                         [ $(stat -c%s $dom_file) == $((2 * 1024 * 1024)) ] || {
2708                                 error_noexit "DoM: bad size after write"
2709                                 return 1
2710                         }
2711                 fi
2712
2713                 if [ "$flr_upgrade" != "no" ]; then
2714                         if ! $mdt2_is_available; then
2715                                 flr_file=$tmp/mnt/lustre/flr_dir/flr_file
2716                         fi
2717                         local mirror_count=$($LFS getstripe -N $flr_file)
2718                         echo "== check FLR file =="
2719                         [ $mirror_count == 2 ] || {
2720                                 error_noexit "FLR mirror count wrong"
2721                                 return 1
2722                         }
2723                 fi
2724
2725                 if [ "$dne_upgrade" != "no" ]; then
2726                         echo "== dne upgrade striped_dir  =="
2727                         $LFS mkdir -i 1 -c2 $tmp/mnt/lustre/striped_dir || {
2728                                 error_noexit "set striped dir failed"
2729                                 return 1
2730                         }
2731                         $LFS setdirstripe -D -c2 $tmp/mnt/lustre/striped_dir
2732
2733                         pushd $tmp/mnt/lustre
2734                         tar -c --exclude=./striped_dir \
2735                                 --exclude=./striped_dir_old \
2736                                 --exclude=./remote_dir -f - .|
2737                                 tar -xvf - -C striped_dir 1>/dev/null || {
2738                                 error_noexit "cp to striped dir failed"
2739                                 return 1
2740                         }
2741                         popd
2742                 fi
2743
2744                 if [ "$pfl_upgrade" != "no" ]; then
2745                         local comp_size
2746                         local comp_cnt
2747                         local stripe_size
2748                         local stripe_cnt
2749                         local comp_id
2750
2751                         echo "== check PFL file =="
2752                         if ! $mdt2_is_available; then
2753                                 pfl_file=$tmp/mnt/lustre/pfl_dir/pfl_file
2754                         fi
2755                         comp_cnt=$($LFS getstripe --component-count $pfl_file)
2756                         [ $comp_cnt == 2 ] || {
2757                                 error_noexit "wrong comp_cnt $comp_cnt"
2758                                 return 1
2759                         }
2760
2761                         comp_size=$($LFS getstripe -I1 -E $pfl_file)
2762                         [ $comp_size == 2097152 ] || {
2763                                 error_noexit "wrong component size $comp_size"
2764                                 return 1
2765                         }
2766
2767                         comp_id=$($LFS getstripe -I1 -i $pfl_file)
2768                         [ $comp_id == 0 ] || {
2769                                 error_noexit "wrong comp id $comp_id"
2770                                 return 1
2771                         }
2772
2773                         comp_id=$($LFS getstripe -I2 -i $pfl_file)
2774                         [ $comp_id -eq 1 ] || {
2775                                 error_noexit "wrong comp id $comp_id"
2776                                 return 1
2777                         }
2778
2779                         stripe_size=$($LFS getstripe -I1 -S $pfl_file)
2780                         [ $stripe_size -eq 1048576 ] || {
2781                                 error_noexit "wrong stripe size $stripe_size"
2782                                 return 1
2783                         }
2784
2785                         stripe_size=$($LFS getstripe -I2 -S $pfl_file)
2786                         [ $comp_size -eq 2097152 ] || {
2787                                 error_noexit "wrong component size $comp_size"
2788                                 return 1
2789                         }
2790                 fi
2791
2792                 local large_xattr_dir=$tmp/mnt/lustre/large_xattr_test_dir
2793
2794                 if [[ -d $large_xattr_dir ]]; then
2795                         echo "== check Large EA =="
2796                         local xattr_file=$large_xattr_dir/large_xattr_file
2797
2798                         xattr_val=$(getfattr --only-values\
2799                                 -n user.fooattr $xattr_file) || {
2800                                 error_noexit "Large EA cannot be read"
2801                                 return 1
2802                         }
2803
2804                         [[ $xattr_val == $(printf "%c" {1..4096}) ]] || {
2805                                 error_noexit "Wrong large EA value"
2806                                 return 1;
2807                         }
2808                 fi
2809
2810                 if [ "$project_quota_upgrade" != "no" ]; then
2811                         if ! $mdt2_is_available; then
2812                                 quota_dir=$tmp/mnt/lustre/project_quota_dir
2813                         fi
2814                         local hardlimit
2815
2816                         echo "== check Project Quota =="
2817                         hardlimit=$(get_project_quota -p $T32_PRJID global 3 \
2818                                                         ${tmp}/mnt/lustre)
2819                         [ $hardlimit == $T32_PROLIMIT ] || {
2820                                 error_noexit "wrong hardlimit $hardlimit"
2821                                 return 1
2822                         }
2823                 fi
2824
2825                 # OST pool #
2826                 $mdt2_is_available || pool_dir=$tmp/mnt/lustre/pool_dir
2827                 local pool_list=$pool_dir/pool_list
2828                 local pool_file=$pool_dir/pool_file
2829                 if (( $(version_code $img_commit) >=
2830                       $(version_code 2.13.56) )) &&
2831                    [[ "$pool_quota_upgrade" == "yes" ]] &&
2832                    [[ -s $pool_list ]]; then
2833                         local pool_name=$(head -1 $pool_list | awk '{print $2}')
2834                         local act_pool_list=$tmp/pool_list
2835
2836                         $r "$LCTL pool_list $pool_name" > $act_pool_list || {
2837                                 rm -f $act_pool_list
2838                                 error_noexit "pool_list $pool_name failed"
2839                                 return 1
2840                         }
2841
2842                         cmp --verbose $pool_list $act_pool_list || {
2843                                 rm -f $act_pool_list
2844                                 error_noexit "OST pool list, act:$act_pool_list, exp:$pool_list"
2845                                 return 1
2846                         }
2847                         rm -f $act_pool_list
2848
2849                         local exp_qpool=${pool_name##$fsname.}
2850                         local act_qpool=$($LFS getstripe -p $pool_file)
2851                         [[ -n "$act_qpool" ]] || {
2852                                 error_noexit "no OST pool on $pool_file"
2853                                 return 1
2854                         }
2855
2856                         [[ "$act_qpool" == "$exp_qpool" ]] || {
2857                                 error_noexit "OST pool name, act:$act_qpool, exp:$exp_qpool"
2858                                 return 1
2859                         }
2860                 fi
2861
2862                 # If it is upgrade from DNE (2.5), then rename the remote dir,
2863                 # which is created in 2.5 to striped dir.
2864                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]]; then
2865                         echo "== rename remote_dir =="
2866                         stripe_index=$($LFS getdirstripe -i     \
2867                                        $tmp/mnt/lustre/remote_dir)
2868
2869                         [[ $stripe_index -eq 1 ]] || {
2870                                 error_noexit "get index \"$stripe_index\"" \
2871                                              "from remote dir failed"
2872                                 return 1
2873                         }
2874                         mv $tmp/mnt/lustre/remote_dir   \
2875                                 $tmp/mnt/lustre/striped_dir/ || {
2876                                 error_noexit "mv remote dir failed"
2877                                 return 1
2878                         }
2879                 fi
2880
2881                 # If it is upgraded from DNE (2.7), then move the striped dir
2882                 # which was created in 2.7 to the new striped dir.
2883                 if $mdt2_is_available && [[ "$dne_upgrade" != "no" ]] &&
2884                         echo "== rename striped dir =="
2885                         [[ -d $tmp/mnt/lustre/striped_dir_old ]]; then
2886                         stripe_count=$($LFS getdirstripe -c     \
2887                                        $tmp/mnt/lustre/striped_dir_old)
2888                         [[ $stripe_count -eq 2 ]] || {
2889                                 error_noexit "get count $stripe_count" \
2890                                              "from striped dir failed"
2891                                 return 1
2892                         }
2893                         mv $tmp/mnt/lustre/striped_dir_old      \
2894                                 $tmp/mnt/lustre/striped_dir/ || {
2895                                 error_noexit "mv striped dir failed"
2896                                 return 1
2897                         }
2898                 fi
2899
2900                 sync; sleep 5; sync
2901                 $r $LCTL set_param -n osd*.*.force_sync=1
2902                 dd if=/dev/zero of=$tmp/mnt/lustre/tmp_file bs=10k count=10 || {
2903                         error_noexit "dd failed"
2904                         return 1
2905                 }
2906                 rm -rf $tmp/mnt/lustre/tmp_file || {
2907                         error_noexit "rm failed"
2908                         return 1
2909                 }
2910
2911                 if $r test -f $tmp/sha1sums; then
2912                         echo "== checking sha1sums =="
2913                         # LU-2393 - do both sorts on same node to ensure locale
2914                         # is identical
2915                         $r cat $tmp/sha1sums | sort -k 2 >$tmp/sha1sums.orig
2916                         which fscrypt ||
2917                                 sed -i '/fscrypt_.*_dir/d' $tmp/sha1sums.orig
2918                         if [[ "$dne_upgrade" != "no" ]]; then
2919                                 if [[ -d $tmp/mnt/lustre/striped_dir/remote_dir ]]; then
2920                                         pushd $tmp/mnt/lustre/striped_dir/remote_dir
2921                                 else
2922                                         pushd $tmp/mnt/lustre/striped_dir
2923                                 fi
2924                         elif [[ "$pfl_upgrade" != "no" ]] ||
2925                                 [[ "$flr_upgrade" != "no" ]] ||
2926                                 [[ "$dom_new_upgrade" != "no" ]] ||
2927                                 [[ "$project_quota_upgrade" != "no" ]] ||
2928                                 [[ -d $tmp/mnt/lustre/remote_dir ]]; then
2929                                 pushd $tmp/mnt/lustre/remote_dir
2930                         else
2931                                 pushd $tmp/mnt/lustre
2932                         fi
2933
2934                         find ! -path "*remote_dir*" ! -path "*striped_dir*" \
2935                              ! -name .lustre -type f -exec sha1sum {} \; |
2936                                 sort -k 2 >$tmp/sha1sums || {
2937                                 popd
2938                                 error_noexit "sha1sum"
2939                                 return 1
2940                         }
2941                         local save=$PWD
2942
2943                         popd
2944                         if ! diff -ub $tmp/sha1sums.orig $tmp/sha1sums; then
2945                                 echo "==** find $save files start **=="
2946                                 find $save -type f -ls
2947                                 echo "==** find $save files finish **=="
2948                                 error_noexit "sha1sum verification failed"
2949                                 return 1
2950                         fi
2951
2952                         # if upgrade from DNE(2.5), then check remote directory
2953                         # if upgrade from DNE(2.7), then check striped directory
2954                         if $mdt2_is_available &&
2955                            [[ "$dne_upgrade" != "no" ]]; then
2956                                 echo "== mdt2 upgrade sha1sum check =="
2957                                 local new_dir="$tmp/mnt/lustre/striped_dir"
2958                                 local striped_dir_old="$new_dir/striped_dir_old"
2959
2960                                 local dir_list="$new_dir/remote_dir"
2961                                 [[ ! -d $triped_dir_old ]] ||
2962                                         dir_list+=" $striped_dir_old"
2963
2964                                 for dir in $dir_list; do
2965                                         echo "== dir = $dir =="
2966                                         pushd $dir
2967                                         find ! -name .lustre -type f \
2968                                                 -exec sha1sum {} \; |
2969                                                 sort -k 2 >$tmp/sha1sums || {
2970                                                         ls -alR
2971                                                         popd
2972                                                         error_noexit "sha1sum"
2973                                                         return 1
2974                                                 }
2975                                         popd
2976                                         if ! diff -ub $tmp/sha1sums.orig \
2977                                                 $tmp/sha1sums; then
2978                                                 ls -alR $dir
2979                                                 error_noexit "sha1sum $dir" \
2980                                                              "failed"
2981                                                 return 1
2982                                         fi
2983                                 done
2984                         fi
2985                 else
2986                         echo "== sha1sum verification skipped =="
2987                 fi
2988
2989                 # PFL write test after sha1sum check
2990                 if [ "$pfl_upgrade" != "no" ]; then
2991                         local rw_len=$((3 * 1034 * 1024))
2992
2993                         if ! $mdt2_is_available; then
2994                                 pfl_file=$tmp/mnt/lustre/pfl_dir/pfl_file
2995                         fi
2996                         small_write $pfl_file $rw_len || {
2997                                 error_noexit "PFL RW Failed"
2998                                 return 1
2999                         }
3000                 fi
3001
3002                 if [ "$dne_upgrade" != "no" ]; then
3003                         rm -rf $tmp/mnt/lustre/striped_dir || {
3004                                 error_noexit "remove remote dir failed"
3005                                 return 1
3006                         }
3007                 fi
3008
3009                 # migrate files/dirs to remote MDT, then move them back
3010                 if [ "$MDS1_VERSION" -ge $(version_code 2.7.50) -a \
3011                      $dne_upgrade != "no" ]; then
3012                         $r $LCTL set_param -n   \
3013                                 mdt.${fsname}*.enable_remote_dir=1 2>/dev/null
3014
3015                         echo "== test migration =="
3016                         pushd $tmp/mnt/lustre
3017                         for dir in $(find ! -name .lustre ! -name . -type d); do
3018                                 mdt_index=$($LFS getdirstripe -i $dir)
3019                                 stripe_cnt=$($LFS getdirstripe -c $dir)
3020                                 if [ $mdt_index = 0 -a $stripe_cnt -le 1 ]; then
3021                                         $LFS migrate -m 1 $dir || {
3022                                         popd
3023                                         error_noexit "migrate MDT1 failed"
3024                                         return 1
3025                                 }
3026                                 fi
3027                         done
3028
3029                         for dir in $(find ! -name . ! -name .lustre -type d); do
3030                                 mdt_index=$($LFS getdirstripe -i $dir)
3031                                 stripe_cnt=$($LFS getdirstripe -c $dir)
3032                                 if [ $mdt_index = 1 -a $stripe_cnt -le 1 ]; then
3033                                         $LFS migrate -m 0 $dir || {
3034                                         popd
3035                                         error_noexit "migrate MDT0 failed"
3036                                         return 1
3037                                 }
3038                                 fi
3039                         done
3040                         popd
3041                 fi
3042
3043                 #
3044                 # When adding new data verification tests, please check for
3045                 # the presence of the required reference files first, like
3046                 # the "sha1sums" and "list" tests above, to avoid the need to
3047                 # regenerate every image for each test addition.
3048                 #
3049
3050                 nrpcs_orig=$($LCTL get_param \
3051                                 -n mdc.*MDT0000*.max_rpcs_in_flight) || {
3052                         error_noexit "Getting \"max_rpcs_in_flight\""
3053                         return 1
3054                 }
3055                 nrpcs=$((nrpcs_orig + 5))
3056
3057                 set_persistent_param_and_check client \
3058                    "mdc.$fsname-MDT0000*.max_rpcs_in_flight" \
3059                    "$fsname-MDT0000.mdc.max_rpcs_in_flight" $nrpcs || {
3060                         error_noexit "Changing \"max_rpcs_in_flight\""
3061                         return 1
3062                 }
3063
3064                 umount $tmp/mnt/lustre || {
3065                         error_noexit "Unmounting the client"
3066                         return 1
3067                 }
3068                 shall_cleanup_lustre=false
3069         else
3070                 $MOUNT_CMD $nid:/$fsname $tmp/mnt/lustre || {
3071                         error_noexit "Mounting the client"
3072                         return 1
3073                 }
3074
3075                 if [ "$mds1_FSTYPE" == ldiskfs -a \
3076                     "$project_upgrade" != "no" ]; then
3077                         ! $LFS project -d -p 1 $tmp/mnt/lustre/* &&
3078                                 error_noexit "set project failed" &&
3079                                         return 1
3080                 fi
3081
3082                 wait_update_facet mds1 "pgrep orph_.*-MDD | wc -l" "0" ||
3083                         error "MDD orphan cleanup thread not quit"
3084
3085                 umount $tmp/mnt/lustre || {
3086                         error_noexit "Unmounting the client"
3087                         return 1
3088                 }
3089
3090                 if [[ "$dne_upgrade" != "no" ]] || $mdt2_is_available; then
3091                         $r $UMOUNT $tmp/mnt/mdt1 || {
3092                                 error_noexit "Unmounting the MDT2"
3093                                 return 1
3094                         }
3095                         if [[ "$mds1_FSTYPE" == zfs ]]; then
3096                             $r "$ZPOOL export t32fs-mdt2"
3097                         fi
3098                         shall_cleanup_mdt1=false
3099                 fi
3100
3101                 $r $UMOUNT $tmp/mnt/mdt || {
3102                         error_noexit "Unmounting the MDT"
3103                         return 1
3104                 }
3105                 if [[ "$mds1_FSTYPE" == zfs ]]; then
3106                     $r "$ZPOOL export t32fs-mdt1"
3107                 fi
3108                 shall_cleanup_mdt=false
3109
3110                 $r $UMOUNT $tmp/mnt/ost || {
3111                         error_noexit "Unmounting the OST"
3112                         return 1
3113                 }
3114                 if $ost2_is_available; then
3115                         $r $UMOUNT $tmp/mnt/ost1 || {
3116                                 error_noexit "Unmounting the OST1"
3117                                 return 1
3118                         }
3119                         shall_cleanup_ost1=false
3120                 fi
3121
3122                 if [[ $ost1_FSTYPE == zfs ]]; then
3123                         $r "$ZPOOL export t32fs-ost1"
3124                         if $ost2_is_available; then
3125                                 $r "$ZPOOL export t32fs-ost2"
3126                         fi
3127                 fi
3128                 shall_cleanup_ost=false
3129
3130                 t32_reload_modules $node || {
3131                         error_noexit "Reloading modules"
3132                         return 1
3133                 }
3134
3135                 if [[ "$mds1_FSTYPE" == zfs ]]; then
3136                         local poolname=t32fs-mdt1
3137                         $r "modprobe zfs;
3138                             $ZPOOL list -H $poolname >/dev/null 2>&1 ||
3139                                 $ZPOOL import -f -d $tmp $poolname"
3140
3141                         # upgrade zpool to latest supported features,
3142                         # including dnode quota accounting in 0.7.0
3143                         $r "$ZPOOL upgrade $poolname"
3144                 fi
3145
3146                 # mount a second time to make sure we didnt leave upgrade flag on
3147                 $r $TUNEFS --dryrun $mdt_dev || {
3148                         $r losetup -a
3149                         error_noexit "tunefs.lustre before remounting the MDT"
3150                         return 1
3151                 }
3152
3153                 mopts=exclude=$fsname-OST0000
3154                 if [ "$mds1_FSTYPE" == ldiskfs ]; then
3155                         mopts="loop,$mopts"
3156                 fi
3157                 $r $MOUNT_CMD -o $mopts $mdt_dev $tmp/mnt/mdt || {
3158                         error_noexit "Remounting the MDT"
3159                         return 1
3160                 }
3161                 shall_cleanup_mdt=true
3162         fi
3163 }
3164
3165 test_32a() {
3166         local tarballs
3167         local tarball
3168         local rc=0
3169
3170         t32_check
3171         for tarball in $tarballs; do
3172                 banner "testing $tarball upgrade"
3173                 t32_test $tarball || let "rc += $?"
3174         done
3175         return $rc
3176 }
3177 run_test 32a "Upgrade (not live)"
3178
3179 test_32b() {
3180         local tarballs
3181         local tarball
3182         local rc=0
3183
3184         t32_check
3185         for tarball in $tarballs; do
3186                 banner "testing $tarball upgrade with writeconf"
3187                 t32_test $tarball writeconf || let "rc += $?"
3188         done
3189         return $rc
3190 }
3191 run_test 32b "Upgrade with writeconf"
3192
3193 test_32c() {
3194         local tarballs
3195         local tarball
3196         local rc=0
3197
3198         t32_check
3199         for tarball in $tarballs; do
3200                 banner "testing $tarball upgrade with DNE"
3201                 load_modules
3202                 dne_upgrade=yes t32_test $tarball writeconf || rc=$?
3203         done
3204         return $rc
3205 }
3206 run_test 32c "dne upgrade test"
3207
3208 test_32d() {
3209         local tarballs
3210         local tarball
3211         local rc=0
3212
3213         t32_check
3214         for tarball in $tarballs; do
3215                 banner "testing $tarball with filter_fid upgrade"
3216                 ff_convert=yes t32_test $tarball || rc=$?
3217         done
3218         return $rc
3219 }
3220 run_test 32d "convert filter_fid upgrade test"
3221
3222 test_32e() {
3223         [[ "$MDS1_VERSION" -ge $(version_code 2.10.56) ]] ||
3224                 skip "Need MDS version at least 2.10.56"
3225
3226         local tarballs
3227         local tarball
3228         local rc=0
3229
3230         t32_check
3231         for tarball in $tarballs; do
3232                 [[ "$tarball" =~ "2_9" ]] ||
3233                         { echo "skip $(basename $tarball)"; continue; }
3234                 #load_modules
3235                 banner "testing $tarball upgrade with DoM"
3236                 dom_upgrade=yes t32_test $tarball writeconf || let "rc += $?"
3237         done
3238         return $rc
3239 }
3240 run_test 32e "dom upgrade test"
3241
3242 test_32f() {
3243         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
3244                 skip "Need MDS version at least 2.10.56"
3245
3246         local tarballs
3247         local tarball
3248         local rc=0
3249
3250         t32_check
3251         for tarball in $tarballs; do
3252                 [[ "$tarball" =~ "2_10" ]] ||
3253                         { echo "skip $(basename $tarball)"; continue; }
3254                 pfl_upgrade=yes project_quota_upgrade=yes \
3255                 t32_test $tarball writeconf || let "rc += $?"
3256         done
3257         return $rc
3258 }
3259 run_test 32f "pfl upgrade test"
3260
3261 test_32g() {
3262         [[ $MDS1_VERSION -ge $(version_code 2.10.56) ]] ||
3263                 skip "Need MDS version at least 2.10.56"
3264
3265         local tarballs
3266         local tarball
3267         local rc=0
3268
3269         t32_check
3270         for tarball in $tarballs; do
3271                 [[ $tarball =~ "2_12" ]] ||
3272                         { echo "skip $(basename $tarball)"; continue; }
3273                 flr_upgrade=yes dom_new_upgrade=yes \
3274                 t32_test $tarball writeconf || let "rc += $?"
3275         done
3276         return $rc
3277 }
3278 run_test 32g "flr/dom upgrade test"
3279
3280 test_32h() {
3281         (( $MDS1_VERSION >= $(version_code 2.13.56) )) ||
3282                 skip "Need MDS >= 2.13.56 for OST pool quotas"
3283
3284         local tarballs
3285         local tarball
3286         local rc=0
3287
3288         t32_check
3289         for tarball in $tarballs; do
3290                 [[ $tarball =~ "2_15" ]] ||
3291                         { echo "skip $(basename $tarball)"; continue; }
3292                 pool_quota_upgrade=yes t32_test $tarball writeconf ||
3293                         let "rc += $?"
3294         done
3295         return $rc
3296 }
3297 run_test 32h "pool quota upgrade test"
3298
3299 test_32i() {
3300         (( $MDS1_VERSION >= $(version_code 2.13.55) )) ||
3301                 skip "Need MDS >= 2.13.55 for fscrypt data encryption"
3302
3303         local tarballs
3304         local tarball
3305         local rc=0
3306
3307         t32_check
3308         for tarball in $tarballs; do
3309                 [[ $tarball =~ "2_15" && $tarball =~ "ldiskfs" ]] ||
3310                         { echo "skip $(basename $tarball)"; continue; }
3311                 fscrypt_data_upgrade=yes t32_test $tarball writeconf ||
3312                         let "rc += $?"
3313         done
3314         return $rc
3315 }
3316 run_test 32i "fscrypt data encryption upgrade test"
3317
3318 test_32j() {
3319         (( $MDS1_VERSION >= $(version_code 2.14.57) )) ||
3320                 skip "Need MDS >= 2.14.56 for fscrypt filename encryption"
3321
3322         local tarballs
3323         local tarball
3324         local rc=0
3325
3326         t32_check
3327         for tarball in $tarballs; do
3328                 [[ $tarball =~ "2_15" && $tarball =~ "ldiskfs" ]] ||
3329                         { echo "skip $(basename $tarball)"; continue; }
3330                 fscrypt_name_upgrade=yes t32_test $tarball writeconf ||
3331                         let "rc += $?"
3332         done
3333         return $rc
3334 }
3335 run_test 32j "fscrypt filename encryption upgrade test"
3336
3337 test_33a() { # bug 12333, was test_33
3338         local FSNAME2=test-$testnum
3339
3340         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
3341         local mkfsoptions
3342
3343         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
3344
3345         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" ]; then
3346                 local dev=${SINGLEMDS}_dev
3347                 local MDSDEV=${!dev}
3348
3349                 is_blkdev $SINGLEMDS $MDSDEV &&
3350                         skip_env "mixed loopback and real device not working"
3351         fi
3352
3353         local fs2mdsdev=$(mdsdevname 1_2)
3354         local fs2ostdev=$(ostdevname 1_2)
3355         local fs2mdsvdev=$(mdsvdevname 1_2)
3356         local fs2ostvdev=$(ostvdevname 1_2)
3357
3358         if [ "$mds1_FSTYPE" == ldiskfs ]; then
3359                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
3360         fi
3361
3362         if combined_mgs_mds; then
3363                 local mgs_flag="--mgs"
3364         fi
3365
3366         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --fsname=${FSNAME2} \
3367                 --reformat $mgs_flag $mkfsoptions $fs2mdsdev $fs2mdsvdev ||
3368                 exit 10
3369         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
3370                 --fsname=${FSNAME2} --index=0x1fff --reformat $fs2ostdev \
3371                 $fs2ostvdev || exit 10
3372
3373         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT
3374         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
3375
3376         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3377                 do_facet mgs "$PERM_CMD timeout=200" ||
3378                         error "$PERM_CMD timeout=200 failed"
3379         else
3380                 do_facet mgs "$PERM_CMD $FSNAME2.sys.timeout=200" ||
3381                         error "$PERM_CMD $FSNAME2.sys.timeout=200 failed"
3382         fi
3383         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
3384         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
3385         echo "ok."
3386
3387         cp /etc/hosts $MOUNT2/ || error "copy /etc/hosts $MOUNT2/ failed"
3388         $LFS getstripe $MOUNT2/hosts ||
3389                 error "$LFS getstripe $MOUNT2/hosts failed"
3390
3391         umount $MOUNT2
3392
3393         if (( "$MGS_VERSION" >= $(version_code 2.15.51) &&
3394               "$MDS1_VERSION" >= $(version_code 2.15.51) )); then
3395                 # test lctl del_ost on large index
3396                 do_facet mgs "$LCTL del_ost -t ${FSNAME2}-OST1fff" ||
3397                         error "del_ost failed with $?"
3398                 $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 ||
3399                         error "$MOUNT_CMD failed"
3400                 echo "ok."
3401                 $LFS df | grep -q OST1fff &&
3402                         error "del_ost did not remove OST1fff!"
3403                 umount $MOUNT2
3404         fi
3405
3406         stop fs2ost -f
3407         stop fs2mds -f
3408         cleanup_nocli || error "cleanup_nocli failed with $?"
3409 }
3410 run_test 33a "Mount ost with a large index number"
3411
3412 test_33b() {    # was test_34
3413         setup
3414
3415         do_facet client dd if=/dev/zero of=$MOUNT/24 bs=1024k count=1
3416         # Drop lock cancelation reply during umount
3417         #define OBD_FAIL_LDLM_CANCEL_NET                        0x304
3418         do_facet client $LCTL set_param fail_loc=0x80000304
3419         #lctl set_param debug=-1
3420         umount_client $MOUNT
3421         cleanup || error "cleanup failed with $?"
3422 }
3423 run_test 33b "Drop cancel during umount"
3424
3425 test_33c() {
3426         (( MDS1_VERSION >= $(version_code 2.15.57) )) ||
3427                 skip "Need MDS version at least 2.15.57"
3428         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
3429         local tstid=${TSTID:-"$(id -u $TSTUSR)"}
3430         local mkfsoptions
3431         local qpool="qpool1"
3432
3433         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST
3434
3435         local fs2mdsdev=$(mdsdevname 1_2)
3436         local fs2ostdev=$(ostdevname 1_2)
3437         local fs2mdsvdev=$(mdsvdevname 1_2)
3438         local fs2ostvdev=$(ostvdevname 1_2)
3439
3440         if [ "$mds1_FSTYPE" == ldiskfs ]; then
3441                 mkfsoptions="--mkfsoptions=\\\"-J size=8\\\"" # See bug 17931.
3442         fi
3443
3444         if combined_mgs_mds; then
3445                 local mgs_flag="--mgs"
3446         fi
3447
3448         load_modules
3449         stack_trap unload_modules_conf
3450
3451         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --fsname=${FSNAME} \
3452                 --reformat $mgs_flag $mkfsoptions $fs2mdsdev $fs2mdsvdev ||
3453                 exit 10
3454         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
3455                 --fsname=${FSNAME} --index=0x7c6 --reformat $fs2ostdev \
3456                 $fs2ostvdev || exit 10
3457
3458
3459         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
3460         stack_trap "stop fs2mds -f"
3461         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
3462         stack_trap "stop fs2ost -f"
3463
3464         mount_client $MOUNT || error "client start failed"
3465         stack_trap "umount_client $MOUNT"
3466         mkdir_on_mdt0 $DIR/$tdir || error "cannot create $DIR/$tdir"
3467         chmod 0777 $DIR/$tdir || error "chown failed"
3468         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3469                 do_facet mgs $PERM_CMD \
3470                         osd-*.$FSNAME-OST*.quota_slave.enable=$QUOTA_TYPE
3471         else
3472                 do_facet mgs $PERM_CMD $FSNAME.quota.ost=$QUOTA_TYPE ||
3473                         error "set ost quota type failed"
3474         fi
3475
3476         local old_MDSCOUNT=$MDSCOUNT
3477         MDSCOUNT=1
3478         stack_trap "MDSCOUNT=$old_MDSCOUNT"
3479
3480         pool_add $qpool || error "pool_add failed"
3481         pool_add_targets $qpool 0x7c6
3482
3483         $LFS setquota -u $tstid -B20M -b 0 $MOUNT
3484         $LFS setquota -g $tstid -B20M -b 0 $MOUNT
3485         $LFS setquota -u $tstid -B20M -b 0 --pool $qpool $MOUNT
3486         $LFS setquota -g $tstid -B20M -b 0 --pool $qpool $MOUNT
3487
3488         for i in {1..10}; do
3489                 runas -u $tstid -g $tstid dd if=/dev/zero of=$DIR/$tdir/f1 \
3490                         bs=1M count=30 oflag=direct
3491                 sleep 3
3492                 rm -f $DIR/$tdir/f1
3493         done
3494
3495         destroy_pools
3496         #umount_client $MOUNT || error "client start failed"
3497         #stop fs2ost -f
3498         #stop fs2mds -f
3499         #cleanup_nocli || error "cleanup_nocli failed with $?"
3500 }
3501 run_test 33c "Mount ost with a large index number"
3502
3503 test_33d() {
3504         setup
3505         stack_trap cleanup
3506
3507         mkdir_on_mdt0 $DIR/$tdir || error "cannot create $DIR/$tdir"
3508         touch $DIR/$tfile
3509         $LFS setquota -p 1 -I1K $MOUNT
3510
3511         do_facet mgs $LCTL set_param osd*.*.quota_slave.enabled=p
3512         $LFS project -p 1 $DIR/
3513 }
3514 run_test 33d "Don't panic when enable project quota"
3515
3516 test_34a() {
3517         setup
3518         do_facet client "bash runmultiop_bg_pause $DIR/file O_c"
3519         manual_umount_client
3520         rc=$?
3521         do_facet client killall -USR1 multiop
3522         if [ $rc -eq 0 ]; then
3523                 error "umount not fail!"
3524         fi
3525         sleep 1
3526         cleanup || error "cleanup failed with rc $?"
3527 }
3528 run_test 34a "umount with opened file should be fail"
3529
3530 test_34b() {
3531         setup
3532         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3533         stop_mds || error "Unable to stop MDS"
3534
3535         manual_umount_client --force || error "mtab after failed umount with $?"
3536
3537         cleanup || error "cleanup failed with $?"
3538 }
3539 run_test 34b "force umount with failed mds should be normal"
3540
3541 test_34c() {
3542         setup
3543         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
3544         stop_ost || error "Unable to stop OST1"
3545
3546         manual_umount_client --force || error "mtab after failed umount with $?"
3547
3548         cleanup || error "cleanup failed with $?"
3549 }
3550 run_test 34c "force umount with failed ost should be normal"
3551
3552 test_35a() { # bug 12459
3553         setup
3554
3555         DBG_SAVE="`$LCTL get_param -n debug`"
3556         $LCTL set_param debug="ha"
3557
3558         log "Set up a fake failnode for the MDS"
3559         FAKENID="127.0.0.2"
3560         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
3561                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
3562
3563         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3564                 do_facet mgs "$PERM_CMD \
3565                               mdc.*${device}*.import=connection=$(h2nettype $FAKENID)" ||
3566                         error "Setting mdc.*${device}*.import=connection=\
3567                                $(h2nettype $FAKENID) failed."
3568         else
3569                 do_facet mgs "$PERM_CMD \
3570                               ${device}.failover.node=$(h2nettype $FAKENID)" ||
3571                         error "Setting ${device}.failover.node=\
3572                                $(h2nettype $FAKENID) failed."
3573         fi
3574         log "Wait for RECONNECT_INTERVAL seconds (10s)"
3575         sleep 10
3576
3577         MSG="conf-sanity.sh test_35a `date +%F%kh%Mm%Ss`"
3578         $LCTL clear
3579         log "$MSG"
3580         log "Stopping the MDT: $device"
3581         stop_mdt 1 || error "MDT0 stop fail"
3582
3583         df $MOUNT > /dev/null 2>&1 &
3584         DFPID=$!
3585         log "Restarting the MDT: $device"
3586         start_mdt 1 || error "MDT0 start fail"
3587         log "Wait for df ($DFPID) ... "
3588         wait $DFPID
3589         log "done"
3590         $LCTL set_param debug="$DBG_SAVE"
3591
3592         # retrieve from the log the first server that the client tried to
3593         # contact after the connection loss
3594         $LCTL dk $TMP/lustre-log-$TESTNAME.log
3595         NEXTCONN=`awk "/${MSG}/ {start = 1;}
3596                        /import_select_connection.*$device-mdc.* using connection/ {
3597                                 if (start) {
3598                                         if (\\\$NF ~ /$FAKENID/)
3599                                                 print \\\$NF;
3600                                         else
3601                                                 print 0;
3602                                         exit;
3603                                 }
3604                        }" $TMP/lustre-log-$TESTNAME.log`
3605         [ "$NEXTCONN" != "0" ] &&
3606                 error "Tried to connect to ${NEXTCONN} not last active server"
3607         cleanup || error "cleanup failed with $?"
3608         # remove nid settings
3609         writeconf_or_reformat
3610 }
3611 run_test 35a "Reconnect to the last active server first"
3612
3613 test_35b() { # bug 18674
3614         remote_mds || skip "local MDS"
3615         setup
3616
3617         debugsave
3618         $LCTL set_param debug="ha"
3619         $LCTL clear
3620         MSG="conf-sanity.sh test_35b `date +%F%kh%Mm%Ss`"
3621         log "$MSG"
3622
3623         log "Set up a fake failnode for the MDS"
3624         FAKENID="127.0.0.2"
3625         local device=$(do_facet $SINGLEMDS "$LCTL get_param -n devices" |
3626                 awk '($3 ~ "mdt" && $4 ~ "MDT") { print $4 }' | head -1)
3627
3628         if [[ $PERM_CMD == *"set_param -P"* ]]; then
3629                 do_facet mgs "$PERM_CMD \
3630                               mdc.*${device}*.import=connection=$(h2nettype $FAKENID)" ||
3631                         error "Set mdc.*${device}*.import=connection=\
3632                                $(h2nettype $FAKENID) failed"
3633         else
3634                 do_facet mgs "$PERM_CMD \
3635                               ${device}.failover.node=$(h2nettype $FAKENID)" ||
3636                         error "Set ${device}.failover.node=\
3637                                $(h2nettype $FAKENID) failed"
3638         fi
3639
3640         local at_max_saved=0
3641         # adaptive timeouts may prevent seeing the issue
3642         if at_is_enabled; then
3643                 at_max_saved=$(at_max_get mds)
3644                 at_max_set 0 mds client
3645         fi
3646
3647         rm -rf $MOUNT/$tdir
3648         mkdir_on_mdt0 $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
3649
3650         log "Injecting EBUSY on MDS"
3651         # Setting OBD_FAIL_MDS_RESEND=0x136
3652         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000136" ||
3653                 error "unable to set param fail_loc=0x80000136"
3654
3655         $LCTL set_param mdc.${FSNAME}*.stats=clear
3656
3657         log "Creating a test file and stat it"
3658         touch $MOUNT/$tdir/$tfile || error "touch $MOUNT/$tdir/$tfile failed"
3659         stat $MOUNT/$tdir/$tfile
3660
3661         log "Stop injecting EBUSY on MDS"
3662         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0" ||
3663                 error "unable to set param fail_loc=0"
3664         rm -f $MOUNT/$tdir/$tfile || error "remove $MOUNT/$tdir/$tfile failed"
3665
3666         log "done"
3667         # restore adaptive timeout
3668         [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds client
3669
3670         $LCTL dk $TMP/lustre-log-$TESTNAME.log
3671
3672         CONNCNT=$($LCTL get_param mdc.${FSNAME}*.stats |
3673                   awk '/mds_connect/{print $2}')
3674
3675         # retrieve from the log if the client has ever tried to
3676         # contact the fake server after the loss of connection
3677         FAILCONN=`awk "BEGIN {ret = 0;}
3678                        /import_select_connection.*${FSNAME}-MDT0000-mdc.* using connection/ {
3679                                 ret = 1;
3680                                 if (\\\$NF ~ /$FAKENID/) {
3681                                         ret = 2;
3682                                         exit;
3683                                 }
3684                        }
3685                        END {print ret}" $TMP/lustre-log-$TESTNAME.log`
3686
3687         [ "$FAILCONN" == "0" ] &&
3688                 error "The client reconnection has not been triggered"
3689         [ "$FAILCONN" == "2" ] &&
3690                 error "Primary server busy, client reconnect to failover failed"
3691
3692         # LU-290
3693         # When OBD_FAIL_MDS_RESEND is hit, we sleep for 2 * obd_timeout
3694         # Reconnects are supposed to be rate limited to one every 5s
3695         [ $CONNCNT -gt $((2 * $TIMEOUT / 5 + 1)) ] &&
3696                 error "Too many reconnects $CONNCNT"
3697
3698         cleanup || error "cleanup failed with $?"
3699         # remove nid settings
3700         writeconf_or_reformat
3701 }
3702 run_test 35b "Continue reconnection retries, if the active server is busy"
3703
3704 test_36() { # 12743
3705         [ $OSTCOUNT -lt 2 ] && skip_env "needs >= 2 OSTs"
3706
3707         [ "$ost_HOST" = "`hostname`" -o "$ost1_HOST" = "`hostname`" ] ||
3708                 skip "remote OST"
3709
3710         local rc=0
3711         local FSNAME2=test1234
3712         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
3713
3714         [ -n "$ost1_HOST" ] && fs2ost_HOST=$ost1_HOST && fs3ost_HOST=$ost1_HOST
3715
3716         if [ -z "$fs2ost_DEV" -o -z "$fs2mds_DEV" -o -z "$fs3ost_DEV" ]; then
3717                 is_blkdev $SINGLEMDS $MDSDEV &&
3718                         skip_env "mixed loopback and real device not working"
3719         fi
3720
3721         local fs2mdsdev=$(mdsdevname 1_2)
3722         local fs2ostdev=$(ostdevname 1_2)
3723         local fs3ostdev=$(ostdevname 2_2)
3724         local fs2mdsvdev=$(mdsvdevname 1_2)
3725         local fs2ostvdev=$(ostvdevname 1_2)
3726         local fs3ostvdev=$(ostvdevname 2_2)
3727
3728         load_modules
3729         add fs2mds $(mkfs_opts mds1 ${fs2mdsdev}) --mgs --fsname=${FSNAME2} \
3730                 --reformat $fs2mdsdev $fs2mdsvdev || exit 10
3731         # XXX after we support non 4K disk blocksize in ldiskfs, specify a
3732         #     different one than the default value here.
3733         add fs2ost $(mkfs_opts ost1 ${fs2ostdev}) --mgsnode=$MGSNID \
3734                 --fsname=${FSNAME2} --reformat $fs2ostdev $fs2ostvdev || exit 10
3735         add fs3ost $(mkfs_opts ost2 ${fs3ostdev}) --mgsnode=$MGSNID \
3736                 --fsname=${FSNAME2} --reformat $fs3ostdev $fs3ostvdev || exit 10
3737
3738         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS
3739         start fs2ost $fs2ostdev $OST_MOUNT_OPTS
3740         start fs3ost $fs3ostdev $OST_MOUNT_OPTS
3741         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
3742         $MOUNT_CMD $MGSNID:/${FSNAME2} $MOUNT2 || error "$MOUNT_CMD failed"
3743
3744         sleep 5 # until 11778 fixed
3745
3746         dd if=/dev/zero of=$MOUNT2/$tfile bs=1M count=7 || error "dd failed"
3747
3748         BKTOTAL=$($LCTL get_param -n obdfilter.*.kbytestotal |
3749                   awk 'BEGIN{total=0}; {total+=$1}; END{print total}')
3750         BKFREE=$($LCTL get_param -n obdfilter.*.kbytesfree |
3751                  awk 'BEGIN{free=0}; {free+=$1}; END{print free}')
3752         BKAVAIL=$($LCTL get_param -n obdfilter.*.kbytesavail |
3753                   awk 'BEGIN{avail=0}; {avail+=$1}; END{print avail}')
3754         STRING=$(df -P $MOUNT2 | tail -n 1 | awk '{print $2","$3","$4}')
3755         DFTOTAL=$(echo $STRING | cut -d, -f1)
3756         DFUSED=$(echo $STRING  | cut -d, -f2)
3757         DFAVAIL=$(echo $STRING | cut -d, -f3)
3758         DFFREE=$(($DFTOTAL - $DFUSED))
3759
3760         ALLOWANCE=$((64 * $OSTCOUNT))
3761
3762         if [ $DFTOTAL -lt $(($BKTOTAL - $ALLOWANCE)) ] ||
3763            [ $DFTOTAL -gt $(($BKTOTAL + $ALLOWANCE)) ] ; then
3764                 echo "**** FAIL: df total($DFTOTAL) mismatch OST total($BKTOTAL)"
3765                 rc=1
3766         fi
3767         if [ $DFFREE -lt $(($BKFREE - $ALLOWANCE)) ] ||
3768            [ $DFFREE -gt $(($BKFREE + $ALLOWANCE)) ] ; then
3769                 echo "**** FAIL: df free($DFFREE) mismatch OST free($BKFREE)"
3770                 rc=2
3771         fi
3772         if [ $DFAVAIL -lt $(($BKAVAIL - $ALLOWANCE)) ] ||
3773            [ $DFAVAIL -gt $(($BKAVAIL + $ALLOWANCE)) ] ; then
3774                 echo "**** FAIL: df avail($DFAVAIL) mismatch OST avail($BKAVAIL)"
3775                 rc=3
3776         fi
3777
3778         $UMOUNT $MOUNT2
3779         stop fs3ost -f || error "unable to stop OST3"
3780         stop fs2ost -f || error "unable to stop OST2"
3781         stop fs2mds -f || error "unable to stop second MDS"
3782         unload_modules_conf || error "unable unload modules"
3783         return $rc
3784 }
3785 run_test 36 "df report consistency on OSTs with different block size"
3786
3787 test_37() {
3788         local mntpt=$(facet_mntpt $SINGLEMDS)
3789         local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
3790         local mdsdev_sym="$TMP/sym_mdt.img"
3791         local opts=$MDS_MOUNT_OPTS
3792         local rc=0
3793
3794         if [ "$mds1_FSTYPE" != ldiskfs ]; then
3795                 skip "ldiskfs only test"
3796         fi
3797
3798         echo "MDS :     $mdsdev"
3799         echo "SYMLINK : $mdsdev_sym"
3800         do_facet $SINGLEMDS rm -f $mdsdev_sym
3801
3802         do_facet $SINGLEMDS ln -s $mdsdev $mdsdev_sym
3803
3804         echo "mount symlink device - $mdsdev_sym"
3805
3806         if ! do_facet $SINGLEMDS test -b $mdsdev; then
3807                 opts=$(csa_add "$opts" -o loop)
3808         fi
3809
3810         load_modules
3811         mount_op=$(do_facet $SINGLEMDS mount -v -t lustre $opts \
3812                 $mdsdev_sym $mntpt 2>&1)
3813         rc=${PIPESTATUS[0]}
3814
3815         echo mount_op=$mount_op
3816
3817         do_facet $SINGLEMDS "$UMOUNT $mntpt && rm -f $mdsdev_sym"
3818
3819         if $(echo $mount_op | grep -q "unable to set tunable"); then
3820                 error "set tunables failed for symlink device"
3821         fi
3822
3823         [ $rc -eq 0 ] || error "mount symlink $mdsdev_sym failed! rc=$rc"
3824 }
3825 run_test 37 "verify set tunables works for symlink device"
3826
3827 test_38() { # bug 14222
3828         local mntpt=$(facet_mntpt $SINGLEMDS)
3829
3830         setup
3831         # like runtests
3832         local COUNT=10
3833         local SRC="/etc /bin"
3834         local FILES=$(find $SRC -type f -mtime +1 | head -n $COUNT)
3835
3836         log "copying $(echo $FILES | wc -w) files to $DIR/$tdir"
3837         rm -rf $DIR/$tdir
3838         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
3839         tar cf - $FILES | tar xf - -C $DIR/$tdir ||
3840                 error "copying $SRC to $DIR/$tdir"
3841         sync
3842         umount_client $MOUNT || error "umount_client $MOUNT failed"
3843         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
3844         stop_mds || error "Unable to stop MDS"
3845         log "delete lov_objid file on MDS"
3846
3847         mount_fstype $SINGLEMDS || error "mount MDS failed (1)"
3848
3849         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid; rm $mntpt/lov_objid"
3850
3851         unmount_fstype $SINGLEMDS || error "umount failed (1)"
3852
3853         # check create in mds_lov_connect
3854         start_mds || error "unable to start MDS"
3855         mount_client $MOUNT || error "mount_client $MOUNT failed"
3856         for f in $FILES; do
3857                 [ $V ] && log "verifying $DIR/$tdir/$f"
3858                 diff -q $f $DIR/$tdir/$f || ERROR=y
3859         done
3860         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
3861         if [ "$ERROR" = "y" ]; then
3862                 # check it's updates in sync
3863                 umount_client $MOUNT
3864                 stop_mds
3865                 mount_fstype $SIGNLEMDS
3866                 do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
3867                 unmount_fstype $SINGLEMDS
3868                 error "old and new files are different after connect" || true
3869         fi
3870         touch $DIR/$tdir/f2 || error "f2 file create failed"
3871
3872         # check it's updates in sync
3873         umount_client $MOUNT || error "second umount_client $MOUNT failed"
3874         stop_mds
3875
3876         mount_fstype $SINGLEMDS || error "mount MDS failed (3)"
3877
3878         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
3879         do_facet $SINGLEMDS dd if=/dev/zero of=$mntpt/lov_objid.clear count=8
3880
3881         unmount_fstype $SINGLEMDS || error "umount failed (3)"
3882
3883         start_mds || error "unable to start MDS"
3884         mount_client $MOUNT || error "mount_client $MOUNT failed"
3885         for f in $FILES; do
3886                 [ $V ] && log "verifying $DIR/$tdir/$f"
3887                 diff -q $f $DIR/$tdir/$f || ERROR=y
3888         done
3889         touch $DIR/$tdir/f3 || error "f3 file create failed"
3890         do_facet $SINGLEMDS "$LCTL get_param osp.*.prealloc_next_id"
3891         umount_client $MOUNT || error "third umount_client $MOUNT failed"
3892         stop_mds
3893         mount_fstype $SINGLEMDS || error "mount MDS failed (4)"
3894         do_facet $SINGLEMDS "od -Ax -td8 $mntpt/lov_objid"
3895         unmount_fstype $SINGLEMDS || error "umount failed (4)"
3896
3897         [[ "$ERROR" != "y" ]] ||
3898                 error "old and new files are different after sync"
3899
3900         log "files compared the same"
3901         cleanup || error "cleanup failed with $?"
3902 }
3903 run_test 38 "MDS recreates missing lov_objid file from OST data"
3904
3905 test_39() {
3906         [[ -n "$(type -p perl)" ]] || skip_env "need perl for leak_finder.pl"
3907
3908         PTLDEBUG=+malloc
3909         setup
3910         cleanup || error "cleanup failed with $?"
3911         perl $SRCDIR/leak_finder.pl $TMP/debug 2>&1 | egrep '*** Leak:' &&
3912                 error "memory leak detected" || true
3913 }
3914 run_test 39 "leak_finder recognizes both LUSTRE and LNET malloc messages"
3915
3916 test_40() { # bug 15759
3917         start_ost || error "Unable to start OST1"
3918         #define OBD_FAIL_TGT_TOOMANY_THREADS     0x706
3919         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x80000706"
3920         start_mds
3921         cleanup || error "cleanup failed with rc $?"
3922 }
3923 run_test 40 "race during service thread startup"
3924
3925 test_41a() { #bug 14134
3926         if [ "$mds1_FSTYPE" == ldiskfs ] &&
3927            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
3928                 skip "Loop devices does not work with nosvc option"
3929         fi
3930
3931         combined_mgs_mds || skip "needs combined MGT and MDT device"
3932
3933         start_mdt 1 -o nosvc -n
3934         if [ $MDSCOUNT -ge 2 ]; then
3935                 for num in $(seq 2 $MDSCOUNT); do
3936                         start_mdt $num || return
3937                 done
3938         fi
3939         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS
3940         start_mdt 1 -o nomgs,force
3941         mount_client $MOUNT || error "mount_client $MOUNT failed"
3942         sleep 5
3943
3944         echo "blah blah" > $MOUNT/$tfile
3945         cat $MOUNT/$tfile
3946
3947         umount_client $MOUNT || error "umount_client $MOUNT failed"
3948         stop ost1 -f || error "unable to stop OST1"
3949         stop_mds || error "Unable to stop MDS"
3950         stop_mds || error "Unable to stop MDS on second try"
3951 }
3952 run_test 41a "mount mds with --nosvc and --nomgs"
3953
3954 test_41b() {
3955         if [ "$mds1_FSTYPE" == ldiskfs ] &&
3956            ! do_facet $SINGLEMDS test -b $(mdsdevname 1); then
3957                 skip "Loop devices does not work with nosvc option"
3958         fi
3959
3960         ! combined_mgs_mds && skip "needs combined mgs device"
3961
3962         stopall
3963         reformat
3964         local MDSDEV=$(mdsdevname ${SINGLEMDS//mds/})
3965
3966         start_mdt 1 -o nosvc -n
3967         if [ $MDSCOUNT -ge 2 ]; then
3968                 for num in $(seq 2 $MDSCOUNT); do
3969                         start_mdt $num || return
3970                 done
3971         fi
3972         start_ost || error "Unable to start OST1"
3973         start_mdt 1 -o nomgs,force
3974         mount_client $MOUNT || error "mount_client $MOUNT failed"
3975         sleep 5
3976
3977         echo "blah blah" > $MOUNT/$tfile
3978         cat $MOUNT/$tfile || error "cat $MOUNT/$tfile failed"
3979
3980         umount_client $MOUNT -f || error "umount_client $MOUNT failed"
3981         stop_ost || error "Unable to stop OST1"
3982         stop_mds || error "Unable to stop MDS"
3983         stop_mds || error "Unable to stop MDS on second try"
3984 }
3985 run_test 41b "mount mds with --nosvc and --nomgs on first mount"
3986
3987 test_41c() {
3988         local osts=$(osts_nodes)
3989
3990         (( "$MDS1_VERSION" >= $(version_code 2.15.62.4) )) ||
3991                 skip "Need MDS >= 2.15.62.4 for parallel device locking"
3992
3993         # ensure mds1 ost1 have been created even if running sub-test standalone
3994         cleanup
3995         setup
3996         cleanup || error "cleanup failed"
3997
3998         # using directly mount command instead of start() function to avoid
3999         # any side effect of // with others/externals tools/features
4000         # ("zpool import", ...)
4001
4002         # MDT concurrent start
4003
4004         LOAD_MODULES_REMOTE=true load_modules
4005         do_facet $SINGLEMDS "lsmod | grep -q libcfs" ||
4006                 error "MDT concurrent start: libcfs module not loaded"
4007
4008         local mds1dev=$(mdsdevname 1)
4009         local mds1mnt=$(facet_mntpt mds1)
4010         local mds1opts=$MDS_MOUNT_OPTS
4011
4012         if [[ "$mds1_FSTYPE" == ldiskfs ]] &&
4013            ! do_facet mds1 test -b $mds1dev; then
4014                 mds1opts=$(csa_add "$mds1opts" -o loop)
4015         fi
4016         if [[ "$mds1_FSTYPE" == zfs ]]; then
4017                 import_zpool mds1 || return ${PIPESTATUS[0]}
4018         fi
4019
4020         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
4021         do_facet mds1 "$LCTL set_param fail_loc=0x80000716"
4022
4023         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts &
4024         local pid=$!
4025
4026         do_facet mds1 mount -t lustre $mds1dev $mds1mnt $mds1opts
4027         local rc2=$?
4028         wait $pid
4029         local rc=$?
4030
4031         do_facet mds1 "$LCTL set_param fail_loc=0x0"
4032         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
4033                 echo "1st MDT start succeed"
4034                 echo "2nd MDT start failed with $rc2"
4035         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
4036                 echo "1st MDT start failed with $rc"
4037                 echo "2nd MDT start succeed"
4038         else
4039                 stop mds1 -f
4040                 error "unexpected concurrent MDT mounts result, rc=$rc rc2=$rc2"
4041         fi
4042
4043         if [ $MDSCOUNT -ge 2 ]; then
4044                 for num in $(seq 2 $MDSCOUNT); do
4045                         start_mdt $num || return
4046                 done
4047         fi
4048
4049         # OST concurrent start
4050
4051         do_rpc_nodes $osts "lsmod | grep -q libcfs" ||
4052                 error "OST concurrent start: libcfs module not loaded"
4053
4054         local ost1dev=$(ostdevname 1)
4055         local ost1mnt=$(facet_mntpt ost1)
4056         local ost1opts=$OST_MOUNT_OPTS
4057
4058         if [ "$ost1_FSTYPE" == ldiskfs ] &&
4059            ! do_facet ost1 test -b $ost1dev; then
4060                 ost1opts=$(csa_add "$ost1opts" -o loop)
4061         fi
4062         if [[ "$ost1_FSTYPE" == zfs ]]; then
4063                 import_zpool ost1 || return ${PIPESTATUS[0]}
4064         fi
4065
4066         #define OBD_FAIL_TGT_MOUNT_RACE 0x716
4067         do_facet ost1 "$LCTL set_param fail_loc=0x80000716"
4068
4069         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts &
4070         pid=$!
4071
4072         do_facet ost1 mount -t lustre $ost1dev $ost1mnt $ost1opts
4073         rc2=$?
4074         wait $pid
4075         rc=$?
4076         do_facet ost1 "$LCTL set_param fail_loc=0x0"
4077         if [ $rc -eq 0 ] && [ $rc2 -ne 0 ]; then
4078                 echo "1st OST start succeed"
4079                 echo "2nd OST start failed with $rc2"
4080         elif [ $rc2 -eq 0 ] && [ $rc -ne 0 ]; then
4081                 echo "1st OST start failed with $rc"
4082                 echo "2nd OST start succeed"
4083         else
4084                 stop_mds -f
4085                 stop ost1 -f
4086                 error "unexpected concurrent OST mounts result, rc=$rc rc2=$rc2"
4087         fi
4088         # cleanup
4089         stop_mds
4090         stop ost1 -f
4091
4092         # verify everything ok
4093         start_mds
4094         if [ $? != 0 ]
4095         then
4096                 stop_mds
4097                 error "MDT(s) start failed"
4098         fi
4099
4100         start_ost
4101         if [ $? != 0 ]
4102         then
4103                 stop_mds
4104                 stop ost1 -f
4105                 error "OST(s) start failed"
4106         fi
4107
4108         mount_client $MOUNT
4109         if [ $? != 0 ]
4110         then
4111                 stop_mds
4112                 stop ost1 -f
4113                 error "client start failed"
4114         fi
4115         check_mount
4116         if [ $? != 0 ]
4117         then
4118                 stop_mds
4119                 stop ost1 -f
4120                 error "client mount failed"
4121         fi
4122         cleanup
4123 }
4124 run_test 41c "concurrent mounts of MDT/OST should all fail but one"
4125
4126 test_42() { #bug 14693
4127         local PARAM
4128
4129         setup
4130         check_mount || error "client was not mounted"
4131
4132         if [[ $PERM_CMD == *"set_param -P"* ]]; then
4133                 PARAM="llite.$FSNAME-*.some_wrong_param"
4134         else
4135                 PARAM="$FSNAME.llite.some_wrong_param"
4136         fi
4137
4138         do_facet mgs $PERM_CMD $PARAM=10
4139         umount_client $MOUNT ||
4140                 error "unmounting client failed with invalid llite param"
4141         mount_client $MOUNT ||
4142                 error "mounting client failed with invalid llite param"
4143
4144         do_facet mgs $PERM_CMD $PARAM=20
4145         cleanup || error "stopping $FSNAME failed with invalid sys param"
4146         setup
4147         check_mount || error "client was not mounted with invalid sys param"
4148         cleanup || error "stopping $FSNAME failed with invalid sys param"
4149 }
4150 run_test 42 "allow client/server mount/unmount with invalid config param"
4151
4152 test_43a_check_nosquash_nids() {
4153         local nidlist="$1"
4154
4155         set_persistent_param_and_check mds1                             \
4156                 "mdt.$FSNAME-MDT0000.nosquash_nids"                     \
4157                 "$FSNAME-MDTall.mdt.nosquash_nids"                      \
4158                 "$nidlist"
4159         wait_update $HOSTNAME                                           \
4160                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
4161                 "$nidlist" ||
4162                 error "check llite nosquash_nids failed!"
4163
4164         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
4165         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
4166                 error "$ST: root read permission is denied"
4167         echo "$ST: root read permission is granted - ok"
4168
4169         echo "666" |
4170         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null ||
4171                 error "$ST: root write permission is denied"
4172         echo "$ST: root write permission is granted - ok"
4173
4174         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
4175         rm $DIR/$tdir-rootdir/tfile-1 ||
4176                 error "$ST: root unlink permission is denied"
4177         echo "$ST: root unlink permission is granted - ok"
4178         touch $DIR/$tdir-rootdir/tfile-2 ||
4179                 error "$ST: root create permission is denied"
4180         echo "$ST: root create permission is granted - ok"
4181
4182         # Re-create test file deleted above in case this function is called
4183         # again
4184         touch $DIR/$tdir-rootdir/tfile-1 || error "touch failed"
4185 }
4186
4187 test_43a() {
4188         [[ "$MGS_VERSION" -ge $(version_code 2.5.58) ]] ||
4189                 skip "Need MDS version at least 2.5.58"
4190         [ $UID -ne 0 -o $RUNAS_ID -eq 0 ] && skip_env "run as root"
4191
4192         ID1=${ID1:-501}
4193         USER1=$(getent passwd | grep :$ID1:$ID1: | cut -d: -f1)
4194         [ -z "$USER1" ] && skip_env "missing user with uid=$ID1 gid=$ID1"
4195
4196         setup
4197         chmod ugo+x $DIR || error "chmod 0 failed"
4198         set_persistent_param_and_check mds1                             \
4199                 "mdt.$FSNAME-MDT0000.root_squash"                       \
4200                 "$FSNAME.mdt.root_squash"                               \
4201                 "0:0"
4202         wait_update $HOSTNAME                                           \
4203                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
4204                 "0:0" ||
4205                 error "check llite root_squash failed!"
4206         set_persistent_param_and_check mds1                             \
4207                 "mdt.$FSNAME-MDT0000.nosquash_nids"                     \
4208                 "$FSNAME.mdt.nosquash_nids"                             \
4209                 "NONE"
4210         wait_update $HOSTNAME                                           \
4211                 "$LCTL get_param -n llite.${FSNAME}*.nosquash_nids"     \
4212                 "NONE" ||
4213                 error "check llite nosquash_nids failed!"
4214
4215         #
4216         # create set of test files
4217         #
4218         echo "111" > $DIR/$tfile-userfile || error "write 1 failed"
4219         chmod go-rw $DIR/$tfile-userfile  || error "chmod 1 failed"
4220         chown $RUNAS_ID.$RUNAS_ID $DIR/$tfile-userfile || error "chown failed"
4221
4222         echo "222" > $DIR/$tfile-rootfile || error "write 2 failed"
4223         chmod go-rw $DIR/$tfile-rootfile  || error "chmod 2 faield"
4224
4225         mkdir_on_mdt0 $DIR/$tdir-rootdir || error "mkdir failed"
4226         chmod go-rwx $DIR/$tdir-rootdir || error "chmod 3 failed"
4227         touch $DIR/$tdir-rootdir/tfile-1 || error "touch failed"
4228
4229         echo "777" > $DIR/$tfile-user1file || error "write 7 failed"
4230         chmod go-rw $DIR/$tfile-user1file || error "chmod 7 failed"
4231         chown $ID1.$ID1 $DIR/$tfile-user1file || error "chown failed"
4232
4233         #
4234         # check root_squash:
4235         #   set root squash UID:GID to RUNAS_ID
4236         #   root should be able to access only files owned by RUNAS_ID
4237         #
4238         set_persistent_param_and_check mds1                             \
4239                 "mdt.$FSNAME-MDT0000.root_squash"                       \
4240                 "$FSNAME.mdt.root_squash"                               \
4241                 "$RUNAS_ID:$RUNAS_ID"
4242         wait_update $HOSTNAME                                           \
4243                 "$LCTL get_param -n llite.${FSNAME}*.root_squash"       \
4244                 "$RUNAS_ID:$RUNAS_ID" ||
4245                 error "check llite root_squash failed!"
4246
4247         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-userfile)
4248         dd if=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
4249                 error "$ST: root read permission is denied"
4250         echo "$ST: root read permission is granted - ok"
4251
4252         echo "444" |
4253         dd conv=notrunc of=$DIR/$tfile-userfile 1>/dev/null 2>/dev/null ||
4254                 error "$ST: root write permission is denied"
4255         echo "$ST: root write permission is granted - ok"
4256
4257         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-rootfile)
4258         dd if=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
4259                 error "$ST: root read permission is granted"
4260         echo "$ST: root read permission is denied - ok"
4261
4262         echo "555" |
4263         dd conv=notrunc of=$DIR/$tfile-rootfile 1>/dev/null 2>/dev/null &&
4264                 error "$ST: root write permission is granted"
4265         echo "$ST: root write permission is denied - ok"
4266
4267         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tdir-rootdir)
4268                 rm $DIR/$tdir-rootdir/tfile-1 1>/dev/null 2>/dev/null &&
4269                         error "$ST: root unlink permission is granted"
4270         echo "$ST: root unlink permission is denied - ok"
4271
4272         touch $DIR/tdir-rootdir/tfile-2 1>/dev/null 2>/dev/null &&
4273                 error "$ST: root create permission is granted"
4274         echo "$ST: root create permission is denied - ok"
4275
4276         # LU-1778
4277         # check root_squash is enforced independently
4278         # of client cache content
4279         #
4280         # access file by USER1, keep access open
4281         # root should be denied access to user file
4282
4283         runas -u $ID1 tail -f $DIR/$tfile-user1file 1>/dev/null 2>&1 &
4284         pid=$!
4285         sleep 1
4286
4287         ST=$(stat -c "%n: owner uid %u (%A)" $DIR/$tfile-user1file)
4288         dd if=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
4289             { kill $pid; error "$ST: root read permission is granted"; }
4290         echo "$ST: root read permission is denied - ok"
4291
4292         echo "777" |
4293         dd conv=notrunc of=$DIR/$tfile-user1file 1>/dev/null 2>&1 &&
4294             { kill $pid; error "$ST: root write permission is granted"; }
4295         echo "$ST: root write permission is denied - ok"
4296
4297         kill $pid
4298         wait $pid
4299
4300         #
4301         # check nosquash_nids:
4302         #   put client's NID into nosquash_nids list,
4303         #   root should be able to access root file after that
4304         #
4305         local nidlist=$($LCTL list_nids all | tr '\n' ' ')
4306         nidlist="2@gni $nidlist 192.168.0.[2,10]@tcp"
4307         nidlist=$(echo $nidlist | tr -s ' ' ' ')
4308
4309         test_43a_check_nosquash_nids "$nidlist"
4310
4311         if ! [[ $NETTYPE =~ ^(tcp|o2ib) ]]; then
4312                 log "Skip nidmask test for NETTYPE = $NETTYPE"
4313                 cleanup || error "cleanup failed with $?"
4314                 return 0
4315         fi
4316
4317         # check nosquash_nids:
4318         #   create a nidmask that contains the client's NID and place it
4319         #   into nosquash_nids list.
4320         #   root should be able to access root file after that
4321         local interfaces=( $(lnet_if_list) )
4322         local intf netmasks nm
4323
4324         for intf in ${interfaces[@]}; do
4325                 nm=$(ip -o -4 a s ${intf} | awk '{print $4}')
4326                 [[ -n $nm ]] && netmasks+=" $nm@${NETTYPE}"
4327                 nm=$(ip -o -6 a s ${intf} | grep -v 'fe80::' | awk '{print $4}')
4328                 [[ -n $nm ]] && netmasks+=" $nm@${NETTYPE}"
4329         done
4330
4331         netmasks="${netmasks/ }"
4332
4333         if [[ -z $netmasks ]]; then
4334                 error "Unable to determine netmasks for ${interfaces[@]}"
4335         fi
4336
4337         test_43a_check_nosquash_nids "$netmasks"
4338
4339         # cleanup test dir/files
4340         rm -rf $DIR/$tfile-* $DIR/$tdir-rootdir ||
4341                 error "Failed to remove test files/dir rc = $?"
4342
4343         cleanup || error "cleanup failed with $?"
4344 }
4345 run_test 43a "check root_squash and nosquash_nids"
4346
4347 test_43b() { # LU-5690
4348         [[ "$MGS_VERSION" -ge $(version_code 2.7.62) ]] ||
4349                 skip "Need MGS version 2.7.62+"
4350
4351         if [[ -z "$fs2mds_DEV" ]]; then
4352                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
4353                 skip_env "mixed loopback and real device not working"
4354         fi
4355
4356         local fs2mdsdev=$(mdsdevname 1_2)
4357         local fs2mdsvdev=$(mdsvdevname 1_2)
4358
4359         # temporarily use fs2mds as fs2mgs
4360         local fs2mgs=fs2mds
4361         local fs2mgsdev=$fs2mdsdev
4362         local fs2mgsvdev=$fs2mdsvdev
4363
4364         local fsname=test1234
4365
4366         load_module llite/lustre
4367         local client_ip=$(host_nids_address $HOSTNAME $NETTYPE)
4368         local host=${client_ip//*./}
4369         local net=${client_ip/%$host/}
4370         local nosquash_nids=$(h2nettype $net[$host,$host,$host])
4371
4372         add $fs2mgs $(mkfs_opts mgs $fs2mgsdev) --fsname=$fsname \
4373                 --param mdt.root_squash=$RUNAS_ID:$RUNAS_ID \
4374                 --param mdt.nosquash_nids=$nosquash_nids \
4375                 --reformat $fs2mgsdev $fs2mgsvdev || error "add fs2mgs failed"
4376         start $fs2mgs $fs2mgsdev $MGS_MOUNT_OPTS  || error "start fs2mgs failed"
4377         stop $fs2mgs -f || error "stop fs2mgs failed"
4378         cleanup || error "cleanup failed with $?"
4379 }
4380 run_test 43b "parse nosquash_nids with commas in expr_list"
4381
4382 test_44() { # 16317
4383         setup
4384         check_mount || error "check_mount"
4385         UUID=$($LCTL get_param llite.${FSNAME}*.uuid | cut -d= -f2)
4386         STATS_FOUND=no
4387         UUIDS=$(do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.*.uuid")
4388         for VAL in $UUIDS; do
4389                 NID=$(echo $VAL | cut -d= -f1)
4390                 CLUUID=$(echo $VAL | cut -d= -f2)
4391                 [ "$UUID" = "$CLUUID" ] && STATS_FOUND=yes && break
4392         done
4393         [ "$STATS_FOUND" = "no" ] && error "stats not found for client"
4394         cleanup || error "cleanup failed with $?"
4395 }
4396 run_test 44 "mounted client proc entry exists"
4397
4398 test_45() { #17310
4399         setup
4400         check_mount || error "check_mount"
4401         stop_mds || error "Unable to stop MDS"
4402         df -h $MOUNT &
4403         log "sleep 60 sec"
4404         sleep 60
4405         #define OBD_FAIL_PTLRPC_LONG_REPL_UNLINK        0x50f
4406         do_facet client "$LCTL set_param fail_loc=0x8000050f"
4407         log "sleep 10 sec"
4408         sleep 10
4409         manual_umount_client --force || error "manual_umount_client failed"
4410         do_facet client "$LCTL set_param fail_loc=0x0"
4411         start_mds || error "unable to start MDS"
4412         mount_client $MOUNT || error "mount_client $MOUNT failed"
4413         cleanup || error "cleanup failed with $?"
4414 }
4415 run_test 45 "long unlink handling in ptlrpcd"
4416
4417 cleanup_46a() {
4418         trap 0
4419         local rc=0
4420         local count=$1
4421
4422         umount_client $MOUNT2 || rc=$?
4423         umount_client $MOUNT || rc=$?
4424         while [ $count -gt 0 ]; do
4425                 stop ost${count} -f || rc=$?
4426                 let count=count-1
4427         done
4428         stop_mds || rc=$?
4429         cleanup_nocli || rc=$?
4430         #writeconf to remove all ost2 traces for subsequent tests
4431         writeconf_or_reformat
4432         return $rc
4433 }
4434
4435 test_46a() {
4436         echo "Testing with $OSTCOUNT OSTs"
4437         reformat_and_config
4438         start_mds || error "unable to start MDS"
4439         #first client should see only one ost
4440         start_ost || error "Unable to start OST1"
4441         wait_osc_import_state mds ost FULL
4442         #start_client
4443         mount_client $MOUNT || error "mount_client $MOUNT failed"
4444         trap "cleanup_46a $OSTCOUNT" EXIT ERR
4445
4446         local i
4447         for (( i=2; i<=$OSTCOUNT; i++ )); do
4448                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
4449                         error "start_ost$i $(ostdevname $i) failed"
4450         done
4451
4452         # wait until osts in sync
4453         for (( i=2; i<=$OSTCOUNT; i++ )); do
4454             wait_osc_import_state mds ost$i FULL
4455             wait_osc_import_ready client ost$i
4456         done
4457
4458         #second client see all ost's
4459
4460         mount_client $MOUNT2 || error "mount_client failed"
4461         $LFS setstripe -c -1 $MOUNT2 ||
4462                 error "$LFS setstripe -c -1 $MOUNT2 failed"
4463         $LFS getstripe $MOUNT2 || error "$LFS getstripe $MOUNT2 failed"
4464
4465         echo "ok" > $MOUNT2/widestripe
4466         $LFS getstripe $MOUNT2/widestripe ||
4467                 error "$LFS getstripe $MOUNT2/widestripe failed"
4468         # fill acl buffer for avoid expand lsm to them
4469         awk -F : '{if (FNR < 25) { print "u:"$1":rwx" }}' /etc/passwd |
4470                 while read acl; do
4471             setfacl -m $acl $MOUNT2/widestripe
4472         done
4473
4474         # will be deadlock
4475         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
4476
4477         cleanup_46a $OSTCOUNT || error "cleanup_46a failed"
4478 }
4479 run_test 46a "handle ost additional - wide striped file"
4480
4481 test_47a() { #17674
4482         reformat
4483         setup_noconfig
4484         check_mount || error "check_mount failed"
4485         $LCTL set_param ldlm.namespaces.$FSNAME-*-*-*.lru_size=100
4486
4487         local lru_size=[]
4488         local count=0
4489         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
4490                 if echo $ns | grep "MDT[[:digit:]]*"; then
4491                         continue
4492                 fi
4493                 lrs=$(echo $ns | sed 's/.*lru_size=//')
4494                 lru_size[count]=$lrs
4495                 let count=count+1
4496         done
4497
4498         facet_failover ost1
4499         facet_failover $SINGLEMDS
4500         client_up || error "client_up failed"
4501
4502         count=0
4503         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME-*-*-*.lru_size); do
4504                 if echo $ns | grep "MDT[[:digit:]]*"; then
4505                         continue
4506                 fi
4507                 lrs=$(echo $ns | sed 's/.*lru_size=//')
4508                 if ! test "$lrs" -eq "${lru_size[count]}"; then
4509                         n=$(echo $ns | sed -e 's/ldlm.namespaces.//' -e 's/.lru_size=.*//')
4510                         error "$n has lost lru_size: $lrs vs. ${lru_size[count]}"
4511                 fi
4512                 let count=count+1
4513         done
4514         cleanup || error "cleanup failed with $?"
4515 }
4516 run_test 47a "server restart does not lose lru_resize"
4517
4518 test_47b() { #17833
4519         local create_simple_link=false
4520
4521         reformat
4522         setup_noconfig
4523         check_mount || error "check_mount failed"
4524
4525         [[ -e /usr/sbin/lctl ]] || {
4526                 # Unfortunately set_param -P rely on the hardcoded path
4527                 # /usr/sbin/lctl
4528                 ln -s /usr/sbin/lctl $LCTL ||
4529                         skip_env "Can not create symlink /usr/sbin/lctl"
4530                 stack_trap "rm -f /usr/sbin/lctl"
4531         }
4532
4533         do_facet mgs $LCTL \
4534                 set_param -P ldlm.namespaces.$FSNAME-*-mdc-*.lru_size=200
4535         wait_update $HOSTNAME \
4536           "$LCTL get_param -n ldlm.namespaces.$FSNAME-MDT0000-mdc-*.lru_size" \
4537           "200"
4538         umount $MOUNT || error "Unable to umount client"
4539         mount_client $MOUNT || error "mount failed"
4540         for ns in $($LCTL get_param ldlm.namespaces.$FSNAME*mdc*.lru_size); do
4541                 (( ${ns/*=/} == 200)) ||
4542                         error "${ns/=*/} is ${ns/*=/}, expect 200"
4543         done
4544         cleanup || error "cleanup failed with $?"
4545 }
4546 run_test 47b "client restart does not lose lru_resize"
4547
4548 cleanup_48() {
4549         trap 0
4550
4551         # reformat after this test is needed - if the test fails,
4552         # we will have unkillable file at FS
4553         reformat_and_config
4554 }
4555
4556 test_48() { # bz-17636 LU-7473
4557         local count
4558
4559         setup_noconfig
4560         check_mount || error "check_mount failed"
4561
4562         debugsave
4563         stack_trap "debugrestore"
4564         $LCTL set_param debug=0
4565         do_facet $SINGLEMDS $LCTL set_param debug=0
4566
4567         $LFS setstripe -c -1 $MOUNT ||
4568                 error "$LFS setstripe -c -1 $MOUNT failed"
4569         $LFS getstripe $MOUNT || error "$LFS getstripe $MOUNT failed"
4570
4571         echo "ok" > $MOUNT/widestripe
4572         $LFS getstripe $MOUNT/widestripe ||
4573                 error "$LFS getstripe $MOUNT/widestripe failed"
4574
4575         # In the future, we may introduce more EAs, such as selinux, enlarged
4576         # LOV EA, and so on. These EA will use some EA space that is shared by
4577         # ACL entries. So here we only check some reasonable ACL entries count,
4578         # instead of the max number that is calculated from the max_ea_size.
4579         if (( $MDS1_VERSION < $(version_code 2.8.57) )); then
4580                 count=28        # hard coded of RPC protocol
4581         elif large_xattr_enabled; then
4582                 count=4500      # max_num 8187 max_ea_size = 65452
4583                                 # not create too many (4500) to save test time
4584         else
4585                 count=450       # max_num 497 max_ea_size = 4012
4586         fi
4587
4588         echo "It is expected to hold at least $count ACL entries"
4589         trap cleanup_48 EXIT ERR
4590         for ((i = 0; i < $count; i++)) do
4591                 setfacl -m u:$((i + 100)):rw $MOUNT/widestripe ||
4592                         error "Fail to setfacl for $MOUNT/widestripe at $i"
4593         done
4594
4595         cancel_lru_locks mdc
4596         stat $MOUNT/widestripe || error "stat $MOUNT/widestripe failed"
4597         local r_count=$(getfacl $MOUNT/widestripe | grep "user:" | wc -l)
4598
4599         count=$((count + 1)) # for the entry "user::rw-"
4600
4601         (( $count == $r_count )) ||
4602                 error "Expected ACL entries $count, but got $r_count"
4603
4604         cleanup_48
4605 }
4606 run_test 48 "too many acls on file"
4607
4608 # check PARAM_SYS_LDLM_TIMEOUT option of MKFS.LUSTRE
4609 test_49a() { # bug 17710
4610         local timeout_orig=$TIMEOUT
4611         local ldlm_timeout_orig=$LDLM_TIMEOUT
4612         local LOCAL_TIMEOUT=20
4613
4614         LDLM_TIMEOUT=$LOCAL_TIMEOUT
4615         TIMEOUT=$LOCAL_TIMEOUT
4616
4617         reformat
4618         setup_noconfig
4619         check_mount || error "client mount failed"
4620
4621         echo "check ldlm_timout..."
4622         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
4623         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
4624         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
4625
4626         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
4627                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
4628         fi
4629
4630         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT / 3)) ]; then
4631                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT / 3))"
4632         fi
4633
4634         umount_client $MOUNT || error "umount_client $MOUNT failed"
4635         stop_ost || error "problem stopping OSS"
4636         stop_mds || error "problem stopping MDS"
4637
4638         LDLM_TIMEOUT=$ldlm_timeout_orig
4639         TIMEOUT=$timeout_orig
4640 }
4641 run_test 49a "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
4642
4643 test_49b() { # bug 17710
4644         local timeout_orig=$TIMEOUT
4645         local ldlm_timeout_orig=$LDLM_TIMEOUT
4646         local LOCAL_TIMEOUT=20
4647
4648         LDLM_TIMEOUT=$((LOCAL_TIMEOUT - 1))
4649         TIMEOUT=$LOCAL_TIMEOUT
4650
4651         reformat
4652         setup_noconfig
4653         check_mount || error "client mount failed"
4654
4655         local LDLM_MDS="$(do_facet $SINGLEMDS $LCTL get_param -n ldlm_timeout)"
4656         local LDLM_OST1="$(do_facet ost1 $LCTL get_param -n ldlm_timeout)"
4657         local LDLM_CLIENT="$(do_facet client $LCTL get_param -n ldlm_timeout)"
4658
4659         if [ $LDLM_MDS -ne $LDLM_OST1 -o $LDLM_MDS -ne $LDLM_CLIENT ]; then
4660                 error "Different LDLM_TIMEOUT:$LDLM_MDS $LDLM_OST1 $LDLM_CLIENT"
4661         fi
4662
4663         if [ $LDLM_MDS -ne $((LOCAL_TIMEOUT - 1)) ]; then
4664                 error "LDLM_TIMEOUT($LDLM_MDS) is not $((LOCAL_TIMEOUT - 1))"
4665         fi
4666
4667         cleanup || error "cleanup failed"
4668
4669         LDLM_TIMEOUT=$ldlm_timeout_orig
4670         TIMEOUT=$timeout_orig
4671 }
4672 run_test 49b "check PARAM_SYS_LDLM_TIMEOUT option of mkfs.lustre"
4673
4674 lazystatfs() {
4675         # wait long enough to exceed OBD_STATFS_CACHE_SECONDS = 1
4676         sleep 2
4677         # Test both statfs and lfs df and fail if either one fails
4678         multiop_bg_pause $1 f_
4679         RC=$?
4680         PID=$!
4681         killall -USR1 multiop
4682         [ $RC -ne 0 ] && log "lazystatfs multiop failed"
4683         wait $PID || { RC=$?; log "multiop return error "; }
4684
4685         # wait long enough to exceed OBD_STATFS_CACHE_SECONDS = 1
4686         sleep 2
4687         $LFS df -l &
4688         PID=$!
4689         sleep 5
4690         if kill -s 0 $PID; then
4691                 RC=1
4692                 kill -s 9 $PID
4693                 log "lazystatfs lfs df failed to complete in 5s"
4694         fi
4695
4696         return $RC
4697 }
4698
4699 test_50a() {
4700         setup
4701         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
4702         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4703
4704         lazystatfs $MOUNT || error "lazystatfs failed but no down servers"
4705
4706         cleanup || error "cleanup failed with rc $?"
4707 }
4708 run_test 50a "lazystatfs all servers available"
4709
4710 test_50b() {
4711         setup
4712         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
4713         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4714
4715         # Wait for client to detect down OST
4716         stop_ost || error "Unable to stop OST1"
4717         wait_osc_import_state client ost DISCONN
4718         $LCTL dl
4719         log "OSCs should all be DISCONN"
4720
4721         lazystatfs $MOUNT || error "lazystatfs should not return EIO"
4722
4723         umount_client $MOUNT || error "Unable to unmount client"
4724         stop_mds || error "Unable to stop MDS"
4725 }
4726 run_test 50b "lazystatfs all servers down"
4727
4728 test_50c() {
4729         start_mds || error "Unable to start MDS"
4730         start_ost || error "Unable to start OST1"
4731         start_ost2 || error "Unable to start OST2"
4732         mount_client $MOUNT || error "Unable to mount client"
4733         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
4734         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4735
4736         # Wait for client to detect down OST
4737         stop_ost || error "Unable to stop OST1"
4738         wait_osc_import_state mds ost DISCONN
4739         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
4740
4741         umount_client $MOUNT || error "Unable to unmount client"
4742         stop_ost2 || error "Unable to stop OST2"
4743         stop_mds || error "Unable to stop MDS"
4744         #writeconf to remove all ost2 traces for subsequent tests
4745         writeconf_or_reformat
4746 }
4747 run_test 50c "lazystatfs one server down"
4748
4749 test_50d() {
4750         start_mds || error "Unable to start MDS"
4751         start_ost || error "Unable to start OST1"
4752         start_ost2 || error "Unable to start OST2"
4753         mount_client $MOUNT || error "Unable to mount client"
4754         $LCTL set_param llite.$FSNAME-*.lazystatfs=1
4755         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
4756
4757         # Issue the statfs during the window where the client still
4758         # belives the OST to be available but it is in fact down.
4759         # No failure just a statfs which hangs for a timeout interval.
4760         stop_ost || error "Unable to stop OST1"
4761         lazystatfs $MOUNT || error "lazystatfs failed with one down server"
4762
4763         umount_client $MOUNT || error "Unable to unmount client"
4764         stop_ost2 || error "Unable to stop OST2"
4765         stop_mds || error "Unable to stop MDS"
4766         #writeconf to remove all ost2 traces for subsequent tests
4767         writeconf_or_reformat
4768 }
4769 run_test 50d "lazystatfs client/server conn race"
4770
4771 test_50e() {
4772         local RC1
4773         local pid
4774
4775         reformat_and_config
4776         start_mds || error "Unable to start MDS"
4777         #first client should see only one ost
4778         start_ost || error "Unable to start OST1"
4779         wait_osc_import_state mds ost FULL
4780
4781         # Wait for client to detect down OST
4782         stop_ost || error "Unable to stop OST1"
4783         wait_osc_import_state mds ost DISCONN
4784
4785         mount_client $MOUNT || error "Unable to mount client"
4786         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
4787
4788         multiop_bg_pause $MOUNT _f
4789         RC1=$?
4790         pid=$!
4791
4792         if [ $RC1 -ne 0 ]; then
4793                 log "multiop failed $RC1"
4794         else
4795             kill -USR1 $pid
4796             sleep $(( $TIMEOUT+1 ))
4797             kill -0 $pid
4798             [ $? -ne 0 ] && error "process isn't sleep"
4799             start_ost || error "Unable to start OST1"
4800             wait $pid || error "statfs failed"
4801         fi
4802
4803         umount_client $MOUNT || error "Unable to unmount client"
4804         stop_ost || error "Unable to stop OST1"
4805         stop_mds || error "Unable to stop MDS"
4806 }
4807 run_test 50e "normal statfs all servers down"
4808
4809 test_50f() {
4810         local RC1
4811         local pid
4812         CONN_PROC="osc.$FSNAME-OST0001-osc-[M]*.ost_server_uuid"
4813
4814         start_mds || error "Unable to start mds"
4815         #first client should see only one ost
4816         start_ost || error "Unable to start OST1"
4817         wait_osc_import_state mds ost FULL
4818
4819         start_ost2 || error "Unable to start OST2"
4820         wait_osc_import_state mds ost2 FULL
4821
4822         # Wait for client to detect down OST
4823         stop_ost2 || error "Unable to stop OST2"
4824
4825         wait_osc_import_state mds ost2 DISCONN
4826         mount_client $MOUNT || error "Unable to mount client"
4827         $LCTL set_param llite.$FSNAME-*.lazystatfs=0
4828
4829         multiop_bg_pause $MOUNT _f
4830         RC1=$?
4831         pid=$!
4832
4833         if [ $RC1 -ne 0 ]; then
4834                 log "lazystatfs multiop failed $RC1"
4835         else
4836             kill -USR1 $pid
4837             sleep $(( $TIMEOUT+1 ))
4838             kill -0 $pid
4839             [ $? -ne 0 ] && error "process isn't sleep"
4840             start_ost2 || error "Unable to start OST2"
4841             wait $pid || error "statfs failed"
4842             stop_ost2 || error "Unable to stop OST2"
4843         fi
4844
4845         umount_client $MOUNT -f || error "Unable to unmount client"
4846         stop_ost || error "Unable to stop OST1"
4847         stop_mds || error "Unable to stop MDS"
4848         #writeconf to remove all ost2 traces for subsequent tests
4849         writeconf_or_reformat
4850 }
4851 run_test 50f "normal statfs one server in down"
4852
4853 test_50g() {
4854         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs"
4855         setup
4856         start_ost2 || error "Unable to start OST2"
4857         wait_osc_import_state mds ost2 FULL
4858         wait_osc_import_ready client ost2
4859
4860         if [[ $PERM_CMD == *"set_param -P"* ]]; then
4861                 local PARAM="osc.${FSNAME}-OST0001*.active"
4862         else
4863                 local PARAM="${FSNAME}-OST0001.osc.active"
4864         fi
4865
4866         $LFS setstripe -c -1 $DIR/$tfile || error "$LFS setstripe failed"
4867         do_facet mgs $PERM_CMD $PARAM=0 || error "Unable to deactivate OST"
4868
4869         umount_client $MOUNT || error "Unable to unmount client"
4870         mount_client $MOUNT || error "Unable to mount client"
4871         # This df should not cause a panic
4872         df -k $MOUNT
4873
4874         do_facet mgs $PERM_CMD $PARAM=1 || error "Unable to activate OST"
4875         rm -f $DIR/$tfile || error "unable to remove file $DIR/$tfile"
4876         umount_client $MOUNT || error "Unable to unmount client"
4877         stop_ost2 || error "Unable to stop OST2"
4878         stop_ost || error "Unable to stop OST1"
4879         stop_mds || error "Unable to stop MDS"
4880         #writeconf to remove all ost2 traces for subsequent tests
4881         writeconf_or_reformat
4882 }
4883 run_test 50g "deactivated OST should not cause panic"
4884
4885 # LU-642
4886 test_50h() {
4887         # prepare MDT/OST, make OSC inactive for OST1
4888         [ "$OSTCOUNT" -lt "2" ] && skip_env "needs >=2 OSTs"
4889
4890         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
4891         do_facet ost1 "$TUNEFS --param osc.active=0 `ostdevname 1`" ||
4892                 error "tunefs OST1 failed"
4893         start_mds  || error "Unable to start MDT"
4894         start_ost  || error "Unable to start OST1"
4895         start_ost2 || error "Unable to start OST2"
4896         mount_client $MOUNT || error "client start failed"
4897
4898         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4899
4900         # activatate OSC for OST1
4901         set_persistent_param_and_check client            \
4902                 "osc.${FSNAME}-OST0000-osc-[!M]*.active" \
4903                 "${FSNAME}-OST0000.osc.active" 1
4904
4905         mkdir $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
4906         $LFS setstripe -c -1 -i 0 $DIR/$tdir/2 ||
4907                 error "$LFS setstripe $DIR/$tdir/2 failed"
4908         sleep 1 && echo "create a file after OST1 is activated"
4909         # doing some io, shouldn't crash
4910         dd if=/dev/zero of=$DIR/$tdir/2/$tfile-io bs=1M count=10
4911
4912         # check OSC import is working
4913         stat $DIR/$tdir/2/* >/dev/null 2>&1 ||
4914                 error "some OSC imports are still not connected"
4915
4916         # cleanup
4917         rm -rf $DIR/$tdir
4918         umount_client $MOUNT || error "Unable to umount client"
4919         stop_ost2 || error "Unable to stop OST2"
4920         cleanup_nocli || error "cleanup_nocli failed with $?"
4921 }
4922 run_test 50h "LU-642: activate deactivated OST"
4923
4924 test_50i() {
4925         # prepare MDT/OST, make OSC inactive for OST1
4926         [ "$MDSCOUNT" -lt "2" ] && skip "needs >= 2 MDTs"
4927
4928         load_modules
4929         [ $(facet_fstype mds2) == zfs ] && import_zpool mds2
4930         do_facet mds2 "$TUNEFS --param mdc.active=0 $(mdsdevname 2)" ||
4931                 error "tunefs MDT2 failed"
4932         start_mds  || error "Unable to start MDT"
4933         start_ost  || error "Unable to start OST1"
4934         start_ost2 || error "Unable to start OST2"
4935         mount_client $MOUNT || error "client start failed"
4936
4937         mkdir_on_mdt0 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
4938
4939         if [[ $PERM_CMD == *"set_param -P"* ]]; then
4940                 $PERM_CMD mdc.${FSNAME}-MDT0001-mdc-*.active=0 &&
4941                         error "deactive MDC0 succeeds"
4942         else
4943                 $PERM_CMD ${FSNAME}-MDT0000.mdc.active=0 &&
4944                         error "deactive MDC0 succeeds"
4945         fi
4946
4947         # activate MDC for MDT2
4948         set_persistent_param_and_check client            \
4949                 "mdc.${FSNAME}-MDT0001-mdc-*.active" \
4950                 "${FSNAME}-MDT0001.mdc.active" 1
4951
4952         wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds2 FULL
4953         if [ "$MDS1_VERSION" -ge $(version_code 2.7.60) ]
4954         then
4955                 wait_dne_interconnect
4956         fi
4957         $LFS mkdir -i1 $DIR/$tdir/2 || error "mkdir $DIR/$tdir/2 failed"
4958         # create some file
4959         createmany -o $DIR/$tdir/2/$tfile-%d 1 || error "create files failed"
4960
4961         rm -rf $DIR/$tdir/2 || error "unlink dir failed"
4962
4963         # deactivate MDC for MDT2
4964         set_persistent_param_and_check client           \
4965                 "mdc.${FSNAME}-MDT0001-mdc-*.active"    \
4966                 "${FSNAME}-MDT0001.mdc.active" 0
4967
4968         wait_osp_active mds ${FSNAME}-MDT0001 1 0
4969
4970         $LFS mkdir -i1 $DIR/$tdir/2 &&
4971                 error "mkdir $DIR/$tdir/2 succeeds after deactive MDT"
4972
4973         $LFS mkdir -i0 -c$MDSCOUNT $DIR/$tdir/striped_dir ||
4974                 error "mkdir $DIR/$tdir/striped_dir fails after deactive MDT2"
4975
4976         local stripe_count=$($LFS getdirstripe -c $DIR/$tdir/striped_dir)
4977         [ $stripe_count -eq $((MDSCOUNT - 1)) ] ||
4978                 error "wrong $stripe_count != $((MDSCOUNT -1)) for striped_dir"
4979
4980         # cleanup
4981         umount_client $MOUNT || error "Unable to umount client"
4982         stop_mds
4983         stop_ost
4984         stop_ost 2
4985 }
4986 run_test 50i "activate deactivated MDT"
4987
4988 test_51() {
4989         local LOCAL_TIMEOUT=20
4990
4991         reformat
4992         setup_noconfig
4993         check_mount || error "check_mount failed"
4994
4995         mkdir_on_mdt0 $MOUNT/$tdir || error "mkdir $MOUNT/$tdir failed"
4996         $LFS setstripe -c -1 $MOUNT/$tdir ||
4997                 error "$LFS setstripe -c -1 $MOUNT/$tdir failed"
4998         #define OBD_FAIL_MDS_REINT_DELAY         0x142
4999         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0x142"
5000         touch $MOUNT/$tdir/$tfile &
5001         local pid=$!
5002         sleep 2
5003         start_ost2 || error "Unable to start OST1"
5004         wait $pid
5005         stop_ost2 || error "Unable to stop OST1"
5006         umount_client $MOUNT -f || error "unmount $MOUNT failed"
5007         cleanup_nocli || error "stop server failed"
5008         #writeconf to remove all ost2 traces for subsequent tests
5009         writeconf_or_reformat
5010 }
5011 run_test 51 "Verify that mdt_reint handles RMF_MDT_MD correctly when an OST is added"
5012
5013 copy_files_xattrs()
5014 {
5015         local node=$1
5016         local dest=$2
5017         local xattrs=$3
5018         shift 3
5019
5020         do_node $node mkdir -p $dest
5021         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
5022
5023         do_node $node  'tar cf - '$*' | tar xf - -C '$dest';
5024                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
5025         [ $? -eq 0 ] || { error "Unable to tar files"; return 2; }
5026
5027         do_node $node 'getfattr -d -m "[a-z]*\\." '$*' > '$xattrs
5028         [ $? -eq 0 ] || { error "Unable to read xattrs"; return 3; }
5029 }
5030
5031 diff_files_xattrs()
5032 {
5033         local node=$1
5034         local backup=$2
5035         local xattrs=$3
5036         shift 3
5037
5038         local backup2=${TMP}/backup2
5039
5040         do_node $node mkdir -p $backup2
5041         [ $? -eq 0 ] || { error "Unable to create directory"; return 1; }
5042
5043         do_node $node  'tar cf - '$*' | tar xf - -C '$backup2';
5044                         [ \"\${PIPESTATUS[*]}\" = \"0 0\" ] || exit 1'
5045         [ $? -eq 0 ] || { error "Unable to tar files to diff"; return 2; }
5046
5047         do_node $node "diff -rq $backup $backup2"
5048         [ $? -eq 0 ] || { error "contents differ"; return 3; }
5049
5050         local xattrs2=${TMP}/xattrs2
5051         do_node $node 'getfattr -d -m "[a-z]*\\." '$*' > '$xattrs2
5052         [ $? -eq 0 ] || { error "Unable to read xattrs to diff"; return 4; }
5053
5054         do_node $node "diff $xattrs $xattrs2"
5055         [ $? -eq 0 ] || { error "xattrs differ"; return 5; }
5056
5057         do_node $node "rm -rf $backup2 $xattrs2"
5058         [ $? -eq 0 ] || { error "Unable to delete temporary files"; return 6; }
5059 }
5060
5061 test_52() {
5062         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5063                 skip "ldiskfs only test"
5064         fi
5065
5066         start_mds || error "Unable to start MDS"
5067         start_ost || error "Unable to start OST1"
5068         mount_client $MOUNT || error "Unable to mount client"
5069
5070         local nrfiles=8
5071         local ost1mnt=$(facet_mntpt ost1)
5072         local ost1node=$(facet_active_host ost1)
5073         local ost1tmp=$TMP/conf52
5074         local loop
5075
5076         mkdir $DIR/$tdir || error "Unable to create $DIR/$tdir"
5077         touch $TMP/modified_first || error "Unable to create temporary file"
5078         local mtime=$(stat -c %Y $TMP/modified_first)
5079         do_node $ost1node "mkdir -p $ost1tmp &&
5080                            touch -m -d @$mtime $ost1tmp/modified_first" ||
5081                 error "Unable to create temporary file"
5082         sleep 1
5083
5084         $LFS setstripe -c -1 -S 1M $DIR/$tdir || error "$LFS setstripe failed"
5085
5086         for (( i=0; i < nrfiles; i++ )); do
5087                 multiop $DIR/$tdir/$tfile-$i Ow1048576w1048576w524288c ||
5088                         error "multiop failed"
5089                 echo -n .
5090         done
5091         echo
5092
5093         # sync all the data and make sure no pending data on the client,
5094         # thus the SOM xattr would not be changed any more.
5095         cancel_lru_locks osc
5096
5097         # backup files
5098         echo backup files to $TMP/$tdir
5099         local files=$(find $DIR/$tdir -type f -newer $TMP/modified_first)
5100         copy_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
5101                 error "Unable to copy files"
5102
5103         umount_client $MOUNT || error "Unable to umount client"
5104         stop_ost || error "Unable to stop ost1"
5105
5106         echo mount ost1 as ldiskfs
5107         do_node $ost1node mkdir -p $ost1mnt || error "Unable to create $ost1mnt"
5108         if ! do_node $ost1node test -b $ost1_dev; then
5109                 loop="-o loop"
5110         fi
5111         do_node $ost1node mount -t "$ost1_FSTYPE" $loop $ost1_dev \
5112                 $ost1mnt ||
5113                 error "Unable to mount ost1 as ldiskfs"
5114
5115         # backup objects
5116         echo backup objects to $ost1tmp/objects
5117         local objects=$(do_node $ost1node 'find '$ost1mnt'/O/[0-9]* -type f'\
5118                 '-size +0 -newer '$ost1tmp'/modified_first -regex ".*\/[0-9]+"')
5119         copy_files_xattrs $ost1node $ost1tmp/objects $ost1tmp/object_xattrs \
5120                         $objects ||
5121                 error "Unable to copy objects"
5122
5123         # move objects to lost+found
5124         do_node $ost1node 'mv '$objects' '${ost1mnt}'/lost+found'
5125         [ $? -eq 0 ] || { error "Unable to move objects"; return 14; }
5126
5127         do_node $ost1node "umount $ost1mnt" ||
5128                 error "Unable to umount ost1 as ldiskfs"
5129
5130         start_ost || error "Unable to start OST1"
5131         mount_client $MOUNT || error "Unable to mount client"
5132
5133         local REPAIRED=$(do_node $ost1node "$LCTL get_param \
5134                          -n osd-ldiskfs.$FSNAME-OST0000.oi_scrub" |
5135                          awk '/^lf_repa[ri]*ed/ { print $2 }')
5136         [ $REPAIRED -gt 0 ] ||
5137                 error "Some entry under /lost+found should be repaired"
5138
5139         # compare files
5140         diff_files_xattrs $(hostname) $TMP/$tdir $TMP/file_xattrs $files ||
5141                 error "Unable to diff files"
5142
5143         rm -rf $TMP/$tdir $TMP/file_xattrs ||
5144                 error "Unable to delete temporary files"
5145         do_node $ost1node "rm -rf $ost1tmp" ||
5146                 error "Unable to delete temporary files"
5147         cleanup || error "cleanup failed with $?"
5148 }
5149 run_test 52 "check recovering objects from lost+found"
5150
5151 # Checks threads_min/max/started for some service
5152 #
5153 # Arguments: service name (OST or MDT), facet (e.g., ost1, $SINGLEMDS), and a
5154 # parameter pattern prefix like 'ost.*.ost'.
5155 thread_sanity() {
5156         local modname=$1
5157         local facet=$2
5158         local parampat=$3
5159         local opts=$4
5160         local basethr=$5
5161         local tmin
5162         local tmin2
5163         local tmax
5164         local tmax2
5165         local tstarted
5166         local paramp
5167         local msg="Insane $modname thread counts"
5168         local ncpts=$(check_cpt_number $facet)
5169         local nthrs
5170         shift 4
5171
5172         check_mount || return 41
5173
5174         # We need to expand $parampat, but it may match multiple parameters, so
5175         # we'll pick the first one
5176         if ! paramp=$(do_facet $facet "lctl get_param -N ${parampat}.threads_min"|head -1); then
5177                 error "Couldn't expand ${parampat}.threads_min parameter name"
5178                 return 22
5179         fi
5180
5181         # Remove the .threads_min part
5182         paramp=${paramp%.threads_min}
5183
5184         # Check for sanity in defaults
5185         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
5186                echo 0)
5187         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
5188                echo 0)
5189         tstarted=$(do_facet $facet "$LCTL get_param \
5190                                     -n ${paramp}.threads_started" || echo 0)
5191         lassert 23 "$msg (PDSH problems?)" '(($tstarted && $tmin && $tmax))' ||
5192                 return $?
5193         lassert 24 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
5194                 return $?
5195         nthrs=$(expr $tmax - $tmin)
5196         if [ $nthrs -lt $ncpts ]; then
5197                 nthrs=0
5198         else
5199                 nthrs=$ncpts
5200         fi
5201
5202         [ $tmin -eq $tmax -a $tmin -eq $tstarted ] &&
5203                 skip_env "module parameter forced $facet thread count"
5204
5205         # Check that we can change min/max
5206         do_facet $facet "$LCTL set_param \
5207                          ${paramp}.threads_min=$((tmin + nthrs))"
5208         do_facet $facet "$LCTL set_param \
5209                          ${paramp}.threads_max=$((tmax - nthrs))"
5210         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
5211                 echo 0)
5212         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
5213                 echo 0)
5214         lassert 25 "$msg" '(($tmin2 == ($tmin + $nthrs) &&
5215                             $tmax2 == ($tmax - $nthrs)))' || return $?
5216
5217         # Check that we can set min/max to the same value
5218         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
5219                echo 0)
5220         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$tmin"
5221         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
5222                 echo 0)
5223         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
5224                 echo 0)
5225         lassert 26 "$msg" '(($tmin2 == $tmin && $tmax2 == $tmin))' || return $?
5226
5227         # Check that we can't set max < min
5228         do_facet $facet "$LCTL set_param ${paramp}.threads_max=$((tmin - 1))"
5229         tmin2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
5230                 echo 0)
5231         tmax2=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
5232                 echo 0)
5233         lassert 27 "$msg" '(($tmin2 <= $tmax2))' || return $?
5234
5235         # We need to ensure that we get the module options desired; to do this
5236         # we set LOAD_MODULES_REMOTE=true and we call setmodopts below.
5237         LOAD_MODULES_REMOTE=true
5238         cleanup
5239         local oldvalue
5240         local newvalue="${opts}=$(expr $basethr \* $ncpts)"
5241
5242         setmodopts -a $modname "$newvalue" oldvalue
5243
5244         setup
5245         check_mount || return 41
5246
5247         # Restore previous setting of MODOPTS_*
5248         setmodopts $modname "$oldvalue"
5249
5250         (( $MDS1_VERSION > $(version_code 2.12.52.91) )) || {
5251                 echo "skip interop for MDS < v2_12_52-91-g183cb1e3cdd2"
5252                 return 0
5253         }
5254
5255         # Check that $opts took
5256         tmin=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_min" ||
5257                 echo 0)
5258         tmax=$(do_facet $facet "$LCTL get_param -n ${paramp}.threads_max" ||
5259                 echo 0)
5260         tstarted=$(do_facet $facet \
5261                    "$LCTL get_param -n ${paramp}.threads_started" || echo 0)
5262         lassert 28 "$msg" '(($tstarted >= $tmin && $tstarted <= $tmax ))' ||
5263                 return $?
5264 }
5265
5266 test_53a() {
5267         setup
5268         thread_sanity OST ost1 'ost.*.ost' 'oss_num_threads' '16'
5269         cleanup || error "cleanup failed with rc $?"
5270 }
5271 run_test 53a "check OSS thread count params"
5272
5273 test_53b() {
5274         setup
5275         thread_sanity MDT $SINGLEMDS 'mds.*.*.' 'mds_num_threads' 16
5276         cleanup || error "cleanup failed with $?"
5277 }
5278 run_test 53b "check MDS thread count params"
5279
5280 test_54a() {
5281         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5282                 skip "ldiskfs only test"
5283         fi
5284
5285         do_rpc_nodes $(facet_host ost1) run_llverdev $(ostdevname 1) -p ||
5286                 error "llverdev failed with rc=$?"
5287         reformat_and_config
5288 }
5289 run_test 54a "test llverdev and partial verify of device"
5290
5291 test_54b() {
5292         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5293                 skip "ldiskfs only test"
5294         fi
5295
5296         setup
5297         run_llverfs $MOUNT -p || error "llverfs failed with rc=$?"
5298         cleanup || error "cleanup failed with rc=$?"
5299 }
5300 run_test 54b "test llverfs and partial verify of filesystem"
5301
5302 lov_objid_size()
5303 {
5304         local max_ost_index=$1
5305
5306         echo -n $(((max_ost_index + 1) * 8))
5307 }
5308
5309 test_55() {
5310         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5311                 skip "ldiskfs only test"
5312         fi
5313
5314         local mdsdev=$(mdsdevname 1)
5315         local mdsvdev=$(mdsvdevname 1)
5316
5317         for i in 1023 2048
5318         do
5319                 if ! combined_mgs_mds; then
5320                         stop_mgs || error "stopping MGS service failed"
5321                         format_mgs || error "formatting MGT failed"
5322                 fi
5323                 add mds1 $(mkfs_opts mds1 ${mdsdev}) --reformat $mdsdev \
5324                         $mdsvdev || exit 10
5325                 add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=$i \
5326                         --reformat $(ostdevname 1) $(ostvdevname 1)
5327                 setup_noconfig
5328                 stopall
5329                 setup_noconfig
5330                 sync
5331
5332                 echo checking size of lov_objid for ost index $i
5333                 LOV_OBJID_SIZE=$(do_facet mds1 "$DEBUGFS -R 'stat lov_objid' $mdsdev 2>/dev/null" |
5334                                  grep ^User | awk -F 'Size: ' '{print $2}')
5335                 if [ "$LOV_OBJID_SIZE" != $(lov_objid_size $i) ]; then
5336                         error "lov_objid size has to be $(lov_objid_size $i), not $LOV_OBJID_SIZE"
5337                 else
5338                         echo ok, lov_objid size is correct: $LOV_OBJID_SIZE
5339                 fi
5340                 stopall
5341         done
5342
5343         reformat_and_config
5344 }
5345 run_test 55 "check lov_objid size"
5346
5347 test_56a() {
5348         local mds_journal_size_orig=$MDSJOURNALSIZE
5349         local n
5350
5351         MDSJOURNALSIZE=16
5352
5353         formatall
5354         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --index=10000 --reformat \
5355                 $(ostdevname 1) $(ostvdevname 1)
5356         add ost2 $(mkfs_opts ost2 $(ostdevname 2)) --index=1000 --reformat \
5357                 $(ostdevname 2) $(ostvdevname 2)
5358
5359         start_mgsmds
5360         start_ost || error "Unable to start first ost (idx 10000)"
5361         start_ost2 || error "Unable to start second ost (idx 1000)"
5362         mount_client $MOUNT || error "Unable to mount client"
5363         echo ok
5364         $LFS osts
5365
5366         # test instantiating PFL components with sparse index LU-15513
5367         mkdir -p $MOUNT/$tdir
5368         $LFS setstripe -E 4M -c 1 -E 1G -c 4 -S4M -E eof -c -1 $MOUNT/$tdir
5369         dd if=/dev/zero of=$MOUNT/$tdir/$tfile bs=4K count=1 seek=10k ||
5370                 error "dd to second component failed"
5371
5372         if [[ "$MDS1_VERSION" -ge $(version_code 2.6.54) ]] ||
5373            [[ "$MDS1_VERSION" -ge $(version_code 2.5.4) &&
5374               "$MDS1_VERSION" -lt $(version_code 2.5.11) ]]; then
5375                 wait_osc_import_state mds ost1 FULL
5376                 wait_osc_import_state mds ost2 FULL
5377                 $LFS setstripe --stripe-count=-1 $DIR/$tfile ||
5378                         error "Unable to setstripe $DIR/$tfile"
5379                 n=$($LFS getstripe --stripe-count $DIR/$tfile)
5380                 [ "$n" -eq 2 ] || error "Stripe count not two: $n"
5381                 rm $DIR/$tfile
5382         fi
5383
5384         stopall
5385         MDSJOURNALSIZE=$mds_journal_size_orig
5386         reformat_and_config
5387 }
5388 run_test 56a "check big OST indexes and out-of-index-order start"
5389
5390 cleanup_56b() {
5391         trap 0
5392
5393         umount_client $MOUNT -f || error "unmount client failed"
5394         stop mds1
5395         stop mds2
5396         stop mds3
5397         stopall
5398         reformat_and_config
5399 }
5400
5401 test_56b() {
5402         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs"
5403
5404         trap cleanup_56b EXIT RETURN ERR
5405         stopall
5406
5407         if ! combined_mgs_mds ; then
5408                 format_mgs
5409                 start_mgs
5410         fi
5411
5412         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) --index=0 --reformat \
5413                 $(mdsdevname 1) $(mdsvdevname 1)
5414         add mds2 $(mkfs_opts mds2 $(mdsdevname 2)) --index=1 --reformat \
5415                 $(mdsdevname 2) $(mdsvdevname 2)
5416         add mds3 $(mkfs_opts mds3 $(mdsdevname 3)) --index=1000 --reformat \
5417                 $(mdsdevname 3) $(mdsvdevname 3)
5418         format_ost 1
5419         format_ost 2
5420
5421         start_mdt 1 || error "MDT 1 (idx 0) start failed"
5422         start_mdt 2 || error "MDT 2 (idx 1) start failed"
5423         start_mdt 3 || error "MDT 3 (idx 1000) start failed"
5424         start_ost || error "Unable to start first ost"
5425         start_ost2 || error "Unable to start second ost"
5426
5427         do_nodes $(mdts_nodes) "$LCTL set_param mdt.*.enable_remote_dir=1 \
5428                 mdt.*.enable_remote_dir_gid=-1"
5429
5430         mount_client $MOUNT || error "Unable to mount client"
5431
5432         $LFS mkdir -c3 $MOUNT/$tdir || error "failed to make testdir"
5433
5434         echo "This is test file 1!" > $MOUNT/$tdir/$tfile.1 ||
5435                 error "failed to make test file 1"
5436         echo "This is test file 2!" > $MOUNT/$tdir/$tfile.2 ||
5437                 error "failed to make test file 2"
5438         echo "This is test file 1000!" > $MOUNT/$tdir/$tfile.1000 ||
5439                 error "failed to make test file 1000"
5440
5441         rm -rf $MOUNT/$tdir || error "failed to remove testdir"
5442
5443         $LFS mkdir -i1000 $MOUNT/$tdir.1000 ||
5444                 error "create remote dir at idx 1000 failed"
5445
5446         output=$($LFS df)
5447         echo "=== START lfs df OUTPUT ==="
5448         echo -e "$output"
5449         echo "==== END lfs df OUTPUT ===="
5450
5451         mdtcnt=$(echo -e "$output" | grep $FSNAME-MDT | wc -l)
5452         ostcnt=$(echo -e "$output" | grep $FSNAME-OST | wc -l)
5453
5454         echo "lfs df returned mdt count $mdtcnt and ost count $ostcnt"
5455         [ $mdtcnt -eq 3 ] || error "lfs df returned wrong mdt count"
5456         [ $ostcnt -eq 2 ] || error "lfs df returned wrong ost count"
5457
5458         echo "This is test file 1!" > $MOUNT/$tdir.1000/$tfile.1 ||
5459                 error "failed to make test file 1"
5460         echo "This is test file 2!" > $MOUNT/$tdir.1000/$tfile.2 ||
5461                 error "failed to make test file 2"
5462         echo "This is test file 1000!" > $MOUNT/$tdir.1000/$tfile.1000 ||
5463                 error "failed to make test file 1000"
5464         rm -rf $MOUNT/$tdir.1000 || error "failed to remove remote_dir"
5465
5466         output=$($LFS mdts)
5467         echo "=== START lfs mdts OUTPUT ==="
5468         echo -e "$output"
5469         echo "==== END lfs mdts OUTPUT ===="
5470
5471         echo -e "$output" | grep -v "MDTS:" | awk '{print $1}' |
5472                 sed 's/://g' > $TMP/mdts-actual.txt
5473         sort $TMP/mdts-actual.txt -o $TMP/mdts-actual.txt
5474
5475         echo -e "0\n1\n1000" > $TMP/mdts-expected.txt
5476
5477         diff $TMP/mdts-expected.txt $TMP/mdts-actual.txt
5478         result=$?
5479
5480         rm $TMP/mdts-expected.txt $TMP/mdts-actual.txt
5481
5482         [ $result -eq 0 ] || error "target_obd proc file is incorrect!"
5483 }
5484 run_test 56b "test target_obd correctness with nonconsecutive MDTs"
5485
5486 test_57a() { # bug 22656
5487         do_rpc_nodes $(facet_active_host ost1) load_modules_local
5488         local NID=$(do_facet ost1 "$LCTL get_param nis" |
5489                     tail -1 | awk '{print $1}')
5490         writeconf_or_reformat
5491         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
5492         do_facet ost1 "$TUNEFS --failnode=$NID `ostdevname 1`" ||
5493                 error "tunefs failed"
5494         start_mgsmds
5495         start_ost && error "OST registration from failnode should fail"
5496         cleanup
5497 }
5498 run_test 57a "initial registration from failnode should fail (should return errs)"
5499
5500 test_57b() {
5501         do_rpc_nodes $(facet_active_host ost1) load_modules_local
5502         local NID=$(do_facet ost1 "$LCTL get_param nis" |
5503                     tail -1 | awk '{print $1}')
5504         writeconf_or_reformat
5505         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
5506         do_facet ost1 "$TUNEFS --servicenode=$NID `ostdevname 1`" ||
5507                 error "tunefs failed"
5508         start_mgsmds
5509         start_ost || error "OST registration from servicenode should not fail"
5510         cleanup
5511 }
5512 run_test 57b "initial registration from servicenode should not fail"
5513
5514 count_osts() {
5515         do_facet mgs $LCTL get_param mgs.MGS.live.$FSNAME | grep OST | wc -l
5516 }
5517
5518 test_58() { # bug 22658
5519         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
5520         setup_noconfig
5521         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
5522         createmany -o $DIR/$tdir/$tfile-%d 100
5523         unlinkmany $DIR/$tdir/$tfile-%d 100
5524         stop_mds || error "Unable to stop MDS"
5525
5526         local MNTDIR=$(facet_mntpt $SINGLEMDS)
5527         local devname=$(mdsdevname ${SINGLEMDS//mds/})
5528
5529         # remove all files from the OBJECTS dir
5530         mount_fstype $SINGLEMDS
5531
5532         do_facet $SINGLEMDS "find $MNTDIR/O/1/d* -type f -delete"
5533
5534         unmount_fstype $SINGLEMDS
5535         # restart MDS with missing llog files
5536         start_mds || error "unable to start MDS"
5537         do_facet $SINGLEMDS "$LCTL set_param fail_loc=0"
5538         cleanup
5539 }
5540 run_test 58 "missing llog files must not prevent MDT from mounting"
5541
5542 test_59() {
5543         start_mgsmds >> /dev/null
5544         local C1=$(count_osts)
5545         if [ $C1 -eq 0 ]; then
5546                 start_ost >> /dev/null
5547                 C1=$(count_osts)
5548         fi
5549         stopall
5550         echo "original ost count: $C1 (expect > 0)"
5551         [ $C1 -gt 0 ] || error "No OSTs in $FSNAME log"
5552         start_mgsmds -o writeconf >> /dev/null || error "MDT start failed"
5553         local C2=$(count_osts)
5554         echo "after mdt writeconf count: $C2 (expect 0)"
5555         [ $C2 -gt 0 ] && error "MDT writeconf should erase OST logs"
5556         echo "OST start without writeconf should fail:"
5557         start_ost >> /dev/null &&
5558                 error "OST start without writeconf didn't fail"
5559         echo "OST start with writeconf should succeed:"
5560         start_ost -o writeconf >> /dev/null || error "OST1 start failed"
5561         local C3=$(count_osts)
5562         echo "after ost writeconf count: $C3 (expect 1)"
5563         [ $C3 -eq 1 ] || error "new OST writeconf should add:"
5564         start_ost2 -o writeconf >> /dev/null || error "OST2 start failed"
5565         local C4=$(count_osts)
5566         echo "after ost2 writeconf count: $C4 (expect 2)"
5567         [ $C4 -eq 2 ] || error "OST2 writeconf should add log"
5568         stop_ost2 >> /dev/null
5569         cleanup_nocli >> /dev/null
5570         #writeconf to remove all ost2 traces for subsequent tests
5571         writeconf_or_reformat
5572 }
5573 run_test 59 "writeconf mount option"
5574
5575 test_60a() { # LU-471
5576         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5577                 skip "ldiskfs only test"
5578         fi
5579
5580         local num
5581
5582         for num in $(seq $MDSCOUNT); do
5583                 add mds${num} $(mkfs_opts mds${num} $(mdsdevname $num)) \
5584                         --mkfsoptions='\" -E stride=64 -O ^uninit_bg\"' \
5585                         --reformat $(mdsdevname $num) $(mdsvdevname $num) ||
5586                         exit 10
5587         done
5588
5589         dump=$(do_facet $SINGLEMDS dumpe2fs $(mdsdevname 1))
5590         [ ${PIPESTATUS[0]} -eq 0 ] || error "dumpe2fs $(mdsdevname 1) failed"
5591
5592         # MDT default has dirdata feature
5593         echo $dump | grep dirdata > /dev/null || error "dirdata is not set"
5594         # we disable uninit_bg feature
5595         echo $dump | grep uninit_bg > /dev/null && error "uninit_bg is set"
5596         # we set stride extended options
5597         echo $dump | grep stride > /dev/null || error "stride is not set"
5598         stop_mds
5599         reformat_and_config
5600 }
5601 run_test 60a "check mkfs.lustre --mkfsoptions -E -O options setting"
5602
5603 test_60b() {
5604         [[ "$mds1_FSTYPE" == ldiskfs ]] || skip "ldiskfs only test"
5605
5606         local features=$(do_facet $SINGLEMDS $DUMPE2FS $(mdsdevname 1) |
5607                          grep features)
5608         [ ${PIPESTATUS[0]} -eq 0 ] || error "$DUMPE2FS $(mdsdevname 1) failed"
5609
5610         echo $features
5611         # ea_inode feature should be enabled by default for MDTs
5612         [[ "$features" =~ "ea_inode" ]] || error "ea_inode is not set"
5613         # large_dir feature should be enabled by default for MDTs
5614         [[ "$features" =~ "large_dir" ]] || error "large_dir is not set"
5615 }
5616 run_test 60b "check mkfs.lustre MDT default features"
5617
5618 test_61a() { # LU-80
5619         local lxattr=$(large_xattr_enabled)
5620
5621         (( "$MDS1_VERSION" >= $(version_code 2.1.53) )) ||
5622                 skip "Need MDS version at least 2.1.53 for large_xattr"
5623
5624         if [[ "$mds1_FSTYPE" == ldiskfs ]] && ! large_xattr_enabled; then
5625                 lxattr=true
5626
5627                 for ((num=1; num <= $MDSCOUNT; num++)); do
5628                         do_facet mds${num} $TUNE2FS -O ea_inode \
5629                                 $(mdsdevname $num) ||
5630                                 error "tune2fs on mds $num failed"
5631                 done
5632         fi
5633
5634         setup || error "setting up the filesystem failed"
5635         client_up || error "starting client failed"
5636
5637         local file=$DIR/$tfile
5638         touch $file || error "touch $file failed"
5639
5640         local large_value="$(generate_string $(max_xattr_size))"
5641         local small_value="bar"
5642
5643         local name="trusted.big"
5644         log "save large xattr of $(max_xattr_size) bytes on $name on $file"
5645         setfattr -n $name -v $large_value $file ||
5646                 error "saving $name on $file failed"
5647
5648         local new_value=$(get_xattr_value $name $file)
5649         [[ "$new_value" != "$large_value" ]] &&
5650                 error "$name different after saving"
5651
5652         log "shrink value of $name on $file"
5653         setfattr -n $name -v $small_value $file ||
5654                 error "shrinking value of $name on $file failed"
5655
5656         new_value=$(get_xattr_value $name $file)
5657         [[ "$new_value" != "$small_value" ]] &&
5658                 error "$name different after shrinking"
5659
5660         log "grow value of $name on $file"
5661         setfattr -n $name -v $large_value $file ||
5662                 error "growing value of $name on $file failed"
5663
5664         new_value=$(get_xattr_value $name $file)
5665         [[ "$new_value" != "$large_value" ]] &&
5666                 error "$name different after growing"
5667
5668         log "check value of $name on $file after remounting MDS"
5669         fail $SINGLEMDS
5670         new_value=$(get_xattr_value $name $file)
5671         [[ "$new_value" != "$large_value" ]] &&
5672                 error "$name different after remounting MDS"
5673
5674         log "remove large xattr $name from $file"
5675         setfattr -x $name $file || error "removing $name from $file failed"
5676
5677         if $lxattr && [ "$mds1_FSTYPE" == ldiskfs ]; then
5678                 stopall || error "stopping for e2fsck run"
5679                 for num in $(seq $MDSCOUNT); do
5680                         run_e2fsck $(facet_active_host mds$num) \
5681                                 $(mdsdevname $num) "-y" ||
5682                                 error "e2fsck MDT$num failed"
5683                 done
5684                 setup_noconfig || error "remounting the filesystem failed"
5685         fi
5686
5687         # need to delete this file to avoid problems in other tests
5688         rm -f $file
5689         cleanup || error "stopping systems failed"
5690 }
5691 run_test 61a "large xattr"
5692
5693 test_61b() { # LU-80
5694         local lxattr=$(large_xattr_enabled)
5695
5696         (( $MDS1_VERSION >= $(version_code 2.15.51) )) ||
5697                 skip "Need MDS version at least 2.15.51 for large_xattr fix"
5698
5699         [[ "$mds1_FSTYPE" == "ldiskfs" ]] || skip "ldiskfs specific bug"
5700
5701         if ! large_xattr_enabled; then
5702                 lxattr=true
5703
5704                 for (( num=1; num <= $MDSCOUNT; num++ )); do
5705                         do_facet mds${num} $TUNE2FS -O ea_inode \
5706                                 $(mdsdevname $num) ||
5707                                 error "tune2fs on mds $num failed"
5708                 done
5709         fi
5710
5711         setup || error "setting up the filesystem failed"
5712         client_up || error "starting client failed"
5713
5714         local _file=$MOUNT/panda
5715         local large_value="$(generate_string $(max_xattr_size))"
5716         local name="trusted.big"
5717
5718         touch ${_file} || error "touch ${_file} failed"
5719         setfattr -n $name -v $large_value ${_file} ||
5720                 error "saving $name on $file failed"
5721
5722         MDT_DEV="${FSNAME}-MDT0000"
5723         MDT_DEVNAME=$(mdsdevname ${SINGLEMDS//mds/})
5724
5725         stopall || error "stopping for e2fsck run"
5726
5727
5728         ino=$(do_facet $SINGLEMDS "$DEBUGFS -R 'stat /ROOT/panda' \
5729                 ${MDT_DEVNAME} | grep trusted.big")
5730         ino=$(echo "${ino}" | awk '{print $2;}')
5731         echo "large ea "${ino}
5732
5733         do_facet $SINGLEMDS "$DEBUGFS -w -R \\\"ln $ino /lost+found\\\" \
5734                  ${MDT_DEVNAME}"
5735
5736         setup_noconfig || error "remounting the filesystem failed"
5737
5738         do_facet $SINGLEMDS $LCTL lfsck_start -M ${MDT_DEV} -t namespace || {
5739                 error "can't start lfsck namespace"
5740         }
5741
5742         sleep 5
5743         wait_update_facet $SINGLEMDS "$LCTL get_param -n \
5744                 mdd.${MDT_DEV}.lfsck_namespace |
5745                 awk '/^status/ { print \\\$2 }'" "completed" 32 || {
5746                 error "(2) unexpected status"
5747         }
5748
5749         stopall || error "stopping for e2fsck run"
5750         for num in $(seq $MDSCOUNT); do
5751                 run_e2fsck $(facet_active_host mds$num) \
5752                         $(mdsdevname $num) "-y" ||
5753                         error "e2fsck MDT$num failed"
5754         done
5755         setup_noconfig || error "remounting the filesystem failed"
5756
5757         # need to delete this file to avoid problems in other tests
5758         rm -f $file
5759         cleanup || error "stopping systems failed"
5760 }
5761 run_test 61b "large xattr"
5762
5763 test_62() {
5764         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5765                 skip "ldiskfs only test"
5766         fi
5767         [[ "$MDS1_VERSION" -ge $(version_code 2.2.51) ]] ||
5768                 skip "Need MDS version at least 2.2.51"
5769
5770         # MRP-118
5771         local mdsdev=$(mdsdevname 1)
5772         local ostdev=$(ostdevname 1)
5773
5774         echo "disable journal for mds"
5775         do_facet mds1 $TUNE2FS -O ^has_journal $mdsdev || error "tune2fs failed"
5776         start_mds && error "MDT start should fail"
5777         echo "disable journal for ost"
5778         do_facet ost1 $TUNE2FS -O ^has_journal $ostdev || error "tune2fs failed"
5779         start_ost && error "OST start should fail"
5780         cleanup || error "cleanup failed with rc $?"
5781         reformat_and_config
5782 }
5783 run_test 62 "start with disabled journal"
5784
5785 test_63() {
5786         if [ "$mds1_FSTYPE" != ldiskfs ]; then
5787                 skip "ldiskfs only test"
5788         fi
5789
5790         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_module ldiskfs
5791         local inode_slab=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
5792                            awk '/ldiskfs_inode_cache/ { print $5 / $6 }')
5793         if [ -z "$inode_slab" ]; then
5794                 skip "ldiskfs module has not been loaded"
5795         fi
5796
5797         if grep -q "CONFIG_DEBUG_LOCK_ALLOC=y" /boot/config-$(uname -r); then
5798                 skip "test is not compatible with CONFIG_DEBUG_LOCK_ALLOC=y"
5799         fi
5800
5801         echo "$inode_slab ldiskfs inodes per page"
5802         [ "${inode_slab%.*}" -ge "3" ] && return 0
5803
5804         # If kmalloc-128 is also 1 per page - this is a debug kernel
5805         # and so this is not an error.
5806         local kmalloc128=$(do_facet $SINGLEMDS "cat /proc/slabinfo" |
5807                            awk '/^(dma-kmalloc|size)-128 / { print $5 / $6 }')
5808         # 32 128-byte chunks in 4k
5809         [ "${kmalloc128%.*}" -lt "32" ] ||
5810                 error "ldiskfs inode too big, only $inode_slab objs/page, " \
5811                       "kmalloc128 = $kmalloc128 objs/page"
5812 }
5813 run_test 63 "Verify each page can at least hold 3 ldiskfs inodes"
5814
5815 test_64() {
5816         start_mds || error "unable to start MDS"
5817         start_ost || error "Unable to start OST1"
5818         start_ost2 || error "Unable to start second ost"
5819         mount_client $MOUNT || error "Unable to mount client"
5820         stop_ost2 || error "Unable to stop second ost"
5821         echo "$LFS df"
5822         $LFS df --lazy
5823         umount_client $MOUNT -f || error "unmount $MOUNT failed"
5824         cleanup_nocli || error "cleanup_nocli failed with $?"
5825         #writeconf to remove all ost2 traces for subsequent tests
5826         writeconf_or_reformat
5827 }
5828 run_test 64 "check lfs df --lazy "
5829
5830 test_65() { # LU-2237
5831         # Currently, the test is only valid for ldiskfs backend
5832         [ "$mds1_FSTYPE" != ldiskfs ] &&
5833                 skip "ldiskfs only test"
5834
5835         local devname=$(mdsdevname ${SINGLEMDS//mds/})
5836         local brpt=$(facet_mntpt brpt)
5837         local opts=""
5838
5839         if ! do_facet $SINGLEMDS "test -b $devname"; then
5840                 opts="-o loop"
5841         fi
5842
5843         stop_mds || error "Unable to stop MDS"
5844         local obj=$(do_facet $SINGLEMDS \
5845                     "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" |
5846                     grep Inode)
5847         if [ -z "$obj" ]; then
5848                 # The MDT may be just re-formatted, mount the MDT for the
5849                 # first time to guarantee the "last_rcvd" file is there.
5850                 start_mds || error "fail to mount the MDS for the first time"
5851                 stop_mds || error "Unable to stop MDS"
5852         fi
5853
5854         # remove the "last_rcvd" file
5855         do_facet $SINGLEMDS "mkdir -p $brpt"
5856         do_facet $SINGLEMDS \
5857                 "mount -t $mds1_FSTYPE $opts $devname $brpt"
5858         do_facet $SINGLEMDS "rm -f ${brpt}/last_rcvd"
5859         do_facet $SINGLEMDS "$UMOUNT $brpt"
5860
5861         # restart MDS, the "last_rcvd" file should be recreated.
5862         start_mds || error "fail to restart the MDS"
5863         stop_mds || error "Unable to stop MDS"
5864         obj=$(do_facet $SINGLEMDS \
5865               "$DEBUGFS -c -R \\\"stat last_rcvd\\\" $devname" | grep Inode)
5866         [ -n "$obj" ] || error "fail to re-create the last_rcvd"
5867 }
5868 run_test 65 "re-create the lost last_rcvd file when server mount"
5869
5870 test_66() {
5871         [[ "$MGS_VERSION" -ge $(version_code 2.3.59) ]] ||
5872                 skip "Need MGS version at least 2.3.59"
5873
5874         check_versions || skip "do not replace_nids with mismatched versions"
5875
5876         setup
5877         local OST1_NID=$(do_facet ost1 $LCTL list_nids | head -1)
5878         local MDS_NID=$(do_facet $SINGLEMDS $LCTL list_nids | head -1)
5879
5880         # add EXCLUDE records to config log, they are not to be
5881         # removed by lctl replace_nids
5882         set_conf_param_and_check mds                                    \
5883             "$LCTL get_param -n osc.$FSNAME-OST0000-osc-MDT0000.active" \
5884             "$FSNAME-OST0000.osc.active"                                \
5885             "0"
5886
5887         echo "replace_nids should fail if MDS, OSTs and clients are UP"
5888         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
5889                 error "replace_nids fail"
5890
5891         umount_client $MOUNT || error "unmounting client failed"
5892         echo "replace_nids should fail if MDS and OSTs are UP"
5893         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
5894                 error "replace_nids fail"
5895
5896         stop_ost || error "Unable to stop OST1"
5897         echo "replace_nids should fail if MDS is UP"
5898         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID &&
5899                 error "replace_nids fail"
5900
5901         stop_mds || error "stopping mds failed"
5902
5903         if combined_mgs_mds; then
5904                 start_mdt 1 "-o nosvc" ||
5905                         error "starting mds with nosvc option failed"
5906         fi
5907
5908         echo "command should accept two parameters"
5909         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 &&
5910                 error "command should accept two params"
5911
5912         echo "correct device name should be passed"
5913         do_facet mgs $LCTL replace_nids $FSNAME-WRONG0000 $OST1_NID &&
5914                 error "wrong devname"
5915
5916         echo "wrong nids list should not destroy the system"
5917         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "wrong nids list" &&
5918                 error "wrong parse"
5919         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 "asdfasdf, asdfadf" &&
5920                 error "wrong parse"
5921
5922         echo "replace OST nid"
5923         do_facet mgs $LCTL replace_nids $FSNAME-OST0000 $OST1_NID ||
5924                 error "replace nids failed"
5925
5926         echo "command should accept two parameters"
5927         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 &&
5928                 error "command should accept two params"
5929
5930         echo "wrong nids list should not destroy the system"
5931         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 "wrong nids list" &&
5932                 error "wrong parse"
5933
5934         local FAKE_NIDS="192.168.0.112@tcp1,192.168.0.112@tcp2"
5935         local FAKE_FAILOVER="192.168.0.113@tcp1,192.168.0.113@tcp2"
5936         local NIDS_AND_FAILOVER="$MDS_NID,$FAKE_NIDS:$FAKE_FAILOVER"
5937         echo "set NIDs with failover"
5938         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $NIDS_AND_FAILOVER ||
5939                 error "replace nids failed"
5940
5941
5942         echo "replace MDS nid"
5943         do_facet mgs $LCTL replace_nids $FSNAME-MDT0000 $MDS_NID ||
5944                 error "replace nids failed"
5945
5946         if ! combined_mgs_mds ; then
5947                 stop_mgs
5948         else
5949                 stop_mds || error "Unable to stop MDS"
5950         fi
5951
5952         start_mgsmds || error "start mgsmds failed"
5953         set_conf_param_and_check mds                                    \
5954             "$LCTL get_param -n osc.$FSNAME-OST0000-osc-MDT0000.active" \
5955             "$FSNAME-OST0000.osc.active"                                \
5956             "1"
5957         start_ost || error "unable to start OST"
5958         mount_client $MOUNT || error "mount client failed"
5959
5960         check_mount || error "error after nid replace"
5961         cleanup || error "cleanup failed"
5962         reformat_and_config
5963 }
5964 run_test 66 "replace nids"
5965
5966 test_67() { #LU-2950
5967         local legacy="$TMP/legacy_lnet_config"
5968         local new="$TMP/new_routes_test"
5969         local out="$TMP/config_out_file"
5970         local verify="$TMP/conv_verify"
5971         local verify_conf="$TMP/conf_verify"
5972
5973         # Create the legacy file that will be run through the
5974         # lustre_routes_conversion script
5975         cat <<- LEGACY_LNET_CONFIG > $legacy
5976                 tcp1 23 192.168.213.1@tcp:1; tcp5 34 193.30.4.3@tcp:4;
5977                 tcp2 54 10.1.3.2@tcp;
5978                 tcp3 10.3.4.3@tcp:3;
5979                 tcp4 10.3.3.4@tcp;
5980         LEGACY_LNET_CONFIG
5981
5982         # Create the verification file to verify the output of
5983         # lustre_routes_conversion script against.
5984         cat <<- VERIFY_LNET_CONFIG > $verify
5985                 tcp1: { gateway: 192.168.213.1@tcp, hop: 23, priority: 1 }
5986                 tcp5: { gateway: 193.30.4.3@tcp, hop: 34, priority: 4 }
5987                 tcp2: { gateway: 10.1.3.2@tcp, hop: 54 }
5988                 tcp3: { gateway: 10.3.4.3@tcp, priority: 3 }
5989                 tcp4: { gateway: 10.3.3.4@tcp }
5990         VERIFY_LNET_CONFIG
5991
5992         # Create the verification file to verify the output of
5993         # lustre_routes_config script against
5994         cat <<- VERIFY_LNET_CONFIG > $verify_conf
5995                 lctl --net tcp1 add_route 192.168.213.1@tcp 23 1
5996                 lctl --net tcp5 add_route 193.30.4.3@tcp 34 4
5997                 lctl --net tcp2 add_route 10.1.3.2@tcp 54 4
5998                 lctl --net tcp3 add_route 10.3.4.3@tcp 1 3
5999                 lctl --net tcp4 add_route 10.3.3.4@tcp 1 3
6000         VERIFY_LNET_CONFIG
6001
6002         $LUSTRE_ROUTES_CONVERSION $legacy $new > /dev/null
6003         if [ -f $new ]; then
6004                 # verify the conversion output
6005                 cmp -s $new $verify > /dev/null
6006                 if [ $? -eq 1 ]; then
6007                         error "routes conversion failed"
6008                 fi
6009
6010                 lustre_routes_config --dry-run --verbose $new > $out
6011                 # check that the script succeeded
6012                 cmp -s $out $verify_conf > /dev/null
6013                 if [ $? -eq 1 ]; then
6014                         error "routes config failed"
6015                 fi
6016         else
6017                 error "routes conversion test failed"
6018         fi
6019         # remove generated files
6020         rm -f $new $legacy $verify $verify_conf $out
6021 }
6022 run_test 67 "test routes conversion and configuration"
6023
6024 test_68() {
6025         local fid
6026         local seq
6027         local START
6028         local END
6029
6030         [ "$MDS1_VERSION" -ge $(version_code 2.4.53) ] ||
6031                 skip "Need MDS version at least 2.4.53"
6032
6033         umount_client $MOUNT || error "umount client failed"
6034
6035         start_mgsmds
6036         start_ost
6037
6038         # START-END - the sequences we'll be reserving
6039         START=$(do_facet $SINGLEMDS \
6040                 $LCTL get_param -n seq.ctl*.space | awk -F'[[ ]' '{print $2}')
6041         END=$((START + (1 << 30)))
6042         do_facet $SINGLEMDS \
6043                 $LCTL set_param seq.ctl*.fldb="[$START-$END\):0:mdt"
6044
6045         # reset the sequences MDT0000 has already assigned
6046         do_facet $SINGLEMDS \
6047                 $LCTL set_param seq.srv*MDT0000.space=clear
6048
6049         # remount to let the client allocate new sequence
6050         mount_client $MOUNT || error "mount client failed"
6051
6052         touch $DIR/$tfile || error "touch $DIR/$tfile failed"
6053         do_facet $SINGLEMDS \
6054                 $LCTL get_param seq.srv*MDT0000.space
6055         $LFS path2fid $DIR/$tfile
6056
6057         local old_ifs="$IFS"
6058         IFS='[:]'
6059         fid=($($LFS path2fid $DIR/$tfile))
6060         IFS="$old_ifs"
6061         let seq=${fid[1]}
6062
6063         if [[ $seq < $END ]]; then
6064                 error "used reserved sequence $seq?"
6065         fi
6066         cleanup || error "cleanup failed with $?"
6067 }
6068 run_test 68 "be able to reserve specific sequences in FLDB"
6069
6070 # Test 69: is about the total number of objects ever created on an OST.
6071 # so that when it is reformatted the normal MDS->OST orphan recovery won't
6072 # just "precreate" the missing objects. In the past it might try to recreate
6073 # millions of objects after an OST was reformatted
6074 test_69() {
6075         [[ "$MDS1_VERSION" -lt $(version_code 2.4.2) ]] &&
6076                 skip "Need MDS version at least 2.4.2"
6077
6078         [[ "$MDS1_VERSION" -ge $(version_code 2.4.50) ]] &&
6079         [[ "$MDS1_VERSION" -lt $(version_code 2.5.0) ]] &&
6080                 skip "Need MDS version at least 2.5.0"
6081
6082         setup
6083         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6084         do_nodes $(osts_nodes) \
6085                 $LCTL set_param seq.*OST*-super.width=$DATA_SEQ_MAX_WIDTH
6086
6087         # use OST0000 since it probably has the most creations
6088         local OSTNAME=$(ostname_from_index 0)
6089         local mdtosc_proc1=$(get_mdtosc_proc_path mds1 $OSTNAME)
6090         local last_id=$(do_facet mds1 $LCTL get_param -n \
6091                         osp.$mdtosc_proc1.prealloc_last_id)
6092
6093         # Want to have OST LAST_ID over 5 * OST_MAX_PRECREATE to
6094         # verify that the LAST_ID recovery is working properly. If
6095         # not, then the OST will refuse to allow the MDS connect
6096         # because the LAST_ID value is too different from the MDS
6097         #define OST_MAX_PRECREATE=20000
6098         local ost_max_pre=20000
6099         local num_create=$(( ost_max_pre * 5 + 1 - last_id))
6100
6101         # If the LAST_ID is already over 5 * OST_MAX_PRECREATE, we don't
6102         # need to create any files. So, skip this section.
6103         if [ $num_create -gt 0 ]; then
6104                 # Check the number of inodes available on OST0
6105                 local files=0
6106                 local ifree=$($LFS df -i $MOUNT |
6107                         awk '/OST0000/ { print $4 }'; exit ${PIPESTATUS[0]})
6108                 log "On OST0, $ifree inodes available. Want $num_create. rc=$?"
6109
6110                 $LFS setstripe -i 0 $DIR/$tdir ||
6111                         error "$LFS setstripe -i 0 $DIR/$tdir failed"
6112                 if [ $ifree -lt 10000 ]; then
6113                         files=$(( ifree - 50 ))
6114                 else
6115                         files=10000
6116                 fi
6117
6118                 local j=$((num_create / files + 1))
6119                 for i in $(seq 1 $j); do
6120                         createmany -o $DIR/$tdir/$tfile-$i- $files ||
6121                                 error "createmany fail create $files files: $?"
6122                         unlinkmany $DIR/$tdir/$tfile-$i- $files ||
6123                                 error "unlinkmany failed unlink $files files"
6124                 done
6125         fi
6126
6127         # delete all of the files with objects on OST0 so the
6128         # filesystem is not inconsistent later on
6129         $LFS find $MOUNT --ost 0 -print0 | xargs -0 rm
6130
6131         umount_client $MOUNT || error "umount client failed"
6132         stop_ost || error "OST0 stop failure"
6133         add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat --replace \
6134                 $(ostdevname 1) $(ostvdevname 1) ||
6135                 error "reformat and replace $ostdev failed"
6136         start_ost || error "OST0 restart failure"
6137         wait_osc_import_state mds ost FULL
6138
6139         mount_client $MOUNT || error "mount client failed"
6140         touch $DIR/$tdir/$tfile-last || error "create file after reformat"
6141         local idx=$($LFS getstripe -i $DIR/$tdir/$tfile-last)
6142         [ $idx -ne 0 ] && error "$DIR/$tdir/$tfile-last on $idx not 0" || true
6143
6144         local iused=$($LFS df -i $MOUNT |
6145                 awk '/OST0000/ { print $3 }'; exit ${PIPESTATUS[0]})
6146         log "On OST0, $iused used inodes rc=$?"
6147         [ $iused -ge $((ost_max_pre + 1000)) ] &&
6148                 error "OST replacement created too many inodes; $iused"
6149         cleanup || error "cleanup failed with $?"
6150 }
6151 run_test 69 "replace an OST with the same index"
6152
6153 test_70a() {
6154         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6155         local MDTIDX=1
6156
6157         cleanup || error "cleanup failed with $?"
6158
6159         start_mdt 1 || error "MDT0 start fail"
6160
6161         start_ost || error "OST0 start fail"
6162         for num in $(seq 2 $MDSCOUNT); do
6163                 start_mdt $num || return
6164         done
6165
6166         mount_client $MOUNT || error "mount client fails"
6167
6168         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
6169
6170         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
6171                 error "create remote dir fail"
6172
6173         rm -rf $DIR/$tdir || error "delete dir fail"
6174         cleanup || error "cleanup failed with $?"
6175 }
6176 run_test 70a "start MDT0, then OST, then MDT1"
6177
6178 test_70b() {
6179         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6180         local MDTIDX=1
6181
6182         start_ost || error "OST0 start fail"
6183
6184         start_mds || error "MDS start fail"
6185
6186         mount_client $MOUNT || error "mount client fails"
6187
6188         mkdir $DIR/$tdir || error "create $DIR/$tdir failed"
6189
6190         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
6191                 error "create remote dir fail"
6192
6193         rm -rf $DIR/$tdir || error "delete dir fail"
6194
6195         cleanup || error "cleanup failed with $?"
6196 }
6197 run_test 70b "start OST, MDT1, MDT0"
6198
6199 test_70c() {
6200         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6201         local MDTIDX=1
6202
6203         start_mds || error "MDS start fail"
6204         start_ost || error "OST0 start fail"
6205
6206         mount_client $MOUNT || error "mount client fails"
6207         stop_mdt 1 || error "MDT1 start fail"
6208
6209         local mdc_for_mdt1=$($LCTL dl | grep MDT0000-mdc | awk '{print $4}')
6210         echo "deactivate $mdc_for_mdt1"
6211         $LCTL --device $mdc_for_mdt1 deactivate ||
6212                 error "set $mdc_for_mdt1 deactivate failed"
6213
6214         mkdir $DIR/$tdir && error "mkdir succeed"
6215
6216         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
6217                 error "create remote dir succeed"
6218
6219         cleanup || error "cleanup failed with $?"
6220 }
6221 run_test 70c "stop MDT0, mkdir fail, create remote dir fail"
6222
6223 test_70d() {
6224         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6225         local MDTIDX=1
6226
6227         start_mds || error "MDS start fail"
6228         start_ost || error "OST0 start fail"
6229
6230         mount_client $MOUNT || error "mount client fails"
6231
6232         stop_mdt 2 || error "MDT1 start fail"
6233
6234         local mdc_for_mdt2=$($LCTL dl | grep MDT0001-mdc |
6235                              awk '{print $4}')
6236         echo "deactivate $mdc_for_mdt2"
6237         $LCTL --device $mdc_for_mdt2 deactivate ||
6238                 error "set $mdc_for_mdt2 deactivate failed"
6239
6240         mkdir $DIR/$tdir || error "mkdir fail"
6241         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir &&
6242                 error "create remote dir succeed"
6243
6244         rm -rf $DIR/$tdir || error "delete dir fail"
6245
6246         cleanup || error "cleanup failed with $?"
6247 }
6248 run_test 70d "stop MDT1, mkdir succeed, create remote dir fail"
6249
6250 test_70e() {
6251         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6252
6253         [ "$MDS1_VERSION" -ge $(version_code 2.7.62) ] ||
6254                 skip "Need MDS version at least 2.7.62"
6255
6256         reformat || error "reformat failed with $?"
6257
6258         load_modules
6259
6260         local mdsdev=$(mdsdevname 1)
6261         local ostdev=$(ostdevname 1)
6262         local mdsvdev=$(mdsvdevname 1)
6263         local ostvdev=$(ostvdevname 1)
6264         local opts_mds="$(mkfs_opts mds1 $mdsdev) --reformat $mdsdev $mdsvdev"
6265         local opts_ost="$(mkfs_opts ost1 $ostdev) --reformat $ostdev $ostvdev"
6266
6267         if ! combined_mgs_mds ; then
6268                 start_mgs
6269         fi
6270
6271         add mds1 $opts_mds || error "add mds1 failed"
6272         start_mdt 1 || error "start mdt1 failed"
6273         add ost1 $opts_ost || error "add ost1 failed"
6274         start_ost || error "start ost failed"
6275         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
6276
6277         local soc=$(do_facet mds1 "$LCTL get_param -n \
6278                     mdt.*MDT0000.sync_lock_cancel")
6279         [ $soc == "never" ] || error "SoC enabled on single MDS"
6280
6281         for i in $(seq 2 $MDSCOUNT); do
6282                 mdsdev=$(mdsdevname $i)
6283                 mdsvdev=$(mdsvdevname $i)
6284                 opts_mds="$(mkfs_opts mds$i $mdsdev) --reformat $mdsdev \
6285                           $mdsvdev"
6286                 add mds$i $opts_mds || error "add mds$i failed"
6287                 start_mdt $i || error "start mdt$i fail"
6288         done
6289
6290         wait_dne_interconnect
6291
6292         for i in $(seq $MDSCOUNT); do
6293                 soc=$(do_facet mds$i "$LCTL get_param -n \
6294                         mdt.*MDT000$((i - 1)).sync_lock_cancel")
6295                 [ $soc == "blocking" ] || error "SoC not enabled on DNE"
6296         done
6297
6298         for i in $(seq 2 $MDSCOUNT); do
6299                 stop_mdt $i || error "stop mdt$i fail"
6300         done
6301         soc=$(do_facet mds1 "$LCTL get_param -n \
6302                 mdt.*MDT0000.sync_lock_cancel")
6303         [ $soc == "never" ] || error "SoC enabled on single MDS"
6304         umount_client $MOUNT -f > /dev/null
6305
6306         cleanup || error "cleanup failed with $?"
6307 }
6308 run_test 70e "Sync-on-Cancel will be enabled by default on DNE"
6309
6310 test_71a() {
6311         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6312         if combined_mgs_mds; then
6313                 skip "needs separate MGS/MDT"
6314         fi
6315         local MDTIDX=1
6316
6317         start_mdt 1 || error "MDT0 start fail"
6318         start_ost || error "OST0 start fail"
6319         for num in $(seq 2 $MDSCOUNT); do
6320                 start_mdt $num || return
6321         done
6322
6323         start_ost2 || error "OST1 start fail"
6324
6325         mount_client $MOUNT || error "mount client fails"
6326
6327         mkdir $DIR/$tdir || error "mkdir fail"
6328         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
6329                 error "create remote dir succeed"
6330
6331         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
6332         rm -rf $DIR/$tdir || error "delete dir fail"
6333
6334         umount_client $MOUNT || error "umount_client failed"
6335         stop_mds || error "MDS stop fail"
6336         stop_ost || error "OST0 stop fail"
6337         stop_ost2 || error "OST1 stop fail"
6338 }
6339 run_test 71a "start MDT0 OST0, MDT1, OST1"
6340
6341 test_71b() {
6342         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6343         if combined_mgs_mds; then
6344                 skip "needs separate MGS/MDT"
6345         fi
6346         local MDTIDX=1
6347
6348         for num in $(seq 2 $MDSCOUNT); do
6349                 start_mdt $num || return
6350         done
6351         start_ost || error "OST0 start fail"
6352         start_mdt 1 || error "MDT0 start fail"
6353         start_ost2 || error "OST1 start fail"
6354
6355         mount_client $MOUNT || error "mount client fails"
6356
6357         mkdir $DIR/$tdir || error "mkdir fail"
6358         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
6359                 error "create remote dir succeed"
6360
6361         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
6362         rm -rf $DIR/$tdir || error "delete dir fail"
6363
6364         umount_client $MOUNT || error "umount_client failed"
6365         stop_mds || error "MDT0 stop fail"
6366         stop_ost || error "OST0 stop fail"
6367         stop_ost2 || error "OST1 stop fail"
6368 }
6369 run_test 71b "start MDT1, OST0, MDT0, OST1"
6370
6371 test_71c() {
6372         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6373         combined_mgs_mds && skip "needs separate MGS/MDT"
6374
6375         local MDTIDX=1
6376
6377         start_ost || error "OST0 start fail"
6378         start_ost2 || error "OST1 start fail"
6379         for num in $(seq 2 $MDSCOUNT); do
6380                 start_mdt $num || return
6381         done
6382         start_mdt 1 || error "MDT0 start fail"
6383
6384         mount_client $MOUNT || error "mount client fails"
6385
6386         mkdir $DIR/$tdir || error "mkdir fail"
6387         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
6388                 error "create remote dir succeed"
6389
6390         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
6391         rm -rf $DIR/$tdir || error "delete dir fail"
6392
6393         umount_client $MOUNT || error "umount_client failed"
6394         stop_mds || error "MDS stop fail"
6395         stop_ost || error "OST0 stop fail"
6396         stop_ost2 || error "OST1 stop fail"
6397
6398 }
6399 run_test 71c "start OST0, OST1, MDT1, MDT0"
6400
6401 test_71d() {
6402         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6403         combined_mgs_mds && skip "needs separate MGS/MDT"
6404
6405         local MDTIDX=1
6406
6407         start_ost || error "OST0 start fail"
6408         for num in $(seq 2 $MDSCOUNT); do
6409                 start_mdt $num || return
6410         done
6411         start_mdt 1 || error "MDT0 start fail"
6412         start_ost2 || error "OST1 start fail"
6413
6414         mount_client $MOUNT || error "mount client fails"
6415
6416         mkdir $DIR/$tdir || error "mkdir fail"
6417         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
6418                         error "create remote dir succeed"
6419
6420         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
6421         rm -rf $DIR/$tdir || error "delete dir fail"
6422
6423         umount_client $MOUNT || error "umount_client failed"
6424         stop_mds || error "MDS stop fail"
6425         stop_ost || error "OST0 stop fail"
6426         stop_ost2 || error "OST1 stop fail"
6427
6428 }
6429 run_test 71d "start OST0, MDT1, MDT0, OST1"
6430
6431 test_71e() {
6432         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
6433         combined_mgs_mds && skip "needs separate MGS/MDT"
6434
6435         local MDTIDX=1
6436
6437         start_ost || error "OST0 start fail"
6438         for num in $(seq 2 $MDSCOUNT); do
6439                 start_mdt $num || return
6440         done
6441         start_ost2 || error "OST1 start fail"
6442         start_mdt 1 || error "MDT0 start fail"
6443
6444         mount_client $MOUNT || error "mount client fails"
6445
6446         mkdir $DIR/$tdir || error "mkdir fail"
6447         $LFS mkdir -i $MDTIDX $DIR/$tdir/remote_dir ||
6448                 error "create remote dir succeed"
6449
6450         mcreate $DIR/$tdir/remote_dir/$tfile || error "create file failed"
6451         rm -rf $DIR/$tdir || error "delete dir fail"
6452
6453         umount_client $MOUNT || error "umount_client failed"
6454         stop_mds || error "MDS stop fail"
6455         stop_ost || error "OST0 stop fail"
6456         stop_ost2 || error "OST1 stop fail"
6457
6458 }
6459 run_test 71e "start OST0, MDT1, OST1, MDT0"
6460
6461 test_72() { #LU-2634
6462         [ "$mds1_FSTYPE" != ldiskfs ] &&
6463                 skip "ldiskfs only test"
6464
6465         local mdsdev=$(mdsdevname 1)
6466         local ostdev=$(ostdevname 1)
6467         local cmd="$E2FSCK -fnvd $mdsdev"
6468         local fn=3
6469         local add_options
6470
6471         cleanup
6472         load_modules
6473
6474         if combined_mgs_mds; then
6475                 add_options='--reformat'
6476         else
6477                 add_options='--reformat --replace'
6478         fi
6479
6480         #tune MDT with "-O extents"
6481
6482         for num in $(seq $MDSCOUNT); do
6483                 add mds${num} $(mkfs_opts mds$num $(mdsdevname $num)) \
6484                         $add_options $(mdsdevname $num) $(mdsvdevname $num) ||
6485                         error "add mds $num failed"
6486                 do_facet mds${num} "$TUNE2FS -O extents $(mdsdevname $num)" ||
6487                         error "$TUNE2FS failed on mds${num}"
6488         done
6489
6490         add ost1 $(mkfs_opts ost1 $ostdev) $add_options $ostdev ||
6491                 error "add $ostdev failed"
6492         start_mds || error "start mds failed"
6493         start_ost || error "start ost failed"
6494         mount_client $MOUNT || error "mount client failed"
6495
6496         #create some short symlinks
6497         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
6498         createmany -o $DIR/$tdir/$tfile-%d $fn
6499         echo "create $fn short symlinks"
6500         for i in $(seq -w 1 $fn); do
6501                 ln -s $DIR/$tdir/$tfile-$i $MOUNT/$tfile-$i
6502         done
6503         ls -al $MOUNT
6504
6505         #umount
6506         umount_client $MOUNT || error "umount client failed"
6507         stop_mds || error "stop mds failed"
6508         stop_ost || error "stop ost failed"
6509
6510         #run e2fsck
6511         run_e2fsck $(facet_active_host $SINGLEMDS) $mdsdev "-n"
6512 }
6513 run_test 72 "test fast symlink with extents flag enabled"
6514
6515 test_73a() { #LU-3006
6516         [[ "$ost1_FSTYPE" == zfs ]] && import_zpool ost1
6517         local ostdev=$(ostdevname 1)
6518
6519         do_facet ost1 "$TUNEFS --failnode=1.2.3.4@$NETTYPE $ostdev" ||
6520                 error "1st tunefs failed"
6521         start_mgsmds || error "start mds failed"
6522         start_ost || error "start ost failed"
6523         mount_client $MOUNT || error "mount client failed"
6524         $LCTL get_param -n osc.*OST0000-osc-[^M]*.import |
6525                 grep "failover_nids.*1.2.3.4@$NETTYPE" ||
6526                 error "failover nids haven't changed"
6527         umount_client $MOUNT || error "umount client failed"
6528         stop_ost
6529         do_facet ost1 "$TUNEFS --erase-param failover.node $ostdev"
6530         stop_mds
6531 }
6532 run_test 73a "failnode to update from mountdata properly"
6533
6534 test_73b() {
6535         (( $OST1_VERSION >= $(version_code 2.16.50) )) ||
6536                 skip "need OST >= 2.16.50 for many NID support"
6537         [[ "$ost1_FSTYPE" == zfs ]] && import_zpool ost1
6538
6539         local ostdev=$(ostdevname 1)
6540         local nids="111.222.173._@$NETTYPE,111.222.142._@$NETTYPE"
6541         local iter=60
6542         local cmd
6543
6544         do_facet ost1 "$TUNEFS --comment='just a comment for tail' $ostdev" ||
6545                 error "1st tunefs failed"
6546
6547         # 4K can fit ~200 IPv4 NIDs, try more for checking failure case too
6548         # add in pairs in both mgsnode and failnode to reduce test time
6549         for ((i = 1; i <= $iter; i++)); do
6550                 local cmd="--failnode=${nids//_/$i} --mgsnode=${nids//_/$i}"
6551                 do_facet ost1 "$TUNEFS $cmd $ostdev" >/dev/null ||
6552                         break
6553         done
6554
6555         start_mgsmds || error "Fail to start mds"
6556         start_ost || error "Fail to mount ost"
6557
6558         local zkeeper=${KEEP_ZPOOL}
6559         stack_trap "KEEP_ZPOOL=$zkeeper" EXIT
6560         KEEP_ZPOOL="true"
6561         stop_ost
6562         stop_mds
6563
6564         # count the actual number of failover NIDs configured in failover.node
6565         # there may be some previously configured, so they should also count
6566         local count=$(do_facet ost1 "$TUNEFS --erase-params $ostdev" |
6567                       grep "^Param" | grep -Fo '@' | wc -l)
6568         echo "Found total $count NIDs in parameters"
6569
6570         KEEP_ZPOOL="${zkeeper}"
6571         reformat
6572
6573         # expect to fit more that 32 mgsnode and 4*32 failover NIDs at least
6574         ((count >= 160)) || error "Only $count NIDs found, need >= (128+32)"
6575 }
6576 run_test 73b "Large failnode NID list in mountdata"
6577
6578 cleanup_73c() {
6579         LOAD_MODULES_REMOTE=true cleanup
6580 }
6581
6582 test_73c() {
6583         (( $OST1_VERSION >= $(version_code 2.16.54) )) ||
6584                 skip "Need OST version at least 2.16.54 to don't LBUG"
6585
6586         cleanup
6587         LOAD_MODULES_REMOTE=true load_modules
6588
6589         INTERFACES=( $(lnet_if_list) )
6590         local inf=${INTERFACES[0]}
6591
6592         do_facet ost1 "$LNETCTL lnet configure" ||
6593                 error "unable to configure lnet on ost1"
6594
6595         stack_trap "cleanup_73c"
6596
6597         for ((n = 100; n <= 135; n++)); do
6598                 do_facet ost1 "$LNETCTL net add --net ${NETTYPE}$n --if $inf" ||
6599                         skip "unable to configure net #$n on ost1"
6600         done
6601
6602         echo "restart with 35 nets"
6603         start_mgsmds
6604         start_ost || error "unable to start ost1"
6605 }
6606 run_test 73c "Server mount doesn't fail with > 32 nets"
6607
6608 test_73d() { #LU-18896
6609         (( $OST1_VERSION >= $(version_code 2.16.53) )) ||
6610                 skip "need OST >= 2.16.53 for LU-18896 fix"
6611         [[ "$ost1_FSTYPE" == zfs ]] && import_zpool ost1
6612
6613         local ostdev=$(ostdevname 1)
6614
6615         # add bogus param to mountdata
6616         do_facet ost1 "$TUNEFS --erase-params \
6617                 --param=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=1 $ostdev"
6618         do_facet ost1 "$TUNEFS --erase-params --mgsnode=10.23.7.1@tcp \
6619                 --mgsnode=10.23.7.2@tcp $ostdev"
6620         bad=$(do_facet ost1 "$TUNEFS --erase-params" $ostdev | grep -c "xx=1")
6621         reformat
6622
6623         (( bad == 0 )) || error "garbage in params"
6624 }
6625 run_test 73d "erase + new parameter doesn't corrupt mountdata"
6626
6627 # LU-15246
6628 test_74() {
6629         (( $MDS1_VERSION >= $(version_code 2.15.57.16) )) ||
6630                 skip "need MDS version >= 2.15.57.16 for per-device timeouts"
6631
6632         setup
6633         stack_trap "cleanup"
6634
6635         # Prepare fs2, share the mgs of fs
6636         local FSNAME2=fs15246
6637         local fs2mdsdev=$(mdsdevname 1_2)
6638         local fs2ostdev=$(ostdevname 1_2)
6639         local fs2mdsvdev=$(mdsvdevname 1_2)
6640         local fs2ostvdev=$(ostvdevname 1_2)
6641
6642         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --fsname=$FSNAME2 \
6643                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
6644         add fs2ost $(mkfs_opts ost1 $fs2ostdev) --fsname=$FSNAME2 \
6645                 --reformat $fs2ostdev $fs2ostvdev || error "add fs2ost failed"
6646
6647         stack_trap "cleanup_fs2"
6648
6649         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
6650         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS || error "start fs2mds failed"
6651
6652         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
6653         $MOUNT_CMD $MGSNID:/$FSNAME2 $MOUNT2 || error "mount $MOUNT2 failed"
6654
6655         echo "========== All mounted lustre fs ===================="
6656         mount | grep 'type lustre'
6657         echo "====================================================="
6658
6659         # Set and check osc/ldlm_enqueue_min
6660         $LCTL set_param osc.${FSNAME}-*.ldlm_enqueue_min=99 ||
6661                 error "failed to set per-device adaptive parameters on client"
6662         stack_trap "$LCTL set_param osc.${FSNAME}-*.ldlm_enqueue_min=0"
6663
6664         local ldlm_enqueue_min
6665         ldlm_enqueue_min=$($LCTL get_param -n osc.${FSNAME}-*.ldlm_enqueue_min \
6666                            | uniq)
6667         (( $ldlm_enqueue_min == 99 )) ||
6668                 error "wrong ldlm_enqueue_min value for osc.${FSNAME}-*"
6669
6670         # Check fs2 as reference
6671         ldlm_enqueue_min=$($LCTL get_param -n osc.${FSNAME2}-*.ldlm_enqueue_min\
6672                            | uniq)
6673         (( $ldlm_enqueue_min == 0 )) ||
6674                 error "wrong ldlm_enqueue_min value for osc.${FSNAME2}-*"
6675
6676         # Set and check obdfilter/at_min
6677         do_facet ost1 $LCTL set_param obdfilter.${FSNAME}-*.at_min=1 ||
6678                 error "failed to set per-device adaptive parameters on ost"
6679         stack_trap "do_facet ost1 $LCTL set_param obdfilter.${FSNAME}-*.at_min=0"
6680
6681         local at_min
6682         at_min=$(do_facet ost1 $LCTL get_param -n obdfilter.${FSNAME}-*.at_min \
6683                 | uniq)
6684         (( $at_min == 1 )) ||
6685                 error "wrong at_min value for obdfilter.${FSNAME}-*"
6686
6687         # set and check mdc/at_max
6688         $LCTL set_param mdc.${FSNAME}-*.at_max=599 ||
6689                 error "failed to set per-device adaptive parameters on client"
6690         stack_trap "$LCTL set_param mdc.${FSNAME}-*.at_max=0"
6691
6692         local at_max
6693         at_max=$($LCTL get_param -n mdc.${FSNAME}-*.at_max | uniq)
6694         (( $at_max == 599 )) ||
6695                 error "wrong at_max value for osc.${FSNAME}-*"
6696
6697         # Check fs2 as reference
6698         at_max=$($LCTL get_param -n mdc.${FSNAME2}-*.at_max | uniq)
6699         (( $at_max == 0 )) ||
6700                 error "wrong at_max value for osc.${FSNAME2}-*"
6701
6702         # Set and check mds/at_max
6703         do_facet mds1 $LCTL set_param *.${FSNAME}-*.at_max=599 ||
6704                 error "failed to set per-device adaptive parameters on mds"
6705         stack_trap "do_facet mds1 $LCTL set_param *.${FSNAME}-*.at_max=0"
6706
6707         local at_max
6708         at_max=$(do_facet mds1 $LCTL get_param -n mdt.${FSNAME}-*.at_max | uniq)
6709         (( at_max == 599 )) ||
6710                 error "wrong at_max value for mdt.${FSNAME}-*"
6711
6712         # Set and check mgs&mgc/at_history
6713         local mgs_nid=$(do_facet $SINGLEMDS $LCTL list_nids | tail -1)
6714         $LCTL set_param mgc.MGC$mgs_nid.at_history=588
6715         stack_trap "$LCTL set_param mgc.MGC$mgs_nid.at_history=0"
6716
6717         local at_history
6718         at_history=$($LCTL get_param -n mgc.MGC$mgs_nid.at_history)
6719         (( $at_history == 588 )) ||
6720                 error "wrong at_history value for mgc.MGC$mgs_nid"
6721
6722         do_facet mgs $LCTL set_param mgs.MGS.at_history=588
6723         stack_trap "do_facet mgs $LCTL set_param mgs.MGS.at_history=0"
6724         at_history=$(do_facet mgs $LCTL get_param -n mgs.MGS.at_history)
6725         (( $at_history == 588 )) ||
6726                 error "wrong at_history value for mgs.MGS"
6727 }
6728 run_test 74 "Test per-device adaptive timeout parameters"
6729
6730 test_75() { # LU-2374
6731         [[ "$MDS1_VERSION" -lt $(version_code 2.4.1) ]] &&
6732                 skip "Need MDS version at least 2.4.1"
6733
6734         local index=0
6735         local opts_mds="$(mkfs_opts mds1 $(mdsdevname 1)) \
6736                 --replace --reformat $(mdsdevname 1) $(mdsvdevname 1)"
6737         local opts_ost="$(mkfs_opts ost1 $(ostdevname 1)) \
6738                 --replace --reformat $(ostdevname 1) $(ostvdevname 1)"
6739
6740         load_modules
6741         #check with default parameters
6742         add mds1 $opts_mds || error "add mds1 failed for default params"
6743         add ost1 $opts_ost || error "add ost1 failed for default params"
6744
6745         opts_mds=$(echo $opts_mds | sed -e "s/--mdt//")
6746         opts_mds=$(echo $opts_mds |
6747                    sed -e "s/--index=$index/--index=$index --mdt/")
6748         opts_ost=$(echo $opts_ost | sed -e "s/--ost//")
6749         opts_ost=$(echo $opts_ost |
6750                    sed -e "s/--index=$index/--index=$index --ost/")
6751
6752         add mds1 $opts_mds || error "add mds1 failed for new params"
6753         add ost1 $opts_ost || error "add ost1 failed for new params"
6754
6755         reformat_and_config
6756         return 0
6757 }
6758 run_test 75 "The order of --index should be irrelevant"
6759
6760 test_76a() {
6761         [[ "$MGS_VERSION" -ge $(version_code 2.4.52) ]] ||
6762                 skip "Need MDS version at least 2.4.52"
6763
6764         setup
6765         local MDMB_PARAM="osc.*.max_dirty_mb"
6766         echo "Change MGS params"
6767         local MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM |
6768                 head -1)
6769         echo "max_dirty_mb: $MAX_DIRTY_MB"
6770         local NEW_MAX_DIRTY_MB=$((MAX_DIRTY_MB - 10))
6771         echo "new_max_dirty_mb: $NEW_MAX_DIRTY_MB"
6772         do_facet mgs $LCTL set_param -P $MDMB_PARAM=$NEW_MAX_DIRTY_MB
6773         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
6774                 head -1" $NEW_MAX_DIRTY_MB
6775         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
6776         echo "$MAX_DIRTY_MB"
6777         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
6778                 error "error while apply max_dirty_mb"
6779
6780         echo "Check the value is stored after remount"
6781         stopall
6782         setupall
6783         wait_update $HOSTNAME "$LCTL get_param -n $MDMB_PARAM |
6784                 head -1" $NEW_MAX_DIRTY_MB
6785         MAX_DIRTY_MB=$($LCTL get_param -n $MDMB_PARAM | head -1)
6786         [ $MAX_DIRTY_MB = $NEW_MAX_DIRTY_MB ] ||
6787                 error "max_dirty_mb is not saved after remount"
6788
6789         echo "Change OST params"
6790         CLIENT_PARAM="obdfilter.*.client_cache_count"
6791         local CLIENT_CACHE_COUNT
6792         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
6793                 head -1)
6794         echo "client_cache_count: $CLIENT_CACHE_COUNT"
6795         NEW_CLIENT_CACHE_COUNT=$((CLIENT_CACHE_COUNT+CLIENT_CACHE_COUNT))
6796         echo "new_client_cache_count: $NEW_CLIENT_CACHE_COUNT"
6797         do_facet mgs $LCTL set_param -P $CLIENT_PARAM=$NEW_CLIENT_CACHE_COUNT
6798         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
6799                 head -1" $NEW_CLIENT_CACHE_COUNT
6800         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
6801                 head -1)
6802         echo "$CLIENT_CACHE_COUNT"
6803         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
6804                 error "error while apply client_cache_count"
6805
6806         echo "Check the value is stored after remount"
6807         stopall
6808         setupall
6809         wait_update $(facet_host ost1) "$LCTL get_param -n $CLIENT_PARAM |
6810                 head -1" $NEW_CLIENT_CACHE_COUNT
6811         CLIENT_CACHE_COUNT=$(do_facet ost1 $LCTL get_param -n $CLIENT_PARAM |
6812                 head -1)
6813         echo "$CLIENT_CACHE_COUNT"
6814         [ $CLIENT_CACHE_COUNT = $NEW_CLIENT_CACHE_COUNT ] ||
6815                 error "client_cache_count is not saved after remount"
6816         stopall
6817 }
6818 run_test 76a "set permanent params with lctl across mounts"
6819
6820 test_76b() { # LU-4783
6821         [[ "$MGS_VERSION" -ge $(version_code 2.5.57) ]] ||
6822                 skip "Need MGS version at least 2.5.57"
6823         stopall
6824         setupall
6825         do_facet mgs $LCTL get_param mgs.MGS.live.params ||
6826                 error "start params log failed"
6827         stopall
6828 }
6829 run_test 76b "verify params log setup correctly"
6830
6831 test_76c() {
6832         [[ "$MGS_VERSION" -ge $(version_code 2.8.54) ]] ||
6833                 skip "Need MDS version at least 2.4.52"
6834         setupall
6835         local MASK_PARAM="mdd.*.changelog_mask"
6836         echo "Change changelog_mask"
6837         do_facet mgs $LCTL set_param -P $MASK_PARAM=-CLOSE ||
6838                 error "Can't change changlog_mask"
6839         wait_update $(facet_host mds) "$LCTL get_param -n $MASK_PARAM |
6840                 grep 'CLOSE'" ""
6841
6842         echo "Check the value is stored after mds remount"
6843         stop_mds || error "Failed to stop MDS"
6844         start_mds || error "Failed to start MDS"
6845         local CHANGELOG_MASK=$(do_facet mgs $LCTL get_param -n $MASK_PARAM)
6846         echo $CHANGELOG_MASK | grep CLOSE > /dev/null &&
6847                 error "changelog_mask is not changed"
6848
6849         stopall
6850 }
6851 run_test 76c "verify changelog_mask is applied with lctl set_param -P"
6852
6853 test_76d() { #LU-9399
6854         setupall
6855
6856         local xattr_cache='llite.$inst.xattr_cache'
6857         local inst=($(lfs getname $MOUNT))
6858         local cmd="$LCTL get_param -n $xattr_cache"
6859         local new=$((($(eval $cmd) + 1) % 2))
6860
6861         echo "lctl set_param -P llite.*.xattr_cache=$new"
6862         do_facet mgs $LCTL set_param -P llite.*.xattr_cache=$new ||
6863                 error "Can't change xattr_cache"
6864         stack_trap "do_facet mgs $LCTL set_param -P -d llite.*.xattr_cache || true"
6865         wait_update $HOSTNAME "$cmd" "$new" ||
6866                 error "$xattr_cache != $new on original client $MOUNT"
6867
6868         echo "Check $xattr_cache on client $MOUNT"
6869         umount_client $MOUNT || error "umount $MOUNT failed"
6870         mount_client $MOUNT || error "mount $MOUNT failed"
6871         inst=($(lfs getname $MOUNT))
6872         wait_update $HOSTNAME "$cmd" "$new" ||
6873                 error "$xattr_cache != $new on remount client $MOUNT"
6874
6875         echo "Check $xattr_cache on the new client $MOUNT2"
6876         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
6877         inst=($(lfs getname $MOUNT2))
6878         wait_update $HOSTNAME "$cmd" "$new" ||
6879                 error "$xattr_cache != $new on second client $MOUNT2"
6880         umount_client $MOUNT2 || error "umount $MOUNT2 failed"
6881
6882         do_facet mgs $LCTL set_param -P -d llite.*.xattr_cache
6883         stopall
6884 }
6885 run_test 76d "verify llite.*.xattr_cache can be set by 'lctl set_param -P' correctly"
6886
6887 test_77() { # LU-3445
6888         [[ "$MDS1_VERSION" -ge $(version_code 2.8.55) ]] ||
6889                 skip "Need MDS version 2.8.55+ "
6890
6891         if [[ -z "$fs2ost_DEV" || -z "$fs2mds_DEV" ]]; then
6892                 is_blkdev $SINGLEMDS $(mdsdevname ${SINGLEMDS//mds/}) &&
6893                 skip_env "mixed loopback and real device not working"
6894         fi
6895
6896         local fs2mdsdev=$(mdsdevname 1_2)
6897         local fs2ostdev=$(ostdevname 1_2)
6898         local fs2mdsvdev=$(mdsvdevname 1_2)
6899         local fs2ostvdev=$(ostvdevname 1_2)
6900         local fsname=test1234
6901         local mgsnid
6902         local failnid="$(h2nettype 1.2.3.4),$(h2nettype 4.3.2.1)"
6903
6904         combined_mgs_mds || stop_mgs || error "stopping MGS service failed"
6905
6906         add fs2mds $(mkfs_opts mds1 $fs2mdsdev) --mgs --fsname=$fsname \
6907                 --reformat $fs2mdsdev $fs2mdsvdev || error "add fs2mds failed"
6908         start fs2mds $fs2mdsdev $MDS_MOUNT_OPTS && trap cleanup_fs2 EXIT INT ||
6909                 error "start fs2mds failed"
6910
6911         mgsnid=$(do_facet fs2mds $LCTL list_nids | xargs | tr ' ' ,)
6912         mgsnid="0.0.0.0@tcp,$mgsnid,$mgsnid:$mgsnid"
6913
6914         add fs2ost --mgsnode=$mgsnid $(mkfs_opts ost1 $fs2ostdev) \
6915                 --failnode=$failnid --fsname=$fsname \
6916                 --reformat $fs2ostdev $fs2ostvdev ||
6917                         error "add fs2ost failed"
6918         start fs2ost $fs2ostdev $OST_MOUNT_OPTS || error "start fs2ost failed"
6919
6920         mkdir -p $MOUNT2 || error "mkdir $MOUNT2 failed"
6921         $MOUNT_CMD $mgsnid:/$fsname $MOUNT2 || error "mount $MOUNT2 failed"
6922         DIR=$MOUNT2 MOUNT=$MOUNT2 check_mount || error "check $MOUNT2 failed"
6923         cleanup_fs2
6924 }
6925 run_test 77 "comma-separated MGS NIDs and failover node NIDs"
6926
6927 test_78() {
6928         [[ "$mds1_FSTYPE" != ldiskfs ||
6929            "$ost1_FSTYPE" != ldiskfs ]] &&
6930                 skip "ldiskfs only test"
6931
6932         # reformat the Lustre filesystem with a smaller size
6933         local saved_MDSCOUNT=$MDSCOUNT
6934         local saved_MDSSIZE=$MDSSIZE
6935         local saved_OSTCOUNT=$OSTCOUNT
6936         local saved_OSTSIZE=$OSTSIZE
6937         MDSCOUNT=1
6938         OSTCOUNT=1
6939         MDSSIZE=$((MDSSIZE - 20000))
6940         OSTSIZE=$((OSTSIZE - 20000))
6941         reformat || error "(1) reformat Lustre filesystem failed"
6942         MDSSIZE=$saved_MDSSIZE
6943         OSTSIZE=$saved_OSTSIZE
6944
6945         # mount the Lustre filesystem
6946         setup_noconfig || error "(2) setup Lustre filesystem failed"
6947
6948         # create some files
6949         log "create test files"
6950         local i
6951         local file
6952         local num_files=100
6953
6954         mkdir $MOUNT/$tdir || error "(3) mkdir $MOUNT/$tdir failed"
6955         $LFS df; $LFS df -i
6956         for i in $(seq $num_files); do
6957                 file=$MOUNT/$tdir/$tfile-$i
6958                 dd if=/dev/urandom of=$file count=1 bs=1M || {
6959                         $LCTL get_param osc.*.cur*grant*
6960                         $LFS df; $LFS df -i;
6961                         # stop creating files if there is no more space
6962                         if [ ! -e $file ]; then
6963                                 num_files=$((i - 1))
6964                                 break
6965                         fi
6966
6967                         $LFS getstripe -v $file
6968                         local ost_idx=$(LFS getstripe -i $file)
6969                         do_facet ost$((ost_idx + 1)) \
6970                                 $LCTL get_param obdfilter.*.*grant*
6971                         error "(4) create $file failed"
6972                 }
6973         done
6974
6975         # unmount the Lustre filesystem
6976         cleanup || error "(5) cleanup Lustre filesystem failed"
6977
6978         # run e2fsck on the MDT and OST devices
6979         local mds_host=$(facet_active_host $SINGLEMDS)
6980         local ost_host=$(facet_active_host ost1)
6981         local mds_dev=$(mdsdevname ${SINGLEMDS//mds/})
6982         local ost_dev=$(ostdevname 1)
6983
6984         run_e2fsck $mds_host $mds_dev "-y"
6985         run_e2fsck $ost_host $ost_dev "-y"
6986
6987         # get the original block count of the MDT and OST filesystems
6988         local mds_orig_blks=$(get_block_count $SINGLEMDS $mds_dev)
6989         local ost_orig_blks=$(get_block_count ost1 $ost_dev)
6990
6991         # expand the MDT and OST filesystems to the device size
6992         run_resize2fs $SINGLEMDS $mds_dev "" || error "expand $SINGLEMDS failed"
6993         run_resize2fs ost1 $ost_dev "" || error "expand ost1 failed"
6994
6995         # run e2fsck on the MDT and OST devices again
6996         run_e2fsck $mds_host $mds_dev "-y"
6997         run_e2fsck $ost_host $ost_dev "-y"
6998
6999         # mount the Lustre filesystem
7000         setup
7001
7002         # check the files
7003         log "check files after expanding the MDT and OST filesystems"
7004         for i in $(seq $num_files); do
7005                 file=$MOUNT/$tdir/$tfile-$i
7006                 $CHECKSTAT -t file -s 1048576 $file ||
7007                         error "(6) checkstat $file failed"
7008         done
7009
7010         # create more files
7011         log "create more files after expanding the MDT and OST filesystems"
7012         for i in $(seq $((num_files + 1)) $((num_files + 10))); do
7013                 file=$MOUNT/$tdir/$tfile-$i
7014                 dd if=/dev/urandom of=$file count=1 bs=1M ||
7015                         error "(7) create $file failed"
7016         done
7017
7018         # unmount the Lustre filesystem
7019         cleanup || error "(8) cleanup Lustre filesystem failed"
7020
7021         # run e2fsck on the MDT and OST devices
7022         run_e2fsck $mds_host $mds_dev "-y"
7023         run_e2fsck $ost_host $ost_dev "-y"
7024
7025         # get the maximum block count of the MDT and OST filesystems
7026         local mds_max_blks=$(get_block_count $SINGLEMDS $mds_dev)
7027         local ost_max_blks=$(get_block_count ost1 $ost_dev)
7028
7029         # get the minimum block count of the MDT and OST filesystems
7030         local mds_min_blks=$(run_resize2fs $SINGLEMDS $mds_dev "" "-P" 2>&1 |
7031                                 grep minimum | sed -e 's/^.*filesystem: //g')
7032         local ost_min_blks=$(run_resize2fs ost1 $ost_dev "" "-P" 2>&1 |
7033                                 grep minimum | sed -e 's/^.*filesystem: //g')
7034
7035         # shrink the MDT and OST filesystems to a smaller size
7036         local shrunk=false
7037         local new_blks
7038         local base_blks
7039         if [[ $mds_max_blks -gt $mds_min_blks &&
7040               $mds_max_blks -gt $mds_orig_blks ]]; then
7041                 [[ $mds_orig_blks -gt $mds_min_blks ]] &&
7042                         base_blks=$mds_orig_blks || base_blks=$mds_min_blks
7043                 new_blks=$(( (mds_max_blks - base_blks) / 2 + base_blks ))
7044                 run_resize2fs $SINGLEMDS $mds_dev $new_blks ||
7045                         error "shrink $SINGLEMDS to $new_blks failed"
7046                 shrunk=true
7047         fi
7048
7049         if [[ $ost_max_blks -gt $ost_min_blks &&
7050               $ost_max_blks -gt $ost_orig_blks ]]; then
7051                 [[ $ost_orig_blks -gt $ost_min_blks ]] &&
7052                         base_blks=$ost_orig_blks || base_blks=$ost_min_blks
7053                 new_blks=$(( (ost_max_blks - base_blks) / 2 + base_blks ))
7054                 run_resize2fs ost1 $ost_dev $new_blks ||
7055                         error "shrink ost1 to $new_blks failed"
7056                 shrunk=true
7057         fi
7058
7059         # check whether the MDT or OST filesystem was shrunk or not
7060         if ! $shrunk; then
7061                 combined_mgs_mds || stop_mgs || error "(9) stop mgs failed"
7062                 reformat_and_config ||
7063                         error "(10) reformat Lustre filesystem failed"
7064                 return 0
7065         fi
7066
7067         # run e2fsck on the MDT and OST devices again
7068         run_e2fsck $mds_host $mds_dev "-y"
7069         run_e2fsck $ost_host $ost_dev "-y"
7070
7071         # mount the Lustre filesystem again
7072         setup
7073
7074         # check the files
7075         log "check files after shrinking the MDT and OST filesystems"
7076         for i in $(seq $((num_files + 10))); do
7077                 file=$MOUNT/$tdir/$tfile-$i
7078                 $CHECKSTAT -t file -s 1048576 $file ||
7079                         error "(11) checkstat $file failed"
7080         done
7081
7082         # unmount and reformat the Lustre filesystem
7083         cleanup || error "(12) cleanup Lustre filesystem failed"
7084         combined_mgs_mds || stop_mgs || error "(13) stop mgs failed"
7085
7086         MDSCOUNT=$saved_MDSCOUNT
7087         OSTCOUNT=$saved_OSTCOUNT
7088         reformat_and_config || error "(14) reformat Lustre filesystem failed"
7089 }
7090 run_test 78 "run resize2fs on MDT and OST filesystems"
7091
7092 test_79() { # LU-4227
7093         [[ "$MDS1_VERSION" -ge $(version_code 2.5.59) ]] ||
7094                 skip "Need MDS version at least 2.5.59"
7095
7096         local mdsdev1=$(mdsdevname 1)
7097         local mdsvdev1=$(mdsvdevname 1)
7098         local mdsdev2=$(mdsdevname 2)
7099         local mdsvdev2=$(mdsvdevname 2)
7100         local ostdev1=$(ostdevname 1)
7101         local ostvdev1=$(ostvdevname 1)
7102         local opts_mds1="$(mkfs_opts mds1 $mdsdev1) --reformat"
7103         local opts_mds2="$(mkfs_opts mds2 $mdsdev2) --reformat"
7104         local opts_ost1="$(mkfs_opts ost1 $ostdev1) --reformat"
7105         local mgsnode_opt
7106
7107         # remove --mgs/--mgsnode from mkfs.lustre options
7108         opts_mds1=$(echo $opts_mds1 | sed -e "s/--mgs//")
7109
7110         mgsnode_opt=$(echo $opts_mds2 |
7111                 awk '{ for ( i = 1; i < NF; i++ )
7112                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
7113         [ -n "$mgsnode_opt" ] &&
7114                 opts_mds2=$(echo $opts_mds2 | sed -e "s/$mgsnode_opt//")
7115
7116         mgsnode_opt=$(echo $opts_ost1 |
7117                 awk '{ for ( i = 1; i < NF; i++ )
7118                         if ( $i ~ "--mgsnode" ) { print $i; break } }')
7119         [ -n "$mgsnode_opt" ] &&
7120                 opts_ost1=$(echo $opts_ost1 | sed -e "s/$mgsnode_opt//")
7121         load_modules
7122         # -MGS, format a mdt without --mgs option
7123         add mds1 $opts_mds1 $mdsdev1 $mdsvdev1 &&
7124                 error "Must specify --mgs when formatting mdt combined with mgs"
7125
7126         # +MGS, format a mdt/ost without --mgsnode option
7127         add mds1 $(mkfs_opts mds1 $mdsdev1) --reformat $mdsdev1 $mdsvdev1 \
7128                 > /dev/null || error "start mds1 failed"
7129         add mds2 $opts_mds2 $mdsdev2 $mdsvdev2 &&
7130                 error "Must specify --mgsnode when formatting a mdt"
7131         add ost1 $opts_ost1 $ostdev1 $ostvdev1 &&
7132                 error "Must specify --mgsnode when formatting an ost"
7133
7134         reformat_and_config
7135 }
7136 run_test 79 "format MDT/OST without mgs option (should return errors)"
7137
7138 test_80() {
7139         start_mds || error "Failed to start MDT"
7140         start_ost || error "Failed to start OST1"
7141         uuid=$(do_facet ost1 $LCTL get_param -n mgc.*.uuid)
7142 #define OBD_FAIL_MGS_PAUSE_TARGET_CON       0x906
7143         do_facet ost1 "$LCTL set_param fail_val=10 fail_loc=0x906"
7144         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x906"
7145         do_facet mgs "$LCTL set_param -n mgs/MGS/evict_client $uuid"
7146         sleep 30
7147         start_ost2 || error "Failed to start OST2"
7148
7149         do_facet ost1 "$LCTL set_param fail_loc=0"
7150         stop_ost2
7151         stop_ost
7152         stop_mds
7153 }
7154 run_test 80 "mgc import reconnect race"
7155
7156 #Save the original values of $OSTCOUNT and $OSTINDEX$i.
7157 save_ostindex() {
7158         local new_ostcount=$1
7159         saved_ostcount=$OSTCOUNT
7160         OSTCOUNT=$new_ostcount
7161
7162         local i
7163         local index
7164         for ((i = 1; i <= $OSTCOUNT; i++ )); do
7165                 index=OSTINDEX$i
7166                 eval saved_ostindex$i=${!index}
7167                 eval OSTINDEX$i=""
7168         done
7169 }
7170
7171 # Restore the original values of $OSTCOUNT and $OSTINDEX$i.
7172 restore_ostindex() {
7173         local i
7174         local index
7175
7176         echo "restoring OSTCOUNT=$saved_ostcount and OSTINDEXn"
7177
7178         for ((i = 1; i <= $OSTCOUNT; i++ )); do
7179                 index=saved_ostindex$i
7180                 eval OSTINDEX$i=${!index}
7181         done
7182         OSTCOUNT=$saved_ostcount
7183
7184         reformat
7185         if ! combined_mgs_mds ; then
7186                 start_mgs
7187         fi
7188 }
7189
7190 max_lov_stripe_index() {
7191         locale facet=$1
7192
7193         if [[ $(lustre_version_code $facet) -lt $(version_code 2.15.64) ]]; then
7194                 echo "65532"
7195         else
7196                 echo "65503"
7197         fi
7198 }
7199
7200 # The main purpose of this test is to ensure the OST_INDEX_LIST functions as
7201 # expected. This test uses OST_INDEX_LIST to format OSTs with a randomly
7202 # assigned index and ensures we can mount such a formatted file system
7203 test_81() { # LU-4665
7204         (( MDS1_VERSION >= $(version_code 2.6.54) )) ||
7205                 skip "Need MDS version at least 2.6.54"
7206         (( OSTCOUNT >= 3 )) || skip_env "needs >= 3 OSTs"
7207
7208         stopall
7209
7210         # Each time RANDOM is referenced, a random integer between 0 and 32767
7211         # is generated.
7212         local i
7213         local saved_ostindex1=$OSTINDEX1
7214         local LOV_V1_INSANE_STRIPE_INDEX=$(max_lov_stripe_index ost1)
7215         local invalid_index=$((LOV_V1_INSANE_STRIPE_INDEX+4))
7216
7217         for i in $((LOV_V1_INSANE_STRIPE_INDEX + 3)) $((RANDOM + invalid_index)); do
7218                 echo -e "\nFormat ost1 with --index=$i, should fail"
7219                 OSTINDEX1=$i
7220                 if add ost1 $(mkfs_opts ost1 $(ostdevname 1)) --reformat \
7221                    $(ostdevname 1) $(ostvdevname 1); then
7222                         OSTINDEX1=$saved_ostindex1
7223                         error "format ost1 with --index=$i should fail"
7224                 fi
7225         done
7226         OSTINDEX1=$saved_ostindex1
7227
7228         save_ostindex 3
7229         stack_trap restore_ostindex
7230
7231         # Format OSTs with random sparse indices.
7232         LOV_V1_INSANE_STRIPE_INDEX=$(max_lov_stripe_index ost2)
7233         local rand_ost=$((RANDOM * 2 % (LOV_V1_INSANE_STRIPE_INDEX - 1) + 1))
7234         LOV_V1_INSANE_STRIPE_INDEX=$(max_lov_stripe_index ost3)
7235         echo  "Format $OSTCOUNT OSTs with OST_INDEX_LIST=[0,$rand_ost,$LOV_V1_INSANE_STRIPE_INDEX]"
7236         OST_INDEX_LIST=[0,$rand_ost,$LOV_V1_INSANE_STRIPE_INDEX] formatall ||
7237                 error "formatall failed with $?"
7238
7239         # Setup and check Lustre filesystem.
7240         start_mgsmds || error "start_mgsmds failed"
7241         for ((i = 1; i <= $OSTCOUNT; i++ )); do
7242                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
7243                         error "start ost$i failed"
7244         done
7245
7246         mount_client $MOUNT || error "mount client $MOUNT failed"
7247         check_mount || error "check client $MOUNT failed"
7248         $LFS df
7249
7250         # Check max_easize.
7251         local max_easize=$($LCTL get_param -n llite.*.max_easize)
7252         local xattr_size_max=$((4096 - 84)) # 4096 less ldiskfs ea overhead
7253
7254         # XATTR_SIZE_MAX less ldiskfs ea overhead
7255         large_xattr_enabled && xattr_size_max=$((65536 - 84))
7256         (( max_easize >= xattr_size_max )) ||
7257                 error "max_easize $max_easize < $xattr_size_max bytes"
7258
7259         test_mkdir $DIR/$tdir
7260         $LFS setstripe -i $rand_ost $DIR/$tdir/$tfile ||
7261                 error "error creating $tfile on ost$rand_ost"
7262         $LFS getstripe $DIR/$tdir/$tfile
7263
7264         local cmd
7265         local idx
7266         local found
7267         local uuid
7268
7269         cmd="getstripe -i $DIR/$tdir/$tfile"
7270         echo lfs $cmd
7271         found=$($LFS $cmd)
7272         (( $found == $rand_ost )) || error "index $found is not $rand_ost"
7273
7274         cmd="find $DIR/$tdir -i $rand_ost"
7275         echo lfs $cmd
7276         $LFS $cmd
7277         found=$($LFS $cmd)
7278         [[ "$found" == "$DIR/$tdir/$tfile" ]] ||
7279                 error "'lfs find' returned '$found', not '$tfile' by index"
7280
7281         $LFS osts
7282         uuid=$(ostuuid_from_index $rand_ost)
7283
7284         cmd="find $DIR/$tdir -O $uuid"
7285         echo lfs $cmd
7286         $LFS $cmd
7287         found=$($LFS $cmd)
7288
7289         [[ "$found" == "$DIR/$tdir/$tfile" ]] ||
7290                 error "'lfs find' returned '$found', not '$tfile' by UUID"
7291 }
7292 run_test 81 "sparse OST indexing"
7293
7294 random_ost_indices() {
7295         local num=$1
7296         local LOV_V1_INSANE_STRIPE_INDEX
7297         local index
7298         local skip
7299         local i=0
7300
7301         while ((i < num)); do
7302                 skip=false
7303
7304                 LOV_V1_INSANE_STRIPE_INDEX=$(max_lov_stripe_index ost$((i+1)))
7305                 index=$(((RANDOM * 2) % LOV_V1_INSANE_STRIPE_INDEX))
7306                 for k in $ost_indices; do
7307                         ((index == k)) && skip=true
7308                 done
7309                 $skip && continue
7310                 ost_indices+=" $index"
7311                 i=$((i+1))
7312         done
7313         echo $ost_indices
7314 }
7315
7316 # Here we exercise the stripe placement functionality on a file system that
7317 # has formatted the OST with a random index. With the file system the following
7318 # functionality is tested:
7319 #
7320 # 1. Creating a new file with a specific stripe layout.
7321 #
7322 # 2. Modifiy a existing empty file with a specific stripe layout.
7323 #
7324 # 3. Ensure we fail to set the stripe layout of a file that already has one.
7325 #
7326 # 4. If ost-index is defined we need to ensure it is the first entry in the
7327 #    ost index list returned by lfs getstripe.
7328 #
7329 # 5. Lastly ensure this functionality fails with directories.
7330 test_82a() { # LU-4665
7331         [[ "$MDS1_VERSION" -ge $(version_code 2.6.54) ]] ||
7332                 skip "Need MDS version at least 2.6.54"
7333         [[ $OSTCOUNT -ge 3 ]] || skip_env "needs >= 3 OSTs"
7334
7335         stopall
7336
7337         save_ostindex 3
7338
7339         # Format OSTs with random sparse indices.
7340         local i
7341         local ost_indices
7342
7343         ost_indices=$(comma_list $(random_ost_indices 3))
7344
7345         stack_trap "restore_ostindex" EXIT
7346         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
7347         OST_INDEX_LIST=[$ost_indices] formatall
7348
7349         # Setup Lustre filesystem.
7350         start_mgsmds || error "start_mgsmds failed"
7351         for i in $(seq $OSTCOUNT); do
7352                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
7353                         error "start ost$i failed"
7354         done
7355
7356         # Collect debug information - start of test
7357         do_nodes $(mdts_nodes) "$LCTL get_param osp.*.prealloc_*_id"
7358
7359         mount_client $MOUNT || error "mount client $MOUNT failed"
7360         wait_osts_up
7361
7362         $LFS df $MOUNT
7363         check_lfs_df_ret_val $? || error "$LFS df $MOUNT failed"
7364         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
7365
7366         stack_trap "do_nodes $(mdts_nodes) $LCTL get_param osp.*.prealloc_*_id"
7367
7368         # 1. If the file does not exist, new file will be created
7369         #    with specified OSTs.
7370         local file=$DIR/$tdir/$tfile-1
7371         local cmd="$LFS setstripe -o $ost_indices $file"
7372         echo -e "\n$cmd"
7373         eval $cmd || error "$cmd failed"
7374         check_stripe_count $file $OSTCOUNT
7375         check_obdidx $file $ost_indices
7376         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
7377                 error "write $file failed"
7378
7379         # 2. If the file already exists and is an empty file, the file
7380         #    will be attached with specified layout.
7381         file=$DIR/$tdir/$tfile-2
7382         mcreate $file || error "mcreate $file failed"
7383         cmd="$LFS setstripe -o $ost_indices $file"
7384         echo -e "\n$cmd"
7385         eval $cmd || error "$cmd failed"
7386         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
7387                 error "write $file failed"
7388         check_stripe_count $file $OSTCOUNT
7389         check_obdidx $file $ost_indices
7390
7391         # 3. If the file already has a valid layout attached, the command
7392         #    should fail with EBUSY.
7393         echo -e "\n$cmd"
7394         eval $cmd && error "stripe is already set on $file, $cmd should fail"
7395
7396         # 4. If [--stripe-index|-i <start_ost_idx>] is used, the index must
7397         #    be in the OST indices list.
7398         local start_ost_idx=${ost_indices##*,}
7399         file=$DIR/$tdir/$tfile-3
7400         cmd="$LFS setstripe -o $ost_indices -i $start_ost_idx $file"
7401         echo -e "\n$cmd"
7402         eval $cmd || error "$cmd failed"
7403         check_stripe_count $file $OSTCOUNT
7404         check_obdidx $file $ost_indices
7405         check_start_ost_idx $file $start_ost_idx
7406
7407         file=$DIR/$tdir/$tfile-4
7408         cmd="$LFS setstripe"
7409         cmd+=" -o $(exclude_items_from_list $ost_indices $start_ost_idx)"
7410         cmd+=" -i $start_ost_idx $file"
7411         echo -e "\n$cmd"
7412         eval $cmd && error "index $start_ost_idx should be in $ost_indices"
7413
7414         # 5. Specifying OST indices for directory should succeed.
7415         local dir=$DIR/$tdir/$tdir
7416         mkdir $dir || error "mkdir $dir failed"
7417         cmd="$LFS setstripe -o $ost_indices $dir"
7418         if [ "$MDS1_VERSION" -gt $(version_code 2.11.53) ] &&
7419                 [ "$CLIENT_VERSION" -gt $(version_code 2.11.53) ]; then
7420                 echo -e "\n$cmd"
7421                 eval $cmd || error "unable to specify OST indices on directory"
7422         else
7423                 echo "need MDS+client version at least 2.11.53"
7424         fi
7425 }
7426 run_test 82a "specify OSTs for file (succeed) or directory (succeed)"
7427
7428 # Test 82b is run to ensure that if the user supplies a pool with a specific
7429 # stripe layout that it behaves proprerly. It should fail in the case that
7430 # the supplied OST index list points to OSTs not contained in the user
7431 # supplied pool.
7432 test_82b() { # LU-4665
7433         [[ "$MDS1_VERSION" -ge $(version_code 2.6.54) ]] ||
7434                 skip "Need MDS version at least 2.6.54"
7435         [[ $OSTCOUNT -ge 4 ]] || skip_env "needs >= 4 OSTs"
7436
7437         stopall
7438
7439         save_ostindex 4
7440
7441         # Format OSTs with random sparse indices.
7442         local i
7443         local ost_indices
7444
7445         ost_indices=$(comma_list $(random_ost_indices 4))
7446
7447         stack_trap "restore_ostindex" EXIT
7448         echo -e "\nFormat $OSTCOUNT OSTs with sparse indices $ost_indices"
7449         OST_INDEX_LIST=[$ost_indices] formatall
7450
7451         # Setup Lustre filesystem.
7452         start_mgsmds || error "start_mgsmds failed"
7453         for i in $(seq $OSTCOUNT); do
7454                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS ||
7455                         error "start ost$i failed"
7456         done
7457
7458         mount_client $MOUNT || error "mount client $MOUNT failed"
7459
7460         wait_osts_up
7461         $LFS df $MOUNT
7462         check_lfs_df_ret_val $? || error "$LFS df $MOUNT failed"
7463         mkdir $DIR/$tdir || error "mkdir $DIR/$tdir failed"
7464
7465         # Create a new pool and add OSTs into it.
7466         local ost_pool=$FSNAME.$TESTNAME
7467         create_pool $ost_pool || error "create OST pool $ost_pool failed"
7468
7469         local ost_idx_in_list=${ost_indices##*,}
7470         local ost_idx_in_pool=$(exclude_items_from_list $ost_indices \
7471                                 $ost_idx_in_list)
7472
7473         local ost_targets="$FSNAME-OST["
7474         for i in ${ost_idx_in_pool//,/ }; do
7475                 ost_targets=$ost_targets$(printf "%04x," $i)
7476         done
7477         ost_targets="${ost_targets%,}]"
7478
7479         local ost_targets_uuid=$(for i in ${ost_idx_in_pool//,/ }; \
7480                                  do printf "$FSNAME-OST%04x_UUID\n" $i; done |
7481                                  sort -u | tr '\n' ' ')
7482
7483         local cmd="$LCTL pool_add $ost_pool $ost_targets"
7484         do_facet mgs $cmd || error "$cmd failed"
7485         wait_update $HOSTNAME "$LCTL get_param -n lov.$FSNAME-*.pools.$TESTNAME|
7486                                sort -u | tr '\n' ' ' " "$ost_targets_uuid" ||
7487                                         error "wait_update $ost_pool failed"
7488         wait_update_facet $SINGLEMDS "$LCTL pool_list $ost_pool | wc -l" 4 ||
7489                                 error "wait_update pool_list $ost_pool failed"
7490
7491         # If [--pool|-p <pool_name>] is set with [--ost-list|-o <ost_indices>],
7492         # then the OSTs must be the members of the pool.
7493         local file=$DIR/$tdir/$tfile
7494         cmd="$LFS setstripe -p $ost_pool -o $ost_idx_in_list $file"
7495         echo -e "\n$cmd"
7496         eval $cmd && error "OST with index $ost_idx_in_list should be" \
7497                            "in OST pool $ost_pool"
7498
7499         # Only select OST $ost_idx_in_list from $ost_pool for file.
7500         ost_idx_in_list=${ost_idx_in_pool#*,}
7501         cmd="$LFS setstripe -p $ost_pool -o $ost_idx_in_list $file"
7502         echo -e "\n$cmd"
7503         eval $cmd || error "$cmd failed"
7504         cmd="$LFS getstripe $file"
7505         echo -e "\n$cmd"
7506         eval $cmd || error "$cmd failed"
7507         check_stripe_count $file 2
7508         check_obdidx $file $ost_idx_in_list
7509         dd if=/dev/urandom of=$file count=1 bs=1M > /dev/null 2>&1 ||
7510                 error "write $file failed"
7511 }
7512 run_test 82b "specify OSTs for file with --pool and --ost-list options"
7513
7514 test_83() {
7515         [[ "$OST1_VERSION" -ge $(version_code 2.6.91) ]] ||
7516                 skip "Need OST version at least 2.6.91"
7517         if [ "$ost1_FSTYPE" != ldiskfs ]; then
7518                 skip "ldiskfs only test"
7519         fi
7520
7521         local dev
7522         local ostmnt
7523         local fstype
7524         local mnt_opts
7525
7526         dev=$(ostdevname 1)
7527         ostmnt=$(facet_mntpt ost1)
7528
7529         # Mount the OST as an ldiskfs filesystem.
7530         log "mount the OST $dev as a $ost1_FSTYPE filesystem"
7531         add ost1 $(mkfs_opts ost1 $dev) $FSTYPE_OPT \
7532                 --reformat $dev > /dev/null ||
7533                 error "format ost1 error"
7534
7535         if ! test -b $dev; then
7536                 mnt_opts=$(csa_add "$OST_MOUNT_FS_OPTS" -o loop)
7537         fi
7538         echo "mnt_opts $mnt_opts"
7539         do_facet ost1 mount -t "$ost1_FSTYPE" $dev \
7540                 $ostmnt $mnt_opts
7541         # Run llverfs on the mounted ldiskfs filesystem.
7542         # It is needed to get ENOSPACE.
7543         log "run llverfs in partial mode on the OST $ost1_FSTYPE $ostmnt"
7544         do_rpc_nodes $(facet_host ost1) run_llverfs $ostmnt -vpl \
7545                 "no" || error "run_llverfs error on $ost1_FSTYPE"
7546
7547         # Unmount the OST.
7548         log "unmount the OST $dev"
7549         stop ost1
7550
7551         # Delete file IO_scrub. Later osd_scrub_setup will try to
7552         # create "IO_scrub" but will get ENOSPACE.
7553         writeconf_all
7554         echo "start ost1 service on `facet_active_host ost1`"
7555         start ost1 `ostdevname 1` $OST_MOUNT_OPTS
7556
7557         local err
7558         err=$(do_facet ost1 dmesg | grep "VFS: Busy inodes after unmount of")
7559         echo "string err $err"
7560         [ -z "$err" ] || error $err
7561         reformat_and_config
7562 }
7563 run_test 83 "ENOSPACE on OST doesn't cause message VFS: \
7564 Busy inodes after unmount ..."
7565
7566 test_84() {
7567         local facet=$SINGLEMDS
7568         local num=$(echo $facet | tr -d "mds")
7569         local dev=$(mdsdevname $num)
7570         local time_min=$(recovery_time_min)
7571         local recovery_duration
7572         local completed_clients
7573         local correct_clients
7574         local wrap_up=5
7575
7576         echo "start mds service on $(facet_active_host $facet)"
7577         start_mds "-o recovery_time_hard=$time_min,recovery_time_soft=$time_min" ||
7578                 error "start MDS failed"
7579
7580         start_ost || error "start OST0000 failed"
7581         wait_osc_import_state mds ost1 FULL
7582         start_ost2 || error "start OST0001 failed"
7583         wait_osc_import_state mds ost2 FULL
7584
7585         echo "recovery_time=$time_min, timeout=$TIMEOUT, wrap_up=$wrap_up"
7586
7587         mount_client $MOUNT1 || error "mount $MOUNT1 failed"
7588         mount_client $MOUNT2 || error "mount $MOUNT2 failed"
7589         # make sure new superblock labels are sync'd before disabling writes
7590         sync_all_data
7591         sleep 5
7592
7593         replay_barrier $SINGLEMDS
7594         createmany -o $DIR1/$tfile-%d 1000
7595
7596         # We need to catch the end of recovery window to extend it.
7597         # Skip 5 requests and add delay to request handling.
7598         #define OBD_FAIL_TGT_REPLAY_DELAY  0x709 | FAIL_SKIP
7599         do_facet $SINGLEMDS "lctl set_param fail_loc=0x20000709 fail_val=5"
7600
7601         facet_failover --fsck $SINGLEMDS || error "failover: $?"
7602         client_up
7603
7604         echo "recovery status"
7605         do_facet $SINGLEMDS \
7606                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status"
7607
7608         recovery_duration=$(do_facet $SINGLEMDS \
7609                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
7610                 awk '/recovery_duration/ { print $2 }')
7611         (( $recovery_duration > $time_min + $wrap_up )) &&
7612                 error "recovery_duration > recovery_time_hard + wrap up"
7613         completed_clients=$(do_facet $SINGLEMDS \
7614                 "$LCTL get_param -n mdt.$FSNAME-MDT0000.recovery_status" |
7615                 awk '/completed_clients/ { print $2 }')
7616
7617         correct_clients="$MDSCOUNT/$((MDSCOUNT+1))"
7618         [ "$completed_clients" = "${correct_clients}" ] ||
7619                 error "$completed_clients != $correct_clients"
7620
7621         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
7622         umount_client $MOUNT1
7623         umount_client $MOUNT2
7624
7625         stop_ost
7626         stop_ost2
7627         stop_mds
7628 }
7629 run_test 84 "check recovery_hard_time"
7630
7631 test_85() {
7632         [[ "$OST1_VERSION" -ge $(version_code 2.7.55) ]] ||
7633                 skip "Need OST version at least 2.7.55"
7634 ##define OBD_FAIL_OSD_OST_EA_FID_SET 0x197
7635         do_facet ost1 "lctl set_param fail_loc=0x197"
7636         start_ost
7637         stop_ost
7638 }
7639 run_test 85 "osd_ost init: fail ea_fid_set"
7640
7641 cleanup_86() {
7642         trap 0
7643
7644         # ost1 has already registered to the MGS before the reformat.
7645         # So after reformatting it with option "-G", it could not be
7646         # mounted to the MGS. Cleanup the system for subsequent tests.
7647         reformat_and_config
7648 }
7649
7650 test_86() {
7651         [ "$ost1_FSTYPE" = zfs ] &&
7652                 skip "LU-6442: no such mkfs params for ZFS OSTs"
7653         [[ "$MDS1_VERSION" -ge $(version_code 2.7.56) ]] ||
7654                 skip "Need server version newer than 2.7.55"
7655
7656         local NEWSIZE=1024
7657         local OLDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
7658                 awk '/Flex block group size: / { print $NF; exit; }')
7659
7660         [ "$OLDSIZE" == "$NEWSIZE" ] && skip "$NEWSIZE groups already"
7661
7662         local opts=" -O flex_bg -G $NEWSIZE"
7663         opts=$(OST_FS_MKFS_OPTS+="$opts" mkfs_opts ost1 $(ostdevname 1))
7664         opts+=" --reformat $(ostdevname 1) $(ostvdevname 1)"
7665         echo "params: $opts"
7666
7667         trap cleanup_86 EXIT ERR
7668
7669         stopall
7670         add ost1 $opts || error "add ost1 failed with new params"
7671
7672         local FOUNDSIZE=$(do_facet ost1 "$DEBUGFS -c -R stats $(ostdevname 1)" |
7673                 awk '/Flex block group size: / { print $NF; exit; }')
7674
7675         [[ $FOUNDSIZE == $NEWSIZE ]] ||
7676                 error "Flex block group size: $FOUNDSIZE, expected: $NEWSIZE"
7677
7678         cleanup_86
7679 }
7680 run_test 86 "Replacing mkfs.lustre -G option"
7681
7682 test_87() { #LU-6544
7683         [[ "$MDS1_VERSION" -ge $(version_code 2.9.51) ]] ||
7684                 skip "Need MDS version at least 2.9.51"
7685         [[ "$mds1_FSTYPE" != ldiskfs ]] &&
7686                 skip "ldiskfs only test"
7687         [[ $OSTCOUNT -gt 59 ]] &&
7688                 skip "Ignore wide striping situation"
7689         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
7690
7691         local mdsdev=$(mdsdevname 1)
7692         local mdsvdev=$(mdsvdevname 1)
7693         local file=$DIR/$tfile
7694         local mntpt=$(facet_mntpt $SINGLEMDS)
7695         local used_xattr_blk=0
7696         local inode_size=${1:-1024}
7697         local left_size=0
7698         local xtest="trusted.test"
7699         local value
7700         local orig
7701         local i
7702         local stripe_cnt=$(($OSTCOUNT + 2))
7703
7704         #Please see ldiskfs_make_lustre() for MDT inode size calculation
7705         if [ $stripe_cnt -gt 16 ]; then
7706                 inode_size=2048
7707         fi
7708         left_size=$(expr $inode_size - \
7709                         156 - \
7710                         32 - \
7711                         32 - 40 \* 3 - 32 \* 3 - $stripe_cnt \* 24 - 16 - 3 -  \
7712                         24 - 16 - 3 - \
7713                         24 - 18 - $(expr length $tfile) - 16 - 4)
7714         if [ $left_size -le 0 ]; then
7715                 echo "No space($left_size) is expected in inode."
7716                 echo "Try 1-byte xattr instead to verify this."
7717                 left_size=1
7718         else
7719                 echo "Estimate: at most $left_size-byte space left in inode."
7720         fi
7721
7722         unload_modules
7723         reformat
7724
7725         if ! combined_mgs_mds ; then
7726                 start_mgs
7727         fi
7728
7729         add mds1 $(mkfs_opts mds1 ${mdsdev}) --stripe-count-hint=$stripe_cnt \
7730                 --reformat $mdsdev $mdsvdev || error "add mds1 failed"
7731         start_mdt 1 > /dev/null || error "start mdt1 failed"
7732         for i in $(seq $OSTCOUNT); do
7733                 start ost$i $(ostdevname $i) $OST_MOUNT_OPTS > /dev/null ||
7734                         error "start ost$i failed"
7735         done
7736         mount_client $MOUNT > /dev/null || error "mount client $MOUNT failed"
7737         check_mount || error "check client $MOUNT failed"
7738
7739         #set xattr
7740         $LFS setstripe -E 1M -S 1M -c 1 -E 64M -c 1 -E -1 -c -1 $file ||
7741                 error "Create file with 3 components failed"
7742         $TRUNCATE $file $((1024*1024*64+1)) || error "truncate file failed"
7743         i=$($LFS getstripe -I3 -c $file) || error "get 3rd stripe count failed"
7744         if [ $i -ne $OSTCOUNT ]; then
7745                 left_size=$(expr $left_size + $(expr $OSTCOUNT - $i) \* 24)
7746                 echo -n "Since only $i out $OSTCOUNT OSTs are used, "
7747                 echo -n "the expected left space is changed to "
7748                 echo "$left_size bytes at most."
7749         fi
7750         value=$(generate_string $left_size)
7751         setfattr -n $xtest -v $value $file
7752         orig=$(get_xattr_value $xtest $file)
7753         [[ "$orig" != "$value" ]] && error "$xtest changed"
7754
7755         #Verify if inode has some expected space left
7756         umount $MOUNT > /dev/null || error "umount $MOUNT failed"
7757         stop_mdt 1 > /dev/null || error "stop mdt1 failed"
7758         mount_ldiskfs $SINGLEMDS || error "mount -t ldiskfs $SINGLEMDS failed"
7759
7760         do_facet $SINGLEMDS ls -sal $mntpt/ROOT/$tfile
7761         used_xattr_blk=$(do_facet $SINGLEMDS ls -s $mntpt/ROOT/$tfile |
7762                         awk '{ print $1 }')
7763         [[ $used_xattr_blk -eq 0 ]] &&
7764                 error "Please check MDS inode size calculation: \
7765                        more than $left_size-byte space left in inode."
7766         echo "Verified: at most $left_size-byte space left in inode."
7767
7768         unmount_ldiskfs $SINGLEMDS
7769
7770         for i in $(seq $OSTCOUNT); do
7771                 stop ost$i -f || error "stop ost$i failed"
7772         done
7773 }
7774 run_test 87 "check if MDT inode can hold EAs with N stripes properly"
7775
7776 test_88() {
7777         [ "$mds1_FSTYPE" == zfs ] &&
7778                 skip "LU-6662: no implementation for ZFS"
7779
7780         load_modules
7781
7782         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
7783                 --reformat $(mdsdevname 1) || error "add mds1 failed"
7784
7785         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
7786                 grep -e \".*opts:.*errors=remount-ro.*\"" ||
7787                 error "default mount options is missing"
7788
7789         add mds1 $(mkfs_opts mds1 $(mdsdevname 1)) \
7790                 --mountfsoptions="user_xattr,errors=panic" \
7791                 --reformat $(mdsdevname 1) || error "add mds1 failed"
7792
7793         do_facet mds1 "$TUNEFS $(mdsdevname 1) |
7794                 grep -e \".*opts:.*errors=panic.*\"" ||
7795                 error "user can't override default mount options"
7796 }
7797 run_test 88 "check the default mount options can be overridden"
7798
7799 test_89() { # LU-7131
7800         [[ "$MDS1_VERSION" -ge $(version_code 2.9.54) ]] ||
7801                 skip "Need MDT version at least 2.9.54"
7802
7803         local key=failover.node
7804         local val1=192.0.2.254@tcp0 # Reserved IPs, see RFC 5735
7805         local val2=192.0.2.255@tcp0
7806         local mdsdev=$(mdsdevname 1)
7807         local params
7808
7809         stopall
7810
7811         if [[ "$mds1_FSTYPE" == zfs ]]; then
7812                 import_zpool mds1 || return ${PIPESTATUS[0]}
7813         fi
7814
7815         # Check that parameters are added correctly
7816         echo "tunefs --param $key=$val1"
7817         do_facet mds1 "$TUNEFS --param $key=$val1 $mdsdev >/dev/null" ||
7818                 error "tunefs --param $key=$val1 failed"
7819         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7820                 error "tunefs --dryrun failed"
7821         params=${params##*Parameters:}
7822         params=${params%%exiting*}
7823         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val1) = "1" ] ||
7824                 error "on-disk parameter not added correctly via tunefs"
7825
7826         # Check that parameters replace existing instances when added
7827         echo "tunefs --param $key=$val2"
7828         do_facet mds1 "$TUNEFS --param $key=$val2 $mdsdev >/dev/null" ||
7829                 error "tunefs --param $key=$val2 failed"
7830         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7831                 error "tunefs --dryrun failed"
7832         params=${params##*Parameters:}
7833         params=${params%%exiting*}
7834         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "1" ] ||
7835                 error "on-disk parameter not replaced via tunefs"
7836         [ $(echo $params | tr ' ' '\n' | grep -c $key=$val2) = "1" ] ||
7837                 error "on-disk parameter not replaced correctly via tunefs"
7838
7839         # Check that a parameter is erased properly
7840         echo "tunefs --erase-param $key"
7841         do_facet mds1 "$TUNEFS --erase-param $key $mdsdev >/dev/null" ||
7842                 error "tunefs --erase-param $key failed"
7843         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7844                 error "tunefs --dryrun failed"
7845         params=${params##*Parameters:}
7846         params=${params%%exiting*}
7847         [ $(echo $params | tr ' ' '\n' | grep -c $key=) = "0" ] ||
7848                 error "on-disk parameter not erased correctly via tunefs"
7849
7850         # Check that all the parameters are erased
7851         do_facet mds1 "$TUNEFS --param $key=$val1 $mdsdev >/dev/null" ||
7852                 error "tunefs --param $key=$val1 failed"
7853         echo "tunefs --erase-params"
7854         do_facet mds1 "$TUNEFS --erase-params $mdsdev >/dev/null" ||
7855                 error "tunefs --erase-params failed"
7856         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7857                 error "tunefs --dryrun failed"
7858         params=${params##*Parameters:}
7859         params=${params%%exiting*}
7860         params=$(echo $params | tr ' ' '\n')
7861         [ -z "$params" ] ||
7862                 error "all on-disk parameters not erased correctly via tunefs $params"
7863
7864         # Check the order of options --erase-params and --param
7865         echo "tunefs --param $key=$val1 --erase-params"
7866         do_facet mds1 \
7867                 "$TUNEFS --param $key=$val1 --erase-params $mdsdev >/dev/null"||
7868                 error "tunefs --param $key=$val1 --erase-params failed"
7869         params=$(do_facet mds1 $TUNEFS --dryrun $mdsdev) ||
7870                 error "tunefs --dryrun failed"
7871         params=${params##*Parameters:}
7872         params=${params%%exiting*}
7873         [ $(echo $params | tr ' ' '\n') == "$key=$val1" ] ||
7874                 error "on-disk param not added correctly with --erase-params"
7875
7876         reformat_and_config
7877 }
7878 run_test 89 "check tunefs --param and --erase-param{s} options"
7879
7880 # $1 test directory
7881 # $2 (optional) value of max_mod_rpcs_in_flight to set
7882 check_max_mod_rpcs_in_flight() {
7883         local dir="$1"
7884         local mmr="$2"
7885         local idx
7886         local facet
7887         local tmp
7888         local i
7889
7890         idx=$(printf "%04x" $($LFS getdirstripe -i $dir))
7891         facet="mds$((0x$idx + 1))"
7892
7893         if [ -z "$mmr" ]; then
7894                 # get value of max_mod_rcps_in_flight
7895                 mmr=$($LCTL get_param -n \
7896                         mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight) ||
7897                         error "Unable to get max_mod_rpcs_in_flight"
7898                 echo "max_mod_rcps_in_flight is $mmr"
7899         else
7900                 # set value of max_mod_rpcs_in_flight
7901                 $LCTL set_param \
7902                     mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight=$mmr ||
7903                         error "Unable to set max_mod_rpcs_in_flight to $mmr"
7904                 echo "max_mod_rpcs_in_flight set to $mmr"
7905         fi
7906
7907         # create mmr+1 files
7908         echo "creating $((mmr + 1)) files ..."
7909         umask 0022
7910         for i in $(seq $((mmr + 1))); do
7911                 touch $dir/file-$i
7912         done
7913
7914         ### part 1 ###
7915
7916         # consumes mmr-1 modify RPC slots
7917         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
7918         # drop requests on MDT so that RPC slots are consumed
7919         # during all the request resend interval
7920         do_facet $facet "$LCTL set_param fail_loc=0x159"
7921         echo "launch $((mmr - 1)) chmod in parallel ..."
7922         for i in $(seq $((mmr - 1))); do
7923                 chmod 0600 $dir/file-$i &
7924         done
7925         sleep 1
7926
7927         # send one additional modify RPC
7928         do_facet $facet "$LCTL set_param fail_loc=0"
7929         echo "launch 1 additional chmod in parallel ..."
7930         chmod 0600 $dir/file-$mmr &
7931         sleep 1
7932
7933         # check this additional modify RPC get a modify RPC slot
7934         # and succeed its operation
7935         checkstat -vp 0600 $dir/file-$mmr ||
7936                 error "Unable to send $mmr modify RPCs in parallel"
7937         wait
7938
7939         ### part 2 ###
7940
7941         # consumes mmr modify RPC slots
7942         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
7943         # drop requests on MDT so that RPC slots are consumed
7944         # during all the request resend interval
7945         do_facet $facet "$LCTL set_param fail_loc=0x159"
7946         echo "launch $mmr chmod in parallel ..."
7947         for i in $(seq $mmr); do
7948                 chmod 0666 $dir/file-$i &
7949         done
7950         sleep 1
7951
7952         # send one additional modify RPC
7953         do_facet $facet "$LCTL set_param fail_loc=0"
7954         echo "launch 1 additional chmod in parallel ..."
7955         chmod 0666 $dir/file-$((mmr + 1)) &
7956         sleep 1
7957
7958         # check this additional modify RPC blocked getting a modify RPC slot
7959         checkstat -vp 0644 $dir/file-$((mmr + 1)) ||
7960                 error "Unexpectedly send $(($mmr + 1)) modify RPCs in parallel"
7961         wait
7962 }
7963
7964 get_mdt_max_mod_rpcs_in_flight_val() {
7965         local max_mrif
7966         local facet="$1"
7967
7968         # It will be enough to get one value from one MDT
7969         max_mrif=$(do_facet $facet \
7970                 "$LCTL get_param -n \
7971                 mdt.$FSNAME-MDT*.max_mod_rpcs_in_flight | head -n 1")
7972         if [[ $max_mrif ]]; then
7973                 echo $max_mrif
7974         else
7975                 max_mrif=$(do_facet $facet \
7976                 cat /sys/module/mdt/parameters/max_mod_rpcs_per_client)
7977                 echo $max_mrif
7978         fi
7979 }
7980
7981 set_mdt_max_mod_rpcs_in_flight() {
7982         local lctl_op
7983         local max_mrif="$1"
7984         local facet="$2"
7985
7986         lctl_op=$($LCTL get_param \
7987                 mdt.*.max_mod_rpcs_in_flight)
7988         if [[ $lctl_op ]]; then
7989                 do_facet $facet \
7990                         "$LCTL set_param \
7991                         mdt.$FSNAME-MDT*.max_mod_rpcs_in_flight=$max_mrif"
7992         else
7993                 do_facet $facet \
7994                         "echo $max_mrif > \
7995                         /sys/module/mdt/parameters/max_mod_rpcs_per_client"
7996                 echo "the deprecated max_mod_rpcs_per_client \
7997                                 parameter was involved"
7998         fi
7999 }
8000
8001 test_90a() {
8002         setup
8003
8004         [[ $($LCTL get_param mdc.*.import |
8005              grep "connect_flags:.*multi_mod_rpc") ]] ||
8006                 skip "Need MDC with 'multi_mod_rpcs' feature"
8007
8008         # check default value
8009         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
8010         check_max_mod_rpcs_in_flight $DIR/$tdir
8011
8012         cleanup
8013 }
8014 run_test 90a "check max_mod_rpcs_in_flight is enforced"
8015
8016 test_90b() {
8017         local idx
8018         local facet
8019         local tmp
8020         local mmrpc
8021
8022         setup
8023
8024         [[ $($LCTL get_param mdc.*.import |
8025              grep "connect_flags:.*multi_mod_rpc") ]] ||
8026                 skip "Need MDC with 'multi_mod_rpcs' feature"
8027
8028         ### test 1.
8029         # update max_mod_rpcs_in_flight
8030         $LFS mkdir -c1 $DIR/${tdir}1 || error "mkdir $DIR/${tdir}1 failed"
8031         check_max_mod_rpcs_in_flight $DIR/${tdir}1 1
8032
8033         ### test 2.
8034         # check client is able to send multiple modify RPCs in paralell
8035         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
8036                 grep -c "multi_mod_rpcs")
8037         if [ "$tmp" -ne $MDSCOUNT ]; then
8038                 cleanup
8039                 skip "Client not able to send multiple modify RPCs in parallel"
8040         fi
8041
8042         # update max_mod_rpcs_in_flight
8043         $LFS mkdir -c1 $DIR/${tdir}2 || error "mkdir $DIR/${tdir}2 failed"
8044         check_max_mod_rpcs_in_flight $DIR/${tdir}2 5
8045
8046         ### test 3.
8047         $LFS mkdir -c1 $DIR/${tdir}3 || error "mkdir $DIR/${tdir}3 failed"
8048         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/${tdir}3))
8049         facet="mds$((0x$idx + 1))"
8050
8051         mmrpc=$(get_mdt_max_mod_rpcs_in_flight_val $facet)
8052         echo "mdt_max_mod_rpcs_in_flight is $mmrpc"
8053         # update max_mod_rpcs_in_flight
8054         umount_client $MOUNT
8055         set_mdt_max_mod_rpcs_in_flight 16 $facet
8056         mount_client $MOUNT
8057         $LCTL set_param mdc.$FSNAME-MDT$idx-mdc-*.max_rpcs_in_flight=17
8058         check_max_mod_rpcs_in_flight $DIR/${tdir}3 16
8059
8060         # restore MDT max_mod_rpcs_in_flight initial value
8061         set_mdt_max_mod_rpcs_in_flight $mmrpc $facet
8062
8063         rm -rf $DIR/${tdir}?
8064         cleanup
8065 }
8066 run_test 90b "check max_mod_rpcs_in_flight is enforced after update"
8067
8068 save_params_90c() {
8069         # get max_rpcs_in_flight value
8070         mrif_90c=$($LCTL get_param -n \
8071                    mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
8072         echo "max_rpcs_in_flight is $mrif_90c"
8073
8074         # get MDC max_mod_rpcs_in_flight value
8075         mmrif_90c=$($LCTL get_param -n \
8076                     mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight)
8077         echo "MDC max_mod_rpcs_in_flight is $mmrif_90c"
8078
8079         # get MDT max_mod_rpcs_in_flight value
8080         mmrpc_90c=$(get_mdt_max_mod_rpcs_in_flight_val "mds1")
8081         echo "mdt_max_mod_rpcs_in_flight is $mmrpc_90c"
8082 }
8083
8084 restore_params_90c() {
8085         trap 0
8086
8087         # restore max_rpcs_in_flight value
8088         do_facet mgs $LCTL set_param -P \
8089                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$mrif_90c
8090
8091         # restore max_mod_rpcs_in_flight value
8092         do_facet mgs $LCTL set_param -P \
8093                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mmrif_90c
8094
8095         # restore MDT max_mod_rpcs_in_flight value
8096         set_mdt_max_mod_rpcs_in_flight $mmrpc_90c "mds1"
8097 }
8098
8099 test_90c() {
8100         local tmp
8101
8102         setup
8103
8104         [[ $($LCTL get_param mdc.*.import |
8105              grep "connect_flags:.*multi_mod_rpc") ]] ||
8106                 skip "Need MDC with 'multi_mod_rpcs' feature"
8107
8108         # check client is able to send multiple modify RPCs in paralell
8109         tmp=$($LCTL get_param -n mdc.$FSNAME-MDT*-mdc-*.import |
8110                 grep -c "multi_mod_rpcs")
8111         if [ "$tmp" -ne $MDSCOUNT ]; then
8112                 cleanup
8113                 skip "Client not able to send multiple modify RPCs in parallel"
8114         fi
8115
8116         save_params_90c
8117         stack_trap restore_params_90c
8118
8119         # testcase 1
8120         # attempt to set max_mod_rpcs_in_flight to max_rpcs_in_flight value
8121         # prerequisite: set MDT max_mod_rpcs_in_flight to
8122         # max_rpcs_in_flight value
8123         set_mdt_max_mod_rpcs_in_flight $mrif_90c "mds1"
8124
8125         # if max_mod_rpcs_in_flight is set to be equal to or larger than
8126         # max_rpcs_in_flight, then max_rpcs_in_flight will be increased
8127         if [[ "$CLIENT_VERSION" -ge $(version_code 2.13.53) ]]; then
8128                 $LCTL set_param \
8129                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif_90c ||
8130                         error "set max_mod_rpcs_in_flight to $mrif_90c failed"
8131
8132                 local new_mrif=$($LCTL get_param -n \
8133                                  mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight)
8134                 ((new_mrif == mrif_90c + 1)) ||
8135                         error "max_rpcs_in_flight was not increased"
8136         fi
8137
8138         umount_client $MOUNT
8139         set_mdt_max_mod_rpcs_in_flight $mmrpc_90c "mds1"
8140         mount_client $MOUNT
8141
8142         # testcase 2
8143         # attempt to set max_mod_rpcs_in_flight to MDT max_mod_rpcs_in_flight+1
8144         # prerequisite: set max_rpcs_in_flight to MDT max_mod_rpcs_in_flight+2
8145         $LCTL set_param \
8146                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$((mmrpc_90c + 2))
8147
8148         $LCTL set_param \
8149         mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$((mmrpc_90c + 1)) &&
8150         error "set max_mod_rpcs_in_flight to $((mmrpc_90c + 1)) should fail"
8151
8152         # testcase 3
8153         # attempt to set max_mod_rpcs_in_flight permanently
8154         do_facet mgs $LCTL set_param -P \
8155                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight=$mrif_90c
8156
8157         do_facet mgs $LCTL set_param -P \
8158                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight=$mrif_90c
8159
8160         remount_client $MOUNT
8161
8162         wait_update_facet --verbose client "$LCTL get_param -n \
8163                 mdc.$FSNAME-MDT0000-mdc-*.max_rpcs_in_flight" \
8164                 "$((mrif_90c + 1))" ||
8165                 error "expected '$((mrif_90c + 1))' for max_rpcs_in_flight"
8166
8167         wait_update_facet --verbose client "$LCTL get_param -n \
8168                 mdc.$FSNAME-MDT0000-mdc-*.max_mod_rpcs_in_flight" \
8169                 "$mrif_90c" ||
8170                 error "expected '$mrif_90c' for max_mod_rpcs_in_flight"
8171
8172         restore_params_90c
8173         cleanup
8174 }
8175 run_test 90c "check max_mod_rpcs_in_flight update limits"
8176
8177 test_90d() {
8178         local idx
8179         local facet
8180         local mmr
8181         local i
8182         local pid
8183
8184         setup
8185
8186         [[ $($LCTL get_param mdc.*.import |
8187              grep "connect_flags:.*multi_mod_rpc") ]] ||
8188                 skip "Need MDC with 'multi_mod_rpcs' feature"
8189
8190         $LFS mkdir -c1 $DIR/$tdir || error "mkdir $DIR/$tdir failed"
8191         idx=$(printf "%04x" $($LFS getdirstripe -i $DIR/$tdir))
8192         facet="mds$((0x$idx + 1))"
8193
8194         # check client version supports multislots
8195         tmp=$($LCTL get_param -N \
8196                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
8197         if [ -z "$tmp" ]; then
8198                 cleanup
8199                 skip "Client does not support multiple modify RPCs in flight"
8200         fi
8201
8202         # get current value of max_mod_rcps_in_flight
8203         mmr=$($LCTL get_param -n \
8204                 mdc.$FSNAME-MDT$idx-mdc-*.max_mod_rpcs_in_flight)
8205         echo "max_mod_rcps_in_flight is $mmr"
8206
8207         # create mmr files
8208         echo "creating $mmr files ..."
8209         umask 0022
8210         for i in $(seq $mmr); do
8211                 touch $DIR/$tdir/file-$i
8212         done
8213
8214         # prepare for close RPC
8215         multiop_bg_pause $DIR/$tdir/file-close O_c
8216         pid=$!
8217
8218         # consumes mmr modify RPC slots
8219         #define OBD_FAIL_MDS_REINT_MULTI_NET     0x159
8220         # drop requests on MDT so that RPC slots are consumed
8221         # during all the request resend interval
8222         do_facet $facet "$LCTL set_param fail_loc=0x159"
8223         echo "launch $mmr chmod in parallel ..."
8224         for i in $(seq $mmr); do
8225                 chmod 0600 $DIR/$tdir/file-$i &
8226         done
8227
8228         # send one additional close RPC
8229         do_facet $facet "$LCTL set_param fail_loc=0"
8230         echo "launch 1 additional close in parallel ..."
8231         kill -USR1 $pid
8232         cancel_lru_locks mdc
8233         sleep 1
8234
8235         # check this additional close RPC get a modify RPC slot
8236         # and multiop process completed
8237         [ -d /proc/$pid ] &&
8238                 error "Unable to send the additional close RPC in parallel"
8239         wait
8240         rm -rf $DIR/$tdir
8241         cleanup
8242 }
8243 run_test 90d "check one close RPC is allowed above max_mod_rpcs_in_flight"
8244
8245 check_uuid_on_ost() {
8246         local nid=$1
8247         do_facet ost1 "$LCTL get_param obdfilter.${FSNAME}*.exports.'$nid'.uuid"
8248 }
8249
8250 check_uuid_on_mdt() {
8251         local nid=$1
8252         do_facet $SINGLEMDS "$LCTL get_param mdt.${mds1_svc}*.exports.'$nid'.uuid"
8253 }
8254
8255 test_91() {
8256         local uuid
8257         local nid
8258         local found
8259
8260         [[ "$OST1_VERSION" -ge $(version_code 2.7.63) ]] ||
8261                 skip "Need OST version at least 2.7.63"
8262         [[ "$MDS1_VERSION" -ge $(version_code 2.7.63) ]] ||
8263                 skip "Need MDT version at least 2.7.63"
8264
8265         start_mds || error "MDS start failed"
8266         start_ost || error "unable to start OST"
8267         mount_client $MOUNT || error "client start failed"
8268         check_mount || error "check_mount failed"
8269
8270         if remote_mds; then
8271                 nid=$($LCTL list_nids | head -1 | sed  "s/\./\\\./g")
8272         else
8273                 nid="0@lo"
8274         fi
8275         uuid=$(get_client_uuid $MOUNT)
8276
8277         echo "list nids on mdt:"
8278         do_facet $SINGLEMDS "$LCTL list_param mdt.${FSNAME}*.exports.*"
8279         echo "uuid from $nid:"
8280         do_facet $SINGLEMDS "$LCTL get_param mdt.${FSNAME}*.exports.'$nid'.uuid"
8281
8282         found=$(check_uuid_on_mdt $nid | grep $uuid)
8283         [ -z "$found" ] && error "can't find $uuid $nid on MDT"
8284         found=$(check_uuid_on_ost $nid | grep $uuid)
8285         [ -z "$found" ] && error "can't find $uuid $nid on OST"
8286
8287         # umount the client so it won't reconnect
8288         manual_umount_client --force || error "failed to umount $?"
8289         # shouldn't disappear on MDS after forced umount
8290         found=$(check_uuid_on_mdt $nid | grep $uuid)
8291         [ -z "$found" ] && error "can't find $uuid $nid"
8292
8293         echo "evict $nid"
8294         do_facet $SINGLEMDS \
8295                 "$LCTL set_param -n mdt.${mds1_svc}.evict_client nid:$nid"
8296         sleep 1 # eviction above is async, give it some time to proceed
8297
8298         found=$(check_uuid_on_mdt $nid | grep $uuid)
8299         [ -n "$found" ] && error "found $uuid $nid on MDT"
8300         found=$(check_uuid_on_ost $nid | grep $uuid)
8301         [ -n "$found" ] && error "found $uuid $nid on OST"
8302
8303         # check it didn't reconnect (being umounted)
8304         sleep $((TIMEOUT+1))
8305         found=$(check_uuid_on_mdt $nid | grep $uuid)
8306         [ -n "$found" ] && error "found $uuid $nid on MDT"
8307         found=$(check_uuid_on_ost $nid | grep $uuid)
8308         [ -n "$found" ] && error "found $uuid $nid on OST"
8309
8310         cleanup
8311 }
8312 run_test 91 "evict-by-nid support"
8313
8314 generate_ldev_conf() {
8315         # generate an ldev.conf file
8316         local ldevconfpath=$1
8317         local fstype=
8318         local fsldevformat=""
8319         rm -f $ldevconfpath
8320
8321         local facets="mgs,$(get_facets OST),$(get_facets MDS)"
8322         for facet in ${facets//,/ }; do
8323                 fsldevformat=""
8324                 fstype=$(facet_fstype $facet)
8325                 [ "$fstype" = zfs ] && fsldevformat="$fstype:"
8326                 local host=$(facet_host $facet)
8327                 local fo="-"
8328                 local varfo=${facet}failover_HOST
8329                 if [ $facet == mgs ] && combined_mgs_mds; then
8330                         varfo=mds1failover_HOST
8331                 fi
8332                 [ -n "${!varfo}" ] && fo=${!varfo}
8333                 local type=$(echo $facet | tr -d "[:digit:]" | \
8334                         tr "[:lower:]" "[:upper:]" | sed s/MDS/MDT/ )
8335                 local num=1
8336                 [ ${facet} == mgs ] ||
8337                         num=$(facet_number $facet)
8338                 printf "%s\t%s\t%s-%s%04x\t%s%s\n" \
8339                         ${host} \
8340                         ${fo} \
8341                         $FSNAME \
8342                         $type \
8343                         $(( num - 1 )) \
8344                         $fsldevformat \
8345                         $(facet_device $facet) >> $ldevconfpath
8346         done
8347
8348         echo "----- $ldevconfpath -----"
8349         cat $ldevconfpath
8350         echo "--- END $ldevconfpath ---"
8351
8352 }
8353
8354 generate_nids() {
8355         # generate a nids file (mapping between hostname to nid)
8356         # looks like we only have the MGS nid available to us
8357         # so just echo that to a file
8358         local nidspath=$1
8359         echo -e "${mgs_HOST}\t${MGSNID}" > $nidspath
8360
8361         echo "----- $nidspath -----"
8362         cat $nidspath
8363         echo "--- END $nidspath ---"
8364 }
8365
8366 compare_ldev_output() {
8367         local ldev_output=$1
8368         local expected_output=$2
8369
8370         sort $expected_output -o $expected_output
8371         sort $ldev_output -o $ldev_output
8372
8373         echo "-- START OF LDEV OUTPUT --"
8374         cat $ldev_output
8375         echo "--- END OF LDEV OUTPUT ---"
8376
8377         echo "-- START OF EXPECTED OUTPUT --"
8378         cat $expected_output
8379         echo "--- END OF EXPECTED OUTPUT ---"
8380
8381         diff $expected_output $ldev_output
8382         return $?
8383 }
8384
8385 test_92() {
8386         if [ -z "$LDEV" ]; then
8387                 error "ldev is missing!"
8388         fi
8389
8390         local LDEVCONFPATH=$TMP/ldev.conf
8391         local NIDSPATH=$TMP/nids
8392
8393         echo "Host is $(hostname)"
8394
8395         generate_ldev_conf $LDEVCONFPATH
8396         generate_nids $NIDSPATH
8397
8398         # echo the mgs nid and compare it to environment variable MGSNID
8399         local facets="$(get_facets OST),$(get_facets MDS),mgs"
8400         for facet in ${facets//,/ }; do
8401                 local host=$(facet_host $facet)
8402                 local output=$($LDEV -c $LDEVCONFPATH -H $host -n $NIDSPATH echo %m)
8403
8404                 echo "-- START OF LDEV OUTPUT --"
8405                 echo -e "$output"
8406                 echo "--- END OF LDEV OUTPUT ---"
8407
8408                 [ -z "$output" ] &&
8409                         error "ldev failed to execute!"
8410
8411                 # need to process multiple lines because of
8412                 # several targets on host
8413                 echo -e $output | awk '{ print $2 }' | while read -r line ; do
8414                         [ "$line" = "$MGSNID" ] ||
8415                                 error "ldev failed mgs nid '$line', \
8416                                         expected '$MGSNID'"
8417                 done
8418         done
8419         rm -f $LDEVCONFPATH $NIDSPATH
8420 }
8421 run_test 92 "ldev returns MGS NID correctly in command substitution"
8422
8423 test_93() {
8424         [ $MDSCOUNT -lt 3 ] && skip "needs >= 3 MDTs"
8425
8426         reformat
8427         #start mgs or mgs/mdt0
8428         if ! combined_mgs_mds ; then
8429                 start_mgs
8430                 start_mdt 1
8431         else
8432                 start_mdt 1
8433         fi
8434
8435         start_ost || error "OST0 start fail"
8436
8437         #define OBD_FAIL_MGS_WRITE_TARGET_DELAY  0x90e
8438         do_facet mgs "$LCTL set_param fail_val=10 fail_loc=0x8000090e"
8439         for num in $(seq 2 $MDSCOUNT); do
8440                 start_mdt $num &
8441         done
8442
8443         mount_client $MOUNT || error "mount client fails"
8444         wait_osc_import_state mds ost FULL
8445         wait_osc_import_ready client ost
8446         check_mount || error "check_mount failed"
8447
8448         cleanup || error "cleanup failed with $?"
8449 }
8450 run_test 93 "register mulitple MDT at the same time"
8451
8452 test_94() {
8453         if [ -z "$LDEV" ]; then
8454                 error "ldev is missing!"
8455         fi
8456
8457         local LDEVCONFPATH=$TMP/ldev.conf
8458         local NIDSPATH=$TMP/nids
8459
8460         generate_ldev_conf $LDEVCONFPATH
8461         generate_nids $NIDSPATH
8462
8463         local LDEV_OUTPUT=$TMP/ldev-output.txt
8464         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME > $LDEV_OUTPUT
8465
8466         # ldev failed, error
8467         if [ $? -ne 0 ]; then
8468                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
8469                 error "ldev failed to execute!"
8470         fi
8471
8472         # expected output
8473         local EXPECTED_OUTPUT=$TMP/ldev-expected.txt
8474
8475         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
8476
8477         for num in $(seq $MDSCOUNT); do
8478                 printf "%s-MDT%04x\n" $FSNAME $((num - 1)) >> $EXPECTED_OUTPUT
8479         done
8480
8481         for num in $(seq $OSTCOUNT); do
8482                 printf "%s-OST%04x\n" $FSNAME $((num - 1)) >> $EXPECTED_OUTPUT
8483         done
8484
8485         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
8486
8487         if [ $? -ne 0 ]; then
8488                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8489                 error "ldev failed to produce the correct hostlist!"
8490         fi
8491
8492         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8493 }
8494 run_test 94 "ldev outputs correct labels for file system name query"
8495
8496 test_95() {
8497         if [ -z "$LDEV" ]; then
8498                 error "ldev is missing!"
8499         fi
8500
8501         local LDEVCONFPATH=$TMP/ldev.conf
8502         local NIDSPATH=$TMP/nids
8503
8504         generate_ldev_conf $LDEVCONFPATH
8505         generate_nids $NIDSPATH
8506
8507         # SUCCESS CASES
8508         # file sys filter
8509         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME &>/dev/null
8510         if [ $? -ne 0 ]; then
8511                 rm $LDEVCONFPATH $NIDSPATH
8512                 error "ldev label filtering w/ -F failed!"
8513         fi
8514
8515         # local filter
8516         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -l  &>/dev/null
8517         if [ $? -ne 0 ]; then
8518                 rm $LDEVCONFPATH $NIDSPATH
8519                 error "ldev label filtering w/ -l failed!"
8520         fi
8521
8522         # foreign filter
8523         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f &>/dev/null
8524         if [ $? -ne 0 ]; then
8525                 rm $LDEVCONFPATH $NIDSPATH
8526                 error "ldev label filtering w/ -f failed!"
8527         fi
8528
8529         # all filter
8530         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a &>/dev/null
8531         if [ $? -ne 0 ]; then
8532                 rm $LDEVCONFPATH $NIDSPATH
8533                 error "ldev label filtering w/ -a failed!"
8534         fi
8535
8536         # FAILURE CASES
8537         # all & file sys
8538         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -F $FSNAME &>/dev/null
8539         if [ $? -eq 0 ]; then
8540                 rm $LDEVCONFPATH $NIDSPATH
8541                 error "ldev label filtering w/ -a and -F incorrectly succeeded"
8542         fi
8543
8544         # all & foreign
8545         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -f &>/dev/null
8546         if [ $? -eq 0 ]; then
8547                 rm $LDEVCONFPATH $NIDSPATH
8548                 error "ldev label filtering w/ -a and -f incorrectly succeeded"
8549         fi
8550
8551         # all & local
8552         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -a -l &>/dev/null
8553         if [ $? -eq 0 ]; then
8554                 rm $LDEVCONFPATH $NIDSPATH
8555                 error "ldev label filtering w/ -a and -l incorrectly succeeded"
8556         fi
8557
8558         # foreign & local
8559         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -f -l &>/dev/null
8560         if [ $? -eq 0 ]; then
8561                 rm $LDEVCONFPATH $NIDSPATH
8562                 error "ldev label filtering w/ -f and -l incorrectly succeeded"
8563         fi
8564
8565         # file sys & local
8566         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -l &>/dev/null
8567         if [ $? -eq 0 ]; then
8568                 rm $LDEVCONFPATH $NIDSPATH
8569                 error "ldev label filtering w/ -F and -l incorrectly succeeded"
8570         fi
8571
8572         # file sys & foreign
8573         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -f &>/dev/null
8574         if [ $? -eq 0 ]; then
8575                 rm $LDEVCONFPATH $NIDSPATH
8576                 error "ldev label filtering w/ -F and -f incorrectly succeeded"
8577         fi
8578
8579         rm $LDEVCONFPATH $NIDSPATH
8580 }
8581 run_test 95 "ldev should only allow one label filter"
8582
8583 test_96() {
8584         if [ -z "$LDEV" ]; then
8585                 error "ldev is missing!"
8586         fi
8587
8588         local LDEVCONFPATH=$TMP/ldev.conf
8589         local NIDSPATH=$TMP/nids
8590
8591         generate_ldev_conf $LDEVCONFPATH
8592         generate_nids $NIDSPATH
8593
8594         local LDEV_OUTPUT=$TMP/ldev-output.txt
8595         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -H $mgs_HOST \
8596                 echo %H-%b | \
8597                 awk '{print $2}' > $LDEV_OUTPUT
8598
8599         # ldev failed, error
8600         if [ $? -ne 0 ]; then
8601                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
8602                 error "ldev failed to execute!"
8603         fi
8604
8605         # expected output
8606         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
8607
8608         echo "$mgs_HOST-$(facet_fstype mgs)" > $EXPECTED_OUTPUT
8609
8610         local facets="$(get_facets OST),$(get_facets MDS)"
8611         for facet in ${facets//,/ }; do
8612                 local host=$(facet_host $facet)
8613                 [ "$mgs_HOST" == "$host" ] &&
8614                         echo "$host-$(facet_fstype $facet)" \
8615                         >> $EXPECTED_OUTPUT
8616         done
8617
8618         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
8619
8620         if [ $? -ne 0 ]; then
8621                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8622                 error "ldev failed to produce the correct output!"
8623         fi
8624
8625         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8626 }
8627 run_test 96 "ldev returns hostname and backend fs correctly in command sub"
8628
8629 test_97() {
8630         if [ -z "$LDEV" ]; then
8631                 error "ldev is missing!"
8632         fi
8633
8634         local LDEVCONFPATH=$TMP/ldev.conf
8635         local NIDSPATH=$TMP/nids
8636
8637         generate_ldev_conf $LDEVCONFPATH
8638         generate_nids $NIDSPATH
8639
8640         local LDEV_OUTPUT=$TMP/ldev-output.txt
8641         local EXPECTED_OUTPUT=$TMP/ldev-expected-output.txt
8642
8643         echo -e "\nMDT role"
8644         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mdt > $LDEV_OUTPUT
8645
8646         if [ $? -ne 0 ]; then
8647                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT
8648                 error "ldev failed to execute for mdt role!"
8649         fi
8650
8651         for num in $(seq $MDSCOUNT); do
8652                 printf "%s-MDT%04x\n" $FSNAME $((num - 1)) >> $EXPECTED_OUTPUT
8653         done
8654
8655         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
8656
8657         if [ $? -ne 0 ]; then
8658                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8659                 error "ldev failed to produce the correct output for mdt role!"
8660         fi
8661
8662         echo -e "\nOST role"
8663         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R ost > $LDEV_OUTPUT
8664
8665         if [ $? -ne 0 ]; then
8666                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
8667                 error "ldev failed to execute for ost role!"
8668         fi
8669
8670         rm $EXPECTED_OUTPUT
8671         for num in $(seq $OSTCOUNT); do
8672                 printf "%s-OST%04x\n" $FSNAME $((num - 1)) >> $EXPECTED_OUTPUT
8673         done
8674
8675         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
8676
8677         if [ $? -ne 0 ]; then
8678                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8679                 error "ldev failed to produce the correct output for ost role!"
8680         fi
8681
8682         echo -e "\nMGS role"
8683         $LDEV -c $LDEVCONFPATH -n $NIDSPATH -F $FSNAME -R mgs > $LDEV_OUTPUT
8684
8685         if [ $? -ne 0 ]; then
8686                 rm $LDEVCONFPATH $NIDSPATH $LDEV_OUTPUT $EXPECTED_OUTPUT
8687                 error "ldev failed to execute for mgs role!"
8688         fi
8689
8690         printf "%s-MGS0000\n" $FSNAME > $EXPECTED_OUTPUT
8691
8692         compare_ldev_output $LDEV_OUTPUT $EXPECTED_OUTPUT
8693
8694         if [ $? -ne 0 ]; then
8695                 rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8696                 error "ldev failed to produce the correct output for mgs role!"
8697         fi
8698
8699         rm $LDEVCONFPATH $NIDSPATH $EXPECTED_OUTPUT $LDEV_OUTPUT
8700 }
8701 run_test 97 "ldev returns correct ouput when querying based on role"
8702
8703 test_98()
8704 {
8705         local mountopt
8706
8707         setup
8708         check_mount || error "mount failed"
8709         mountopt="user_xattr"
8710         for ((x = 1; x <= PAGE_SIZE/10; x++)); do
8711                 mountopt="$mountopt,user_xattr"
8712         done
8713         mount.lustre -o remount,$mountopt -v $MGSNID:/$FSNAME $MOUNT 2>&1 |
8714                 tee $TMP/$tfile.out
8715         grep "too long" $TMP/$tfile.out ||
8716                 error "Buffer overflow check failed"
8717
8718         cleanup || error "cleanup failed"
8719 }
8720 run_test 98 "Buffer-overflow check while parsing mount_opts"
8721
8722 test_99()
8723 {
8724         [[ "$ost1_FSTYPE" != ldiskfs ]] &&
8725                 skip "ldiskfs only test"
8726         [[ "$OST1_VERSION" -ge $(version_code 2.8.57) ]] ||
8727                 skip "Need OST version at least 2.8.57"
8728
8729         local ost_opts="$(mkfs_opts ost1 $(ostdevname 1)) \
8730                 --reformat $(ostdevname 1) $(ostvdevname 1)"
8731         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" &&
8732                 skip "meta_bg already set"
8733
8734         local opts=ost_opts
8735         if [[ ${!opts} != *mkfsoptions* ]]; then
8736                 eval opts=\"${!opts} \
8737                 --mkfsoptions='\\\"-O ^resize_inode,meta_bg\\\"'\"
8738         else
8739                 local val=${!opts//--mkfsoptions=\\\"/ \
8740                 --mkfsoptions=\\\"-O ^resize_inode,meta_bg }
8741                 eval opts='${val}'
8742         fi
8743
8744         echo "params: $opts"
8745
8746         load_modules
8747         add ost1 $opts || error "add ost1 failed with new params"
8748
8749         do_facet ost1 $DEBUGFS -c -R stats `ostdevname 1` | grep "meta_bg" ||
8750                 error "meta_bg is not set"
8751 }
8752 run_test 99 "Adding meta_bg option"
8753
8754 test_100() {
8755         reformat
8756
8757         start_mgsmds || error "MDS start failed"
8758         start_ost || error "unable to start OST"
8759         mount_client $MOUNT || error "client start failed"
8760         check_mount || error "check_mount failed"
8761
8762         # Desired output
8763         # MGS:
8764         #     0@lo
8765         # $FSNAME-MDT0000:
8766         #     0@lo
8767         # $FSNAME-OST0000:
8768         #     0@lo
8769         do_facet mgs 'lshowmount -v' | awk 'BEGIN {NR == 0; rc=1} /MGS:/ {rc=0}
8770                 END {exit rc}' || error "lshowmount have no output MGS"
8771
8772         do_facet mds1 'lshowmount -v' | awk 'BEGIN {NR == 2; rc=1} /-MDT0000:/
8773                 {rc=0} END {exit rc}' || error "lshowmount have no output MDT0"
8774
8775         do_facet ost1 'lshowmount -v' | awk 'BEGIN {NR == 4; rc=1} /-OST0000:/
8776                 {rc=0} END {exit rc}' || error "lshowmount have no output OST0"
8777
8778         cleanup || error "cleanup failed with $?"
8779 }
8780 run_test 100 "check lshowmount lists MGS, MDT, OST and 0@lo"
8781
8782 test_101a() {
8783         local createmany_pid
8784         local dev=$FSNAME-OST0000-osc-MDT0000
8785         setup
8786
8787         mkdir_on_mdt0 $DIR1/$tdir
8788         do_nodes $(osts_nodes) \
8789                 $LCTL set_param seq.*OST*-super.width=$DATA_SEQ_MAX_WIDTH
8790         createmany -o $DIR1/$tdir/$tfile-%d 50000 &
8791         createmany_pid=$!
8792         # MDT->OST reconnection causes MDT<->OST last_id synchornisation
8793         # via osp_precreate_cleanup_orphans.
8794         for ((i = 0; i < 100; i++)); do
8795                 for ((k = 0; k < 10; k++)); do
8796                         do_facet $SINGLEMDS "$LCTL --device $dev deactivate;" \
8797                                             "$LCTL --device $dev activate"
8798                 done
8799
8800                 ls -asl $MOUNT | grep '???' &&
8801                         { kill -9 $createmany_pid &>/dev/null;
8802                           error "File has no object on OST"; }
8803
8804                 kill -s 0 $createmany_pid || break
8805         done
8806         wait $createmany_pid
8807
8808         unlinkmany $DIR1/$tdir/$tfile-%d 50000
8809         cleanup
8810 }
8811 run_test 101a "Race MDT->OST reconnection with create"
8812
8813 test_101b () {
8814         local dev=$FSNAME-OST0000-osc-MDT0000
8815         local dir=$DIR1/$tdir
8816         setup
8817
8818         mkdir_on_mdt0 $dir
8819         $LFS setstripe -c 1 -i 0 $dir
8820         do_facet $SINGLEMDS "$LCTL --device $dev deactivate;"
8821 #define OBD_FAIL_OSP_CON_EVENT_DELAY 0x2107
8822         do_facet mds1 "$LCTL set_param fail_loc=0x80002107 fail_val=20"
8823         do_facet $SINGLEMDS "$LCTL --device $dev activate;"
8824         stop_ost
8825         sleep 25
8826         start_ost
8827
8828         wait_osc_import_ready client ost1
8829         touch $dir/$tfile || error "Can't create file"
8830
8831         cleanup
8832 }
8833 run_test 101b "Race events DISCONNECT and ACTIVE in osp"
8834
8835 test_102() {
8836         [[ "$MDS1_VERSION" -gt $(version_code 2.9.53) ]] ||
8837                 skip "Need server version greater than 2.9.53"
8838         [[ "$(mdsdevname 1)" != "$(mgsdevname)" ]] &&
8839                 [[ "$(facet_host mds1)" == "$(facet_host mgs)" ]] &&
8840                 skip "MGS must be on different node or combined"
8841
8842         cleanup || error "cleanup failed with $?"
8843
8844         local mds1dev=$(mdsdevname 1)
8845         local mds1mnt=$(facet_mntpt mds1)
8846         local mds1opts=$MDS_MOUNT_OPTS
8847
8848         if [ "$mds1_FSTYPE" == ldiskfs ] &&
8849            ! do_facet mds1 test -b $mds1dev; then
8850                 mds1opts=$(csa_add "$mds1opts" -o loop)
8851         fi
8852         if [[ "$mds1_FSTYPE" == zfs ]]; then
8853                 import_zpool mds1 || return ${PIPESTATUS[0]}
8854         fi
8855
8856         # unload all and only load libcfs to allow fail_loc setting
8857         do_facet mds1 $LUSTRE_RMMOD || error "unable to unload modules"
8858         do_rpc_nodes $(facet_active_host mds1) load_module ../libcfs/libcfs/libcfs
8859         do_facet mds1 lsmod | grep libcfs || error "libcfs not loaded"
8860
8861         #define OBD_FAIL_OBDCLASS_MODULE_LOAD    0x60a
8862         do_facet mds1 "$LCTL set_param fail_loc=0x8000060a"
8863
8864         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts &&
8865                 error "mdt start must fail" || log "mount failed as expected"
8866         do_facet mds1 lsmod | grep obdclass && error "obdclass must not load" ||
8867                 log "obdclass not loaded as expected"
8868
8869         do_facet mds1 "$LCTL set_param fail_loc=0x0"
8870
8871         do_rpc_nodes $(facet_active_host mds1) load_modules
8872         do_facet mds1 $MOUNT_CMD $mds1dev $mds1mnt $mds1opts &&
8873                 log "mds1 mounted properly" ||
8874                 error "mdt start must not fail"
8875
8876         cleanup || error "cleanup failed with $?"
8877 }
8878 run_test 102 "obdclass module cleanup upon error"
8879
8880 test_renamefs() {
8881         local newname=$1
8882
8883         echo "rename $FSNAME to $newname"
8884
8885         if ! combined_mgs_mds ; then
8886                 local dev=$(mgsdevname)
8887
8888                 do_facet mgs \
8889                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $dev" ||
8890                                 error "(7) Fail to rename MGS"
8891                 if [ "$(facet_fstype mgs)" = "zfs" ]; then
8892                         reimport_zpool mgs $newname-mgs
8893                 fi
8894         fi
8895
8896         for num in $(seq $MDSCOUNT); do
8897                 local dev=$(mdsdevname $num)
8898
8899                 do_facet mds${num} \
8900                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $dev" ||
8901                                 error "(8) Fail to rename MDT $num"
8902                 if [ "$(facet_fstype mds${num})" = "zfs" ]; then
8903                         reimport_zpool mds${num} $newname-mdt${num}
8904                 fi
8905         done
8906
8907         for num in $(seq $OSTCOUNT); do
8908                 local dev=$(ostdevname $num)
8909
8910                 do_facet ost${num} \
8911                         "$TUNEFS --fsname=$newname --rename=$FSNAME -v $dev" ||
8912                                 error "(9) Fail to rename OST $num"
8913                 if [ "$(facet_fstype ost${num})" = "zfs" ]; then
8914                         reimport_zpool ost${num} $newname-ost${num}
8915                 fi
8916         done
8917 }
8918
8919 test_103_set_pool() {
8920         local pname=$1
8921         local ost_x=$2
8922
8923         do_facet mgs $LCTL pool_add $FSNAME.$pname ${FSNAME}-$ost_x ||
8924                 error "Fail to add $ost_x to $FSNAME.$pname"
8925         wait_update $HOSTNAME \
8926                 "lctl get_param -n lov.$FSNAME-clilov-*.pools.$pname |
8927                  grep $ost_x" "$FSNAME-${ost_x}_UUID" ||
8928                 error "$ost_x is NOT in pool $FSNAME.$pname"
8929 }
8930
8931 test_103_check_pool() {
8932         local save_fsname=$1
8933         local errno=$2
8934
8935         stat $DIR/$tdir/test-framework.sh ||
8936                 error "($errno) Fail to stat"
8937         do_facet mgs $LCTL pool_list $FSNAME.pool1 ||
8938                 error "($errno) Fail to list $FSNAME.pool1"
8939         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname ||
8940                 error "($errno) Fail to list $FSNAME.$save_fsname"
8941         do_facet mgs $LCTL pool_list $FSNAME.$save_fsname |
8942                 grep ${FSNAME}-OST0000 ||
8943                 error "($errno) List $FSNAME.$save_fsname is invalid"
8944
8945         local pname=$($LFS getstripe --pool $DIR/$tdir/d0)
8946         [ "$pname" = "$save_fsname" ] ||
8947                 error "($errno) Unexpected pool name $pname"
8948 }
8949
8950 test_103() {
8951         check_mount_and_prep
8952         rm -rf $DIR/$tdir
8953         mkdir $DIR/$tdir || error "(1) Fail to mkdir $DIR/$tdir"
8954         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir ||
8955                 error "(2) Fail to copy test-framework.sh"
8956
8957         do_facet mgs $LCTL pool_new $FSNAME.pool1 ||
8958                 error "(3) Fail to create $FSNAME.pool1"
8959         # name the pool name as the fsname
8960         do_facet mgs $LCTL pool_new $FSNAME.$FSNAME ||
8961                 error "(4) Fail to create $FSNAME.$FSNAME"
8962
8963         test_103_set_pool $FSNAME OST0000
8964
8965         $LFS setstripe -p $FSNAME $DIR/$tdir/d0 ||
8966                 error "(6) Fail to setstripe on $DIR/$tdir/d0"
8967
8968         KEEP_ZPOOL=true
8969         stopall
8970
8971         test_renamefs mylustre
8972
8973         local save_fsname=$FSNAME
8974         FSNAME="mylustre"
8975         setupall
8976
8977         test_103_check_pool $save_fsname 7
8978
8979         if [ $OSTCOUNT -ge 2 ]; then
8980                 test_103_set_pool $save_fsname OST0001
8981         fi
8982
8983         $LFS setstripe -p $save_fsname $DIR/$tdir/f0 ||
8984                 error "(16) Fail to setstripe on $DIR/$tdir/f0"
8985
8986         stopall
8987
8988         test_renamefs tfs
8989
8990         FSNAME="tfs"
8991         setupall
8992
8993         test_103_check_pool $save_fsname 17
8994
8995         stopall
8996
8997         test_renamefs $save_fsname
8998
8999         FSNAME=$save_fsname
9000         setupall
9001         KEEP_ZPOOL=false
9002 }
9003 run_test 103 "rename filesystem name"
9004
9005 test_104a() { # LU-6952
9006         local mds_mountopts=$MDS_MOUNT_OPTS
9007         local ost_mountopts=$OST_MOUNT_OPTS
9008         local mds_mountfsopts=$MDS_MOUNT_FS_OPTS
9009         local lctl_ver=$(do_facet $SINGLEMDS $LCTL --version |
9010                         awk '{ print $2 }')
9011
9012         [[ $(version_code $lctl_ver) -lt $(version_code 2.9.55) ]] &&
9013                 skip "this test needs utils above 2.9.55"
9014
9015         # specify "acl" in mount options used by mkfs.lustre
9016         if [ -z "$MDS_MOUNT_FS_OPTS" ]; then
9017                 MDS_MOUNT_FS_OPTS="acl,user_xattr"
9018         else
9019
9020                 MDS_MOUNT_FS_OPTS="${MDS_MOUNT_FS_OPTS},acl,user_xattr"
9021         fi
9022
9023         echo "mountfsopt: $MDS_MOUNT_FS_OPTS"
9024
9025         #reformat/remount the MDT to apply the MDT_MOUNT_FS_OPT options
9026         formatall
9027         if ! combined_mgs_mds ; then
9028                 start_mgs
9029         fi
9030
9031         if [ -z "$MDS_MOUNT_OPTS" ]; then
9032                 MDS_MOUNT_OPTS="-o noacl"
9033         else
9034                 MDS_MOUNT_OPTS="${MDS_MOUNT_OPTS},noacl"
9035         fi
9036
9037         for num in $(seq $MDSCOUNT); do
9038                 start mds$num $(mdsdevname $num) $MDS_MOUNT_OPTS ||
9039                         error "Failed to start MDS"
9040         done
9041
9042         for num in $(seq $OSTCOUNT); do
9043                 start ost$num $(ostdevname $num) $OST_MOUNT_OPTS ||
9044                         error "Failed to start OST"
9045         done
9046
9047         mount_client $MOUNT
9048         setfacl -m "d:$RUNAS_ID:rwx" $MOUNT &&
9049                 error "ACL is applied when FS is mounted with noacl."
9050
9051         MDS_MOUNT_OPTS=$mds_mountopts
9052         OST_MOUNT_OPTS=$ost_mountopts
9053         MDS_MOUNT_FS_OPTS=$mds_mountfsopts
9054 }
9055 run_test 104a "Make sure user defined options are reflected in mount"
9056
9057 test_104b() { # LU-12859
9058         mount_client $MOUNT3 flock,localflock
9059         stack_trap "umount_client $MOUNT3" EXIT
9060         mount | grep "$MOUNT3 .*,flock" && error "flock is still set"
9061         mount | grep "$MOUNT3 .*,localflock" || error "localflock is not set"
9062         umount_client $MOUNT3
9063         mount_client $MOUNT3 localflock,flock
9064         mount | grep "$MOUNT3 .*,localflock" && error "localflock is still set"
9065         mount | grep "$MOUNT3 .*,flock" || error "flock is not set"
9066         umount_client $MOUNT3
9067         mount_client $MOUNT3 localflock,flock,noflock
9068         flock_is_enabled $MOUNT3 && error "some flock is still enabled" || true
9069 }
9070 run_test 104b "Mount uses last flock argument"
9071
9072 error_and_umount() {
9073         umount $TMP/$tdir
9074         rmdir $TMP/$tdir
9075         error $*
9076 }
9077
9078 test_105() {
9079         cleanup -f
9080         reformat
9081         setup_noconfig
9082         mkdir -p $TMP/$tdir
9083         mount --bind $DIR $TMP/$tdir || error "mount bind mnt pt failed"
9084         rm -f $TMP/$tdir/$tfile
9085         rm -f $TMP/$tdir/${tfile}1
9086
9087         # Files should not be created in ro bind mount point
9088         # remounting from rw to ro
9089         mount -o remount,ro $TMP/$tdir ||
9090                 error_and_umount "readonly remount of bind mnt pt failed"
9091         touch $TMP/$tdir/$tfile &&
9092                 error_and_umount "touch succeeds on ro bind mnt pt"
9093         [ -e $TMP/$tdir/$tfile ] &&
9094                 error_and_umount "file created on ro bind mnt pt"
9095
9096         # Files should be created in rw bind mount point
9097         # remounting from ro to rw
9098         mount -o remount,rw $TMP/$tdir ||
9099                 error_and_umount "read-write remount of bind mnt pt failed"
9100         touch $TMP/$tdir/${tfile}1 ||
9101                 error_and_umount "touch fails on rw bind mnt pt"
9102         [ -e $TMP/$tdir/${tfile}1 ] ||
9103                 error_and_umount "file not created on rw bind mnt pt"
9104         umount $TMP/$tdir || error "umount of bind mnt pt failed"
9105         rmdir $TMP/$tdir
9106         cleanup || error "cleanup failed with $?"
9107 }
9108 run_test 105 "check file creation for ro and rw bind mnt pt"
9109
9110 test_106() {
9111         local repeat=5
9112         local creates=64768     # one full plain llog
9113
9114         # ensure there are enough inodes in the filesystem
9115         (( OSTSIZE < (creates + 1024) * 16)) && OSTSIZE=$(((creates + 1024) * 16))
9116         reformat
9117         setup_noconfig
9118         lfs df -i
9119         mkdir -p $DIR/$tdir || error "create $tdir failed"
9120         do_nodes $(osts_nodes) \
9121                 $LCTL set_param seq.*OST*-super.width=$DATA_SEQ_MAX_WIDTH
9122         lfs setstripe -c 1 -i 0 $DIR/$tdir
9123 #define OBD_FAIL_CAT_RECORDS                        0x1312
9124         do_facet mds1 $LCTL set_param fail_loc=0x1312 fail_val=$repeat
9125
9126         for ((i = 1; i <= $repeat; i++)); do
9127                 createmany -o $DIR/$tdir/f- $creates || lfs df -i
9128                 createmany -u $DIR/$tdir/f- $creates
9129                 wait_delete_completed $((TIMEOUT * 7))
9130         done
9131 #ASSERTION osp_sync_thread() ( thread->t_flags != SVC_RUNNING ) failed
9132 #shows that osp code is buggy
9133         do_facet mds1 $LCTL set_param fail_loc=0 fail_val=0
9134
9135         cleanup
9136 }
9137 run_test 106 "check osp llog processing when catalog is wrapped"
9138
9139 test_107() {
9140         [[ "$MDS1_VERSION" -ge $(version_code 2.10.50) ]] ||
9141                 skip "Need MDS version > 2.10.50"
9142         local cmd
9143
9144         start_mgsmds || error "start_mgsmds failed"
9145         start_ost || error "unable to start OST"
9146
9147         # add unknown configuration parameter.
9148         if [[ $PERM_CMD == *"set_param -P"* ]]; then
9149                 cmd="$PERM_CMD ost.$FSNAME-OST0000*.unknown_param"
9150         else
9151                 cmd="$PERM_CMD $FSNAME-OST0000*.ost.unknown_param"
9152         fi
9153         do_facet mgs "$cmd=50"
9154         cleanup_nocli || error "cleanup_nocli failed with $?"
9155         load_modules
9156
9157         # unknown param should be ignored while mounting.
9158         start_ost || error "unable to start OST after unknown param set"
9159
9160         cleanup || error "cleanup failed with $?"
9161 }
9162 run_test 107 "Unknown config param should not fail target mounting"
9163
9164 t_108_prep() {
9165         local facet
9166
9167         $rcmd rm -rf $tmp > /dev/null 2>&1
9168         $rcmd mkdir -p $tmp/{mnt,images} || error "failed to mkdir remotely"
9169
9170         for facet in $facets; do
9171                 [ "$mds1_FSTYPE" = zfs ] &&
9172                         $rcmd $ZPOOL -f export lustre-$facet > /dev/null 2>&1
9173                 $rcmd mkdir $tmp/mnt/$facet ||
9174                         error "failed to mkdir $tmp/mnt/$facet"
9175                 $rcmd dd if=/dev/zero of=$tmp/images/$facet \
9176                         seek=199 bs=1M count=1 ||
9177                         error "failed to create $tmp/images/$facet"
9178         done
9179 }
9180
9181 t_108_mkfs() {
9182         local role=$1
9183         local idx=$2
9184         local bkfs=$3
9185         local mgs=$4
9186         local facet=${role}$((idx + 1))
9187         local pool=""
9188         [ $# -eq 5 ] && pool=$5
9189
9190         do_facet $SINGLEMDS $MKFS --fsname=lustre --$mgs \
9191                 --$role --index=$idx --replace --backfstype=$bkfs \
9192                 --device-size=200000 --reformat $pool $tmp/images/$facet ||
9193                 error "failed to mkfs for $facet"
9194 }
9195
9196 t_108_check() {
9197         echo "mounting client..."
9198         mount -t lustre ${nid}:/lustre $MOUNT ||
9199                 error "failed to mount lustre"
9200
9201         echo "check list"
9202         ls -l $MOUNT/local_dir || error "failed to list"
9203
9204         echo "check truncate && write"
9205         echo "dummmmmmmmmmmmm" > $MOUNT/remote_dir/fsx.c ||
9206                 error "failed to tuncate & write"
9207
9208         echo "check create"
9209         touch $MOUNT/foooo ||
9210                 error "failed to create"
9211
9212         echo "check read && write && append"
9213         sha1sum $MOUNT/conf-sanity.sh |
9214                 awk '{ print $1 }' > $MOUNT/checksum.new ||
9215                 error "failed to read(1)"
9216         sha1sum $MOUNT/remote_dir/unlinkmany.c |
9217                 awk '{ print $1 }' >> $MOUNT/checksum.new ||
9218                 error "failed to read(2)"
9219         sha1sum $MOUNT/striped_dir/lockahead_test.o |
9220                 awk '{ print $1 }' >> $MOUNT/checksum.new ||
9221                 error "failed to read(3)"
9222
9223         echo "verify data"
9224         diff $MOUNT/checksum.new $MOUNT/checksum.src ||
9225                 error "failed to verify data"
9226
9227         echo "done."
9228 }
9229
9230 t_108_cleanup() {
9231         trap 0
9232         local facet
9233
9234         echo "cleanup..."
9235         umount -f $MOUNT || error "failed to umount client"
9236         for facet in $facets; do
9237                 $rcmd umount -f $tmp/mnt/$facet ||
9238                         error "failed to umount $facet"
9239                 if [ "$mds1_FSTYPE" = zfs ]; then
9240                         $rcmd $ZPOOL export -f lustre-$facet ||
9241                                 error "failed to export lustre-$facet"
9242                 fi
9243         done
9244
9245         $rcmd rm -rf $tmp || error "failed to rm the dir $tmp"
9246 }
9247
9248 test_108a() {
9249         [ "$CLIENTONLY" ] && skip "Client-only testing"
9250         [ "$mds1_FSTYPE" != zfs ] && skip "zfs only test"
9251         [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
9252                 skip "Need server version at least 2.10.58"
9253
9254         stopall
9255         load_modules
9256
9257         local tmp=$TMP/$tdir
9258         local rcmd="do_facet $SINGLEMDS"
9259         local facets="mdt1 mdt2 ost1 ost2"
9260         local nid=$($rcmd $LCTL list_nids | head -1)
9261         local facet
9262
9263         trap t_108_cleanup EXIT ERR
9264         t_108_prep
9265
9266         t_108_mkfs mdt 0 zfs mgs lustre-mdt1/mdt1
9267         t_108_mkfs mdt 1 zfs mgsnode=$nid lustre-mdt2/mdt2
9268         t_108_mkfs ost 0 zfs mgsnode=$nid lustre-ost1/ost1
9269         t_108_mkfs ost 1 zfs mgsnode=$nid lustre-ost2/ost2
9270
9271         for facet in $facets; do
9272                 $rcmd zfs set mountpoint=$tmp/mnt/$facet canmount=on \
9273                         lustre-$facet/$facet ||
9274                         error "failed to zfs set for $facet (1)"
9275                 $rcmd zfs mount lustre-$facet/$facet ||
9276                         error "failed to local mount $facet"
9277                 $rcmd tar jxf $LUSTRE/tests/ldiskfs_${facet}_2_11.tar.bz2 \
9278                         --xattrs --xattrs-include="trusted.*" \
9279                         -C $tmp/mnt/$facet/ > /dev/null 2>&1 ||
9280                         error "failed to untar image for $facet"
9281                 $rcmd "cd $tmp/mnt/$facet && rm -rf oi.* OI_* lfsck_* LFSCK" ||
9282                         error "failed to cleanup for $facet"
9283                 $rcmd zfs umount lustre-$facet/$facet ||
9284                         error "failed to local umount $facet"
9285                 $rcmd zfs set canmount=off lustre-$facet/$facet ||
9286                         error "failed to zfs set $facet (2)"
9287         done
9288
9289         echo "changing server nid..."
9290         $rcmd mount -t lustre -o nosvc lustre-mdt1/mdt1 $tmp/mnt/mdt1
9291         $rcmd lctl replace_nids $FSNAME-MDT0000 $nid
9292         $rcmd lctl replace_nids $FSNAME-MDT0001 $nid
9293         $rcmd lctl replace_nids $FSNAME-OST0000 $nid
9294         $rcmd lctl replace_nids $FSNAME-OST0001 $nid
9295         $rcmd umount $tmp/mnt/mdt1
9296
9297         for facet in $facets; do
9298                 echo "mounting $facet from backup..."
9299                 $rcmd mount -t lustre -o abort_recov lustre-$facet/$facet \
9300                         $tmp/mnt/$facet || error "failed to mount $facet"
9301         done
9302
9303         # ZFS backend can detect migration and trigger OI scrub automatically
9304         # sleep 3 seconds for scrub done
9305         sleep 3
9306
9307         t_108_check
9308         t_108_cleanup
9309 }
9310 run_test 108a "migrate from ldiskfs to ZFS"
9311
9312 test_108b() {
9313         [ "$CLIENTONLY" ] && skip "Client-only testing"
9314         [ "$mds1_FSTYPE" != ldiskfs ] && skip "ldiskfs only test"
9315         [ "$MDS1_VERSION" -lt $(version_code 2.10.58) ] &&
9316                 skip "Need server version at least 2.10.58"
9317
9318         stopall
9319         load_modules
9320
9321         local tmp=$TMP/$tdir
9322         local rcmd="do_facet $SINGLEMDS"
9323         local facets="mdt1 mdt2 ost1 ost2"
9324         local scrub_list="MDT0000 MDT0001 OST0000 OST0001"
9325         local nid=$($rcmd $LCTL list_nids | head -1)
9326         local facet
9327
9328         trap t_108_cleanup EXIT ERR
9329         t_108_prep
9330
9331         t_108_mkfs mdt 0 ldiskfs mgs
9332         t_108_mkfs mdt 1 ldiskfs mgsnode=$nid
9333         t_108_mkfs ost 0 ldiskfs mgsnode=$nid
9334         t_108_mkfs ost 1 ldiskfs mgsnode=$nid
9335
9336         for facet in $facets; do
9337                 $rcmd mount -t ldiskfs -o loop $tmp/images/$facet \
9338                         $tmp/mnt/$facet ||
9339                         error "failed to local mount $facet"
9340
9341                 $rcmd tar jxf $LUSTRE/tests/zfs_${facet}_2_11.tar.bz2 \
9342                         --xattrs --xattrs-include="*.*" \
9343                         -C $tmp/mnt/$facet/ > /dev/null 2>&1 ||
9344                         error "failed to untar image for $facet"
9345                 $rcmd "cd $tmp/mnt/$facet && rm -rf oi.* OI_* lfsck_* LFSCK" ||
9346                         error "failed to cleanup for $facet"
9347                 $rcmd umount $tmp/mnt/$facet ||
9348                         error "failed to local umount $facet"
9349         done
9350
9351         echo "changing server nid..."
9352         $rcmd mount -t lustre -o nosvc,loop $tmp/images/mdt1 $tmp/mnt/mdt1
9353         $rcmd lctl replace_nids $FSNAME-MDT0000 $nid
9354         $rcmd lctl replace_nids $FSNAME-MDT0001 $nid
9355         $rcmd lctl replace_nids $FSNAME-OST0000 $nid
9356         $rcmd lctl replace_nids $FSNAME-OST0001 $nid
9357         $rcmd umount $tmp/mnt/mdt1
9358
9359         for facet in $facets; do
9360                 echo "mounting $facet from backup..."
9361                 $rcmd mount -t lustre -o loop,abort_recov $tmp/images/$facet \
9362                         $tmp/mnt/$facet || error "failed to mount $facet"
9363         done
9364
9365         for facet in $scrub_list; do
9366                 $rcmd $LCTL lfsck_start -M $FSNAME-$facet -t scrub ||
9367                         error "failed to start OI scrub on $facet"
9368         done
9369
9370         # sleep 3 seconds for scrub done
9371         sleep 3
9372
9373         t_108_check
9374         t_108_cleanup
9375 }
9376 run_test 108b "migrate from ZFS to ldiskfs"
9377
9378 #
9379 # set number of permanent parameters
9380 #
9381 test_109_set_params() {
9382         local fsname=$1
9383
9384         set_persistent_param_and_check mds                          \
9385             "mdd.$fsname-MDT0000.atime_diff"                        \
9386             "$fsname-MDT0000.mdd.atime_diff"                        \
9387             "62"
9388         set_persistent_param_and_check mds                          \
9389             "mdd.$fsname-MDT0000.atime_diff"                        \
9390             "$fsname-MDT0000.mdd.atime_diff"                        \
9391             "63"
9392         set_persistent_param_and_check client                       \
9393             "llite.$fsname*.max_read_ahead_mb"                      \
9394             "$fsname.llite.max_read_ahead_mb"                       \
9395             "32"
9396         set_persistent_param_and_check client                       \
9397             "llite.$fsname*.max_read_ahead_mb"                      \
9398             "$fsname.llite.max_read_ahead_mb"                       \
9399             "64"
9400         create_pool $fsname.pool1 || error "create pool failed"
9401         do_facet mgs $LCTL pool_add $fsname.pool1 OST0000 ||
9402                 error "pool_add failed"
9403         do_facet mgs $LCTL pool_remove $fsname.pool1 OST0000 ||
9404                 error "pool_remove failed"
9405         do_facet mgs $LCTL pool_add $fsname.pool1 OST0000 ||
9406                 error "pool_add failed"
9407 }
9408
9409 #
9410 # check permanent parameters
9411 #
9412 test_109_test_params() {
9413         local fsname=$1
9414
9415         local atime_diff=$(do_facet mds $LCTL \
9416                 get_param -n mdd.$fsname-MDT0000.atime_diff)
9417         [ $atime_diff == 63 ] || error "wrong mdd parameter after clear_conf"
9418         local max_read_ahead_mb=$(do_facet client $LCTL \
9419                 get_param -n llite.$fsname*.max_read_ahead_mb)
9420         [ $max_read_ahead_mb == 64 ] ||
9421                 error "wrong llite parameter after clear_conf"
9422         local ost_in_pool=$(do_facet mds $LCTL pool_list $fsname.pool1 |
9423                 grep -v "^Pool:" | sed 's/_UUID//')
9424         [ $ost_in_pool = "$fsname-OST0000" ] ||
9425                 error "wrong pool after clear_conf"
9426 }
9427
9428 #
9429 # run lctl clear_conf, store CONFIGS before and after that
9430 #
9431 test_109_clear_conf()
9432 {
9433         local clear_conf_arg=$1
9434
9435         local mgsdev
9436         if ! combined_mgs_mds ; then
9437                 mgsdev=$(mgsdevname)
9438                 stop_mgs || error "stop_mgs failed"
9439                 start_mgs "-o nosvc" || error "start_mgs nosvc failed"
9440         else
9441                 mgsdev=$(mdsdevname 1)
9442                 start_mdt 1 "-o nosvc" || error "start_mdt 1 nosvc failed"
9443         fi
9444
9445         do_facet mgs "rm -rf $TMP/${tdir}/conf1; mkdir -p $TMP/${tdir}/conf1;" \
9446                 "$DEBUGFS -c -R \\\"rdump CONFIGS $TMP/${tdir}/conf1\\\" \
9447                 $mgsdev"
9448
9449         #
9450         # the command being tested
9451         #
9452         do_facet mgs $LCTL clear_conf $clear_conf_arg ||
9453                 error "clear_conf failed"
9454         if ! combined_mgs_mds ; then
9455                 stop_mgs || error "stop_mgs failed"
9456         else
9457                 stop_mdt 1 || error "stop_mdt 1 failed"
9458         fi
9459
9460         do_facet mgs "rm -rf $TMP/${tdir}/conf2; mkdir -p $TMP/${tdir}/conf2;" \
9461                 "$DEBUGFS -c -R \\\"rdump CONFIGS $TMP/${tdir}/conf2\\\" \
9462                 $mgsdev"
9463 }
9464
9465 test_109_file_shortened() {
9466         local file=$1
9467         local sizes=($(do_facet mgs "stat -c %s " \
9468                 "$TMP/${tdir}/conf1/CONFIGS/$file" \
9469                 "$TMP/${tdir}/conf2/CONFIGS/$file"))
9470         [ ${sizes[1]} -lt ${sizes[0]} ] && return 0
9471         return 1
9472 }
9473
9474 test_109a()
9475 {
9476         [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
9477                 skip "Needs MDS version 2.10.59 or later."
9478         [ "$(facet_fstype mgs)" == zfs ] &&
9479                 skip "LU-8727: no implementation for ZFS"
9480
9481         stopall
9482         reformat
9483         setup_noconfig
9484         client_up || error "client_up failed"
9485
9486         #
9487         # set number of permanent parameters
9488         #
9489         test_109_set_params $FSNAME
9490
9491         umount_client $MOUNT || error "umount_client failed"
9492         stop_ost || error "stop_ost failed"
9493         stop_mds || error "stop_mds failed"
9494
9495         test_109_clear_conf $FSNAME
9496         #
9497         # make sure that all configs are cleared
9498         #
9499         test_109_file_shortened $FSNAME-MDT0000 ||
9500                 error "failed to clear MDT0000 config"
9501         test_109_file_shortened $FSNAME-client ||
9502                 error "failed to clear client config"
9503
9504         setup_noconfig
9505
9506         #
9507         # check that configurations are intact
9508         #
9509         test_109_test_params $FSNAME
9510
9511         #
9512         # Destroy pool.
9513         #
9514         destroy_test_pools || error "destroy test pools failed"
9515
9516         cleanup
9517 }
9518 run_test 109a "test lctl clear_conf fsname"
9519
9520 test_109b()
9521 {
9522         [ $MDS1_VERSION -lt $(version_code 2.10.59) ] &&
9523                 skip "Needs MDS version 2.10.59 or later."
9524         [ "$(facet_fstype mgs)" == zfs ] &&
9525                 skip "LU-8727: no implementation for ZFS"
9526
9527         stopall
9528         reformat
9529         setup_noconfig
9530         client_up || error "client_up failed"
9531
9532         #
9533         # set number of permanent parameters
9534         #
9535         test_109_set_params $FSNAME
9536
9537         umount_client $MOUNT || error "umount_client failed"
9538         stop_ost || error "stop_ost failed"
9539         stop_mds || error "stop_mds failed"
9540
9541         test_109_clear_conf $FSNAME-MDT0000
9542         #
9543         # make sure that only one config is cleared
9544         #
9545         test_109_file_shortened $FSNAME-MDT0000 ||
9546                 error "failed to clear MDT0000 config"
9547         test_109_file_shortened $FSNAME-client &&
9548                 error "failed to clear client config"
9549
9550         setup_noconfig
9551         #
9552         # check that configurations are intact
9553         #
9554         test_109_test_params $FSNAME
9555
9556         #
9557         # Destroy pool.
9558         #
9559         destroy_test_pools || error "destroy test pools failed"
9560
9561         cleanup
9562 }
9563 run_test 109b "test lctl clear_conf one config"
9564
9565 test_110()
9566 {
9567         [[ "$mds1_FSTYPE" == ldiskfs ]] ||
9568                 skip "Only applicable to ldiskfs-based MDTs"
9569         do_facet mds1 $DEBUGFS -w -R supported_features |grep large_dir ||
9570                 skip "large_dir option is not supported on MDS"
9571
9572         # stop all targets before modifying the target counts
9573         local old_mdscount=$MDSCOUNT
9574         local old_ostcount=$OSTCOUNT
9575         stack_trap "MDSCOUNT=$old_mdscount OSTCOUNT=$old_ostcount \
9576                 reformat_and_config"
9577         MDSCOUNT=1
9578         OSTCOUNT=1
9579         reformat
9580         # ext4_dir_entry_2 struct size:264
9581         # dx_root struct size:8
9582         # dx_node struct size:8
9583         # dx_entry struct size:8
9584         # For 1024 bytes block size.
9585         # First level directory entries: 126
9586         # Second level directory entries: 127
9587         # Entries in leaf: 3
9588         # For 2 levels limit: 48006
9589         # For 3 levels limit : 6096762
9590         # Create enough files to safely exceed 2-level htree limit.
9591         CONF_SANITY_110_LINKS=${CONF_SANITY_110_LINKS:-60000}
9592
9593         # can fit at most 3 filenames per 1KB leaf block, but each
9594         # leaf/index block will only be 3/4 full before split at each level
9595         (( MDSSIZE < CONF_SANITY_110_LINKS / 3 * 4/3 * 4/3 )) &&
9596                 CONF_SANITY_110_LINKS=$((MDSSIZE * 3 * 3/4 * 3/4))
9597
9598         local dev=$(mdsdevname 1)
9599         local opts="$(mkfs_opts mds1 $dev) --reformat $dev $(mdsvdevname 1)"
9600
9601         if [[ $opts != *large_dir* ]]; then
9602                 if [[ $opts != *mkfsoptions* ]]; then
9603                         opts+=" --mkfsoptions=\\\"-O large_dir\\\""
9604                 else
9605                         if [[ $opts != *-O* ]]; then
9606                                 opts="${opts//--mkfsoptions=\\\"/ \
9607                                         --mkfsoptions=\\\"-O large_dir }"
9608                         else
9609                                 opts="${opts/-O /-O large_dir,}"
9610                         fi
9611                 fi
9612         fi
9613
9614         # Use INDEX_UNASSIGNED for index for --mkfsoptions
9615         if [[ $opts != *mkfsoptions* ]]; then
9616                 opts+=" --mkfsoptions=\\\"-b 1024 -i 65536\\\""
9617         else
9618                 opts="${opts//--mkfsoptions=\\\"/ \
9619                         --mkfsoptions=\\\"-b 1024 -i 65536 }"
9620         fi
9621
9622         echo "MDT params: $opts"
9623         load_modules
9624         combined_mgs_mds || start_mgs
9625         add mds1 $opts || error "add mds1 failed with new params"
9626         start mds1 $dev $MDS_MOUNT_OPTS || error "start mds1 failed"
9627         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS || error "start ost1 failed"
9628         MOUNT_2=yes mountcli || error "mount clients failed"
9629
9630         mkdir -v $DIR/$tdir || error "cannot create $DIR/$tdir"
9631         local pids count=0 group=0
9632
9633         echo "creating $CONF_SANITY_110_LINKS in total"
9634         while (( count < CONF_SANITY_110_LINKS )); do
9635                 local len=$((253 - $(wc -c <<<"$tfile-$group-40000-")))
9636                 local dir=DIR$((group % 2 + 1))
9637                 local target=${!dir}/$tdir/$tfile-$group
9638                 local long=$target-$(generate_name $len)-
9639                 local create=$((CONF_SANITY_110_LINKS - count))
9640
9641                 (( create > 40000 )) && create=40000
9642                 touch $target || error "creating $target failed"
9643                 echo "creating $create hard links to $target"
9644                 createmany -l $target $long $create &
9645                 pids+=" $!"
9646
9647                 count=$((count + create))
9648                 group=$((group + 1))
9649         done
9650         echo "waiting for PIDs$pids to complete"
9651         wait $pids || error "createmany failed after $group groups"
9652
9653         stopall
9654
9655         run_e2fsck $(facet_active_host mds1) $dev -n
9656 }
9657 run_test 110 "Adding large_dir with 3-level htree"
9658
9659 test_111() {
9660         [[ "$mds1_FSTYPE" = ldiskfs ]] ||
9661                 skip "Only applicable to ldiskfs-based MDTs"
9662         do_facet mds1 $DEBUGFS -w -R supported_features |grep large_dir ||
9663                 skip "large_dir option is not supported on MDS"
9664
9665         # cleanup before changing target counts
9666         local old_mdscount=$MDSCOUNT
9667         local old_ostcount=$OSTCOUNT
9668         local old_mdssize=$MDSSIZE
9669         stack_trap "MDSSIZE=$old_mdssize MDSCOUNT=$old_mdscount \
9670                     OSTCOUNT=$old_ostcount reformat_and_config"
9671         MDSCOUNT=1
9672         OSTCOUNT=1
9673         reformat
9674         local min=5000000
9675         # cannot enlarge a block device, so skip the test if size not enough
9676         local dev=$(mdsdevname 1)
9677
9678         if is_blkdev mds1 $dev; then
9679                 is_blkdev mds1 $dev $min ||
9680                         skip "$dev too small for ${min}kB MDS"
9681         fi
9682         (( MDSSIZE < min )) && MDSSIZE=$min # need at least 2.4GB
9683         local opts="$(mkfs_opts mds1 $dev) --reformat $dev $(mdsvdevname 1)"
9684         if [[ $opts != *large_dir* ]]; then
9685                 if [[ $opts != *mkfsoptions* ]]; then
9686                         opts+=" --mkfsoptions=\\\"-O large_dir\\\""
9687                 else
9688                         if [[ $opts != *-O* ]]; then
9689                                 opts="${opts//--mkfsoptions=\\\"/ \
9690                                         --mkfsoptions=\\\"-O large_dir }"
9691                         else
9692                                 opts="${opts/-O /-O large_dir,}"
9693                         fi
9694                 fi
9695         fi
9696
9697         echo "MDT params: $opts"
9698         load_modules
9699         combined_mgs_mds || start_mgs
9700         add mds1 $opts || error "add mds1 failed with new params"
9701         start mds1 $dev $MDS_MOUNT_OPTS ||
9702                 error "start mds1 failed"
9703         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS ||
9704                 error "start ost1 failed"
9705
9706         MOUNT_2=yes mountcli
9707         mkdir $DIR/$tdir || error "cannot create $DIR/$tdir"
9708         $LFS df $DIR/$tdir
9709         $LFS df -i $DIR/$tdir
9710
9711         local group=0
9712
9713         local start=$SECONDS
9714         local dirsize=0
9715         local dirmax=$((2 << 30))
9716         local needskip=0
9717         local taken=0
9718         local rate=0
9719         local left=0
9720         local num=0
9721         while (( !needskip & dirsize < dirmax )); do
9722                 local pids=""
9723
9724                 for cli in ${CLIENTS//,/ }; do
9725                         local len=$((253 - $(wc -c <<<"$cli-$group-60000-")))
9726                         local target=$cli-$group
9727                         local long=$DIR/$tdir/$target-$(generate_name $len)-
9728
9729                         RPWD=$DIR/$tdir do_node $cli touch $target ||
9730                                 error "creating $target failed"
9731                         echo "creating 60000 hardlinks to $target"
9732                         RPWD=$DIR/$tdir do_node $cli createmany -l $target $long 60000 &
9733                         pids+=" $!"
9734
9735                         group=$((group + 1))
9736                         target=$cli-$group
9737                         long=$DIR2/$tdir/$target-$(generate_name $len)-
9738
9739                         RPWD=$DIR2/$tdir do_node $cli touch $target ||
9740                                 error "creating $target failed"
9741                         echo "creating 60000 hardlinks to $target"
9742                         RPWD=$DIR2/$tdir do_node $cli createmany -l $target $long 60000 &
9743                         pids+=" $!"
9744
9745                         group=$((group + 1))
9746                 done
9747                 echo "waiting for PIDs$pids to complete"
9748                 wait $pids || error "createmany failed after $group groups"
9749
9750                 dirsize=$(stat -c %s $DIR/$tdir)
9751                 taken=$((SECONDS - start))
9752                 rate=$((dirsize / taken))
9753                 left=$(((dirmax - dirsize) / rate))
9754                 num=$((group * 60000))
9755                 echo "estimate ${left}s left after $num files / ${taken}s"
9756                 echo "Reached $dirsize of $dirmax directory size"
9757                 echo "Free space:"
9758                 $LFS df $DIR/$tdir
9759                 $LFS df -i $DIR/$tdir
9760
9761                 $FORCE_TEST_111 && continue
9762                 # if the estimated time remaining is too large (it may change
9763                 # over time as the create rate is not constant) then exit
9764                 # without declaring a failure.
9765                 (( left > 1200 )) && needskip=1
9766         done
9767
9768         umount_client $MOUNT2 -f
9769         cleanup
9770         ! (( needskip )) ||
9771                 skip "ETA ${left}s after $num files / ${taken}s is too long"
9772         run_e2fsck $(facet_active_host mds1) $dev -n
9773 }
9774 run_test 111 "Adding large_dir with over 2GB directory"
9775
9776 test_112a() {
9777         local param="no_create"
9778
9779         (( $OST1_VERSION > $(version_code 2.14.0) )) ||
9780                 skip "need OSS at least 2.14.0"
9781         (( $OST1_VERSION >= $(version_code 2.15.56.125) )) ||
9782                 param="no_precreate"
9783
9784         start_mds || error "MDS start failed"
9785         start_ost || error "OSS start failed"
9786         echo "start ost2 service on $(facet_active_host ost2)"
9787         start ost2 $(ostdevname 2) $(csa_add "$OST_MOUNT_OPTS" -o $param) ||
9788                 error "start ost2 facet failed"
9789         local val=$(do_facet ost2 \
9790                    "$LCTL get_param -n obdfilter.$FSNAME-OST0001*.$param")
9791         (( $val == 1 )) || error "obdfilter.$FSNAME-OST0001*.$param=$val"
9792
9793         mount_client $MOUNT || error "mount client failed"
9794         wait_osc_import_state mds1 ost1 FULL
9795         wait_osc_import_ready client ost1
9796         wait_osc_import_ready client ost2
9797
9798         $LFS setstripe -i 0 $DIR/$tfile.0 ||
9799                 error "problem creating $tfile.0 on OST0000"
9800         $LFS setstripe -i 1 $DIR/$tfile.1 && $LFS getstripe $DIR/$tfile.1 &&
9801                 (( $($LFS getstripe -i $DIR/$tfile.1) == 1 )) &&
9802                 error "allowed to create $tfile.1 on OST0001"
9803         $LFS df -v $MOUNT
9804         $LFS df -v $MOUNT | grep -q "OST:1.*N" ||
9805                 error "NOCREATE not in 'lfs df'"
9806
9807         do_facet ost2 $LCTL set_param obdfilter.$FSNAME-OST0001*.$param=0
9808         sleep_maxage
9809         $LFS setstripe -i 1 $DIR/$tfile.2 ||
9810                 error "failed to create $tfile.2 on ost1 facet"
9811         # files not cleaned with ONLY_REPEAT because of client unmount below
9812         rm -f $DIR/$tfile.[012]
9813         stop_ost2 || error "stop ost2 facet failed"
9814         cleanup
9815 }
9816 run_test 112a "mount OST with no_create option"
9817
9818 test_112b() {
9819         (( MDSCOUNT >= 2 )) || skip "need at least 2 MDTs"
9820         (( $MDS1_VERSION >= $(version_code 2.15.56.125) )) ||
9821                 skip "need MDS >= 2.15.56.125"
9822         local mdsnum=$MDSCOUNT
9823         local facet=mds$mdsnum
9824         local mdtidx=$((mdsnum - 1))
9825         local mdtname=$FSNAME-MDT$(printf %04x $mdtidx)
9826
9827         start_mds --mdscount $((mdsnum - 1)) || error "MDS start failed"
9828         start_mdt $mdsnum -o no_create || error "start $facet failed"
9829         local val=$(do_facet $facet \
9830                    "$LCTL get_param -n mdt.$mdtname*.no_create")
9831         (( $val == 1 )) || error "mdt.$mdtname*.no_create=$val"
9832         start_ost || error "ost1 start failed"
9833         start_ost2 || error "ost1 start failed"
9834
9835         mount_client $MOUNT || error "mount client failed"
9836         wait_osc_import_ready $facet ost2
9837
9838         $LFS df -v $MOUNT
9839         $LFS df -v $MOUNT | grep -q "MDT:$mdtidx.*N" ||
9840                 error "NOCREATE not in 'lfs df'"
9841
9842         $LFS mkdir -i $mdtidx $DIR/$tdir ||
9843                 $LFS setdirstripe -D -c 1 -i -1 --max-inherit-rr 2 $DIR/$tdir ||
9844                 error "error creating $tdir on $mdtname"
9845         stack_trap "rm -rf $DIR/$tdir"
9846
9847         mkdir $DIR/$tdir/d1.{1..100} || error "mkdir $tdir/d1.{1..100} failed"
9848         $LFS getdirstripe -i $DIR/$tdir/d1.* | sort | uniq -c
9849         do_facet $facet $LCTL set_param mdt.$mdtname*.no_create=0
9850         # allow one initial create for delayed statfs on client
9851         (( $($LFS getdirstripe -i $DIR/$tdir/d1.* | grep -c $mdtidx) < 2 )) ||
9852                 error "allowed create on $mdtname"
9853         sleep_maxage_lmv
9854
9855         mkdir $DIR/$tdir/d2.{1..100} || error "mkdir $tdir/d2.{1..100} failed"
9856         $LFS getdirstripe -i $DIR/$tdir/d2.{1..100} | sort | uniq -c
9857         (( $($LFS getdirstripe -i $DIR/$tdir/d2.* | grep -c $mdtidx) > 10 )) ||
9858                 error "no create on $mdtname"
9859         # files not cleaned with ONLY_REPEAT because of client unmount below
9860         rm -r $DIR/$tdir
9861         stop_ost2 || error "ost1 start failed"
9862         cleanup
9863 }
9864 run_test 112b "mount MDT with no_create option"
9865
9866 # Global for 113
9867 SAVE_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
9868 SAVE_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
9869 SAVE_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
9870
9871 cleanup_113() {
9872         trap 0
9873
9874         stopall
9875         MGS_MOUNT_OPTS=$SAVE_MGS_MOUNT_OPTS
9876         MDS_MOUNT_OPTS=$SAVE_MDS_MOUNT_OPTS
9877         OST_MOUNT_OPTS=$SAVE_OST_MOUNT_OPTS
9878         # Revert old mount options back
9879         setupall
9880         # Subsequent following test requires
9881         # conf-sanity to be in stopall state.
9882         # Force 'stopall' so others following
9883         # test can pass
9884         stopall
9885 }
9886
9887 # Error out with mount info
9888 error_113() {
9889         local err=$1
9890
9891         echo "--Client Mount Info--"
9892         mount | grep -i lustre
9893         echo "--Server Mount Info--"
9894         do_nodes $(tgts_nodes) mount | grep -i lustre
9895
9896         error $err
9897 }
9898
9899 test_113() {
9900         local ost_version="2.15.51" # Minimum version required
9901
9902         (( OST1_VERSION >= $(version_code $ost_version) )) ||
9903                 skip "Need server version at least $ost_version"
9904         sync; sleep 3
9905         stack_trap cleanup_113 EXIT
9906
9907         # Reset before starting
9908         stopall
9909         setupall
9910
9911         # Verify MDS's should start with "rw"
9912         do_facet $SINGLEMDS mount | grep "lustre.*rw,.*MDT" ||
9913                 error_113 "$SINGLEMDS should be read-write"
9914
9915         # Verify OST's should start with "rw"
9916         for (( i=1; i <= OSTCOUNT; i++ )); do
9917                 do_facet ost$i mount | grep "lustre.*rw,.*OST" ||
9918                         error_113 "ost$i should be read-write"
9919         done
9920
9921         # rdonly_dev does not currently work for ldiskfs
9922         # We skip the rdonly_dev check until then.
9923         if [[ $ost1_FSTYPE == ldiskfs ]]; then
9924                 echo "Shadow Mountpoint correctly reports rw for ldiskfs"
9925                 return 0
9926         fi
9927
9928         #
9929         # Only ZFS specific tests below.
9930         #
9931
9932         # Must stop all (server+client) and restart to verify new
9933         # mount options
9934         stopall
9935
9936         # add rdonly_dev to mount option
9937         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
9938         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
9939         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
9940
9941         # Only restart server(mds/ost). Sufficient for test
9942         setupall server_only || error "Fail to start servers"
9943
9944         # Verify MDS's should be "ro"
9945         do_facet $SINGLEMDS mount | grep "lustre.*ro,.*MDT.*rdonly_dev" ||
9946                 error_113 "$SINGLEMDS should be read-only"
9947
9948         # Verify OST's should be "ro"
9949         for (( i=1; i <= OSTCOUNT; i++ )); do
9950                 do_facet ost$i mount | grep "lustre.*ro,.*OST.*rdonly_dev" ||
9951                         error_113 "ost$i should be read-only"
9952         done
9953 }
9954 run_test 113 "Shadow mountpoint correctly report ro/rw for mounts"
9955
9956 #
9957 # Purpose: To verify dynamic thread (OSS) creation.
9958 # (This was sanity/115)
9959 #
9960 test_114() {
9961         [ $PARALLEL == "yes" ] && skip "skip parallel run"
9962         remote_ost_nodsh && skip "remote OST with nodsh"
9963
9964         # Lustre does not stop service threads once they are started.
9965         # Reset number of running threads to default.
9966         stopall
9967         setupall
9968
9969         local OSTIO_pre
9970         local save_params="$TMP/sanity-$TESTNAME.parameters"
9971
9972         # Get ll_ost_io count before I/O
9973         OSTIO_pre=$(do_facet ost1 \
9974                 "$LCTL get_param ost.OSS.ost_io.threads_started | cut -d= -f2")
9975         # Exit if lustre is not running (ll_ost_io not running).
9976         [ -z "$OSTIO_pre" ] && error "no OSS threads"
9977
9978         echo "Starting with $OSTIO_pre threads"
9979         local thread_max=$((OSTIO_pre * 2))
9980         local rpc_in_flight=$((thread_max * 2))
9981
9982         # this is limited to OSC_MAX_RIF_MAX (256)
9983         [ $rpc_in_flight -gt 256 ] && rpc_in_flight=256
9984         thread_max=$((rpc_in_flight / 2))
9985         [ $thread_max -le $OSTIO_pre ] && skip "Too many ost_io threads" &&
9986                 return
9987
9988         # Number of I/O Process proposed to be started.
9989         local nfiles
9990         local facets=$(get_facets OST)
9991
9992         save_lustre_params client "osc.*OST*.max_rpcs_in_flight" > $save_params
9993         save_lustre_params $facets "ost.OSS.ost_io.threads_max" >> $save_params
9994
9995         # Set in_flight to $rpc_in_flight
9996         $LCTL set_param osc.*OST*.max_rpcs_in_flight=$rpc_in_flight ||
9997                 error "Failed to set max_rpcs_in_flight to $rpc_in_flight"
9998         nfiles=${rpc_in_flight}
9999         # Set ost thread_max to $thread_max
10000         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.threads_max=$thread_max"
10001
10002         # 5 Minutes should be sufficient for max number of OSS
10003         # threads(thread_max) to be created.
10004         local timeout=300
10005
10006         # Start I/O.
10007         local wtl=${WTL:-"$LUSTRE/tests/write_time_limit"}
10008
10009         test_mkdir $DIR/$tdir
10010         for ((i = 1; i <= nfiles; i++)); do
10011                 local file=$DIR/$tdir/${tfile}-$i
10012
10013                 $LFS setstripe -c -1 -i 0 $file
10014                 ($wtl $file $timeout)&
10015         done
10016
10017         # I/O Started - Wait for thread_started to reach thread_max or report
10018         # error if thread_started is more than thread_max.
10019         echo "Waiting for thread_started to reach thread_max"
10020         local thread_started=0
10021         local end_time=$((SECONDS + timeout))
10022
10023         while [ $SECONDS -le $end_time ] ; do
10024                 echo -n "."
10025                 # Get ost i/o thread_started count.
10026                 thread_started=$(do_facet ost1 \
10027                         "$LCTL get_param \
10028                         ost.OSS.ost_io.threads_started | cut -d= -f2")
10029                 # Break out if thread_started is equal/greater than thread_max
10030                 if (( $thread_started >= $thread_max )); then
10031                         echo ll_ost_io thread_started $thread_started, \
10032                                 equal/greater than thread_max $thread_max
10033                         break
10034                 fi
10035                 sleep 1
10036         done
10037
10038         # Cleanup - We have the numbers, Kill i/o jobs if running.
10039         jobcount=($(jobs -p))
10040
10041         for ((i=0; i < ${#jobcount[*]}; i++)); do
10042                 kill -9 ${jobcount[$i]}
10043                 if [ $? -ne 0 ] ; then
10044                         echo "warning: cannot kill WTL pid ${jobcount[$i]}"
10045                 fi
10046         done
10047
10048         # Cleanup files left by WTL binary.
10049         for ((i = 1; i <= nfiles; i++)); do
10050                 local file=$DIR/$tdir/${tfile}-$i
10051
10052                 rm -rf $file
10053                 if [ $? -ne 0 ] ; then
10054                         echo "Warning: Failed to delete file $file"
10055                 fi
10056         done
10057
10058         restore_lustre_params <$save_params
10059         rm -f $save_params || echo "Warning: delete file '$save_params' failed"
10060
10061         # Error out if no new thread has started or Thread started is greater
10062         # than thread max.
10063         if (( $thread_started <= $OSTIO_pre ||
10064                 $thread_started > $thread_max )); then
10065                 error "ll_ost_io: thread_started $thread_started" \
10066                       "OSTIO_pre $OSTIO_pre, thread_max $thread_max." \
10067                       "No new thread started or thread started greater " \
10068                       "than thread_max."
10069         fi
10070 }
10071 run_test 114 "verify dynamic thread creation===================="
10072
10073 cleanup_115()
10074 {
10075         trap 0
10076         stopall
10077         do_facet mds1 rm -f $1
10078 }
10079
10080 test_115() {
10081         if [ "$mds1_FSTYPE" != ldiskfs ]; then
10082                 skip "Only applicable to ldiskfs-based MDTs"
10083         fi
10084         [ -n "$FILESET" ] && skip "Not functional for FILESET set"
10085
10086         local dbfs_ver=$(do_facet mds1 $DEBUGFS -V 2>&1)
10087
10088         echo "debugfs version: $dbfs_ver"
10089         echo "$dbfs_ver" | egrep -w "1.44.3.wc1|1.44.5.wc1|1.45.2.wc1" &&
10090                 skip_env "This version of debugfs doesn't show inode number"
10091
10092         local IMAGESIZE=$((3072 << 30)) # 3072 GiB
10093
10094         stopall
10095
10096         FLAKEY=false
10097
10098         echo "client1: "
10099         $LCTL dl
10100         mount | grep lustre
10101         echo "mds1: "
10102         do_facet mds1 "hostname; $LCTL dl; mount"
10103         echo "ost1: "
10104         do_facet ost1 "hostname; $LCTL dl; mount"
10105         # We need MDT size 3072GB, because it is smallest
10106         # partition that can store 2B inodes
10107         do_facet mds1 "mkdir -p $TMP/$tdir"
10108         local mdsimgname=$TMP/$tdir/lustre-mdt
10109
10110         do_facet mds1 "rm -f $mdsimgname"
10111         do_facet mds1 "touch $mdsimgname"
10112         stack_trap "cleanup_115 $mdsimgname" EXIT
10113         do_facet mds1 "$TRUNCATE $mdsimgname $IMAGESIZE" ||
10114                 skip "Backend FS doesn't support sparse files"
10115         local mdsdev=$(do_facet mds1 "losetup -f")
10116
10117         do_facet mds1 "losetup $mdsdev $mdsimgname"
10118
10119         local mds_opts="$(mkfs_opts mds1 $(mdsdevname 1))        \
10120                 --mkfsoptions='-O ea_inode,^resize_inode,meta_bg \
10121                 -N 2247484000 -E lazy_itable_init' --device-size=$IMAGESIZE"
10122         add mds1 $mds_opts --mgs --reformat $mdsdev || {
10123                 do_facet $SINGLEMDS \
10124                         "losetup -d $mdsdev && rm -f $mdsimgname"
10125                 skip_env "format large MDT failed"
10126         }
10127
10128         local ostdev=$(ostdevname 1)
10129
10130         local opts="$(mkfs_opts ost1 $ostdev) \
10131                 --reformat $ostdev $ostdev"
10132         add ost1 $opts || error "add ost1 failed with new params"
10133         start mds1  $mdsdev $MDS_MOUNT_OPTS || error "start MDS failed"
10134         start_ost || error "start OSS failed"
10135         mount_client $MOUNT || error "mount client failed"
10136
10137         mkdir -p $DIR/$tdir || error "mkdir $DIR/$tdir fail"
10138         local goal="/sys/fs/ldiskfs/$(basename $mdsdev)/inode_goal"
10139         echo goal: $goal
10140         # 2147483648 is 0x80000000
10141         do_facet mds1 "echo 2147483648 >> $goal; grep . $goal"
10142         touch $DIR/$tdir/$tfile
10143
10144         # attrs from 1 to 16 go to block, 17th - to inode
10145         local i
10146
10147         for i in {1..17}; do
10148                 local nm="trusted.ea$i"
10149                 setfattr -n $nm -v $(printf "xattr%0250d" $i) $DIR/$tdir/$tfile
10150         done
10151
10152         do_facet mds1 "$DEBUGFS -c -R 'stat ROOT/$tdir/$tfile' $mdsdev"
10153
10154         # inode <2147483649> trusted.ea16 (255)
10155         local inode_num=$(do_facet mds1 \
10156                         "$DEBUGFS -c -R 'stat ROOT/$tdir/$tfile' $mdsdev" |
10157                          awk '/ea17/ { print $2 }' |
10158                          sed -e 's/>//' -e 's/<//' -e 's/\"//')
10159         echo "inode num: $inode_num"
10160         [ $inode_num -ge 2147483648 ] || error "inode $inode_num too small"
10161         do_facet mds1 "losetup -d $mdsdev"
10162 }
10163 run_test 115 "Access large xattr with inodes number over 2TB"
10164
10165 test_116() {
10166         [ "$mds1_FSTYPE" != ldiskfs ] && skip "ldiskfs only test"
10167         [ "$MDS1_VERSION" -lt $(version_code 2.10.59) ] &&
10168                 skip "Need server version at least 2.10.59"
10169         do_facet $SINGLEMDS which mkfs.xfs ||
10170                 skip_env "No mkfs.xfs installed"
10171
10172         stopall
10173         load_modules
10174
10175         local tmpmnt=$TMP/$tdir
10176         local mdtimg=$tfile-mdt0
10177
10178         do_facet $SINGLEMDS mkdir -p $tmpmnt
10179         stack_trap "do_facet $SINGLEMDS rmdir $tmpmnt" EXIT
10180
10181         do_facet $SINGLEMDS touch $TMP/$mdtimg
10182         stack_trap "do_facet $SINGLEMDS rm -f $TMP/$mdtimg" EXIT
10183         do_facet $SINGLEMDS mkfs -t xfs -d file,size=1t,name=$TMP/$mdtimg ||
10184                 error "mkfs temporary xfs image"
10185
10186         do_facet $SINGLEMDS mount $TMP/$mdtimg $tmpmnt ||
10187                 error "mount temporary xfs image"
10188         stack_trap "do_facet $SINGLEMDS umount $tmpmnt" EXIT
10189         local old_mdssize=$MDSSIZE
10190         local old_mdsisize=$MDSISIZE
10191
10192         MDSSIZE=$((17 * 1024 * 1024 * 1024)) # 17T MDT
10193         MDSISIZE=$((16 << 20))
10194         local opts17t="$(mkfs_opts $SINGLEMDS)"
10195
10196         MDSSIZE=$old_mdssize
10197         MDSISIZE=$old_mdsisize
10198
10199         do_facet $SINGLEMDS $MKFS \
10200                 ${opts17t/-E /-E lazy_itable_init,lazy_journal_init,} \
10201                 $tmpmnt/$mdtimg ||
10202                 error "failed to mkfs for $tmpmnt/$mdtimg"
10203
10204         do_facet $SINGLEMDS $TUNE2FS -l $tmpmnt/$mdtimg |
10205                 grep -qw 'features.*extent' || error "extent should be enabled"
10206         reformat_and_config
10207 }
10208 run_test 116 "big size MDT support"
10209
10210 test_117() {
10211         # Call setup only if LustreFS is not mounted
10212         check_mount || setup
10213
10214         do_facet ost1 "$LCTL set_param ost.OSS.ost_io.nrs_policies=fifo"
10215         do_facet ost1 "$LCTL get_param -n ost.OSS.ost_io.nrs_tbf_rule" &&
10216                 error "get_param should fail"
10217         cleanup || error "cleanup failed with rc $?"
10218 }
10219 run_test 117 "lctl get_param return errors properly"
10220
10221 test_119() {
10222         local had_config
10223         local size_mb
10224
10225         [[ "$MDSCOUNT" -ge 2 ]] || skip "Need more at least 2 MDTs"
10226
10227         had_config=$(do_facet mds1 "$LCTL get_param debug | grep config")
10228         do_facet mds1 "$LCTL set_param debug=+config"
10229         do_facet mds1 "$LCTL clear"
10230
10231         setup
10232         do_facet mds2 "$TUNEFS --writeconf $(mdsdevname 2)" &>/dev/null
10233         # mount after writeconf will make "add osp" added to mdt0 config:
10234         # 53 (224)marker  60 (flags=0x01, v2.5.1.0) lustre-MDT0001  'add osp'
10235         # 54 (080)add_uuid  nid=...  0:  1:...
10236         # 55 (144)attach    0:lustre-MDT0001-osp-MDT0000  1:osp  2:...
10237         # 56 (144)setup     0:lustre-MDT0001-osp-MDT0000  1:...  2:...
10238         # 57 (136)modify_mdc_tgts add 0:lustre-MDT0000-mdtlov  1:...  2:1  3:1
10239         # duplicate modify_mdc_tgts caused crashes
10240
10241         debug_size_save
10242         # using larger debug_mb size to avoid lctl dk log truncation
10243         size_mb=$((DEBUG_SIZE_SAVED * 4))
10244         for i in {1..3}; do
10245                 stop_mdt 2
10246                 # though config processing stops after failed attach and setup
10247                 # it will proceed after the failed command after each writeconf
10248                 # this is the original scenario of the issue
10249                 do_facet mds2 "$TUNEFS --writeconf $(mdsdevname 2)" &>/dev/null
10250                 do_facet mds1 "$LCTL set_param debug_mb=$size_mb"
10251                 start_mdt 2
10252
10253                 wait_update_facet_cond mds1 \
10254                         "$LCTL dk | grep -c Processed.log.$FSNAME-MDT0000" \
10255                         ">" 1 300
10256         done
10257         debug_size_restore
10258
10259         [[ -z "$had_config" ]] && do_facet mds1 lctl set_param debug=-config
10260
10261         reformat
10262 }
10263 run_test 119 "writeconf on slave mdt shouldn't duplicate mdc/osp and crash"
10264
10265 test_120() { # LU-11130
10266         [ "$MDSCOUNT" -lt 2 ] && skip "mdt count < 2"
10267         [ "$mds1_FSTYPE" != ldiskfs ] &&
10268                 skip "ldiskfs only test"
10269         [ "$MDS1_VERSION" -lt $(version_code 2.11.56) ] &&
10270                 skip "Need DNE2 capable MD target with LU-11130 fix"
10271
10272         setup
10273
10274         local mds1host=$(facet_active_host mds1)
10275         local mds1dev=$(mdsdevname 1)
10276
10277         $LFS mkdir -i 1 $DIR/$tdir
10278         $LFS mkdir -i 0 $DIR/$tdir/mds1dir
10279
10280         ln -s foo $DIR/$tdir/bar
10281         mv $DIR/$tdir/bar $DIR/$tdir/mds1dir/bar2 ||
10282                 error "cross-target rename failed"
10283
10284         stopall
10285
10286         run_e2fsck $mds1host $mds1dev "-n"
10287 }
10288 run_test 120 "cross-target rename should not create bad symlinks"
10289
10290 test_121(){
10291         stopall
10292         start_mgsmds || error "MGS MDS Start failed"
10293         fail mgs
10294         stop_mds || error "Stopping MDSes failed"
10295         #failback
10296         start_mds
10297         fail mgs
10298         stop_mds || error "Stopping MDSes failed"
10299 }
10300 run_test 121 "failover MGS"
10301
10302 test_122a() {
10303         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
10304         [[ "$OST1_VERSION" -ge $(version_code 2.11.53) ]] ||
10305                 skip "Need OST version at least 2.11.53"
10306
10307         reformat
10308         LOAD_MODULES_REMOTE=true load_modules
10309 #define OBD_FAIL_OFD_SET_OID 0x1e0
10310         do_facet ost1 $LCTL set_param fail_loc=0x00001e0
10311
10312         setup_noconfig
10313         $LFS mkdir -i1 -c1 $DIR/$tdir
10314         $LFS setstripe -i0 -c1 $DIR/$tdir
10315         do_facet ost1 $LCTL set_param fail_loc=0
10316         createmany -o $DIR/$tdir/file_ 1000 ||
10317                 error "Fail to create a new sequence"
10318
10319         cleanup
10320 }
10321 run_test 122a "Check OST sequence update"
10322
10323 test_123aa() {
10324         remote_mgs_nodsh && skip "remote MGS with nodsh"
10325         [ -d $MOUNT/.lustre ] || setup
10326
10327         # test old logid format until removal from llog_ioctl.c::str2logid()
10328         if (( $MGS_VERSION < $(version_code 2.99.53) )); then
10329                 do_facet mgs $LCTL dl | grep MGS
10330                 do_facet mgs "$LCTL --device %MGS llog_print \
10331                               \\\\\\\$$FSNAME-client 1 10" ||
10332                         error "old llog_print failed"
10333         fi
10334
10335         # test new logid format
10336         if [ $MGS_VERSION -ge $(version_code 2.9.53) ]; then
10337                 do_facet mgs "$LCTL --device MGS llog_print $FSNAME-client" ||
10338                         error "new llog_print failed"
10339         fi
10340 }
10341 run_test 123aa "llog_print works with FIDs and simple names"
10342
10343 test_123ab() {
10344         remote_mgs_nodsh && skip "remote MGS with nodsh"
10345         [[ $MGS_VERSION -gt $(version_code 2.11.51) ]] ||
10346                 skip "Need server with working llog_print support"
10347
10348         [ -d $MOUNT/.lustre ] || setup
10349
10350         local yaml
10351         local orig_val
10352         local mgs_arg=""
10353
10354         [[ $MGS_VERSION -gt $(version_code 2.13.54) ]] ||
10355                 mgs_arg="--device MGS"
10356
10357         orig_val=$(do_facet mgs $LCTL get_param jobid_name)
10358         do_facet mgs $LCTL set_param -P jobid_name="TESTNAME"
10359
10360         yaml=$(do_facet mgs $LCTL $mgs_arg llog_print params |
10361                grep jobid_name | tail -n 1)
10362
10363         local param=$(awk '{ print $10 }' <<< "$yaml")
10364         local val=$(awk '{ print $12 }' <<< "$yaml")
10365         #return to the default
10366         do_facet mgs $LCTL set_param -P jobid_name=$orig_val
10367         [ $val = "TESTNAME" ] || error "bad value: $val"
10368         [ $param = "jobid_name," ] || error "Bad param: $param"
10369 }
10370 run_test 123ab "llog_print params output values from set_param -P"
10371
10372 test_123ac() { # LU-11566
10373         remote_mgs_nodsh && skip "remote MGS with nodsh"
10374         do_facet mgs "$LCTL help llog_print" 2>&1 | grep -q -- --start ||
10375                 skip "Need 'lctl llog_print --start' on MGS"
10376
10377         local start=10
10378         local end=50
10379         local mgs_arg=""
10380
10381         [[ $MGS_VERSION -gt $(version_code 2.13.54) ]] ||
10382                 mgs_arg="--device MGS"
10383
10384         [ -d $MOUNT/.lustre ] || setup
10385
10386         # - { index: 10, event: add_uuid, nid: 192.168.20.1@tcp(0x20000c0a81401,
10387         #     node: 192.168.20.1@tcp }
10388         do_facet mgs $LCTL $mgs_arg \
10389                 llog_print --start $start --end $end $FSNAME-client | tr -d , |
10390                 while read DASH BRACE INDEX idx EVENT BLAH BLAH BLAH; do
10391                 (( idx >= start )) || error "llog_print index $idx < $start"
10392                 (( idx <= end )) || error "llog_print index $idx > $end"
10393         done
10394 }
10395 run_test 123ac "llog_print with --start and --end"
10396
10397 test_123ad() { # LU-11566
10398         remote_mgs_nodsh && skip "remote MGS with nodsh"
10399         if (( $MDS1_VERSION >= $(version_code 2.16.50) )); then
10400                 llog_info="llog info"
10401                 llog_print="llog print"
10402         else
10403                 llog_info="llog_info"
10404                 llog_print="llog_print"
10405         fi
10406         # older versions of lctl may not print all records properly
10407         (( MGS_VERSION >= $(version_code 2.15.90) )) ||
10408                 skip "Need MGS version at least 2.15.90"
10409
10410         [ -d $MOUNT/.lustre ] || setup
10411
10412         # append a new record, to avoid issues if last record was cancelled
10413         local old=$($LCTL get_param -n osc.*-OST0000-*.max_dirty_mb | head -1)
10414         do_facet mgs $LCTL conf_param $FSNAME-OST0000.osc.max_dirty_mb=$old
10415         stack_trap "do_facet mgs $LCTL conf_param -d $FSNAME-OST0000.osc.max_dirty_mb"
10416
10417         # logid:            [0x3:0xa:0x0]:0
10418         # flags:            4 (plain)
10419         # records_count:    72
10420         # last_index:       72
10421         local num=$(do_facet mgs $LCTL --device MGS $llog_info $FSNAME-client |
10422                     awk '/last_index:/ { print $2 }')
10423
10424         do_facet mgs $LCTL --device MGS $llog_print $FSNAME-client |
10425                 grep -q "$FSNAME-OST0000.*osc\.max_dirty_mb=$old" ||
10426                 error "ocs.max_dirty_mb=$old not found in $FSNAME-client"
10427
10428         # - { index: 72, event: marker, flags: 0x06, ... }
10429         local last=$(do_facet mgs $LCTL --device MGS $llog_print -r $FSNAME-client |
10430                      tail -1 | awk '{ print $4 }' | tr -d , )
10431         (( last == num )) || error "$llog_print only showed $last/$num records"
10432 }
10433 run_test 123ad "llog_print shows all records"
10434
10435 test_123ae() { # LU-11566
10436         local max
10437         local mgs_arg=""
10438         local log
10439         local id
10440         local orig
10441         local new
10442
10443         remote_mgs_nodsh && skip "remote MGS with nodsh"
10444         [ -d $MOUNT/.lustre ] || setupall
10445
10446         max=$($LCTL get_param -n osc.*-OST0000-*.max_dirty_mb | head -1)
10447         pgs=$($LCTL get_param -n osc.*-OST0000-*.max_pages_per_rpc | head -1)
10448         [[ $MGS_VERSION -gt $(version_code 2.13.54) ]] ||
10449                 mgs_arg="--device MGS"
10450
10451         if do_facet mgs "$LCTL help llog_cancel" 2>&1| grep -q -- --log_id; then
10452                 # save one set_param -P record in case none exist
10453
10454                 do_facet mgs $LCTL set_param -P osc.*.max_pages_per_rpc=$pgs
10455                 stack_trap "do_facet mgs $LCTL set_param -P -d \
10456                                 osc.*.max_pages_per_rpc"
10457
10458                 log=params
10459                 orig=$(do_facet mgs $LCTL $mgs_arg llog_print $log |
10460                         tail -1 | awk '{ print $4 }' | tr -d , )
10461                 do_facet mgs $LCTL set_param -P osc.*.max_dirty_mb=$max
10462                 do_facet mgs $LCTL $mgs_arg llog_print $log | tail -1 |
10463                         grep "parameter: osc.*.max_dirty_mb" ||
10464                         error "new set_param -P wasn't stored in params log"
10465
10466                 # - { index: 71, event: set_param, device: general,
10467                 #     param: osc.*.max_dirty_mb, value: 256 }
10468                 id=$(do_facet mgs $LCTL $mgs_arg llog_print $log |
10469                      tail -1 | awk '{ print $4 }' | tr -d , )
10470                 do_facet mgs $LCTL $mgs_arg llog_cancel $log --log_idx=$id
10471                 local new=$(do_facet mgs $LCTL $mgs_arg llog_print $log |
10472                             tail -1 | awk '{ print $4 }' | tr -d , )
10473                 (( new == orig )) ||
10474                         error "new llog_cancel now $new, not at $orig records"
10475         fi
10476
10477         # test old positional parameters for a while still
10478         if [ "$MGS_VERSION" -le $(version_code 3.1.53) ]; then
10479                 log=$FSNAME-client
10480
10481                 do_facet mgs $LCTL conf_param \
10482                         $FSNAME-OST0000.osc.max_pages_per_rpc=$pgs
10483                 stack_trap "do_facet mgs $LCTL conf_param -d \
10484                                 $FSNAME-OST0000.osc.max_pages_per_rpc"
10485
10486                 orig=$(do_facet mgs $LCTL --device MGS llog_print $log |
10487                        tail -1 | awk '{ print $4 }' | tr -d , )
10488                 do_facet mgs $LCTL conf_param $FSNAME-OST0000.osc.max_dirty_mb=$max
10489                 do_facet mgs $LCTL --device MGS llog_print $log |
10490                         tail -1 | grep "parameter: osc.max_dirty_mb" ||
10491                         error "old conf_param wasn't stored in params log"
10492                 do_facet mgs $LCTL --device MGS llog_print $log
10493                 # - { index: 71, event: conf_param, device: testfs-OST0000-osc,
10494                 #     param: osc.max_dirty_mb=256 }
10495                 id=$(do_facet mgs $LCTL --device MGS llog_print $log |
10496                      tail -1 | awk '{ print $4 }' | tr -d , )
10497                 do_facet mgs $LCTL --device MGS llog_cancel $log $id
10498                 do_facet mgs $LCTL --device MGS llog_print $log
10499                 new=$(do_facet mgs $LCTL --device MGS llog_print $log |
10500                       tail -1 | awk '{ print $4 }' | tr -d , )
10501                 (( new == orig )) ||
10502                         error "old llog_cancel now $new, not at $orig records"
10503         fi
10504 }
10505 run_test 123ae "llog_cancel can cancel requested record"
10506
10507 test_123af() { #LU-13609
10508         [ "$MGS_VERSION" -ge $(version_code 2.13.54) -a \
10509            "$MDS1_VERSION" -ge $(version_code 2.13.54) ] ||
10510                 skip "Need both MGS and MDS version at least 2.13.54"
10511
10512         [ -d $MOUNT/.lustre ] || setupall
10513         stack_trap "do_facet mds1 $LCTL set_param fail_loc=0" EXIT
10514
10515         local device
10516         local facet
10517         local cmd
10518         local orig_clist
10519         local orig_count
10520         local new_clist
10521         local new_count
10522
10523         for device in "MGS" "$FSNAME-MDT0000"; do
10524                 cmd="--device $device llog_catlist"
10525                 echo "lctl $cmd ..."
10526                 if [ "$device" = "MGS" ]; then
10527                         facet="mgs"
10528                 else
10529                         facet="mds1"
10530                 fi
10531                 orig_clist=($(do_facet $facet $LCTL $cmd | awk '{ print $2 }'))
10532                 orig_count=${#orig_clist[@]}
10533                 echo "orig_clist: ${orig_clist[*]}"
10534
10535                 #define OBD_FAIL_CATLIST 0x131b
10536                 #fetch to llog records from the second one
10537                 do_facet $facet $LCTL set_param fail_loc=0x131b fail_val=2
10538
10539                 new_clist=($(do_facet $facet $LCTL $cmd | awk '{ print $2 }'))
10540                 new_count=${#new_clist[@]}
10541                 echo "new_clist: ${new_clist[*]}"
10542
10543                 [ $new_count -eq $((orig_count - 1)) ] ||
10544                         error "$new_count != $orig_count - 1"
10545                 for i in $(seq 0 $new_count); do
10546                         j=$((i + 1))
10547                         [ "${orig_clist[$j]}" = "${new_clist[$i]}" ] ||
10548                                 error "${orig_clist[$j]} != ${new_clist[$i]}"
10549                 done
10550                 do_facet mds1 $LCTL set_param fail_loc=0
10551                 echo "done"
10552         done
10553 }
10554 run_test 123af "llog_catlist can show all config files correctly"
10555
10556 test_123ag() { # LU-15142
10557         local rec
10558         local orig_val
10559
10560         remote_mgs_nodsh && skip "remote MGS with nodsh"
10561         (( $MGS_VERSION >= $(version_code 2.14.55) )) ||
10562                 skip "Need server version least 2.14.55"
10563
10564         [ -d $MOUNT/.lustre ] || setup
10565
10566         orig_val=$(do_facet mgs $LCTL get_param jobid_name)
10567         stack_trap "do_facet mgs $LCTL set_param -P jobid_name=$orig_val"
10568
10569         do_facet mgs $LCTL set_param -P jobid_name="TESTNAME1"
10570         do_facet mgs $LCTL set_param -P -d jobid_name
10571         rec=$(do_facet mgs $LCTL --device MGS llog_print params |
10572                 grep -c jobid_name)
10573         (( rec == 0 )) || error "parameter was not deleted, check #1"
10574         do_facet mgs $LCTL set_param -P jobid_name="TESTNAME1"
10575         rec=$(do_facet mgs $LCTL --device MGS llog_print params |
10576                 grep -c jobid_name)
10577         (( rec == 1)) || error "parameter is not set"
10578         # usage with ordinary set_param format works too
10579         do_facet mgs $LCTL set_param -P -d jobid_name="TESTNAME1"
10580         rec=$(do_facet mgs $LCTL --device MGS llog_print params |
10581                 grep -c jobid_name)
10582         (( rec == 0 )) || error "parameter was not deleted, check #2"
10583 }
10584 run_test 123ag "llog_print skips values deleted by set_param -P -d"
10585
10586 test_123ah() { #LU-7668 del_ost
10587         (( "$MGS_VERSION" >= $(version_code 2.15.51) &&
10588            "$MDS1_VERSION" >= $(version_code 2.15.51) )) ||
10589                 skip "Need MGS/MDS version >= 2.15.51 for del_ost"
10590
10591         [ -d $MOUNT/.lustre ] || setupall
10592         stack_trap "do_facet mds1 $LCTL set_param fail_loc=0" EXIT
10593
10594         local cmd="--device MGS llog_print"
10595
10596         cli_llogcnt_orig=$(do_facet mgs $LCTL $cmd $FSNAME-client |
10597                                 grep -c $FSNAME-OST0000)
10598         mds1_llogcnt_orig=$(do_facet mgs $LCTL $cmd $FSNAME-MDT0000 |
10599                                 grep -c $FSNAME-OST0000)
10600
10601         [ $cli_llogcnt_orig -gt 0 ] ||
10602                 error "$FSNAME-OST0000 not found (client)"
10603         [ $mds1_llogcnt_orig -gt 0 ] || error "$FSNAME-OST0000 not found (MDT)"
10604
10605         # -n/--dryrun should NOT modify catalog
10606         do_facet mgs "$LCTL del_ost -n -t $FSNAME-OST0000" ||
10607                 error "del_ost --dryrun failed with $?"
10608
10609         local cli_llogcnt=$(do_facet mgs $LCTL $cmd $FSNAME-client |
10610                         grep -c $FSNAME-OST0000)
10611         local mds1_llogcnt=$(do_facet mgs $LCTL $cmd $FSNAME-MDT0000 |
10612                         grep -c $FSNAME-OST0000)
10613
10614         [ $cli_llogcnt -eq $cli_llogcnt_orig ] ||
10615                 error "--dryrun error: $cli_llogcnt != $cli_llogcnt_orig"
10616         [ $mds1_llogcnt -eq $mds1_llogcnt_orig ] ||
10617                 error "--dryrun error: $mds1_llogcnt != $mds1_llogcnt_orig"
10618
10619         # actual run
10620         do_facet mgs "$LCTL del_ost --target $FSNAME-OST0000" ||
10621                 error "del_ost failed with $?"
10622
10623         local cli_llogcnt=$(do_facet mgs $LCTL $cmd $FSNAME-client |
10624                         grep -c $FSNAME-OST0000)
10625         local mds1_llogcnt=$(do_facet mgs $LCTL $cmd $FSNAME-MDT0000 |
10626                         grep -c $FSNAME-OST0000)
10627
10628         # every catalog entry for OST0000 should have been cancelled
10629         [ $cli_llogcnt -eq 0 ] || error "$FSNAME-OST0000 not cancelled (cli)"
10630         [ $mds1_llogcnt -eq 0 ] || error "$FSNAME-OST0000 not cancelled (MDT)"
10631
10632         umount_client $MOUNT
10633         mount_client $MOUNT
10634
10635         $LFS df | grep -q OST0000 && error "del_ost did not remove OST0000!"
10636         cleanup
10637         reformat_and_config
10638 }
10639 run_test 123ah "del_ost cancels config log entries correctly"
10640
10641 cleanup_123ai() {
10642         local timeout=$1
10643
10644         echo "cleanup test 123ai"
10645
10646         # cancel last timeout record
10647         do_facet mgs "$LCTL set_param -P -d timeout"
10648
10649         # restore timeout value
10650         do_nodes $(comma_list $(all_nodes)) "$LCTL set_param timeout=$timeout"
10651 }
10652
10653 test_123ai() { #LU-16167
10654         local i
10655         local count
10656         local old_count
10657         local old_timeout
10658
10659         remote_mgs_nodsh && skip "remote MGS with nodsh"
10660         (( MDS1_VERSION >= $(version_code 2.15.51) )) ||
10661                 skip "Need MDS version at least 2.15.51"
10662
10663         [ -d $MOUNT/.lustre ] || setup
10664
10665         old_count=$(do_facet mgs "$LCTL --device MGS llog_print -r params" |
10666                 grep -c "parameter: timeout")
10667
10668         old_timeout=$($LCTL get_param -n timeout)
10669         stack_trap "cleanup_123ai $old_timeout" EXIT
10670
10671         # add and cancel params (2 * MAX_IOC_BUFLEN / 128 + 1 = 129)
10672         for i in {1..129}; do
10673                 do_facet mgs "$LCTL set_param -P timeout=$i" ||
10674                         error "fail to set timeout=$i on MGS"
10675         done
10676
10677         count=$(do_facet mgs "$LCTL --device MGS llog_print -r params" |
10678                 grep -c "parameter: timeout")
10679
10680         ((count - old_count == 129)) ||
10681                 error "number timeout record missmatch ($count - $old_count != 129)"
10682
10683         do_facet mgs "$LCTL --device MGS llog_print params" |
10684                 tail -1 | grep  "timeout, value: 129" ||
10685                 error "llog_print could not display the last record (timeout=129)"
10686
10687 }
10688 run_test 123ai "llog_print display all non skipped records"
10689
10690 cleanup_123aj() {
10691         local svc=$1
10692
10693         echo "cleanup test 123aj"
10694
10695         # cancel last TBF parameter records
10696         do_facet mgs "$LCTL set_param -P -d  ${svc}.nrs_tbf_rule" || true
10697         do_facet mgs "$LCTL set_param -P -d  ${svc}.nrs_policies" || true
10698
10699         # restore old NRS policy
10700         do_nodes $(comma_list $(osts_nodes)) \
10701                 "$LCTL set_param ${svc}.nrs_policies=fifo"
10702 }
10703
10704 check_compound_param_val() {
10705         local value llog_print
10706         local svc=$1
10707         shift
10708
10709         llog_print=$(do_facet mgs "$LCTL llog_print params") ||
10710                 error "fail to read CONFIG/params"
10711
10712         for value in "$@"; do
10713                 local n=$(grep -c "${svc}.*$value }$" <<< "$llog_print")
10714
10715                 (( n > 0 )) || error "fail to found '$value' in params config"
10716                 (( n == 1 )) || error "several records found ($n) for '$value'"
10717         done
10718 }
10719
10720 add_random_spaces()
10721 {
10722         local word str
10723         local spaces=$(printf '%*s' $(($RANDOM % 4)) '')
10724
10725         str=$spaces
10726         for word in $*; do
10727                 spaces=$(printf '%*s' $(($RANDOM % 4)) '')
10728                 str+="$word $spaces"
10729         done
10730
10731         echo "${str:0:-1}"
10732 }
10733
10734 test_123aj() { #LU-17920
10735         local old_policy
10736         local key rule
10737         local llog_print
10738         local -A tbf_rules
10739         local ost_io="ost.OSS.ost_io"
10740
10741         tbf_rules[rule1]="start rule1 uid={500 502 } rate=1000"
10742         tbf_rules[rule2]="start rule2 nid={10.10.2.20@tcp} rate=1000"
10743         tbf_rules[rule3]="start rule3 jobid={cat.0.0} rate=1000"
10744         tbf_rules[rule4]="start rule4 jobid={fio.0.0} rate=500"
10745         tbf_rules[change4_1]="change rule4 rate=50"
10746         tbf_rules[change4_2]="change rule4 rate=5000"
10747
10748         remote_mgs_nodsh && skip "remote MGS with nodsh"
10749         (( MGS_VERSION >= $(version_code v2_16_54-23) )) ||
10750                 skip "need MGS >= v2_16_54-23 for compound llog records"
10751
10752         [ -d $MOUNT/.lustre ] || setup
10753
10754         stack_trap "cleanup_123aj $ost_io"
10755
10756         do_facet mgs "$LCTL set_param -P ${ost_io}.nrs_policies=tbf" ||
10757                 error "fail to set nrs_policies=tbf on MGS"
10758
10759         for rule in "${tbf_rules[@]}"; do
10760                 do_facet mgs "$LCTL set_param -P ${ost_io}.nrs_tbf_rule='$rule'" ||
10761                         error "fail to set nrs_tbf_rule='$rule' on MGS"
10762
10763                 # the rec should be added only the first time
10764                 rule="$(add_random_spaces "$rule")"
10765                 do_facet mgs "$LCTL set_param -P ${ost_io}.nrs_tbf_rule='$rule'" ||
10766                         error "fail to set nrs_tbf_rule='$rule' on MGS"
10767         done
10768         check_compound_param_val $ost_io "${tbf_rules[@]}"
10769
10770         # remove all the rules
10771         do_facet mgs "$LCTL set_param -P -d ${ost_io}.nrs_tbf_rule" ||
10772                 error "fail to remove all the TBF rules"
10773
10774         llog_print=$(do_facet mgs "$LCTL llog_print params") ||
10775                 error "fail to read CONFIG/params"
10776         ! grep -q nrs_tbf_rule <<< "$llog_print" ||
10777                 error "fail to remove all the TBF rules"
10778
10779         # re-add the rules
10780         for rule in "${tbf_rules[@]}"; do
10781                 do_facet mgs "$LCTL set_param -P ${ost_io}.nrs_tbf_rule='$rule'" ||
10782                         error "fail to set nrs_tbf_rule='$rule' on MGS"
10783         done
10784         check_compound_param_val $ost_io "${tbf_rules[@]}"
10785
10786         # shuffle and remove the rule one by one
10787         printf "%s\n" "${!tbf_rules[@]}" | sort -R |
10788                 while read key; do
10789                         rule="${tbf_rules[$key]}"
10790                         unset tbf_rules[$key]
10791                         do_facet mgs "$LCTL set_param -P -d ${ost_io}.nrs_tbf_rule='$rule'" ||
10792                                 error "fail to set nrs_tbf_rule='$rule' on MGS"
10793                         check_compound_param_val $ost_io "${tbf_rules[@]}"
10794                 done
10795 }
10796 run_test 123aj "check permanent TBF rules"
10797
10798 test_123_prep() {
10799         remote_mgs_nodsh && skip "remote MGS with nodsh"
10800
10801         [ -d $MOUNT/.lustre ] || setup
10802         yaml_file="$TMP/$tfile.yaml"
10803
10804         do_facet mgs rm "$yaml_file"
10805         cfgfiles=$(do_facet mgs "lctl --device MGS llog_catlist" |
10806                          sed 's/config_log://')
10807
10808         # set jobid_var to a different value for test
10809         orig_val=$(do_facet mgs $LCTL get_param jobid_var)
10810
10811         do_facet mgs $LCTL set_param -P jobid_var="TESTNAME"
10812
10813         for i in $cfgfiles params; do
10814                 do_facet mgs "lctl --device MGS llog_print ${i} >> $yaml_file"
10815         done
10816
10817         echo "Unmounting FS"
10818         stopall
10819         echo "Writeconf"
10820         writeconf_all
10821         echo "Remounting"
10822         setup_noconfig
10823 }
10824
10825 test_123_restore() {
10826         set_val=$(do_facet mgs $LCTL get_param jobid_var)
10827
10828         do_facet mgs $LCTL set_param -P $orig_val
10829
10830         [ $set_val == "jobid_var=TESTNAME" ] ||
10831                 error "$set_val is not TESTNAME"
10832
10833         do_facet mgs rm "$yaml_file"
10834         cleanup
10835 }
10836
10837 test_123F() {
10838         local yaml_file
10839         local cfgfiles
10840         local orig_val
10841         local set_val
10842
10843         test_123_prep
10844
10845         # Reapply the config from before
10846         echo "Setting configuration parameters"
10847         do_facet mgs "$LCTL set_param -F $yaml_file" ||
10848                 error "'set_param -F $yaml_file' failed"
10849
10850         test_123_restore
10851 }
10852 run_test 123F "clear and reset all parameters using set_param -F"
10853
10854 test_123G() {
10855         local yaml_file
10856         local cfgfiles
10857         local orig_val
10858         local set_val
10859
10860         test_123_prep
10861
10862         # Reapply the config from before
10863         echo "Setting configuration parameters"
10864         do_facet mgs "$LCTL apply_yaml $yaml_file" ||
10865                 error "'apply_yaml $yaml_file' failed"
10866
10867         test_123_restore
10868 }
10869 run_test 123G "clear and reset all parameters using apply_yaml"
10870
10871 test_123H() { #LU-18170
10872         local old
10873         local i
10874
10875         (( MGS_VERSION >= $(version_code 2.16.51) )) ||
10876                 skip "Need MGS version at least 2.16.51"
10877
10878         [ -d $MOUNT/.lustre ] || setup
10879
10880         old=$(do_facet mgs $LCTL get_param jobid_var)
10881         stack_trap "do_facet mgs $LCTL set_param -d jobid_var"
10882         stack_trap "do_facet mgs $LCTL set_param -P jobid_var=$old"
10883
10884         # fill the "params" llog file
10885         for i in {1..50}; do
10886                 do_facet mgs $LCTL set_param -P jobid_var=TEST_123H
10887                 do_facet mgs $LCTL set_param -P jobid_var=$old
10888         done
10889
10890         local llog_str
10891         local num
10892         llog_str=$(do_facet mgs $LCTL llog_print -r params) ||
10893                 error "'lctl llog_print -r params' failed"
10894         num=$(wc -l <<< "$llog_str")
10895
10896         # llog_print parallel executions
10897         do_facet mgs "seq 1 20 | "\
10898                 "xargs -P20 -I{} bash -c '$LCTL llog_print -r params | wc -l' | "\
10899                 "sort | uniq -c" |
10900                 awk '$2 == "'$num'" { print $0; if ($1 != 20) exit 1; }' ||
10901                 error "'corrupted output for 'lctl llog_print -r params'"
10902 }
10903 run_test 123H "check concurent accesses with 'lctl llog_print"
10904
10905 test_124()
10906 {
10907         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
10908         [ -z $mds2failover_HOST ] && skip "needs MDT failover setup"
10909
10910         setup
10911         do_facet mgs $LCTL --device MGS llog_print $FSNAME-client |
10912                 grep 1.2.3.4@tcp && error "Should not be fake nid"
10913         do_facet mgs $LCTL conf_param $FSNAME-MDT0001.failover.node=1.2.3.4@tcp\
10914                 || error "Set params error"
10915         do_facet mgs $LCTL --device MGS llog_print $FSNAME-client |
10916                 grep 1.2.3.4@tcp || error "Fake nid should be added"
10917         cleanup
10918
10919         load_modules
10920         if combined_mgs_mds; then
10921                 start_mdt 1 "-o nosvc" ||
10922                         error "starting mds with nosvc option failed"
10923         fi
10924         local nid=$(do_facet mds2 $LCTL list_nids | head -1)
10925         local failover_nid=$(do_node $mds2failover_HOST $LCTL list_nids | head -1)
10926
10927         do_facet mgs $LCTL replace_nids $FSNAME-MDT0001 $nid:$failover_nid ||
10928                 error "replace_nids execution error"
10929
10930         if combined_mgs_mds; then
10931                 stop_mdt 1
10932         fi
10933
10934         setup
10935         fail mds2
10936         echo "lfs setdirstripe"
10937         $LFS setdirstripe -i 1 $MOUNT/$tdir || error "setdirstirpe error"
10938         echo ok
10939 }
10940 run_test 124 "check failover after replace_nids"
10941
10942 get_max_sectors_kb() {
10943         local facet="$1"
10944         local device="$2"
10945         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
10946         local max_sectors_path="/sys/block/${dev_base}/queue/max_sectors_kb"
10947
10948         do_facet ${facet} "[[ -e ${max_sectors_path} ]] &&
10949                            cat ${max_sectors_path}"
10950 }
10951
10952 get_max_hw_sectors_kb() {
10953         local facet="$1"
10954         local device="$2"
10955         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
10956         local max_hw_path="/sys/block/${dev_base}/queue/max_hw_sectors_kb"
10957
10958         do_facet ${facet} "[[ -e ${max_hw_path} ]] && cat ${max_hw_path}"
10959 }
10960
10961 set_max_sectors_kb() {
10962         local facet="$1"
10963         local device="$2"
10964         local value="$3"
10965         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
10966         local max_sectors_path="/sys/block/${dev_base}/queue/max_sectors_kb"
10967
10968         do_facet ${facet} "[[ -e ${max_sectors_path} ]] &&
10969                            echo ${value} > ${max_sectors_path}"
10970         rc=$?
10971
10972         [[ $rc -ne 0 ]] && echo "Failed to set ${max_sectors_path} to ${value}"
10973
10974         return $rc
10975 }
10976
10977 # Return 0 if all slave devices have max_sectors_kb == max_hw_sectors_kb
10978 # Otherwise return > 0
10979 check_slaves_max_sectors_kb()
10980 {
10981         local facet="$1"
10982         local device="$2"
10983         local dev_base=$(basename $(do_facet ${facet} "readlink -f ${device}"))
10984         local slaves_dir=/sys/block/${dev_base}/slaves
10985         local slave_devices=$(do_facet ${facet} "ls ${slaves_dir} 2>/dev/null")
10986         [[ -z ${slave_devices} ]] && return 0
10987
10988         local slave max_sectors new_max_sectors max_hw_sectors path
10989         local rc=0
10990
10991         for slave in ${slave_devices}; do
10992                 path="/dev/${slave}"
10993                 ! is_blkdev ${facet} ${path} && continue
10994                 max_sectors=$(get_max_sectors_kb ${facet} ${path})
10995                 max_hw_sectors=$(get_max_hw_sectors_kb ${facet} ${path})
10996                 new_max_sectors=${max_hw_sectors}
10997                 [[ ${new_max_sectors} -gt ${RQ_SIZE_LIMIT} ]] &&
10998                         new_max_sectors=${RQ_SIZE_LIMIT}
10999
11000                 if [[ ${max_sectors} -ne ${new_max_sectors} ]]; then
11001                         echo "${path} ${max_sectors} ${new_max_sectors}"
11002                         ((rc++))
11003                 fi
11004                 check_slaves_max_sectors_kb ${facet} ${path}
11005                 ((rc + $?))
11006         done
11007
11008         return $rc
11009 }
11010
11011 test_126() {
11012         [[ "$MDS1_VERSION" -ge $(version_code 2.13.52) ]] ||
11013                 skip "Need MDS version at least 2.13.52"
11014
11015         cleanup
11016         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_module ../libcfs/libcfs/libcfs
11017         #define OBD_FAIL_OBD_SETUP 0x60d
11018         do_facet mds1 $LCTL set_param fail_loc=0x60d
11019         do_rpc_nodes $(facet_active_host $SINGLEMDS) load_modules &
11020         for i in {1..40}; do
11021                 do_facet mds1 lsmod | grep -q osd_$mds1_FSTYPE && break
11022                 sleep 1
11023         done
11024         clear_failloc $SINGLEMDS 20 &
11025         start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS
11026 }
11027 run_test 126 "mount in parallel shouldn't cause a crash"
11028
11029 test_127() {
11030         [[ "$ost1_FSTYPE" == ldiskfs ]] || skip "ldiskfs only test"
11031
11032         cleanup
11033         setup
11034         zconf_umount_clients $RCLIENTS $MOUNT
11035
11036         wait_osp_active ost ${FSNAME}-OST0000 0 1
11037         local osc_tgt="$FSNAME-OST0000-osc-$($LFS getname -i $DIR)"
11038         local avail1=($($LCTL get_param -n osc.${osc_tgt}.kbytesavail))
11039
11040         wait_delete_completed
11041         $LFS setstripe -i 0 -c1 $DIR/$tfile || {
11042                 $LFS df $DIR
11043                 $LCTL get_param osc.*.*grant_bytes
11044                 error "failed creating $DIR/$tfile"
11045         }
11046         dd if=/dev/zero of=$DIR/$tfile bs=1M oflag=direct || true
11047
11048         sleep_maxage
11049         local avail2=($($LCTL get_param -n osc.${osc_tgt}.kbytesavail))
11050
11051         if ((avail2 * 100 / avail1 > 1)); then
11052                 lfs df $DIR
11053                 ls -l $DIR/$tfile
11054                 error "more than 1% space left: before=$avail1 after=$avail2"
11055         fi
11056
11057         local mbs=$(($(stat -c %s $DIR/$tfile) / (1024 * 1024)))
11058
11059         dd if=/dev/zero of=$DIR/$tfile bs=1M count=$mbs conv=notrunc \
11060                 oflag=direct || error "overwrite failed"
11061 }
11062 run_test 127 "direct io overwrite on full ost"
11063
11064 test_128()
11065 {
11066         combined_mgs_mds && skip "need separate mgs device"
11067         [ "$ost2_FSTYPE" == zfs ] && import_zpool ost2
11068
11069         format_ost 2
11070         # Try to apply nolocallogs to the virgin OST. Should fail.
11071         do_facet ost2 "$TUNEFS --nolocallogs $(ostdevname 2)" &&
11072                 error "nolocallogs should not be allowed on the virgin target"
11073
11074         setupall
11075         stopall
11076
11077         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
11078         # Start OST without MGS (local configs)
11079         do_facet ost1 "$TUNEFS --dryrun $(ostdevname 1)"
11080         start_ost || error "unable to start OST1"
11081         stop_ost || error "Unable to stop OST1"
11082
11083         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
11084         # Do not allow reading local configs, should fail
11085         do_facet ost1 "$TUNEFS --nolocallogs $(ostdevname 1)" ||
11086                 error "Can not set nolocallogs"
11087         start_ost && error "OST1 started, but should fail"
11088
11089         # Connect to MGS successfully, reset nolocallogs flag
11090         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
11091         start_mgs || error "unable to start MGS"
11092         start_ost || error "unable to start OST1"
11093
11094         do_facet ost1 "$TUNEFS --dryrun $(ostdevname 1)" | grep "nolocallogs" &&
11095                 error "nolocallogs expected to be reset"
11096
11097         stop_ost || error "Unable to stop OST1"
11098 }
11099 run_test 128 "Force using remote logs with --nolocallogs"
11100
11101 test_129()
11102 {
11103         (( MDS1_VERSION >= $(version_code 2.14.57) )) ||
11104                 skip "Need MDS version at least 2.14.57"
11105         stopall
11106         start_mgsmds || error "MGS/MDS start failed"
11107         format_ost 1
11108         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &&
11109                 error "start ost1 should fail" || true
11110         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS &&
11111                 error "second start ost1 should fail" || true
11112         do_facet ost1 "$TUNEFS --writeconf $(ostdevname 1)"
11113         start ost1 $(ostdevname 1) $OST_MOUNT_OPTS ||
11114                 error "start ost1 failed"
11115         stop ost1
11116         stop_mds
11117 }
11118 run_test 129 "attempt to connect an OST with the same index should fail"
11119
11120 test_130()
11121 {
11122         [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs"
11123         setupall
11124         stop_mdt 2 || error "mdt2 stop failed"
11125         do_facet mds2 "$TUNEFS --writeconf $(mdsdevname 2)"
11126         start_mdt 2 || error "mdt2 start failed"
11127         do_facet mds2 "$LCTL dl" | grep MDT0001-osp-MDT0001 &&
11128                 error "Illegal OSP device created" || true
11129 }
11130 run_test 130 "re-register an MDT after writeconf"
11131
11132 test_131() {
11133         [ "$mds1_FSTYPE" == "ldiskfs" ] || skip "ldiskfs only test"
11134         (( $MDS1_VERSION >= $(version_code 2.14.56.35) )) ||
11135                 skip "Need MDS version at least 2.14.56.35"
11136         do_facet mds1 $DEBUGFS -R features $(mdsdevname 1) |
11137                 grep -q project || skip "skip project quota not supported"
11138
11139         local projid
11140
11141         setupall
11142         test_mkdir -c $MDSCOUNT -p $DIR/$tdir
11143         $LFS project -p 1000 $DIR/$tdir || error "set dir project id failed"
11144         createmany -o $DIR/$tdir/f 512
11145         for ((i = 0; i < 512; ++i)); do
11146                 $LFS project -p $i $DIR/$tdir/f${i} ||
11147                         error "set f${i} project id failed"
11148         done
11149
11150         test_mkdir -c $MDSCOUNT -p $DIR/$tdir.inherit
11151         $LFS project -p 1001 -s $DIR/$tdir.inherit
11152         createmany -o $DIR/$tdir.inherit/f 128
11153         (( $($LFS project $DIR/$tdir.inherit/f* |
11154                 awk '$1 == 1001 { print }' | wc -l) == 128 )) ||
11155                         error "files did not inherit projid 1001"
11156
11157         stopall
11158
11159         for i in $(seq $MDSCOUNT); do
11160                 mds_backup_restore mds$i ||
11161                         error "Backup/restore on mds$i failed"
11162         done
11163
11164         setupall
11165
11166         projid=($($LFS project -d $DIR/$tdir))
11167         [ ${projid[0]} == "1000" ] ||
11168                 error "projid expected 1000 not ${projid[0]}"
11169         for ((i = 0; i < 512; ++i)); do
11170                 projid=($($LFS project $DIR/$tdir/f${i}))
11171                 [ ${projid[0]} == "$i" ] ||
11172                         error "projid expected $i not ${projid[0]}"
11173         done
11174
11175         (( $($LFS project $DIR/$tdir.inherit/f* |
11176                 awk '$1 == 1001 { print }' | wc -l) == 128 )) ||
11177                         error "restore did not copy projid 1001"
11178 }
11179 run_test 131 "MDT backup restore with project ID"
11180
11181 test_132() {
11182         local err_cnt
11183         local err_cnt2
11184
11185         (( MDS1_VERSION >= $(version_code 2.14.57) )) ||
11186                 skip "Need MDS version at least 2.14.57"
11187         reformat
11188         combined_mgs_mds || start_mgs || error "unable to start MGS"
11189         start_mdt 1 || error "unable to start mdt1"
11190
11191         err_cnt=$(do_facet mds1 dmesg | grep -c "cannot take the layout locks")
11192         stop_mdt 1 || error "stop mdt1 failed"
11193
11194         [ "$mds1_FSTYPE" == zfs ] && import_zpool mds1
11195         do_facet mds1 $TUNEFS --param mdt.hsm_control=enabled $(mdsdevname 1) ||
11196                 error "tunefs failed"
11197         start_mdt 1 || error "cannot start mdt1"
11198
11199         err_cnt2=$(do_facet mds1 dmesg | grep -c "cannot take the layout locks")
11200         [ $err_cnt -eq $err_cnt2 ] || error "Can not take the layout lock"
11201         stop_mdt 1 || error "stop mdt1 failed"
11202 }
11203 run_test 132 "hsm_actions processed after failover"
11204
11205 # This test verifies we do RR allocation within a pool even if there is a
11206 # significant imbalance vs an OST outside the pool
11207 test_133() {
11208         [[ $OSTCOUNT -lt 4 ]] && skip_env "needs >= 4 OSTs"
11209         [[ "$OST1_VERSION" -ge $(version_code 2.15.51) ]] ||
11210                 skip "Need OST version at least 2.15.51"
11211         # This is the easiest way to ensure OSTs start out balanced
11212         reformat_and_config
11213         setupall
11214
11215         check_set_fallocate_or_skip
11216
11217         local testfile=$DIR/$tdir/$tfile
11218         local pool="testpool"
11219         local ostrange=$((OSTCOUNT - 1))
11220         # Select all but the last OST to add to the pool
11221         local poolostrange=$((OSTCOUNT - 2))
11222         local filenum=20
11223         local filecount
11224         local stripecount
11225
11226         declare -a AVAIL
11227         free_min_max
11228
11229         [ $MINV -eq 0 ] && error "no free space in OST$MINI"
11230         [ $MAXV -gt $((2 * $MINV)) ] &&
11231                 error "OSTs badly unbalanced after reformat"
11232
11233         create_pool $FSNAME.$pool || error "failed to create a pool"
11234         do_facet mgs $LCTL pool_add $FSNAME.$pool OST[0-$poolostrange] ||
11235                 error "failed to add OST[0-$poolostrange] to the pool"
11236
11237         test_mkdir -p $DIR/$tdir || error "failed to mkdir $DIR/$tdir"
11238         # Consume space on the OSTs in the pool so they are unbalanced with the
11239         # OST outside of the pool
11240         # fill each OST 90% with fallocate so they are widely
11241         # imbalanced
11242         local size=$(((MINV * 9 / 10) * 1024))
11243         for ((i = 0; i <= poolostrange; i++)); do
11244                 $LFS setstripe -c 1 -i $i $testfile$i ||
11245                         error "failed to setstripe $testfile$i"
11246                 fallocate -l $size $testfile$i || error "fallocate failed"
11247         done
11248         ls -la $DIR/$tdir
11249         sleep_maxage
11250         $LFS df
11251
11252         # Create files in the pool now that there is an imbalance
11253         filecount=$(((OSTCOUNT - 1) * filenum))
11254         for ((i = 0; i < filecount; i++)); do
11255                 $LFS setstripe -p $pool $testfile-$i ||
11256                         error "failed to setstripe -p $pool $testfile-$i"
11257         done
11258         $LFS getstripe -i $testfile-* > /tmp/$tfile.log
11259         # Count the number of files with a stripe on each OST to verify the
11260         # pool allocated with round-robin
11261         for ((i = 0; i <= poolostrange; i++)); do
11262                 stripecount=$(grep -c $i /tmp/$tfile.log)
11263                 # Allow a little leeway
11264                 if (( stripecount < filenum - 1 ||
11265                       stripecount > filenum + 1 )); then
11266                         cat /tmp/$tfile.log
11267                         error "$stripecount != $filenum files on OST$i"
11268                 fi
11269         done
11270
11271         # Create files across the system now that there is an imbalance
11272         filecount=$((OSTCOUNT * filenum))
11273         for ((i = 1; i < filecount; i++)); do
11274                 $LFS setstripe $testfile-$i.2 ||
11275                         error "failed to setstripe $testfile-$i.2"
11276         done
11277         $LFS getstripe -i $testfile-*.2 > /tmp/$tfile.log
11278         local qos_used=""
11279         # Count the number of files with a stripe on each OST to verify the
11280         # files are *NOT* allocated with round-robin
11281         for ((i = 0; i <= ostrange; i++)); do
11282                 stripecount=$(grep -c $i /tmp/$tfile.log)
11283                 if [[ $stripecount -ne $filenum ]]; then
11284                         qos_used="true"
11285                         echo "QOS: $stripecount != $filenum files on OST$i"
11286                 fi
11287         done
11288         if [ -z "$qos_used" ]; then
11289                 error "QOS not used on imbalanced OSTs!"
11290         fi
11291
11292         rm -rf /tmp/$tfile.log $DIR/$tdir
11293         do_facet mgs $LCTL pool_remove $FSNAME.$pool OST[0-$poolostrange] ||
11294                 "failed to remove OST[0-$poolostrange] from the pool"
11295         do_facet mgs $LCTL pool_destroy $FSNAME.$pool ||
11296                 error "failed to destroy pool"
11297 }
11298 run_test 133 "stripe QOS: free space balance in a pool"
11299
11300 test_134() {
11301         [ "$mds1_FSTYPE" == "ldiskfs" ] || skip "ldiskfs only test"
11302         local errors
11303         local rc rc_corrupted
11304         local mdt_dev=$(facet_device mds1)
11305         local tmp_dir=$TMP/$tdir
11306         local dir=$DIR/$tdir
11307         local out=$tmp_dir/check_iam.txt
11308         local CHECK_IAM=${CHECK_IAM:-$(do_facet mds1 "which check_iam 2> /dev/null || true")}
11309         local iam_files=$(printf "oi.16.%d " {0..63})
11310
11311         [[ -n "$CHECK_IAM" ]] || skip "check_iam not found"
11312
11313         setupall
11314
11315         # Fill the iam files
11316         test_mkdir -p $dir || error "failed to mkdir $DIR/$tdir"
11317         stack_trap "rm -rf $dir"
11318
11319         touch $dir/$tfile.{0..1000} || error "failed to touch files"
11320         stack_trap "find $dir -type f | xargs -P10 -n1 unlink"
11321
11322         local f
11323         for f in $dir/$tfile.{0..10}; do
11324                 printf "%s\n" $f.ln.{0..500} | xargs -P10 -n1 ln $f ||
11325                         error "failed to create 500 hard links of $f"
11326         done
11327
11328         local nm_name=${TESTNAME:0:15}
11329
11330         do_facet mgs "$LCTL nodemap_add $nm_name"
11331         stack_trap "do_facet mgs $LCTL nodemap_del $nm_name"
11332         do_facet mgs "$LCTL nodemap_add_range --name $nm_name --range '121.23.2.[100-120]@tcp'"
11333
11334         do_facet mds1 "$LCTL lfsck_start -A && $LCTL lfsck_query -w > /dev/null"
11335
11336         if (( MDS1_VERSION >= $(version_code 2.16.0) )); then
11337                 # LU-18401
11338                 iam_files+=$(printf "LFSCK/lfsck_layout_%02u " {0..15})
11339                 iam_files+=$(printf "LFSCK/lfsck_namespace_%02u " {0..15})
11340                 iam_files+="CONFIGS/nodemap "
11341         fi
11342
11343         mkdir -p $tmp_dir
11344         for f in $iam_files; do
11345                 #cmd introduce a random corruption to IAM file
11346                 local tmp_file=$tmp_dir/$(basename $f)
11347                 local cmd="dd if=/dev/urandom of=$tmp_file bs=2 conv=notrunc count=1 seek=$((RANDOM % 36))"
11348
11349                 local facet
11350                 [[ "$f" =~ nodemap ]] && facet=mgs || facet=mds1
11351                 do_facet $facet "mkdir -p $tmp_dir; \
11352                    $DEBUGFS -c -R 'dump $f $tmp_file' $mdt_dev 2>&1; \
11353                    $CHECK_IAM -rv $tmp_file 2>&1; \
11354                    echo $cmd; eval $cmd 2>/dev/null;
11355                    $CHECK_IAM -v $tmp_file 2>&1; \
11356                    rc=\\\$?; echo \\\$rc; exit \\\$rc;" >> $out 2>&1 ||
11357                    (( rc_corrupted += ($? == 255) )) || true
11358         done
11359
11360         tail -n100 $out
11361
11362         stack_trap "rm -rf $tmp_dir && do_facet mds1 rm -rf $tmp_dir" EXIT
11363
11364         rc=$(grep -c "\<fault\>\|\<except" $out)
11365         (( rc == 0 )) || { cat $out &&
11366                 error "check_iam failed with fault or exception $rc"; }
11367
11368         errors=$(grep -c "FINISHED WITH ERRORS" $out)
11369
11370         (( rc_corrupted == errors )) || { cat $out &&
11371                 error "check_iam errcode does not fit with errors $rc $errors"; }
11372 }
11373 run_test 134 "check_iam works without faults"
11374
11375 cleanup_test_135(){
11376         local oldgc=$1
11377
11378         printf "\nCleanup test_135\n" >&2
11379         do_facet mds1 "$LCTL set_param -n $oldgc"
11380         rm -rf $DIR/$tdir &> /dev/null
11381         cleanup
11382 }
11383
11384 __test_135_file_thread() {
11385         local service="$1"
11386         local init_time=$(awk '{print $1}' /proc/uptime)
11387         local awkcmd="/crosses index zero/ {if (\$1 > $init_time) exit(1);}"
11388
11389         #Generate a full plain llogs
11390         while dmesg | sed -r 's/(\[|\])//g' | awk "$awkcmd" ; do
11391                 createmany -o $DIR/$tdir/f 4500 >&2
11392                 createmany -u $DIR/$tdir/f 4500 >&2
11393         done
11394 }
11395
11396 __test_135_reader() {
11397         local fd=$1
11398         local cl_user=$2
11399         local firstidx=$(changelog_user_rec mds1 $cl_user)
11400         local oldidx=$firstidx
11401         local newidx=0
11402         local pid=0
11403         local other
11404
11405         while read -t10 -u$fd newidx other; do
11406                 (( (newidx - oldidx) == 1 )) ||
11407                         error  "changelog jump detected (last: $oldidx, current: $newidx)"
11408
11409                 if (( (newidx - firstidx + 1) % 13000 == 0 )); then
11410                         [[ $pid -eq 0 ]] ||
11411                                 wait $pid || error "changelog_clear failed"
11412                         changelog_clear $((newidx - 1)) mds1 >&2 & pid=$!
11413                 fi
11414                 oldidx=$newidx
11415         done
11416
11417         [[ $pid -eq 0 ]] ||
11418                 wait $pid || error "changelog_clear failed"
11419
11420         echo "$oldidx"
11421 }
11422
11423 test_135() {
11424         (( MDS1_VERSION >= $(version_code 2.15.52) )) ||
11425                 skip "need MDS version at least 2.15.52"
11426
11427         local service=$(facet_svc mds1)
11428         local rc=0
11429         local lastread lastidx
11430         local files_pid reader_pid
11431         local fd
11432         local init_time
11433         local cl_user
11434
11435         # Need to reformat because we are changing llog catalog sizes to 5.
11436         # Otherwise, processing could fail with existing catalogs (last_idx>5).
11437         reformat
11438         setup_noconfig
11439
11440         # Disable changelog garbage colector
11441         local oldgc=$(do_facet mds1 "$LCTL get_param mdd.${service}.changelog_gc")
11442         do_facet mds1 "$LCTL set_param -n mdd.${service}.changelog_gc=0"
11443         stack_trap "cleanup_test_135 $oldgc" EXIT INT
11444
11445         # change the changelog_catalog size to 5 entries for everybody
11446 #define OBD_FAIL_CAT_RECORDS                        0x1312
11447         do_node $(comma_list $(all_nodes)) $LCTL set_param fail_loc=0x1312 fail_val=5
11448
11449         # disable console ratelimit
11450         local rl=$(cat /sys/module/libcfs/parameters/libcfs_console_ratelimit)
11451         echo 0 > /sys/module/libcfs/parameters/libcfs_console_ratelimit
11452         stack_trap "echo $rl > /sys/module/libcfs/parameters/libcfs_console_ratelimit" EXIT
11453
11454         test_mkdir -c 1 -i 0 $DIR/$tdir || error "Failed to create directory"
11455         do_nodes $(comma_list $(osts_nodes)) $LCTL set_param \
11456                 seq.*OST*-super.width=$DATA_SEQ_MAX_WIDTH
11457
11458         changelog_chmask "ALL" || error "changelog_chmask failed"
11459         changelog_register || error "changelog_register failed"
11460
11461         cl_user="${CL_USERS[mds1]%% *}"
11462         changelog_users mds1 | grep -q $cl_user ||
11463                 error "User $cl_user not found in changelog_users"
11464
11465         # Start reader thread
11466         coproc $LFS changelog --follow $service
11467         reader_pid=$!
11468         fd=${COPROC[0]}
11469         stack_trap "echo kill changelog reader; kill $reader_pid" EXIT
11470
11471         echo -e "\nWrap arround changelog catalog"
11472
11473         # Start file writer thread
11474         __test_135_file_thread "$service" & files_pid=$!
11475         stack_trap "(pkill -P$files_pid; kill $files_pid) &> /dev/null || true" EXIT
11476
11477         # Check changelog entries
11478         lastread=$(__test_135_reader $fd $cl_user) || exit $?
11479
11480         ! kill -0 $files_pid 2>/dev/null ||
11481                 error "creation thread is running. Is changelog reader stuck?"
11482
11483         lastidx=$(changelog_users mds1 | awk '/current_index/ {print $NF}' )
11484         [[ "$lastread" -eq "$lastidx" ]] ||
11485                 error "invalid changelog lastidx (read: $lastread, mds: $lastidx)"
11486 }
11487 run_test 135 "check the behavior when changelog is wrapped around"
11488
11489 cleanup_136 () {
11490         do_facet mds2 "$LCTL --device ec cleanup" || true
11491         do_facet mds2 "$LCTL --device ec detach" || true
11492
11493         stopall
11494         reformat_and_config
11495 }
11496
11497 test_136() {
11498         (( MDSCOUNT >= 2 )) || skip "needs >= 2 MDTs"
11499         (( $MDS1_VERSION >= $(version_code v2_15_61-43-g55c143a66d) )) ||
11500                 skip "Need MDS >= 2.15.61.43 for obdecho on second MDT"
11501
11502         reformat
11503         setup_noconfig
11504
11505         do_rpc_nodes $(facet_active_host mds2) "load_module obdecho/obdecho"
11506         do_facet mds2 "$LCTL attach echo_client ec ec_uuid" ||
11507             error "echo attach fail"
11508
11509         stack_trap cleanup_136 EXIT
11510
11511         do_facet mds2 "$LCTL --device ec setup lustre-MDT0001 mdt" &&
11512             error "attach to MDT should fail!"
11513
11514         do_facet mds2 "$LCTL --device ec setup lustre-MDT0001 mdd" ||
11515             error "attach to MDD should OK"
11516         do_facet mds2 "$LCTL --device ec test_mkdir /tt" &&
11517             error "mkdir test should fail with remote object"
11518
11519         return 0
11520 }
11521 run_test 136 "don't panic with bad obdecho setup"
11522
11523 test_137() {
11524         (( MDS1_VERSION >= $(version_code 2.15.61) )) ||
11525                 skip "need MDS version at least 2.15.61"
11526
11527         (( $MDSCOUNT >= 3 )) || skip "needs >= 3 MDTs"
11528
11529         local failnode=1.2.3.4@$NETTYPE
11530         local keep_zpool=$KEEP_ZPOOL
11531
11532         reformat
11533         #start mgs or mgs/mdt0
11534         if ! combined_mgs_mds ; then
11535                 start_mgs || error "Fail to register mgs"
11536                 start_mdt 1 || error "Fail to register mds1"
11537         else
11538                 start_mdt 1 || error "Fail to register mds1"
11539         fi
11540
11541         start_ost || error "OST0 start fail"
11542
11543         mount_client $MOUNT || error "mount client fails"
11544         wait_osc_import_ready client ost
11545         check_mount || error "check_mount failed"
11546
11547         # Add failover node on OST0000
11548         stop_ost
11549         [ "$ost1_FSTYPE" == zfs ] && import_zpool ost1
11550         do_facet ost1 "$TUNEFS --failnode=$failnode $(ostdevname 1)" ||
11551                 error "ost1 tunefs failed"
11552         start_ost || error "OST0 start fail"
11553
11554         # Add pool and parameters on MDT0000 to check the inheritance
11555         do_facet mgs $LCTL pool_new $FSNAME.pool1 || error "pool_new failed"
11556         do_facet mgs $LCTL pool_add $FSNAME.pool1 OST0000 ||
11557                 error "pool_add failed"
11558
11559         set_conf_param_and_check mds1                                   \
11560             "$LCTL get_param -n lod.$FSNAME-MDT0000*.dom_stripesize"    \
11561             "$FSNAME-MDT0000.lod.dom_stripesize"                        \
11562             "$((2<<20))"
11563
11564         start_mdt 2 || error "Fail to register mds2"
11565
11566         wait_osp_import mds1 mds2 FULL
11567         wait_osp_import mds2 mds1 FULL
11568         wait_osp_import mds2 ost1 FULL
11569
11570         # Add failover node on MDT0001
11571         stop_mdt 2 || error "Fail to umount  mds2"
11572         [ "$mds1_FSTYPE" == zfs ] && import_zpool mds2
11573         do_facet mds2 "$TUNEFS --failnode=$failnode $(mdsdevname 2)" ||
11574                 error "mds2 tunefs failed"
11575         start_mdt 2 || error "Fail to mount mds2"
11576
11577         wait_osp_import mds1 mds2 FULL
11578         wait_osp_import mds2 mds1 FULL
11579         wait_osp_import mds2 ost1 FULL
11580
11581         local i
11582         for ((i=3; i <= MDSCOUNT; i++)); do
11583                 start_mdt $i || error "Fail to register mds$i"
11584         done
11585
11586         wait_osc_import_state mds ost FULL
11587
11588         for ((i=2; i <= MDSCOUNT; i++)); do
11589                 local import
11590                 local facet=mds$i
11591                 local tgt=$(facet_svc $facet)
11592                 local lod="lod.$tgt*"
11593
11594                 wait_osp_active mds $tgt $(( i - 1 )) 1
11595
11596                 do_facet $facet $LCTL get_param -n $lod.pools.pool1 |
11597                         grep -q "OST0000" || error "pool1 should be inherited"
11598
11599                 val=$(do_facet $facet $LCTL get_param -n $lod.dom_stripesize)
11600                 (( val == (2<<20) )) ||
11601                         error "dom_stripesize should be inherited"
11602
11603                 import="osc.$FSNAME-OST0000-osc-${tgt#*-}.import"
11604                 do_facet $facet $LCTL get_param -n $import |
11605                         grep -q "failover_nids:.*$failnode" ||
11606                         error "$failnode not found in $import"
11607
11608                 [[ "${tgt#*-}" != MDT0001 ]] || continue
11609
11610                 import="osp.$FSNAME-MDT0001-osp-${tgt#*-}.import"
11611                 do_facet $facet $LCTL get_param -n $import |
11612                         grep -q "failover_nids:.*$failnode" ||
11613                         error "$failnode not found in $import"
11614         done
11615
11616         cleanup || error "cleanup failed with rc $?"
11617         reformat_and_config
11618 }
11619 run_test 137 "a new MDT should inherit pools, parameters and failnode"
11620
11621 test_140() {
11622         (( MDS1_VERSION >= $(version_code 2.15.55) )) ||
11623                 skip "need MDS version at least 2.15.55"
11624         (( MDSCOUNT >= 2 )) || skip "needs >= 2 MDTs"
11625
11626         RM_UPDATELOG=$(do_facet mds2 "which remove_updatelog 2> /dev/null")
11627         RM_UPDATELOG=${RM_UPDATELOG:-"$LUSTRE/scripts/remove_updatelog"}
11628
11629         [ -f "$RM_UPDATELOG" ] ||
11630                 skip_env "remove_updatelog is not found on mds2"
11631
11632         local mntpt=$(facet_mntpt mds2)
11633
11634         setup_noconfig
11635         test_mkdir -c $MDSCOUNT -p $DIR/$tdir ||
11636                 error "mkdir $DIR/$tdir failed"
11637         mkdir $DIR/$tdir/d{1..256}
11638
11639         stop_mdt 1
11640         stop_mdt 2
11641
11642         mount_fstype mds2 || error "mount as fstype mds2 failed"
11643         do_facet mds2 $RM_UPDATELOG -n $mntpt
11644         MDTS=($(do_facet mds2 $RM_UPDATELOG -n $mntpt |
11645                 grep -o "Processing MDT[0-9]*" | awk -F'MDT' '{print $2}'))
11646         (( ${#MDTS[@]} == MDSCOUNT )) ||
11647                 error "Processed ${#MDTS[@]} from $MDSCOUNT"
11648
11649         do_facet mds2 $RM_UPDATELOG -n -m 1,0 $mntpt
11650         MDTS=($(do_facet mds2 $RM_UPDATELOG -n -m 1,0 $mntpt |
11651                 grep -o "Processing MDT[0-9]*" | awk -F'MDT' '{print $2}'))
11652         (( ${#MDTS[@]} == 2 )) ||
11653                 error "Processed ${#MDTS[@]} instead of 2"
11654         (( ${MDTS[0]} == 1 && ${MDTS[1]} == 0 )) ||
11655                 error "Processed: ${MDTS[*]}, expected: 1 0"
11656
11657         do_facet mds2 $RM_UPDATELOG -m 0 $mntpt
11658         unmount_fstype mds2
11659         start_mdt 2 || error "mds2 start fail"
11660         start_mdt 1 || error "mds1 start fail"
11661         wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds1 FULL
11662         wait_clients_import_state ${CLIENTS:-$HOSTNAME} mds2 FULL
11663
11664         rm -rf $DIR/$tdir || error "Can't remove $tdir"
11665         stopall
11666         reformat_and_config
11667 }
11668 run_test 140 "remove_updatelog script actions"
11669
11670 test_150() {
11671         setup
11672
11673         local max_cached_mb=$($LCTL get_param llite.*.max_cached_mb |
11674                               awk '/^max_cached_mb/ { print $2 }')
11675         stack_trap "$LCTL set_param -n llite.*.max_cached_mb=$max_cached_mb"
11676
11677         $LCTL set_param llite.*.max_cached_mb='100%'
11678
11679         local new_max_cached_mb=$($LCTL get_param llite.*.max_cached_mb |
11680                                   awk '/^max_cached_mb/ { print $2 }')
11681         local total_ram_mb=$(free -m | grep 'Mem:' | awk '{print $2}')
11682
11683         $LCTL get_param llite.*.max_cached_mb
11684         echo "total ram mb: $total_ram_mb"
11685         (( new_max_cached_mb == total_ram_mb )) ||
11686                 error "setting cache to 100% not equal to total RAM"
11687
11688         $LCTL set_param llite.*.max_cached_mb='50%'
11689         new_max_cached_mb=$($LCTL get_param llite.*.max_cached_mb |
11690                             awk '/^max_cached_mb/ { print $2 }')
11691
11692         $LCTL get_param llite.*.max_cached_mb
11693         (( new_max_cached_mb == $((total_ram_mb / 2)) )) ||
11694                 error "setting cache to 50% not equal to 50% of RAM"
11695
11696         $LCTL set_param llite.*.max_cached_mb='105%' &&
11697                 error "should not be able to set insane value"
11698
11699         $LCTL set_param llite.*.max_cached_mb='0%'
11700         new_max_cached_mb=$($LCTL get_param llite.*.max_cached_mb |
11701                             awk '/^max_cached_mb/ { print $2 }')
11702         # Minimum cache size is 64 MiB
11703         $LCTL get_param llite.*.max_cached_mb
11704         (( new_max_cached_mb == 64 )) ||
11705                 error "setting cache to 0% != minimum cache size"
11706 }
11707 run_test 150 "test setting max_cached_mb to a %"
11708
11709 test_151a() {
11710         (( MDS1_VERSION >= $(version_code 2.15.58) )) ||
11711                 skip "need MDS version at least 2.15.58"
11712         [[ "$ost1_FSTYPE" == ldiskfs ]] || skip "ldiskfs only test"
11713
11714         cleanup
11715         if ! combined_mgs_mds ; then
11716                 stop mgs
11717         fi
11718
11719         echo "Damage ost1 local config log"
11720         do_facet ost1 "$DEBUGFS -w -R 'punch CONFIGS/$FSNAME-OST0000 0 1' \
11721                       $(ostdevname 1) || return \$?" ||
11722                 error "do_facet ost1 failed with $?"
11723
11724         # expect OST to fail mount with no MGS and bad local config
11725         start_ost && error "OST start should fail"
11726
11727         if ! combined_mgs_mds ; then
11728                 start_mgs
11729         fi
11730         start_mds || error "MDS start failed"
11731         # now it should start with MGS config
11732         start_ost || error "OST start failed"
11733         reformat_and_config
11734 }
11735 run_test 151a "damaged local config doesn't prevent mounting"
11736
11737 test_151b() {
11738         (( MDS1_VERSION >= $(version_code 2.15.63) )) ||
11739                 skip "need MDS version at least 2.15.63"
11740         [[ "$ost1_FSTYPE" == ldiskfs ]] || skip "ldiskfs only test"
11741
11742         cleanup
11743         if ! combined_mgs_mds ; then
11744                 stop mgs
11745         fi
11746
11747         start_mgsmds || error "MDS start failed"
11748
11749         # start despite -ENOSPC errors
11750 #define OBD_FAIL_LLOG_BACKUP_ENOSPC 0x131e
11751         do_facet ost1 $LCTL set_param fail_loc=0x131e
11752         start_ost || error "OST start failed"
11753         reformat_and_config
11754 }
11755 run_test 151b "-ENOSPC doesn't affect mount"
11756
11757 test_152() {
11758         (( MDS1_VERSION >= $(version_code 2.15.59.53) )) ||
11759                 skip "need MDS >= 2.15.59.53 for sequence allocation retry"
11760         (( MDSCOUNT >= 2 )) || skip "needs >= 2 MDTs"
11761         local tf=$DIR/$tdir/$tfile
11762         local nost=$((OSTCOUNT+1))
11763         local nostdevname=$(ostdevname $nost)
11764
11765         setupall
11766         stack_trap "reformat_and_config"
11767         test_mkdir -i 1 -c1 $DIR/$tdir || error "can't mkdir"
11768
11769         log "ADD OST$nost"
11770         add ost$nost $(mkfs_opts ost1 $nostdevname) --index=$nost \
11771                 --reformat $nostdevname $(ostvdevname $nost)
11772         [[ -d "$nostdevname" ]] || stack_trap "do_facet mds1 rm -f $nostdevname"
11773
11774 #define OBD_FAIL_OPS_FAIL_SEQ_ALLOC             0x2109
11775         do_facet mds1 $LCTL set_param fail_loc=0x80002109 fail_val=2
11776         echo "START OST$nost"
11777         stack_trap "stop ost$nost"
11778         start ost$nost $nostdevname $OST_MOUNT_OPTS &
11779         local PID=$!
11780         sleep 2
11781
11782         $LFS setstripe -c -1 $tf &
11783         local PID2=$!
11784         sleep 2
11785
11786         log "STOP OST$nost"
11787         # probably mount hasn't completed yet, so stop races with it
11788         while true; do
11789                 stop ost$nost
11790                 jobs -pr | grep -E "^$PID\$" && sleep 0.5 && continue
11791                 break
11792         done
11793         wait $PID
11794         wait $PID2
11795         do_facet mds1 $LCTL set_param fail_loc=0
11796         log "START OST$nost again"
11797         start ost$nost $nostdevname $OST_MOUNT_OPTS ||
11798                 error "can't start ost$nost"
11799         sleep 10
11800         $LFS setstripe -c -1 $tf-2 || error "can't touch  $tf-2"
11801         $LFS getstripe -v $tf-2
11802         local stripes=$($LFS getstripe -c $tf-2)
11803         (( stripes == $nost )) || error "$tf-2 $stripes != $nost"
11804 }
11805 run_test 152 "seq allocation error in OSP"
11806
11807 test_153a() {
11808         reformat_and_config
11809
11810         start_mds || error "MDS start failed"
11811         start_ost || error "OST start failed"
11812
11813         local nid=$($LCTL list_nids | grep ${NETTYPE} | head -n1)
11814         local net=${nid#*@}
11815         local mgs_nid=$(do_facet mgs $LCTL list_nids | head -1)
11816         local ost1_nid=$(do_facet ost1 $LCTL list_nids | head -1)
11817         local fake_pnid="192.168.252.112@${net}"
11818         local fake_nids="${fake_pnid},${fake_pnid}2"
11819         local fake_failover="10.252.252.113@${net},10.252.252.113@${net}2"
11820         local nids_and_failover="$fake_nids:$fake_failover:$ost1_nid:$mgs_nid"
11821         local period=0
11822         local pid
11823         local rc
11824
11825         mount -t lustre $nids_and_failover:/lustre $MOUNT &
11826         pid=$!
11827         while (( period < 30 )); do
11828                 [[ -n "$(ps -p $pid -o pid=)" ]] || break
11829                 echo "waiting for mount ..."
11830                 sleep 5
11831                 period=$((period + 5))
11832         done
11833         $LCTL get_param mgc.MGC${fake_pnid}.import | grep "uptodate:"
11834         check_mount || error "check_mount failed"
11835         umount $MOUNT
11836         cleanup || error "cleanup failed with rc $?"
11837 }
11838 run_test 153a "bypass invalid NIDs quickly"
11839
11840 #LU-17367
11841 test_153b() {
11842         reformat_and_config
11843         setupall
11844
11845         local IPv6_1="6699:7654::1234:1234:d84@tcp"
11846         local IPv6_2="2001:0db8:85a3:0000:0000:8a2e:0370:7334@tcp"
11847         local IPv6_3="5031:db8:85a3:8d3:1319:8a2e:370:7348@tcp"
11848         local IPv4_1="127.0.0.5"
11849         local IPv4_2="193.168.0.240@tcp"
11850         local IPv4_3="162.32.0.100"
11851
11852         local mgslist
11853
11854         umount $MOUNT
11855
11856         mgslist="$IPv6_1:$mgs_HOST"
11857         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11858                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11859         umount $MOUNT
11860
11861         mgslist="$mgs_HOST:$mgs_HOST:$mgs_HOST"
11862         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11863                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11864         umount $MOUNT
11865
11866         mgslist="$mgs_HOST:$IPv6_1"
11867         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11868                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11869         umount $MOUNT
11870
11871         mgslist="$mgs_HOST:$IPv4_1"
11872         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11873                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11874         umount $MOUNT
11875
11876         mgslist="$IPv4_1:$mgs_HOST"
11877         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11878                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11879         umount $MOUNT
11880
11881         mgslist="$IPv4_2:$IPv4_1:$mgs_HOST"
11882         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11883                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11884         umount $MOUNT
11885
11886         mgslist="$IPv6_1,$IPv4_2,$IPv4_1:$mgs_HOST"
11887         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11888                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11889         umount $MOUNT
11890
11891         mgslist="$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1\
11892 :$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1\
11893 :$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1\
11894 :$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1\
11895 :$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1:$IPv4_1\
11896 :$IPv4_1:$IPv4_1:$mgs_HOST"
11897         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11898                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11899         umount $MOUNT
11900
11901         mgslist="$IPv6_1,$IPv4_2,$IPv4_1:$IPv6_3,$IPv4_3,$IPv6_2:$mgs_HOST"
11902         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11903                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11904         umount $MOUNT
11905
11906         mgslist="$IPv4_2,$IPv6_1,$IPv4_2,$IPv4_1:$IPv6_3,$IPv4_3:$IPv6_2\
11907 ,$IPv6_1,$IPv4_2,$IPv4_1:$IPv6_3,$IPv4_3:$IPv6_2,$IPv6_1,$IPv4_2\
11908 ,$IPv4_1:$IPv6_3,$IPv4_3:$IPv6_2,$IPv6_1,$IPv4_2,$IPv4_1:$IPv6_3\
11909 ,$IPv4_3:$IPv6_2,$IPv6_1,$IPv4_2,$IPv4_1:$IPv6_3,$IPv4_3:$IPv6_2\
11910 :$mgs_HOST"
11911         mount -t lustre $mgslist:/$FSNAME $MOUNT ||
11912                 error "mount failed with $mgslist:/$FSNAME $MOUNT"
11913         umount $MOUNT
11914 }
11915 run_test 153b "added IPv6 NID support"
11916
11917 test_153c() {
11918         reformat_and_config
11919
11920         start_mds || error "MDS start failed"
11921         start_ost || error "OST start failed"
11922
11923         local nid=$($LCTL list_nids | grep ${NETTYPE} | head -n1)
11924         local net=${nid#*@}
11925         local fake_pnid="192.168.252.112@${net}"
11926         local fake_failover="192.168.252.113@${net}:192.168.252.115@${net}"
11927         local nids_and_failover="$fake_pnid:$fake_failover"
11928         local period=0
11929         local pid
11930         local rc
11931
11932         umount_client $MOUNT
11933         mount -t lustre $nids_and_failover:/lustre $MOUNT &
11934         pid=$!
11935         while (( period < 30 )); do
11936                 [[ -n "$(ps -p $pid -o pid=)" ]] || break
11937                 echo "waiting for mount ..."
11938                 sleep 5
11939                 period=$((period + 5))
11940         done
11941         $LCTL get_param mgc.MGC${fake_pnid}.import | grep "sec_ago"
11942         conn=$($LCTL get_param mgc.MGC${fake_pnid}.import |
11943                 awk '/connection_attempts:/ {print $2}')
11944         echo "connection attempts: $conn"
11945         (( conn > 2)) || error "too few connection attempts"
11946         echo "Waiting for mount to fail"
11947         wait $pid
11948         cleanup || error "cleanup failed with rc $?"
11949 }
11950 run_test 153c "don't stuck on unreached NID"
11951
11952 test_154() {
11953         [ "$mds1_FSTYPE" == "ldiskfs" ] || skip "ldiskfs only test"
11954         (( $MDS1_VERSION >= $(version_code 2.15.63.1) )) ||
11955                 skip "Need MDS version at least 2.15.63.1"
11956         local mdt1=$(mdsdevname 1)
11957         local cmd
11958         local parentfid
11959         local dotdotfid
11960         local ino
11961
11962         reformat
11963         setupall
11964
11965         # create rename test dir on MDT0000 to simplify later debugfs checks
11966         test_mkdir -c 1 -i 0 $DIR/$tdir || error "mkdir $tdir failed"
11967         test_mkdir -c 1 -i 0 $DIR/$tdir.tgt || error "mkdir $tdir.tgt failed"
11968
11969         for name in dx_dir dirent empty; do
11970                 test_mkdir -c 1 -i 0 $DIR/$tdir.$name ||
11971                         error "mkdir $tdir.$name failed"
11972         done
11973
11974         # make this directory large enough to htree split
11975         createmany -o $DIR/$tdir.dx_dir/$tfile.longfilename 128
11976         # put 2 entries after dotdot in this directory
11977         createmany -o $DIR/$tdir.dirent/$tfile.longfilename 2
11978
11979         for name in dx_dir dirent empty; do
11980                 mv $DIR/$tdir.$name $DIR/$tdir || error "mv $tdir.$name failed"
11981         done
11982
11983         parentfid="fid:$($LFS path2fid $DIR/$tdir)"
11984         echo "==target parent FID: $parentfid=="
11985
11986         stopall
11987
11988         # check that ".." FID is updated during normal operation
11989         echo "==debugfs before backup=="
11990         for name in dx_dir dirent empty; do
11991                 cmd="debugfs -c -R 'stat ROOT/$tdir/$tdir.$name' $mdt1"
11992                 do_facet mds1 "$cmd" ||
11993                         error "debugfs stat before backup failed"
11994                 cmd="debugfs -c -R 'ls -lD ROOT/$tdir/$tdir.$name' $mdt1"
11995                 do_facet mds1 "$cmd" ||
11996                         error "debugfs before backup $name failed"
11997                 dotdotfid=$(do_facet mds1 "$cmd" |& awk '/fid:.+\.\./ { print $9 }')
11998                 [[ "$dotdotfid" == "$parentfid" ]] ||
11999                         error "parent '$parentfid' != dotdot '$dotdotfid' on $name"
12000         done
12001
12002         for ((i = 1; i <= $MDSCOUNT; i++ )); do
12003                 mds_backup_restore mds$i ||
12004                         error "Backup/restore on mds$i failed"
12005         done
12006
12007         setupall
12008
12009         # verify that rename of the restored directory updates the
12010         # ".." entry in the directory with the parent FID
12011         echo "==pre-rename parent/.. inodes=="
12012         for name in dx_dir dirent empty; do
12013                 ls -dial $DIR/$tdir $DIR/$tdir/$tdir.$name/.. ||
12014                         error "ls on original dirs failed"
12015                 ino=($(stat -c "%i" $DIR/$tdir $DIR/$tdir/$tdir.$name/..))
12016                 (( ${ino[0]} == ${ino[1]} )) ||
12017                         error "ino $DIR/$tdir ${ino[0]} != $tdir.$name/.. ${ino[1]}"
12018         done
12019
12020         for name in dx_dir dirent empty; do
12021                 mv $DIR/$tdir/$tdir.$name $DIR/$tdir.tgt ||
12022                         error "mv $tdir.$name failed"
12023         done
12024
12025         echo "==post-rename parent/.. inodes=="
12026         for name in dx_dir dirent empty; do
12027                 ls -dial $DIR/$tdir.tgt $DIR/$tdir.tgt/$tdir.$name/.. ||
12028                         error "ls on renamed dirs failed"
12029                 ino=($(stat -c "%i" $DIR/$tdir.tgt $DIR/$tdir.tgt/$tdir.$name/..))
12030                 (( ${ino[0]} == ${ino[1]} )) ||
12031                         error "ino $DIR/$tdir.tgt ${ino[0]} != $tdir.$name/.. ${ino[1]}"
12032         done
12033
12034         parentfid="fid:$($LFS path2fid $DIR/$tdir.tgt)"
12035         echo "==target parent FID: $parentfid=="
12036
12037         stopall
12038
12039         for name in dx_dir dirent empty; do
12040                 echo "==post-rename .$name should have '$parentfid ..'=="
12041                 cmd="debugfs -c -R 'stat ROOT/$tdir.tgt/$tdir.$name' $mdt1"
12042                 do_facet mds1 "$cmd" ||
12043                         error "debugfs stat after rename failed"
12044                 cmd="debugfs -c -R 'ls -lD ROOT/$tdir.tgt/$tdir.$name' $mdt1"
12045                 do_facet mds1 "$cmd" ||
12046                         error "debugfs ls .$name after rename failed"
12047                 dotdotfid=$(do_facet mds1 "$cmd" |& awk '/fid:.+\.\./ { print $9 }')
12048                 [[ "$dotdotfid" == "$parentfid" ]] ||
12049                         error "parent '$parentfid' != dotdot '$dotdotfid' on $name"
12050         done
12051
12052         FSCK_MAX_ERR=0 run_e2fsck $(facet_active_host mds1) $mdt1 -n ||
12053                 error "e2fsck returned $?"
12054 }
12055 run_test 154 "expand .. on rename after MDT backup restore"
12056
12057 test_155() {
12058         (( OST1_VERSION >= $(version_code 2.16.50.134) )) ||
12059                 skip "Need OST version at least 2.16.50.134"
12060
12061         reformat_and_config
12062         setupall
12063
12064         rm -rf $DIR/$tdir
12065         mkdir_on_mdt0 $DIR/$tdir
12066         $LFS setstripe -c 1 -i 0 $DIR/$tdir
12067
12068         force_new_seq mds1
12069         touch $DIR/$tdir/$tfile
12070         local seq1=$($LFS getstripe --yaml $DIR/$tdir/$tfile |
12071                      awk -F ':' '/l_fid:/ {print $2}' | tr -d [:blank:])
12072
12073         stopall
12074         setupall
12075
12076         force_new_seq mds1
12077         touch $DIR/$tdir/${tfile}2
12078         local seq2=$($LFS getstripe --yaml $DIR/$tdir/${tfile}2 |
12079                      awk -F ':' '/l_fid:/ {print $2}' | tr -d [:blank:])
12080
12081         (( seq2 == seq1 + 1 )) || error "gap in seq: old $seq1 new $seq2"
12082 }
12083 run_test 155 "gap in seq allocation from ofd after restarting"
12084
12085 test_160() {
12086         ((OST1_VERSION >= $(version_code 2.16.55) )) ||
12087                 skip "need OST >= 2.16.55 to have MGC with all failovers"
12088
12089         stopall
12090         reformat
12091
12092         local mgs_nid=$(do_facet mgs $LCTL list_nids | head -1)
12093         local failover_nid="192.168.252.160@${NETTYPE}"
12094         local mgs_nodes=$mgs_nid:$failover_nid
12095         local tmp_mnt="$TMP/lmount"
12096         local count;
12097
12098         start_mgsmds
12099         start_ost
12100
12101         stack_trap "cleanup; reformat"
12102
12103         do_facet mgs "mkdir -p $tmp_mnt"
12104         do_facet mgs "$MOUNT_CMD $mgs_nodes:/$FSNAME $tmp_mnt" ||
12105                 error "Fail to mount local client on MGS"
12106         do_facet mgs "umount $tmp_mnt"
12107
12108         do_facet mgs "$LCTL get_param mgc.MGC${mgs_nid}.import"
12109         count=$(do_facet mgs "$LCTL get_param mgc.MGC${mgs_nid}.import" |
12110                 grep -c "$failover_nid")
12111         (( count > 0 )) ||
12112                 error "MGC misses failover MGS nid"
12113 }
12114 run_test 160 "MGC updates failnodes from all participants"
12115
12116 cleanup_200() {
12117         local modopts=$1
12118         stopall
12119         $LUSTRE_RMMOD
12120         [[ -z $modopts ]] || MODOPTS_LIBCFS=$modopts
12121 }
12122
12123 test_200a() {
12124         cleanup_200
12125
12126         local cpus=$(lscpu | awk '/^CPU.s.:/ {print $NF}')
12127         local old_modopts=$MODOPTS_LIBCFS
12128         stack_trap "cleanup_200 $old_modopts"
12129
12130         MODOPTS_LIBCFS="cpu_npartitions=$cpus"
12131
12132         load_modules_local libcfs
12133         $LCTL get_param -n cpu_partition_table
12134
12135         local expected=$(cat /sys/module/libcfs/parameters/cpu_npartitions)
12136         local result=$($LCTL get_param -n cpu_partition_table | wc -l)
12137
12138         (( $result == $expected )) ||
12139                 error "CPU partitions not $expected, found: $result"
12140 }
12141 run_test 200a "check CPU partitions"
12142
12143 test_200b() {
12144         cleanup_200
12145
12146         local cpus=$(lscpu | awk '/^CPU.s.:/ {print $NF}')
12147         local nodes=$(lscpu | awk '/NUMA node.s.:/ {print $NF}')
12148         local old_modopts=$MODOPTS_LIBCFS
12149         stack_trap "cleanup_200 $old_modopts"
12150
12151         local pattern="0[$(lscpu | awk '/CPU.s. list:/ {print $NF}')]"
12152         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\""
12153
12154         load_modules_local libcfs
12155         grep . /sys/module/libcfs/parameters/cpu*
12156         $LCTL get_param -n cpu_partition_table
12157         local expected=cpus
12158         local table=$($LCTL get_param -n cpu_partition_table)
12159         # ignore partition num and ':'
12160         local actual=$(( $(awk '{print NF; exit}' <<< $table) - 2 ))
12161
12162         (( expected == actual )) || {
12163                 echo -e "layout wrong:\n$table"
12164                 error "partition 0 is missing CPUs from pattern: '$pattern'"
12165         }
12166
12167         (( $(echo $table | wc -l) == 1 )) || {
12168                 echo -e "layout wrong\n$table"
12169                 error "layout has too many partitions from pattern: '$pattern'"
12170         }
12171
12172         (( cpus >= 4 )) || skip "need at least 4 cpu cores"
12173         cleanup
12174
12175         pattern="0[1-2]"
12176         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\""
12177
12178         load_modules_local libcfs
12179         $LCTL get_param -n cpu_partition_table
12180         expected="0     : 1 2"
12181         table=$($LCTL get_param -n cpu_partition_table)
12182
12183         [[ $table == $expected ]] ||
12184                 error "CPU pattern not $expected, found: $table"
12185 }
12186 run_test 200b "set CPU pattern using core selection"
12187
12188 test_200c() {
12189         cleanup_200
12190
12191         local cpus=$(lscpu | awk '/^CPU.s.:/ {print $NF}')
12192         local nodes=$(lscpu | awk '/NUMA node.s.:/ {print $NF}')
12193
12194         local old_modopts=$MODOPTS_LIBCFS
12195         stack_trap "cleanup_200 $old_modopts"
12196
12197         local pattern="N"
12198         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\""
12199
12200         load_modules_local libcfs
12201         grep . /sys/module/libcfs/parameters/cpu*
12202         $LCTL get_param -n cpu_partition_table
12203         local expected=$nodes
12204         local table=$($LCTL get_param -n cpu_partition_table)
12205         local actual=$(echo $table | wc -l)
12206
12207         (( actual == expected )) ||
12208                 error "CPU partitions not $expected, found: $actual"
12209
12210         cleanup
12211
12212         pattern="0[$(lscpu | awk '/^NUMA node0 CPU.s.:/ {print $NF}')]"
12213         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\""
12214
12215         load_modules_local libcfs
12216         expected=$($LCTL get_param -n cpu_partition_table)
12217
12218         cleanup
12219
12220         pattern="N 0[0]"
12221         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\""
12222
12223         load_modules_local libcfs
12224         $LCTL get_param -n cpu_partition_table
12225         local table=$($LCTL get_param -n cpu_partition_table)
12226
12227         [[ $table == $expected ]] ||
12228                 error "CPU pattern not $expected, found: $table"
12229 }
12230 run_test 200c "set CPU pattern using NUMA node layout"
12231
12232 test_200d() {
12233         cleanup_200
12234
12235         local cpus=$(lscpu | awk '/^CPU.s.:/ {print $NF}')
12236         local nodes=$(lscpu | awk '/NUMA node.s.:/ {print $NF}')
12237         local parts=$((cpus / 2))
12238
12239         local old_modopts=$MODOPTS_LIBCFS
12240         stack_trap "cleanup_200 $old_modopts"
12241
12242         local full_cpu_count=0
12243         local excluded_count=0
12244
12245         # First, get the full table
12246         MODOPTS_LIBCFS="cpu_npartitions=$parts"
12247
12248         load_modules_local libcfs
12249         echo "full_table:"
12250         $LCTL get_param -n cpu_partition_table
12251
12252         local full_table=()
12253         while read -r line; do
12254                 full_table+=("$line")
12255                 full_cpu_count=$((full_cpu_count + $(echo $line | wc -w) - 2))
12256         done < <($LCTL get_param -n cpu_partition_table)
12257
12258         cleanup
12259
12260         # Now, set the pattern to exclude CPU 1
12261         pattern="X[1]"
12262         MODOPTS_LIBCFS="cpu_npartitions=$parts cpu_pattern=\"$pattern\""
12263
12264         load_modules_local libcfs
12265         echo "table with CPU 1 excluded:"
12266         grep . /sys/module/libcfs/parameters/cpu*
12267         $LCTL get_param -n cpu_partition_table
12268
12269         local table=()
12270         while read -r line; do
12271                 table+=("$line")
12272                 excluded_count=$((excluded_count + $(echo $line | wc -w) - 2))
12273         done < <($LCTL get_param -n cpu_partition_table)
12274
12275         # Check if CPU 1 is excluded
12276         for line in "${table[@]}"; do
12277                 ! [[ "$line" =~ " 1 " ]] ||
12278                         error "CPU 1 was not excluded with pattern: $pattern"
12279         done
12280
12281         # Check if only CPU 1 is excluded
12282         (( excluded_count == full_cpu_count - 1 )) ||
12283                 error "More than one CPU was excluded with pattern: $pattern"
12284
12285         cleanup
12286
12287         full_cpu_count=0
12288         excluded_count=0
12289
12290         # First, get the full table
12291         pattern="N"
12292         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\""
12293
12294         load_modules_local libcfs
12295         echo "full_table:"
12296         $LCTL get_param -n cpu_partition_table
12297
12298         full_table=()
12299         while read -r line; do
12300                 full_table+=("$line")
12301                 full_cpu_count=$((full_cpu_count + $(echo $line | wc -w) - 2))
12302         done < <($LCTL get_param -n cpu_partition_table)
12303
12304         cleanup
12305
12306         # Now, set the pattern to exclude CPU 1
12307         pattern="N X[1]"
12308         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\""
12309
12310         load_modules_local libcfs
12311         echo "table with CPU 1 excluded:"
12312         grep . /sys/module/libcfs/parameters/cpu*
12313         $LCTL get_param -n cpu_partition_table
12314
12315         table=()
12316         while read -r line; do
12317                 table+=("$line")
12318                 excluded_count=$((excluded_count + $(echo $line | wc -w) - 2))
12319         done < <($LCTL get_param -n cpu_partition_table)
12320
12321         # Check if CPU 1 is excluded
12322         cpu_1_found=false
12323         for line in "${table[@]}"; do
12324                 [[ "$line" =~ " 1 " ]] && cpu_1_found=true
12325         done
12326         $cpu_1_found && error "CPU 1 was not excluded with pattern: $pattern"
12327
12328         # Check if only CPU 1 is excluded
12329         (( excluded_count == full_cpu_count - 1 )) ||
12330                 error "More than one CPU was excluded with pattern: $pattern"
12331 }
12332 run_test 200d "set CPU pattern to exclude only CPU 1"
12333
12334 test_200e() {
12335         cleanup_200
12336
12337         local cpus=$(lscpu | awk '/^CPU.s.:/ {print $NF}')
12338         local nodes=$(lscpu | awk '/NUMA node.s.:/ {print $NF}')
12339         local npartitions=$((cpus / 2))
12340         local expected
12341         local actual
12342         local excluded
12343         local partition
12344
12345         local old_modopts=$MODOPTS_LIBCFS
12346         stack_trap "cleanup_200 $old_modopts"
12347
12348         # N C[0]
12349         pattern="N"
12350         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\""
12351
12352         load_modules_local libcfs
12353         echo "full_table:"
12354         $LCTL get_param -n cpu_partition_table
12355
12356         local full_table=()
12357         while read -r line; do
12358                 full_table+=("$line")
12359         done < <($LCTL get_param -n cpu_partition_table)
12360         (( $($LCTL get_param -n cpu_partition_table |\
12361              awk '/\<0\>.*:/ {print NF - 3; exit}') > 0 )) ||
12362                 skip "need at least 2 cores in each CPT to exclude one"
12363
12364         cleanup
12365
12366         pattern="N C[0]"
12367         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\""
12368
12369         load_modules_local libcfs
12370         grep . /sys/module/libcfs/parameters/cpu*
12371         echo "table with npartitions=$npartitions:"
12372         $LCTL get_param -n cpu_partition_table
12373
12374         local table=()
12375         while read -r line; do
12376                 table+=("$line")
12377         done < <($LCTL get_param -n cpu_partition_table)
12378
12379         for (( i = 0; i < ${#table[@]}; i++ )); do
12380                 expected=$(echo ${full_table[$i]} | awk '{print NF - 3; exit}')
12381                 actual=$(echo ${table[$i]} | awk '{print NF - 2; exit}')
12382
12383                 (( actual == expected )) ||
12384                         error "CPU count not $expected, found: $actual"
12385
12386                 excluded=$(echo ${full_table[$i]} | awk '{print $3; exit}')
12387                 partition=$(echo ${table[$i]} | awk '{print $3; exit}')
12388
12389                 ! [[ "$partition" =~ "$excluded" ]] || {
12390                         echo -e "layout wrong:\n$table"
12391                         error "excluded the wrong CPU with pattern: $pattern"
12392                 }
12393         done
12394
12395         cleanup
12396
12397         # C[0] with npartitions
12398         MODOPTS_LIBCFS="cpu_npartitions=$npartitions"
12399
12400         load_modules_local libcfs
12401         echo "full_table:"
12402         $LCTL get_param -n cpu_partition_table
12403
12404         full_table=()
12405         while read -r line; do
12406                 full_table+=("$line")
12407         done < <($LCTL get_param -n cpu_partition_table)
12408         (( $($LCTL get_param -n cpu_partition_table |\
12409              awk '/\<0\>.*:/ {print NF - 3; exit}') > 0 )) ||
12410                 skip "need at least 2 cores in each CPT to exclude one"
12411
12412         cleanup
12413
12414         pattern="C[0]"
12415         MODOPTS_LIBCFS="cpu_pattern=\"$pattern\" cpu_npartitions=$npartitions"
12416
12417         load_modules_local libcfs
12418         grep . /sys/module/libcfs/parameters/cpu*
12419         echo "table with npartitions=$npartitions:"
12420         $LCTL get_param -n cpu_partition_table
12421
12422         table=()
12423         while read -r line; do
12424                 table+=("$line")
12425         done < <($LCTL get_param -n cpu_partition_table)
12426
12427         for (( i = 0; i < ${#table[@]}; i++ )); do
12428                 expected=$(echo ${full_table[$i]} | awk '{print NF - 3; exit}')
12429                 actual=$(echo ${table[$i]} | awk '{print NF - 2; exit}')
12430
12431                 (( actual == expected )) ||
12432                         error "CPU count not $expected, found: $actual"
12433
12434                 excluded=$(echo ${full_table[$i]} | awk '{print $3; exit}')
12435                 partition=$(echo ${table[$i]} | awk '{print $3; exit}')
12436
12437                 ! [[ "$partition" =~ "$excluded" ]] || {
12438                         echo -e "layout wrong:\n$table"
12439                         error "excluded the wrong CPU with pattern: $pattern"
12440                 }
12441         done
12442 }
12443 run_test 200e "set CPU pattern using relative core exclusion"
12444
12445 #
12446 # (This was sanity/802a)
12447 #
12448 saved_MGS_MOUNT_OPTS=$MGS_MOUNT_OPTS
12449 saved_MDS_MOUNT_OPTS=$MDS_MOUNT_OPTS
12450 saved_OST_MOUNT_OPTS=$OST_MOUNT_OPTS
12451 saved_MOUNT_OPTS=$MOUNT_OPTS
12452
12453 cleanup_802a() {
12454         stopall
12455         MGS_MOUNT_OPTS=$saved_MGS_MOUNT_OPTS
12456         MDS_MOUNT_OPTS=$saved_MDS_MOUNT_OPTS
12457         OST_MOUNT_OPTS=$saved_OST_MOUNT_OPTS
12458         MOUNT_OPTS=$saved_MOUNT_OPTS
12459         setupall
12460 }
12461
12462 test_802a() {
12463         [[ $mds1_FSTYPE = zfs ]] || skip "ZFS specific test"
12464         [[ $MDS1_VERSION -lt $(version_code 2.9.55) ]] ||
12465         [[ $OST1_VERSION -lt $(version_code 2.9.55) ]] &&
12466                 skip "Need server version at least 2.9.55"
12467
12468         [[ $ENABLE_QUOTA ]] && skip "Quota enabled for read-only test"
12469
12470         # Reset before starting
12471         stopall
12472         setupall
12473
12474         mkdir $DIR/$tdir || error "(1) fail to mkdir"
12475
12476         cp $LUSTRE/tests/test-framework.sh $DIR/$tdir/ ||
12477                 error "(2) Fail to copy"
12478
12479         stack_trap cleanup_802a EXIT
12480
12481         # sync by force before remount as readonly
12482         sync; sync_all_data; sleep 3; sync_all_data
12483
12484         stopall
12485
12486         MGS_MOUNT_OPTS=$(csa_add "$MGS_MOUNT_OPTS" -o rdonly_dev)
12487         MDS_MOUNT_OPTS=$(csa_add "$MDS_MOUNT_OPTS" -o rdonly_dev)
12488         OST_MOUNT_OPTS=$(csa_add "$OST_MOUNT_OPTS" -o rdonly_dev)
12489
12490         echo "Mount the server as read only"
12491         setupall server_only || error "(3) Fail to start servers"
12492
12493         echo "Mount client without ro should fail"
12494         mount_client $MOUNT &&
12495                 error "(4) Mount client without 'ro' should fail"
12496
12497         echo "Mount client with ro should succeed"
12498         MOUNT_OPTS=$(csa_add "$MOUNT_OPTS" -o ro)
12499         mount_client $MOUNT ||
12500                 error "(5) Mount client with 'ro' should succeed"
12501
12502         echo "Modify should be refused"
12503         touch $DIR/$tdir/guard && error "(6) Touch should fail under ro mode"
12504
12505         echo "Read should be allowed"
12506         diff $LUSTRE/tests/test-framework.sh $DIR/$tdir/test-framework.sh ||
12507                 error "(7) Read should succeed under ro mode"
12508 }
12509 run_test 802a "simulate readonly device"
12510
12511 if ! combined_mgs_mds ; then
12512         stop mgs
12513 fi
12514
12515 cleanup_gss
12516
12517 # restore the values of MDSSIZE and OSTSIZE
12518 MDSSIZE=$STORED_MDSSIZE
12519 OSTSIZE=$STORED_OSTSIZE
12520 reformat
12521
12522 complete_test $SECONDS
12523 check_and_cleanup_lustre
12524 exit_status