3 # OCF resource agent for mapping and unmapping
4 # RADOS Block Devices (RBDs)
6 # License: GNU Lesser General Public License (LGPL) 2.1 or 3.0
7 # (c) 2012 Florian Haas, hastexo
11 : ${OCF_FUNCTIONS_DIR=${OCF_ROOT}/lib/heartbeat}
12 .
${OCF_FUNCTIONS_DIR}/ocf-shellfuncs
14 # Convenience variables
15 # When sysconfdir isn't passed in as a configure flag,
16 # it's defined in terms of prefix
20 OCF_RESKEY_pool_default
="rbd"
21 OCF_RESKEY_cephconf_default
="@sysconfdir@/@PACKAGE_TARNAME@/@PACKAGE_TARNAME@.conf"
22 : ${OCF_RESKEY_pool=${OCF_RESKEY_pool_default}}
23 : ${OCF_RESKEY_cephconf=${OCF_RESKEY_cephconf_default}}
28 <!DOCTYPE resource-agent SYSTEM "ra-api-1.dtd">
29 <resource-agent name="rbd" version="0.1">
30 <version>0.1</version>
32 Manages RADOS Block Devices (RBDs) as a highly available
33 resource. Maps and unmaps RBDs as needed.
35 <shortdesc lang="en">Maps and unmaps RADOS Block Devices</shortdesc>
37 <parameter name="name" unique="0" required="1">
39 Name of the RBD device.
41 <shortdesc lang="en">RBD device name</shortdesc>
42 <content type="string"/>
44 <parameter name="pool_namespace" unique="0" required="0">
46 Name of the RADOS pool namespace where the RBD has been created
48 <shortdesc lang="en">RADOS pool namespace name</shortdesc>
50 <parameter name="pool" unique="0" required="0">
52 Name of the RADOS pool where the RBD has been created
54 <shortdesc lang="en">RADOS pool name</shortdesc>
55 <content type="string" default="${OCF_RESKEY_pool_default}"/>
57 <parameter name="snap" unique="0" required="0">
59 Name of the device snapshot to map.
61 <shortdesc lang="en">Snapshot name</shortdesc>
62 <content type="string"/>
64 <parameter name="cephconf" unique="0" required="0">
66 Location of the Ceph configuration file
68 <shortdesc lang="en">Ceph configuration file</shortdesc>
69 <content type="string" default="${OCF_RESKEY_cephconf_default}"/>
71 <parameter name="mon" unique="0" required="0">
73 Address (or comma-separated list of addresses) of
74 monitor servers to connect to. Overrides values from
77 <shortdesc lang="en">Monitor address(es)</shortdesc>
78 <content type="string"/>
80 <parameter name="user" unique="0" required="0">
82 Username to use when mapping the device. Required
83 if Ceph authentication is enabled on the monitor.
85 <shortdesc lang="en">Authentication username</shortdesc>
86 <content type="string"/>
88 <parameter name="secret" unique="0" required="0">
90 File containing an authentication secret. Required
91 if Ceph authentication is enabled on the monitor.
93 <shortdesc lang="en">Authentication secret file</shortdesc>
94 <content type="string"/>
98 <action name="start" timeout="20" />
99 <action name="stop" timeout="20" />
100 <action name="monitor" timeout="20"
101 interval="10" depth="0" />
102 <action name="meta-data" timeout="5" />
103 <action name="validate-all" timeout="20" />
111 usage: $0 {start|stop|status|monitor|validate-all|meta-data}
113 Expects to have a fully populated OCF RA-compliant environment set.
120 if [ -n "${OCF_RESKEY_cephconf}" ]; then
121 rbd_options
="$rbd_options -c ${OCF_RESKEY_cephconf}"
123 if [ -n "${OCF_RESKEY_mon}" ]; then
124 rbd_options
="$rbd_options -m ${OCF_RESKEY_mon}"
127 echo "${rbd_options}"
131 # rbd command wrapper: builds an option string for invoking RBD based
132 # on resource parameters, and invokes rbd through ocf_run.
134 local rbd_options
="$(get_rbd_options)"
136 ocf_run rbd
$rbd_options $@
139 # Convenience function that uses "rbd device list" to retrieve the
140 # mapped device name from the pool, RBD name, and snapshot.
142 local rbd_options
="$(get_rbd_options)"
145 # Example output from "rbd device list" (tab separated):
146 # id pool namespace image snap device
147 # 0 rbd test - /dev/rbd0
148 # 1 rbd ns1 test - /dev/rbd1
150 # Build the sed pattern, substituting "-" for the snapshot name if
152 sedpat
="[0-9]\+[ \t]\+${OCF_RESKEY_pool}[ \t]\+${OCF_RESKEY_pool_namespace}[ \t]\+${OCF_RESKEY_name}[ \t]\+${OCF_RESKEY_snap:--}[ \t]\+\(/dev/rbd[0-9]\+\).*"
154 # Run "rbd device list", filter out the header line, then try to
155 # extract the device name
156 rbd
$rbd_options device list |
tail -n +2 |
sed -n -e "s,$sedpat,\1,p"
160 # Test for configuration errors first
161 if [ -z "$OCF_RESKEY_name" ]; then
162 ocf_log err
'Required parameter "name" is unset!'
163 exit $OCF_ERR_CONFIGURED
166 # Test for required binaries
176 if ! [ -d /sys
/bus
/rbd
]; then
177 ocf_log debug
"rbd module is not loaded"
178 return $OCF_NOT_RUNNING
181 rbd_dev
=`find_rbd_dev`
183 if [ -z "$rbd_dev" ]; then
184 ocf_log debug
"RBD device is unmapped"
186 elif [ -b "$rbd_dev" ]; then
187 ocf_log debug
"RBD device is mapped to $rbd_dev"
190 # Device is listed, but the corresponding path is not a block
192 ocf_log err
"$rbd_dev is not a block device!"
200 local rbd_map_options
203 # if resource is already running, bail out early
205 ocf_log info
"Resource is already running"
209 # actually start up the resource here (make sure to immediately
210 # exit with an $OCF_ERR_ error code if anything goes seriously
213 if [ ! -d /sys
/bus
/rbd
]; then
214 ocf_run modprobe
-v rbd ||
exit $OCF_ERR_INSTALLED
217 if [ -n "${OCF_RESKEY_user}" ]; then
218 rbd_map_options
="--id ${OCF_RESKEY_user}"
220 if [ -n "${OCF_RESKEY_secret}" ]; then
221 rbd_map_options
="$rbd_map_options --keyfile ${OCF_RESKEY_secret}"
224 rbd_name
="${OCF_RESKEY_pool}"
225 if [ -n "${OCF_RESKEY_pool_namespace}" ]; then
226 rbd_name
="${rbd_name}/${OCF_RESKEY_pool_namespace}"
228 rbd_name
="${rbd_name}/${OCF_RESKEY_name}"
229 if [ -n "${OCF_RESKEY_snap}" ]; then
230 rbd_name
="${rbd_name}@${OCF_RESKEY_snap}"
233 do_rbd device map
$rbd_name $rbd_map_options ||
exit $OCF_ERR_GENERIC
235 # After the resource has been started, check whether it started up
236 # correctly. If the resource starts asynchronously, the agent may
237 # spin on the monitor function here -- if the resource does not
238 # start up within the defined timeout, the cluster manager will
239 # consider the start action failed
240 while ! rbd_monitor
; do
241 ocf_log debug
"Resource has not started yet, waiting"
245 # only return $OCF_SUCCESS if _everything_ succeeded as expected
257 # Currently running. Normal, expected behavior.
258 ocf_log debug
"Resource is currently running"
261 # Currently not running. Nothing to do.
262 ocf_log info
"Resource is already stopped"
267 # actually shut down the resource here (make sure to immediately
268 # exit with an $OCF_ERR_ error code if anything goes seriously
270 rbd_dev
=`find_rbd_dev`
271 do_rbd device unmap
$rbd_dev ||
exit $OCF_ERR_GENERIC
273 # After the resource has been stopped, check whether it shut down
274 # correctly. If the resource stops asynchronously, the agent may
275 # spin on the monitor function here -- if the resource does not
276 # shut down within the defined timeout, the cluster manager will
277 # consider the stop action failed
278 while rbd_monitor
; do
279 ocf_log debug
"Resource has not stopped yet, waiting"
283 # only return $OCF_SUCCESS if _everything_ succeeded as expected
288 # Make sure meta-data and usage always succeed
289 case $__OCF_ACTION in
290 meta-data
) rbd_meta_data
293 usage|
help) rbd_usage
298 # Anything other than meta-data and usage must pass validation
299 rbd_validate_all ||
exit $?
301 # Translate each action into the appropriate function call
302 case $__OCF_ACTION in
305 status|monitor
) rbd_monitor
;;
308 exit $OCF_ERR_UNIMPLEMENTED
313 # The resource agent may optionally log a debug message
314 ocf_log debug
"${OCF_RESOURCE_INSTANCE} $__OCF_ACTION returned $rc"