]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/WriteLogImageDispatch.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / cache / WriteLogImageDispatch.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_WRITELOG_IMAGE_DISPATCH_H
5 #define CEPH_LIBRBD_WRITELOG_IMAGE_DISPATCH_H
6
7 #include "librbd/io/ImageDispatchInterface.h"
8 #include "include/int_types.h"
9 #include "include/buffer.h"
10 #include "common/zipkin_trace.h"
11 #include "librbd/io/ReadResult.h"
12 #include "librbd/io/Types.h"
13 #include "librbd/plugin/Api.h"
14
15 struct Context;
16
17 namespace librbd {
18
19 struct ImageCtx;
20
21 namespace cache {
22
23 namespace pwl { template <typename> class AbstractWriteLog; }
24
25 template <typename ImageCtxT>
26 class WriteLogImageDispatch : public io::ImageDispatchInterface {
27 public:
28 WriteLogImageDispatch(ImageCtxT* image_ctx,
29 pwl::AbstractWriteLog<ImageCtx> *image_cache,
30 plugin::Api<ImageCtxT>& plugin_api) :
31 m_image_ctx(image_ctx), m_image_cache(image_cache),
32 m_plugin_api(plugin_api) {
33 }
34
35 io::ImageDispatchLayer get_dispatch_layer() const override {
36 return io::IMAGE_DISPATCH_LAYER_WRITEBACK_CACHE;
37 }
38
39 void shut_down(Context* on_finish) override;
40
41 bool read(
42 io::AioCompletion* aio_comp, io::Extents &&image_extents,
43 io::ReadResult &&read_result, IOContext io_context,
44 int op_flags, int read_flags,
45 const ZTracer::Trace &parent_trace, uint64_t tid,
46 std::atomic<uint32_t>* image_dispatch_flags,
47 io::DispatchResult* dispatch_result, Context** on_finish,
48 Context* on_dispatched) override;
49 bool write(
50 io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
51 IOContext io_context, int op_flags, const ZTracer::Trace &parent_trace,
52 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
53 io::DispatchResult* dispatch_result,
54 Context** on_finish, Context* on_dispatched) override;
55 bool discard(
56 io::AioCompletion* aio_comp, io::Extents &&image_extents,
57 uint32_t discard_granularity_bytes, IOContext io_context,
58 const ZTracer::Trace &parent_trace, uint64_t tid,
59 std::atomic<uint32_t>* image_dispatch_flags,
60 io::DispatchResult* dispatch_result,
61 Context** on_finish, Context* on_dispatched) override;
62 bool write_same(
63 io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
64 IOContext io_context, int op_flags, const ZTracer::Trace &parent_trace,
65 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
66 io::DispatchResult* dispatch_result,
67 Context** on_finish, Context* on_dispatched) override;
68 bool compare_and_write(
69 io::AioCompletion* aio_comp, io::Extents &&image_extents,
70 bufferlist &&cmp_bl,
71 bufferlist &&bl, uint64_t *mismatch_offset,
72 IOContext io_context, int op_flags,
73 const ZTracer::Trace &parent_trace, uint64_t tid,
74 std::atomic<uint32_t>* image_dispatch_flags,
75 io::DispatchResult* dispatch_result,
76 Context** on_finish, Context* on_dispatched) override;
77 bool flush(
78 io::AioCompletion* aio_comp, io::FlushSource flush_source,
79 const ZTracer::Trace &parent_trace, uint64_t tid,
80 std::atomic<uint32_t>* image_dispatch_flags,
81 io::DispatchResult* dispatch_result,
82 Context** on_finish, Context* on_dispatched) override;
83 bool list_snaps(
84 io::AioCompletion* aio_comp, io::Extents&& image_extents,
85 io::SnapIds&& snap_ids, int list_snaps_flags,
86 io::SnapshotDelta* snapshot_delta,
87 const ZTracer::Trace &parent_trace, uint64_t tid,
88 std::atomic<uint32_t>* image_dispatch_flags,
89 io::DispatchResult* dispatch_result, Context** on_finish,
90 Context* on_dispatched) override;
91
92 bool invalidate_cache(Context* on_finish) override;
93
94 private:
95 ImageCtxT* m_image_ctx;
96 pwl::AbstractWriteLog<ImageCtx> *m_image_cache;
97 plugin::Api<ImageCtxT>& m_plugin_api;
98
99 bool preprocess_length(
100 io::AioCompletion* aio_comp, io::Extents &image_extents) const;
101 };
102
103 } // namespace cache
104 } // namespace librbd
105
106 extern template class librbd::cache::WriteLogImageDispatch<librbd::ImageCtx>;
107
108 #endif // CEPH_LIBRBD_WRITELOG_IMAGE_DISPATCH_H