Home | History | Annotate | Download | only in testscripts
      1 #!/bin/bash
      2 
      3 
      4 ##############################################################
      5 #
      6 #  Copyright (c) International Business Machines  Corp., 2003
      7 #
      8 #  This program is free software;  you can redistribute it and/or modify
      9 #  it under the terms of the GNU General Public License as published by
     10 #  the Free Software Foundation; either version 2 of the License, or
     11 #  (at your option) any later version.
     12 #
     13 #  This program is distributed in the hope that it will be useful,
     14 #  but WITHOUT ANY WARRANTY;  without even the implied warranty of
     15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     16 #  the GNU General Public License for more details.
     17 #
     18 #  You should have received a copy of the GNU General Public License
     19 #  along with this program;  if not, write to the Free Software
     20 #  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     21 #
     22 #  FILE        : exportfs.sh
     23 #  USAGE       : exportfs.sh -h <nfs_server> -d <nfs_server_disk_partition>
     24 #                            -t <server_fs_type>
     25 #
     26 #  DESCRIPTION : A script that will test exportfs on Linux system.
     27 #  REQUIREMENTS:
     28 #                1) NFS Server system with rsh enabled between client & server.
     29 #                2) 100MB Disk partition on NFS server.
     30 #
     31 #  HISTORY     :
     32 #      06/18/2003 Prakash Narayana (prakashn (at] us.ibm.com)
     33 #
     34 #  CODE COVERAGE: 7.1% - fs/exportfs (Total Coverage)
     35 #                 7.1% - fs/exportfs/expfs.c
     36 #
     37 ##############################################################
     38 
     39 
     40 NFS_SERVER=""
     41 REM_DISK_PART=""
     42 FS_TYPE=""
     43 MNT_POINT="/tmp/exportfs_$$"
     44 
     45 USAGE="$0 -h <nfs_server> -d <nfs_server_disk_partition> -t <server_fs_type>"
     46 
     47 
     48 ##############################################################
     49 #
     50 # Make sure that uid=root is running this script.
     51 # Validate the command line arguments.
     52 # Make sure that NFS Server is up with rsh is enabled.
     53 # Make sure that FS_TYPE package has been installed on NFS Server side.
     54 # Make sure that FS_TYPE module is built into the kernel or loaded
     55 # on NFS Server side.
     56 #
     57 ##############################################################
     58 
     59 if [ $UID != 0 ]
     60 then
     61 	echo "FAILED: Must have root access to execute this script"
     62 	exit 1
     63 fi
     64 
     65 while getopts h:d:t: args
     66 do
     67 	case $args in
     68 	h)	NFS_SERVER=$OPTARG ;;
     69 	d)	REM_DISK_PART=$OPTARG ;;
     70 	t)	FS_TYPE=$OPTARG ;;
     71 	\?)	echo $USAGE ; exit 1 ;;
     72 	esac
     73 done
     74 
     75 if [ -z "$NFS_SERVER" ]
     76 then
     77 	echo $USAGE
     78 	echo "FAILED: NFS Server not specificed"
     79 	exit 1
     80 fi
     81 
     82 if [ -z "$REM_DISK_PART" ]
     83 then
     84 	echo $USAGE
     85 	echo "FAILED: NFS Server disk partition not specified"
     86 	exit 1
     87 fi
     88 
     89 if [ -z "$FS_TYPE" ]
     90 then
     91 	echo $USAGE
     92 	echo "FAILED: NFS Server file system type not specified"
     93 	exit 1
     94 fi
     95 
     96 #
     97 # How to check if it a valid block special device on NFS Server ???
     98 # Add code here.
     99 
    100 
    101 ping -c 2 -w 15 $NFS_SERVER >/dev/null 2>&1
    102 if [ $? != 0 ]
    103 then
    104 	echo "FAILED: ping $NFS_SERVER failed"
    105 	exit 1
    106 fi
    107 
    108 rsh -n -l root $NFS_SERVER "ls -l /etc" >/dev/null 2>&1
    109 if [ $? != 0 ]
    110 then
    111 	echo "FAILED: rsh -n -l root $NFS_SERVER "ls -l /etc" failed"
    112 	exit 1
    113 fi
    114 
    115 rsh -n -l root $NFS_SERVER "rpm -q -a | grep $FS_TYPE" | grep $FS_TYPE >/dev/null 2>&1
    116 if [ $? != 0 ]
    117 then
    118 	rsh -n -l root $NFS_SERVER "grep $FS_TYPE /etc/filesystems" | grep $FS_TYPE >/dev/null 2>&1
    119 	if [ $? != 0 ]
    120 	then
    121 		rsh -n -l root $NFS_SERVER "grep $FS_TYPE /proc/filesystems" | grep $FS_TYPE >/dev/null 2>&1
    122 		if [ $? != 0 ]
    123 		then
    124 			echo "FAILED: $FS_TYPE package is not installed or loaded on $NFS_SERVER"
    125 			exit 1
    126 		fi
    127 	fi
    128 fi
    129 
    130 if [ "$FS_TYPE" = "reiserfs" ]
    131 then
    132 #	rsh -n -l root $NFS_SERVER "/sbin/mkfs -t $FS_TYPE --format 3.6 -f $REM_DISK_PART >/dev/null 2>&1"
    133 	rsh -n -l root $NFS_SERVER "/sbin/mkfs -t $FS_TYPE -f $REM_DISK_PART --format 3.6 >/dev/null 2>&1"
    134 	echo "/sbin/mkfs -t $FS_TYPE --format 3.6 -f $REM_DISK_PART >/dev/null 2>&1"
    135 else
    136 #	rsh -n -l root $NFS_SERVER "/sbin/mkfs -t $FS_TYPE $REM_DISK_PART >/dev/null 2>&1"
    137 	QUIETFLAG=
    138 	if [ "$FS_TYPE" = "jfs" ]
    139 	then
    140 		QUIETFLAG="-q"
    141 	fi
    142 	rsh -n -l root $NFS_SERVER "/sbin/mkfs -t $FS_TYPE $QUIETFLAG $REM_DISK_PART >/dev/null 2>&1"
    143 	if [ $? != 0 ]
    144 	then
    145 		echo "FAILED: Could not /sbin/mkfs -t $FS_TYPE $REM_DISK_PART on $NFS_SERVER"
    146 		exit 1
    147 	fi
    148 fi
    149 
    150 rsh -n -l root $NFS_SERVER "mkdir -p -m 777 $MNT_POINT"
    151 if [ $? != 0 ]
    152 then
    153 	echo "FAILED: Could not mkdir -p -m 777 $MNT_POINT on $NFS_SERVER"
    154 	exit 1
    155 fi
    156 
    157 rsh -n -l root $NFS_SERVER "mount -t $FS_TYPE $REM_DISK_PART $MNT_POINT"
    158 if [ $? != 0 ]
    159 then
    160 	echo "FAILED: Could not mount -t $FS_TYPE $REM_DISK_PART on $MNT_POINT"
    161 	exit 1
    162 fi
    163 
    164 rsh -n -l root $NFS_SERVER "chmod 777 $MNT_POINT"
    165 if [ $? != 0 ]
    166 then
    167 	echo "FAILED: Could not chmod 777 $MNT_POINT on $NFS_SERVER"
    168 	exit 1
    169 fi
    170 
    171 rsh -n -l root $NFS_SERVER "/usr/sbin/exportfs -i -o no_root_squash,rw *:$MNT_POINT"
    172 if [ $? != 0 ]
    173 then
    174 	rsh -n -l root $NFS_SERVER "umount $MNT_POINT"
    175 	rsh -n -l root $NFS_SERVER "rm -rf $MNT_POINT"
    176 	echo "FAILED: Could not export remote directory $MNT_POINT"
    177 	exit 1
    178 fi
    179 sleep 15
    180 
    181 # Here is the code coverage for fs/exportfs
    182 #
    183 mkdir -p -m 777 $MNT_POINT
    184 mount -t nfs $NFS_SERVER:$MNT_POINT $MNT_POINT
    185 if [ $? != 0 ]
    186 then
    187 	echo "FAILED: NFS mount failed"
    188 	exit 1
    189 fi
    190 
    191 mkdir -p -m 777 $MNT_POINT/test_dir
    192 echo "NFS mount of $FS_TYPE file system and I/O to NFS mount point generates the  fs/exportfs code coverage" > $MNT_POINT/test_dir/exportfs_coverage
    193 
    194 
    195 #######################################################
    196 #
    197 # Just before exit, perform NFS CLIENT & SERVER cleanup
    198 #
    199 #######################################################
    200 
    201 umount $MNT_POINT
    202 rm -rf $MNT_POINT
    203 
    204 rsh -n -l root $NFS_SERVER "/usr/sbin/exportfs -u :$MNT_POINT"
    205 rsh -n -l root $NFS_SERVER "umount $MNT_POINT"
    206 rsh -n -l root $NFS_SERVER "rm -rf $MNT_POINT"
    207 echo "PASSED: $0 passed!"
    208 exit 0
    209