From 42dc970392e8c49fde46aae66ce8ef81ff00d49c Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 22 Nov 2022 12:06:33 +0800 Subject: [PATCH] crimson/net: print shared_ptr using fmt::ptr() 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 --- src/crimson/net/ProtocolV2.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/crimson/net/ProtocolV2.cc b/src/crimson/net/ProtocolV2.cc index 2b41e868f00..54d42f6ef3e 100644 --- a/src/crimson/net/ProtocolV2.cc +++ b/src/crimson/net/ProtocolV2.cc @@ -100,6 +100,13 @@ inline uint64_t generate_client_cookie() { } // namespace anonymous +namespace fmt { + +template auto ptr(const ::seastar::shared_ptr& 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(); } -- 2.39.5