]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbdmap: Move do_map and do_unmap shell functions to rbdmap script
authorBoris Ranto <branto@redhat.com>
Fri, 30 Oct 2015 17:33:36 +0000 (18:33 +0100)
committerNathan Cutler <ncutler@suse.com>
Tue, 1 Dec 2015 14:47:56 +0000 (15:47 +0100)
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>
(cherry picked from commit c0980af3c72f01e6f99fd1e7e91c446934d6d856)

Conflicts:
src/init-rbdmap
            Trivial resolution.

ceph.spec.in
debian/ceph-common.install
debian/rules
src/CMakeLists.txt
src/Makefile-client.am
src/Makefile.am
src/etc-rbdmap [new file with mode: 0644]
src/init-rbdmap
src/rbdmap [changed mode: 0644->0755]

index 8f2a6fc06ca8b3bf446b808f8c42b5c1f835757a..4c8aacd221a7eed0773283d88bfbdc9c011fbdca 100644 (file)
@@ -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
index 25bb8e2e571bd3c29d4cbe1e94057f922151227e..e16536e79c5eac85adbf1e00a42b064d989a406c 100644 (file)
@@ -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
index 69ad8c88ba1fc8b49d753cf144148018b469077d..13ea829734bb2855ad03b8df8d3108facadc3f01 100755 (executable)
@@ -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.
index d0122b3a78ba00647ab2b096022087c968c78541..875244fd4388c007d324e8a62df88ac88c4e26e8 100644 (file)
@@ -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)
index dcd18359962e83d1d63a17898ab29dbae834651f..0e36da16624f64ef7ef49f9aa09a7a98e74fa61a 100644 (file)
@@ -48,7 +48,8 @@ bash_completion_DATA += \
 
 bin_SCRIPTS += \
        ceph-rbdnamer \
-       rbd-replay-many
+       rbd-replay-many \
+        rbdmap
 
 python_PYTHON += pybind/rbd.py
 
index 90ec3f1fceee329d43a4f320e00b6e48649cbb63..0cc2ee31dd26954f353d67692e868e61b68d13f1 100644 (file)
@@ -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 (file)
index 0000000..b0784cf
--- /dev/null
@@ -0,0 +1,2 @@
+# RbdDevice            Parameters
+#poolname/imagename    id=client,keyring=/etc/ceph/ceph.client.keyring
index 8650ed4cd3a5f71c5c019fec0cdef337842ec1a6..42839f240594d6fc72f83f1a4d12a081c08e0f0d 100755 (executable)
@@ -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)
old mode 100644 (file)
new mode 100755 (executable)
index b0784cf..09145b2
@@ -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