Skip to content

Commit a14003c

Browse files
rbd-wnbd: use the right AdminSocket instance
The rbd-wnbd daemon currently caches one rados context per cluster. However, it's registering hooks against the global context admin socket, which won't be available. For this reason, the "rbd-wnbd stats" command no longer works. To address this issue, we'll ensure that rbd-wnbd sets command hooks against the right admin socket instance, leveraging the image context. Signed-off-by: Lucian Petrut <[email protected]>
1 parent 83d58ab commit a14003c

File tree

3 files changed

+24
-9
lines changed

3 files changed

+24
-9
lines changed

src/tools/rbd_wnbd/rbd_mapping.cc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,17 @@ int RbdMapping::init()
7676

7777
initial_image_size = info.size;
7878

79+
CephContext* cct = reinterpret_cast<CephContext*>(io_ctx.cct());
80+
ceph_assert(cct != nullptr);
81+
7982
handler = new WnbdHandler(image, cfg.devpath,
8083
info.size / RBD_WNBD_BLKSIZE,
8184
RBD_WNBD_BLKSIZE,
8285
!cfg.snapname.empty() || cfg.readonly,
8386
g_conf().get_val<bool>("rbd_cache"),
8487
cfg.io_req_workers,
85-
cfg.io_reply_workers);
88+
cfg.io_reply_workers,
89+
cct->get_admin_socket());
8690
return 0;
8791
}
8892

src/tools/rbd_wnbd/wnbd_handler.cc

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,18 @@ int WnbdHandler::wait()
6565
return err;
6666
}
6767

68-
WnbdAdminHook::WnbdAdminHook(WnbdHandler *handler) : m_handler(handler)
68+
WnbdAdminHook::WnbdAdminHook(WnbdHandler *handler, AdminSocket* admin_socket)
69+
: m_handler(handler)
70+
, m_admin_socket(admin_socket)
6971
{
70-
g_ceph_context->get_admin_socket()->register_command(
71-
std::string("wnbd stats ") + m_handler->instance_name,
72-
this, "get WNBD stats");
72+
if (m_admin_socket) {
73+
m_admin_socket->register_command(
74+
std::string("wnbd stats ") + m_handler->instance_name,
75+
this, "get WNBD stats");
76+
} else {
77+
dout(0) << "no admin socket provided, skipped registering wnbd hooks"
78+
<< dendl;
79+
}
7380
}
7481

7582
int WnbdAdminHook::call (

src/tools/rbd_wnbd/wnbd_handler.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,14 @@ class WnbdHandler;
4242

4343
class WnbdAdminHook : public AdminSocketHook {
4444
WnbdHandler *m_handler;
45+
AdminSocket *m_admin_socket;
4546

4647
public:
47-
explicit WnbdAdminHook(WnbdHandler *handler);
48+
explicit WnbdAdminHook(WnbdHandler *handler, AdminSocket* admin_socket);
4849
~WnbdAdminHook() override {
49-
g_ceph_context->get_admin_socket()->unregister_commands(this);
50+
if (m_admin_socket) {
51+
m_admin_socket->unregister_commands(this);
52+
}
5053
}
5154

5255
int call(std::string_view command, const cmdmap_t& cmdmap,
@@ -74,7 +77,8 @@ class WnbdHandler
7477
uint64_t _block_count, uint32_t _block_size,
7578
bool _readonly, bool _rbd_cache_enabled,
7679
uint32_t _io_req_workers,
77-
uint32_t _io_reply_workers)
80+
uint32_t _io_reply_workers,
81+
AdminSocket* admin_socket)
7882
: image(_image)
7983
, instance_name(_instance_name)
8084
, block_count(_block_count)
@@ -84,7 +88,7 @@ class WnbdHandler
8488
, io_req_workers(_io_req_workers)
8589
, io_reply_workers(_io_reply_workers)
8690
{
87-
admin_hook = new WnbdAdminHook(this);
91+
admin_hook = new WnbdAdminHook(this, admin_socket);
8892
// Instead of relying on librbd's own thread pool, we're going to use a
8993
// separate one. This allows us to make assumptions on the threads that
9094
// are going to send the IO replies and thus be able to cache Windows

0 commit comments

Comments
 (0)