From: Yingxin Cheng Date: Wed, 26 Apr 2023 08:45:42 +0000 (+0800) Subject: crimson/net: check that Socket only works in its core X-Git-Tag: v19.0.0~951^2~24 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=d5a9f0eda34f08e9eadbdd5d5e2e26147d27f759;p=ceph.git crimson/net: check that Socket only works in its core Signed-off-by: Yingxin Cheng --- diff --git a/src/crimson/net/Socket.cc b/src/crimson/net/Socket.cc index 1b8e863f7209a..da2140db69427 100644 --- a/src/crimson/net/Socket.cc +++ b/src/crimson/net/Socket.cc @@ -107,6 +107,7 @@ Socket::Socket( Socket::~Socket() { + assert(seastar::this_shard_id() == sid); #ifndef NDEBUG assert(closed); #endif @@ -115,6 +116,7 @@ Socket::~Socket() seastar::future Socket::read(size_t bytes) { + assert(seastar::this_shard_id() == sid); #ifdef UNIT_TESTS_BUILT return try_trap_pre(next_trap_read).then([bytes, this] { #endif @@ -144,6 +146,7 @@ Socket::read(size_t bytes) seastar::future Socket::read_exactly(size_t bytes) { + assert(seastar::this_shard_id() == sid); #ifdef UNIT_TESTS_BUILT return try_trap_pre(next_trap_read).then([bytes, this] { #endif @@ -174,6 +177,7 @@ Socket::read_exactly(size_t bytes) { seastar::future<> Socket::write(bufferlist buf) { + assert(seastar::this_shard_id() == sid); #ifdef UNIT_TESTS_BUILT return try_trap_pre(next_trap_write ).then([buf = std::move(buf), this]() mutable { @@ -194,6 +198,7 @@ Socket::write(bufferlist buf) seastar::future<> Socket::flush() { + assert(seastar::this_shard_id() == sid); inject_failure(); return inject_delay().then([this] { return out.flush(); @@ -203,6 +208,7 @@ Socket::flush() seastar::future<> Socket::write_flush(bufferlist buf) { + assert(seastar::this_shard_id() == sid); #ifdef UNIT_TESTS_BUILT return try_trap_pre(next_trap_write ).then([buf = std::move(buf), this]() mutable { @@ -223,7 +229,9 @@ Socket::write_flush(bufferlist buf) #endif } -void Socket::shutdown() { +void Socket::shutdown() +{ + assert(seastar::this_shard_id() == sid); socket_is_shutdown = true; socket.shutdown_input(); socket.shutdown_output(); @@ -243,7 +251,9 @@ close_and_handle_errors(seastar::output_stream& out) } seastar::future<> -Socket::close() { +Socket::close() +{ + assert(seastar::this_shard_id() == sid); #ifndef NDEBUG ceph_assert_always(!closed); closed = true; @@ -284,6 +294,7 @@ Socket::connect(const entity_addr_t &peer_addr) #ifdef UNIT_TESTS_BUILT void Socket::set_trap(bp_type_t type, bp_action_t action, socket_blocker* blocker_) { + assert(seastar::this_shard_id() == sid); blocker = blocker_; if (type == bp_type_t::READ) { ceph_assert_always(next_trap_read == bp_action_t::CONTINUE); diff --git a/src/crimson/net/Socket.h b/src/crimson/net/Socket.h index 6241c9fbad265..789a83a6c03a8 100644 --- a/src/crimson/net/Socket.h +++ b/src/crimson/net/Socket.h @@ -38,6 +38,10 @@ public: Socket(Socket&& o) = delete; + seastar::shard_id get_shard_id() const { + return sid; + } + side_t get_side() const { return side; } @@ -51,6 +55,7 @@ public: } bool is_shutdown() const { + assert(seastar::this_shard_id() == sid); return socket_is_shutdown; } @@ -89,17 +94,20 @@ public: // shutdown for tests void force_shutdown() { + assert(seastar::this_shard_id() == sid); socket.shutdown_input(); socket.shutdown_output(); } // shutdown input_stream only, for tests void force_shutdown_in() { + assert(seastar::this_shard_id() == sid); socket.shutdown_input(); } // shutdown output_stream only, for tests void force_shutdown_out() { + assert(seastar::this_shard_id() == sid); socket.shutdown_output(); }