From: Jesse F. Williamson <1643380+chardan@users.noreply.github.com> Date: Mon, 9 Dec 2024 18:27:00 +0000 (-0800) Subject: Fix signed/unsigned warning and add parameter range checking. X-Git-Tag: v20.0.0~513^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=06a56b7efb838d1eee1327803ff893f695e54f69;p=ceph.git Fix signed/unsigned warning and add parameter range checking. Signed-off-by: Jesse F. Williamson <1643380+chardan@users.noreply.github.com> --- diff --git a/src/test/objectstore/allocsim/ops_replayer.cc b/src/test/objectstore/allocsim/ops_replayer.cc index fd947f5c4547a..ec76d6eb7a857 100644 --- a/src/test/objectstore/allocsim/ops_replayer.cc +++ b/src/test/objectstore/allocsim/ops_replayer.cc @@ -1,4 +1,5 @@ #include +#include #include #include #include @@ -23,6 +24,7 @@ #include #include #include +#include #include #include @@ -33,6 +35,23 @@ namespace po = boost::program_options; using namespace std; using namespace ceph; +namespace settings { + +// Returns a function which restricts a value to a specified range by throwing if it is not in range: +// (Note: std::clamp() does not throw.) +auto clamp_or_throw(auto min, auto max) +{ + return [=](auto& x) { + if(std::less<>{}(x, min) or std::greater<>{}(x, max)) { + throw std::out_of_range(std::format("value expected between {} and {}, but got {}", min, max, x)); + } + + return x; + }; +} + +} // namespace settings + // compare shared_ptr struct StringPtrCompare { @@ -338,8 +357,8 @@ int main(int argc, char** argv) { // options uint64_t io_depth = 8; - uint64_t nparser_threads = 16; - uint64_t nworker_threads = 16; + int nparser_threads = 16; + int nworker_threads = 16; string file("input.txt"); string ceph_conf_path("./ceph.conf"); string pool("test_pool"); @@ -351,8 +370,8 @@ int main(int argc, char** argv) { ("input-files,i", po::value>()->multitoken(), "List of input files (output of op_scraper.py). Multiple files will be merged and sorted by time order") ("ceph-conf", po::value(&ceph_conf_path)->default_value("ceph.conf"), "Path to ceph conf") ("io-depth", po::value(&io_depth)->default_value(64), "I/O depth") - ("parser-threads", po::value(&nparser_threads)->default_value(16), "Number of parser threads") - ("worker-threads", po::value(&nworker_threads)->default_value(16), "Number of I/O worker threads") + ("parser-threads", po::value(&nparser_threads)->default_value(16)->notifier(settings::clamp_or_throw(1, 256)), "Number of parser threads") + ("worker-threads", po::value(&nworker_threads)->default_value(16)->notifier(settings::clamp_or_throw(1, 256)), "Number of I/O worker threads") ("pool", po::value(&pool)->default_value("test_pool"), "Pool to use for I/O") ("skip-do-ops", po::bool_switch(&skip_do_ops)->default_value(false), "Skip doing operations") ;