-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.hpp
358 lines (264 loc) · 8.16 KB
/
actions.hpp
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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab
/*
* Ceph - scalable distributed file system
*
* Copyright (C) 2014 Adam Crume <[email protected]>
*
* This is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License version 2.1, as published by the Free Software
* Foundation. See file COPYING.
*
*/
#ifndef _INCLUDED_RBD_REPLAY_ACTIONS_HPP
#define _INCLUDED_RBD_REPLAY_ACTIONS_HPP
#include <boost/shared_ptr.hpp>
#include "include/rbd/librbd.hpp"
#include "Deser.hpp"
#include "rbd_loc.hpp"
// Stupid Doxygen requires this or else the typedef docs don't appear anywhere.
/// @file rbd_replay/actions.hpp
namespace rbd_replay {
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;
/**
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_d {
/// 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_d(action_id_t id,
uint64_t time_delta)
: id(id),
time_delta(time_delta) {
}
};
// These are written to files, so don't change existing assignments.
enum io_type {
IO_START_THREAD,
IO_STOP_THREAD,
IO_READ,
IO_WRITE,
IO_ASYNC_READ,
IO_ASYNC_WRITE,
IO_OPEN_IMAGE,
IO_CLOSE_IMAGE,
};
class PendingIO;
/**
%Context through which an Action interacts with its environment.
*/
class ActionCtx {
public:
virtual ~ActionCtx() {
}
/**
Returns the image with the given ID.
The image must have been previously tracked with put_image(imagectx_id_t,librbd::Image*).
*/
virtual librbd::Image* get_image(imagectx_id_t imagectx_id) = 0;
/**
Tracks an image.
put_image(imagectx_id_t,librbd::Image*) must not have been called previously with the same ID,
and the image must not be NULL.
*/
virtual void put_image(imagectx_id_t imagectx_id, librbd::Image* image) = 0;
/**
Stops tracking an Image and release it.
This deletes the C++ object, not the image itself.
The image must have been previously tracked with put_image(imagectx_id_t,librbd::Image*).
*/
virtual void erase_image(imagectx_id_t imagectx_id) = 0;
virtual librbd::RBD* rbd() = 0;
virtual librados::IoCtx* ioctx() = 0;
virtual void add_pending(boost::shared_ptr<PendingIO> io) = 0;
virtual bool readonly() const = 0;
virtual void remove_pending(boost::shared_ptr<PendingIO> io) = 0;
virtual void set_action_complete(action_id_t id) = 0;
virtual void stop() = 0;
/**
Maps an image name from the name in the original trace to the name that should be used when replaying.
@param image_name name of the image in the original trace
@param snap_name name of the snap in the orginal trace
@return image name to replay against
*/
virtual rbd_loc map_image_name(std::string image_name, std::string snap_name) const = 0;
};
/**
Performs an %IO or a maintenance action such as starting or stopping a thread.
Actions are read from a replay file and scheduled by Replayer.
Corresponds to the IO class, except that Actions are executed by rbd-replay,
and IOs are used by rbd-replay-prep for processing the raw trace.
*/
class Action {
public:
typedef boost::shared_ptr<Action> ptr;
Action(action_id_t id,
thread_id_t thread_id,
int num_successors,
int num_completion_successors,
std::vector<dependency_d> &predecessors);
virtual ~Action();
virtual void perform(ActionCtx &ctx) = 0;
/// Returns the ID of the completion corresponding to this action.
action_id_t pending_io_id() {
return m_id + 1;
}
// There's probably a better way to do this, but oh well.
virtual bool is_start_thread() {
return false;
}
action_id_t id() const {
return m_id;
}
thread_id_t thread_id() const {
return m_thread_id;
}
const std::vector<dependency_d>& predecessors() const {
return m_predecessors;
}
/// Reads and constructs an action from the replay file.
static ptr read_from(Deser &d);
protected:
std::ostream& dump_action_fields(std::ostream& o) const;
private:
friend std::ostream& operator<<(std::ostream&, const Action&);
virtual std::ostream& dump(std::ostream& o) const = 0;
const action_id_t m_id;
const thread_id_t m_thread_id;
const int m_num_successors;
const int m_num_completion_successors;
const std::vector<dependency_d> m_predecessors;
};
/// Writes human-readable debug information about the action to the stream.
/// @related Action
std::ostream& operator<<(std::ostream& o, const Action& a);
/**
Placeholder for partially-constructed actions.
Does nothing, and does not appear in the replay file.
*/
class DummyAction : public Action {
public:
DummyAction(action_id_t id,
thread_id_t thread_id,
int num_successors,
int num_completion_successors,
std::vector<dependency_d> &predecessors)
: Action(id, thread_id, num_successors, num_completion_successors, predecessors) {
}
void perform(ActionCtx &ctx) {
}
private:
std::ostream& dump(std::ostream& o) const;
};
class StopThreadAction : public Action {
public:
explicit StopThreadAction(Action &src);
void perform(ActionCtx &ctx);
static Action::ptr read_from(Action &src, Deser &d);
private:
std::ostream& dump(std::ostream& o) const;
};
class AioReadAction : public Action {
public:
AioReadAction(const Action &src,
imagectx_id_t imagectx_id,
uint64_t offset,
uint64_t length);
void perform(ActionCtx &ctx);
static Action::ptr read_from(Action &src, Deser &d);
private:
std::ostream& dump(std::ostream& o) const;
imagectx_id_t m_imagectx_id;
uint64_t m_offset;
uint64_t m_length;
};
class ReadAction : public Action {
public:
ReadAction(const Action &src,
imagectx_id_t imagectx_id,
uint64_t offset,
uint64_t length);
void perform(ActionCtx &ctx);
static Action::ptr read_from(Action &src, Deser &d);
private:
std::ostream& dump(std::ostream& o) const;
imagectx_id_t m_imagectx_id;
uint64_t m_offset;
uint64_t m_length;
};
class AioWriteAction : public Action {
public:
AioWriteAction(const Action &src,
imagectx_id_t imagectx_id,
uint64_t offset,
uint64_t length);
void perform(ActionCtx &ctx);
static Action::ptr read_from(Action &src, Deser &d);
private:
std::ostream& dump(std::ostream& o) const;
imagectx_id_t m_imagectx_id;
uint64_t m_offset;
uint64_t m_length;
};
class WriteAction : public Action {
public:
WriteAction(const Action &src,
imagectx_id_t imagectx_id,
uint64_t offset,
uint64_t length);
void perform(ActionCtx &ctx);
static Action::ptr read_from(Action &src, Deser &d);
private:
std::ostream& dump(std::ostream& o) const;
imagectx_id_t m_imagectx_id;
uint64_t m_offset;
uint64_t m_length;
};
class OpenImageAction : public Action {
public:
OpenImageAction(Action &src,
imagectx_id_t imagectx_id,
std::string name,
std::string snap_name,
bool readonly);
void perform(ActionCtx &ctx);
static Action::ptr read_from(Action &src, Deser &d);
private:
std::ostream& dump(std::ostream& o) const;
imagectx_id_t m_imagectx_id;
std::string m_name;
std::string m_snap_name;
bool m_readonly;
};
class CloseImageAction : public Action {
public:
CloseImageAction(Action &src,
imagectx_id_t imagectx_id);
void perform(ActionCtx &ctx);
static Action::ptr read_from(Action &src, Deser &d);
private:
std::ostream& dump(std::ostream& o) const;
imagectx_id_t m_imagectx_id;
};
class StartThreadAction : public Action {
public:
explicit StartThreadAction(Action &src);
void perform(ActionCtx &ctx);
bool is_start_thread();
static Action::ptr read_from(Action &src, Deser &d);
private:
std::ostream& dump(std::ostream& o) const;
};
}
#endif