]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/ObjectCacherObjectDispatch.h
update source to Ceph Pacific 16.2.2
[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/ceph_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 size_t max_dirty,
28 bool writethrough_until_flush) {
29 return new ObjectCacherObjectDispatch(image_ctx, max_dirty,
30 writethrough_until_flush);
31 }
32
33 ObjectCacherObjectDispatch(ImageCtxT* image_ctx, size_t max_dirty,
34 bool writethrough_until_flush);
35 ~ObjectCacherObjectDispatch() override;
36
37 io::ObjectDispatchLayer get_dispatch_layer() const override {
38 return io::OBJECT_DISPATCH_LAYER_CACHE;
39 }
40
41 void init();
42 void shut_down(Context* on_finish) override;
43
44 bool read(
45 uint64_t object_no, io::ReadExtents* extents, IOContext io_context,
46 int op_flags, int read_flags, const ZTracer::Trace &parent_trace,
47 uint64_t* version, int* object_dispatch_flags,
48 io::DispatchResult* dispatch_result, Context** on_finish,
49 Context* on_dispatched) override;
50
51 bool discard(
52 uint64_t object_no, uint64_t object_off, uint64_t object_len,
53 IOContext io_context, int discard_flags,
54 const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
55 uint64_t* journal_tid, io::DispatchResult* dispatch_result,
56 Context** on_finish, Context* on_dispatched) override;
57
58 bool write(
59 uint64_t object_no, uint64_t object_off, ceph::bufferlist&& data,
60 IOContext io_context, int op_flags, int write_flags,
61 std::optional<uint64_t> assert_version,
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) override;
65
66 bool write_same(
67 uint64_t object_no, uint64_t object_off, uint64_t object_len,
68 io::LightweightBufferExtents&& buffer_extents, ceph::bufferlist&& data,
69 IOContext io_context, int op_flags,
70 const ZTracer::Trace &parent_trace, int* object_dispatch_flags,
71 uint64_t* journal_tid, io::DispatchResult* dispatch_result,
72 Context** on_finish, Context* on_dispatched) override;
73
74 bool compare_and_write(
75 uint64_t object_no, uint64_t object_off, ceph::bufferlist&& cmp_data,
76 ceph::bufferlist&& write_data, IOContext io_context, int op_flags,
77 const ZTracer::Trace &parent_trace, uint64_t* mismatch_offset,
78 int* object_dispatch_flags, uint64_t* journal_tid,
79 io::DispatchResult* dispatch_result, Context** on_finish,
80 Context* on_dispatched) override;
81
82 bool flush(
83 io::FlushSource flush_source, const ZTracer::Trace &parent_trace,
84 uint64_t* journal_tid, io::DispatchResult* dispatch_result,
85 Context** on_finish, Context* on_dispatched) override;
86
87 bool list_snaps(
88 uint64_t object_no, io::Extents&& extents, io::SnapIds&& snap_ids,
89 int list_snap_flags, const ZTracer::Trace &parent_trace,
90 io::SnapshotDelta* snapshot_delta, int* object_dispatch_flags,
91 io::DispatchResult* dispatch_result, Context** on_finish,
92 Context* on_dispatched) override {
93 return false;
94 }
95
96 bool invalidate_cache(Context* on_finish) override;
97 bool reset_existence_cache(Context* on_finish) override;
98
99 void extent_overwritten(
100 uint64_t object_no, uint64_t object_off, uint64_t object_len,
101 uint64_t journal_tid, uint64_t new_journal_tid) {
102 }
103
104 int prepare_copyup(
105 uint64_t object_no,
106 io::SnapshotSparseBufferlist* snapshot_sparse_bufferlist) override {
107 return 0;
108 }
109
110 private:
111 struct C_InvalidateCache;
112
113 ImageCtxT* m_image_ctx;
114 size_t m_max_dirty;
115 bool m_writethrough_until_flush;
116
117 ceph::mutex m_cache_lock;
118 ObjectCacher *m_object_cacher = nullptr;
119 ObjectCacher::ObjectSet *m_object_set = nullptr;
120
121 WritebackHandler *m_writeback_handler = nullptr;
122
123 bool m_user_flushed = false;
124
125 };
126
127 } // namespace cache
128 } // namespace librbd
129
130 extern template class librbd::cache::ObjectCacherObjectDispatch<librbd::ImageCtx>;
131
132 #endif // CEPH_LIBRBD_CACHE_OBJECT_CACHER_OBJECT_DISPATCH_H