forked from Mellanox/nv_peer_memory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
nv_peer_mem
executable file
·151 lines (126 loc) · 2.69 KB
/
nv_peer_mem
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
#!/bin/bash
#
# Copyright (c) 2013 Mellanox Technologies. All rights reserved.
#
# config: /etc/infiniband/nv_peer_mem.conf
CONFIG=${CONFIG:-"/etc/infiniband/nv_peer_mem.conf"}
modname=nv_peer_mem
reqmods="ib_core nvidia"
if [ ! -f $CONFIG ]; then
echo No configuration file found for $modname
exit 0
fi
. $CONFIG
CWD=`pwd`
cd /etc/infiniband
WD=`pwd`
# Allow unsupported modules, if disallowed by current configuration
modprobe=/sbin/modprobe
if ${modprobe} -c | grep -q '^allow_unsupported_modules *0'; then
modprobe="${modprobe} --allow-unsupported-modules"
fi
ACTION=$1
shift
# Check if configured to start automatically
if [ "X${ONBOOT}" != "Xyes" ]; then
exit 0
fi
is_module()
{
local RC
/sbin/lsmod | grep -w "$1" > /dev/null 2>&1
RC=$?
return $RC
}
log_msg()
{
logger -i "$modname: $@"
}
load_module()
{
local module=$1
filename=`modinfo $module | grep filename | awk '{print $NF}'`
if [ ! -n "$filename" ]; then
echo "Module $module does not exist"
log_msg "Error: Module $module does not exist"
return 1
fi
${modprobe} $module 2>&1
}
start()
{
local RC=0
echo -n "starting... "
# Check if required modules are loaded
for mod in $reqmods
do
if is_module $mod ; then
continue
else
echo "Error: the following required module is not loaded: $mod"
log_msg "Error: the following required module is not loaded: $mod"
exit 1
fi
done
load_module $modname
RC=$?
if [ $RC -eq 0 ];then
echo "OK"
log_msg "$modname loaded."
else
echo "Failed to load $modname"
log_msg "Failed to load $modname"
fi
return $RC
}
stop()
{
local RC=0
echo -n "stopping... "
if is_module $modname ; then
/sbin/rmmod $modname 2>&1
RC=$?
if [ $RC -eq 0 ];then
echo "OK"
log_msg "$modname unloaded."
else
echo "Failed to unload $modname"
log_msg "Failed to unload $modname"
fi
else
echo "OK"
fi
return $RC
}
status()
{
if is_module $modname ; then
echo "$modname module is loaded."
else
echo "$modname module is NOT loaded."
fi
}
RC=0
case $ACTION in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
status
;;
*)
echo
echo "Usage: `basename $0` {start|stop|restart|status}"
echo
exit 1
;;
esac
RC=$?
exit $RC