+print_jbd_stat () {
+ local dev
+ local mdts=$(get_facets MDS)
+ local varcvs
+ local mds
+
+ local stat=0
+ for mds in ${mdts//,/ }; do
+ varsvc=${mds}_svc
+ dev=$(basename $(do_facet $mds lctl get_param -n osd.${!varsvc}.mntdev))
+ val=$(do_facet $mds cat /proc/fs/jbd/$dev/info | head -1 | cut -d" " -f1)
+ stat=$(( stat + val))
+ done
+ echo $stat
+}
+
+# commit on sharing tests
+test_33a() {
+ remote_mds_nodsh && skip "remote MDS with nodsh" && return
+
+ [ -n "$CLIENTS" ] || { skip "Need two or more clients" && return 0; }
+ [ $CLIENTCOUNT -ge 2 ] || \
+ { skip "Need two or more clients, have $CLIENTCOUNT" && return 0; }
+
+ zconf_mount_clients $CLIENT1,$CLIENT2 $DIR1
+ zconf_mount_clients $CLIENT1,$CLIENT2 $DIR2
+
+ local nfiles=${TEST33_NFILES:-10000}
+ local param_file=$TMP/$tfile-params
+
+ save_lustre_params $(comma_list $(mdts_nodes)) "mdt.*.commit_on_sharing" > $param_file
+
+ local COS
+ local jbdold
+ local jbdnew
+ local jbd
+
+ for COS in 0 1; do
+ do_facet $SINGLEMDS lctl set_param mdt.*.commit_on_sharing=$COS
+ avgjbd=0
+ avgtime=0
+ for i in 1 2 3; do
+ do_nodes $CLIENT1,$CLIENT2 "mkdir -p $DIR1/$tdir-\\\$(hostname)-$i"
+
+ jbdold=$(print_jbd_stat)
+ echo "=== START createmany old: $jbdold transaction"
+ local elapsed=$(do_and_time "do_nodes $CLIENT1,$CLIENT2 createmany -o $DIR1/$tdir-\\\$(hostname)-$i/f- -r $DIR2/$tdir-\\\$(hostname)-$i/f- $nfiles > /dev/null 2>&1")
+ jbdnew=$(print_jbd_stat)
+ jbd=$(( jbdnew - jbdold ))
+ echo "=== END createmany new: $jbdnew transaction : $jbd transactions nfiles $nfiles time $ELAPSED COS=$COS"
+ avgjbd=$(( avgjbd + jbd ))
+ avgtime=$(( avgtime + elapsed ))
+ done
+ eval cos${COS}_jbd=$((avgjbd / 3))
+ eval cos${COS}_time=$((avgtime / 3))
+ done
+
+ echo "COS=0 transactions (avg): $cos0_jbd time (avg): $cos0_time"
+ echo "COS=1 transactions (avg): $cos1_jbd time (avg): $cos1_time"
+ [ "$cos0_jbd" != 0 ] && echo "COS=1 vs COS=0 jbd: $((((cos1_jbd/cos0_jbd - 1)) * 100 )) %"
+ [ "$cos0_time" != 0 ] && echo "COS=1 vs COS=0 time: $((((cos1_time/cos0_time - 1)) * 100 )) %"
+
+ restore_lustre_params < $param_file
+ rm -f $param_file
+ return 0
+}
+run_test 33a "commit on sharing, cross crete/delete, 2 clients, benchmark"
+
+# End commit on sharing tests
+
+test_34() { #16129
+ local OPER
+ local lock_in
+ local lock_out
+ for OPER in notimeout timeout ; do
+ rm $DIR1/$tfile 2>/dev/null
+ lock_in=$(do_nodes $(osts_nodes) "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
+ if [ $OPER == "timeout" ] ; then
+ for j in `seq $OSTCOUNT`; do
+ #define OBD_FAIL_PTLRPC_HPREQ_TIMEOUT 0x511
+ do_facet ost$j lctl set_param fail_loc=0x511
+ done
+ echo lock should expire
+ else
+ for j in `seq $OSTCOUNT`; do
+ #define OBD_FAIL_PTLRPC_HPREQ_NOTIMEOUT 0x512
+ do_facet ost$j lctl set_param fail_loc=0x512
+ done
+ echo lock should not expire
+ fi
+ echo writing on client1
+ dd if=/dev/zero of=$DIR1/$tfile count=100 conv=notrunc > /dev/null 2>&1
+ sync &
+ echo reading on client2
+ dd of=/dev/null if=$DIR2/$tfile > /dev/null 2>&1
+ # wait for a lock timeout
+ sleep 4
+ lock_out=$(do_nodes $(osts_nodes) "lctl get_param -n ldlm.namespaces.filter-*.lock_timeouts" | calc_sum)
+ if [ $OPER == "timeout" ] ; then
+ if [ $lock_in == $lock_out ]; then
+ error "no lock timeout happened"
+ else
+ echo "success"
+ fi
+ else
+ if [ $lock_in != $lock_out ]; then
+ error "lock timeout happened"
+ else
+ echo "success"
+ fi
+ fi
+ done
+}
+run_test 34 "no lock timeout under IO"
+
+test_35() { # bug 17645
+ local generation=[]
+ local count=0
+ for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
+ g=$(awk '/generation/{print $2}' $imp/import)
+ generation[count]=$g
+ let count=count+1
+ done
+
+ mkdir -p $MOUNT1/$tfile
+ cancel_lru_locks mdc
+
+ # Let's initiate -EINTR situation by setting fail_loc and take
+ # write lock on same file from same client. This will not cause
+ # bl_ast yet as lock is already in local cache.
+#define OBD_FAIL_LDLM_INTR_CP_AST 0x317
+ do_facet client "lctl set_param fail_loc=0x80000317"
+ local timeout=`do_facet $SINGLEMDS lctl get_param -n timeout`
+ let timeout=timeout*3
+ local nr=0
+ while test $nr -lt 10; do
+ log "Race attempt $nr"
+ local blk1=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
+ test "x$blk1" = "x" && blk1=0
+ createmany -o $MOUNT2/$tfile/a 4000 &
+ pid1=$!
+ sleep 1
+
+ # Let's make conflict and bl_ast
+ ls -la $MOUNT1/$tfile > /dev/null &
+ pid2=$!
+
+ log "Wait for $pid1 $pid2 for $timeout sec..."
+ sleep $timeout
+ kill -9 $pid1 $pid2 > /dev/null 2>&1
+ wait
+ local blk2=`lctl get_param -n ldlm.services.ldlm_cbd.stats | awk '/ldlm_bl_callback/ {print $2}'`
+ test "x$blk2" = "x" && blk2=0
+ test $blk2 -gt $blk1 && break
+ rm -fr $MOUNT1/$tfile/*
+ cancel_lru_locks mdc
+ let nr=nr+1
+ done
+ do_facet client "lctl set_param fail_loc=0x0"
+ df -h $MOUNT1 $MOUNT2
+ count=0
+ for imp in /proc/fs/lustre/mdc/$FSNAME-MDT*-mdc-*; do
+ g=$(awk '/generation/{print $2}' $imp/import)
+ if ! test "$g" -eq "${generation[count]}"; then
+ error "Eviction happened on import $(basename $imp)"
+ fi
+ let count=count+1
+ done
+}
+run_test 35 "-EINTR cp_ast vs. bl_ast race does not evict client"
+
+test_36() { #bug 16417
+ local SIZE
+ local SIZE_B
+ local i
+
+ mkdir -p $DIR1/$tdir
+ $LFS setstripe -c -1 $DIR1/$tdir
+ i=0
+ SIZE=50
+ let SIZE_B=SIZE*1024*1024
+
+ while [ $i -le 10 ]; do
+ lctl mark "start test"
+ local before=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
+ dd if=/dev/zero of=$DIR1/$tdir/file000 bs=1M count=$SIZE
+ sync
+ sleep 1
+ local after_dd=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
+ multiop_bg_pause $DIR2/$tdir/file000 O_r${SIZE_B}c || return 3
+ read_pid=$!
+ rm -f $DIR1/$tdir/file000
+ kill -USR1 $read_pid
+ wait $read_pid
+ sleep 1
+ local after=$($LFS df | awk '{if ($1 ~/^filesystem/) {print $5; exit} }')
+ echo "*** cycle($i) *** before($before):after_dd($after_dd):after($after)"
+ # this free space! not used
+ if [ $after_dd -ge $after ]; then
+ error "space leaked"
+ return 1;
+ fi
+ let i=i+1
+ done
+}
+run_test 36 "handle ESTALE/open-unlink corectly"
+
+test_37() { # bug 18695
+ mkdir -p $DIR1/$tdir
+ multiop_bg_pause $DIR1/$tdir D_c || return 1
+ MULTIPID=$!
+ # create large directory (32kB seems enough from e2fsck, ~= 1000 files)
+ createmany -m $DIR2/$tdir/f 10000
+ # set mtime/atime backward
+ touch -t 198001010000 $DIR2/$tdir
+ kill -USR1 $MULTIPID
+ nr_files=`lfs find $DIR1/$tdir -type f | wc -l`
+ [ $nr_files -eq 10000 ] || error "$nr_files != 10000 truncated directory?"
+
+}
+run_test 37 "check i_size is not updated for directory on close (bug 18695) =============="
+