From: Igor Golikov Date: Mon, 9 Feb 2026 13:32:05 +0000 (+0000) Subject: mds: switch to readable string error X-Git-Tag: testing/wip-vshankar-testing-20260222.101816~3^2~5 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=711f4d68ace8adbed6d8034c048e28f4f38aed17;p=ceph-ci.git mds: switch to readable string error in read_process_cpu_ticks function Signed-off-by: Igor Golikov --- diff --git a/src/common/util.cc b/src/common/util.cc index acd1af97f25..e3fd0ea20b8 100644 --- a/src/common/util.cc +++ b/src/common/util.cc @@ -465,17 +465,14 @@ std::string bytes2str(uint64_t count) { } #ifndef _WIN32 -bool ceph::read_process_cpu_ticks(uint64_t* total, ceph::proc_stat_error* error) +bool ceph::read_process_cpu_ticks(uint64_t* total, std::string* error) { ceph_assert(total != nullptr); - if (error) { - *error = ceph::proc_stat_error::none; - } const char* stat_path = PROCPREFIX "/proc/self/stat"; std::ifstream stat_file(stat_path); if (!stat_file.is_open()) { if (error) { - *error = ceph::proc_stat_error::not_found; + *error = std::string("failed to open '") + stat_path + "'"; } return false; } @@ -484,7 +481,7 @@ bool ceph::read_process_cpu_ticks(uint64_t* total, ceph::proc_stat_error* error) std::istream_iterator()); if (stat_vec.size() < 15) { if (error) { - *error = ceph::proc_stat_error::not_resolvable; + *error = std::string("failed to parse '") + stat_path + "'"; } return false; } @@ -495,10 +492,10 @@ bool ceph::read_process_cpu_ticks(uint64_t* total, ceph::proc_stat_error* error) return true; } #else -bool ceph::read_process_cpu_ticks(uint64_t* total, ceph::proc_stat_error* error) +bool ceph::read_process_cpu_ticks(uint64_t* total, std::string* error) { if (error) { - *error = ceph::proc_stat_error::not_found; + *error = "/proc/self/stat not available on this platform"; } return false; } diff --git a/src/include/util.h b/src/include/util.h index cebdad9e8fe..fc114c2bb23 100644 --- a/src/include/util.h +++ b/src/include/util.h @@ -112,14 +112,8 @@ std::string cleanbin(std::string &str); namespace ceph { -enum class proc_stat_error { - none, - not_found, - not_resolvable -}; - /// Read user+system CPU ticks for the current process from /proc/self/stat -bool read_process_cpu_ticks(uint64_t* total, proc_stat_error* error = nullptr); +bool read_process_cpu_ticks(uint64_t* total, std::string* error = nullptr); namespace util { diff --git a/src/mds/MDBalancer.cc b/src/mds/MDBalancer.cc index 18c5d663381..f109384f486 100644 --- a/src/mds/MDBalancer.cc +++ b/src/mds/MDBalancer.cc @@ -361,16 +361,11 @@ mds_load_t MDBalancer::get_load() uint64_t cpu_time = 1; { uint64_t ticks = 0; - ceph::proc_stat_error err; + std::string err; if (ceph::read_process_cpu_ticks(&ticks, &err)) { cpu_time = ticks; } else { - constexpr const char* stat_path = PROCPREFIX "/proc/self/stat"; - if (err == ceph::proc_stat_error::not_resolvable) { - derr << "input file '" << stat_path << "' not resolvable" << dendl_impl; - } else if (err == ceph::proc_stat_error::not_found) { - derr << "input file '" << stat_path << "' not found" << dendl_impl; - } + derr << err << dendl_impl; } } diff --git a/src/mds/MetricsHandler.cc b/src/mds/MetricsHandler.cc index ffb996b3f21..63328e40ed7 100644 --- a/src/mds/MetricsHandler.cc +++ b/src/mds/MetricsHandler.cc @@ -672,7 +672,7 @@ void MetricsHandler::maybe_update_subvolume_quota(inodeno_t subvol_id, uint64_t void MetricsHandler::sample_cpu_usage() { uint64_t current_ticks = 0; - ceph::proc_stat_error err; + std::string err; if (clk_tck <= 0) { rank_telemetry.metrics.cpu_usage_percent = 0; @@ -687,12 +687,7 @@ void MetricsHandler::sample_cpu_usage() { if (rank_perf_counters) { rank_perf_counters->set(l_mds_rank_perf_cpu_usage, 0); } - constexpr const char* stat_path = PROCPREFIX "/proc/self/stat"; - if (err == ceph::proc_stat_error::not_resolvable) { - dout(5) << "input file '" << stat_path << "' not resolvable" << dendl; - } else if (err == ceph::proc_stat_error::not_found) { - dout(5) << "input file '" << stat_path << "' not found" << dendl; - } + dout(5) << err << dendl; return; }