]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/LibrbdAdminSocketHook.cc
f91bda3f0d2fbe23c73ffda53da141ea36e5a27c
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "common/errno.h"
6 #include "librbd/ImageCtx.h"
7 #include "librbd/LibrbdAdminSocketHook.h"
8 #include "librbd/internal.h"
9 #include "librbd/api/Io.h"
11 #define dout_subsys ceph_subsys_rbd
13 #define dout_prefix *_dout << "librbdadminsocket: "
17 class LibrbdAdminSocketCommand
{
19 virtual ~LibrbdAdminSocketCommand() {}
20 virtual int call(Formatter
*f
) = 0;
23 class FlushCacheCommand
: public LibrbdAdminSocketCommand
{
25 explicit FlushCacheCommand(ImageCtx
*ictx
) : ictx(ictx
) {}
27 int call(Formatter
*f
) override
{
28 return api::Io
<>::flush(*ictx
);
35 struct InvalidateCacheCommand
: public LibrbdAdminSocketCommand
{
37 explicit InvalidateCacheCommand(ImageCtx
*ictx
) : ictx(ictx
) {}
39 int call(Formatter
*f
) override
{
40 return invalidate_cache(ictx
);
47 LibrbdAdminSocketHook::LibrbdAdminSocketHook(ImageCtx
*ictx
) :
48 admin_socket(ictx
->cct
->get_admin_socket()) {
51 std::string imagename
;
54 imagename
= ictx
->md_ctx
.get_pool_name() + "/" + ictx
->name
;
55 command
= "rbd cache flush " + imagename
;
57 r
= admin_socket
->register_command(command
, this,
58 "flush rbd image " + imagename
+
61 commands
[command
] = new FlushCacheCommand(ictx
);
64 command
= "rbd cache invalidate " + imagename
;
65 r
= admin_socket
->register_command(command
, this,
66 "invalidate rbd image " + imagename
+
69 commands
[command
] = new InvalidateCacheCommand(ictx
);
73 LibrbdAdminSocketHook::~LibrbdAdminSocketHook() {
74 (void)admin_socket
->unregister_commands(this);
75 for (Commands::const_iterator i
= commands
.begin(); i
!= commands
.end();
81 int LibrbdAdminSocketHook::call(std::string_view command
,
82 const cmdmap_t
& cmdmap
,
86 Commands::const_iterator i
= commands
.find(command
);
87 ceph_assert(i
!= commands
.end());
88 return i
->second
->call(f
);