]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crimson/net: check that Socket only works in its core
authorYingxin Cheng <yingxin.cheng@intel.com>
Wed, 26 Apr 2023 08:45:42 +0000 (16:45 +0800)
committerMatan Breizman <mbreizma@redhat.com>
Wed, 11 Oct 2023 11:38:31 +0000 (11:38 +0000)
Signed-off-by: Yingxin Cheng <yingxin.cheng@intel.com>
(cherry picked from commit d5a9f0eda34f08e9eadbdd5d5e2e26147d27f759)

src/crimson/net/Socket.cc
src/crimson/net/Socket.h

index 1b8e863f7209acb78090602cf84e1c6962b8751f..da2140db6942709023dcee8923af7e95eee6221a 100644 (file)
@@ -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<bufferlist>
 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<bufferptr>
 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<char>& 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);
index 6241c9fbad265bcdf3f4245c6fd5d26d97360a14..789a83a6c03a83d1b7733f96b118b96a3f178715 100644 (file)
@@ -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();
   }