]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/ParentCacheObjectDispatch.h
update ceph source to reef 18.1.2
[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 plugin { template <typename> struct Api; }
18
19 namespace cache {
20
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;
26
27 public:
28 static ParentCacheObjectDispatch* create(ImageCtxT* image_ctx,
29 plugin::Api<ImageCtxT>& plugin_api) {
30 return new ParentCacheObjectDispatch(image_ctx, plugin_api);
31 }
32
33 ParentCacheObjectDispatch(ImageCtxT* image_ctx,
34 plugin::Api<ImageCtxT>& plugin_api);
35 ~ParentCacheObjectDispatch() override;
36
37 io::ObjectDispatchLayer get_dispatch_layer() const override {
38 return io::OBJECT_DISPATCH_LAYER_PARENT_CACHE;
39 }
40
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);
44 }
45
46 bool read(
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;
52
53 bool discard(
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) {
59 return false;
60 }
61
62 bool write(
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) {
69 return false;
70 }
71
72 bool write_same(
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) {
79 return false;
80 }
81
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) {
89 return false;
90 }
91
92 bool flush(
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) {
96 return false;
97 }
98
99 bool list_snaps(
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 {
105 return false;
106 }
107
108 bool invalidate_cache(Context* on_finish) {
109 return false;
110 }
111
112 bool reset_existence_cache(Context* on_finish) {
113 return false;
114 }
115
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) {
119 }
120
121 int prepare_copyup(
122 uint64_t object_no,
123 io::SnapshotSparseBufferlist* snapshot_sparse_bufferlist) override {
124 return 0;
125 }
126
127 ImageCtxT* get_image_ctx() {
128 return m_image_ctx;
129 }
130
131 CacheClient* get_cache_client() {
132 return m_cache_client;
133 }
134
135 private:
136
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);
147
148 ImageCtxT* m_image_ctx;
149 plugin::Api<ImageCtxT>& m_plugin_api;
150
151 ceph::mutex m_lock;
152 CacheClient *m_cache_client = nullptr;
153 bool m_connecting = false;
154 };
155
156 } // namespace cache
157 } // namespace librbd
158
159 extern template class librbd::cache::ParentCacheObjectDispatch<librbd::ImageCtx>;
160
161 #endif // CEPH_LIBRBD_CACHE_PARENT_CACHER_OBJECT_DISPATCH_H