]>
git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/LibrbdAdminSocketHook.cc
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"
10 #define dout_subsys ceph_subsys_rbd
12 #define dout_prefix *_dout << "librbdadminsocket: "
16 class LibrbdAdminSocketCommand
{
18 virtual ~LibrbdAdminSocketCommand() {}
19 virtual bool call(stringstream
*ss
) = 0;
22 class FlushCacheCommand
: public LibrbdAdminSocketCommand
{
24 explicit FlushCacheCommand(ImageCtx
*ictx
) : ictx(ictx
) {}
26 bool call(stringstream
*ss
) override
{
29 *ss
<< "flush: " << cpp_strerror(r
);
39 struct InvalidateCacheCommand
: public LibrbdAdminSocketCommand
{
41 explicit InvalidateCacheCommand(ImageCtx
*ictx
) : ictx(ictx
) {}
43 bool call(stringstream
*ss
) override
{
44 int r
= invalidate_cache(ictx
);
46 *ss
<< "invalidate_cache: " << cpp_strerror(r
);
56 LibrbdAdminSocketHook::LibrbdAdminSocketHook(ImageCtx
*ictx
) :
57 admin_socket(ictx
->cct
->get_admin_socket()) {
60 std::string imagename
;
63 imagename
= ictx
->md_ctx
.get_pool_name() + "/" + ictx
->name
;
64 command
= "rbd cache flush " + imagename
;
66 r
= admin_socket
->register_command(command
, command
, this,
67 "flush rbd image " + imagename
+
70 commands
[command
] = new FlushCacheCommand(ictx
);
73 command
= "rbd cache invalidate " + imagename
;
74 r
= admin_socket
->register_command(command
, command
, this,
75 "invalidate rbd image " + imagename
+
78 commands
[command
] = new InvalidateCacheCommand(ictx
);
82 LibrbdAdminSocketHook::~LibrbdAdminSocketHook() {
83 for (Commands::const_iterator i
= commands
.begin(); i
!= commands
.end();
85 (void)admin_socket
->unregister_command(i
->first
);
90 bool LibrbdAdminSocketHook::call(std::string command
, cmdmap_t
& cmdmap
,
91 std::string format
, bufferlist
& out
) {
92 Commands::const_iterator i
= commands
.find(command
);
93 assert(i
!= commands
.end());
95 bool r
= i
->second
->call(&ss
);
100 } // namespace librbd