summaryrefslogtreecommitdiffstats
path: root/src/rbd_replay/ActionTypes.h
blob: 19e1bb8fabfef3131b377b2c71dfcf9d08ec8634 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#ifndef CEPH_RBD_REPLAY_ACTION_TYPES_H
#define CEPH_RBD_REPLAY_ACTION_TYPES_H

#include "include/int_types.h"
#include "include/buffer_fwd.h"
#include "include/encoding.h"
#include <iosfwd>
#include <list>
#include <string>
#include <vector>
#include <boost/variant/variant.hpp>

namespace ceph { class Formatter; }

namespace rbd_replay {
namespace action {

typedef uint64_t imagectx_id_t;
typedef uint64_t thread_id_t;

/// Even IDs are normal actions, odd IDs are completions.
typedef uint32_t action_id_t;

static const std::string BANNER("rbd-replay-trace");

/**
 * Dependencies link actions to earlier actions or completions.
 * If an action has a dependency \c d then it waits until \c d.time_delta
 * nanoseconds after the action or completion with ID \c d.id has fired.
 */
struct Dependency {
  /// ID of the action or completion to wait for.
  action_id_t id;

  /// Nanoseconds of delay to wait until after the action or completion fires.
  uint64_t time_delta;

  /**
   * @param id ID of the action or completion to wait for.
   * @param time_delta Nanoseconds of delay to wait after the action or
   *                   completion fires.
   */
  Dependency() : id(0), time_delta(0) {
  }
  Dependency(action_id_t id, uint64_t time_delta)
    : id(id), time_delta(time_delta) {
  }

  void encode(bufferlist &bl) const;
  void decode(bufferlist::const_iterator &it);
  void decode(__u8 version, bufferlist::const_iterator &it);
  void dump(Formatter *f) const;

  static void generate_test_instances(std::list<Dependency *> &o);
};

WRITE_CLASS_ENCODER(Dependency);

typedef std::vector<Dependency> Dependencies;

enum ActionType {
  ACTION_TYPE_START_THREAD    = 0,
  ACTION_TYPE_STOP_THREAD     = 1,
  ACTION_TYPE_READ            = 2,
  ACTION_TYPE_WRITE           = 3,
  ACTION_TYPE_AIO_READ        = 4,
  ACTION_TYPE_AIO_WRITE       = 5,
  ACTION_TYPE_OPEN_IMAGE      = 6,
  ACTION_TYPE_CLOSE_IMAGE     = 7,
  ACTION_TYPE_AIO_OPEN_IMAGE  = 8,
  ACTION_TYPE_AIO_CLOSE_IMAGE = 9,
  ACTION_TYPE_DISCARD         = 10,
  ACTION_TYPE_AIO_DISCARD     = 11
};

struct ActionBase {
  action_id_t id;
  thread_id_t thread_id;
  Dependencies dependencies;

  ActionBase() : id(0), thread_id(0) {
  }
  ActionBase(action_id_t id, thread_id_t thread_id,
             const Dependencies &dependencies)
    : id(id), thread_id(thread_id), dependencies(dependencies) {
  }

  void encode(bufferlist &bl) const;
  void decode(__u8 version, bufferlist::const_iterator &it);
  void dump(Formatter *f) const;
};

struct StartThreadAction : public ActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_START_THREAD;

  StartThreadAction() {
  }
  StartThreadAction(action_id_t id, thread_id_t thread_id,
                    const Dependencies &dependencies)
    : ActionBase(id, thread_id, dependencies) {
  }
};

struct StopThreadAction : public ActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_STOP_THREAD;

  StopThreadAction() {
  }
  StopThreadAction(action_id_t id, thread_id_t thread_id,
                   const Dependencies &dependencies)
    : ActionBase(id, thread_id, dependencies) {
  }
};

struct ImageActionBase : public ActionBase {
  imagectx_id_t imagectx_id;

  ImageActionBase() : imagectx_id(0) {
  }
  ImageActionBase(action_id_t id, thread_id_t thread_id,
                  const Dependencies &dependencies, imagectx_id_t imagectx_id)
    : ActionBase(id, thread_id, dependencies), imagectx_id(imagectx_id) {
  }

  void encode(bufferlist &bl) const;
  void decode(__u8 version, bufferlist::const_iterator &it);
  void dump(Formatter *f) const;
};

struct IoActionBase : public ImageActionBase {
  uint64_t offset;
  uint64_t length;

  IoActionBase() : offset(0), length(0) {
  }
  IoActionBase(action_id_t id, thread_id_t thread_id,
               const Dependencies &dependencies, imagectx_id_t imagectx_id,
               uint64_t offset, uint64_t length)
    : ImageActionBase(id, thread_id, dependencies, imagectx_id),
      offset(offset), length(length) {
  }

  void encode(bufferlist &bl) const;
  void decode(__u8 version, bufferlist::const_iterator &it);
  void dump(Formatter *f) const;
};

struct ReadAction : public IoActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_READ;

  ReadAction() {
  }
  ReadAction(action_id_t id, thread_id_t thread_id,
             const Dependencies &dependencies, imagectx_id_t imagectx_id,
             uint64_t offset, uint64_t length)
    : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
  }
};

struct WriteAction : public IoActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_WRITE;

  WriteAction() {
  }
  WriteAction(action_id_t id, thread_id_t thread_id,
              const Dependencies &dependencies, imagectx_id_t imagectx_id,
              uint64_t offset, uint64_t length)
    : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
  }
};

struct DiscardAction : public IoActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_DISCARD;

  DiscardAction() {
  }
  DiscardAction(action_id_t id, thread_id_t thread_id,
                const Dependencies &dependencies, imagectx_id_t imagectx_id,
                uint64_t offset, uint64_t length)
    : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
  }
};

struct AioReadAction : public IoActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_READ;

  AioReadAction() {
  }
  AioReadAction(action_id_t id, thread_id_t thread_id,
                const Dependencies &dependencies, imagectx_id_t imagectx_id,
                uint64_t offset, uint64_t length)
    : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
  }
};

struct AioWriteAction : public IoActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_WRITE;

  AioWriteAction() {
  }
  AioWriteAction(action_id_t id, thread_id_t thread_id,
                 const Dependencies &dependencies, imagectx_id_t imagectx_id,
                 uint64_t offset, uint64_t length)
    : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
  }
};

struct AioDiscardAction : public IoActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_DISCARD;

  AioDiscardAction() {
  }
  AioDiscardAction(action_id_t id, thread_id_t thread_id,
                   const Dependencies &dependencies, imagectx_id_t imagectx_id,
                   uint64_t offset, uint64_t length)
    : IoActionBase(id, thread_id, dependencies, imagectx_id, offset, length) {
  }
};

struct OpenImageAction : public ImageActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_OPEN_IMAGE;

  std::string name;
  std::string snap_name;
  bool read_only;

  OpenImageAction() : read_only(false) {
  }
  OpenImageAction(action_id_t id, thread_id_t thread_id,
                  const Dependencies &dependencies, imagectx_id_t imagectx_id,
                  const std::string &name, const std::string &snap_name,
                  bool read_only)
    : ImageActionBase(id, thread_id, dependencies, imagectx_id),
      name(name), snap_name(snap_name), read_only(read_only) {
  }

  void encode(bufferlist &bl) const;
  void decode(__u8 version, bufferlist::const_iterator &it);
  void dump(Formatter *f) const;
};

struct CloseImageAction : public ImageActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_CLOSE_IMAGE;

  CloseImageAction() {
  }
  CloseImageAction(action_id_t id, thread_id_t thread_id,
                   const Dependencies &dependencies, imagectx_id_t imagectx_id)
    : ImageActionBase(id, thread_id, dependencies, imagectx_id) {
  }
};

struct AioOpenImageAction : public ImageActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_OPEN_IMAGE;

  std::string name;
  std::string snap_name;
  bool read_only;

  AioOpenImageAction() : read_only(false) {
  }
  AioOpenImageAction(action_id_t id, thread_id_t thread_id,
		     const Dependencies &dependencies, imagectx_id_t imagectx_id,
		     const std::string &name, const std::string &snap_name,
		     bool read_only)
    : ImageActionBase(id, thread_id, dependencies, imagectx_id),
      name(name), snap_name(snap_name), read_only(read_only) {
  }

  void encode(bufferlist &bl) const;
  void decode(__u8 version, bufferlist::const_iterator &it);
  void dump(Formatter *f) const;
};

struct AioCloseImageAction : public ImageActionBase {
  static const ActionType ACTION_TYPE = ACTION_TYPE_AIO_CLOSE_IMAGE;

  AioCloseImageAction() {
  }
  AioCloseImageAction(action_id_t id, thread_id_t thread_id,
		      const Dependencies &dependencies, imagectx_id_t imagectx_id)
    : ImageActionBase(id, thread_id, dependencies, imagectx_id) {
  }
};

struct UnknownAction {
  static const ActionType ACTION_TYPE = static_cast<ActionType>(-1);

  void encode(bufferlist &bl) const;
  void decode(__u8 version, bufferlist::const_iterator &it);
  void dump(Formatter *f) const;
};

typedef boost::variant<StartThreadAction,
                       StopThreadAction,
                       ReadAction,
                       WriteAction,
                       DiscardAction,
                       AioReadAction,
                       AioWriteAction,
                       AioDiscardAction,
                       OpenImageAction,
                       CloseImageAction,
                       AioOpenImageAction,
                       AioCloseImageAction,
                       UnknownAction> Action;

class ActionEntry {
public:
  Action action;

  ActionEntry() : action(UnknownAction()) {
  }
  ActionEntry(const Action &action) : action(action) {
  }

  void encode(bufferlist &bl) const;
  void decode(bufferlist::const_iterator &it);
  void decode_unversioned(bufferlist::const_iterator &it);
  void dump(Formatter *f) const;

  static void generate_test_instances(std::list<ActionEntry *> &o);

private:
  void decode_versioned(__u8 version, bufferlist::const_iterator &it);
};

WRITE_CLASS_ENCODER(ActionEntry);

std::ostream &operator<<(std::ostream &out,
                         const rbd_replay::action::ActionType &type);

} // namespace action
} // namespace rbd_replay

#endif // CEPH_RBD_REPLAY_ACTION_TYPES_H