summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bailey <Jonathan.bailey1@ibm.com>2025-01-14 14:14:52 +0100
committerGitHub <noreply@github.com>2025-01-14 14:14:52 +0100
commit3fa2f0e9616b24dc8b5c61aaefdb99cded10fb56 (patch)
tree3ed795d900eb293a2d7edda5e414f9712e5c2d2a
parentMerge pull request #61352 from zdover23/wip-doc-2025-01-14-releases-quincy-eol (diff)
parentcommon/io_exerciser: Reorder lines in RadosIo send_command functions (diff)
downloadceph-3fa2f0e9616b24dc8b5c61aaefdb99cded10fb56.tar.xz
ceph-3fa2f0e9616b24dc8b5c61aaefdb99cded10fb56.zip
Merge pull request #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 <rfriedma@redhat.com>
-rw-r--r--src/common/io_exerciser/RadosIo.cc96
1 files changed, 60 insertions, 36 deletions
diff --git a/src/common/io_exerciser/RadosIo.cc b/src/common/io_exerciser/RadosIo.cc
index 4451900b7bb..a78c074228b 100644
--- a/src/common/io_exerciser/RadosIo.cc
+++ b/src/common/io_exerciser/RadosIo.cc
@@ -11,6 +11,32 @@
using RadosIo = ceph::io_exerciser::RadosIo;
+namespace {
+template <typename S>
+int send_osd_command(int osd, S& s, librados::Rados& rados, const char* name,
+ ceph::buffer::list& inbl, ceph::buffer::list* outbl,
+ Formatter* f) {
+ encode_json(name, s, f);
+
+ std::ostringstream oss;
+ f->flush(oss);
+ int rc = rados.osd_command(osd, oss.str(), inbl, outbl, nullptr);
+ return rc;
+}
+
+template <typename S>
+int send_mon_command(S& s, librados::Rados& rados, const char* name,
+ ceph::buffer::list& inbl, ceph::buffer::list* outbl,
+ Formatter* f) {
+ encode_json(name, s, f);
+
+ std::ostringstream oss;
+ f->flush(oss);
+ int rc = rados.mon_command(oss.str(), inbl, outbl, nullptr);
+ return rc;
+}
+} // namespace
+
RadosIo::RadosIo(librados::Rados& rados, boost::asio::io_context& asio,
const std::string& pool, const std::string& oid,
const std::optional<std::vector<int>>& cached_shard_order,
@@ -293,15 +319,13 @@ void RadosIo::applyReadWriteOp(IoOp& op) {
void RadosIo::applyInjectOp(IoOp& op) {
bufferlist osdmap_inbl, inject_inbl, osdmap_outbl, inject_outbl;
auto formatter = std::make_unique<JSONFormatter>(false);
- std::ostringstream oss;
int osd = -1;
std::vector<int> shard_order;
ceph::messaging::osd::OSDMapRequest osdMapRequest{pool, get_oid(), ""};
- encode_json("OSDMapRequest", osdMapRequest, formatter.get());
- formatter->flush(oss);
- int rc = rados.mon_command(oss.str(), osdmap_inbl, &osdmap_outbl, nullptr);
+ int rc = send_mon_command(osdMapRequest, rados, "OSDMapRequest", osdmap_inbl,
+ &osdmap_outbl, formatter.get());
ceph_assert(rc == 0);
JSONParser p;
@@ -322,22 +346,22 @@ void RadosIo::applyInjectOp(IoOp& op) {
ceph::messaging::osd::InjectECErrorRequest<InjectOpType::ReadEIO>
injectErrorRequest{pool, oid, errorOp.shard,
errorOp.type, errorOp.when, errorOp.duration};
- encode_json("InjectECErrorRequest", injectErrorRequest,
- formatter.get());
+ int rc = send_osd_command(osd, injectErrorRequest, rados,
+ "InjectECErrorRequest", inject_inbl,
+ &inject_outbl, formatter.get());
+ ceph_assert(rc == 0);
} else if (errorOp.type == 1) {
ceph::messaging::osd::InjectECErrorRequest<
InjectOpType::ReadMissingShard>
injectErrorRequest{pool, oid, errorOp.shard,
errorOp.type, errorOp.when, errorOp.duration};
- encode_json("InjectECErrorRequest", injectErrorRequest,
- formatter.get());
+ int rc = send_osd_command(osd, injectErrorRequest, rados,
+ "InjectECErrorRequest", inject_inbl,
+ &inject_outbl, formatter.get());
+ ceph_assert(rc == 0);
} else {
ceph_abort_msg("Unsupported inject type");
}
- formatter->flush(oss);
- int rc = rados.osd_command(osd, oss.str(), inject_inbl, &inject_outbl,
- nullptr);
- ceph_assert(rc == 0);
break;
}
case OpType::InjectWriteError: {
@@ -348,14 +372,18 @@ void RadosIo::applyInjectOp(IoOp& op) {
InjectOpType::WriteFailAndRollback>
injectErrorRequest{pool, oid, errorOp.shard,
errorOp.type, errorOp.when, errorOp.duration};
- encode_json("InjectECErrorRequest", injectErrorRequest,
- formatter.get());
+ int rc = send_osd_command(osd, injectErrorRequest, rados,
+ "InjectECErrorRequest", inject_inbl,
+ &inject_outbl, formatter.get());
+ ceph_assert(rc == 0);
} else if (errorOp.type == 3) {
ceph::messaging::osd::InjectECErrorRequest<InjectOpType::WriteOSDAbort>
injectErrorRequest{pool, oid, errorOp.shard,
errorOp.type, errorOp.when, errorOp.duration};
- encode_json("InjectECErrorRequest", injectErrorRequest,
- formatter.get());
+ int rc = send_osd_command(osd, injectErrorRequest, rados,
+ "InjectECErrorRequest", inject_inbl,
+ &inject_outbl, formatter.get());
+ ceph_assert(rc == 0);
// This inject is sent directly to the shard we want to inject the error
// on
@@ -364,10 +392,6 @@ void RadosIo::applyInjectOp(IoOp& op) {
ceph_abort("Unsupported inject type");
}
- formatter->flush(oss);
- int rc = rados.osd_command(osd, oss.str(), inject_inbl, &inject_outbl,
- nullptr);
- ceph_assert(rc == 0);
break;
}
case OpType::ClearReadErrorInject: {
@@ -377,22 +401,22 @@ void RadosIo::applyInjectOp(IoOp& op) {
if (errorOp.type == 0) {
ceph::messaging::osd::InjectECClearErrorRequest<InjectOpType::ReadEIO>
clearErrorInject{pool, oid, errorOp.shard, errorOp.type};
- encode_json("InjectECClearErrorRequest", clearErrorInject,
- formatter.get());
+ int rc = send_osd_command(osd, clearErrorInject, rados,
+ "InjectECClearErrorRequest", inject_inbl,
+ &inject_outbl, formatter.get());
+ ceph_assert(rc == 0);
} else if (errorOp.type == 1) {
ceph::messaging::osd::InjectECClearErrorRequest<
InjectOpType::ReadMissingShard>
clearErrorInject{pool, oid, errorOp.shard, errorOp.type};
- encode_json("InjectECClearErrorRequest", clearErrorInject,
- formatter.get());
+ int rc = send_osd_command(osd, clearErrorInject, rados,
+ "InjectECClearErrorRequest", inject_inbl,
+ &inject_outbl, formatter.get());
+ ceph_assert(rc == 0);
} else {
ceph_abort("Unsupported inject type");
}
- formatter->flush(oss);
- int rc = rados.osd_command(osd, oss.str(), inject_inbl, &inject_outbl,
- nullptr);
- ceph_assert(rc == 0);
break;
}
case OpType::ClearWriteErrorInject: {
@@ -403,22 +427,22 @@ void RadosIo::applyInjectOp(IoOp& op) {
ceph::messaging::osd::InjectECClearErrorRequest<
InjectOpType::WriteFailAndRollback>
clearErrorInject{pool, oid, errorOp.shard, errorOp.type};
- encode_json("InjectECClearErrorRequest", clearErrorInject,
- formatter.get());
+ int rc = send_osd_command(osd, clearErrorInject, rados,
+ "InjectECClearErrorRequest", inject_inbl,
+ &inject_outbl, formatter.get());
+ ceph_assert(rc == 0);
} else if (errorOp.type == 3) {
ceph::messaging::osd::InjectECClearErrorRequest<
InjectOpType::WriteOSDAbort>
clearErrorInject{pool, oid, errorOp.shard, errorOp.type};
- encode_json("InjectECClearErrorRequest", clearErrorInject,
- formatter.get());
+ int rc = send_osd_command(osd, clearErrorInject, rados,
+ "InjectECClearErrorRequest", inject_inbl,
+ &inject_outbl, formatter.get());
+ ceph_assert(rc == 0);
} else {
ceph_abort("Unsupported inject type");
}
- formatter->flush(oss);
- int rc = rados.osd_command(osd, oss.str(), inject_inbl, &inject_outbl,
- nullptr);
- ceph_assert(rc == 0);
break;
}
default: