7 for (( i=0; i<${#PARAMS}; i++ )); do
14 if [ "$STATE" == "INQUOTE" ];then
21 if [ "$STATE" == "INQUOTE" ]; then
22 CMDPARAMS="${CMDPARAMS}${CHAR}"
24 CMDPARAMS="${CMDPARAMS} "
28 if [ "$STATE" == "INQUOTE" ]; then
29 CMDPARAMS="${CMDPARAMS}${CHAR}"
30 elif [ "$STATE" == "START" ]; then
32 CMDPARAMS="${CMDPARAMS} --"
34 CMDPARAMS="${CMDPARAMS} --"
38 if [ "$STATE" == "START" ];then
40 CMDPARAMS="${CMDPARAMS}--${CHAR}"
42 CMDPARAMS="${CMDPARAMS}${CHAR}"
51 # Read /etc/rbdtab to create non-existant mapping
53 while read DEV PARAMS; do
65 CMDPARAMS="$(create_cmd_params "${PARAMS}")"
66 logger -p "daemon.debug" -t rbdmap "Mapping '${DEV}'"
70 if [ -b /dev/rbd/$DEV ]; then
71 MAP_RV="$(readlink -f /dev/rbd/$DEV)"
73 MAP_RV="$(rbd device map $DEV $CMDPARAMS 2>&1)"
78 logger -p "daemon.warning" -t rbdmap "Failed to map '${DEV}"
82 logger -p "daemon.debug" -t rbdmap "Mapped '${DEV}' to '${MAP_RV}'"
84 if [ "$newrbd" ]; then
87 mount --fake /dev/rbd/$DEV >>/dev/null 2>&1 \
88 && MNT_RV=$(mount -vn /dev/rbd/$DEV 2>&1)
89 [ -n "${MNT_RV}" ] && logger -p "daemon.debug" -t rbdmap "Mounted '${MAP_RV}' to '${MNT_RV}'"
92 if [ -x "/etc/ceph/rbd.d/${DEV}" ]; then
93 logger -p "daemon.debug" -t rbdmap "Running post-map hook '/etc/ceph/rbd.d/${DEV}'"
94 /etc/ceph/rbd.d/${DEV} map "/dev/rbd/${DEV}"
104 local mnts=$(findmnt --mtab --source ${rbd_dev} --noheadings \
107 logger -p "daemon.debug" -t rbdmap "Unmapping '${rbd_dev}'"
108 for mnt in ${mnts}; do
109 logger -p "daemon.debug" -t rbdmap "Unmounting '${mnt}'"
110 umount "${mnt}" >>/dev/null 2>&1
111 if mountpoint -q "${mnt}"; then
112 ## Un-mounting failed.
113 logger -p "daemon.warning" -t rbdmap "Failed to unmount '${mnt}'"
118 rbd device unmap $rbd_dev >>/dev/null 2>&1
119 if [ $? -ne 0 ]; then
120 logger -p "daemon.warning" -t rbdmap "Failed to unmap '${mnt}'"
123 logger -p "daemon.debug" -t rbdmap "Unmapped '${rbd_dev}'"
130 ## Unmount and unmap all rbd devices
131 if ls /dev/rbd[0-9]* >/dev/null 2>&1; then
132 for DEV in /dev/rbd[0-9]*; do
134 for L in $(find /dev/rbd -type l); do
136 if [ "$(readlink -f $L)" = "${DEV}" ] \
137 && [ -x "/etc/ceph/rbd.d/${LL}" ]; then
138 logger -p "daemon.debug" -t rbdmap "Running pre-unmap hook for '${DEV}': '/etc/ceph/rbd.d/${LL}'"
139 /etc/ceph/rbd.d/${LL} unmap "$L"
144 unmount_unmap "$DEV" || RET=$((${RET}+$?))
153 ## skip if nothing is mapped
154 ls /dev/rbd[0-9]* >/dev/null 2>&1 || exit ${RET}
156 # Read /etc/rbdtab to create non-existant mapping
157 while read DEV PARAMS; do
169 MAP_RV="$(readlink -f /dev/rbd/$DEV)"
170 if [ ! -b $MAP_RV ]; then
171 logger -p "daemon.debug" -t rbdmap "$DEV not mapped, skipping unmap"
176 if [ -x "/etc/ceph/rbd.d/${DEV}" ]; then
177 logger -p "daemon.debug" -t rbdmap "Running pre-unmap hook '/etc/ceph/rbd.d/${DEV}'"
178 /etc/ceph/rbd.d/${DEV} unmap "/dev/rbd/${DEV}"
181 unmount_unmap "$MAP_RV" || RET=$((${RET}+$?))
187 # default to reasonable value if RBDMAPFILE not set in environment
188 RBDMAPFILE="${RBDMAPFILE:-/etc/ceph/rbdmap}"
190 if [ ! -f "$RBDMAPFILE" ]; then
191 logger -p "daemon.warning" -t rbdmap "No $RBDMAPFILE found."
209 echo "Usage: rbdmap map | unmap | unmap-all"