Skip to content

Commit

Permalink
Merge pull request ceph#2092 from onlyjob/rbdmap
Browse files Browse the repository at this point in the history
rbdmap: per-device mount (Closes: ceph#8538)

Reviewed-by: Sage Weil <[email protected]>
  • Loading branch information
Sage Weil committed Jul 11, 2014
2 parents 02683ac + b844ec9 commit bf04897
Showing 1 changed file with 47 additions and 27 deletions.
74 changes: 47 additions & 27 deletions src/init-rbdmap
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Description: Ceph RBD Mapping
### END INIT INFO

DESC="RBD Mapping"
DESC="RBD Mapping:"
RBDMAPFILE="/etc/ceph/rbdmap"

. /lib/lsb/init-functions
Expand All @@ -29,9 +29,7 @@ do_map() {
exit 0
fi

log_daemon_msg "Starting $DESC"
# Read /etc/rbdtab to create non-existant mapping
newrbd=
RET=0
while read DEV PARAMS; do
case "$DEV" in
Expand All @@ -44,46 +42,70 @@ do_map() {
DEV=rbd/$DEV
;;
esac
log_action_begin_msg "${DESC} '${DEV}'"
newrbd=""
MAP_RV=""
RET_OP=0
OIFS=$IFS
IFS=','
for PARAM in ${PARAMS[@]}; do
CMDPARAMS="$CMDPARAMS --$(echo $PARAM | tr '=' ' ')"
done
IFS=$OIFS
if [ ! -b /dev/rbd/$DEV ]; then
log_progress_msg $DEV
rbd map $DEV $CMDPARAMS
[ $? -ne "0" ] && RET=1
newrbd="yes"
MAP_RV=$(rbd map $DEV $CMDPARAMS 2>&1)
if [ $? -eq 0 ]; then
newrbd="yes"
else
RET=$((${RET}+$?))
RET_OP=1
fi
fi
log_action_end_msg ${RET_OP} "${MAP_RV}"

if [ "$newrbd" ]; then
## Mount new rbd
MNT_RV=""
mount --fake /dev/rbd/$DEV >>/dev/null 2>&1 \
&& MNT_RV=$(mount -v /dev/rbd/$DEV 2>&1)
[ -n "${MNT_RV}" ] && log_action_msg "mount: ${MNT_RV}"
fi
done < $RBDMAPFILE
log_end_msg $RET
exit ${RET}

# Mount new rbd
if [ "$newrbd" ]; then
log_action_begin_msg "Mounting all filesystems"
mount -a
log_action_end_msg $?
fi
}

do_unmap() {
log_daemon_msg "Stopping $DESC"
RET=0
# Recursive umount that depends /dev/rbd*
MNTDEP=$(findmnt --mtab | awk '$2 ~ /^\/dev\/rbd[0-9]*$/ {print $1}' | sort -r)
for MNT in $MNTDEP; do
umount $MNT
done
# Unmap all rbd device
## Unmount and unmap all rbd devices
if ls /dev/rbd[0-9]* >/dev/null 2>&1; then
for DEV in /dev/rbd[0-9]*; do
log_progress_msg $DEV
rbd unmap $DEV
[ $? -ne "0" ] && RET=1
log_action_begin_msg "RBD un-mapping: '${DEV}'"
UMNT_RV=""
UMAP_RV=""
RET_OP=0
MNT=$(findmnt --mtab --source ${DEV} --noheadings | awk '{print $1'})
if [ -n "${MNT}" ]; then
log_action_cont_msg "un-mounting '${MNT}'"
UMNT_RV=$(umount "${MNT}" 2>&1)
fi
if mountpoint -q "${MNT}"; then
## Un-mounting failed.
RET_OP=1
RET=$((${RET}+1))
else
## Un-mapping.
UMAP_RV=$(rbd unmap $DEV 2>&1)
if [ $? -ne 0 ]; then
RET=$((${RET}+$?))
RET_OP=1
fi
fi
log_action_end_msg ${RET_OP} "${UMAP_RV}"
[ -n "${UMNT_RV}" ] && log_action_msg "${UMNT_RV}"
done
fi
log_end_msg $RET
exit ${RET}
}


Expand Down Expand Up @@ -114,5 +136,3 @@ case "$1" in
exit 1
;;
esac

exit 0

0 comments on commit bf04897

Please sign in to comment.