]> git.proxmox.com Git - ceph.git/blob - ceph/src/librbd/cache/pwl/LogOperation.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / librbd / cache / pwl / LogOperation.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_RWL_LOG_OPERATION_H
5 #define CEPH_LIBRBD_CACHE_RWL_LOG_OPERATION_H
6
7 #include "include/utime.h"
8 #include "librbd/cache/pwl/LogEntry.h"
9 #include "librbd/cache/pwl/SyncPoint.h"
10
11 namespace librbd {
12 namespace cache {
13 namespace pwl {
14
15 struct WriteBufferAllocation;
16
17 class WriteLogOperationSet;
18
19 class WriteLogOperation;
20
21 class GenericWriteLogOperation;
22
23 class SyncPointLogOperation;
24
25 class GenericLogOperation;
26
27 template <typename T>
28 class AbstractWriteLog;
29
30 using GenericLogOperationSharedPtr = std::shared_ptr<GenericLogOperation>;
31
32 using GenericLogOperationsVector = std::vector<GenericLogOperationSharedPtr>;
33
34 class GenericLogOperation {
35 protected:
36 PerfCounters *m_perfcounter = nullptr;
37 public:
38 utime_t dispatch_time; // When op created
39 utime_t buf_persist_time; // When buffer persist begins
40 utime_t buf_persist_comp_time; // When buffer persist completes
41 utime_t log_append_time; // When log append begins
42 utime_t log_append_comp_time; // When log append completes
43 GenericLogOperation(utime_t dispatch_time, PerfCounters *perfcounter);
44 virtual ~GenericLogOperation() { };
45 GenericLogOperation(const GenericLogOperation&) = delete;
46 GenericLogOperation &operator=(const GenericLogOperation&) = delete;
47 virtual std::ostream &format(std::ostream &os) const;
48 friend std::ostream &operator<<(std::ostream &os,
49 const GenericLogOperation &op);
50 virtual const std::shared_ptr<GenericLogEntry> get_log_entry() = 0;
51 virtual void appending() = 0;
52 virtual void complete(int r) = 0;
53 virtual void mark_log_entry_completed() {};
54 virtual bool reserved_allocated() const {
55 return false;
56 }
57 virtual bool is_writing_op() const {
58 return false;
59 }
60 virtual void init_op(uint64_t current_sync_gen, bool persist_on_flush,
61 uint64_t last_op_sequence_num, Context *write_persist,
62 Context *write_append) {};
63 virtual void copy_bl_to_cache_buffer(
64 std::vector<WriteBufferAllocation>::iterator allocation) {};
65 };
66
67 class SyncPointLogOperation : public GenericLogOperation {
68 private:
69 CephContext *m_cct;
70 ceph::mutex &m_lock;
71 std::vector<Context*> append_sync_point();
72 void clear_earlier_sync_point();
73 std::vector<Context*> swap_on_sync_point_persisted();
74 public:
75 std::shared_ptr<SyncPoint> sync_point;
76 SyncPointLogOperation(ceph::mutex &lock,
77 std::shared_ptr<SyncPoint> sync_point,
78 utime_t dispatch_time,
79 PerfCounters *perfcounter,
80 CephContext *cct);
81 ~SyncPointLogOperation() override;
82 SyncPointLogOperation(const SyncPointLogOperation&) = delete;
83 SyncPointLogOperation &operator=(const SyncPointLogOperation&) = delete;
84 std::ostream &format(std::ostream &os) const;
85 friend std::ostream &operator<<(std::ostream &os,
86 const SyncPointLogOperation &op);
87 const std::shared_ptr<GenericLogEntry> get_log_entry() override {
88 return sync_point->log_entry;
89 }
90 void appending() override;
91 void complete(int r) override;
92 };
93
94 class GenericWriteLogOperation : public GenericLogOperation {
95 protected:
96 ceph::mutex m_lock;
97 CephContext *m_cct;
98 public:
99 std::shared_ptr<SyncPoint> sync_point;
100 Context *on_write_append = nullptr; /* Completion for things waiting on this
101 * write's position in the log to be
102 * guaranteed */
103 Context *on_write_persist = nullptr; /* Completion for things waiting on this
104 * write to persist */
105 GenericWriteLogOperation(std::shared_ptr<SyncPoint> sync_point,
106 utime_t dispatch_time,
107 PerfCounters *perfcounter,
108 CephContext *cct);
109 ~GenericWriteLogOperation() override;
110 GenericWriteLogOperation(const GenericWriteLogOperation&) = delete;
111 GenericWriteLogOperation &operator=(const GenericWriteLogOperation&) = delete;
112 std::ostream &format(std::ostream &os) const;
113 friend std::ostream &operator<<(std::ostream &os,
114 const GenericWriteLogOperation &op);
115 void mark_log_entry_completed() override{
116 sync_point->log_entry->writes_completed++;
117 }
118 bool reserved_allocated() const override {
119 return true;
120 }
121 bool is_writing_op() const override {
122 return true;
123 }
124 void appending() override;
125 void complete(int r) override;
126 };
127
128 class WriteLogOperation : public GenericWriteLogOperation {
129 public:
130 using GenericWriteLogOperation::m_lock;
131 using GenericWriteLogOperation::sync_point;
132 using GenericWriteLogOperation::on_write_append;
133 using GenericWriteLogOperation::on_write_persist;
134 std::shared_ptr<WriteLogEntry> log_entry;
135 bufferlist bl;
136 bool is_writesame = false;
137 WriteBufferAllocation *buffer_alloc = nullptr;
138 WriteLogOperation(WriteLogOperationSet &set,
139 uint64_t image_offset_bytes,
140 uint64_t write_bytes, CephContext *cct,
141 std::shared_ptr<WriteLogEntry> write_log_entry);
142 WriteLogOperation(WriteLogOperationSet &set,
143 uint64_t image_offset_bytes,
144 uint64_t write_bytes, uint32_t data_len,
145 CephContext *cct,
146 std::shared_ptr<WriteLogEntry> writesame_log_entry);
147 ~WriteLogOperation() override;
148 WriteLogOperation(const WriteLogOperation&) = delete;
149 WriteLogOperation &operator=(const WriteLogOperation&) = delete;
150 void init(bool has_data,
151 std::vector<WriteBufferAllocation>::iterator allocation,
152 uint64_t current_sync_gen, uint64_t last_op_sequence_num,
153 bufferlist &write_req_bl, uint64_t buffer_offset,
154 bool persist_on_flush);
155 std::ostream &format(std::ostream &os) const;
156 friend std::ostream &operator<<(std::ostream &os,
157 const WriteLogOperation &op);
158 const std::shared_ptr<GenericLogEntry> get_log_entry() override {
159 return log_entry;
160 }
161
162 void complete(int r) override;
163 };
164
165
166 class WriteLogOperationSet {
167 private:
168 CephContext *m_cct;
169 Context *m_on_finish;
170 public:
171 bool persist_on_flush;
172 BlockGuardCell *cell;
173 C_Gather *extent_ops_appending;
174 Context *on_ops_appending;
175 C_Gather *extent_ops_persist;
176 Context *on_ops_persist;
177 GenericLogOperationsVector operations;
178 utime_t dispatch_time; /* When set created */
179 PerfCounters *perfcounter = nullptr;
180 std::shared_ptr<SyncPoint> sync_point;
181 WriteLogOperationSet(utime_t dispatched, PerfCounters *perfcounter,
182 std::shared_ptr<SyncPoint> sync_point,
183 const bool persist_on_flush, CephContext *cct,
184 Context *on_finish);
185 ~WriteLogOperationSet();
186 WriteLogOperationSet(const WriteLogOperationSet&) = delete;
187 WriteLogOperationSet &operator=(const WriteLogOperationSet&) = delete;
188 friend std::ostream &operator<<(std::ostream &os,
189 const WriteLogOperationSet &s);
190 };
191
192 class DiscardLogOperation : public GenericWriteLogOperation {
193 public:
194 using GenericWriteLogOperation::m_lock;
195 using GenericWriteLogOperation::sync_point;
196 using GenericWriteLogOperation::on_write_append;
197 using GenericWriteLogOperation::on_write_persist;
198 std::shared_ptr<DiscardLogEntry> log_entry;
199 DiscardLogOperation(std::shared_ptr<SyncPoint> sync_point,
200 uint64_t image_offset_bytes,
201 uint64_t write_bytes,
202 uint32_t discard_granularity_bytes,
203 utime_t dispatch_time,
204 PerfCounters *perfcounter,
205 CephContext *cct);
206 ~DiscardLogOperation() override;
207 DiscardLogOperation(const DiscardLogOperation&) = delete;
208 DiscardLogOperation &operator=(const DiscardLogOperation&) = delete;
209 const std::shared_ptr<GenericLogEntry> get_log_entry() override {
210 return log_entry;
211 }
212 bool reserved_allocated() const override {
213 return false;
214 }
215 std::ostream &format(std::ostream &os) const;
216 friend std::ostream &operator<<(std::ostream &os,
217 const DiscardLogOperation &op);
218 };
219
220 } // namespace pwl
221 } // namespace cache
222 } // namespace librbd
223
224 #endif // CEPH_LIBRBD_CACHE_RWL_LOG_OPERATION_H