Whamcloud - gitweb
LU-13705 utils: improve llstat/llobdstat usability
[fs/lustre-release.git] / lustre / tests / sanity.sh
index 8a58ac8..737e16d 100755 (executable)
@@ -3954,63 +3954,57 @@ test_33c() {
        local write_bytes
        local all_zeros
 
-       all_zeros=:
-       rm -fr $DIR/$tdir
+       all_zeros=true
        test_mkdir $DIR/$tdir
        # Read: 0, Write: 4, create/destroy: 2/0, stat: 1, punch: 0
 
-        sync
-        for ostnum in $(seq $OSTCOUNT); do
-                # test-framework's OST numbering is one-based, while Lustre's
-                # is zero-based
-                ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
-                # Parsing llobdstat's output sucks; we could grep the /proc
-                # path, but that's likely to not be as portable as using the
-                # llobdstat utility.  So we parse lctl output instead.
-                write_bytes=$(do_facet ost$ostnum lctl get_param -n \
-                        obdfilter/$ostname/stats |
-                        awk '/^write_bytes/ {print $7}' )
-                echo "baseline_write_bytes@$OSTnum/$ostname=$write_bytes"
-                if (( ${write_bytes:-0} > 0 ))
-                then
-                        all_zeros=false
-                        break;
-                fi
-        done
+       sync
+       for ostnum in $(seq $OSTCOUNT); do
+               # test-framework's OST numbering is one-based, while Lustre's
+               # is zero-based
+               ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
+               # check if at least some write_bytes stats are counted
+               write_bytes=$(do_facet ost$ostnum lctl get_param -n \
+                             obdfilter.$ostname.stats |
+                             awk '/^write_bytes/ {print $7}' )
+               echo "baseline_write_bytes@ost$ostnum/$ostname=$write_bytes"
+               if (( ${write_bytes:-0} > 0 )); then
+                       all_zeros=false
+                       break
+               fi
+       done
 
-        $all_zeros || return 0
+       $all_zeros || return 0
 
        # Write four bytes
        echo foo > $DIR/$tdir/bar
        # Really write them
        sync
 
-        # Total up write_bytes after writing.  We'd better find non-zeros.
-        for ostnum in $(seq $OSTCOUNT); do
-                ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
-                write_bytes=$(do_facet ost$ostnum lctl get_param -n \
-                        obdfilter/$ostname/stats |
-                        awk '/^write_bytes/ {print $7}' )
-                echo "write_bytes@$OSTnum/$ostname=$write_bytes"
-                if (( ${write_bytes:-0} > 0 ))
-                then
-                        all_zeros=false
-                        break;
-                fi
-        done
+       # Total up write_bytes after writing.  We'd better find non-zeros.
+       for ostnum in $(seq $OSTCOUNT); do
+               ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
+               write_bytes=$(do_facet ost$ostnum lctl get_param -n \
+                             obdfilter/$ostname/stats |
+                             awk '/^write_bytes/ {print $7}' )
+               echo "write_bytes@ost$ostnum/$ostname=$write_bytes"
+               if (( ${write_bytes:-0} > 0 )); then
+                       all_zeros=false
+                       break
+               fi
+       done
 
-        if $all_zeros
-        then
-                for ostnum in $(seq $OSTCOUNT); do
-                        ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
-                        echo "Check that write_bytes is present in obdfilter/*/stats:"
-                        do_facet ost$ostnum lctl get_param -n \
-                                obdfilter/$ostname/stats
-                done
-                error "OST not keeping write_bytes stats (b22312)"
-        fi
+       if $all_zeros; then
+               for ostnum in $(seq $OSTCOUNT); do
+                       ostname=$(printf "$FSNAME-OST%.4x" $((ostnum - 1)))
+                       echo "Check write_bytes is in obdfilter.*.stats:"
+                       do_facet ost$ostnum lctl get_param -n \
+                               obdfilter.$ostname.stats
+               done
+               error "OST not keeping write_bytes stats (b=22312)"
+       fi
 }
-run_test 33c "test llobdstat and write_bytes"
+run_test 33c "test write_bytes stats"
 
 test_33d() {
        [[ $MDSCOUNT -lt 2 ]] && skip_env "needs >= 2 MDTs"
@@ -9635,18 +9629,9 @@ run_test 100 "check local port using privileged port ==========="
 
 function get_named_value()
 {
-    local tag
-
-    tag=$1
-    while read ;do
-        line=$REPLY
-        case $line in
-        $tag*)
-            echo $line | sed "s/^$tag[ ]*//"
-            break
-            ;;
-        esac
-    done
+    local tag=$1
+
+    grep -w "$tag" | sed "s/^$tag  *\([0-9]*\)  *.*/\1/"
 }
 
 export CACHE_MAX=$($LCTL get_param -n llite.*.max_cached_mb |
@@ -9665,10 +9650,10 @@ test_101a() {
        local nreads=10000
        local cache_limit=32
 
-       $LCTL set_param -n osc.*-osc*.rpc_stats 0
+       $LCTL set_param -n osc.*-osc*.rpc_stats=0
        trap cleanup_101a EXIT
-       $LCTL set_param -n llite.*.read_ahead_stats 0
-       $LCTL set_param -n llite.*.max_cached_mb $cache_limit
+       $LCTL set_param -n llite.*.read_ahead_stats=0
+       $LCTL set_param -n llite.*.max_cached_mb=$cache_limit
 
        #
        # randomly read 10000 of 64K chunks from file 3x 32MB in size
@@ -9678,7 +9663,7 @@ test_101a() {
 
        discard=0
        for s in $($LCTL get_param -n llite.*.read_ahead_stats |
-               get_named_value 'read but discarded' | cut -d" " -f1); do
+                  get_named_value 'read.but.discarded'); do
                        discard=$(($discard + $s))
        done
        cleanup_101a
@@ -9739,8 +9724,7 @@ ra_check_101() {
        local discard_limit=$((((STRIDE_LENGTH - 1)*3/(STRIDE_LENGTH*OSTCOUNT))* \
                             (STRIDE_LENGTH*OSTCOUNT - STRIDE_LENGTH)))
        DISCARD=$($LCTL get_param -n llite.*.read_ahead_stats |
-                       get_named_value 'read but discarded' |
-                       cut -d" " -f1 | calc_total)
+                 get_named_value 'read.but.discarded' | calc_total)
        if [[ $DISCARD -gt $discard_limit ]]; then
                $LCTL get_param llite.*.read_ahead_stats
                error "Too many ($DISCARD) discarded pages with size (${READ_SIZE})"
@@ -9773,7 +9757,7 @@ test_101b() {
                local READ_COUNT=$((STRIPE_SIZE/BSIZE))
                local STRIDE_LENGTH=$((STRIDE_SIZE/BSIZE))
                local OFFSET=$((STRIPE_SIZE/BSIZE*(OSTCOUNT - 1)))
-               $LCTL set_param -n llite.*.read_ahead_stats 0
+               $LCTL set_param -n llite.*.read_ahead_stats=0
                $READS -f $DIR/$tfile  -l $STRIDE_LENGTH -o $OFFSET \
                              -s $FILE_LENGTH -b $STRIPE_SIZE -a $READ_COUNT -n $ITERATION
                cancel_lru_locks osc
@@ -9796,7 +9780,7 @@ test_101c() {
        setup_test101bc $STRIPE_SIZE $FILE_LENGTH
 
        cancel_lru_locks osc
-       $LCTL set_param osc.*.rpc_stats 0
+       $LCTL set_param osc.*.rpc_stats=0
        $READS -f $DIR/$tfile -s$FILE_LENGTH -b$rsize -n$nreads -t 180
        $LCTL get_param osc.*.rpc_stats
        for osc_rpc_stats in $($LCTL get_param -N osc.*.rpc_stats); do
@@ -9819,7 +9803,7 @@ test_101c() {
        cleanup_test101bc
        true
 }
-run_test 101c "check stripe_size aligned read-ahead ================="
+run_test 101c "check stripe_size aligned read-ahead"
 
 test_101d() {
        [ $PARALLEL == "yes" ] && skip "skip parallel run"
@@ -9842,7 +9826,7 @@ test_101d() {
        echo Disable read-ahead
        local old_RA=$($LCTL get_param -n llite.*.max_read_ahead_mb | head -n 1)
        $LCTL set_param -n llite.*.max_read_ahead_mb=0
-       stack_trap "$LCTL set_param -n llite.*.max_read_ahead_mb $old_RA" EXIT
+       stack_trap "$LCTL set_param -n llite.*.max_read_ahead_mb=$old_RA" EXIT
        $LCTL get_param -n llite.*.max_read_ahead_mb
 
        echo "Reading the test file $file with read-ahead disabled"
@@ -9895,14 +9879,14 @@ test_101e() {
        cancel_lru_locks $OSC
 
        echo "Reset readahead stats"
-       $LCTL set_param -n llite.*.read_ahead_stats 0
+       $LCTL set_param -n llite.*.read_ahead_stats=0
 
        for ((i = 0; i < $count; i++)); do
                dd if=$file.$i of=/dev/null bs=$bsize count=$size_KB 2>/dev/null
        done
 
        local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
-                    get_named_value 'misses' | cut -d" " -f1 | calc_total)
+                    get_named_value 'misses' | calc_total)
 
        for ((i = 0; i < $count; i++)); do
                rm -rf $file.$i 2>/dev/null
@@ -9927,7 +9911,7 @@ test_101f() {
        cancel_lru_locks osc
 
        echo Reset readahead stats
-       $LCTL set_param -n llite.*.read_ahead_stats 0
+       $LCTL set_param -n llite.*.read_ahead_stats=0
 
        echo mmap read the file with small block size
        iozone -i 1 -u 1 -l 1 -+n -r 32k -s 128m -B -f $DIR/$tfile \
@@ -9936,7 +9920,7 @@ test_101f() {
        echo checking missing pages
        $LCTL get_param llite.*.read_ahead_stats
        local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
-                       get_named_value 'misses' | cut -d" " -f1 | calc_total)
+                       get_named_value 'misses' | calc_total)
 
        $LCTL set_param debug="$old_debug"
        [ $miss -lt 3 ] || error "misses too much pages ('$miss')!"
@@ -10041,7 +10025,7 @@ test_101h() {
        echo "Read 10M of data but cross 64M bundary"
        dd if=$DIR/$tfile of=/dev/null bs=10M skip=6 count=1
        local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
-                       get_named_value 'misses' | cut -d" " -f1 | calc_total)
+                    get_named_value 'misses' | calc_total)
        [ $miss -eq 1 ] || error "expected miss 1 but got $miss"
        rm -f $p $DIR/$tfile
 }
@@ -10089,8 +10073,7 @@ test_101j() {
                local count=$(($file_size / $blk))
                dd if=$DIR/$tfile bs=$blk count=$count of=/dev/null
                local miss=$($LCTL get_param -n llite.*.read_ahead_stats |
-                            get_named_value 'failed to fast read' |
-                            cut -d" " -f1 | calc_total)
+                            get_named_value 'failed.to.fast.read' | calc_total)
                $LCTL get_param -n llite.*.read_ahead_stats
                [ $miss -eq $count ] || error "expected $count got $miss"
        done