Whamcloud - gitweb
LU-7121 tests: Extra items shown in the stack trace in t-f
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index 57d4f24..6c309d1 100755 (executable)
@@ -817,7 +817,7 @@ facet_type() {
 facet_number() {
        local facet=$1
 
-       if [ $facet == mgs ]; then
+       if [ $facet == mgs ] || [ $facet == client ]; then
                return 1
        fi
 
@@ -1116,7 +1116,7 @@ get_osd_param() {
        local name=$3
 
        do_nodes $nodes "$LCTL get_param -n obdfilter.$device.$name \
-               osd-*.$device.$name 2>&1" | grep -v 'Found no match'
+               osd-*.$device.$name 2>&1" | grep -v 'error:'
 }
 
 set_osd_param() {
@@ -1126,7 +1126,7 @@ set_osd_param() {
        local value=$4
 
        do_nodes $nodes "$LCTL set_param -n obdfilter.$device.$name=$value \
-               osd-*.$device.$name=$value 2>&1" | grep -v 'Found no match'
+               osd-*.$device.$name=$value 2>&1" | grep -v 'error:'
 }
 
 set_debug_size () {
@@ -1223,6 +1223,8 @@ mount_facet() {
        local opt=${facet}_opt
        local mntpt=$(facet_mntpt $facet)
        local opts="${!opt} $@"
+       local fstype=$(facet_fstype $facet)
+       local devicelabel
 
        module_loaded lustre || load_modules
 
@@ -1236,6 +1238,16 @@ mount_facet() {
                import_zpool $facet || return ${PIPESTATUS[0]}
        fi
 
+       case $fstype in
+       ldiskfs)
+               devicelabel=$(do_facet ${facet} "$E2LABEL ${!dev}");;
+       zfs)
+               devicelabel=$(do_facet ${facet} "$ZFS get -H -o value \
+                                               lustre:svname ${!dev}");;
+       *)
+               error "unknown fstype!";;
+       esac
+
        echo "Starting ${facet}: $opts ${!dev} $mntpt"
        # for testing LU-482 error handling in mount_facets() and test_0a()
        if [ -f $TMP/test-lu482-trigger ]; then
@@ -1261,7 +1273,6 @@ mount_facet() {
        if [[ $opts =~ .*nosvc.* ]]; then
                echo "Start ${!dev} without service"
        else
-               local fstype=$(facet_fstype $facet)
 
                case $fstype in
                ldiskfs)
@@ -1279,6 +1290,12 @@ mount_facet() {
                esac
        fi
 
+       # commit the device label change to disk
+       if [[ $devicelabel =~ (:[a-zA-Z]{3}[0-9]{4}) ]]; then
+               do_facet $facet "sync; sync; sync"
+       fi
+
+
        label=$(devicelabel ${facet} ${!dev})
        [ -z "$label" ] && echo no label for ${!dev} && exit 1
        eval export ${facet}_svc=${label}
@@ -1482,25 +1499,37 @@ setup_quota(){
 }
 
 zconf_mount() {
-    local client=$1
-    local mnt=$2
-    local opts=${3:-$MOUNT_OPTS}
-    opts=${opts:+-o $opts}
-    local flags=${4:-$MOUNT_FLAGS}
-
-    local device=$MGSNID:/$FSNAME
-    if [ -z "$mnt" -o -z "$FSNAME" ]; then
-        echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
-        exit 1
-    fi
-
-    echo "Starting client: $client: $flags $opts $device $mnt"
-    do_node $client mkdir -p $mnt
-    do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
+       local client=$1
+       local mnt=$2
+       local opts=${3:-$MOUNT_OPTS}
+       opts=${opts:+-o $opts}
+       local flags=${4:-$MOUNT_FLAGS}
+
+       local device=$MGSNID:/$FSNAME$FILESET
+       if [ -z "$mnt" -o -z "$FSNAME" ]; then
+               echo "Bad mount command: opt=$flags $opts dev=$device " \
+                    "mnt=$mnt"
+               exit 1
+       fi
+
+       echo "Starting client: $client: $flags $opts $device $mnt"
+       do_node $client mkdir -p $mnt
+       if [ -n "$FILESET" -a -z "$SKIP_FILESET" ];then
+               do_node $client $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
+                       $mnt || return 1
+               #disable FILESET if not supported
+               do_nodes $client lctl get_param -n \
+                       mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
+                               device=$MGSNID:/$FSNAME
+               do_node $client mkdir -p $mnt/$FILESET
+               do_node $client "! grep -q $mnt' ' /proc/mounts ||
+                       umount $mnt"
+       fi
+       do_node $client $MOUNT_CMD $flags $opts $device $mnt || return 1
+
+       set_default_debug_nodes $client
 
-    set_default_debug_nodes $client
-
-    return 0
+       return 0
 }
 
 zconf_umount() {
@@ -1590,21 +1619,35 @@ sanity_mount_check () {
 
 # mount clients if not mouted
 zconf_mount_clients() {
-    local clients=$1
-    local mnt=$2
-    local opts=${3:-$MOUNT_OPTS}
-    opts=${opts:+-o $opts}
-    local flags=${4:-$MOUNT_FLAGS}
-
-    local device=$MGSNID:/$FSNAME
-    if [ -z "$mnt" -o -z "$FSNAME" ]; then
-        echo Bad zconf mount command: opt=$flags $opts dev=$device mnt=$mnt
-        exit 1
-    fi
-
-    echo "Starting client $clients: $flags $opts $device $mnt"
-
-    do_nodes $clients "
+       local clients=$1
+       local mnt=$2
+       local opts=${3:-$MOUNT_OPTS}
+       opts=${opts:+-o $opts}
+       local flags=${4:-$MOUNT_FLAGS}
+
+       local device=$MGSNID:/$FSNAME$FILESET
+       if [ -z "$mnt" -o -z "$FSNAME" ]; then
+               echo "Bad conf mount command: opt=$flags $opts dev=$device " \
+                    "mnt=$mnt"
+               exit 1
+       fi
+
+       echo "Starting client $clients: $flags $opts $device $mnt"
+       if [ -n "$FILESET" -a ! -n "$SKIP_FILESET" ]; then
+               do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
+                       umount $mnt"
+               do_nodes $clients $MOUNT_CMD $flags $opts $MGSNID:/$FSNAME \
+                       $mnt || return 1
+               #disable FILESET if not supported
+               do_nodes $clients lctl get_param -n \
+                       mdc.$FSNAME-MDT0000*.import | grep -q subtree ||
+                               device=$MGSNID:/$FSNAME
+               do_nodes $clients mkdir -p $mnt/$FILESET
+               do_nodes $clients "! grep -q $mnt' ' /proc/mounts ||
+                       umount $mnt"
+       fi
+
+       do_nodes $clients "
 running=\\\$(mount | grep -c $mnt' ');
 rc=0;
 if [ \\\$running -eq 0 ] ; then
@@ -1614,12 +1657,12 @@ if [ \\\$running -eq 0 ] ; then
 fi;
 exit \\\$rc" || return ${PIPESTATUS[0]}
 
-    echo "Started clients $clients: "
-    do_nodes $clients "mount | grep $mnt' '"
+       echo "Started clients $clients: "
+       do_nodes $clients "mount | grep $mnt' '"
 
-    set_default_debug_nodes $clients
+       set_default_debug_nodes $clients
 
-    return 0
+       return 0
 }
 
 zconf_umount_clients() {
@@ -4642,20 +4685,17 @@ stop_full_debug_logging() {
 
 # prints bash call stack
 print_stack_trace() {
+       local skip=${1:-1}
        echo "  Trace dump:"
-       for (( i=1; i < ${#BASH_LINENO[*]} ; i++ )) ; do
-               local s=${BASH_SOURCE[$i]}
-               local l=${BASH_LINENO[$i-1]}
-               local f=${FUNCNAME[$i]}
-               echo "  = $s:$l:$f()"
+       for (( i=$skip; i < ${#BASH_LINENO[*]} ; i++ )) ; do
+               local src=${BASH_SOURCE[$i]}
+               local lineno=${BASH_LINENO[$i-1]}
+               local funcname=${FUNCNAME[$i]}
+               echo "  = $src:$lineno:$funcname()"
        done
 }
 
-##################################
-# Test interface
-##################################
-
-error_noexit() {
+report_error() {
        local TYPE=${TYPE:-"FAIL"}
 
        local dump=true
@@ -4665,10 +4705,8 @@ error_noexit() {
                dump=false
        fi
 
-
        log " ${TESTSUITE} ${TESTNAME}: @@@@@@ ${TYPE}: $@ "
-       print_stack_trace >&2
-
+       (print_stack_trace 2) >&2
        mkdir -p $LOGDIR
        # We need to dump the logs on all nodes
        if $dump; then
@@ -4687,6 +4725,17 @@ error_noexit() {
                        echo "$@" > $LOGDIR/err
                fi
        fi
+
+       # cleanup the env for failed tests
+       reset_fail_loc
+}
+
+##################################
+# Test interface
+##################################
+
+error_noexit() {
+       report_error "$@"
 }
 
 exit_status () {
@@ -4698,12 +4747,13 @@ exit_status () {
 }
 
 error() {
-       error_noexit "$@"
+       report_error "$@"
        exit 1
 }
 
 error_exit() {
-       error "$@"
+       report_error "$@"
+       exit 1
 }
 
 # use only if we are ignoring failures for this test, bugno required.
@@ -4713,11 +4763,11 @@ error_exit() {
 error_ignore() {
        local TYPE="IGNORE ($1)"
        shift
-       error_noexit "$@"
+       report_error "$@"
 }
 
 error_and_remount() {
-       error_noexit "$@"
+       report_error "$@"
        remount_client $MOUNT
        exit 1
 }
@@ -4929,6 +4979,18 @@ banner() {
     log "$msg== $(date +"%H:%M:%S (%s)")"
 }
 
+check_dmesg_for_errors() {
+       local res
+       local errors="VFS: Busy inodes after unmount of\|\
+ldiskfs_check_descriptors: Checksum for group 0 failed\|\
+group descriptors corrupted"
+
+       res=$(do_nodes $(comma_list $(nodes_list)) "dmesg" | grep "$errors")
+       [ -z "$res" ] && return 0
+       echo "Kernel error detected: $res"
+       return 1
+}
+
 #
 # Run a single test function and cleanup after it.
 #
@@ -4944,12 +5006,17 @@ run_one() {
        local SAVE_UMASK=`umask`
        umask 0022
 
+       if ! grep -q $DIR /proc/mounts; then
+               $SETUP
+       fi
+
        banner "test $testnum: $message"
        test_${testnum} || error "test_$testnum failed with $?"
        cd $SAVE_PWD
        reset_fail_loc
        check_grant ${testnum} || error "check_grant $testnum failed with $?"
        check_catastrophe || error "LBUG/LASSERT detected"
+       check_dmesg_for_errors || error "Error in dmesg detected"
        if [ "$PARALLEL" != "yes" ]; then
                ps auxww | grep -v grep | grep -q multiop &&
                                        error "multiop still running"
@@ -4958,6 +5025,7 @@ run_one() {
        unset tdir
        unset tfile
        umask $SAVE_UMASK
+       $CLEANUP
        return 0
 }
 
@@ -6070,19 +6138,21 @@ create_pool() {
 }
 
 add_pool_to_list () {
-    local fsname=${1%%.*}
-    local poolname=${1##$fsname.}
+       local fsname=${1%%.*}
+       local poolname=${1##$fsname.}
 
-    local listvar=${fsname}_CREATED_POOLS
-    eval export ${listvar}=$(expand_list ${!listvar} $poolname)
+       local listvar=${fsname}_CREATED_POOLS
+       local temp=${listvar}=$(expand_list ${!listvar} $poolname)
+       eval export $temp
 }
 
 remove_pool_from_list () {
-    local fsname=${1%%.*}
-    local poolname=${1##$fsname.}
+       local fsname=${1%%.*}
+       local poolname=${1##$fsname.}
 
-    local listvar=${fsname}_CREATED_POOLS
-    eval export ${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
+       local listvar=${fsname}_CREATED_POOLS
+       local temp=${listvar}=$(exclude_items_from_list ${!listvar} $poolname)
+       eval export $temp
 }
 
 destroy_pool_int() {
@@ -6219,6 +6289,31 @@ max_recovery_time() {
        echo -n $service_time
 }
 
+recovery_time_min() {
+       local connection_switch_min=5
+       local connection_switch_inc=5
+       local connection_switch_max
+       local reconnect_delay_max
+       local initial_connect_timeout
+       local max
+       local timout_20
+
+       #connection_switch_max=min(50, max($connection_switch_min,$TIMEOUT)
+       (($connection_switch_min > $TIMEOUT)) &&
+               max=$connection_switch_min || max=$TIMEOUT
+       (($max < 50)) && connection_switch_max=$max || connection_switch_max=50
+
+       #initial_connect_timeout = max(connection_switch_min, obd_timeout/20)
+       timeout_20=$((TIMEOUT/20))
+       (($connection_switch_min > $timeout_20)) &&
+               initial_connect_timeout=$connection_switch_min ||
+               initial_connect_timeout=$timeout_20
+
+       reconnect_delay_max=$((connection_switch_max + connection_switch_inc + \
+                              initial_connect_timeout))
+       echo $((2 * reconnect_delay_max))
+}
+
 get_clients_mount_count () {
     local clients=${CLIENTS:-`hostname`}