]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
crimson/net: print shared_ptr using fmt::ptr()
authorKefu Chai <tchaikov@gmail.com>
Tue, 22 Nov 2022 04:06:33 +0000 (12:06 +0800)
committerKefu Chai <tchaikov@gmail.com>
Tue, 22 Nov 2022 05:54:41 +0000 (13:54 +0800)
in {fmt} v9, only `void*` pointers can be printed directly. when it
comes to typed pointer or smart pointers, we need to print them using
`fmt::ptr()`. in this change, an overload is added so we can print
`seastar::shared_ptr<>` via `fmt::ptr()` as well, just like how we
print `std::shared_ptr<>`.

Signed-off-by: Kefu Chai <tchaikov@gmail.com>
src/crimson/net/ProtocolV2.cc

index 2b41e868f000898fdbf78a7df42aff290c7c03d2..54d42f6ef3e3a9b53a7c453f663f869cb5e2ce7d 100644 (file)
@@ -100,6 +100,13 @@ inline uint64_t generate_client_cookie() {
 
 } // namespace anonymous
 
+namespace fmt {
+
+template <typename T> auto ptr(const ::seastar::shared_ptr<T>& p) -> const void* {
+  return p.get();
+}
+
+}
 namespace crimson::net {
 
 #ifdef UNIT_TESTS_BUILT
@@ -1095,7 +1102,7 @@ ProtocolV2::handle_existing_connection(SocketConnectionRef existing_conn)
                  " found existing {}(state={}, gs={}, pgs={}, cs={}, cc={}, sc={})",
                  conn, global_seq, peer_global_seq, connect_seq,
                  client_cookie, server_cookie,
-                 existing_conn, get_state_name(existing_proto->state),
+                 fmt::ptr(existing_conn), get_state_name(existing_proto->state),
                  existing_proto->global_seq,
                  existing_proto->peer_global_seq,
                  existing_proto->connect_seq,
@@ -1104,7 +1111,7 @@ ProtocolV2::handle_existing_connection(SocketConnectionRef existing_conn)
 
   if (!validate_peer_name(existing_conn->get_peer_name())) {
     logger().error("{} server_connect: my peer_name doesn't match"
-                   " the existing connection {}, abort", conn, existing_conn);
+                   " the existing connection {}, abort", conn, fmt::ptr(existing_conn));
     abort_in_fault();
   }
 
@@ -1360,7 +1367,7 @@ ProtocolV2::server_reconnect()
                    " found existing {}(state={}, gs={}, pgs={}, cs={}, cc={}, sc={})",
                    conn, global_seq, peer_global_seq, reconnect.connect_seq(),
                    reconnect.client_cookie(), reconnect.server_cookie(),
-                   existing_conn,
+                   fmt::ptr(existing_conn),
                    get_state_name(existing_proto->state),
                    existing_proto->global_seq,
                    existing_proto->peer_global_seq,
@@ -1370,7 +1377,7 @@ ProtocolV2::server_reconnect()
 
     if (!validate_peer_name(existing_conn->get_peer_name())) {
       logger().error("{} server_reconnect: my peer_name doesn't match"
-                     " the existing connection {}, abort", conn, existing_conn);
+                     " the existing connection {}, abort", conn, fmt::ptr(existing_conn));
       abort_in_fault();
     }