3
# rbdmap Ceph RBD Mapping
5
# chkconfig: 2345 20 80
6
# description: Ceph RBD Mapping
10
# Required-Start: $network $remote_fs
11
# Required-Stop: $network $remote_fs
14
# X-Start-Before: $x-display-manager
15
# Default-Start: 2 3 4 5
17
# Short-Description: Ceph RBD Mapping
18
# Description: Ceph RBD Mapping
22
RBDMAPFILE="/etc/ceph/rbdmap"
24
. /lib/lsb/init-functions
27
if [ ! -f "$RBDMAPFILE" ]; then
28
log_warning_msg "$DESC : No $RBDMAPFILE found."
32
# Read /etc/rbdtab to create non-existant mapping
34
while read DEV PARAMS; do
45
log_action_begin_msg "${DESC} '${DEV}'"
51
for PARAM in ${PARAMS[@]}; do
52
CMDPARAMS="$CMDPARAMS --$(echo $PARAM | tr '=' ' ')"
55
if [ ! -b /dev/rbd/$DEV ]; then
56
MAP_RV=$(rbd map $DEV $CMDPARAMS 2>&1)
64
log_action_end_msg ${RET_OP} "${MAP_RV}"
66
if [ "$newrbd" ]; then
69
mount --fake /dev/rbd/$DEV >>/dev/null 2>&1 \
70
&& MNT_RV=$(mount -v /dev/rbd/$DEV 2>&1)
71
[ -n "${MNT_RV}" ] && log_action_msg "mount: ${MNT_RV}"
74
if [ -x "/etc/ceph/rbd.d/${DEV}" ]; then
75
log_action_msg "RBD Running post-map hook '/etc/ceph/rbd.d/${DEV}'"
76
/etc/ceph/rbd.d/${DEV} map "/dev/rbd/${DEV}"
86
## Unmount and unmap all rbd devices
87
if ls /dev/rbd[0-9]* >/dev/null 2>&1; then
88
for DEV in /dev/rbd[0-9]*; do
90
for L in $(find /dev/rbd -type l); do
92
if [ "$(readlink -f $L)" = "${DEV}" ] \
93
&& [ -x "/etc/ceph/rbd.d/${LL}" ]; then
94
log_action_msg "RBD pre-unmap: '${DEV}' hook '/etc/ceph/rbd.d/${LL}'"
95
/etc/ceph/rbd.d/${LL} unmap "$L"
100
log_action_begin_msg "RBD un-mapping: '${DEV}'"
104
MNT=$(findmnt --mtab --source ${DEV} --noheadings | awk '{print $1'})
105
if [ -n "${MNT}" ]; then
106
log_action_cont_msg "un-mounting '${MNT}'"
108
local RUNLEVEL=$(runlevel | awk '{print $2}')
109
if [ $? -eq 0 ]; then
110
if [ "${RUNLEVEL}" -eq 0 ] \
111
|| [ "${RUNLEVEL}" -eq 6 ] ; then
113
if [ -x "$(which fuser)" ]; then
114
fuser -M -m "${MNT}" --kill -TERM
118
UMNT_RV=$(umount ${ULAZY} "${MNT}" 2>&1)
120
if mountpoint -q "${MNT}"; then
121
## Un-mounting failed.
126
UMAP_RV=$(rbd unmap $DEV 2>&1)
127
if [ $? -ne 0 ]; then
132
log_action_end_msg ${RET_OP} "${UMAP_RV}"
133
[ -n "${UMNT_RV}" ] && log_action_msg "${UMNT_RV}"
149
restart|force-reload)
163
log_success_msg "Usage: rbdmap {start|stop|restart|force-reload|reload|status}"