Whamcloud - gitweb
LU-843 iokit: get_ec_devno returns trash
authorBruce Korb <bruce_korb@xyratex.com>
Mon, 28 Nov 2011 23:08:04 +0000 (15:08 -0800)
committerOleg Drokin <green@whamcloud.com>
Wed, 14 Dec 2011 20:30:18 +0000 (15:30 -0500)
Some commands leak output to stdout and get_ec_devno returns
its results via stdout.  Redirect fd 8 to stdout and redirect
stdout to stderr.  Echo final results to fd 8.  Since this
only works when run as a subshell, invoke "exit" instead of
"return" when done.

Inside create_objects() function, stdin is redirected for a
shell "while" command.  Though this is done in the current
environment (process) for current BASH, it is not required
and there is no committment that BASH will always behave
this way.  Instead, set fd 3 to be reading from that file
and read from fd 3 insted of stdin.

While there, also test for "is object id" lines and extract
values using shell constructs instead of fork-ed commands.

Also while there, ensure that "ERROR" is always printed on
every error exit.

Also while there, ensure that the libecho file comes from
the same directory as the obdfilter-survey script.

Reviewed-by: Alexey Lyashkov <alexey_lyashkov@xyratex.com>
Signed-off-by: Bruce Korb <bruce_korb@xyratex.com>
Change-Id: I50137c9ded816aac792aba4a0a79f59c28d16e01
Reviewed-on: http://review.whamcloud.com/1699
Tested-by: Hudson
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Tested-by: Maloo <whamcloud.maloo@gmail.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
lustre-iokit/obdfilter-survey/libecho
lustre-iokit/obdfilter-survey/obdfilter-survey

index 20cc11d..e12c853 100644 (file)
@@ -248,34 +248,38 @@ cleanup () {
 trap cleanup SIGHUP SIGINT SIGTERM
 
 # gets echoclient device number and attach it to the client UUID
-# 
+# Results are  returned by an echo followed by an exit
+# This must run in a subshell.
+#
 # parameter: 1. hostname
 #           2. client name, ex:- ns8:ECHO_ns8
 #           3. name of ost instances, ex:- lustre-OST0001 
 get_ec_devno () {
+    exec 8>&1 1>&2
     local host=$1
     local client_name="$2"
     local ost_name="$3"
     if [ -z "$client_name" ]; then
        if [ -z "$ost_name" ]; then
-           echo "client and ost name both null" 1>&2
-           return
+           echo "client and ost name both null"
+           exit 1
        fi
         client_name=${ost_name}_ecc
     fi
     ec=`get_devno $host echo_client $client_name`
     if [ -n "$ec" ]; then
-       echo $ec $client_name $client_name
-       return
+       echo $ec $client_name $client_name >&8
+       exit 0
     fi
     if [ -z "$ost_name" ]; then
-       echo "no echo client and ost_name not set, client: $client_name, host: $host" 1>&2
-       return
+       echo "no echo client and ost_name not set, client:" \
+            "$client_name, host: $host"
+       exit 1
     fi
     ost=`get_devno $host obdfilter $ost_name`
     if [ -z "$ost" ]; then
-       echo "OST $ost_name not setup" 1>&2
-       return
+       echo "OST $ost_name not setup"
+       exit 1
     fi
     client_name=${ost_name}_ecc
     remote_shell $host "$lctl <<EOF
@@ -284,10 +288,11 @@ get_ec_devno () {
 EOF"
     ec=`get_devno $host echo_client $client_name`
     if [ -z "$ec" ]; then
-       echo "Can't setup echo-client" 1>&2
-       return
+       echo "Can't setup echo-client"
+       exit 1
     fi
-    echo $ec $client_name 1
+    echo $ec $client_name 1 >&8
+    exit 0
 }
 
 # Create echo-clients using osc_names and osc_uuid
index f5e5476..4ebb3e6 100755 (executable)
@@ -36,7 +36,7 @@
 #  client systems on which this test runs.]
 
 # include library 
-source libecho
+source $(dirname $0)/libecho
 
 # The following variables can be set in the environment, or on the
 # command line
@@ -71,7 +71,7 @@ export LC_ALL=POSIX
 # End of variables
 
 # create a set of objects, check there are 'n' contiguous ones and
-# return the first or 'ERROR'
+# echo out the first or 'ERROR'
 # parameter: 1. hostname
 #           2. device number
 #           3. number of object to be created (specified by user)
@@ -86,36 +86,37 @@ create_objects () {
     prev=0
     count=0
     error=0
-    while read line; do
-        echo "$line" | grep -q 'is object id'
-        if [ $?  -ne 0 ]; then
-            continue
-        fi
-        if [ $first -eq 0 ]; then
-            first=$(echo $line | awk '{print $6}')
-            first=$(printf "%d" $first)
-            prev=$first
-            count=1
-        else
-            obj=$(echo $line | awk '{print $6}') 
-            obj=$(printf "%d" $obj) 
-            diff=$((obj - (prev+1))) 
-            if [ $diff -ne 0 ]; then 
-                error=1 
-            fi 
-            prev=$obj 
-            count=$((count+1)) 
-        fi 
-    done < $rfile 
+
+    # Count number of objects (lines containing " is object id "), and
+    # ensure that the objects numbers are sequential.
+    #
+    exec 3< $rfile
+    while read -u3 line; do
+        case "$line" in
+        ( *' is object id '* )
+            set -- $line
+            if test $(( count += 1 )) -gt 1 ; then
+                (( $6 != prev + 1 )) && error=1
+            else
+                first=$(( $6 + 0 ))
+            fi
+            prev=$6
+            ;;
+        esac
+    done
+    exec 3<&-
+
     if [ $nobj -ne $count ]; then 
         echo "ERROR: $nobj != $count" >&2 
         cat $rfile >&2 
         echo "ERROR" 
     elif [ $error -ne 0 ]; then 
-        echo "ERROR: non contiguous objs found" >&2 
+        echo "ERROR: non contiguous objs found" >&2
+        echo ERROR
     else 
         echo $first 
     fi
+    return $error
 }
 
 # destroys all objects created in create_objects routine