1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H
5 #define CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H
7 #include "librbd/io/ObjectDispatchInterface.h"
8 #include "common/ceph_mutex.h"
9 #include "librbd/cache/TypeTraits.h"
10 #include "tools/immutable_object_cache/CacheClient.h"
11 #include "tools/immutable_object_cache/Types.h"
19 template <typename ImageCtxT
= ImageCtx
>
20 class ParentCacheObjectDispatch
: public io::ObjectDispatchInterface
{
21 // mock unit testing support
22 typedef cache::TypeTraits
<ImageCtxT
> TypeTraits
;
23 typedef typename
TypeTraits::CacheClient CacheClient
;
26 static ParentCacheObjectDispatch
* create(ImageCtxT
* image_ctx
) {
27 return new ParentCacheObjectDispatch(image_ctx
);
30 ParentCacheObjectDispatch(ImageCtxT
* image_ctx
);
31 ~ParentCacheObjectDispatch() override
;
33 io::ObjectDispatchLayer
get_object_dispatch_layer() const override
{
34 return io::OBJECT_DISPATCH_LAYER_PARENT_CACHE
;
37 void init(Context
* on_finish
= nullptr);
38 void shut_down(Context
* on_finish
) {
39 m_image_ctx
->op_work_queue
->queue(on_finish
, 0);
43 uint64_t object_no
, uint64_t object_off
, uint64_t object_len
,
44 librados::snap_t snap_id
, int op_flags
,
45 const ZTracer::Trace
&parent_trace
, ceph::bufferlist
* read_data
,
46 io::ExtentMap
* extent_map
, int* object_dispatch_flags
,
47 io::DispatchResult
* dispatch_result
, Context
** on_finish
,
48 Context
* on_dispatched
) override
;
51 uint64_t object_no
, uint64_t object_off
, uint64_t object_len
,
52 const ::SnapContext
&snapc
, int discard_flags
,
53 const ZTracer::Trace
&parent_trace
, int* object_dispatch_flags
,
54 uint64_t* journal_tid
, io::DispatchResult
* dispatch_result
,
55 Context
** on_finish
, Context
* on_dispatched
) {
60 uint64_t object_no
, uint64_t object_off
, ceph::bufferlist
&& data
,
61 const ::SnapContext
&snapc
, int op_flags
,
62 const ZTracer::Trace
&parent_trace
, int* object_dispatch_flags
,
63 uint64_t* journal_tid
, io::DispatchResult
* dispatch_result
,
64 Context
** on_finish
, Context
* on_dispatched
) {
69 uint64_t object_no
, uint64_t object_off
, uint64_t object_len
,
70 io::LightweightBufferExtents
&& buffer_extents
, ceph::bufferlist
&& data
,
71 const ::SnapContext
&snapc
, int op_flags
,
72 const ZTracer::Trace
&parent_trace
, int* object_dispatch_flags
,
73 uint64_t* journal_tid
, io::DispatchResult
* dispatch_result
,
74 Context
** on_finish
, Context
* on_dispatched
) {
78 bool compare_and_write(
79 uint64_t object_no
, uint64_t object_off
, ceph::bufferlist
&& cmp_data
,
80 ceph::bufferlist
&& write_data
, const ::SnapContext
&snapc
, int op_flags
,
81 const ZTracer::Trace
&parent_trace
, uint64_t* mismatch_offset
,
82 int* object_dispatch_flags
, uint64_t* journal_tid
,
83 io::DispatchResult
* dispatch_result
, Context
** on_finish
,
84 Context
* on_dispatched
) {
89 io::FlushSource flush_source
, const ZTracer::Trace
&parent_trace
,
90 uint64_t* journal_id
, io::DispatchResult
* dispatch_result
,
91 Context
** on_finish
, Context
* on_dispatched
) {
95 bool invalidate_cache(Context
* on_finish
) {
99 bool reset_existence_cache(Context
* on_finish
) {
103 void extent_overwritten(
104 uint64_t object_no
, uint64_t object_off
, uint64_t object_len
,
105 uint64_t journal_tid
, uint64_t new_journal_tid
) {
108 ImageCtxT
* get_image_ctx() {
112 CacheClient
* get_cache_client() {
113 return m_cache_client
;
118 int read_object(std::string file_path
, ceph::bufferlist
* read_data
,
119 uint64_t offset
, uint64_t length
, Context
*on_finish
);
120 void handle_read_cache(ceph::immutable_obj_cache::ObjectCacheRequest
* ack
,
121 uint64_t object_no
, uint64_t read_off
,
122 uint64_t read_len
, librados::snap_t snap_id
,
123 const ZTracer::Trace
&parent_trace
,
124 ceph::bufferlist
* read_data
,
125 io::DispatchResult
* dispatch_result
,
126 Context
* on_dispatched
);
127 int handle_register_client(bool reg
);
128 void create_cache_session(Context
* on_finish
, bool is_reconnect
);
130 ImageCtxT
* m_image_ctx
;
133 CacheClient
*m_cache_client
= nullptr;
134 bool m_connecting
= false;
138 } // namespace librbd
140 extern template class librbd::cache::ParentCacheObjectDispatch
<librbd::ImageCtx
>;
142 #endif // CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H