-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rbdmap: Move do_map and do_unmap shell functions to rbdmap script
This patch creates rbdmap shell script that is called from init-rbdmap init script. The patch also renames src/rbdmap configuration file to src/etc-rbdmap so that rbdmap shell script can be installed via build system directly. Finally, the patch accomodates these changes in spec file and build system. Fixes: #13374 Signed-off-by: Boris Ranto <branto@redhat.com>
- Loading branch information
Showing
9 changed files
with
128 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# RbdDevice Parameters | ||
#poolname/imagename id=client,keyring=/etc/ceph/ceph.client.keyring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,115 @@ | ||
# RbdDevice Parameters | ||
#poolname/imagename id=client,keyring=/etc/ceph/ceph.client.keyring | ||
#!/bin/sh | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
do_map() { | ||
if [ ! -f "$RBDMAPFILE" ]; then | ||
logger -p "daemon.warning" -t init-rbdmap "No $RBDMAPFILE found." | ||
exit 0 | ||
fi | ||
|
||
# Read /etc/rbdtab to create non-existant mapping | ||
RET=0 | ||
while read DEV PARAMS; do | ||
case "$DEV" in | ||
""|\#*) | ||
continue | ||
;; | ||
*/*) | ||
;; | ||
*) | ||
DEV=rbd/$DEV | ||
;; | ||
esac | ||
logger -p "daemon.debug" -t init-rbdmap "Mapping '${DEV}'" | ||
newrbd="" | ||
MAP_RV="" | ||
OIFS=$IFS | ||
IFS=',' | ||
CMDPARAMS="" | ||
for PARAM in ${PARAMS[@]}; do | ||
CMDPARAMS="$CMDPARAMS --$(echo $PARAM | tr '=' ' ')" | ||
done | ||
IFS=$OIFS | ||
if [ -b /dev/rbd/$DEV ]; then | ||
MAP_RV="$(readlink -f /dev/rbd/$DEV)" | ||
else | ||
MAP_RV="$(rbd map $DEV $CMDPARAMS 2>&1)" | ||
if [ $? -eq 0 ]; then | ||
newrbd="yes" | ||
else | ||
RET=$((${RET}+$?)) | ||
logger -p "daemon.warning" -t init-rbdmap "Failed to map '${DEV}" | ||
continue | ||
fi | ||
fi | ||
logger -p "daemon.debug" -t init-rbdmap "Mapped '${DEV}' to '${MAP_RV}'" | ||
|
||
if [ "$newrbd" ]; then | ||
## Mount new rbd | ||
MNT_RV="" | ||
mount --fake /dev/rbd/$DEV >>/dev/null 2>&1 \ | ||
&& MNT_RV=$(mount -vn /dev/rbd/$DEV 2>&1) | ||
[ -n "${MNT_RV}" ] && logger -p "daemon.debug" -t init-rbdmap "Mounted '${MAP_RV}' to '${MNT_RV}'" | ||
|
||
## post-mapping | ||
if [ -x "/etc/ceph/rbd.d/${DEV}" ]; then | ||
logger -p "daemon.debug" -t init-rbdmap "Running post-map hook '/etc/ceph/rbd.d/${DEV}'" | ||
/etc/ceph/rbd.d/${DEV} map "/dev/rbd/${DEV}" | ||
fi | ||
fi | ||
done < $RBDMAPFILE | ||
exit ${RET} | ||
|
||
} | ||
|
||
do_unmap() { | ||
RET=0 | ||
## 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 | ||
## pre-unmapping | ||
for L in $(find /dev/rbd -type l); do | ||
LL="${L##/dev/rbd/}" | ||
if [ "$(readlink -f $L)" = "${DEV}" ] \ | ||
&& [ -x "/etc/ceph/rbd.d/${LL}" ]; then | ||
logger -p "daemon.debug" -t init-rbdmap "Running pre-unmap hook for '${DEV}': '/etc/ceph/rbd.d/${LL}'" | ||
/etc/ceph/rbd.d/${LL} unmap "$L" | ||
break | ||
fi | ||
done | ||
|
||
logger -p "daemon.debug" -t init-rbdmap "Unmapping '${DEV}'" | ||
MNT=$(findmnt --mtab --source ${DEV} --noheadings | awk '{print $1'}) | ||
if [ -n "${MNT}" ]; then | ||
logger -p "daemon.debug" -t init-rbdmap "Unmounting '${MNT}'" | ||
umount "${MNT}" >>/dev/null 2>&1 | ||
fi | ||
if mountpoint -q "${MNT}"; then | ||
## Un-mounting failed. | ||
logger -p "daemon.warning" -t init-rbdmap "Failed to unmount '${MNT}'" | ||
RET=$((${RET}+1)) | ||
continue | ||
fi | ||
## Un-mapping. | ||
rbd unmap $DEV >>/dev/null 2>&1 | ||
if [ $? -ne 0 ]; then | ||
logger -p "daemon.warning" -t init-rbdmap "Failed to unmap '${MNT}'" | ||
RET=$((${RET}+$?)) | ||
continue | ||
fi | ||
logger -p "daemon.debug" -t init-rbdmap "Unmapped '${DEV}'" | ||
done | ||
fi | ||
exit ${RET} | ||
} | ||
|
||
case "$1" in | ||
map) | ||
do_map | ||
;; | ||
|
||
unmap) | ||
do_unmap | ||
;; | ||
*) | ||
echo "Usage: rbdmap map | unmap" | ||
esac |
This should probably be
#!/bin/bash
- otherwise the use of${PARAMS[@]}
might fail.