]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson, osd: declare fmt formatters before they are used
authorKefu Chai <k.chai@proxmox.com>
Tue, 16 Jun 2026 12:19:11 +0000 (20:19 +0800)
committerKefu Chai <k.chai@proxmox.com>
Wed, 17 Jun 2026 08:54:51 +0000 (16:54 +0800)
the seastar logger checks log format strings with a consteval call at
the use site, which instantiates fmt::formatter<T> there. a
specialization declared at the bottom of a header, after inline methods
that already log T, is then "explicit specialization after
instantiation".

move the offending specializations ahead of the type: PG, LBALeafNode,
DummyNodeExtent and WatchTimeoutRequest get a forward declaration plus
the formatter before the class; overwrite_range_t, data_t and edge_t in
object_data_handler.cc move ahead of the functions that log them. while
here, trim_data_reservation() formatted a laddr_t base with 0x{:x}, but
laddr_t's formatter takes no spec, so use {}.

osd_types_fmt.h includes msg/msg_fmt.h: formatter<osd_reqid_t> formats
req_id.name (an entity_name_t), so it depends on that type's formatter
and must pull it in. otherwise logging a reqid instantiates
formatter<entity_name_t> before msg_fmt.h is seen.

Signed-off-by: Kefu Chai <k.chai@proxmox.com>
src/crimson/os/seastore/lba/lba_btree_node.h
src/crimson/os/seastore/object_data_handler.cc
src/crimson/os/seastore/onode_manager/staged-fltree/node_extent_manager/dummy.h
src/crimson/osd/pg.h
src/crimson/osd/watch.cc
src/osd/osd_types_fmt.h

index dd15c2a8cf2e133732f051b168957ccff8ee2ccf..de7e18d8e6e4e8503367fcd808949707404d60c7 100644 (file)
@@ -7,6 +7,7 @@
 #include <memory>
 #include <string.h>
 
+#include <fmt/ostream.h>
 
 #include "include/buffer.h"
 
@@ -24,6 +25,16 @@ namespace crimson::os::seastore {
 class LogicalChildNode;
 }
 
+namespace crimson::os::seastore::lba {
+struct LBALeafNode;
+}
+
+// declared ahead of the struct so the consteval {fmt} check sees it from
+// LBALeafNode's own inline logging methods.
+#if FMT_VERSION >= 90000
+template <> struct fmt::formatter<crimson::os::seastore::lba::LBALeafNode> : fmt::ostream_formatter {};
+#endif
+
 namespace crimson::os::seastore::lba {
 
 using LBANode = FixedKVNode<laddr_t>;
@@ -470,6 +481,5 @@ using LBACursorRef = boost::intrusive_ptr<LBACursor>;
 template <> struct fmt::formatter<crimson::os::seastore::lba::lba_node_meta_t> : fmt::ostream_formatter {};
 template <> struct fmt::formatter<crimson::os::seastore::lba::lba_map_val_t> : fmt::ostream_formatter {};
 template <> struct fmt::formatter<crimson::os::seastore::lba::LBAInternalNode> : fmt::ostream_formatter {};
-template <> struct fmt::formatter<crimson::os::seastore::lba::LBALeafNode> : fmt::ostream_formatter {};
 template <> struct fmt::formatter<crimson::os::seastore::lba::LBACursor> : fmt::ostream_formatter {};
 #endif
index a586a606d68423510512b6b5f65bc5d633966501..a71de48635218946fcebead017223ef9755283e5 100644 (file)
@@ -4,10 +4,23 @@
 #include <utility>
 #include <functional>
 
+#include <fmt/ostream.h>
+
 #include "crimson/common/log.h"
 
 #include "crimson/os/seastore/object_data_handler.h"
 
+// declared ahead of the logging functions below so the consteval {fmt}
+// check can see them at the call sites.
+#if FMT_VERSION >= 90000
+template <> struct fmt::formatter<crimson::os::seastore::overwrite_range_t>
+  : fmt::ostream_formatter {};
+template <> struct fmt::formatter<crimson::os::seastore::data_t>
+  : fmt::ostream_formatter {};
+template <> struct fmt::formatter<crimson::os::seastore::edge_t>
+  : fmt::ostream_formatter {};
+#endif
+
 namespace {
   seastar::logger& logger() {
     return crimson::get_logger(ceph_subsys_seastore_odata);
@@ -1881,11 +1894,3 @@ ObjectDataHandler::rename(context_t ctx)
 
 } // namespace crimson::os::seastore
 
-#if FMT_VERSION >= 90000
-template <> struct fmt::formatter<crimson::os::seastore::overwrite_range_t>
-  : fmt::ostream_formatter {};
-template <> struct fmt::formatter<crimson::os::seastore::data_t>
-  : fmt::ostream_formatter {};
-template <> struct fmt::formatter<crimson::os::seastore::edge_t>
-  : fmt::ostream_formatter {};
-#endif
index 6852ec0298c16fb634b557dc51525c65227d8e82..3a1610d15785c2942a8421b5df2095570fade2b3 100644 (file)
 
 #include "crimson/os/seastore/onode_manager/staged-fltree/node_extent_manager.h"
 
+#include <fmt/ostream.h>
+
 /**
  * dummy.h
  *
  * Dummy backend implementations for test purposes.
  */
 
+namespace crimson::os::seastore::onode {
+class DummyNodeExtent;
+}
+
+#if FMT_VERSION >= 90000
+template <> struct fmt::formatter<crimson::os::seastore::onode::DummyNodeExtent> : fmt::ostream_formatter {};
+#endif
+
 namespace crimson::os::seastore::onode {
 
 class DummySuper final: public Super {
@@ -191,7 +201,3 @@ class DummyNodeExtentManager final: public NodeExtentManager {
 };
 
 }
-
-#if FMT_VERSION >= 90000
-template <> struct fmt::formatter<crimson::os::seastore::onode::DummyNodeExtent> : fmt::ostream_formatter {};
-#endif
index 6e5e47c591c290b9251b714ac786e4794906f121..d44f4455a015d9c5d75299197e8c2c02f19c2e9e 100644 (file)
@@ -11,6 +11,8 @@
 #include <seastar/core/semaphore.hh>
 #include <seastar/core/sharded.hh>
 
+#include <fmt/ostream.h>
+
 #include "common/dout.h"
 #include "common/ostream_temp.h"
 #include "include/interval_set.h"
@@ -67,6 +69,16 @@ namespace crimson::os {
   class FuturizedStore;
 }
 
+namespace crimson::osd {
+class PG;
+}
+
+// declared ahead of the class so the consteval {fmt} check can see it from
+// PG's own inline logging methods (which format *this) above the class.
+#if FMT_VERSION >= 90000
+template <> struct fmt::formatter<crimson::osd::PG> : fmt::ostream_formatter {};
+#endif
+
 namespace crimson::osd {
 class OpsExecuter;
 class SnapTrimEvent;
@@ -1356,7 +1368,3 @@ struct PG::do_osd_ops_params_t {
 std::ostream& operator<<(std::ostream&, const PG& pg);
 
 }
-
-#if FMT_VERSION >= 90000
-template <> struct fmt::formatter<crimson::osd::PG> : fmt::ostream_formatter {};
-#endif
index d8db6ba628eb67386db4abc83853681207c9b686..085345409417634c3f3dda2fd8d34f73ac4e4db2 100644 (file)
@@ -11,6 +11,8 @@
 
 #include "messages/MWatchNotify.h"
 
+#include <fmt/ostream.h>
+
 
 namespace {
   seastar::logger& logger() {
@@ -18,6 +20,14 @@ namespace {
   }
 }
 
+namespace crimson::osd {
+class WatchTimeoutRequest;
+}
+
+#if FMT_VERSION >= 90000
+template <> struct fmt::formatter<crimson::osd::WatchTimeoutRequest> : fmt::ostream_formatter {};
+#endif
+
 namespace crimson::osd {
 
 // a watcher can remove itself if it has not seen a notification after a period of time.
@@ -348,7 +358,3 @@ void Notify::do_notify_timeout()
 }
 
 } // namespace crimson::osd
-
-#if FMT_VERSION >= 90000
-template <> struct fmt::formatter<crimson::osd::WatchTimeoutRequest> : fmt::ostream_formatter {};
-#endif
index 0e36755782a173f4fef2f06d5e01af9d104126c1..402453bc2e98be2e86a108b5f352412a0e3b93ce 100644 (file)
@@ -8,6 +8,11 @@
 
 #include "common/hobject.h"
 #include "include/types_fmt.h"
+// formatter<osd_reqid_t> below formats req_id.name (entity_name_t), so its
+// formatter must be visible here, otherwise it gets instantiated before
+// msg_fmt.h is pulled in by a later include (explicit-specialization-after-
+// instantiation under compile-time {fmt} checking).
+#include "msg/msg_fmt.h"
 #include "osd/osd_types.h"
 #include <fmt/chrono.h>
 #include <fmt/ranges.h>