]> git.proxmox.com Git - ceph.git/blame - ceph/src/rbd_replay/ios.hpp
d/control: depend on python3-yaml for ceph-mgr
[ceph.git] / ceph / src / rbd_replay / ios.hpp
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3/*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2014 Adam Crume <adamcrume@gmail.com>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15#ifndef _INCLUDED_RBD_REPLAY_IOS_HPP
16#define _INCLUDED_RBD_REPLAY_IOS_HPP
17
18// This code assumes that IO IDs and timestamps are related monotonically.
19// In other words, (a.id < b.id) == (a.timestamp < b.timestamp) for all IOs a and b.
20
21#include "include/buffer_fwd.h"
22#include <boost/enable_shared_from_this.hpp>
23#include <boost/shared_ptr.hpp>
24#include <iostream>
25#include <map>
26#include <set>
27#include <vector>
28#include "actions.hpp"
29
30
31namespace rbd_replay {
32
33class IO;
34
35typedef std::set<boost::shared_ptr<IO> > io_set_t;
36
37typedef std::map<action_id_t, boost::shared_ptr<IO> > io_map_t;
38
39/**
40 Used by rbd-replay-prep for processing the raw trace.
41 Corresponds to the Action class, except that Actions are executed by rbd-replay,
42 and IOs are used by rbd-replay-prep for processing the raw trace.
43 */
44class IO : public boost::enable_shared_from_this<IO> {
45public:
46 typedef boost::shared_ptr<IO> ptr;
47 typedef std::vector<ptr> ptrs;
48
49 /**
50 @param ionum ID of this %IO
51 @param start_time time the %IO started, in nanoseconds
52 @param thread_id ID of the thread that issued the %IO
53 */
54 IO(action_id_t ionum,
55 uint64_t start_time,
56 thread_id_t thread_id,
57 const io_set_t& deps)
58 : m_ionum(ionum),
59 m_start_time(start_time),
60 m_dependencies(deps),
61 m_thread_id(thread_id),
62 m_completed(false) {
63 }
64
65 virtual ~IO() {
66 }
67
68 uint64_t start_time() const {
69 return m_start_time;
70 }
71
72 io_set_t& dependencies() {
73 return m_dependencies;
74 }
75
76 const io_set_t& dependencies() const {
77 return m_dependencies;
78 }
79
80 virtual void encode(bufferlist &bl) const = 0;
81
82 void set_ionum(action_id_t ionum) {
83 m_ionum = ionum;
84 }
85
86 action_id_t ionum() const {
87 return m_ionum;
88 }
89
90 thread_id_t thread_id() const {
91 return m_thread_id;
92 }
93
94 virtual void write_debug(std::ostream& out) const = 0;
95
96protected:
11fdf7f2 97 void write_debug_base(std::ostream& out, const std::string &iotype) const;
7c673cae
FG
98
99private:
100 action_id_t m_ionum;
101 uint64_t m_start_time;
102 io_set_t m_dependencies;
103 thread_id_t m_thread_id;
104 bool m_completed;
105};
106
107/// Used for dumping debug info.
108/// @related IO
109std::ostream& operator<<(std::ostream &out, const IO::ptr &io);
110
111
112class StartThreadIO : public IO {
113public:
114 StartThreadIO(action_id_t ionum,
115 uint64_t start_time,
116 thread_id_t thread_id)
117 : IO(ionum, start_time, thread_id, io_set_t()) {
118 }
119
120 void encode(bufferlist &bl) const override;
121
122 void write_debug(std::ostream& out) const override;
123};
124
125class StopThreadIO : public IO {
126public:
127 StopThreadIO(action_id_t ionum,
128 uint64_t start_time,
129 thread_id_t thread_id,
130 const io_set_t& deps)
131 : IO(ionum, start_time, thread_id, deps) {
132 }
133
134 void encode(bufferlist &bl) const override;
135
136 void write_debug(std::ostream& out) const override;
137};
138
139class ReadIO : public IO {
140public:
141 ReadIO(action_id_t ionum,
142 uint64_t start_time,
143 thread_id_t thread_id,
144 const io_set_t& deps,
145 imagectx_id_t imagectx,
146 uint64_t offset,
147 uint64_t length)
148 : IO(ionum, start_time, thread_id, deps),
149 m_imagectx(imagectx),
150 m_offset(offset),
151 m_length(length) {
152 }
153
154 void encode(bufferlist &bl) const override;
155
156 void write_debug(std::ostream& out) const override;
157
158private:
159 imagectx_id_t m_imagectx;
160 uint64_t m_offset;
161 uint64_t m_length;
162};
163
164class WriteIO : public IO {
165public:
166 WriteIO(action_id_t ionum,
167 uint64_t start_time,
168 thread_id_t thread_id,
169 const io_set_t& deps,
170 imagectx_id_t imagectx,
171 uint64_t offset,
172 uint64_t length)
173 : IO(ionum, start_time, thread_id, deps),
174 m_imagectx(imagectx),
175 m_offset(offset),
176 m_length(length) {
177 }
178
179 void encode(bufferlist &bl) const override;
180
181 void write_debug(std::ostream& out) const override;
182
183private:
184 imagectx_id_t m_imagectx;
185 uint64_t m_offset;
186 uint64_t m_length;
187};
188
189class DiscardIO : public IO {
190public:
191 DiscardIO(action_id_t ionum,
192 uint64_t start_time,
193 thread_id_t thread_id,
194 const io_set_t& deps,
195 imagectx_id_t imagectx,
196 uint64_t offset,
197 uint64_t length)
198 : IO(ionum, start_time, thread_id, deps),
199 m_imagectx(imagectx),
200 m_offset(offset),
201 m_length(length) {
202 }
203
204 void encode(bufferlist &bl) const override;
205
206 void write_debug(std::ostream& out) const override;
207
208private:
209 imagectx_id_t m_imagectx;
210 uint64_t m_offset;
211 uint64_t m_length;
212};
213
214class AioReadIO : public IO {
215public:
216 AioReadIO(action_id_t ionum,
217 uint64_t start_time,
218 thread_id_t thread_id,
219 const io_set_t& deps,
220 imagectx_id_t imagectx,
221 uint64_t offset,
222 uint64_t length)
223 : IO(ionum, start_time, thread_id, deps),
224 m_imagectx(imagectx),
225 m_offset(offset),
226 m_length(length) {
227 }
228
229 void encode(bufferlist &bl) const override;
230
231 void write_debug(std::ostream& out) const override;
232
233private:
234 imagectx_id_t m_imagectx;
235 uint64_t m_offset;
236 uint64_t m_length;
237};
238
239class AioWriteIO : public IO {
240public:
241 AioWriteIO(action_id_t ionum,
242 uint64_t start_time,
243 thread_id_t thread_id,
244 const io_set_t& deps,
245 imagectx_id_t imagectx,
246 uint64_t offset,
247 uint64_t length)
248 : IO(ionum, start_time, thread_id, deps),
249 m_imagectx(imagectx),
250 m_offset(offset),
251 m_length(length) {
252 }
253
254 void encode(bufferlist &bl) const override;
255
256 void write_debug(std::ostream& out) const override;
257
258private:
259 imagectx_id_t m_imagectx;
260 uint64_t m_offset;
261 uint64_t m_length;
262};
263
264class AioDiscardIO : public IO {
265public:
266 AioDiscardIO(action_id_t ionum,
267 uint64_t start_time,
268 thread_id_t thread_id,
269 const io_set_t& deps,
270 imagectx_id_t imagectx,
271 uint64_t offset,
272 uint64_t length)
273 : IO(ionum, start_time, thread_id, deps),
274 m_imagectx(imagectx),
275 m_offset(offset),
276 m_length(length) {
277 }
278
279 void encode(bufferlist &bl) const override;
280
281 void write_debug(std::ostream& out) const override;
282
283private:
284 imagectx_id_t m_imagectx;
285 uint64_t m_offset;
286 uint64_t m_length;
287};
288
289class OpenImageIO : public IO {
290public:
291 OpenImageIO(action_id_t ionum,
292 uint64_t start_time,
293 thread_id_t thread_id,
294 const io_set_t& deps,
295 imagectx_id_t imagectx,
296 const std::string& name,
297 const std::string& snap_name,
298 bool readonly)
299 : IO(ionum, start_time, thread_id, deps),
300 m_imagectx(imagectx),
301 m_name(name),
302 m_snap_name(snap_name),
303 m_readonly(readonly) {
304 }
305
306 void encode(bufferlist &bl) const override;
307
308 imagectx_id_t imagectx() const {
309 return m_imagectx;
310 }
311
312 void write_debug(std::ostream& out) const override;
313
314private:
315 imagectx_id_t m_imagectx;
316 std::string m_name;
317 std::string m_snap_name;
318 bool m_readonly;
319};
320
321class CloseImageIO : public IO {
322public:
323 CloseImageIO(action_id_t ionum,
324 uint64_t start_time,
325 thread_id_t thread_id,
326 const io_set_t& deps,
327 imagectx_id_t imagectx)
328 : IO(ionum, start_time, thread_id, deps),
329 m_imagectx(imagectx) {
330 }
331
332 void encode(bufferlist &bl) const override;
333
334 imagectx_id_t imagectx() const {
335 return m_imagectx;
336 }
337
338 void write_debug(std::ostream& out) const override;
339
340private:
341 imagectx_id_t m_imagectx;
342};
343
344class AioOpenImageIO : public IO {
345public:
346 AioOpenImageIO(action_id_t ionum,
347 uint64_t start_time,
348 thread_id_t thread_id,
349 const io_set_t& deps,
350 imagectx_id_t imagectx,
351 const std::string& name,
352 const std::string& snap_name,
353 bool readonly)
354 : IO(ionum, start_time, thread_id, deps),
355 m_imagectx(imagectx),
356 m_name(name),
357 m_snap_name(snap_name),
358 m_readonly(readonly) {
359 }
360
361 void encode(bufferlist &bl) const override;
362
363 imagectx_id_t imagectx() const {
364 return m_imagectx;
365 }
366
367 void write_debug(std::ostream& out) const override;
368
369private:
370 imagectx_id_t m_imagectx;
371 std::string m_name;
372 std::string m_snap_name;
373 bool m_readonly;
374};
375
376class AioCloseImageIO : public IO {
377public:
378 AioCloseImageIO(action_id_t ionum,
379 uint64_t start_time,
380 thread_id_t thread_id,
381 const io_set_t& deps,
382 imagectx_id_t imagectx)
383 : IO(ionum, start_time, thread_id, deps),
384 m_imagectx(imagectx) {
385 }
386
387 void encode(bufferlist &bl) const override;
388
389 imagectx_id_t imagectx() const {
390 return m_imagectx;
391 }
392
393 void write_debug(std::ostream& out) const override;
394
395private:
396 imagectx_id_t m_imagectx;
397};
398
399}
400
401#endif