head     1.1;
branch   1.1.1;
access   ;
symbols  LTP_20031204:1.1.1.1 LINUX_TEST_PROJECT:1.1.1;
locks    ; strict;
comment  @# @;


1.1
date     2003.12.31.09.00.21;  author mtm;  state Exp;
branches 1.1.1.1;
next     ;

1.1.1.1
date     2003.12.31.09.00.21;  author mtm;  state Exp;
branches ;
next     ;


desc
@@



1.1
log
@Initial revision
@
text
@#! /bin/sh
#
#   Copyright (c) International Business Machines  Corp., 2001
#
#   This program is free software;  you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY;  without even the implie; warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
#   the GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program;  if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
#
#
#  FILE   : nfs03
#
#  DESCRIPTION: This script sets up the NFS directories in the remote machine 
#		and runs the LTP's filesystem test: fs_inod.
#  
#  SETUP: The home directory of root on the machine exported as "RHOST"
#         MUST have a ".rhosts" file with the hostname of the machine
#         where the test is executed.
#
#
#  HISTORY:
#    11/2/01 Robbie Williamson (robbiew@@us.ibm.com)
#      -Created
#
#***********************************************************************

#Uncomment line below for debug output.
#trace_logic=${trace_logic:-"set -x"}

$trace_logic

#-----------------------------------------------------------------------
# Initialize local variables
#-----------------------------------------------------------------------
TC=${TC:=nfs03}
TCbin=${TCbin:=`pwd`}
TCdat=${TCdat:=$TCbin}
TCsrc=${TCsrc:=$TCbin}
TCtmp=${TCtmp:=$TCbin/$TC$$}
TCdump=${TCdump:=$TCbin}
RHOST=${RHOST:=`hostname | awk {'print $1'}`}

# Setting the NFS to version 2 by default
VERSION=${VERSION:=2}
SOCKET_TYPE=${SOCKET_TYPE:=udp}

# If CLEANUP is not set; set it to "ON"
CLEANUP=${CLEANUP:="ON"}

DIR_NUM=$1
FILE_NUM=$2
NFSD_NUM=$3

DIR_NUM=${DIR_NUM:=100}
FILE_NUM=${FILE_NUM:= 100}
THREAD_NUM=${THREAD_NUM:=1}

#============================================================================
# FUNCITON NAME:        fs_inod
#
# FUNCTION DESCRIPTION: Filesystems test from LTP.
# 
# PARAMETERS:		Filesystem, number of directories, number of files, 
#			and loops
#
# RETURNS:		0 for PASS and Error Code for FAIL.
#============================================================================
fs_inod()
{

#=============================================================================
# FUNCTION NAME:        err_log
#
# FUNCTION DESCRIPTION: Log error
#
# PARAMETERS:           None.
#
# RETURNS:              None.
#=============================================================================
function err_log
{
    error "$1"
    let step_errors="$step_errors + 1"
}


#=============================================================================
# FUNCTION NAME:        make_subdirs
#
# FUNCTION DESCRIPTION: Creates $numsubdirs subdirectories
#
# PARAMETERS:           None.
#
# RETURNS:              None.
#=============================================================================
function make_subdirs
{
    i=0;
    while [ "$i" -lt "$numsubdirs" ]; do
        [ -d dir$i ] || { \
            echo "$0: mkdir dir$i"
            mkdir -p dir$i || echo "mkdir dir$i FAILED"
        }
        let i="$i + 1"
    done;
}


#=============================================================================
# FUNCTION NAME:        touch_files
#
# FUNCTION DESCRIPTION: Creates $numfiles in each of $numsubdirs directories
#
# PARAMETERS:           None.
#
# RETURNS:              None.
#=============================================================================
function touch_files
{
    echo "$0: touch files [0-$numsubdirs]/file$numsubdirs[0-$numfiles]"
    j=0;

    while [ "$j" -lt "$numsubdirs" ]; do
        cd dir$j
        k=0;

        while [ "$k" -lt "$numfiles" ]; do
            >file$j$k || err_log ">file$j$k FAILED"
            let k="$k + 1"
        done

        let j="$j + 1"
        cd ..
    done
}


#=============================================================================
# FUNCTION NAME:        rm_files
#
# FUNCTION DESCRIPTION: Removes $numfiles in each $numsubdir directory
#
# PARAMETERS:   None.
#
# RETURNS:      None.
#=============================================================================
function rm_files
{
    echo "$0: rm files [0-$numsubdirs]/file$numsubdirs[0-$numfiles]"
    j=0;

    while [ "$j" -lt "$numsubdirs" ]; do
        cd dir$j
        k=0;

        while [ "$k" -lt "$numfiles" ]; do
            rm -f file$j$k || err_log "rm -f file$j$k FAILED"
            let k="$k + 1"
        done

        let j="$j + 1"
        cd ..
    done
}


#=============================================================================
# FUNCTION NAME:        step1
#
# FUNCTION DESCRIPTION: multiple processes creating and deleting files
#
# PARAMETERS:           None.
#
# RETURNS:              None.
#=============================================================================
function step1
{
    echo "=============================================="
    echo "MULTIPLE PROCESSES CREATING AND DELETING FILES"
    echo "=============================================="

    echo "$0: creating dir2 subdirectories"
    [ -d dir2 ] || { \
        mkdir -p dir2 || end_testcase "mkdir dir2 failed"
    }
    cd dir2 || err_log "cd dir2 FAILED"
    make_subdirs || err_log "make_subdirs on dir2 FAILED"
    cd ..

    echo "$0: creating dir1 subdirectories & files"
    [ -d dir1 ] || { \
        mkdir dir1 || abort "mkdir dir1 FAILED"
    }
    cd dir1 || err_log "cd dir1 FAILED"
    make_subdirs || err_log "make_subdirs on dir1 FAILED"
    touch_files
    pid1=$!

    i=1;
    while [ "$i" -le "$numloops" ]; do
        echo "Executing loop $i of $numloops..."

#       Added date stamps to track execution time and duration

        echo "$0: cd ../dir1 & creating files"
        cd ../dir1
        wait $pid1
        touch_files &
        pid1=$!

        echo "$0: cd ../dir1 & removing files"
        cd ../dir1
        wait $pid1
        rm_files &
        pid1=$!

        echo "$0: cd ../dir2 & creating files"
        cd ../dir2
        wait $pid2
        touch_files &
        pid2=$!

        echo "$0: cd ../dir2 & removing files"
        cd ../dir2
        wait $pid2
        rm_files &
        pid2=$!

        let i="$i + 1"
    done

    # wait for all background processes to complete execution
    wait
    return $step_errors
}


#=============================================================================
# MAIN
#     See the description, purpose, and design of this test under TEST
#     in this test's prolog.
#=============================================================================
    USAGE="Usage: ./fs_inod [volumename] [numsubdirectories] [numfiles] [numloops]"

    if [ $# -ne 4 ]
    then
       echo $USAGE
       exit 2
    fi

    testvol=$1
    numsubdirs=$2
    numfiles=$3
    numloops=$4

    cd $testvol || exit 2

    echo "FS_INODE: File system stress - inode allocation/deallocation"
    echo "Volume under test: $testvol"
    echo "Number of subdirectories: $numsubdirs"
    echo "Number of files: $numfiles"
    echo "Number of loops: $numloops"
    echo "Execution begins "
    date

    STEPS="1"
    for I in $STEPS
    do
         step_errors=0
         step$I
         if [ $? != 0 ]; then
            error "step$I failed - see above errors"
         fi
    done

# Clean up and timestamp
    rm -rf $testvol/dir*
    echo "Execution completed"
    date

    return $ERRORS
}

#=============================================================================
# FUNCTION NAME:        setup_testcase
#
# FUNCTION DESCRIPTION: Perform the setup function for the testcase.
#
# PARAMETERS:   	None.
#
# RETURNS:      	None.
#=============================================================================

setup_testcase()
{
$trace_logic
   

    echo ""
    echo "Test Options:"
    echo " VERSION: $VERSION"
    echo " SOCKET_TYPE: $SOCKET_TYPE"
    echo " RHOST: $RHOST"
    echo ""
    echo "Test Parameters:"
    echo " Number of Directories: $DIR_NUM"
    echo " Number of Files per Directory: $FILE_NUM"
    echo " Number of nfsds tested: $THREAD_NUM"
    echo ""
    
    sleep 5

    PID=$$
    OPTS=${OPTS:="vers=$VERSION,proto=$SOCKET_TYPE "}
    REMOTE_DIR=${RHOST}:/mnt/nfs03$PID.testdir
    mkdir -p $TCtmp || end_testcase "Could not create $TCtmp"
    chmod 777 $TCtmp

    echo "Setting up remote machine: $RHOST"
    rsh -n $RHOST "mkdir /mnt/nfs03$PID.testdir"
    [ $? = 0 ] || end_testcase "Could not create remote directory"
    rsh -n $RHOST "/usr/sbin/exportfs -i -o no_root_squash,rw *:/mnt/nfs03$PID.testdir"
    [ $? = 0 ] || end_testcase "Could export remote directory"

    echo "Mounting NFS filesystem $REMOTE_DIR on $TCtmp with parameters $OPTS"
    mount -o $OPTS $REMOTE_DIR $TCtmp || end_testcase "Cannot mount $TCtmp"
    [ $? = 0 ] || end_testcase "Could not mount $REMOTE_DIR"
    
    echo "Setting server side nfsd count to $THREAD_NUM"
    ORIG_NFSD=`rsh -n $RHOST "ps -ef" | grep nfsd | grep -v grep | wc -l`
    rsh -n $RHOST "/usr/sbin/rpc.nfsd $THREAD_NUM"
    [ $? = 0 ] || end_testcase "Could not set the number of nfsds on $RHOST"

}


#=============================================================================
# FUNCTION NAME:        do_test
#
# FUNCTION DESCRIPTION: Perform the test
#
# PARAMETERS:   	None.
#
# RETURNS:      	None.
#=============================================================================
do_test()
{
$trace_logic
    echo "fs_inod starting on $TCtmp."
    fs_inod $TCtmp $DIR_NUM $FILE_NUM 1 
    retval=$?
    echo $"fs_inod on $TCtmp finished."
    
    if [ "$retval" != 0 ]; then
      end_testcase "Errors have resulted from this test: fs_inod returned $retval."
    fi

    cd /
}


#=============================================================================
# FUNCTION NAME:        end_testcase
#
# FUNCTION DESCRIPTION: Clean up
#
# PARAMETERS:   	None.
#
# RETURNS:      	None.
#=============================================================================
end_testcase()
{
$trace_logic
    if [ "$CLEANUP" = "ON" ]; then
	cd \
	
	echo "Cleaning up testcase"
        /bin/umount $TCtmp || echo "Cannot umount $TCtmp"
	sleep 2
	rmdir $TCtmp || echo "Cannot remove $TCtmp"
        rsh -n $RHOST "/usr/sbin/exportfs -u *:/mnt/nfs03$PID.testdir"
	rsh -n $RHOST "rm -rf /mnt/nfs03$PID.testdir"
	rsh -n $RHOST "/usr/sbin/rpc.nfsd $ORIG_NFSD"

    fi

    [ $# = 0 ] && { echo "Test Successful"; exit 0; }
    echo "Test Failed: $@@"
    exit 1
}

#=============================================================================
# MAIN PROCEDURE
#=============================================================================

setup_testcase
do_test
end_testcase
@


1.1.1.1
log
@Initial import of the Linux Test Project (http://ltp.sourceforge.net).

This import is minus the Posix test suite, which will be imported separately,
and the HPI suite, which doesn't concern us.
@
text
@@
