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
|
#include "RadosIo.h"
#include "DataGenerator.h"
using RadosIo = ceph::io_exerciser::RadosIo;
RadosIo::RadosIo(librados::Rados& rados,
boost::asio::io_context& asio,
const std::string& pool,
const std::string& oid,
uint64_t block_size,
int seed,
int threads,
ceph::mutex& lock,
ceph::condition_variable& cond) :
Model(oid, block_size),
rados(rados),
asio(asio),
om(std::make_unique<ObjectModel>(oid, block_size, seed)),
db(data_generation::DataGenerator::create_generator(
data_generation::GenerationType::HeaderedSeededRandom, *om)),
pool(pool),
threads(threads),
lock(lock),
cond(cond),
outstanding_io(0)
{
int rc;
rc = rados.ioctx_create(pool.c_str(), io);
ceph_assert(rc == 0);
allow_ec_overwrites(true);
}
RadosIo::~RadosIo()
{
}
void RadosIo::start_io()
{
std::lock_guard l(lock);
outstanding_io++;
}
void RadosIo::finish_io()
{
std::lock_guard l(lock);
ceph_assert(outstanding_io > 0);
outstanding_io--;
cond.notify_all();
}
void RadosIo::wait_for_io(int count)
{
std::unique_lock l(lock);
while (outstanding_io > count) {
cond.wait(l);
}
}
void RadosIo::allow_ec_overwrites(bool allow)
{
int rc;
bufferlist inbl, outbl;
std::string cmdstr =
"{\"prefix\": \"osd pool set\", \"pool\": \"" + pool + "\", \
\"var\": \"allow_ec_overwrites\", \"val\": \"" +
(allow ? "true" : "false") + "\"}";
rc = rados.mon_command(cmdstr, inbl, &outbl, nullptr);
ceph_assert(rc == 0);
}
RadosIo::AsyncOpInfo::AsyncOpInfo(uint64_t offset1, uint64_t length1,
uint64_t offset2, uint64_t length2,
uint64_t offset3, uint64_t length3 ) :
offset1(offset1), length1(length1),
offset2(offset2), length2(length2),
offset3(offset3), length3(length3)
{
}
bool RadosIo::readyForIoOp(IoOp &op)
{
ceph_assert(ceph_mutex_is_locked_by_me(lock)); //Must be called with lock held
if (!om->readyForIoOp(op)) {
return false;
}
switch (op.op) {
case OpType::Done:
case OpType::BARRIER:
return outstanding_io == 0;
default:
return outstanding_io < threads;
}
}
void RadosIo::applyIoOp(IoOp &op)
{
std::shared_ptr<AsyncOpInfo> op_info;
om->applyIoOp(op);
// If there are thread concurrent I/Os in flight then wait for
// at least one I/O to complete
wait_for_io(threads-1);
switch (op.op) {
case OpType::Done:
[[ fallthrough ]];
case OpType::BARRIER:
// Wait for all outstanding I/O to complete
wait_for_io(0);
break;
case OpType::CREATE:
{
start_io();
op_info = std::make_shared<AsyncOpInfo>(0, op.length1);
op_info->bl1 = db->generate_data(0, op.length1);
op_info->wop.write_full(op_info->bl1);
auto create_cb = [this] (boost::system::error_code ec,
version_t ver) {
ceph_assert(ec == boost::system::errc::success);
finish_io();
};
librados::async_operate(asio, io, oid,
&op_info->wop, 0, nullptr, create_cb);
}
break;
case OpType::REMOVE:
{
start_io();
op_info = std::make_shared<AsyncOpInfo>();
op_info->wop.remove();
auto remove_cb = [this] (boost::system::error_code ec,
version_t ver) {
ceph_assert(ec == boost::system::errc::success);
finish_io();
};
librados::async_operate(asio, io, oid,
&op_info->wop, 0, nullptr, remove_cb);
}
break;
case OpType::READ:
{
start_io();
op_info = std::make_shared<AsyncOpInfo>(op.offset1, op.length1);
op_info->rop.read(op.offset1 * block_size,
op.length1 * block_size,
&op_info->bl1, nullptr);
auto read_cb = [this, op_info] (boost::system::error_code ec,
version_t ver,
bufferlist bl) {
ceph_assert(ec == boost::system::errc::success);
db->validate(op_info->bl1, op_info->offset1, op_info->length1);
finish_io();
};
librados::async_operate(asio, io, oid,
&op_info->rop, 0, nullptr, read_cb);
num_io++;
}
break;
case OpType::READ2:
{
start_io();
op_info = std::make_shared<AsyncOpInfo>(op.offset1,
op.length1,
op.offset2,
op.length2);
op_info->rop.read(op.offset1 * block_size,
op.length1 * block_size,
&op_info->bl1, nullptr);
op_info->rop.read(op.offset2 * block_size,
op.length2 * block_size,
&op_info->bl2, nullptr);
auto read2_cb = [this, op_info] (boost::system::error_code ec,
version_t ver,
bufferlist bl) {
ceph_assert(ec == boost::system::errc::success);
db->validate(op_info->bl1, op_info->offset1, op_info->length1);
db->validate(op_info->bl2, op_info->offset2, op_info->length2);
finish_io();
};
librados::async_operate(asio, io, oid,
&op_info->rop, 0, nullptr, read2_cb);
num_io++;
}
break;
case OpType::READ3:
{
start_io();
op_info = std::make_shared<AsyncOpInfo>(op.offset1, op.length1,
op.offset2, op.length2,
op.offset3, op.length3);
op_info->rop.read(op.offset1 * block_size,
op.length1 * block_size,
&op_info->bl1, nullptr);
op_info->rop.read(op.offset2 * block_size,
op.length2 * block_size,
&op_info->bl2, nullptr);
op_info->rop.read(op.offset3 * block_size,
op.length3 * block_size,
&op_info->bl3, nullptr);
auto read3_cb = [this, op_info] (boost::system::error_code ec,
version_t ver,
bufferlist bl) {
ceph_assert(ec == boost::system::errc::success);
db->validate(op_info->bl1, op_info->offset1, op_info->length1);
db->validate(op_info->bl2, op_info->offset2, op_info->length2);
db->validate(op_info->bl3, op_info->offset3, op_info->length3);
finish_io();
};
librados::async_operate(asio, io, oid,
&op_info->rop, 0, nullptr, read3_cb);
num_io++;
}
break;
case OpType::WRITE:
{
start_io();
op_info = std::make_shared<AsyncOpInfo>(op.offset1, op.length1);
op_info->bl1 = db->generate_data(op.offset1, op.length1);
op_info->wop.write(op.offset1 * block_size, op_info->bl1);
auto write_cb = [this] (boost::system::error_code ec,
version_t ver) {
ceph_assert(ec == boost::system::errc::success);
finish_io();
};
librados::async_operate(asio, io, oid,
&op_info->wop, 0, nullptr, write_cb);
num_io++;
}
break;
case OpType::WRITE2:
{
start_io();
op_info = std::make_shared<AsyncOpInfo>(op.offset1, op.length1,
op.offset2, op.length2);
op_info->bl1 = db->generate_data(op.offset1, op.length1);
op_info->bl2 = db->generate_data(op.offset2, op.length2);
op_info->wop.write(op.offset1 * block_size, op_info->bl1);
op_info->wop.write(op.offset2 * block_size, op_info->bl2);
auto write2_cb = [this] (boost::system::error_code ec,
version_t ver) {
ceph_assert(ec == boost::system::errc::success);
finish_io();
};
librados::async_operate(asio, io, oid,
&op_info->wop, 0, nullptr, write2_cb);
num_io++;
}
break;
case OpType::WRITE3:
{
start_io();
op_info = std::make_shared<AsyncOpInfo>(op.offset1, op.length1,
op.offset2, op.length2,
op.offset3, op.length3);
op_info->bl1 = db->generate_data(op.offset1, op.length1);
op_info->bl2 = db->generate_data(op.offset2, op.length2);
op_info->bl3 = db->generate_data(op.offset3, op.length3);
op_info->wop.write(op.offset1 * block_size, op_info->bl1);
op_info->wop.write(op.offset2 * block_size, op_info->bl2);
op_info->wop.write(op.offset3 * block_size, op_info->bl3);
auto write3_cb = [this] (boost::system::error_code ec,
version_t ver) {
ceph_assert(ec == boost::system::errc::success);
finish_io();
};
librados::async_operate(asio, io, oid,
&op_info->wop, 0, nullptr, write3_cb);
num_io++;
}
break;
default:
break;
}
}
|