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_OBJECT_CACHER_OBJECT_DISPATCH_H
5 #define CEPH_LIBRBD_CACHE_OBJECT_CACHER_OBJECT_DISPATCH_H
7 #include "librbd/io/ObjectDispatchInterface.h"
8 #include "common/ceph_mutex.h"
9 #include "osdc/ObjectCacher.h"
11 struct WritebackHandler
;
20 * Facade around the OSDC object cacher to make it align with
21 * the object dispatcher interface
23 template <typename ImageCtxT
= ImageCtx
>
24 class ObjectCacherObjectDispatch
: public io::ObjectDispatchInterface
{
26 static ObjectCacherObjectDispatch
* create(ImageCtxT
* image_ctx
,
28 bool writethrough_until_flush
) {
29 return new ObjectCacherObjectDispatch(image_ctx
, max_dirty
,
30 writethrough_until_flush
);
33 ObjectCacherObjectDispatch(ImageCtxT
* image_ctx
, size_t max_dirty
,
34 bool writethrough_until_flush
);
35 ~ObjectCacherObjectDispatch() override
;
37 io::ObjectDispatchLayer
get_dispatch_layer() const override
{
38 return io::OBJECT_DISPATCH_LAYER_CACHE
;
42 void shut_down(Context
* on_finish
) override
;
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
;
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
;
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
;
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
;
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
;
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
;
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
{
96 bool invalidate_cache(Context
* on_finish
) override
;
97 bool reset_existence_cache(Context
* on_finish
) override
;
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
) {
106 io::SnapshotSparseBufferlist
* snapshot_sparse_bufferlist
) override
{
111 struct C_InvalidateCache
;
113 ImageCtxT
* m_image_ctx
;
115 bool m_writethrough_until_flush
;
117 ceph::mutex m_cache_lock
;
118 ObjectCacher
*m_object_cacher
= nullptr;
119 ObjectCacher::ObjectSet
*m_object_set
= nullptr;
121 WritebackHandler
*m_writeback_handler
= nullptr;
123 bool m_user_flushed
= false;
128 } // namespace librbd
130 extern template class librbd::cache::ObjectCacherObjectDispatch
<librbd::ImageCtx
>;
132 #endif // CEPH_LIBRBD_CACHE_OBJECT_CACHER_OBJECT_DISPATCH_H