1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_RBD_REPLAY_ACTION_TYPES_H
5 #define CEPH_RBD_REPLAY_ACTION_TYPES_H
7 #include "include/int_types.h"
8 #include "include/buffer_fwd.h"
9 #include "include/encoding.h"
14 #include <boost/variant/variant.hpp>
16 namespace ceph { class Formatter; }
18 namespace rbd_replay {
21 typedef uint64_t imagectx_id_t;
22 typedef uint64_t thread_id_t;
24 /// Even IDs are normal actions, odd IDs are completions.
25 typedef uint32_t action_id_t;
27 static const std::string BANNER("rbd-replay-trace");
30 * Dependencies link actions to earlier actions or completions.
31 * If an action has a dependency \c d then it waits until \c d.time_delta
32 * nanoseconds after the action or completion with ID \c d.id has fired.
35 /// ID of the action or completion to wait for.
38 /// Nanoseconds of delay to wait until after the action or completion fires.
42 * @param id ID of the action or completion to wait for.
43 * @param time_delta Nanoseconds of delay to wait after the action or
46 Dependency() : id(0), time_delta(0) {
48 Dependency(action_id_t id, uint64_t time_delta)
49 : id(id), time_delta(time_delta) {
52 void encode(bufferlist &bl) const;
53 void decode(bufferlist::iterator &it);
54 void decode(__u8 version, bufferlist::iterator &it);
55 void dump(Formatter *f) const;
57 static void generate_test_instances(std::list<Dependency *> &o);
60 WRITE_CLASS_ENCODER(Dependency);
62 typedef std::vector<Dependency> Dependencies;
65 ACTION_TYPE_START_THREAD = 0,
66 ACTION_TYPE_STOP_THREAD = 1,
68 ACTION_TYPE_WRITE = 3,
69 ACTION_TYPE_AIO_READ = 4,
70 ACTION_TYPE_AIO_WRITE = 5,
71 ACTION_TYPE_OPEN_IMAGE = 6,
72 ACTION_TYPE_CLOSE_IMAGE = 7,
73 ACTION_TYPE_AIO_OPEN_IMAGE = 8,
74 ACTION_TYPE_AIO_CLOSE_IMAGE = 9,
75 ACTION_TYPE_DISCARD = 10,
76 ACTION_TYPE_AIO_DISCARD = 11
81 thread_id_t thread_id;
82 Dependencies dependencies;
84 ActionBase() : id(0), thread_id(0) {
86 ActionBase(action_id_t id, thread_id_t thread_id,
87 const Dependencies &dependencies)
88 : id(id), thread_id(thread_id), dependencies(dependencies) {
91 void encode(bufferlist &bl) const;
92 void decode(__u8 version, bufferlist::iterator &it);
93 void dump(Formatter *f) const;
96 struct StartThreadAction : public ActionBase {
97 static const ActionType ACTION_TYPE = ACTION_TYPE_START_THREAD;
101 StartThreadAction(action_id_t id, thread_id_t thread_id,
102 const Dependencies &dependencies)
103 : ActionBase(id, thread_id, dependencies) {
107 struct StopThreadAction : public ActionBase {
108 static const ActionType ACTION_TYPE = ACTION_TYPE_STOP_THREAD;
112 StopThreadAction(action_id_t id, thread_id_t thread_id,
113 const Dependencies &dependencies)
114 : ActionBase(id, thread_id, dependencies) {
118 struct ImageActionBase : public ActionBase {
119 imagectx_id_t imagectx_id;
121 ImageActionBase() : imagectx_id(0) {
123 ImageActionBase(action_id_t id, thread_id_t thread_id,
124 const Dependencies &dependencies, imagectx_id_t imagectx_id)
125 : ActionBase(id, thread_id, dependencies), imagectx_id(imagectx_id) {
128 void encode(bufferlist &bl) const;
129 void decode(__u8 version, bufferlist::iterator &it);
130 void dump(Formatter *f) const;
133 struct IoActionBase : public ImageActionBase {
137 IoActionBase() : offset(0), length(0) {
139 IoActionBase(action_id_t id, thread_id_t thread_id,
140 const Dependencies &dependencies, imagectx_id_t imagectx_id,
141 uint64_t offset, uint64_t length)
142 : ImageActionBase(id, thread_id, dependencies, imagectx_id),
143 offset(offset), length(length) {
146 void encode(bufferlist &bl) const;
147 void decode(__u8 version, bufferlist::iterator &it);
148 void dump(Formatter *f) const;
151 struct ReadAction : public IoActionBase {
152 static const ActionType ACTION_TYPE = ACTION_TYPE_READ;
156 ReadAction(action_id_t id, thread_id_t thread_id,
157 const Dependencies &dependencies, imagectx_id_t imagectx_id,
158 uint64_t offset, uint64_t length)
159 : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
163 struct WriteAction : public IoActionBase {
164 static const ActionType ACTION_TYPE = ACTION_TYPE_WRITE;
168 WriteAction(action_id_t id, thread_id_t thread_id,
169 const Dependencies &dependencies, imagectx_id_t imagectx_id,
170 uint64_t offset, uint64_t length)
171 : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
175 struct DiscardAction : public IoActionBase {
176 static const ActionType ACTION_TYPE = ACTION_TYPE_DISCARD;
180 DiscardAction(action_id_t id, thread_id_t thread_id,
181 const Dependencies &dependencies, imagectx_id_t imagectx_id,
182 uint64_t offset, uint64_t length)
183 : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
187 struct AioReadAction : public IoActionBase {
188 static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_READ;
192 AioReadAction(action_id_t id, thread_id_t thread_id,
193 const Dependencies &dependencies, imagectx_id_t imagectx_id,
194 uint64_t offset, uint64_t length)
195 : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
199 struct AioWriteAction : public IoActionBase {
200 static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_WRITE;
204 AioWriteAction(action_id_t id, thread_id_t thread_id,
205 const Dependencies &dependencies, imagectx_id_t imagectx_id,
206 uint64_t offset, uint64_t length)
207 : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
211 struct AioDiscardAction : public IoActionBase {
212 static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_DISCARD;
216 AioDiscardAction(action_id_t id, thread_id_t thread_id,
217 const Dependencies &dependencies, imagectx_id_t imagectx_id,
218 uint64_t offset, uint64_t length)
219 : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
223 struct OpenImageAction : public ImageActionBase {
224 static const ActionType ACTION_TYPE = ACTION_TYPE_OPEN_IMAGE;
227 std::string snap_name;
230 OpenImageAction() : read_only(false) {
232 OpenImageAction(action_id_t id, thread_id_t thread_id,
233 const Dependencies &dependencies, imagectx_id_t imagectx_id,
234 const std::string &name, const std::string &snap_name,
236 : ImageActionBase(id, thread_id, dependencies, imagectx_id),
237 name(name), snap_name(snap_name), read_only(read_only) {
240 void encode(bufferlist &bl) const;
241 void decode(__u8 version, bufferlist::iterator &it);
242 void dump(Formatter *f) const;
245 struct CloseImageAction : public ImageActionBase {
246 static const ActionType ACTION_TYPE = ACTION_TYPE_CLOSE_IMAGE;
250 CloseImageAction(action_id_t id, thread_id_t thread_id,
251 const Dependencies &dependencies, imagectx_id_t imagectx_id)
252 : ImageActionBase(id, thread_id, dependencies, imagectx_id) {
256 struct AioOpenImageAction : public ImageActionBase {
257 static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_OPEN_IMAGE;
260 std::string snap_name;
263 AioOpenImageAction() : read_only(false) {
265 AioOpenImageAction(action_id_t id, thread_id_t thread_id,
266 const Dependencies &dependencies, imagectx_id_t imagectx_id,
267 const std::string &name, const std::string &snap_name,
269 : ImageActionBase(id, thread_id, dependencies, imagectx_id),
270 name(name), snap_name(snap_name), read_only(read_only) {
273 void encode(bufferlist &bl) const;
274 void decode(__u8 version, bufferlist::iterator &it);
275 void dump(Formatter *f) const;
278 struct AioCloseImageAction : public ImageActionBase {
279 static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_CLOSE_IMAGE;
281 AioCloseImageAction() {
283 AioCloseImageAction(action_id_t id, thread_id_t thread_id,
284 const Dependencies &dependencies, imagectx_id_t imagectx_id)
285 : ImageActionBase(id, thread_id, dependencies, imagectx_id) {
289 struct UnknownAction {
290 static const ActionType ACTION_TYPE = static_cast<ActionType>(-1);
292 void encode(bufferlist &bl) const;
293 void decode(__u8 version, bufferlist::iterator &it);
294 void dump(Formatter *f) const;
297 typedef boost::variant<StartThreadAction,
309 UnknownAction> Action;
315 ActionEntry() : action(UnknownAction()) {
317 ActionEntry(const Action &action) : action(action) {
320 void encode(bufferlist &bl) const;
321 void decode(bufferlist::iterator &it);
322 void decode_unversioned(bufferlist::iterator &it);
323 void dump(Formatter *f) const;
325 static void generate_test_instances(std::list<ActionEntry *> &o);
328 void decode(__u8 version, bufferlist::iterator &it);
331 WRITE_CLASS_ENCODER(ActionEntry);
333 } // namespace action
334 } // namespace rbd_replay
336 std::ostream &operator<<(std::ostream &out,
337 const rbd_replay::action::ActionType &type);
339 using rbd_replay::action::decode;
340 using rbd_replay::action::encode;
342 #endif // CEPH_RBD_REPLAY_ACTION_TYPES_H