Skip to content

Commit 3fa2f0e

Browse files
Merge pull request ceph#61322 from JonBailey1993/JonBailey1993/ceph_test_rados_io_sequence_ostringstream_fix
common/io_exerciser: Ensure empty stringstream in ceph_test_rados_io_sequence RadosIO between ReST calls Reviewed-by: Ronen Friedman <[email protected]>
2 parents a0f2a3b + 1694b8a commit 3fa2f0e

File tree

1 file changed

+60
-36
lines changed

1 file changed

+60
-36
lines changed

src/common/io_exerciser/RadosIo.cc

Lines changed: 60 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,32 @@
1111

1212
using RadosIo = ceph::io_exerciser::RadosIo;
1313

14+
namespace {
15+
template <typename S>
16+
int send_osd_command(int osd, S& s, librados::Rados& rados, const char* name,
17+
ceph::buffer::list& inbl, ceph::buffer::list* outbl,
18+
Formatter* f) {
19+
encode_json(name, s, f);
20+
21+
std::ostringstream oss;
22+
f->flush(oss);
23+
int rc = rados.osd_command(osd, oss.str(), inbl, outbl, nullptr);
24+
return rc;
25+
}
26+
27+
template <typename S>
28+
int send_mon_command(S& s, librados::Rados& rados, const char* name,
29+
ceph::buffer::list& inbl, ceph::buffer::list* outbl,
30+
Formatter* f) {
31+
encode_json(name, s, f);
32+
33+
std::ostringstream oss;
34+
f->flush(oss);
35+
int rc = rados.mon_command(oss.str(), inbl, outbl, nullptr);
36+
return rc;
37+
}
38+
} // namespace
39+
1440
RadosIo::RadosIo(librados::Rados& rados, boost::asio::io_context& asio,
1541
const std::string& pool, const std::string& oid,
1642
const std::optional<std::vector<int>>& cached_shard_order,
@@ -293,15 +319,13 @@ void RadosIo::applyReadWriteOp(IoOp& op) {
293319
void RadosIo::applyInjectOp(IoOp& op) {
294320
bufferlist osdmap_inbl, inject_inbl, osdmap_outbl, inject_outbl;
295321
auto formatter = std::make_unique<JSONFormatter>(false);
296-
std::ostringstream oss;
297322

298323
int osd = -1;
299324
std::vector<int> shard_order;
300325

301326
ceph::messaging::osd::OSDMapRequest osdMapRequest{pool, get_oid(), ""};
302-
encode_json("OSDMapRequest", osdMapRequest, formatter.get());
303-
formatter->flush(oss);
304-
int rc = rados.mon_command(oss.str(), osdmap_inbl, &osdmap_outbl, nullptr);
327+
int rc = send_mon_command(osdMapRequest, rados, "OSDMapRequest", osdmap_inbl,
328+
&osdmap_outbl, formatter.get());
305329
ceph_assert(rc == 0);
306330

307331
JSONParser p;
@@ -322,22 +346,22 @@ void RadosIo::applyInjectOp(IoOp& op) {
322346
ceph::messaging::osd::InjectECErrorRequest<InjectOpType::ReadEIO>
323347
injectErrorRequest{pool, oid, errorOp.shard,
324348
errorOp.type, errorOp.when, errorOp.duration};
325-
encode_json("InjectECErrorRequest", injectErrorRequest,
326-
formatter.get());
349+
int rc = send_osd_command(osd, injectErrorRequest, rados,
350+
"InjectECErrorRequest", inject_inbl,
351+
&inject_outbl, formatter.get());
352+
ceph_assert(rc == 0);
327353
} else if (errorOp.type == 1) {
328354
ceph::messaging::osd::InjectECErrorRequest<
329355
InjectOpType::ReadMissingShard>
330356
injectErrorRequest{pool, oid, errorOp.shard,
331357
errorOp.type, errorOp.when, errorOp.duration};
332-
encode_json("InjectECErrorRequest", injectErrorRequest,
333-
formatter.get());
358+
int rc = send_osd_command(osd, injectErrorRequest, rados,
359+
"InjectECErrorRequest", inject_inbl,
360+
&inject_outbl, formatter.get());
361+
ceph_assert(rc == 0);
334362
} else {
335363
ceph_abort_msg("Unsupported inject type");
336364
}
337-
formatter->flush(oss);
338-
int rc = rados.osd_command(osd, oss.str(), inject_inbl, &inject_outbl,
339-
nullptr);
340-
ceph_assert(rc == 0);
341365
break;
342366
}
343367
case OpType::InjectWriteError: {
@@ -348,14 +372,18 @@ void RadosIo::applyInjectOp(IoOp& op) {
348372
InjectOpType::WriteFailAndRollback>
349373
injectErrorRequest{pool, oid, errorOp.shard,
350374
errorOp.type, errorOp.when, errorOp.duration};
351-
encode_json("InjectECErrorRequest", injectErrorRequest,
352-
formatter.get());
375+
int rc = send_osd_command(osd, injectErrorRequest, rados,
376+
"InjectECErrorRequest", inject_inbl,
377+
&inject_outbl, formatter.get());
378+
ceph_assert(rc == 0);
353379
} else if (errorOp.type == 3) {
354380
ceph::messaging::osd::InjectECErrorRequest<InjectOpType::WriteOSDAbort>
355381
injectErrorRequest{pool, oid, errorOp.shard,
356382
errorOp.type, errorOp.when, errorOp.duration};
357-
encode_json("InjectECErrorRequest", injectErrorRequest,
358-
formatter.get());
383+
int rc = send_osd_command(osd, injectErrorRequest, rados,
384+
"InjectECErrorRequest", inject_inbl,
385+
&inject_outbl, formatter.get());
386+
ceph_assert(rc == 0);
359387

360388
// This inject is sent directly to the shard we want to inject the error
361389
// on
@@ -364,10 +392,6 @@ void RadosIo::applyInjectOp(IoOp& op) {
364392
ceph_abort("Unsupported inject type");
365393
}
366394

367-
formatter->flush(oss);
368-
int rc = rados.osd_command(osd, oss.str(), inject_inbl, &inject_outbl,
369-
nullptr);
370-
ceph_assert(rc == 0);
371395
break;
372396
}
373397
case OpType::ClearReadErrorInject: {
@@ -377,22 +401,22 @@ void RadosIo::applyInjectOp(IoOp& op) {
377401
if (errorOp.type == 0) {
378402
ceph::messaging::osd::InjectECClearErrorRequest<InjectOpType::ReadEIO>
379403
clearErrorInject{pool, oid, errorOp.shard, errorOp.type};
380-
encode_json("InjectECClearErrorRequest", clearErrorInject,
381-
formatter.get());
404+
int rc = send_osd_command(osd, clearErrorInject, rados,
405+
"InjectECClearErrorRequest", inject_inbl,
406+
&inject_outbl, formatter.get());
407+
ceph_assert(rc == 0);
382408
} else if (errorOp.type == 1) {
383409
ceph::messaging::osd::InjectECClearErrorRequest<
384410
InjectOpType::ReadMissingShard>
385411
clearErrorInject{pool, oid, errorOp.shard, errorOp.type};
386-
encode_json("InjectECClearErrorRequest", clearErrorInject,
387-
formatter.get());
412+
int rc = send_osd_command(osd, clearErrorInject, rados,
413+
"InjectECClearErrorRequest", inject_inbl,
414+
&inject_outbl, formatter.get());
415+
ceph_assert(rc == 0);
388416
} else {
389417
ceph_abort("Unsupported inject type");
390418
}
391419

392-
formatter->flush(oss);
393-
int rc = rados.osd_command(osd, oss.str(), inject_inbl, &inject_outbl,
394-
nullptr);
395-
ceph_assert(rc == 0);
396420
break;
397421
}
398422
case OpType::ClearWriteErrorInject: {
@@ -403,22 +427,22 @@ void RadosIo::applyInjectOp(IoOp& op) {
403427
ceph::messaging::osd::InjectECClearErrorRequest<
404428
InjectOpType::WriteFailAndRollback>
405429
clearErrorInject{pool, oid, errorOp.shard, errorOp.type};
406-
encode_json("InjectECClearErrorRequest", clearErrorInject,
407-
formatter.get());
430+
int rc = send_osd_command(osd, clearErrorInject, rados,
431+
"InjectECClearErrorRequest", inject_inbl,
432+
&inject_outbl, formatter.get());
433+
ceph_assert(rc == 0);
408434
} else if (errorOp.type == 3) {
409435
ceph::messaging::osd::InjectECClearErrorRequest<
410436
InjectOpType::WriteOSDAbort>
411437
clearErrorInject{pool, oid, errorOp.shard, errorOp.type};
412-
encode_json("InjectECClearErrorRequest", clearErrorInject,
413-
formatter.get());
438+
int rc = send_osd_command(osd, clearErrorInject, rados,
439+
"InjectECClearErrorRequest", inject_inbl,
440+
&inject_outbl, formatter.get());
441+
ceph_assert(rc == 0);
414442
} else {
415443
ceph_abort("Unsupported inject type");
416444
}
417445

418-
formatter->flush(oss);
419-
int rc = rados.osd_command(osd, oss.str(), inject_inbl, &inject_outbl,
420-
nullptr);
421-
ceph_assert(rc == 0);
422446
break;
423447
}
424448
default:

0 commit comments

Comments
 (0)