From e8ef0f441c2f682d855767bba1dfbd58d2bf9ac2 Mon Sep 17 00:00:00 2001 From: Jon Bailey Date: Mon, 14 Jul 2025 13:52:28 +0100 Subject: [PATCH] common: Added values to json::OSDPoolGetReply OSDPoolGetReply actually returns a lot more values than what is currently supplied. These have been added in as optionals (as they can not be give as well) so its possible to query them to find out if they exist and use them if they do. Signed-off-by: Jon Bailey --- src/common/json/OSDStructures.cc | 24 +++++++++++++++++++ src/common/json/OSDStructures.h | 19 ++++++++++++--- src/erasure-code/consistency/RadosCommands.cc | 13 ++++++---- .../ceph_ec_consistency_checker.cc | 11 ++++++--- .../ceph_test_rados_io_sequence.cc | 3 ++- 5 files changed, 59 insertions(+), 11 deletions(-) diff --git a/src/common/json/OSDStructures.cc b/src/common/json/OSDStructures.cc index f374b05360d..24e3e0ce60e 100644 --- a/src/common/json/OSDStructures.cc +++ b/src/common/json/OSDStructures.cc @@ -60,12 +60,36 @@ void OSDPoolGetRequest::decode_json(JSONObj* obj) { } void OSDPoolGetReply::dump(Formatter* f) const { + encode_json("size", size, f); + encode_json("min_size", min_size, f); + encode_json("pg_num", pg_num, f); + encode_json("pgp_num", pgp_num, f); + encode_json("crush_rule", crush_rule, f); + encode_json("allow_ec_overwrites", allow_ec_overwrites, f); + encode_json("nodelete", nodelete, f); + encode_json("nopgchange", nopgchange, f); + encode_json("nosizechange", nosizechange, f); + encode_json("noscrub", noscrub, f); + encode_json("nodeep-scrub", nodeep_scrub, f); encode_json("erasure_code_profile", erasure_code_profile, f); + encode_json("fast_read", fast_read, f); encode_json("allow_ec_optimizations", allow_ec_optimizations, f); } void OSDPoolGetReply::decode_json(JSONObj* obj) { + JSONDecoder::decode_json("size", size, obj); + JSONDecoder::decode_json("min_size", min_size, obj); + JSONDecoder::decode_json("pg_num", pg_num, obj); + JSONDecoder::decode_json("pgp_num", pgp_num, obj); + JSONDecoder::decode_json("crush_rule", crush_rule, obj); + JSONDecoder::decode_json("allow_ec_overwrites", allow_ec_overwrites, obj); + JSONDecoder::decode_json("nodelete", nodelete, obj); + JSONDecoder::decode_json("nopgchange", nopgchange, obj); + JSONDecoder::decode_json("nosizechange", nosizechange, obj); + JSONDecoder::decode_json("noscrub", noscrub, obj); + JSONDecoder::decode_json("nodeep-scrub", nodeep_scrub, obj); JSONDecoder::decode_json("erasure_code_profile", erasure_code_profile, obj); + JSONDecoder::decode_json("fast_read", fast_read, obj); JSONDecoder::decode_json("allow_ec_optimizations", allow_ec_optimizations, obj); } diff --git a/src/common/json/OSDStructures.h b/src/common/json/OSDStructures.h index d4f97bd9b95..9f6d1c7e824 100644 --- a/src/common/json/OSDStructures.h +++ b/src/common/json/OSDStructures.h @@ -41,7 +41,7 @@ struct OSDMapReply { struct OSDPoolGetRequest { std::string pool; - std::string var = "erasure_code_profile"; + std::string var; std::string format = "json"; void dump(Formatter* f) const; @@ -49,8 +49,21 @@ struct OSDPoolGetRequest { }; struct OSDPoolGetReply { - std::string erasure_code_profile; - bool allow_ec_optimizations; + std::optional size; + std::optional min_size; + std::optional pg_num; + std::optional pgp_num; + std::optional crush_rule; + std::optional allow_ec_overwrites; + std::optional nodelete; + std::optional nopgchange; + std::optional nosizechange; + std::optional noscrub; + std::optional nodeep_scrub; + std::optional erasure_code_profile; + std::optional fast_read; + std::optional allow_ec_optimizations; + void dump(Formatter* f) const; void decode_json(JSONObj* obj); }; diff --git a/src/erasure-code/consistency/RadosCommands.cc b/src/erasure-code/consistency/RadosCommands.cc index 8fb97587f1f..0eaab5db75c 100644 --- a/src/erasure-code/consistency/RadosCommands.cc +++ b/src/erasure-code/consistency/RadosCommands.cc @@ -54,7 +54,7 @@ int RadosCommands::get_primary_osd(const std::string& pool_name, */ bool RadosCommands::get_pool_allow_ec_optimizations(const std::string& pool_name) { - ceph::messaging::osd::OSDPoolGetRequest osd_pool_get_request{pool_name, "allow_ec_optimizations"}; + ceph::messaging::osd::OSDPoolGetRequest osd_pool_get_request{pool_name, "all"}; encode_json("OSDPoolGetRequest", osd_pool_get_request, formatter.get()); std::ostringstream oss; @@ -71,7 +71,7 @@ bool RadosCommands::get_pool_allow_ec_optimizations(const std::string& pool_name ceph::messaging::osd::OSDPoolGetReply osd_pool_get_reply; osd_pool_get_reply.decode_json(&p); - return osd_pool_get_reply.allow_ec_optimizations; + return osd_pool_get_reply.allow_ec_optimizations.value_or(false); } /** @@ -83,7 +83,7 @@ bool RadosCommands::get_pool_allow_ec_optimizations(const std::string& pool_name */ std::string RadosCommands::get_pool_ec_profile_name(const std::string& pool_name) { - ceph::messaging::osd::OSDPoolGetRequest osd_pool_get_request{pool_name}; + ceph::messaging::osd::OSDPoolGetRequest osd_pool_get_request{pool_name, "all"}; encode_json("OSDPoolGetRequest", osd_pool_get_request, formatter.get()); std::ostringstream oss; @@ -100,7 +100,12 @@ std::string RadosCommands::get_pool_ec_profile_name(const std::string& pool_name ceph::messaging::osd::OSDPoolGetReply osd_pool_get_reply; osd_pool_get_reply.decode_json(&p); - return osd_pool_get_reply.erasure_code_profile; + if (!osd_pool_get_reply.erasure_code_profile) { + throw std::runtime_error("No profile for given pool. " + "Is it an Erasure Coded pool?"); + } + + return *osd_pool_get_reply.erasure_code_profile; } /** diff --git a/src/erasure-code/consistency/ceph_ec_consistency_checker.cc b/src/erasure-code/consistency/ceph_ec_consistency_checker.cc index 35606084b2a..4a783724c7d 100644 --- a/src/erasure-code/consistency/ceph_ec_consistency_checker.cc +++ b/src/erasure-code/consistency/ceph_ec_consistency_checker.cc @@ -71,9 +71,14 @@ int main(int argc, char **argv) guard.emplace(boost::asio::make_work_guard(asio)); thread = make_named_thread("io_thread",[&asio] { asio.run(); }); - auto checker = ceph::consistency::ConsistencyChecker(rados, asio, pool); - checker.single_read_and_check_consistency(oid, blocksize, offset, length); - checker.print_results(std::cout); + try { + auto checker = ceph::consistency::ConsistencyChecker(rados, asio, pool); + checker.single_read_and_check_consistency(oid, blocksize, offset, length); + checker.print_results(std::cout); + } catch (std::runtime_error& e) { + std::cerr << e.what() << std::endl; + exit(1); + } exit(0); } \ No newline at end of file diff --git a/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc b/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc index 980e8d9f26f..0526527be0a 100644 --- a/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc +++ b/src/test/osd/ceph_test_rados_io_sequence/ceph_test_rados_io_sequence.cc @@ -831,7 +831,8 @@ const std::string ceph::io_sequence::tester::SelectErasurePool::select() { bufferlist inbl, outbl; auto formatter = std::make_shared(false); - ceph::messaging::osd::OSDPoolGetRequest osdPoolGetRequest{*force_value}; + ceph::messaging::osd::OSDPoolGetRequest osdPoolGetRequest{*force_value, + "all"}; rc = send_mon_command(osdPoolGetRequest, rados, "OSDPoolGetRequest", inbl, &outbl, formatter.get()); ceph_assert(rc == 0); -- 2.39.5