Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rbdmap: systemd support #6479

Merged
merged 2 commits into from
Nov 6, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions ceph.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +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/init-rbdmap $RPM_BUILD_ROOT%{_initrddir}/rbdmap
install -D src/etc-rbdmap $RPM_BUILD_ROOT%{_sysconfdir}/ceph/rbdmap
%if 0%{?fedora} || 0%{?rhel}
install -m 0644 -D etc/sysconfig/ceph $RPM_BUILD_ROOT%{_sysconfdir}/sysconfig/ceph
%endif
Expand All @@ -617,6 +616,7 @@ install -m 0644 -D etc/sysconfig/ceph $RPM_BUILD_ROOT%{_localstatedir}/adm/fillu
%endif
%if 0%{?_with_systemd}
install -m 0644 -D systemd/ceph.tmpfiles.d $RPM_BUILD_ROOT%{_tmpfilesdir}/ceph-common.conf
install -m 0644 -D systemd/rbdmap.service $RPM_BUILD_ROOT%{_unitdir}/rbdmap.service
install -m 0644 -D systemd/ceph-osd@.service $RPM_BUILD_ROOT%{_unitdir}/ceph-osd@.service
install -m 0644 -D systemd/ceph-mon@.service $RPM_BUILD_ROOT%{_unitdir}/ceph-mon@.service
install -m 0644 -D systemd/ceph-create-keys@.service $RPM_BUILD_ROOT%{_unitdir}/ceph-create-keys@.service
Expand All @@ -626,6 +626,7 @@ install -m 0644 -D etc/sysconfig/ceph $RPM_BUILD_ROOT%{_localstatedir}/adm/fillu
install -m 0644 -D systemd/ceph-disk@.service $RPM_BUILD_ROOT%{_unitdir}/ceph-disk@.service
install -m 0755 -D systemd/ceph $RPM_BUILD_ROOT%{_sbindir}/rcceph
%else
install -D src/init-rbdmap $RPM_BUILD_ROOT%{_initrddir}/rbdmap
install -D src/init-ceph $RPM_BUILD_ROOT%{_initrddir}/ceph
install -D src/init-radosgw $RPM_BUILD_ROOT%{_initrddir}/ceph-radosgw
ln -sf ../../etc/init.d/ceph %{buildroot}/%{_sbindir}/rcceph
Expand Down Expand Up @@ -872,6 +873,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 Expand Up @@ -901,7 +903,11 @@ rm -rf $RPM_BUILD_ROOT
%config %{_sysconfdir}/bash_completion.d/rados
%config %{_sysconfdir}/bash_completion.d/rbd
%config(noreplace) %{_sysconfdir}/ceph/rbdmap
%if 0%{?_with_systemd}
%{_unitdir}/rbdmap.service
%else
%{_initrddir}/rbdmap
%endif
%{python_sitelib}/ceph_argparse.py*
%{python_sitelib}/ceph_daemon.py*
%{_udevrulesdir}/50-rbd.rules
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

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
3 changes: 2 additions & 1 deletion systemd/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ unitfiles = \
ceph-create-keys@.service \
ceph-osd@.service \
ceph-radosgw@.service \
ceph-disk@.service
ceph-disk@.service \
rbdmap.service

unitdir = $(systemd_unit_dir)

Expand Down
12 changes: 12 additions & 0 deletions systemd/rbdmap.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=Map RBD devices

After=network-online.target local-fs.target
Wants=network-online.target local-fs.target

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/bin/rbdmap map
ExecReload=/usr/bin/rbdmap map
ExecStop=/usr/bin/rbdmap unmap