Subversion Repositories configs

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
34 - 1
#!/bin/bash
2
#
3
# Bring up/down NFSoRDMA support
4
#
5
# chkconfig: - 31 61
6
# description: Enables/Disables NFS over RDMA interfaces
7
# config:	/etc/rdma/rdma.conf
8
#
9
### BEGIN INIT INFO
10
# Provides:       nfs-rdma
11
# Default-Stop: 0 1 2 3 4 5 6
12
# Required-Start: $network $rdma $nfs
13
# Required-Stop: $nfs
14
# Short-Description: Enables/Disables NFS over RDMA interfaces
15
# Description: Enables/Disables NFS over RDMA interfaces
16
### END INIT INFO
17
 
18
CONFIG=/etc/rdma/rdma.conf
19
 
20
. /etc/rc.d/init.d/functions
21
 
22
LOAD_ULP_MODULES=""
23
if [ -f $CONFIG ]; then
24
    . $CONFIG
25
 
26
    if [ "${NFSoRDMA_LOAD}" == "yes" ]; then
27
	LOAD_ULP_MODULES="svcrdma xprtrdma"
28
    fi
29
    if [ -n "${NFSoRDMA_PORT}" ]; then
30
	PORT=${NFSoRDMA_PORT}
31
    else
32
	PORT=2050
33
    fi
34
fi
35
 
36
UNLOAD_ULP_MODULES="xprtrdma svcrdma"
37
 
38
 
39
# If module $1 is loaded return - 0 else - 1
40
is_module()
41
{
42
    /sbin/lsmod | grep -w "$1" > /dev/null 2>&1
43
    return $?
44
}
45
 
46
load_modules()
47
{
48
    local RC=0
49
 
50
    for module in $*; do
51
	if ! is_module $module; then
52
	    /sbin/modprobe $module
53
	    res=$?
54
	    RC=$[ $RC + $res ]
55
	    if [ $res -ne 0 ]; then
56
		echo
57
		echo -n "Failed to load module $mod"
58
	    fi
59
	fi
60
    done
61
    return $RC
62
}
63
 
64
unload_module()
65
{
66
    local mod=$1
67
    # Unload module $1
68
    if is_module $mod; then
69
	/sbin/rmmod $mod > /dev/null 2>&1
70
	if [ $? -ne 0 ]; then
71
	    echo
72
	    echo "Failed to unload $mod"
73
	    return 1
74
	fi
75
    fi
76
    return 0
77
}
78
 
79
start()
80
{
81
    local RC=0
82
    local loaded=0
83
 
84
    echo -n "Enabling NFSoRDMA support:"
85
 
86
    load_modules $LOAD_ULP_MODULES
87
    RC=$[ $RC + $? ]
88
 
89
    if [ $RC -gt 0 ]; then
90
    	for mod in $UNLOAD_ULP_MODULES; do
91
	    unload_module $mod
92
	done
93
	echo_failure
94
	echo
95
	return $RC
96
    fi
97
 
98
    echo "rdma $PORT" > /proc/fs/nfsd/portlist
99
    sleep 1
100
    entry=$(grep rdma /proc/fs/nfsd/portlist)
101
    if [ -z "$entry" ]; then
102
    	for mod in $UNLOAD_ULP_MODULES; do
103
	    unload_module $mod
104
	done
105
	echo_failure
106
	echo
107
	return 1
108
    fi
109
 
110
    touch /var/lock/subsys/nfs-rdma
111
    echo_success
112
    echo
113
    return $RC
114
}
115
 
116
stop()
117
{
118
    echo -n "Disabling NFSoRDMA support:"
119
 
120
    if ! is_module svcrdma; then
121
	# Nothing to do, make sure lock file is gone and return
122
	rm -f /var/lock/subsys/nfs-rdma
123
	echo_success
124
	echo
125
	return 0
126
    fi
127
 
128
    # Tell the nfs server to quit listening on the rdma port
129
    port=$(grep rdma /proc/fs/nfsd/portlist)
130
    if [ -n "$port" ]; then
131
	echo "-$port" > /proc/fs/nfsd/portlist
132
	# Small sleep to let nfsd process our request
133
	sleep 1
134
    fi
135
 
136
    # Unload NFSoRDMA modules
137
    for mod in $UNLOAD_ULP_MODULES
138
    do
139
	unload_module $mod
140
	RC=$[ $RC + $? ]
141
    done
142
 
143
    [ $RC -eq 0 ] && rm -f /var/lock/subsys/nfs-rdma
144
    [ $RC -eq 0 ] && echo_success || echo_failure
145
    echo
146
    return $RC
147
}
148
 
149
status()
150
{
151
    entry=$(grep rdma /proc/fs/nfsd/portlist)
152
 
153
    if [ -z "$entry" ]; then
154
	if [ -f /var/lock/subsys/nfs-rdma ]; then
155
	    return 2
156
	else
157
	    return 3
158
	fi
159
    else
160
	return 0
161
    fi
162
}
163
 
164
restart ()
165
{
166
    stop
167
    start
168
}
169
 
170
condrestart ()
171
{
172
    [ -e /var/lock/subsys/nfs-rdma ] && restart || return 0
173
}
174
 
175
usage ()
176
{
177
    echo
178
    echo "Usage: `basename $0` {start|stop|restart|condrestart|try-restart|force-reload|status}"
179
    echo
180
    return 2
181
}
182
 
183
case $1 in
184
    start|stop|restart|condrestart|try-restart|force-reload)
185
	[ `id -u` != "0" ] && exit 4 ;;
186
esac
187
 
188
case $1 in
189
    start) start; RC=$? ;;
190
    stop) stop; RC=$? ;;
191
    restart) restart; RC=$? ;;
192
    reload) RC=3 ;;
193
    condrestart) condrestart; RC=$? ;;
194
    try-restart) condrestart; RC=$? ;;
195
    force-reload) condrestart; RC=$? ;;
196
    status) status; RC=$? ;;
197
    *) usage; RC=$? ;;
198
esac
199
 
200
exit $RC