~ubuntu-branches/debian/stretch/resource-agents/stretch

« back to all changes in this revision

Viewing changes to heartbeat/LinuxSCSI

  • Committer: Bazaar Package Importer
  • Author(s): Andres Rodriguez
  • Date: 2011-06-10 16:26:35 UTC
  • Revision ID: james.westby@ubuntu.com-20110610162635-yiy0vfopqw4trzgx
Tags: upstream-3.9.0
ImportĀ upstreamĀ versionĀ 3.9.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
#
 
3
#
 
4
# LinuxSCSI
 
5
#
 
6
# Description:  Enables/Disables SCSI devices to protect them from being
 
7
#               used by mistake
 
8
#
 
9
#
 
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
 
14
#
 
15
# CAVEATS:      See the usage message for some important warnings
 
16
#
 
17
# usage: ./LinuxSCSI (start|stop|status|monitor|meta-data|validate-all|methods)
 
18
#
 
19
#         OCF parameters are as below:
 
20
#               OCF_RESKEY_scsi
 
21
#
 
22
# An example usage in /etc/ha.d/haresources:
 
23
#       node1  10.0.0.170 LinuxSCSI:0:0:11
 
24
#
 
25
 
 
26
#######################################################################
 
27
# Initialization:
 
28
 
 
29
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
 
30
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
 
31
 
 
32
#######################################################################
 
33
 
 
34
zeropat="[ 0]0"
 
35
 
 
36
PROCSCSI=/proc/scsi/scsi
 
37
 
 
38
usage() {
 
39
  cat <<EOF
 
40
        usage: $0 (start|stop|status|monitor|meta-data|validate-all|methods)
 
41
 
 
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.
 
45
 
 
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.
 
49
 
 
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.
 
53
        
 
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
 
58
        data may take a hit.
 
59
 
 
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.
 
64
 
 
65
        Here are the warnings from the kernel source about the "stop"
 
66
        operation as of 2.4.10:
 
67
 
 
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.
 
73
 
 
74
        Similar warnings apply to the "start" operation...
 
75
 
 
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
 
79
             hardware !
 
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
        -------------------------
 
84
 
 
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!
 
88
 
 
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.
 
95
        
 
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.
 
100
 
 
101
EOF
 
102
}
 
103
 
 
104
meta_data() {
 
105
        cat <<EOF
 
106
<?xml version="1.0"?>
 
107
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
 
108
<resource-agent name="LinuxSCSI">
 
109
<version>1.0</version>
 
110
 
 
111
<longdesc lang="en">
 
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.
 
119
</longdesc>
 
120
<shortdesc lang="en">Enables and disables SCSI devices through the
 
121
kernel SCSI hot-plug subsystem (deprecated)</shortdesc>
 
122
 
 
123
<parameters>
 
124
<parameter name="scsi" unique="0" required="1">
 
125
<longdesc lang="en">
 
126
The SCSI instance to be managed.
 
127
</longdesc>
 
128
<shortdesc lang="en">SCSI instance</shortdesc>
 
129
<content type="string" default="" />
 
130
</parameter>
 
131
 
 
132
<parameter name="ignore_deprecation">
 
133
<longdesc lang="en">
 
134
If set to true, suppresses the deprecation warning for this agent.
 
135
</longdesc>
 
136
<shortdesc lang="en">Suppress deprecation warning</shortdesc>
 
137
<content type="boolean" default="false" />
 
138
</parameter>
 
139
 
 
140
</parameters>
 
141
 
 
142
<actions>
 
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" />
 
150
</actions>
 
151
</resource-agent>
 
152
EOF
 
153
}
 
154
 
 
155
scsi_methods() {
 
156
  cat <<EOF
 
157
        start
 
158
        stop
 
159
        status
 
160
        monitor
 
161
        validate-all
 
162
        methods
 
163
EOF
 
164
}
 
165
 
 
166
 
 
167
parseinst() {
 
168
  lun=0
 
169
  case "$1" in
 
170
        
 
171
    [0-9]*:[0-9]*:[0-9]*);;
 
172
 
 
173
    [0-9]*:[0-9]*:[0-9]*:[0-9]*)
 
174
        lun=`echo "$1" | cut -d: -f4`;;
 
175
 
 
176
    *)  #host=error
 
177
        #channel=error
 
178
        #target=error
 
179
        #lun=error
 
180
        ocf_log err "Invalid SCSI instance $1"
 
181
        exit $OCF_ERR_ARGS
 
182
  esac
 
183
  host=`echo "$1" | cut -d: -f1`
 
184
  channel=`echo "$1" | cut -d: -f2`
 
185
  target=`echo "$1" | cut -d: -f3`
 
186
}
 
187
 
 
188
#
 
189
# start: Enable the given SCSI device in the kernel
 
190
#
 
191
scsi_start() {
 
192
  parseinst "$1"
 
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
 
196
  if
 
197
    scsi_status "$1"
 
198
  then
 
199
    return $OCF_SUCCESS
 
200
  else
 
201
    ocf_log err "SCSI device $1 not active!"
 
202
    return $OCF_ERR_GENERIC
 
203
  fi
 
204
}
 
205
 
 
206
 
 
207
#
 
208
# stop: Disable the given SCSI device in the kernel
 
209
#
 
210
scsi_stop() {
 
211
  parseinst "$1"
 
212
#  [ $target = error ] && exit 1
 
213
  echo "scsi remove-single-device $host $channel $target $lun" >>$PROCSCSI
 
214
  if
 
215
    scsi_status "$1"
 
216
  then
 
217
    ocf_log err "SCSI device $1 still active!"
 
218
    return $OCF_ERR_GENERIC
 
219
  else
 
220
    return $OCF_SUCCESS
 
221
  fi
 
222
}
 
223
 
 
224
 
 
225
#
 
226
# status: is the given device now available?
 
227
#
 
228
scsi_status() {
 
229
  parseinst "$1"
 
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
 
237
        return $OCF_SUCCESS
 
238
  else
 
239
        return $OCF_NOT_RUNNING
 
240
  fi
 
241
}
 
242
 
 
243
#
 
244
# validate_all: Check the OCF instance parameters
 
245
#
 
246
scsi_validate_all() {
 
247
  parseinst $instance
 
248
  return $OCF_SUCCESS
 
249
}
 
250
 
 
251
if
 
252
  ( [ $# -ne 1 ] )
 
253
then
 
254
  ocf_log err "Parameter number error."
 
255
  usage
 
256
  exit $OCF_ERR_GENERIC
 
257
fi
 
258
 
 
259
#if
 
260
#  [ -z "$OCF_RESKEY_scsi" ] && [ "X$1" = "Xmethods" ]
 
261
#then
 
262
#  scsi_methods
 
263
#  exit #?
 
264
#fi
 
265
case $1 in
 
266
  methods)              scsi_methods
 
267
                        exit $OCF_SUCCESS
 
268
                        ;;
 
269
  meta-data)            meta_data
 
270
                        exit $OCF_SUCCESS
 
271
                        ;;
 
272
  usage)                usage
 
273
                        exit $OCF_SUCCESS
 
274
                        ;;
 
275
  *)                    ;;
 
276
esac
 
277
 
 
278
# Be obnoxious, log deprecation warning on every invocation (unless
 
279
# suppressed by resource configuration).
 
280
ocf_deprecated
 
281
 
 
282
if
 
283
  [ -z "$OCF_RESKEY_scsi" ]
 
284
then
 
285
  ocf_log err "You have to set a valid scsi id at least!"
 
286
#  usage
 
287
  exit $OCF_ERR_GENERIC
 
288
fi
 
289
 
 
290
instance=$OCF_RESKEY_scsi
 
291
 
 
292
case $1 in
 
293
  start)                scsi_start $instance
 
294
                        ;;
 
295
  stop)                 scsi_stop $instance
 
296
                        ;;
 
297
  status|monitor)       
 
298
                        if
 
299
                          scsi_status $instance
 
300
                        then
 
301
                          ocf_log info "SCSI device $instance is running"
 
302
                          return $OCF_SUCCESS
 
303
                        else
 
304
                          ocf_log info "SCSI device $instance is stopped"
 
305
                          exit $OCF_NOT_RUNNING
 
306
                        fi
 
307
                        ;;
 
308
  validate-all)         scsi_validate_all
 
309
                        ;;
 
310
  *)                    usage
 
311
                        exit $OCF_ERR_UNIMPLEMENTED
 
312
                        ;;
 
313
esac
 
314
exit $?