From 4d80432924656f725ccfcd5481aebb30b4041b43 Mon Sep 17 00:00:00 2001 From: Lucian Petrut Date: Wed, 27 Jan 2021 09:06:19 +0000 Subject: [PATCH] rbd: allow non persistent Windows mappings At the moment, all Windows RBD mappings are persistent, being recreated when the Ceph service starts. This change adds the "--non-persistent" flag to allow skipping certain images. Note that even for non-persistent mappings, we're still storing data in the Windows registry, allowing us to retrieve image details such as the rbd pool as well as the admin socket path. When the daemons stop or the Ceph service starts, non-persistent entries are cleaned up from the Windows registry. Signed-off-by: Lucian Petrut (cherry picked from commit 2455a907e66e706e2be4f91322b8f4cdd59fc844) --- src/common/win32/registry.cc | 14 ++++++++++++-- src/common/win32/registry.h | 3 ++- src/tools/rbd_wnbd/rbd_wnbd.cc | 32 ++++++++++++++++++++++++++++++++ src/tools/rbd_wnbd/rbd_wnbd.h | 3 +++ 4 files changed, 49 insertions(+), 3 deletions(-) diff --git a/src/common/win32/registry.cc b/src/common/win32/registry.cc index d032e3b602ab8..85ab80df97b61 100644 --- a/src/common/win32/registry.cc +++ b/src/common/win32/registry.cc @@ -112,7 +112,17 @@ int RegistryKey::set(LPCTSTR lpValue, std::string data) return 0; } -int RegistryKey::get(LPCTSTR lpValue, DWORD* value) +int RegistryKey::get(LPCTSTR lpValue, bool& value) +{ + DWORD value_dw = 0; + int r = get(lpValue, value_dw); + if (!r) { + value = !!value_dw; + } + return r; +} + +int RegistryKey::get(LPCTSTR lpValue, DWORD& value) { DWORD data; DWORD size = sizeof(data); @@ -125,7 +135,7 @@ int RegistryKey::get(LPCTSTR lpValue, DWORD* value) << (char*)lpValue << dendl; return -EINVAL; } - *value = data; + value = data; return 0; } diff --git a/src/common/win32/registry.h b/src/common/win32/registry.h index 974d662de2d98..fdaf9708a9b63 100644 --- a/src/common/win32/registry.h +++ b/src/common/win32/registry.h @@ -26,7 +26,8 @@ public: int set(LPCTSTR lpValue, DWORD data); int set(LPCTSTR lpValue, std::string data); - int get(LPCTSTR lpValue, DWORD* value); + int get(LPCTSTR lpValue, bool& value); + int get(LPCTSTR lpValue, DWORD& value); int get(LPCTSTR lpValue, std::string& value); HKEY hKey = NULL; diff --git a/src/tools/rbd_wnbd/rbd_wnbd.cc b/src/tools/rbd_wnbd/rbd_wnbd.cc index e5733c2685793..7421f01609721 100644 --- a/src/tools/rbd_wnbd/rbd_wnbd.cc +++ b/src/tools/rbd_wnbd/rbd_wnbd.cc @@ -404,6 +404,7 @@ int save_config_to_registry(Config* cfg) reg_key.set("imgname", cfg->imgname) || reg_key.set("snapname", cfg->snapname) || reg_key.set("command_line", GetCommandLine()) || + reg_key.set("persistent", cfg->persistent) || reg_key.set("admin_sock_path", g_conf()->admin_socket) || reg_key.flush()) { ret_val = -EINVAL; @@ -441,6 +442,7 @@ int load_mapping_config_from_registry(string devpath, Config* cfg) reg_key.get("imgname", cfg->imgname); reg_key.get("snapname", cfg->snapname); reg_key.get("command_line", cfg->command_line); + reg_key.get("persistent", cfg->persistent); reg_key.get("admin_sock_path", cfg->admin_sock_path); return 0; @@ -465,6 +467,16 @@ int restart_registered_mappings(int worker_count) << cfg.devpath << dendl; continue; } + if (!cfg.persistent) { + dout(5) << __func__ << ": cleaning up non-persistent mapping: " + << cfg.devpath << dendl; + r = remove_config_from_registry(&cfg); + if (r) { + derr << __func__ << ": could not clean up non-persistent mapping: " + << cfg.devpath << dendl; + } + continue; + } boost::asio::post(pool, [&, cfg]() mutable @@ -747,6 +759,8 @@ Map options: --device Optional mapping unique identifier --exclusive Forbid writes by other clients --read-only Map read-only + --non-persistent Do not recreate the mapping when the Ceph service + restarts. By default, mappings are persistent --io-req-workers The number of workers that dispatch IO requests. Default: 4 --io-reply-workers The number of workers that dispatch IO replies. @@ -935,6 +949,11 @@ static int do_map(Config *cfg) goto close_ret; } + // 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) goto close_ret; @@ -967,6 +986,16 @@ static int do_map(Config *cfg) handler->wait(); handler->shutdown(); + if (!cfg->persistent) { + dout(5) << __func__ << ": cleaning up non-persistent mapping: " + << cfg->devpath << dendl; + r = remove_config_from_registry(cfg); + if (r) { + derr << __func__ << ": could not clean up non-persistent mapping: " + << cfg->devpath << dendl; + } + } + close_ret: std::unique_lock l{shutdown_lock}; @@ -1144,6 +1173,7 @@ static int do_show_mapped_device(std::string format, bool pretty_format, f->dump_string("namespace", cfg.nsname); f->dump_string("image", cfg.imgname); f->dump_string("snap", cfg.snapname); + f->dump_int("persistent", cfg.persistent); f->dump_int("disk_number", conn_info.DiskNumber ? conn_info.DiskNumber : -1); f->dump_string("status", cfg.active ? WNBD_STATUS_ACTIVE : WNBD_STATUS_INACTIVE); f->dump_string("pnp_device_id", to_string(conn_info.PNPDeviceID)); @@ -1228,6 +1258,8 @@ static int parse_args(std::vector& args, cfg->readonly = true; } else if (ceph_argparse_flag(args, i, "--exclusive", (char *)NULL)) { cfg->exclusive = true; + } else if (ceph_argparse_flag(args, i, "--non-persistent", (char *)NULL)) { + cfg->persistent = false; } else if (ceph_argparse_flag(args, i, "--pretty-format", (char *)NULL)) { cfg->pretty_format = true; } else if (ceph_argparse_witharg(args, i, &cfg->parent_pipe, err, diff --git a/src/tools/rbd_wnbd/rbd_wnbd.h b/src/tools/rbd_wnbd/rbd_wnbd.h index 4cb5da0a48637..30428c3ee84ce 100644 --- a/src/tools/rbd_wnbd/rbd_wnbd.h +++ b/src/tools/rbd_wnbd/rbd_wnbd.h @@ -76,6 +76,9 @@ struct Config { int io_req_workers = DEFAULT_IO_WORKER_COUNT; int io_reply_workers = DEFAULT_IO_WORKER_COUNT; int service_thread_count = DEFAULT_SERVICE_THREAD_COUNT; + + // register the mapping, recreating it when the Ceph service starts. + bool persistent = true; }; enum Command { -- 2.39.5