3
# Shared Disk File EXclusiveness (SF-EX) OCF RA.
4
# prevent a destruction of data on shared disk file system
7
# This program is free software; you can redistribute it and/or
8
# modify it under the terms of the GNU General Public License
9
# as published by the Free Software Foundation; either version 2
10
# of the License, or (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
# Copyright (c) 2007 NIPPON TELEGRAPH AND TELEPHONE CORPORATION
25
# As a prerequisite for running SF-EX, one device should be
26
# initialized as below.
28
# sfex_init [-n <numlocks>] <device>
32
# /usr/sbin/sfex_init -n 10 /dev/sdb1
34
# if further information is necessary, See README.
36
#######################################################################
39
# switching ocf-shellfuncs path
40
: ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
41
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
43
#######################################################################
45
SFEX_DAEMON=${HA_BIN}/sfex_daemon
49
usage: $0 {start|stop|monitor|meta-data}
56
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
57
<resource-agent name="sfex">
58
<version>1.3</version>
61
Resource script for SF-EX. It manages a shared storage medium exclusively .
63
<shortdesc lang="en">Manages exclusive access to shared storage using Shared Disk File EXclusiveness (SF-EX)</shortdesc>
65
<parameter name="device" unique="0" required="1">
67
Block device path that stores exclusive control data.
69
<shortdesc lang="en">block device</shortdesc>
70
<content type="string" default="" />
72
<parameter name="index" unique="0" required="0">
74
Location in block device where exclusive control data is stored. 1 or more is specified. Default is 1.
76
<shortdesc lang="en">index</shortdesc>
77
<content type="integer" default="1" />
79
<parameter name="collision_timeout" unique="0" required="0">
81
Waiting time when a collision of lock acquisition is detected. Default is 1 second.
83
<shortdesc lang="en">waiting time for lock acquisition</shortdesc>
84
<content type="integer" default="1" />
86
<parameter name="monitor_interval" unique="0" required="0">
88
Monitor interval(sec). Default is 10 seconds
90
<shortdesc lang="en">monitor interval</shortdesc>
91
<content type="integer" default="10" />
93
<parameter name="lock_timeout" unique="0" required="0">
95
Valid term of lock(sec). Default is 100 seconds.
96
The lock_timeout is calculated by the following formula.
98
lock_timeout = monitor_interval + "The expiration time of the lock"
100
We suggest 90 seconds as a default value of the "The expiration time of the lock", but you should change it in consideration of access delay to the shared disk and the switch time of the multipath driver.
102
The lock timeout have an impact on start action timeout because start action timeout value is calculated by the following formula.
104
start timeout = collision_timeout + lock_timeout + "safety margin"
106
The "safety margin" is decided within the range of about 10-20 seconds(It depends on your system requirement).
108
<shortdesc lang="en">Valid term of lock</shortdesc>
109
<content type="integer" default="100" />
114
<action name="start" timeout="120s" />
115
<action name="stop" timeout="20s" />
116
<action name="monitor" depth="0" timeout="10s" interval="10s" />
117
<action name="meta-data" timeout="5s" />
118
<action name="validate-all" timeout="5s" />
125
# START: Exclusive control starts.
127
# It loops permanently until the lock can be acquired when locked with
128
# the other node. In this case, the reception of the stop signal by the
129
# timeout time passage set to CIB becomes the only stop opportunity.
132
ocf_log info "sfex_daemon: starting..."
135
if [ $? -eq $OCF_SUCCESS ]; then
136
ocf_log info "sfex_daemon already started."
140
$SFEX_DAEMON -i $INDEX -c $COLLISION_TIMEOUT -t $LOCK_TIMEOUT -m $MONITOR_INTERVAL -r ${OCF_RESOURCE_INSTANCE} $DEVICE
143
if [ $rc -ne 0 ]; then
144
ocf_log err "sfex_daemon failed to start."
145
return $OCF_ERR_GENERIC
151
if [ $? -eq $OCF_SUCCESS ]; then
152
ocf_log info "sfex_daemon: started."
155
ocf_log debug "Waiting for the start-up of the sfex_daemon..."
158
ocf_log err "Can't find a sfex_daemon process. Starting a sfex_daemon failed."
159
return $OCF_ERR_GENERIC
163
# STOP: stop exclusive control
166
ocf_log info "sfex_daemon: stopping..."
168
# Check the sfex daemon has already stopped.
170
if [ $? -eq $OCF_NOT_RUNNING ]; then
171
ocf_log info "sfex_daemon already stopped."
175
# Stop sfex daemon by sending SIGTERM signal.
176
pid=`/usr/bin/pgrep -f "$SFEX_DAEMON .* ${OCF_RESOURCE_INSTANCE} "`
179
if [ $rc -ne 0 ]; then
180
ocf_log err "sfex_daemon failed to stop"
184
#sfex could be in state D if the device is gone, and then not terminate.
185
#Wait and check again if the daemon is already properly shutdown.
187
shutdown_timeout=$((($OCF_RESKEY_CRM_meta_timeout/1000)-5))
189
while [ $count -lt $shutdown_timeout ]
192
if [ $? -eq $OCF_NOT_RUNNING ]; then
193
ocf_log info "sfex_daemon: stopped."
196
count=`expr $count + 1`
197
ocf_log debug "waiting for sfex_daemon to exit ($count/$shutdown_timeout)"
202
if [ $? -ne $OCF_NOT_RUNNING ]; then
203
ocf_log warn "regular shutdown of sfex_daemon timed out, using SIGKILL"
204
/bin/kill -s KILL $pid
210
if [ $? -eq $OCF_NOT_RUNNING ]; then
213
ocf_log debug "waiting for sfex_daemon to exit after SIGKILL"
217
ocf_log info "sfex_daemon: stopped."
222
ocf_log debug "sfex_monitor: started..."
224
# Find a sfex_daemon process using daemon name and resource name.
225
if /usr/bin/pgrep -f "$SFEX_DAEMON .* ${OCF_RESOURCE_INSTANCE} " > /dev/null 2>&1; then
226
ocf_log debug "sfex_monitor: complete. sfex_daemon is running."
230
ocf_log debug "sfex_monitor: complete. sfex_daemon is not running."
231
return $OCF_NOT_RUNNING
239
if [ $# -ne 1 ]; then
245
# These operations do not require instance parameters
258
DEVICE=$OCF_RESKEY_device
259
INDEX=${OCF_RESKEY_index:-1}
260
COLLISION_TIMEOUT=${OCF_RESKEY_collision_timeout:-1}
261
LOCK_TIMEOUT=${OCF_RESKEY_lock_timeout:-100}
262
MONITOR_INTERVAL=${OCF_RESKEY_monitor_interval:-10}
265
if [ -z "$DEVICE" ]; then
266
ocf_log err "Please set OCF_RESKEY_device to device for sfex meta-data"
269
if [ ! -w "$DEVICE" ]; then
270
ocf_log warn "Couldn't find device [$DEVICE]. Expected /dev/??? to exist"
275
if [ -n "$OCF_RESKEY_CRM_meta_clone" ]; then
276
ocf_log err "THIS RA DO NOT SUPPORT CLONE MODE!"
277
exit $OCF_ERR_CONFIGURED
294
exit $OCF_ERR_UNIMPLEMENTED