]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/ParentCacheObjectDispatch.h
Import ceph 15.2.8
[ceph.git] / ceph / src / librbd / cache / ParentCacheObjectDispatch.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H
5 #define CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H
6
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"
12
13 namespace librbd {
14
15 class ImageCtx;
16
17 namespace cache {
18
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;
24
25 public:
26 static ParentCacheObjectDispatch* create(ImageCtxT* image_ctx) {
27 return new ParentCacheObjectDispatch(image_ctx);
28 }
29
30 ParentCacheObjectDispatch(ImageCtxT* image_ctx);
31 ~ParentCacheObjectDispatch() override;
32
33 io::ObjectDispatchLayer get_object_dispatch_layer() const override {
34 return io::OBJECT_DISPATCH_LAYER_PARENT_CACHE;
35 }
36
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);
40 }
41
42 bool read(
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;
49
50 bool discard(
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) {
56 return false;
57 }
58
59 bool write(
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) {
65 return false;
66 }
67
68 bool write_same(
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) {
75 return false;
76 }
77
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) {
85 return false;
86 }
87
88 bool flush(
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) {
92 return false;
93 }
94
95 bool invalidate_cache(Context* on_finish) {
96 return false;
97 }
98
99 bool reset_existence_cache(Context* on_finish) {
100 return false;
101 }
102
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) {
106 }
107
108 ImageCtxT* get_image_ctx() {
109 return m_image_ctx;
110 }
111
112 CacheClient* get_cache_client() {
113 return m_cache_client;
114 }
115
116 private:
117
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);
129
130 ImageCtxT* m_image_ctx;
131
132 ceph::mutex m_lock;
133 CacheClient *m_cache_client = nullptr;
134 bool m_connecting = false;
135 };
136
137 } // namespace cache
138 } // namespace librbd
139
140 extern template class librbd::cache::ParentCacheObjectDispatch<librbd::ImageCtx>;
141
142 #endif // CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H