]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/scrubber: replace deprecated fmt::localtime() with localtime_r() 63970/head
authorKefu Chai <tchaikov@gmail.com>
Tue, 17 Jun 2025 04:00:17 +0000 (12:00 +0800)
committerKefu Chai <tchaikov@gmail.com>
Wed, 18 Jun 2025 00:57:19 +0000 (08:57 +0800)
Replace fmt::localtime() with localtime_r() to fix build failure with
fmt 11.2.0. The fmt::localtime() function was deprecated in favor of
std::localtime, causing build errors when treating warnings as errors:

```
[1/3] Building CXX object src/osd/CMakeFiles/osd.dir/scrubber/pg_scrubber.cc.o
/home/kefu/dev/ceph/src/osd/scrubber/pg_scrubber.cc: In member function ‘virtual void PgScrubber::update_scrub_stats(ceph::coarse_real_clock::time_point)’:
/home/kefu/dev/ceph/src/osd/scrubber/pg_scrubber.cc:2767:41: warning: ‘tm fmt::v11::localtime(time_t)’ is deprecated [-Wdeprecated-declarations]
 2767 |     auto printable_last = fmt::localtime(clock::to_time_t(m_last_stat_upd));
      |                           ~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /home/kefu/dev/ceph/src/fmt/include/fmt/ostream.h:23,
                 from /home/kefu/dev/ceph/src/msg/msg_types.h:26,
                 from /home/kefu/dev/ceph/src/common/options.h:12,
                 from /home/kefu/dev/ceph/src/common/config.h:25,
                 from /home/kefu/dev/ceph/src/common/config_proxy.h:7,
                 from /home/kefu/dev/ceph/src/osd/scrubber/./pg_scrubber.h:78,
                 from /home/kefu/dev/ceph/src/osd/scrubber/pg_scrubber.cc:4:
/home/kefu/dev/ceph/src/fmt/include/fmt/chrono.h:538:28: note: declared here
  538 | FMT_DEPRECATED inline auto localtime(std::time_t time) -> std::tm {
      |                            ^~~~~~~~~
```

Unlike other parts of the codebase, this implementation checks the return
value of localtime_r() to preserve the error-handling behavior of
fmt::localtime(), which throws on failure. Future changes may opt for
consistency with the broader codebase over behavioral compatibility.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/osd/scrubber/pg_scrubber.cc

index 65e99ad387c4ea8470033b215f4d78e3465fa8e8..f3b399c3bd9bbbffba997a1cdeb1d0e2eea28973 100644 (file)
@@ -2760,18 +2760,19 @@ void PgScrubber::update_scrub_stats(ceph::coarse_real_clock::time_point now_is)
 
   /// \todo use the date library (either the one included in Arrow or directly)
   /// to get the formatting of the time_points.
-
   if (g_conf()->subsys.should_gather<ceph_subsys_osd, 25>()) {
     // will only create the debug strings if required
-    char buf[50];
-    auto printable_last = fmt::localtime(clock::to_time_t(m_last_stat_upd));
-    strftime(buf, sizeof(buf), "%Y-%m-%dT%T", &printable_last);
-    dout(20) << fmt::format("{}: period: {}/{}-> {} last:{}",
+    std::time_t time = clock::to_time_t(m_last_stat_upd);
+    std::tm tm_local;
+    if (!localtime_r(&time, &tm_local)) {
+      throw fmt::format_error("time_t value out of range");
+    }
+    dout(20) << fmt::format("{}: period: {}/{}-> {} last:{:%FT%T}",
                            __func__,
                            period_active,
                            period_inactive,
                            period,
-                           buf)
+                           tm_local)
             << dendl;
   }