]>
git.proxmox.com Git - ceph.git/blob - ceph/src/tools/immutable_object_cache/CacheController.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "CacheController.h"
6 #define dout_context g_ceph_context
7 #define dout_subsys ceph_subsys_immutable_obj_cache
9 #define dout_prefix *_dout << "ceph::cache::CacheController: " << this << " " \
13 namespace immutable_obj_cache
{
15 CacheController::CacheController(CephContext
*cct
,
16 const std::vector
<const char*> &args
):
17 m_args(args
), m_cct(cct
) {
18 ldout(m_cct
, 20) << dendl
;
21 CacheController::~CacheController() {
22 delete m_cache_server
;
23 delete m_object_cache_store
;
26 int CacheController::init() {
27 ldout(m_cct
, 20) << dendl
;
29 m_object_cache_store
= new ObjectCacheStore(m_cct
);
30 // TODO(dehao): make this configurable
31 int r
= m_object_cache_store
->init(true);
33 lderr(m_cct
) << "init error\n" << dendl
;
37 r
= m_object_cache_store
->init_cache();
39 lderr(m_cct
) << "init error\n" << dendl
;
45 int CacheController::shutdown() {
46 ldout(m_cct
, 20) << dendl
;
49 if (m_cache_server
!= nullptr) {
50 r
= m_cache_server
->stop();
52 lderr(m_cct
) << "stop error\n" << dendl
;
57 r
= m_object_cache_store
->shutdown();
59 lderr(m_cct
) << "stop error\n" << dendl
;
66 void CacheController::handle_signal(int signum
) {
70 int CacheController::run() {
72 std::string controller_path
=
73 m_cct
->_conf
.get_val
<std::string
>("immutable_object_cache_sock");
74 if (controller_path
.empty()) {
75 lderr(m_cct
) << "'immutable_object_cache_sock' path not set" << dendl
;
79 std::remove(controller_path
.c_str());
81 m_cache_server
= new CacheServer(m_cct
, controller_path
,
82 std::bind(&CacheController::handle_request
, this,
83 std::placeholders::_1
, std::placeholders::_2
));
85 int ret
= m_cache_server
->run();
91 } catch (std::exception
& e
) {
92 lderr(m_cct
) << "Exception: " << e
.what() << dendl
;
97 void CacheController::handle_request(CacheSession
* session
,
98 ObjectCacheRequest
* req
) {
99 ldout(m_cct
, 20) << dendl
;
101 switch (req
->get_request_type()) {
102 case RBDSC_REGISTER
: {
103 // TODO(dehao): skip register and allow clients to lookup directly
105 auto req_reg_data
= reinterpret_cast <ObjectCacheRegData
*> (req
);
106 session
->set_client_version(req_reg_data
->version
);
108 ObjectCacheRequest
* reply
= new ObjectCacheRegReplyData(
109 RBDSC_REGISTER_REPLY
, req
->seq
);
110 session
->send(reply
);
114 // lookup object in local cache store
115 std::string cache_path
;
116 ObjectCacheReadData
* req_read_data
=
117 reinterpret_cast <ObjectCacheReadData
*> (req
);
118 bool return_dne_path
= session
->client_version().empty();
119 int ret
= m_object_cache_store
->lookup_object(
120 req_read_data
->pool_namespace
, req_read_data
->pool_id
,
121 req_read_data
->snap_id
, req_read_data
->oid
, return_dne_path
,
123 ObjectCacheRequest
* reply
= nullptr;
124 if (ret
!= OBJ_CACHE_PROMOTED
&& ret
!= OBJ_CACHE_DNE
) {
125 reply
= new ObjectCacheReadRadosData(RBDSC_READ_RADOS
, req
->seq
);
127 reply
= new ObjectCacheReadReplyData(RBDSC_READ_REPLY
,
128 req
->seq
, cache_path
);
130 session
->send(reply
);
134 ldout(m_cct
, 5) << "can't recongize request" << dendl
;
139 } // namespace immutable_obj_cache