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@us.ibm.com)
33#
34#  CODE COVERAGE: 7.1% - fs/exportfs (Total Coverage)
35#                 7.1% - fs/exportfs/expfs.c
36#
37##############################################################
38
39
40NFS_SERVER=""
41REM_DISK_PART=""
42FS_TYPE=""
43MNT_POINT="/tmp/exportfs_$$"
44
45USAGE="$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
59if [ $UID != 0 ]
60then
61	echo "FAILED: Must have root access to execute this script"
62	exit 1
63fi
64
65while getopts h:d:t: args
66do
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
73done
74
75if [ -z "$NFS_SERVER" ]
76then
77	echo $USAGE
78	echo "FAILED: NFS Server not specificed"
79	exit 1
80fi
81
82if [ -z "$REM_DISK_PART" ]
83then
84	echo $USAGE
85	echo "FAILED: NFS Server disk partition not specified"
86	exit 1
87fi
88
89if [ -z "$FS_TYPE" ]
90then
91	echo $USAGE
92	echo "FAILED: NFS Server file system type not specified"
93	exit 1
94fi
95
96#
97# How to check if it a valid block special device on NFS Server ???
98# Add code here.
99
100
101ping -c 2 -w 15 $NFS_SERVER >/dev/null 2>&1
102if [ $? != 0 ]
103then
104	echo "FAILED: ping $NFS_SERVER failed"
105	exit 1
106fi
107
108rsh -n -l root $NFS_SERVER "ls -l /etc" >/dev/null 2>&1
109if [ $? != 0 ]
110then
111	echo "FAILED: rsh -n -l root $NFS_SERVER "ls -l /etc" failed"
112	exit 1
113fi
114
115rsh -n -l root $NFS_SERVER "rpm -q -a | grep $FS_TYPE" | grep $FS_TYPE >/dev/null 2>&1
116if [ $? != 0 ]
117then
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
128fi
129
130if [ "$FS_TYPE" = "reiserfs" ]
131then
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"
135else
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
148fi
149
150rsh -n -l root $NFS_SERVER "mkdir -p -m 777 $MNT_POINT"
151if [ $? != 0 ]
152then
153	echo "FAILED: Could not mkdir -p -m 777 $MNT_POINT on $NFS_SERVER"
154	exit 1
155fi
156
157rsh -n -l root $NFS_SERVER "mount -t $FS_TYPE $REM_DISK_PART $MNT_POINT"
158if [ $? != 0 ]
159then
160	echo "FAILED: Could not mount -t $FS_TYPE $REM_DISK_PART on $MNT_POINT"
161	exit 1
162fi
163
164rsh -n -l root $NFS_SERVER "chmod 777 $MNT_POINT"
165if [ $? != 0 ]
166then
167	echo "FAILED: Could not chmod 777 $MNT_POINT on $NFS_SERVER"
168	exit 1
169fi
170
171rsh -n -l root $NFS_SERVER "/usr/sbin/exportfs -i -o no_root_squash,rw *:$MNT_POINT"
172if [ $? != 0 ]
173then
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
178fi
179sleep 15
180
181# Here is the code coverage for fs/exportfs
182#
183mkdir -p -m 777 $MNT_POINT
184mount -t nfs $NFS_SERVER:$MNT_POINT $MNT_POINT
185if [ $? != 0 ]
186then
187	echo "FAILED: NFS mount failed"
188	exit 1
189fi
190
191mkdir -p -m 777 $MNT_POINT/test_dir
192echo "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
201umount $MNT_POINT
202rm -rf $MNT_POINT
203
204rsh -n -l root $NFS_SERVER "/usr/sbin/exportfs -u :$MNT_POINT"
205rsh -n -l root $NFS_SERVER "umount $MNT_POINT"
206rsh -n -l root $NFS_SERVER "rm -rf $MNT_POINT"
207echo "PASSED: $0 passed!"
208exit 0
209