]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mds: switch to readable string error
authorIgor Golikov <igolikov@redhat.com>
Mon, 9 Feb 2026 13:32:05 +0000 (13:32 +0000)
committerIgor Golikov <igolikov@redhat.com>
Mon, 9 Feb 2026 13:32:05 +0000 (13:32 +0000)
in read_process_cpu_ticks function

Signed-off-by: Igor Golikov <igolikov@redhat.com>
src/common/util.cc
src/include/util.h
src/mds/MDBalancer.cc
src/mds/MetricsHandler.cc

index acd1af97f25d63e4d536dee6e81e6dc5bd01faa8..e3fd0ea20b822001df7a7f65737ed074121aee5c 100644 (file)
@@ -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<std::string>());
   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;
 }
index cebdad9e8fe2229f4b7163cb521269861070ba09..fc114c2bb23c50ed9db288be04862e8a1bac0e90 100644 (file)
@@ -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 {
 
index 18c5d66338195c80e3f3e5d12151be23c3a60da8..f109384f486e869d969b8765a4cd0bae44ff53d7 100644 (file)
@@ -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;
     }
   }
 
index ffb996b3f211ffbfec4d1a67a66eb55862ff6f38..63328e40ed7d6da22cf8d0571dcb886da4e6bea2 100644 (file)
@@ -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;
   }