-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathios.hpp
371 lines (299 loc) · 8.27 KB
/
ios.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
359
360
361
362
363
364
365
366
367
368
369
370
371
// -*- 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_IOS_HPP
#define _INCLUDED_RBD_REPLAY_IOS_HPP
// This code assumes that IO IDs and timestamps are related monotonically.
// In other words, (a.id < b.id) == (a.timestamp < b.timestamp) for all IOs a and b.
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>
#include <iostream>
#include <map>
#include <set>
#include "actions.hpp"
#include "Ser.hpp"
namespace rbd_replay {
class IO;
typedef std::set<boost::shared_ptr<IO> > io_set_t;
typedef std::map<action_id_t, boost::shared_ptr<IO> > io_map_t;
/**
Calculates reachability of IOs in the dependency graph.
All IOs in \c deps which are not transitive dependencies of anything in \c base
is added to \c unreachable.
In other words, for every IO \c x in \c deps: if nothing in \c base depends on \c x,
and nothing in \c base has dependencies that depend on \c x, etc.,
then \c x is added to \c unreachable.
Note that \c unreachable is \em not cleared, so the same set can be used across multiple
calls to collect dependencies.
@param[in] deps IOs to search for
@param[in] base root set of IOs to search from
@param[out] unreachable collects unreachable IOs
@related IO
*/
void batch_unreachable_from(const io_set_t& deps, const io_set_t& base, io_set_t* unreachable);
/**
Used by rbd-replay-prep for processing the raw trace.
Corresponds to the Action class, except that Actions are executed by rbd-replay,
and IOs are used by rbd-replay-prep for processing the raw trace.
*/
class IO : public boost::enable_shared_from_this<IO> {
public:
typedef boost::shared_ptr<IO> ptr;
typedef boost::weak_ptr<IO> weak_ptr;
/**
@param ionum ID of this %IO
@param start_time time the %IO started, in nanoseconds
@param thread_id ID of the thread that issued the %IO
@param prev previously issued %IO on the same thread. NULL for the first %IO on a thread.
*/
IO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id,
ptr prev)
: m_ionum(ionum),
m_start_time(start_time),
m_dependencies(io_set_t()),
m_completion(weak_ptr()),
m_num_successors(0),
m_thread_id(thread_id),
m_prev(prev) {
}
virtual ~IO() {
}
uint64_t start_time() const {
return m_start_time;
}
io_set_t& dependencies() {
return m_dependencies;
}
const io_set_t& dependencies() const {
return m_dependencies;
}
void add_dependencies(const io_set_t& deps);
/**
Returns the completion's number of successors, or 0 if the %IO does not have a completion.
*/
uint64_t num_completion_successors() const {
ptr c(m_completion.lock());
return c ? c->m_num_successors : 0;
}
virtual void write_to(Ser& out) const = 0;
virtual bool is_completion() const {
return false;
}
void set_ionum(action_id_t ionum) {
m_ionum = ionum;
}
action_id_t ionum() const {
return m_ionum;
}
ptr prev() const {
return m_prev;
}
void set_num_successors(uint32_t n) {
m_num_successors = n;
}
uint32_t num_successors() const {
return m_num_successors;
}
virtual void write_debug(std::ostream& out) const = 0;
/**
Creates the completion for this IO.
This may only be called once per IO, and may not be called on completion IOs.
The completion must be stored, or else m_completion will expire.
*/
ptr create_completion(uint64_t start_time, thread_id_t thread_id);
protected:
void write_to(Ser& out, io_type iotype) const;
void write_debug_base(std::ostream& out, std::string iotype) const;
private:
action_id_t m_ionum;
uint64_t m_start_time;
io_set_t m_dependencies;
boost::weak_ptr<IO> m_completion;
uint32_t m_num_successors;
thread_id_t m_thread_id;
ptr m_prev;
};
/// Used for dumping debug info.
/// @related IO
std::ostream& operator<<(std::ostream& out, IO::ptr io);
class StartThreadIO : public IO {
public:
StartThreadIO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id)
: IO(ionum, start_time, thread_id, IO::ptr()) {
}
void write_to(Ser& out) const;
void write_debug(std::ostream& out) const;
};
class StopThreadIO : public IO {
public:
StopThreadIO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id)
: IO(ionum, start_time, thread_id, IO::ptr()) {
}
void write_to(Ser& out) const;
void write_debug(std::ostream& out) const;
};
class ReadIO : public IO {
public:
ReadIO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id,
IO::ptr prev,
imagectx_id_t imagectx,
uint64_t offset,
uint64_t length)
: IO(ionum, start_time, thread_id, prev),
m_imagectx(imagectx),
m_offset(offset),
m_length(length) {
}
void write_to(Ser& out) const;
void write_debug(std::ostream& out) const;
private:
imagectx_id_t m_imagectx;
uint64_t m_offset;
uint64_t m_length;
};
class WriteIO : public IO {
public:
WriteIO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id,
IO::ptr prev,
imagectx_id_t imagectx,
uint64_t offset,
uint64_t length)
: IO(ionum, start_time, thread_id, prev),
m_imagectx(imagectx),
m_offset(offset),
m_length(length) {
}
void write_to(Ser& out) const;
void write_debug(std::ostream& out) const;
private:
imagectx_id_t m_imagectx;
uint64_t m_offset;
uint64_t m_length;
};
class AioReadIO : public IO {
public:
AioReadIO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id,
IO::ptr prev,
imagectx_id_t imagectx,
uint64_t offset,
uint64_t length)
: IO(ionum, start_time, thread_id, prev),
m_imagectx(imagectx),
m_offset(offset),
m_length(length) {
}
void write_to(Ser& out) const;
void write_debug(std::ostream& out) const;
private:
imagectx_id_t m_imagectx;
uint64_t m_offset;
uint64_t m_length;
};
class AioWriteIO : public IO {
public:
AioWriteIO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id,
IO::ptr prev,
imagectx_id_t imagectx,
uint64_t offset,
uint64_t length)
: IO(ionum, start_time, thread_id, prev),
m_imagectx(imagectx),
m_offset(offset),
m_length(length) {
}
void write_to(Ser& out) const;
void write_debug(std::ostream& out) const;
private:
imagectx_id_t m_imagectx;
uint64_t m_offset;
uint64_t m_length;
};
class OpenImageIO : public IO {
public:
OpenImageIO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id,
IO::ptr prev,
imagectx_id_t imagectx,
const std::string& name,
const std::string& snap_name,
bool readonly)
: IO(ionum, start_time, thread_id, prev),
m_imagectx(imagectx),
m_name(name),
m_snap_name(snap_name),
m_readonly(readonly) {
}
void write_to(Ser& out) const;
imagectx_id_t imagectx() const {
return m_imagectx;
}
void write_debug(std::ostream& out) const;
private:
imagectx_id_t m_imagectx;
std::string m_name;
std::string m_snap_name;
bool m_readonly;
};
class CloseImageIO : public IO {
public:
CloseImageIO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id,
IO::ptr prev,
imagectx_id_t imagectx)
: IO(ionum, start_time, thread_id, prev),
m_imagectx(imagectx) {
}
void write_to(Ser& out) const;
imagectx_id_t imagectx() const {
return m_imagectx;
}
void write_debug(std::ostream& out) const;
private:
imagectx_id_t m_imagectx;
};
class CompletionIO : public IO {
public:
CompletionIO(action_id_t ionum,
uint64_t start_time,
thread_id_t thread_id)
: IO(ionum, start_time, thread_id, IO::ptr()) {
}
void write_to(Ser& out) const {
}
bool is_completion() const {
return true;
}
void write_debug(std::ostream& out) const {
write_debug_base(out, "completion");
}
};
/// @related IO
bool compare_io_ptrs_by_start_time(IO::ptr p1, IO::ptr p2);
}
#endif