summaryrefslogtreecommitdiffstats
path: root/heartbeat/scsi2reservation
blob: 9b29ec460805911ff85efd0d10ea9b97ed7196e3 (plain)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
#!/bin/sh
# by hxinwei@gmail.com
# License: GNU General Public License 2 (GPL2)

if [ -n "$OCF_DEBUG_LIBRARY" ]; then
    . $OCF_DEBUG_LIBRARY
else
    : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
. ${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
fi

# Parameter defaults

OCF_RESKEY_scsi_reserve_default="/usr/sbin/scsi_reserve"
OCF_RESKEY_sharedisk_default="/dev/sdb"
OCF_RESKEY_start_loop_default="10"

: ${OCF_RESKEY_scsi_reserve=${OCF_RESKEY_scsi_reserve_default}}
: ${OCF_RESKEY_sharedisk=${OCF_RESKEY_sharedisk_default}}
: ${OCF_RESKEY_start_loop=${OCF_RESKEY_start_loop_default}}

scsi2reserve_meta_data() {
	cat <<END
<?xml version="1.0"?>
<!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
<resource-agent name="scsi2reservation" version="1.0">
<version>1.0</version>

<longdesc lang="en">
The scsi-2-reserve resource agent is a place holder for SCSI-2 reservation.
A healthy instance of scsi-2-reserve resource, indicates the own of the specified SCSI device.
This resource agent depends on the scsi_reserve from scsires package, which is Linux specific.
</longdesc>

<shortdesc lang="en">
scsi-2 reservation
</shortdesc>

<parameters>

<parameter name="scsi_reserve" unique="0" required="0">
<longdesc lang="en">
The scsi_reserve is a command from scsires package. 
It helps one to issue SCSI-2 reservation on SCSI devices.
</longdesc>
<shortdesc lang="en">Manages exclusive access to shared storage media thrugh SCSI-2 reservations</shortdesc>
<content type="string" default="${OCF_RESKEY_scsi_reserve_default}" />
</parameter>


<parameter name="sharedisk" unique="0" required="0">
<longdesc lang="en">
The shared disk that can be reserved.
</longdesc>
<shortdesc lang="en">
Shared disk.
</shortdesc>
<content type="string" default="${OCF_RESKEY_sharedisk_default}" />
</parameter>

<parameter name="start_loop" unique="0" required="0">
<longdesc lang="en">
We are going to try several times before giving up. Start_loop indicates how many times we are going to re-try.
</longdesc>
<shortdesc lang="en">
Times to re-try before giving up.
</shortdesc>
<content type="string" default="${OCF_RESKEY_start_loop_default}" />
</parameter>


</parameters>

<actions>
<action name="start"   timeout="300s" />
<action name="stop"    timeout="100s" />
<action name="monitor" depth="0"  timeout="20s" interval="20s" />
<action name="meta-data"  timeout="5s" />
<action name="validate-all"  timeout="30s" />
</actions>
</resource-agent>
END

	return $OCF_SUCCESS
}

scsi2reserve_usage() {
	cat <<END
		usage: $0 {start|stop|monitor|validate-all|meta-data}
END
}

case $__OCF_ACTION in
	meta-data)  scsi2reserve_meta_data
		exit $OCF_SUCCESS
		;;
	usage|help) scsi2reserve_usage
		exit $OCF_SUCCESS
		;;
	*)
		;;
esac		
	

scsi2reserve_validate ()
{
	if [ ! -x "${OCF_RESKEY_scsi_reserve}" ]; then
		exit $OCF_ERR_INSTALLED
	fi
	if [ -z "${OCF_RESKEY_sharedisk}" ]; then
		exit $OCF_ERR_GENERIC
	fi	
	if [ ! -b "${OCF_RESKEY_sharedisk}" ]; then
		exit $OCF_ERR_ARGS
	fi
}

scsi2reserve_validate

scsi2reserve_start ()
{
	ite=$OCF_RESKEY_start_loop
	while [ $ite -ge 0 ]; do	
		/sbin/startproc ${OCF_RESKEY_scsi_reserve} -d ${OCF_RESKEY_sharedisk} --preempt --hold --stonith
		sleep 15
		/sbin/checkproc ${OCF_RESKEY_scsi_reserve}
		rc=$?
		if [ $rc -eq 0 ]; then
			exit $OCF_SUCCESS
		fi		
		ite=`expr $ite - 1`
	done	
	exit $OCF_ERR_GENERIC
}

scsi2reserve_monitor ()
{
	/sbin/checkproc ${OCF_RESKEY_scsi_reserve}
	rc=$?
	if [ $rc -eq 0 ]; then
		exit $OCF_SUCCESS
	else
		exit $OCF_NOT_RUNNING
	fi	
}

scsi2reserve_stop ()
{
	/sbin/killproc ${OCF_RESKEY_scsi_reserve}
	${OCF_RESKEY_scsi_reserve} -d ${OCF_RESKEY_sharedisk} --release
	exit $OCF_SUCCESS
}

if [ $# -ne 1 ]; then
	scsi2reserve_usage
	exit $OCF_ERR_ARGS
fi

case $__OCF_ACTION in
	start)      scsi2reserve_start
		;;
	stop)       scsi2reserve_stop
		;;
	monitor)    scsi2reserve_monitor
		;;
	validate-all)   scsi2reserve_validate
			exit $OCF_SUCCESS
		;;
	*)      scsi2reserve_usage
		exit $OCF_ERR_UNIMPLEMENTED
	;;
esac

exit $?