6
# Description: Enables/Disables SCSI devices to protect them from being
10
# Author: Alan Robertson
11
# Support: linux-ha@lists.linux-ha.org
12
# License: GNU General Public License (GPL)
13
# Copyright: (C) 2002 - 2005 IBM
15
# CAVEATS: See the usage message for some important warnings
17
# usage: ./LinuxSCSI (start|stop|status|monitor|meta-data|validate-all|methods)
19
# OCF parameters are as below:
22
# An example usage in /etc/ha.d/haresources:
23
# node1 10.0.0.170 LinuxSCSI:0:0:11
26
#######################################################################
29
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
30
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
32
#######################################################################
36
PROCSCSI=/proc/scsi/scsi
40
usage: $0 (start|stop|status|monitor|meta-data|validate-all|methods)
42
$0 manages the availability of a SCSI device from the point
43
of view of the linux kernel. It make Linux believe the
44
device has gone away, and it can make it come back again.
46
The purpose of this resource script is to keep admins from
47
accidentally messing with a shared disk that is managed by the
48
HA subsystem and is currently owned by the other side.
50
To get maximum benefit from this feature, you should (manually)
51
disable the resources on boot, and let your HA software enable
52
them when it wants to acquire the disk.
54
The kernel code says this is potentially dangerous. DO NOT USE
55
IT ON AN ACTIVE DEVICE. If the device is inactive, this script
56
will make it stay inactive, when given "off". If you inactivate
57
the wrong device, you may have to reboot your machine, and your
60
On the other hand, at least one RAID controller requires the
61
use of this technique for it to work correctly in a failover
62
environment - so it is believed that it is more stable in this
63
usage than the comments in the code imply.
65
Here are the warnings from the kernel source about the "stop"
66
operation as of 2.4.10:
68
------------------------------
69
Consider this feature pre-BETA.
70
CAUTION: This is not for hotplugging your peripherals. As
71
SCSI was not designed for this, you could damage your
72
hardware and thoroughly confuse the SCSI subsystem.
74
Similar warnings apply to the "start" operation...
76
Consider this feature BETA.
77
CAUTION: This is not for hotplugging your peripherals.
78
As SCSI was not designed for this you could damage your
80
However perhaps it is legal to switch on an already connected
81
device. It is perhaps not guaranteed this device doesn't corrupt
82
an ongoing data transfer.
83
-------------------------
85
So, Caveat Emptor, and test this feature thoroughly on
86
your kernel and your configuration with real load on the SCSI
87
bus before using it in production!
89
Another potential trouble spot...
90
The order in which you bring up LinuxSCSI resources determines which
91
SCSI device they show up as on Linux. If you have two SCSI devices
92
in different resource groups they will be brought up asyncronously
93
resulting in indeterminate device name assignments. This usually
94
happens in an active-active configuration.
96
To solve this you probably should use LVM or EVMS to manage these
97
volumes. LVM and EVMS solve this problem for you by labels they
98
keep in the volumes. If you don't use a reasonable volume manager,
99
then you'll have to mount by UUID.
106
<?xml version="1.0"?>
107
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
108
<resource-agent name="LinuxSCSI">
109
<version>1.0</version>
112
Deprecation warning: This agent makes use of Linux SCSI hot-plug
113
functionality which has been superseded by SCSI reservations. It is
114
deprecated and may be removed from a future release. See the
115
scsi2reservation and sfex agents for alternatives. --
116
This is a resource agent for LinuxSCSI. It manages the availability of a
117
SCSI device from the point of view of the linux kernel. It make Linux
118
believe the device has gone away, and it can make it come back again.
120
<shortdesc lang="en">Enables and disables SCSI devices through the
121
kernel SCSI hot-plug subsystem (deprecated)</shortdesc>
124
<parameter name="scsi" unique="0" required="1">
126
The SCSI instance to be managed.
128
<shortdesc lang="en">SCSI instance</shortdesc>
129
<content type="string" default="" />
132
<parameter name="ignore_deprecation">
134
If set to true, suppresses the deprecation warning for this agent.
136
<shortdesc lang="en">Suppress deprecation warning</shortdesc>
137
<content type="boolean" default="false" />
143
<action name="start" timeout="20s" />
144
<action name="stop" timeout="20s" />
145
<action name="methods" timeout="5" />
146
<action name="status" depth="0" timeout="20s" interval="10" />
147
<action name="monitor" depth="0" timeout="20s" interval="10" />
148
<action name="meta-data" timeout="5" />
149
<action name="validate-all" timeout="5" />
171
[0-9]*:[0-9]*:[0-9]*);;
173
[0-9]*:[0-9]*:[0-9]*:[0-9]*)
174
lun=`echo "$1" | cut -d: -f4`;;
180
ocf_log err "Invalid SCSI instance $1"
183
host=`echo "$1" | cut -d: -f1`
184
channel=`echo "$1" | cut -d: -f2`
185
target=`echo "$1" | cut -d: -f3`
189
# start: Enable the given SCSI device in the kernel
193
# [ $target = error ] && exit 1
194
# echo "scsi-add-single-device $host $channel $target $lun" >>$PROCSCSI
195
echo "scsi add-single-device $host $channel $target $lun" >>$PROCSCSI
201
ocf_log err "SCSI device $1 not active!"
202
return $OCF_ERR_GENERIC
208
# stop: Disable the given SCSI device in the kernel
212
# [ $target = error ] && exit 1
213
echo "scsi remove-single-device $host $channel $target $lun" >>$PROCSCSI
217
ocf_log err "SCSI device $1 still active!"
218
return $OCF_ERR_GENERIC
226
# status: is the given device now available?
230
# [ $target = error ] && exit 1
231
[ $channel -eq 0 ] && channel=$zeropat
232
[ $target -eq 0 ] && target=$zeropat
233
[ $lun -eq 0 ] && lun=$zeropat
234
greppat="Host: *scsi$host *Channel: *$channel *Id: *$target *Lun: *$lun"
235
grep -i "$greppat" $PROCSCSI >/dev/null
236
if [ $? -eq 0 ]; then
239
return $OCF_NOT_RUNNING
244
# validate_all: Check the OCF instance parameters
246
scsi_validate_all() {
254
ocf_log err "Parameter number error."
256
exit $OCF_ERR_GENERIC
260
# [ -z "$OCF_RESKEY_scsi" ] && [ "X$1" = "Xmethods" ]
266
methods) scsi_methods
278
# Be obnoxious, log deprecation warning on every invocation (unless
279
# suppressed by resource configuration).
283
[ -z "$OCF_RESKEY_scsi" ]
285
ocf_log err "You have to set a valid scsi id at least!"
287
exit $OCF_ERR_GENERIC
290
instance=$OCF_RESKEY_scsi
293
start) scsi_start $instance
295
stop) scsi_stop $instance
299
scsi_status $instance
301
ocf_log info "SCSI device $instance is running"
304
ocf_log info "SCSI device $instance is stopped"
305
exit $OCF_NOT_RUNNING
308
validate-all) scsi_validate_all
311
exit $OCF_ERR_UNIMPLEMENTED