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"
17 namespace plugin
{ template <typename
> struct Api
; }
21 template <typename ImageCtxT
= ImageCtx
>
22 class ParentCacheObjectDispatch
: public io::ObjectDispatchInterface
{
23 // mock unit testing support
24 typedef cache::TypeTraits
<ImageCtxT
> TypeTraits
;
25 typedef typename
TypeTraits::CacheClient CacheClient
;
28 static ParentCacheObjectDispatch
* create(ImageCtxT
* image_ctx
,
29 plugin::Api
<ImageCtxT
>& plugin_api
) {
30 return new ParentCacheObjectDispatch(image_ctx
, plugin_api
);
33 ParentCacheObjectDispatch(ImageCtxT
* image_ctx
,
34 plugin::Api
<ImageCtxT
>& plugin_api
);
35 ~ParentCacheObjectDispatch() override
;
37 io::ObjectDispatchLayer
get_dispatch_layer() const override
{
38 return io::OBJECT_DISPATCH_LAYER_PARENT_CACHE
;
41 void init(Context
* on_finish
= nullptr);
42 void shut_down(Context
* on_finish
) {
43 m_image_ctx
->op_work_queue
->queue(on_finish
, 0);
47 uint64_t object_no
, io::ReadExtents
* extents
, IOContext io_context
,
48 int op_flags
, int read_flags
, const ZTracer::Trace
&parent_trace
,
49 uint64_t* version
, int* object_dispatch_flags
,
50 io::DispatchResult
* dispatch_result
, Context
** on_finish
,
51 Context
* on_dispatched
) override
;
54 uint64_t object_no
, uint64_t object_off
, uint64_t object_len
,
55 IOContext io_context
, int discard_flags
,
56 const ZTracer::Trace
&parent_trace
, int* object_dispatch_flags
,
57 uint64_t* journal_tid
, io::DispatchResult
* dispatch_result
,
58 Context
** on_finish
, Context
* on_dispatched
) {
63 uint64_t object_no
, uint64_t object_off
, ceph::bufferlist
&& data
,
64 IOContext io_context
, int op_flags
, int write_flags
,
65 std::optional
<uint64_t> assert_version
,
66 const ZTracer::Trace
&parent_trace
, int* object_dispatch_flags
,
67 uint64_t* journal_tid
, io::DispatchResult
* dispatch_result
,
68 Context
** on_finish
, Context
* on_dispatched
) {
73 uint64_t object_no
, uint64_t object_off
, uint64_t object_len
,
74 io::LightweightBufferExtents
&& buffer_extents
, ceph::bufferlist
&& data
,
75 IOContext io_context
, int op_flags
,
76 const ZTracer::Trace
&parent_trace
, int* object_dispatch_flags
,
77 uint64_t* journal_tid
, io::DispatchResult
* dispatch_result
,
78 Context
** on_finish
, Context
* on_dispatched
) {
82 bool compare_and_write(
83 uint64_t object_no
, uint64_t object_off
, ceph::bufferlist
&& cmp_data
,
84 ceph::bufferlist
&& write_data
, IOContext io_context
, int op_flags
,
85 const ZTracer::Trace
&parent_trace
, uint64_t* mismatch_offset
,
86 int* object_dispatch_flags
, uint64_t* journal_tid
,
87 io::DispatchResult
* dispatch_result
, Context
** on_finish
,
88 Context
* on_dispatched
) {
93 io::FlushSource flush_source
, const ZTracer::Trace
&parent_trace
,
94 uint64_t* journal_id
, io::DispatchResult
* dispatch_result
,
95 Context
** on_finish
, Context
* on_dispatched
) {
100 uint64_t object_no
, io::Extents
&& extents
, io::SnapIds
&& snap_ids
,
101 int list_snap_flags
, const ZTracer::Trace
&parent_trace
,
102 io::SnapshotDelta
* snapshot_delta
, int* object_dispatch_flags
,
103 io::DispatchResult
* dispatch_result
, Context
** on_finish
,
104 Context
* on_dispatched
) override
{
108 bool invalidate_cache(Context
* on_finish
) {
112 bool reset_existence_cache(Context
* on_finish
) {
116 void extent_overwritten(
117 uint64_t object_no
, uint64_t object_off
, uint64_t object_len
,
118 uint64_t journal_tid
, uint64_t new_journal_tid
) {
123 io::SnapshotSparseBufferlist
* snapshot_sparse_bufferlist
) override
{
127 ImageCtxT
* get_image_ctx() {
131 CacheClient
* get_cache_client() {
132 return m_cache_client
;
137 int read_object(std::string file_path
, ceph::bufferlist
* read_data
,
138 uint64_t offset
, uint64_t length
, Context
*on_finish
);
139 void handle_read_cache(ceph::immutable_obj_cache::ObjectCacheRequest
* ack
,
140 uint64_t object_no
, io::ReadExtents
* extents
,
141 IOContext io_context
, int read_flags
,
142 const ZTracer::Trace
&parent_trace
,
143 io::DispatchResult
* dispatch_result
,
144 Context
* on_dispatched
);
145 int handle_register_client(bool reg
);
146 void create_cache_session(Context
* on_finish
, bool is_reconnect
);
148 ImageCtxT
* m_image_ctx
;
149 plugin::Api
<ImageCtxT
>& m_plugin_api
;
152 CacheClient
*m_cache_client
= nullptr;
153 bool m_connecting
= false;
157 } // namespace librbd
159 extern template class librbd::cache::ParentCacheObjectDispatch
<librbd::ImageCtx
>;
161 #endif // CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H