From: Yingxin Cheng Date: Mon, 10 Feb 2020 09:00:31 +0000 (+0800) Subject: crimson/net: remove duplicated error codes and conditions X-Git-Tag: v15.1.1~394^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=193113a0ac1fd67772b02f9e502e5ddd23e64a92;p=ceph.git crimson/net: remove duplicated error codes and conditions The duplicated error codes and conditions were originally introduced to match connection errors with both system category (thrown by seastar) and generic category (thrown by standard library). Since error_code with system category can be matched by error_condition with generic category (see std::errc and system_error_category::default_error_condition(int)), our duplicated counterparts are not needed actually. Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/net/Errors.cc b/src/crimson/net/Errors.cc index bc92bc75d3695..d07c090db737a 100644 --- a/src/crimson/net/Errors.cc +++ b/src/crimson/net/Errors.cc @@ -35,104 +35,14 @@ const std::error_category& net_category() return "negotiation failure"; case error::read_eof: return "read eof"; - case error::connection_aborted: - return "connection aborted"; - case error::connection_refused: - return "connection refused"; - case error::connection_reset: - return "connection reset"; case error::corrupted_message: return "corrupted message"; - case error::invalid_argument: - return "invalid argument"; - case error::address_in_use: - return "address in use"; - case error::broken_pipe: - return "broken pipe"; case error::protocol_aborted: return "protocol aborted"; default: return "unknown"; } } - - // unfortunately, seastar throws connection errors with the system category, - // rather than the generic category that would match their counterparts - // in std::errc. we add our own errors for them, so we can match either - std::error_condition default_error_condition(int ev) const noexcept override { - switch (static_cast(ev)) { - case error::connection_aborted: - return std::errc::connection_aborted; - case error::connection_refused: - return std::errc::connection_refused; - case error::connection_reset: - return std::errc::connection_reset; - case error::invalid_argument: - return std::errc::invalid_argument; - case error::address_in_use: - return std::errc::address_in_use; - case error::broken_pipe: - return std::errc::broken_pipe; - default: - return std::error_condition(ev, *this); - } - } - - bool equivalent(int code, const std::error_condition& cond) const noexcept override { - if (error_category::equivalent(code, cond)) { - return true; - } - switch (static_cast(code)) { - case error::connection_aborted: - return cond == std::errc::connection_aborted - || cond == std::error_condition(ECONNABORTED, std::system_category()); - case error::connection_refused: - return cond == std::errc::connection_refused - || cond == std::error_condition(ECONNREFUSED, std::system_category()); - case error::connection_reset: - return cond == std::errc::connection_reset - || cond == std::error_condition(ECONNRESET, std::system_category()); - case error::invalid_argument: - return cond == std::errc::invalid_argument - || cond == std::error_condition(EINVAL, std::system_category()); - case error::address_in_use: - return cond == std::errc::address_in_use - || cond == std::error_condition(EADDRINUSE, std::system_category()); - case error::broken_pipe: - return cond == std::errc::broken_pipe - || cond == std::error_condition(EPIPE, std::system_category()); - default: - return false; - } - } - - bool equivalent(const std::error_code& code, int cond) const noexcept override { - if (error_category::equivalent(code, cond)) { - return true; - } - switch (static_cast(cond)) { - case error::connection_aborted: - return code == std::errc::connection_aborted - || code == std::error_code(ECONNABORTED, std::system_category()); - case error::connection_refused: - return code == std::errc::connection_refused - || code == std::error_code(ECONNREFUSED, std::system_category()); - case error::connection_reset: - return code == std::errc::connection_reset - || code == std::error_code(ECONNRESET, std::system_category()); - case error::invalid_argument: - return code == std::errc::invalid_argument - || code == std::error_code(EINVAL, std::system_category()); - case error::address_in_use: - return code == std::errc::address_in_use - || code == std::error_code(EADDRINUSE, std::system_category()); - case error::broken_pipe: - return code == std::errc::broken_pipe - || code == std::error_code(EPIPE, std::system_category()); - default: - return false; - } - } }; static category instance; return instance; diff --git a/src/crimson/net/Errors.h b/src/crimson/net/Errors.h index 0957517b0085e..3a17a103a1982 100644 --- a/src/crimson/net/Errors.h +++ b/src/crimson/net/Errors.h @@ -25,13 +25,7 @@ enum class error { bad_peer_address, negotiation_failure, read_eof, - connection_aborted, - connection_refused, - connection_reset, corrupted_message, - invalid_argument, - address_in_use, - broken_pipe, protocol_aborted, }; diff --git a/src/crimson/net/Protocol.cc b/src/crimson/net/Protocol.cc index 10e232a7eca2d..bf2633c1c2214 100644 --- a/src/crimson/net/Protocol.cc +++ b/src/crimson/net/Protocol.cc @@ -257,8 +257,8 @@ seastar::future<> Protocol::do_write_dispatch_sweep() ceph_assert(false); } }).handle_exception_type([this] (const std::system_error& e) { - if (e.code() != error::broken_pipe && - e.code() != error::connection_reset && + if (e.code() != std::errc::broken_pipe && + e.code() != std::errc::connection_reset && e.code() != error::negotiation_failure) { logger().error("{} write_event(): unexpected error at {} -- {}", conn, get_state_name(write_state), e); diff --git a/src/crimson/net/ProtocolV1.cc b/src/crimson/net/ProtocolV1.cc index e079a29091635..3eac0d2c92431 100644 --- a/src/crimson/net/ProtocolV1.cc +++ b/src/crimson/net/ProtocolV1.cc @@ -324,7 +324,7 @@ void ProtocolV1::start_connect(const entity_addr_t& _peer_addr, socket = std::move(sock); if (state == state_t::closing) { return socket->close().then([] { - throw std::system_error(make_error_code(error::connection_aborted)); + throw std::system_error(make_error_code(error::protocol_aborted)); }); } return seastar::now(); @@ -878,7 +878,7 @@ seastar::future<> ProtocolV1::handle_tags() return handle_keepalive2_ack(); case CEPH_MSGR_TAG_CLOSE: logger().info("{} got tag close", conn); - throw std::system_error(make_error_code(error::connection_aborted)); + throw std::system_error(make_error_code(error::protocol_aborted)); default: logger().error("{} got unknown msgr tag {}", conn, static_cast(buf[0])); @@ -899,8 +899,8 @@ void ProtocolV1::execute_open() return handle_tags() .handle_exception_type([this] (const std::system_error& e) { logger().warn("{} open fault: {}", conn, e); - if (e.code() == error::connection_aborted || - e.code() == error::connection_reset) { + if (e.code() == error::protocol_aborted || + e.code() == std::errc::connection_reset) { return dispatcher.ms_handle_reset( seastar::static_pointer_cast(conn.shared_from_this())) .then([this] { diff --git a/src/crimson/net/Socket.cc b/src/crimson/net/Socket.cc index 86b5f6752cc08..75c215bf144f2 100644 --- a/src/crimson/net/Socket.cc +++ b/src/crimson/net/Socket.cc @@ -115,8 +115,8 @@ static inline seastar::future<> close_and_handle_errors(seastar::output_stream& out) { return out.close().handle_exception_type([] (const std::system_error& e) { - if (e.code() != error::broken_pipe && - e.code() != error::connection_reset) { + if (e.code() != std::errc::broken_pipe && + e.code() != std::errc::connection_reset) { logger().error("Socket::close(): unexpected error {}", e); ceph_abort(); } diff --git a/src/crimson/net/Socket.h b/src/crimson/net/Socket.h index 2123136bdda28..c97554f50bab7 100644 --- a/src/crimson/net/Socket.h +++ b/src/crimson/net/Socket.h @@ -178,7 +178,7 @@ public: lo.set_fixed_cpu(ss.cpu); ss.listener = seastar::listen(s_addr, lo); }).handle_exception_type([addr] (const std::system_error& e) { - if (e.code() == error::address_in_use) { + if (e.code() == std::errc::address_in_use) { logger().trace("FixedCPUServerSocket::listen({}): address in use", addr); throw; } else { @@ -230,8 +230,8 @@ public: }); }); }).handle_exception_type([&ss] (const std::system_error& e) { - if (e.code() == error::connection_aborted || - e.code() == error::invalid_argument) { + if (e.code() == std::errc::connection_aborted || + e.code() == std::errc::invalid_argument) { logger().trace("FixedCPUServerSocket({})::accept(): stopped ({})", ss.addr, e); } else { diff --git a/src/crimson/net/SocketMessenger.cc b/src/crimson/net/SocketMessenger.cc index 807511712f017..423e7d4edc987 100644 --- a/src/crimson/net/SocketMessenger.cc +++ b/src/crimson/net/SocketMessenger.cc @@ -99,7 +99,7 @@ SocketMessenger::try_bind(const entity_addrvec_t& addrs, logger().info("{} try_bind: done", *this); return stop_t::yes; }).handle_exception_type([this, max_port, &port] (const std::system_error& e) { - assert(e.code() == error::address_in_use); + assert(e.code() == std::errc::address_in_use); logger().trace("{} try_bind: {} already used", *this, port); if (port == max_port) { throw; diff --git a/src/test/crimson/test_socket.cc b/src/test/crimson/test_socket.cc index 3810f4fd07291..cb44373f8de58 100644 --- a/src/test/crimson/test_socket.cc +++ b/src/test/crimson/test_socket.cc @@ -43,7 +43,7 @@ future<> test_refused() { return socket_connect().discard_result().then([] { ceph_abort_msg("connection is not refused"); }).handle_exception_type([] (const std::system_error& e) { - if (e.code() != error::connection_refused) { + if (e.code() != std::errc::connection_refused) { logger.error("test_refused() got unexpeted error {}", e); ceph_abort(); } else { @@ -69,7 +69,7 @@ future<> test_bind_same() { }).finally([pss2] { return pss2->destroy(); }).handle_exception_type([] (const std::system_error& e) { - if (e.code() != error::address_in_use) { + if (e.code() != std::errc::address_in_use) { logger.error("test_bind_same() got unexpeted error {}", e); ceph_abort(); } else { @@ -246,8 +246,8 @@ class Connection { ).then([] { ceph_abort(); }).handle_exception_type([this] (const std::system_error& e) { - if (e.code() != error::broken_pipe && - e.code() != error::connection_reset) { + if (e.code() != std::errc::broken_pipe && + e.code() != std::errc::connection_reset) { logger.error("dispatch_write_unbounded(): " "unexpected error {}", e); throw; @@ -305,7 +305,7 @@ class Connection { ceph_abort(); }).handle_exception_type([this] (const std::system_error& e) { if (e.code() != error::read_eof - && e.code() != error::connection_reset) { + && e.code() != std::errc::connection_reset) { logger.error("dispatch_read_unbounded(): " "unexpected error {}", e); throw;