From 5f9c69d53c522f3b939c91c974cedb9fdd085a60 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Wed, 19 Jul 2023 12:32:40 +0000 Subject: [PATCH] rbd-wnbd: update registry settings handling This commit will store the mapping config in the Windows registry only after initializing the mapping. This ensures that we aren't replacing the registry settings for already mapped images. We'll also check if the registry setting was added by us before cleaning it up. Signed-off-by: Lucian Petrut --- src/tools/rbd_wnbd/rbd_mapping.cc | 23 +++++++++++++---------- src/tools/rbd_wnbd/rbd_mapping.h | 1 + 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/tools/rbd_wnbd/rbd_mapping.cc b/src/tools/rbd_wnbd/rbd_mapping.cc index b2d7cff93bc..eaa79180929 100644 --- a/src/tools/rbd_wnbd/rbd_mapping.cc +++ b/src/tools/rbd_wnbd/rbd_mapping.cc @@ -76,15 +76,6 @@ int RbdMapping::init() initial_image_size = info.size; - // We're storing mapping details in the registry even for non-persistent - // mappings. This allows us to easily retrieve mapping details such - // as the rbd pool or admin socket path. - // We're cleaning up the registry entry when the non-persistent mapping - // gets disconnected or when the ceph service restarts. - r = save_config_to_registry(&cfg); - if (r < 0) - return r; - handler = new WnbdHandler(image, cfg.devpath, info.size / RBD_WNBD_BLKSIZE, RBD_WNBD_BLKSIZE, @@ -102,7 +93,7 @@ void RbdMapping::shutdown() dout(5) << __func__ << ": removing RBD mapping: " << cfg.devpath << dendl; int r = 0; - if (!cfg.persistent) { + if (!cfg.persistent && saved_cfg_to_registry) { dout(5) << __func__ << ": cleaning up non-persistent mapping: " << cfg.devpath << dendl; r = remove_config_from_registry(&cfg); @@ -161,6 +152,18 @@ int RbdMapping::start() return r; } + // We're storing mapping details in the registry even for non-persistent + // mappings. This allows us to easily retrieve mapping details such + // as the rbd pool or admin socket path. + // We're cleaning up the registry entry when the non-persistent mapping + // gets disconnected or when the ceph service restarts. + r = save_config_to_registry(&cfg); + if (r < 0) { + return r; + } else { + saved_cfg_to_registry = true; + } + if (disconnect_cbk) { monitor_thread = std::thread([this]{ int ret = this->wait(); diff --git a/src/tools/rbd_wnbd/rbd_mapping.h b/src/tools/rbd_wnbd/rbd_mapping.h index 52404ed503f..1255880cb79 100644 --- a/src/tools/rbd_wnbd/rbd_mapping.h +++ b/src/tools/rbd_wnbd/rbd_mapping.h @@ -65,6 +65,7 @@ private: WnbdHandler* handler = nullptr; uint64_t watch_handle; WNBDWatchCtx* watch_ctx = nullptr; + bool saved_cfg_to_registry = false; disconnect_cbk_t disconnect_cbk; ceph::mutex shutdown_lock = ceph::make_mutex("RbdMapping::ShutdownLock"); -- 2.39.5