]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/ObjectCacherObjectDispatch.h
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / librbd / cache / ObjectCacherObjectDispatch.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_OBJECT_CACHER_OBJECT_DISPATCH_H
5 #define CEPH_LIBRBD_CACHE_OBJECT_CACHER_OBJECT_DISPATCH_H
6
7 #include "librbd/io/ObjectDispatchInterface.h"
8 #include "common/Mutex.h"
9 #include "osdc/ObjectCacher.h"
10
11 struct WritebackHandler;
12
13 namespace librbd {
14
15 class ImageCtx;
16
17 namespace cache {
18
19 /**
20 * Facade around the OSDC object cacher to make it align with
21 * the object dispatcher interface
22 */
23 template <typename ImageCtxT = ImageCtx>
24 class ObjectCacherObjectDispatch : public io::ObjectDispatchInterface {
25 public:
26 static ObjectCacherObjectDispatch* create(ImageCtxT* image_ctx) {
27 return new ObjectCacherObjectDispatch(image_ctx);
28 }
29
30 ObjectCacherObjectDispatch(ImageCtxT* image_ctx);
31 ~ObjectCacherObjectDispatch() override;
32
33 io::ObjectDispatchLayer get_object_dispatch_layer() const override {
34 return io::OBJECT_DISPATCH_LAYER_CACHE;
35 }
36
37 void init();
38 void shut_down(Context* on_finish) override;
39
40 bool read(
41 const std::string &oid, uint64_t object_no, uint64_t object_off,
42 uint64_t object_len, librados::snap_t snap_id, int op_flags,
43 const ZTracer::Trace &parent_trace, ceph::bufferlist* read_data,
44 io::ExtentMap* extent_map, int* object_dispatch_flags,
45 io::DispatchResult* dispatch_result, Context** on_finish,
46 Context* on_dispatched) override;
47
48 bool discard(
49 const std::string &oid, uint64_t object_no, uint64_t object_off,
50 uint64_t object_len, const ::SnapContext &snapc, int discard_flags,
51 const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
52 uint64_t* journal_tid, io::DispatchResult* dispatch_result,
53 Context** on_finish, Context* on_dispatched) override;
54
55 bool write(
56 const std::string &oid, uint64_t object_no, uint64_t object_off,
57 ceph::bufferlist&& data, const ::SnapContext &snapc, int op_flags,
58 const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
59 uint64_t* journal_tid, io::DispatchResult* dispatch_result,
60 Context** on_finish, Context* on_dispatched) override;
61
62 bool write_same(
63 const std::string &oid, uint64_t object_no, uint64_t object_off,
64 uint64_t object_len, io::Extents&& buffer_extents,
65 ceph::bufferlist&& data, const ::SnapContext &snapc, int op_flags,
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) override;
69
70 bool compare_and_write(
71 const std::string &oid, uint64_t object_no, uint64_t object_off,
72 ceph::bufferlist&& cmp_data, ceph::bufferlist&& write_data,
73 const ::SnapContext &snapc, int op_flags,
74 const ZTracer::Trace &parent_trace, uint64_t* mismatch_offset,
75 int* object_dispatch_flags, uint64_t* journal_tid,
76 io::DispatchResult* dispatch_result, Context** on_finish,
77 Context* on_dispatched) override;
78
79 bool flush(
80 io::FlushSource flush_source, const ZTracer::Trace &parent_trace,
81 io::DispatchResult* dispatch_result, Context** on_finish,
82 Context* on_dispatched) override;
83
84 bool invalidate_cache(Context* on_finish) override;
85 bool reset_existence_cache(Context* on_finish) override;
86
87 void extent_overwritten(
88 uint64_t object_no, uint64_t object_off, uint64_t object_len,
89 uint64_t journal_tid, uint64_t new_journal_tid) {
90 }
91
92 private:
93 struct C_InvalidateCache;
94
95 ImageCtxT* m_image_ctx;
96
97 Mutex m_cache_lock;
98 ObjectCacher *m_object_cacher = nullptr;
99 ObjectCacher::ObjectSet *m_object_set = nullptr;
100
101 WritebackHandler *m_writeback_handler = nullptr;
102
103 bool m_user_flushed = false;
104
105 };
106
107 } // namespace cache
108 } // namespace librbd
109
110 extern template class librbd::cache::ObjectCacherObjectDispatch<librbd::ImageCtx>;
111
112 #endif // CEPH_LIBRBD_CACHE_OBJECT_CACHER_OBJECT_DISPATCH_H