]> git.proxmox.com Git - ceph.git/blame - ceph/src/librbd/exclusive_lock/ImageDispatch.h
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / librbd / exclusive_lock / ImageDispatch.h
CommitLineData
f67539c2
TL
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_EXCLUSIVE_LOCK_IMAGE_DISPATCH_H
5#define CEPH_LIBRBD_EXCLUSIVE_LOCK_IMAGE_DISPATCH_H
6
7#include "librbd/io/ImageDispatchInterface.h"
8#include "include/int_types.h"
9#include "include/buffer.h"
10#include "common/ceph_mutex.h"
11#include "common/zipkin_trace.h"
12#include "librbd/io/ReadResult.h"
13#include "librbd/io/Types.h"
14#include <atomic>
15#include <list>
16#include <unordered_set>
17
18struct Context;
19
20namespace librbd {
21
22struct ImageCtx;
23
24namespace io {
25struct AioCompletion;
26}
27
28namespace exclusive_lock {
29
30template <typename ImageCtxT>
31class ImageDispatch : public io::ImageDispatchInterface {
32public:
33 static ImageDispatch* create(ImageCtxT* image_ctx) {
34 return new ImageDispatch(image_ctx);
35 }
36 void destroy() {
37 delete this;
38 }
39
40 ImageDispatch(ImageCtxT* image_ctx);
41
42 io::ImageDispatchLayer get_dispatch_layer() const override {
43 return io::IMAGE_DISPATCH_LAYER_EXCLUSIVE_LOCK;
44 }
45
46 void set_require_lock(bool init_shutdown,
47 io::Direction direction, Context* on_finish);
48 void unset_require_lock(io::Direction direction);
49
50 void shut_down(Context* on_finish) override;
51
52 bool read(
53 io::AioCompletion* aio_comp, io::Extents &&image_extents,
54 io::ReadResult &&read_result, IOContext io_context, int op_flags,
55 int read_flags, const ZTracer::Trace &parent_trace, uint64_t tid,
56 std::atomic<uint32_t>* image_dispatch_flags,
57 io::DispatchResult* dispatch_result, Context** on_finish,
58 Context* on_dispatched) override;
59 bool write(
60 io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
1e59de90 61 int op_flags, const ZTracer::Trace &parent_trace,
f67539c2
TL
62 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
63 io::DispatchResult* dispatch_result, Context** on_finish,
64 Context* on_dispatched) override;
65 bool discard(
66 io::AioCompletion* aio_comp, io::Extents &&image_extents,
1e59de90
TL
67 uint32_t discard_granularity_bytes, const ZTracer::Trace &parent_trace,
68 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
f67539c2
TL
69 io::DispatchResult* dispatch_result, Context** on_finish,
70 Context* on_dispatched) override;
71 bool write_same(
72 io::AioCompletion* aio_comp, io::Extents &&image_extents, bufferlist &&bl,
1e59de90 73 int op_flags, const ZTracer::Trace &parent_trace,
f67539c2
TL
74 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
75 io::DispatchResult* dispatch_result, Context** on_finish,
76 Context* on_dispatched) override;
77 bool compare_and_write(
78 io::AioCompletion* aio_comp, io::Extents &&image_extents,
79 bufferlist &&cmp_bl, bufferlist &&bl, uint64_t *mismatch_offset,
1e59de90 80 int op_flags, const ZTracer::Trace &parent_trace,
f67539c2
TL
81 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
82 io::DispatchResult* dispatch_result, Context** on_finish,
83 Context* on_dispatched) override;
84 bool flush(
85 io::AioCompletion* aio_comp, io::FlushSource flush_source,
86 const ZTracer::Trace &parent_trace, uint64_t tid,
87 std::atomic<uint32_t>* image_dispatch_flags,
88 io::DispatchResult* dispatch_result, Context** on_finish,
89 Context* on_dispatched) override;
90
91 bool list_snaps(
92 io::AioCompletion* aio_comp, io::Extents&& image_extents,
93 io::SnapIds&& snap_ids, int list_snaps_flags,
94 io::SnapshotDelta* snapshot_delta, const ZTracer::Trace &parent_trace,
95 uint64_t tid, std::atomic<uint32_t>* image_dispatch_flags,
96 io::DispatchResult* dispatch_result, Context** on_finish,
97 Context* on_dispatched) override {
98 return false;
99 }
100
101 bool invalidate_cache(Context* on_finish) override {
102 return false;
103 }
104
105private:
106 typedef std::list<Context*> Contexts;
107 typedef std::unordered_set<uint64_t> Tids;
108
109 ImageCtxT* m_image_ctx;
110 mutable ceph::shared_mutex m_lock;
111
112 bool m_require_lock_on_read = false;
113 bool m_require_lock_on_write = false;
114
115 Contexts m_on_dispatches;
116
117 bool set_require_lock(io::Direction direction, bool enabled);
118
119 bool is_lock_required(bool read_op) const;
120
121 bool needs_exclusive_lock(bool read_op, uint64_t tid,
122 io::DispatchResult* dispatch_result,
123 Context* on_dispatched);
124
125 void handle_acquire_lock(int r);
126};
127
128} // namespace exclusiv_lock
129} // namespace librbd
130
131extern template class librbd::exclusive_lock::ImageDispatch<librbd::ImageCtx>;
132
133#endif // CEPH_LIBRBD_EXCLUSIVE_LOCK_IMAGE_DISPATCH_H