+test_83a() {
+ mkdir -p $DIR/$tdir
+ createmany -o $DIR/$tdir/$tfile- 10 || return 1
+#define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD 0x140
+ do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000140"
+ unlinkmany $DIR/$tdir/$tfile- 10 || return 2
+}
+run_test 83a "fail log_add during unlink recovery"
+
+test_83b() {
+ mkdir -p $DIR/$tdir
+ createmany -o $DIR/$tdir/$tfile- 10 || return 1
+ replay_barrier $SINGLEMDS
+ unlinkmany $DIR/$tdir/$tfile- 10 || return 2
+#define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD 0x140
+ do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000140"
+ fail $SINGLEMDS
+}
+run_test 83b "fail log_add during unlink recovery"
+
+test_84a() {
+#define OBD_FAIL_MDS_OPEN_WAIT_CREATE 0x144
+ do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000144"
+ createmany -o $DIR/$tfile- 1 &
+ PID=$!
+ mds_evict_client
+ wait $PID
+ client_up || client_up || true # reconnect
+}
+run_test 84a "stale open during export disconnect"
+
+test_85a() { #bug 16774
+ lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
+
+ for i in `seq 100`; do
+ echo "tag-$i" > $DIR/$tfile-$i
+ grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
+ done
+
+ lov_id=`lctl dl | grep "clilov"`
+ addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
+ count=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
+ echo "before recovery: unused locks count = $count"
+
+ fail $SINGLEMDS
+
+ count2=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
+ echo "after recovery: unused locks count = $count2"
+
+ if [ $count2 -ge $count ]; then
+ error "unused locks are not canceled"
+ fi
+}
+run_test 85a "check the cancellation of unused locks during recovery(IBITS)"
+
+test_85b() { #bug 16774
+ lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
+
+ do_facet mgs $LCTL pool_new $FSNAME.$TESTNAME || return 1
+ do_facet mgs $LCTL pool_add $FSNAME.$TESTNAME $FSNAME-OST0000 || return 2
+
+ lfs setstripe -c 1 -p $FSNAME.$TESTNAME $DIR
+
+ for i in `seq 100`; do
+ dd if=/dev/urandom of=$DIR/$tfile-$i bs=4096 count=32 >/dev/null 2>&1
+ done
+
+ cancel_lru_locks osc
+
+ for i in `seq 100`; do
+ dd if=$DIR/$tfile-$i of=/dev/null bs=4096 count=32 >/dev/null 2>&1
+ done
+
+ lov_id=`lctl dl | grep "clilov"`
+ addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
+ count=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
+ echo "before recovery: unused locks count = $count"
+ [ $count != 0 ] || return 3
+
+ fail ost1
+
+ count2=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
+ echo "after recovery: unused locks count = $count2"
+
+ do_facet mgs $LCTL pool_remove $FSNAME.$TESTNAME $FSNAME-OST0000 || return 4
+ do_facet mgs $LCTL pool_destroy $FSNAME.$TESTNAME || return 5
+
+ if [ $count2 -ge $count ]; then
+ error "unused locks are not canceled"
+ fi
+}
+run_test 85b "check the cancellation of unused locks during recovery(EXTENT)"
+
+test_86() {
+ local clients=${CLIENTS:-$HOSTNAME}
+
+ zconf_umount_clients $clients $MOUNT
+ do_facet $SINGLEMDS lctl set_param mdt.${FSNAME}-MDT*.exports.clear=0
+ remount_facet $SINGLEMDS
+ zconf_mount_clients $clients $MOUNT
+}
+run_test 86 "umount server after clear nid_stats should not hit LBUG"
+
+test_87() {
+ do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
+
+ replay_barrier ost1
+ lfs setstripe -i 0 -c 1 $DIR/$tfile
+ dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
+ cksum=`md5sum $DIR/$tfile | awk '{print $1}'`
+ cancel_lru_locks osc
+ fail ost1
+ dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
+ cksum2=`md5sum $DIR/$tfile | awk '{print $1}'`
+ if [ $cksum != $cksum2 ] ; then
+ error "New checksum $cksum2 does not match original $cksum"
+ fi
+}
+run_test 87 "write replay"
+
+test_87b() {
+ do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
+
+ replay_barrier ost1
+ lfs setstripe -i 0 -c 1 $DIR/$tfile
+ dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
+ sleep 1 # Give it a chance to flush dirty data
+ echo TESTTEST | dd of=$DIR/$tfile bs=1 count=8 seek=64
+ cksum=`md5sum $DIR/$tfile | awk '{print $1}'`
+ cancel_lru_locks osc
+ fail ost1
+ dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
+ cksum2=`md5sum $DIR/$tfile | awk '{print $1}'`
+ if [ $cksum != $cksum2 ] ; then
+ error "New checksum $cksum2 does not match original $cksum"
+ fi
+}
+run_test 87b "write replay with changed data (checksum resend)"
+
+test_88() { #bug 17485
+ mkdir -p $DIR/$tdir
+ mkdir -p $TMP/$tdir
+
+ lfs setstripe $DIR/$tdir -o 0 -c 1 || error "setstripe"
+
+ replay_barrier ost1
+ replay_barrier $SINGLEMDS
+
+ # exhaust precreations on ost1
+ local OST=$(ostname_from_index 0)
+ local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $OST)
+ local last_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
+ local next_id=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
+ echo "before test: last_id = $last_id, next_id = $next_id"
+
+ echo "Creating to objid $last_id on ost $OST..."
+ createmany -o $DIR/$tdir/f-%d $next_id $((last_id - next_id + 2))
+
+ #create some files to use some uncommitted objids
+ last_id=$(($last_id + 1))
+ createmany -o $DIR/$tdir/f-%d $last_id 8
+
+ last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
+ next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
+ echo "before recovery: last_id = $last_id2, next_id = $next_id2"
+
+ # if test uses shutdown_facet && reboot_facet instead of facet_failover ()
+ # it has to take care about the affected facets, bug20407
+ local affected_mds1=$(affected_facets mds1)
+ local affected_ost1=$(affected_facets ost1)
+
+ shutdown_facet $SINGLEMDS
+ shutdown_facet ost1
+
+ reboot_facet $SINGLEMDS
+ change_active $affected_mds1
+ wait_for_facet $affected_mds1
+ mount_facets $affected_mds1 || error "Restart of mds failed"
+
+ reboot_facet ost1
+ change_active $affected_ost1
+ wait_for_facet $affected_ost1
+ mount_facets $affected_ost1 || error "Restart of ost1 failed"
+
+ clients_up
+
+ last_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_last_id)
+ next_id2=$(do_facet $SINGLEMDS lctl get_param -n osc.$mdtosc.prealloc_next_id)
+ echo "after recovery: last_id = $last_id2, next_id = $next_id2"
+
+ # create new files, which should use new objids, and ensure the orphan
+ # cleanup phase for ost1 is completed at the same time
+ for i in `seq 8`; do
+ file_id=$(($last_id + 10 + $i))
+ dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
+ done
+
+ # if the objids were not recreated, then "ls" will failed for -ENOENT
+ ls -l $DIR/$tdir/* || error "can't get the status of precreated files"
+
+ local file_id
+ # write into previously created files
+ for i in `seq 8`; do
+ file_id=$(($last_id + $i))
+ dd if=/dev/urandom of=$DIR/$tdir/f-$file_id bs=4096 count=128
+ cp -f $DIR/$tdir/f-$file_id $TMP/$tdir/
+ done
+
+ # compare the content
+ for i in `seq 8`; do
+ file_id=$(($last_id + $i))
+ cmp $TMP/$tdir/f-$file_id $DIR/$tdir/f-$file_id || error "the content" \
+ "of file is modified!"
+ done
+
+ rm -fr $TMP/$tdir
+}
+run_test 88 "MDS should not assign same objid to different files "
+
+test_89() {
+ cancel_lru_locks osc
+ mkdir -p $DIR/$tdir
+ rm -f $DIR/$tdir/$tfile
+ wait_mds_ost_sync
+ wait_destroy_complete
+ BLOCKS1=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
+ lfs setstripe -i 0 -c 1 $DIR/$tdir/$tfile
+ dd if=/dev/zero bs=1M count=10 of=$DIR/$tdir/$tfile
+ sync
+ stop ost1
+ facet_failover $SINGLEMDS
+ rm $DIR/$tdir/$tfile
+ umount $MOUNT
+ mount_facet ost1
+ zconf_mount $(hostname) $MOUNT
+ client_up || return 1
+ wait_mds_ost_sync
+ BLOCKS2=$(df -P $MOUNT | tail -n 1 | awk '{ print $3 }')
+ [ "$BLOCKS1" == "$BLOCKS2" ] || error $((BLOCKS2 - BLOCKS1)) blocks leaked
+}
+
+run_test 89 "no disk space leak on late ost connection"
+
+cleanup_90 () {
+ local facet=$1
+ trap 0
+ reboot_facet $facet
+ change_active $facet
+ wait_for_facet $facet
+ mount_facet $facet || error "Restart of $facet failed"
+ clients_up
+}
+
+test_90() { # bug 19494
+ local dir=$DIR/$tdir
+ local ostfail=$(get_random_entry $(get_facets OST))
+
+ if [[ $FAILURE_MODE = HARD ]]; then
+ local affected=$(affected_facets $ostfail);
+ if [[ "$affected" != $ostfail ]]; then
+ skip not functional with FAILURE_MODE=$FAILURE_MODE, affected: $affected
+ return 0
+ fi
+ fi
+
+ mkdir -p $dir
+
+ echo "Create the files"
+
+ # file "f${index}" striped over 1 OST
+ # file "all" striped over all OSTs
+
+ $LFS setstripe -c $OSTCOUNT $dir/all || error "setstripe failed to create $dir/all"
+
+ for (( i=0; i<$OSTCOUNT; i++ )); do
+ local f=$dir/f$i
+ $LFS setstripe -i $i -c 1 $f || error "setstripe failed to create $f"
+
+ # confirm that setstripe actually created the stripe on the requested OST
+ local uuid=$(ostuuid_from_index $i)
+ for file in f$i all; do
+ if [[ $dir/$file != $($LFS find --obd $uuid --name $file $dir) ]]; then
+ $LFS getstripe $dir/file
+ error wrong stripe: $file, uuid: $uuid
+ fi
+ done
+ done
+
+ # Before failing an OST, get its obd name and index
+ local varsvc=${ostfail}_svc
+ local obd=$(do_facet $ostfail lctl get_param -n obdfilter.${!varsvc}.uuid)
+ local index=${obd:(-6):1}
+
+ echo "Fail $ostfail $obd, display the list of affected files"
+ shutdown_facet $ostfail || return 2
+
+ trap "cleanup_90 $ostfail" EXIT INT
+ echo "General Query: lfs find $dir"
+ local list=$($LFS find $dir)
+ echo "$list"
+ for (( i=0; i<$OSTCOUNT; i++ )); do
+ list_member "$list" $dir/f$i || error_noexit "lfs find $dir: no file f$i"
+ done
+ list_member "$list" $dir/all || error_noexit "lfs find $dir: no file all"
+
+ # focus on the missing OST,
+ # we expect to see only two files affected: "f$(index)" and "all"
+
+ echo "Querying files on shutdown $ostfail: lfs find --obd $obd"
+ list=$($LFS find --obd $obd $dir)
+ echo "$list"
+ for file in all f$index; do
+ list_member "$list" $dir/$file ||
+ error_noexit "lfs find does not report the affected $obd for $file"
+ done
+
+ [[ $(echo $list | wc -w) -eq 2 ]] ||
+ error_noexit "lfs find reports the wrong list of affected files ${#list[@]}"
+
+ echo "Check getstripe: lfs getstripe -r --obd $obd"
+ list=$($LFS getstripe -r --obd $obd $dir)
+ echo "$list"
+ for file in all f$index; do
+ echo "$list" | grep $dir/$file ||
+ error_noexit "lfs getsripe does not report the affected $obd for $file"
+ done
+
+ cleanup_90 $ostfail
+}
+run_test 90 "lfs find identifies the missing striped file segments"
+
+complete $(basename $0) $SECONDS