Whamcloud - gitweb
LU-14707 tests: Bashify scripts for Ubuntu et. al.
[fs/lustre-release.git] / lustre / tests / functions.sh
index 1bd6384..1807bb8 100644 (file)
@@ -51,7 +51,7 @@ lrepl() {
 EOF
 
     # Prompt escapes don't work in read -p, sadly.
-    prompt=":test_${testnum:-UNKNOWN}:$(uname -n):$(basename $PWD)% "
+    prompt=":${TESTNAME:-UNKNOWN}:$(uname -n):$(basename $PWD)% "
 
     # We use read -r to get close to a shell experience
     while read -e -r -p "$prompt" rawline; do
@@ -126,35 +126,35 @@ $msg"
 #
 # In the second usage the new value is appended to the old.
 setmodopts() {
-        local _append=false
+       local _append=false
 
-        if [ "$1" = -a ]; then
-            _append=true
-            shift
-        fi
+       if [ "$1" = -a ]; then
+               _append=true
+               shift
+       fi
 
-        local _var=MODOPTS_$1
-        local _newvalue=$2
-        local _savevar=$3
-        local _oldvalue
+       local _var=MODOPTS_$1
+       local _newvalue=$2
+       local _savevar=$3
+       local _oldvalue
 
-        # Dynamic naming of variables is a pain in bash.  In ksh93 we could
-        # write "nameref opts_var=${modname}_MODOPTS" then assign directly
-        # to opts_var.  Associative arrays would also help, alternatively.
-        # Alas, we're stuck with eval until all distros move to a more recent
-        # version of bash.  Fortunately we don't need to eval unset and export.
+       # Dynamic naming of variables is a pain in bash.  In ksh93 we could
+       # write "nameref opts_var=${modname}_MODOPTS" then assign directly
+       # to opts_var.  Associative arrays would also help, alternatively.
+       # Alas, we're stuck with eval until all distros move to a more recent
+       # version of bash.  Fortunately we don't need to eval unset and export.
 
-        if [ -z "$_newvalue" ]; then
-            unset $_var
-            return 0
-        fi
+       if [ -z "$_newvalue" ]; then
+               unset $_var
+               return 0
+       fi
 
-        _oldvalue=${!var}
-        $_append && _newvalue="$_oldvalue $_newvalue"
-        export $_var="$_newvalue"
-        echo setmodopts: ${_var}=${_newvalue}
+       _oldvalue=${!_var}
+       $_append && _newvalue="$_oldvalue $_newvalue"
+       export $_var="$_newvalue"
+       echo setmodopts: ${_var}=${_newvalue}
 
-        [ -n "$_savevar" ] && eval $_savevar=\""$_oldvalue"\"
+       [ -n "$_savevar" ] && eval $_savevar=\""$_oldvalue"\"
 }
 
 echoerr () { echo "$@" 1>&2 ; }
@@ -169,26 +169,26 @@ signaled() {
 }
 
 mpi_run () {
-    local mpirun="$MPIRUN $MPIRUN_OPTIONS --oversubscribe"
-    local command="$mpirun $@"
-    local mpilog=$TMP/mpi.log
-    local rc
-
-    if [ -n "$MPI_USER" -a "$MPI_USER" != root -a -n "$mpirun" ]; then
-        echo "+ chmod 0777 $MOUNT"
-        chmod 0777 $MOUNT
-        command="su $MPI_USER sh -c \"$command \""
-    fi
+       local mpirun="$MPIRUN $MPIRUN_OPTIONS"
+       local command="$mpirun $@"
+       local mpilog=$TMP/mpi.log
+       local rc
+
+       if [ -n "$MPI_USER" -a "$MPI_USER" != root -a -n "$mpirun" ]; then
+               echo "+ chmod 0777 $MOUNT"
+               chmod 0777 $MOUNT
+               command="su $MPI_USER bash -c \"$command \""
+       fi
 
-    ls -ald $MOUNT
-    echo "+ $command"
-    eval $command 2>&1 | tee $mpilog || true
+       ls -ald $MOUNT
+       echo "+ $command"
+       eval $command 2>&1 | tee $mpilog || true
 
-    rc=${PIPESTATUS[0]}
-    if [ $rc -eq 0 ] && grep -q "p4_error:" $mpilog ; then
-       rc=1
-    fi
-    return $rc
+       rc=${PIPESTATUS[0]}
+       if [ $rc -eq 0 ] && grep -q "p4_error:" $mpilog ; then
+               rc=1
+       fi
+       return $rc
 }
 
 nids_list () {
@@ -282,6 +282,25 @@ print_opts () {
     [ -e $MACHINEFILE ] && cat $MACHINEFILE
 }
 
+is_lustre () {
+       [ "$(stat -f -c %T $1)" = "lustre" ]
+}
+
+setstripe_getstripe () {
+       local file=$1
+       shift
+       local params=$@
+
+       is_lustre $file || return 0
+
+       if [ -n "$params" ]; then
+               $LFS setstripe $params $file ||
+                       error "setstripe $params failed"
+       fi
+       $LFS getstripe $file ||
+               error "getstripe $file failed"
+}
+
 run_compilebench() {
        local dir=${1:-$DIR}
        local cbench_DIR=${cbench_DIR:-""}
@@ -314,7 +333,8 @@ run_compilebench() {
        # for new "test_foo" functions names
        # local testdir=$DIR/$tdir
        local testdir=$dir/d0.compilebench.$$
-       mkdir -p $testdir
+       test_mkdir -p $testdir
+       setstripe_getstripe $testdir $cbench_STRIPEPARAMS
 
     local savePWD=$PWD
     cd $cbench_DIR
@@ -347,7 +367,9 @@ run_metabench() {
        print_opts METABENCH clients mbench_NFILES mbench_THREADS
 
        local testdir=$dir/d0.metabench
-       mkdir -p $testdir
+       test_mkdir -p $testdir
+       setstripe_getstripe $testdir $mbench_STRIPEPARAMS
+
        # mpi_run uses mpiuser
        chmod 0777 $testdir
 
@@ -395,7 +417,9 @@ run_simul() {
        print_opts SIMUL clients simul_REP simul_THREADS
 
        local testdir=$DIR/d0.simul
-       mkdir -p $testdir
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $simul_STRIPEPARAMS
+
        # mpi_run uses mpiuser
        chmod 0777 $testdir
 
@@ -436,16 +460,34 @@ run_mdtest() {
        local mdtest_custom_params=${mdtest_custom_params:-""}
        local type=${1:-"ssf"}
 
+       local mdtest_Nmntp=${mdtest_Nmntp:-1}
+
+       if [ $type = "ssf" ] && [ $mdtest_Nmntp -ne 1 ]; then
+               skip "shared directory mode is not compatible" \
+                       "with multiple directory paths"
+       fi
+
        # FIXME
        # Need space estimation here.
 
        print_opts MDTEST mdtest_iteration mdtest_THREADS mdtest_nFiles
 
        local testdir=$DIR/d0.mdtest
-       mkdir -p $testdir
-       # mpi_run uses mpiuser
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $mdtest_STRIPEPARAMS
        chmod 0777 $testdir
 
+       for ((i=1; i<mdtest_Nmntp; i++)); do
+               zconf_mount_clients $clients $MOUNT$i "$mntopts" ||
+                       error_exit "Failed $clients on $MOUNT$i"
+               local dir=$DIR$i/d0.mdtest$i
+               test_mkdir $dir
+               setstripe_getstripe $dir $mdtest_SETSTRIPEPARAMS
+               chmod 0777 $dir
+               testdir="$testdir@$dir"
+       done
+       # mpi_run uses mpiuser
+
        # -i # : repeat each test # times
        # -d   : test dir
        # -n # : number of file/dir to create/stat/remove
@@ -471,7 +513,13 @@ run_mdtest() {
     if [ $rc != 0 ] ; then
         error "mdtest failed! $rc"
     fi
-    rm -rf $testdir
+       rm -rf $testdir
+       for ((i=1; i<mdtest_Nmntp; i++)); do
+               local dir=$DIR$i/d0.mdtest$i
+               rm -rf $dir
+               zconf_umount_clients $clients $MOUNT$i ||
+                       error_exit "Failed umount $MOUNT$i on $clients"
+       done
 }
 
 run_connectathon() {
@@ -494,7 +542,8 @@ run_connectathon() {
        echo "free space = $space KB"
 
        local testdir=$dir/d0.connectathon
-       mkdir -p $testdir
+       test_mkdir -p $testdir
+       setstripe_getstripe $testdir $cnt_STRIPEPARAMS
 
        local savePWD=$PWD
        cd $cnt_DIR
@@ -562,6 +611,7 @@ run_ior() {
        ior_xferSize=${ior_xferSize:-1M}
        ior_type=${ior_type:-POSIX}
        ior_DURATION=${ior_DURATION:-30}        # minutes
+       ior_CLEANUP=${ior_CLEANUP:-true}
        local multiplier=1
        case ${ior_blockUnit} in
                [G])
@@ -594,14 +644,15 @@ run_ior() {
 
        print_opts IOR ior_THREADS ior_DURATION MACHINEFILE
 
-       mkdir -p $testdir
+       test_mkdir -p $testdir
+
        # mpi_run uses mpiuser
        chmod 0777 $testdir
-       if [ -z "$NFSCLIENT" ]; then
-               ior_stripe_params=${ior_stripe_params:-"-c -1"}
-               $LFS setstripe $testdir $ior_stripe_params ||
-                       { error "setstripe failed" && return 2; }
-       fi
+       [[ "$ior_stripe_params" && -z "$ior_STRIPEPARAMS" ]] &&
+               ior_STRIPEPARAMS="$ior_stripe_params" &&
+               echo "got deprecated ior_stripe_params,"\
+                       "use ior_STRIPEPARAMS instead"
+       setstripe_getstripe $testdir $ior_STRIPEPARAMS
 
        #
        # -b N  blockSize --
@@ -617,7 +668,7 @@ run_ior() {
 
        local cmd
        if [ -n "$ior_custom_params" ]; then
-               cmd="$IOR $ior_custom_params -o $testdir/iorData"
+               cmd="$IOR -o $testdir/iorData $ior_custom_params"
        else
                cmd="$IOR -a $ior_type -b ${ior_blockSize}${ior_blockUnit} \
                -o $testdir/iorData -t $ior_xferSize -v -C -w -r -W \
@@ -642,7 +693,7 @@ run_ior() {
     if [ $rc != 0 ] ; then
         error "ior failed! $rc"
     fi
-    rm -rf $testdir
+    $ior_CLEANUP && rm -rf $testdir || true
 }
 
 run_mib() {
@@ -655,16 +706,18 @@ run_mib() {
        mib_xferSize=${mib_xferSize:-1m}
        mib_xferLimit=${mib_xferLimit:-5000}
        mib_timeLimit=${mib_timeLimit:-300}
+       mib_STRIPEPARAMS=${mib_STRIPEPARAMS:-"-c -1"}
 
        print_opts MIB mib_THREADS mib_xferSize mib_xferLimit mib_timeLimit \
                MACHINEFILE
 
        local testdir=$DIR/d0.mib
-       mkdir -p $testdir
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $mib_STRIPEPARAMS
+
        # mpi_run uses mpiuser
        chmod 0777 $testdir
-       $LFS setstripe $testdir -c -1 ||
-               error "setstripe failed"
+
        #
        # -I    Show intermediate values in output
        # -H    Show headers in output
@@ -708,7 +761,9 @@ run_cascading_rw() {
        print_opts CASC_RW clients casc_THREADS casc_REP MACHINEFILE
 
        local testdir=$DIR/d0.cascading_rw
-       mkdir -p $testdir
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $casc_STRIPEPARAMS
+
        # mpi_run uses mpiuser
        chmod 0777 $testdir
 
@@ -747,8 +802,10 @@ run_write_append_truncate() {
 
        print_opts clients write_REP write_THREADS MACHINEFILE
 
-       mkdir -p $testdir
+       test_mkdir $testdir
        # mpi_run uses mpiuser
+       setstripe_getstripe $testdir $write_STRIPEPARAMS
+
        chmod 0777 $testdir
 
        local cmd="write_append_truncate -n $write_REP $file"
@@ -776,15 +833,17 @@ run_write_disjoint() {
        wdisjoint_REP=${wdisjoint_REP:-10000}
        chunk_size_limit=$1
 
-    # FIXME
-    # Need space estimation here.
+       # FIXME
+       # Need space estimation here.
 
-    print_opts WRITE_DISJOINT clients wdisjoint_THREADS wdisjoint_REP \
-        MACHINEFILE
-    local testdir=$DIR/d0.write_disjoint
-    mkdir -p $testdir
-    # mpi_run uses mpiuser
-    chmod 0777 $testdir
+       print_opts WRITE_DISJOINT clients wdisjoint_THREADS wdisjoint_REP \
+               MACHINEFILE
+       local testdir=$DIR/d0.write_disjoint
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $wdisjoint_STRIPEPARAMS
+
+       # mpi_run uses mpiuser
+       chmod 0777 $testdir
 
        local cmd="$WRITE_DISJOINT -f $testdir/file -n $wdisjoint_REP -m \
                        $chunk_size_limit"
@@ -812,7 +871,9 @@ run_parallel_grouplock() {
        print_opts clients parallel_grouplock_MINTASKS MACHINEFILE
 
        local testdir=$DIR/d0.parallel_grouplock
-       mkdir -p $testdir
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $parallel_grouplock_STRIPEPARAMS
+
        # mpi_run uses mpiuser
        chmod 0777 $testdir
 
@@ -867,19 +928,21 @@ run_statahead () {
 
        # create large dir
 
-    # do not use default "d[0-9]*" dir name
-    # to avoid of rm $statahead_NUMFILES (500k) files in t-f cleanup
-    local dir=dstatahead
-    local testdir=$DIR/$dir
+       # do not use default "d[0-9]*" dir name
+       # to avoid of rm $statahead_NUMFILES (500k) files in t-f cleanup
+       local dir=dstatahead
+       local testdir=$DIR/$dir
+
+       # cleanup only if dir exists
+       # cleanup only $statahead_NUMFILES number of files
+       # ignore the other files created by someone else
+       [ -d $testdir ] &&
+       mdsrate_cleanup $((num_clients * 32)) $MACHINEFILE \
+               $statahead_NUMFILES $testdir 'f%%d' --ignore
 
-    # cleanup only if dir exists
-    # cleanup only $statahead_NUMFILES number of files
-    # ignore the other files created by someone else
-    [ -d $testdir ] &&
-        mdsrate_cleanup $((num_clients * 32)) $MACHINEFILE \
-            $statahead_NUMFILES $testdir 'f%%d' --ignore
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $statahead_STRIPEPARAMS
 
-    mkdir -p $testdir
     # mpi_run uses mpiuser
     chmod 0777 $testdir
 
@@ -962,13 +1025,10 @@ run_rr_alloc() {
        local rr_alloc_MNTPTS=${rr_alloc_MNTPTS:-11}
        local total_MNTPTS=$((rr_alloc_MNTPTS * num_clients))
        local mntpt_root="${TMP}/rr_alloc_mntpt/lustre"
-       if [ $MDSCOUNT -lt 2 ]; then
-               [ -e $DIR/$tdir ] || mkdir -p $DIR/$tdir
-       else
-               [ -e $DIR/$tdir ] || $LFS mkdir -i 0 $DIR/$tdir
-       fi
+       test_mkdir $DIR/$tdir
+       setstripe_getstripe $DIR/$tdir $rr_alloc_STRIPEPARAMS
+
        chmod 0777 $DIR/$tdir
-       $LFS setstripe -c 1 /$DIR/$tdir
 
        trap "cleanup_rr_alloc $clients $mntpt_root $rr_alloc_MNTPTS" EXIT ERR
        for i in $(seq 0 $((rr_alloc_MNTPTS - 1))); do
@@ -982,7 +1042,7 @@ run_rr_alloc() {
        # Save mdt values, set threshold to 100% i.e always Round Robin,
        # restore the saved values again after creating files...
        save_lustre_params mds1 \
-               "lov.$FSNAME-MDT0000*.qos_threshold_rr" > $qos_prec_objs
+               "lod.$FSNAME-MDT0000*.qos_threshold_rr" > $qos_prec_objs
        save_lustre_params mds1 \
                "osp.$FSNAME-OST*-osc-MDT0000.create_count" >> $qos_prec_objs
 
@@ -998,10 +1058,17 @@ run_rr_alloc() {
 
        foeo_calc=$((rr_alloc_NFILES * total_MNTPTS / OSTCOUNT))
        local create_count=$((2 * foeo_calc))
-       do_facet mds1 "$LCTL set_param -n \
-               lov.$FSNAME-MDT0000*.qos_threshold_rr 100 \
-               osp.$FSNAME-OST*-osc-MDT0000.create_count $create_count" ||
-               error "failed while setting qos_threshold_rr & creat_count"
+
+       # create_count accepted values:
+       #   [OST_MIN_PRECREATE=32, OST_MAX_PRECREATE=20000]
+       # values exceeding OST_MAX_PRECREATE are lowered to the maximum.
+       [[ $create_count -lt 32 ]] && create_count=32
+       local i
+       for i in $(seq $MDSCOUNT); do
+               do_facet mds$i "$LCTL set_param -n \
+                       lod.$FSNAME-MDT*.qos_threshold_rr=100 \
+                       osp.$FSNAME-OST*-osc-MDT*.create_count=$create_count"
+       done
 
        # Create few temporary files in order to increase the precreated objects
        # to a desired value, before starting 'rr_alloc' app. Due to default
@@ -1096,7 +1163,9 @@ run_fs_test() {
 
        print_opts FS_TEST clients fs_test_threads fs_test_objsize MACHINEFILE
 
-       mkdir -p $testdir
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $fs_test_STRIPEPARAMS
+
        # mpi_run uses mpiuser
        chmod 0777 $testdir
 
@@ -1166,7 +1235,8 @@ run_fio() {
 
        [ x$FIO = x ] && skip_env "FIO not found"
 
-       mkdir -p $testdir
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $fio_STRIPEPARAMS
 
        # use fio job file if exists,
        # create a simple one if missing
@@ -1235,7 +1305,8 @@ run_xdd() {
        print_opts XDD clients xdd_queuedepth xdd_blocksize xdd_reqsize \
                xdd_mbytes xdd_passes xdd_rwratio
 
-       mkdir -p $testdir
+       test_mkdir $testdir
+       setstripe_getstripe $testdir $xdd_STRIPEPARAMS
 
        local files=""
        # Target files creates based on the given number of targets