Skip to content

Commit

Permalink
rbdmap: Move do_map and do_unmap shell functions to rbdmap script
Browse files Browse the repository at this point in the history
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
b-ranto committed Nov 5, 2015
1 parent c17a75a commit c0980af
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 108 deletions.
3 changes: 2 additions & 1 deletion ceph.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ make %{?_smp_mflags} check-local
make DESTDIR=$RPM_BUILD_ROOT install
find $RPM_BUILD_ROOT -type f -name "*.la" -exec rm -f {} ';'
find $RPM_BUILD_ROOT -type f -name "*.a" -exec rm -f {} ';'
install -D src/rbdmap $RPM_BUILD_ROOT%{_sysconfdir}/ceph/rbdmap
install -D src/etc-rbdmap $RPM_BUILD_ROOT%{_sysconfdir}/ceph/rbdmap
install -D src/init-rbdmap $RPM_BUILD_ROOT%{_initrddir}/rbdmap
%if 0%{?fedora} || 0%{?rhel}
install -m 0644 -D etc/sysconfig/ceph $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ceph
Expand Down Expand Up @@ -872,6 +872,7 @@ rm -rf $RPM_BUILD_ROOT
%{_bindir}/rbd
%{_bindir}/rbd-replay
%{_bindir}/rbd-replay-many
%{_bindir}/rbdmap
%if 0%{?_with_lttng}
%{_bindir}/rbd-replay-prep
%endif
Expand Down
1 change: 1 addition & 0 deletions debian/ceph-common.install
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ usr/bin/ceph-syn
usr/bin/ceph-crush-location
usr/bin/rados
usr/bin/rbd
usr/bin/rbdmap
usr/bin/rbd-replay*
usr/bin/ceph-post-file
usr/bin/ceph-brag
Expand Down
2 changes: 1 addition & 1 deletion debian/rules
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ install: build
install -D -m 644 udev/50-rbd.rules $(DESTDIR)/lib/udev/rules.d/50-rbd.rules
install -D -m 644 udev/60-ceph-partuuid-workaround.rules $(DESTDIR)/lib/udev/rules.d/60-ceph-partuuid-workaround.rules
install -D -m 644 udev/95-ceph-osd.rules $(DESTDIR)/lib/udev/rules.d/95-ceph-osd.rules
install -D -m 644 src/rbdmap $(DESTDIR)/etc/ceph/rbdmap
install -D -m 644 src/etc-rbdmap $(DESTDIR)/etc/ceph/rbdmap
install -D -m 755 src/init-rbdmap $(DESTDIR)/etc/init.d/rbdmap

# Add here commands to install the package into debian/testpack.
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,7 @@ if(${WITH_RBD})
${BLKID_LIBRARIES} ${CMAKE_DL_LIBS} ${TCMALLOC_LIBS})
install(TARGETS rbd DESTINATION bin)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/src/ceph-rbdnamer DESTINATION bin)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/src/rbdmap DESTINATION bin)

set(librbd_replay_types_srcs
rbd_replay/ActionTypes.cc)
Expand Down
3 changes: 2 additions & 1 deletion src/Makefile-client.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ bash_completion_DATA += \

bin_SCRIPTS += \
ceph-rbdnamer \
rbd-replay-many
rbd-replay-many \
rbdmap

python_PYTHON += pybind/rbd.py

Expand Down
1 change: 1 addition & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ EXTRA_DIST += \
mount.fuse.ceph \
rbd-replay-many \
rbdmap \
etc-rbdmap \
yasm-wrapper

EXTRA_DIST += \
Expand Down
2 changes: 2 additions & 0 deletions src/etc-rbdmap
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
106 changes: 3 additions & 103 deletions src/init-rbdmap
Original file line number Diff line number Diff line change
Expand Up @@ -24,116 +24,16 @@ if [ -e /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
fi

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
start)
do_map
rbdmap map
;;

stop)
do_unmap
rbdmap unmap
;;

restart|force-reload)
Expand All @@ -142,7 +42,7 @@ case "$1" in
;;

reload)
do_map
rbdmap map
;;

status)
Expand Down
117 changes: 115 additions & 2 deletions src/rbdmap
100644 → 100755
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.

Copy link
@Kriechi

Kriechi Jul 6, 2016

Contributor

This should probably be #!/bin/bash - otherwise the use of ${PARAMS[@]} might fail.

This comment has been minimized.

Copy link
@tchaikov

tchaikov Jul 7, 2016

Contributor

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

0 comments on commit c0980af

Please sign in to comment.