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