From 4eded389eea931fd9cdb0b9700c022088e8825ec Mon Sep 17 00:00:00 2001 From: Boris Ranto Date: Fri, 30 Oct 2015 18:33:36 +0100 Subject: [PATCH] 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 (cherry picked from commit c0980af3c72f01e6f99fd1e7e91c446934d6d856) Conflicts: src/init-rbdmap Trivial resolution. --- ceph.spec.in | 3 +- debian/ceph-common.install | 1 + debian/rules | 2 +- src/CMakeLists.txt | 1 + src/Makefile-client.am | 3 +- src/Makefile.am | 1 + src/etc-rbdmap | 2 + src/init-rbdmap | 109 +--------------------------------- src/rbdmap | 117 ++++++++++++++++++++++++++++++++++++- 9 files changed, 128 insertions(+), 111 deletions(-) create mode 100644 src/etc-rbdmap mode change 100644 => 100755 src/rbdmap diff --git a/ceph.spec.in b/ceph.spec.in index 8f2a6fc06ca8b..4c8aacd221a7e 100644 --- a/ceph.spec.in +++ b/ceph.spec.in @@ -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 @@ -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 diff --git a/debian/ceph-common.install b/debian/ceph-common.install index 25bb8e2e571bd..e16536e79c5ea 100644 --- a/debian/ceph-common.install +++ b/debian/ceph-common.install @@ -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 diff --git a/debian/rules b/debian/rules index 69ad8c88ba1fc..13ea829734bb2 100755 --- a/debian/rules +++ b/debian/rules @@ -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. diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d0122b3a78ba0..875244fd4388c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -870,6 +870,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) diff --git a/src/Makefile-client.am b/src/Makefile-client.am index dcd18359962e8..0e36da16624f6 100644 --- a/src/Makefile-client.am +++ b/src/Makefile-client.am @@ -48,7 +48,8 @@ bash_completion_DATA += \ bin_SCRIPTS += \ ceph-rbdnamer \ - rbd-replay-many + rbd-replay-many \ + rbdmap python_PYTHON += pybind/rbd.py diff --git a/src/Makefile.am b/src/Makefile.am index 90ec3f1fceee3..0cc2ee31dd269 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -106,6 +106,7 @@ EXTRA_DIST += \ mount.fuse.ceph \ rbd-replay-many \ rbdmap \ + etc-rbdmap \ yasm-wrapper EXTRA_DIST += \ diff --git a/src/etc-rbdmap b/src/etc-rbdmap new file mode 100644 index 0000000000000..b0784cfd7d881 --- /dev/null +++ b/src/etc-rbdmap @@ -0,0 +1,2 @@ +# RbdDevice Parameters +#poolname/imagename id=client,keyring=/etc/ceph/ceph.client.keyring diff --git a/src/init-rbdmap b/src/init-rbdmap index 8650ed4cd3a5f..42839f240594d 100755 --- a/src/init-rbdmap +++ b/src/init-rbdmap @@ -24,116 +24,13 @@ 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) @@ -142,7 +39,7 @@ case "$1" in ;; reload) - do_map + rbdmap map ;; status) diff --git a/src/rbdmap b/src/rbdmap old mode 100644 new mode 100755 index b0784cfd7d881..09145b29dbab5 --- a/src/rbdmap +++ b/src/rbdmap @@ -1,2 +1,115 @@ -# RbdDevice Parameters -#poolname/imagename id=client,keyring=/etc/ceph/ceph.client.keyring +#!/bin/sh + +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 -- 2.39.5