Whamcloud - gitweb
LU-6609 test: wait for import state FULL
[fs/lustre-release.git] / lustre / tests / test-framework.sh
index be82fec..509041d 100755 (executable)
@@ -250,6 +250,7 @@ init_test_env() {
        export SGPDDSURVEY=${SGPDDSURVEY:-"$LUSTRE/../lustre-iokit/sgpdd-survey/sgpdd-survey")}
        [ ! -f "$SGPDDSURVEY" ] && export SGPDDSURVEY=$(which sgpdd-survey)
        export MCREATE=${MCREATE:-mcreate}
+       export MULTIOP=${MULTIOP:-multiop}
        # Ubuntu, at least, has a truncate command in /usr/bin
        # so fully path our truncate command.
        export TRUNCATE=${TRUNCATE:-$LUSTRE/tests/truncate}
@@ -4128,12 +4129,16 @@ mountcli() {
                [ "$arg1" = "server_only" ] && return
        fi
        mount_client $MOUNT
-       [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT
+       if [ -n "$CLIENTS" ]; then
+               zconf_mount_clients $CLIENTS $MOUNT
+       fi
        clients_up
 
        if [ "$MOUNT_2" ]; then
                mount_client $MOUNT2
-               [ -n "$CLIENTS" ] && zconf_mount_clients $CLIENTS $MOUNT2
+               if [ -n "$CLIENTS" ]; then
+                       zconf_mount_clients $CLIENTS $MOUNT2
+               fi
        fi
 }
 
@@ -4870,17 +4875,19 @@ wait_for_function () {
 }
 
 check_network() {
-    local host=$1
-    local max=$2
-    local sleep=${3:-5}
+       local host=$1
+       local max=$2
+       local sleep=${3:-5}
 
-    echo `date +"%H:%M:%S (%s)"` waiting for $host network $max secs ...
-    if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
-        echo "Network not available!"
-        exit 1
-    fi
+       [ "$host" = "$HOSTNAME" ] && return 0
 
-    echo `date +"%H:%M:%S (%s)"` network interface is UP
+       echo "$(date +'%H:%M:%S (%s)') waiting for $host network $max secs ..."
+       if ! wait_for_function --quiet "ping -c 1 -w 3 $host" $max $sleep ; then
+               echo "Network not available!"
+               exit 1
+       fi
+
+       echo "$(date +'%H:%M:%S (%s)') network interface is UP"
 }
 
 no_dsh() {
@@ -5286,6 +5293,29 @@ report_error() {
 # Test interface
 ##################################
 
+# usage: stack_trap arg sigspec
+#
+# stack_trap() behaves like bash's built-in trap, except that it "stacks" the
+# command ``arg`` on top of previously defined commands for ``sigspec`` instead
+# of overwriting them.
+# stacked traps are executed in reverse order of their registration
+#
+# arg and sigspec have the same meaning as in man (1) trap
+stack_trap()
+{
+       local arg="$1"
+       local sigspec="$2"
+
+       local cmd="$(trap -p $sigspec)"
+
+       cmd="${cmd#trap -- \'}"
+       cmd="${cmd%\'*}"
+       [ -n "$cmd" ] && cmd="; $cmd"
+       cmd="${arg}$cmd"
+
+       trap "$cmd" $sigspec
+}
+
 error_noexit() {
        report_error "$@"
 }
@@ -6332,7 +6362,7 @@ convert_facet2label() {
 }
 
 get_clientosc_proc_path() {
-       echo "${1}-osc-*"
+       echo "${1}-osc-ffff*"
 }
 
 # If the 2.0 MDS was mounted on 1.8 device, then the OSC and LOV names
@@ -6357,10 +6387,7 @@ get_mdtosc_proc_path() {
        local mdt_label=$(convert_facet2label $mds_facet)
        local mdt_index=$(echo $mdt_label | sed -e 's/^.*-//')
 
-       if [ $(lustre_version_code $mds_facet) -le $(version_code 1.8.0) ] ||
-          mds_on_old_device $mds_facet; then
-               echo "${ost_label}-osc"
-       elif [[ $ost_label = *OST* ]]; then
+       if [[ $ost_label = *OST* ]]; then
                echo "${ost_label}-osc-${mdt_index}"
        else
                echo "${ost_label}-osp-${mdt_index}"
@@ -8397,3 +8424,65 @@ get_layout_param()
        local param=$($LFS getstripe -d $1 | parse_layout_param)
        echo "$param"
 }
+
+lfsck_verify_pfid()
+{
+       local f
+       local rc=0
+
+       # Cancel locks before setting lfsck_verify_pfid so that errors are more
+        # controllable
+       cancel_lru_locks mdc
+       cancel_lru_locks osc
+        
+       # make sure PFID is set correctly for files
+       do_nodes $(comma_list $(osts_nodes)) \
+              "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=1"
+
+       for f in "$@"; do
+               cat $f &> /dev/nullA ||
+                       { rc=$?; echo "verify $f failed"; break; }
+       done
+
+       do_nodes $(comma_list $(osts_nodes)) \
+              "$LCTL set_param -n obdfilter.${FSNAME}-OST*.lfsck_verify_pfid=0"
+       return $rc
+}
+
+# check that clients "oscs" was evicted after "before"
+check_clients_evicted() {
+       local before=$1
+       shift
+       local oscs=${@}
+       local osc
+       local rc=0
+
+       for osc in $oscs; do
+               ((rc++))
+               echo "Check state for $osc"
+               local evicted=$(do_facet client $LCTL get_param osc.$osc.state |
+                       tail -n 3 | awk -F"[ [,]" \
+                       '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
+               if (($? == 0)) && (($evicted > $before)); then
+                       echo "$osc is evicted at $evicted"
+                       ((rc--))
+               fi
+       done
+
+       [ $rc -eq 0 ] || error "client not evicted from OST"
+}
+
+# check that clients OSCS current_state is FULL
+check_clients_full() {
+       local timeout=$1
+       shift
+       local oscs=${@}
+
+       for osc in $oscs; do
+               wait_update_facet client \
+                       "lctl get_param -n osc.$osc.state |
+                       grep 'current_state: FULL'" \
+                       "current_state: FULL" $timeout
+               [ $? -eq 0 ] || error "$osc state is not FULL"
+       done
+}