From 373b75d6cec6a7ec8b5947345d7630580170887f Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Fri, 22 Jan 2021 10:29:29 -0500 Subject: [PATCH] ocf: add support for mapping images within an RBD namespace Support for RBD namespaces was not added to the OCF resource agent. This commit fixes this oversight and also fixes a bug in handling of the "rbd device list" output. Fixes: https://tracker.ceph.com/issues/48964 Signed-off-by: Jason Dillaman (cherry picked from commit 2a23a92aaf122627151874c56848667169fac064) --- src/ocf/rbd.in | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) diff --git a/src/ocf/rbd.in b/src/ocf/rbd.in index fa92660e15b6e..cbcc1d5b3a9c5 100644 --- a/src/ocf/rbd.in +++ b/src/ocf/rbd.in @@ -41,6 +41,12 @@ resource. Maps and unmaps RBDs as needed. RBD device name + + + Name of the RADOS pool namespace where the RBD has been created + + RADOS pool namespace name + Name of the RADOS pool where the RBD has been created @@ -108,9 +114,7 @@ Expects to have a fully populated OCF RA-compliant environment set. EOF } -# rbd command wrapper: builds an option string for invoking RBD based -# on resource parameters, and invokes rbd through ocf_run. -do_rbd() { +get_rbd_options() { local rbd_options if [ -n "${OCF_RESKEY_cephconf}" ]; then @@ -120,25 +124,36 @@ do_rbd() { rbd_options="$rbd_options -m ${OCF_RESKEY_mon}" fi + echo "${rbd_options}" +} + + +# rbd command wrapper: builds an option string for invoking RBD based +# on resource parameters, and invokes rbd through ocf_run. +do_rbd() { + local rbd_options="$(get_rbd_options)" + ocf_run rbd $rbd_options $@ } # Convenience function that uses "rbd device list" to retrieve the # mapped device name from the pool, RBD name, and snapshot. find_rbd_dev() { + local rbd_options="$(get_rbd_options)" local sedpat # Example output from "rbd device list" (tab separated): - # id pool image snap device - # 0 rbd test - /dev/rbd0 + # id pool namespace image snap device + # 0 rbd test - /dev/rbd0 + # 1 rbd ns1 test - /dev/rbd1 # Build the sed pattern, substituting "-" for the snapshot name if # it's unset - sedpat="[0-9]\+[ \t]\+${OCF_RESKEY_pool}[ \t]\+${OCF_RESKEY_name}[ \t]\+${OCF_RESKEY_snap:--}[ \t]\+\(/dev/rbd[0-9]\+\).*" + sedpat="[0-9]\+[ \t]\+${OCF_RESKEY_pool}[ \t]\+${OCF_RESKEY_pool_namespace}[ \t]\+${OCF_RESKEY_name}[ \t]\+${OCF_RESKEY_snap:--}[ \t]\+\(/dev/rbd[0-9]\+\).*" # Run "rbd device list", filter out the header line, then try to # extract the device name - rbd device list | tail -n +2 | sed -n -e "s,$sedpat,\1,p" + rbd $rbd_options device list | tail -n +2 | sed -n -e "s,$sedpat,\1,p" } rbd_validate_all() { @@ -206,9 +221,13 @@ rbd_start() { rbd_map_options="$rbd_map_options --keyfile ${OCF_RESKEY_secret}" fi - rbd_name="${OCF_RESKEY_pool}/${OCF_RESKEY_name}" + rbd_name="${OCF_RESKEY_pool}" + if [ -n "${OCF_RESKEY_pool_namespace}" ]; then + rbd_name="${rbd_name}/${OCF_RESKEY_pool_namespace}" + fi + rbd_name="${rbd_name}/${OCF_RESKEY_name}" if [ -n "${OCF_RESKEY_snap}" ]; then - rbd_name="$rbd_name@${OCF_RESKEY_snap}" + rbd_name="${rbd_name}@${OCF_RESKEY_snap}" fi do_rbd device map $rbd_name $rbd_map_options || exit $OCF_ERR_GENERIC -- 2.39.5