~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/net/smc/smc_close.c

Version: ~ [ linux-6.11.5 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.58 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.114 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.169 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.228 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.284 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.322 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /net/smc/smc_close.c (Version linux-6.11.5) and /net/smc/smc_close.c (Version linux-4.17.19)


  1 // SPDX-License-Identifier: GPL-2.0                 1 // SPDX-License-Identifier: GPL-2.0
  2 /*                                                  2 /*
  3  *  Shared Memory Communications over RDMA (SM      3  *  Shared Memory Communications over RDMA (SMC-R) and RoCE
  4  *                                                  4  *
  5  *  Socket Closing - normal and abnormal            5  *  Socket Closing - normal and abnormal
  6  *                                                  6  *
  7  *  Copyright IBM Corp. 2016                        7  *  Copyright IBM Corp. 2016
  8  *                                                  8  *
  9  *  Author(s):  Ursula Braun <ubraun@linux.vne      9  *  Author(s):  Ursula Braun <ubraun@linux.vnet.ibm.com>
 10  */                                                10  */
 11                                                    11 
 12 #include <linux/workqueue.h>                       12 #include <linux/workqueue.h>
 13 #include <linux/sched/signal.h>                    13 #include <linux/sched/signal.h>
 14                                                    14 
 15 #include <net/sock.h>                              15 #include <net/sock.h>
 16 #include <net/tcp.h>                           << 
 17                                                    16 
 18 #include "smc.h"                                   17 #include "smc.h"
 19 #include "smc_tx.h"                                18 #include "smc_tx.h"
 20 #include "smc_cdc.h"                               19 #include "smc_cdc.h"
 21 #include "smc_close.h"                             20 #include "smc_close.h"
 22                                                    21 
 23 /* release the clcsock that is assigned to the !!  22 #define SMC_CLOSE_WAIT_LISTEN_CLCSOCK_TIME      (5 * HZ)
 24 void smc_clcsock_release(struct smc_sock *smc) << 
 25 {                                              << 
 26         struct socket *tcp;                    << 
 27                                                << 
 28         if (smc->listen_smc && current_work()  << 
 29                 cancel_work_sync(&smc->smc_lis << 
 30         mutex_lock(&smc->clcsock_release_lock) << 
 31         if (smc->clcsock) {                    << 
 32                 tcp = smc->clcsock;            << 
 33                 smc->clcsock = NULL;           << 
 34                 sock_release(tcp);             << 
 35         }                                      << 
 36         mutex_unlock(&smc->clcsock_release_loc << 
 37 }                                              << 
 38                                                    23 
 39 static void smc_close_cleanup_listen(struct so     24 static void smc_close_cleanup_listen(struct sock *parent)
 40 {                                                  25 {
 41         struct sock *sk;                           26         struct sock *sk;
 42                                                    27 
 43         /* Close non-accepted connections */       28         /* Close non-accepted connections */
 44         while ((sk = smc_accept_dequeue(parent     29         while ((sk = smc_accept_dequeue(parent, NULL)))
 45                 smc_close_non_accepted(sk);        30                 smc_close_non_accepted(sk);
 46 }                                                  31 }
 47                                                    32 
 48 /* wait for sndbuf data being transmitted */       33 /* wait for sndbuf data being transmitted */
 49 static void smc_close_stream_wait(struct smc_s     34 static void smc_close_stream_wait(struct smc_sock *smc, long timeout)
 50 {                                                  35 {
 51         DEFINE_WAIT_FUNC(wait, woken_wake_func     36         DEFINE_WAIT_FUNC(wait, woken_wake_function);
 52         struct sock *sk = &smc->sk;                37         struct sock *sk = &smc->sk;
 53                                                    38 
 54         if (!timeout)                              39         if (!timeout)
 55                 return;                            40                 return;
 56                                                    41 
 57         if (!smc_tx_prepared_sends(&smc->conn)     42         if (!smc_tx_prepared_sends(&smc->conn))
 58                 return;                            43                 return;
 59                                                    44 
 60         /* Send out corked data remaining in s << 
 61         smc_tx_pending(&smc->conn);            << 
 62                                                << 
 63         smc->wait_close_tx_prepared = 1;           45         smc->wait_close_tx_prepared = 1;
 64         add_wait_queue(sk_sleep(sk), &wait);       46         add_wait_queue(sk_sleep(sk), &wait);
 65         while (!signal_pending(current) && tim     47         while (!signal_pending(current) && timeout) {
 66                 int rc;                            48                 int rc;
 67                                                    49 
 68                 rc = sk_wait_event(sk, &timeou     50                 rc = sk_wait_event(sk, &timeout,
 69                                    !smc_tx_pre     51                                    !smc_tx_prepared_sends(&smc->conn) ||
 70                                    READ_ONCE(s !!  52                                    (sk->sk_err == ECONNABORTED) ||
 71                                    READ_ONCE(s !!  53                                    (sk->sk_err == ECONNRESET),
 72                                    smc->conn.k << 
 73                                    &wait);         54                                    &wait);
 74                 if (rc)                            55                 if (rc)
 75                         break;                     56                         break;
 76         }                                          57         }
 77         remove_wait_queue(sk_sleep(sk), &wait)     58         remove_wait_queue(sk_sleep(sk), &wait);
 78         smc->wait_close_tx_prepared = 0;           59         smc->wait_close_tx_prepared = 0;
 79 }                                                  60 }
 80                                                    61 
 81 void smc_close_wake_tx_prepared(struct smc_soc     62 void smc_close_wake_tx_prepared(struct smc_sock *smc)
 82 {                                                  63 {
 83         if (smc->wait_close_tx_prepared)           64         if (smc->wait_close_tx_prepared)
 84                 /* wake up socket closing */       65                 /* wake up socket closing */
 85                 smc->sk.sk_state_change(&smc->     66                 smc->sk.sk_state_change(&smc->sk);
 86 }                                                  67 }
 87                                                    68 
 88 static int smc_close_wr(struct smc_connection      69 static int smc_close_wr(struct smc_connection *conn)
 89 {                                                  70 {
 90         conn->local_tx_ctrl.conn_state_flags.p     71         conn->local_tx_ctrl.conn_state_flags.peer_done_writing = 1;
 91                                                    72 
 92         return smc_cdc_get_slot_and_msg_send(c     73         return smc_cdc_get_slot_and_msg_send(conn);
 93 }                                                  74 }
 94                                                    75 
 95 static int smc_close_final(struct smc_connecti     76 static int smc_close_final(struct smc_connection *conn)
 96 {                                                  77 {
 97         if (atomic_read(&conn->bytes_to_rcv))      78         if (atomic_read(&conn->bytes_to_rcv))
 98                 conn->local_tx_ctrl.conn_state     79                 conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1;
 99         else                                       80         else
100                 conn->local_tx_ctrl.conn_state     81                 conn->local_tx_ctrl.conn_state_flags.peer_conn_closed = 1;
101         if (conn->killed)                      << 
102                 return -EPIPE;                 << 
103                                                    82 
104         return smc_cdc_get_slot_and_msg_send(c     83         return smc_cdc_get_slot_and_msg_send(conn);
105 }                                                  84 }
106                                                    85 
107 int smc_close_abort(struct smc_connection *con !!  86 static int smc_close_abort(struct smc_connection *conn)
108 {                                                  87 {
109         conn->local_tx_ctrl.conn_state_flags.p     88         conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1;
110                                                    89 
111         return smc_cdc_get_slot_and_msg_send(c     90         return smc_cdc_get_slot_and_msg_send(conn);
112 }                                                  91 }
113                                                    92 
114 static void smc_close_cancel_work(struct smc_s << 
115 {                                              << 
116         struct sock *sk = &smc->sk;            << 
117                                                << 
118         release_sock(sk);                      << 
119         if (cancel_work_sync(&smc->conn.close_ << 
120                 sock_put(sk);                  << 
121         cancel_delayed_work_sync(&smc->conn.tx << 
122         lock_sock(sk);                         << 
123 }                                              << 
124                                                << 
125 /* terminate smc socket abnormally - active ab     93 /* terminate smc socket abnormally - active abort
126  * link group is terminated, i.e. RDMA communi     94  * link group is terminated, i.e. RDMA communication no longer possible
127  */                                                95  */
128 void smc_close_active_abort(struct smc_sock *s !!  96 static void smc_close_active_abort(struct smc_sock *smc)
129 {                                                  97 {
130         struct sock *sk = &smc->sk;                98         struct sock *sk = &smc->sk;
131         bool release_clcsock = false;          << 
132                                                    99 
133         if (sk->sk_state != SMC_INIT && smc->c !! 100         struct smc_cdc_conn_state_flags *txflags =
134                 sk->sk_err = ECONNABORTED;     !! 101                 &smc->conn.local_tx_ctrl.conn_state_flags;
135                 if (smc->clcsock && smc->clcso !! 102 
136                         tcp_abort(smc->clcsock !! 103         sk->sk_err = ECONNABORTED;
                                                   >> 104         if (smc->clcsock && smc->clcsock->sk) {
                                                   >> 105                 smc->clcsock->sk->sk_err = ECONNABORTED;
                                                   >> 106                 smc->clcsock->sk->sk_state_change(smc->clcsock->sk);
137         }                                         107         }
138         switch (sk->sk_state) {                   108         switch (sk->sk_state) {
                                                   >> 109         case SMC_INIT:
139         case SMC_ACTIVE:                          110         case SMC_ACTIVE:
                                                   >> 111                 sk->sk_state = SMC_PEERABORTWAIT;
                                                   >> 112                 release_sock(sk);
                                                   >> 113                 cancel_delayed_work_sync(&smc->conn.tx_work);
                                                   >> 114                 lock_sock(sk);
                                                   >> 115                 sock_put(sk); /* passive closing */
                                                   >> 116                 break;
140         case SMC_APPCLOSEWAIT1:                   117         case SMC_APPCLOSEWAIT1:
141         case SMC_APPCLOSEWAIT2:                   118         case SMC_APPCLOSEWAIT2:
142                 sk->sk_state = SMC_PEERABORTWA !! 119                 if (!smc_cdc_rxed_any_close(&smc->conn))
143                 smc_close_cancel_work(smc);    !! 120                         sk->sk_state = SMC_PEERABORTWAIT;
144                 if (sk->sk_state != SMC_PEERAB !! 121                 else
145                         break;                 !! 122                         sk->sk_state = SMC_CLOSED;
146                 sk->sk_state = SMC_CLOSED;     !! 123                 release_sock(sk);
147                 sock_put(sk); /* (postponed) p !! 124                 cancel_delayed_work_sync(&smc->conn.tx_work);
                                                   >> 125                 lock_sock(sk);
148                 break;                            126                 break;
149         case SMC_PEERCLOSEWAIT1:                  127         case SMC_PEERCLOSEWAIT1:
150         case SMC_PEERCLOSEWAIT2:                  128         case SMC_PEERCLOSEWAIT2:
151         case SMC_PEERFINCLOSEWAIT:             !! 129                 if (!txflags->peer_conn_closed) {
152                 sk->sk_state = SMC_PEERABORTWA !! 130                         /* just SHUTDOWN_SEND done */
153                 smc_close_cancel_work(smc);    !! 131                         sk->sk_state = SMC_PEERABORTWAIT;
154                 if (sk->sk_state != SMC_PEERAB !! 132                 } else {
155                         break;                 !! 133                         sk->sk_state = SMC_CLOSED;
156                 sk->sk_state = SMC_CLOSED;     !! 134                 }
157                 smc_conn_free(&smc->conn);     << 
158                 release_clcsock = true;        << 
159                 sock_put(sk); /* passive closi    135                 sock_put(sk); /* passive closing */
160                 break;                            136                 break;
161         case SMC_PROCESSABORT:                    137         case SMC_PROCESSABORT:
162         case SMC_APPFINCLOSEWAIT:                 138         case SMC_APPFINCLOSEWAIT:
163                 sk->sk_state = SMC_PEERABORTWA << 
164                 smc_close_cancel_work(smc);    << 
165                 if (sk->sk_state != SMC_PEERAB << 
166                         break;                 << 
167                 sk->sk_state = SMC_CLOSED;        139                 sk->sk_state = SMC_CLOSED;
168                 smc_conn_free(&smc->conn);     << 
169                 release_clcsock = true;        << 
170                 break;                            140                 break;
171         case SMC_INIT:                         !! 141         case SMC_PEERFINCLOSEWAIT:
                                                   >> 142                 sock_put(sk); /* passive closing */
                                                   >> 143                 break;
172         case SMC_PEERABORTWAIT:                   144         case SMC_PEERABORTWAIT:
173         case SMC_CLOSED:                          145         case SMC_CLOSED:
174                 break;                            146                 break;
175         }                                         147         }
176                                                   148 
177         smc_sock_set_flag(sk, SOCK_DEAD);      !! 149         sock_set_flag(sk, SOCK_DEAD);
178         sk->sk_state_change(sk);                  150         sk->sk_state_change(sk);
179                                                << 
180         if (release_clcsock) {                 << 
181                 release_sock(sk);              << 
182                 smc_clcsock_release(smc);      << 
183                 lock_sock(sk);                 << 
184         }                                      << 
185 }                                                 151 }
186                                                   152 
187 static inline bool smc_close_sent_any_close(st    153 static inline bool smc_close_sent_any_close(struct smc_connection *conn)
188 {                                                 154 {
189         return conn->local_tx_ctrl.conn_state_    155         return conn->local_tx_ctrl.conn_state_flags.peer_conn_abort ||
190                conn->local_tx_ctrl.conn_state_    156                conn->local_tx_ctrl.conn_state_flags.peer_conn_closed;
191 }                                                 157 }
192                                                   158 
193 int smc_close_active(struct smc_sock *smc)        159 int smc_close_active(struct smc_sock *smc)
194 {                                                 160 {
195         struct smc_cdc_conn_state_flags *txfla    161         struct smc_cdc_conn_state_flags *txflags =
196                 &smc->conn.local_tx_ctrl.conn_    162                 &smc->conn.local_tx_ctrl.conn_state_flags;
197         struct smc_connection *conn = &smc->co    163         struct smc_connection *conn = &smc->conn;
198         struct sock *sk = &smc->sk;               164         struct sock *sk = &smc->sk;
199         int old_state;                            165         int old_state;
200         long timeout;                             166         long timeout;
201         int rc = 0;                               167         int rc = 0;
202         int rc1 = 0;                           << 
203                                                   168 
204         timeout = current->flags & PF_EXITING     169         timeout = current->flags & PF_EXITING ?
205                   0 : sock_flag(sk, SOCK_LINGE    170                   0 : sock_flag(sk, SOCK_LINGER) ?
206                       sk->sk_lingertime : SMC_    171                       sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
207                                                   172 
208         old_state = sk->sk_state;                 173         old_state = sk->sk_state;
209 again:                                            174 again:
210         switch (sk->sk_state) {                   175         switch (sk->sk_state) {
211         case SMC_INIT:                            176         case SMC_INIT:
212                 sk->sk_state = SMC_CLOSED;        177                 sk->sk_state = SMC_CLOSED;
213                 break;                            178                 break;
214         case SMC_LISTEN:                          179         case SMC_LISTEN:
215                 sk->sk_state = SMC_CLOSED;        180                 sk->sk_state = SMC_CLOSED;
216                 sk->sk_state_change(sk); /* wa    181                 sk->sk_state_change(sk); /* wake up accept */
217                 if (smc->clcsock && smc->clcso    182                 if (smc->clcsock && smc->clcsock->sk) {
218                         write_lock_bh(&smc->cl << 
219                         smc_clcsock_restore_cb << 
220                                                << 
221                         smc->clcsock->sk->sk_u << 
222                         write_unlock_bh(&smc-> << 
223                         rc = kernel_sock_shutd    183                         rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR);
                                                   >> 184                         /* wake up kernel_accept of smc_tcp_listen_worker */
                                                   >> 185                         smc->clcsock->sk->sk_data_ready(smc->clcsock->sk);
224                 }                                 186                 }
225                 smc_close_cleanup_listen(sk);     187                 smc_close_cleanup_listen(sk);
226                 release_sock(sk);                 188                 release_sock(sk);
227                 flush_work(&smc->tcp_listen_wo    189                 flush_work(&smc->tcp_listen_work);
228                 lock_sock(sk);                    190                 lock_sock(sk);
229                 break;                            191                 break;
230         case SMC_ACTIVE:                          192         case SMC_ACTIVE:
231                 smc_close_stream_wait(smc, tim    193                 smc_close_stream_wait(smc, timeout);
232                 release_sock(sk);                 194                 release_sock(sk);
233                 cancel_delayed_work_sync(&conn    195                 cancel_delayed_work_sync(&conn->tx_work);
234                 lock_sock(sk);                    196                 lock_sock(sk);
235                 if (sk->sk_state == SMC_ACTIVE    197                 if (sk->sk_state == SMC_ACTIVE) {
236                         /* send close request     198                         /* send close request */
237                         rc = smc_close_final(c    199                         rc = smc_close_final(conn);
                                                   >> 200                         if (rc)
                                                   >> 201                                 break;
238                         sk->sk_state = SMC_PEE    202                         sk->sk_state = SMC_PEERCLOSEWAIT1;
239                                                << 
240                         /* actively shutdown c << 
241                          * prevent peer from e << 
242                          */                    << 
243                         if (smc->clcsock && sm << 
244                                 rc1 = kernel_s << 
245                                                << 
246                                 rc = rc ? rc : << 
247                         }                      << 
248                 } else {                          203                 } else {
249                         /* peer event has chan    204                         /* peer event has changed the state */
250                         goto again;               205                         goto again;
251                 }                                 206                 }
252                 break;                            207                 break;
253         case SMC_APPFINCLOSEWAIT:                 208         case SMC_APPFINCLOSEWAIT:
254                 /* socket already shutdown wr     209                 /* socket already shutdown wr or both (active close) */
255                 if (txflags->peer_done_writing    210                 if (txflags->peer_done_writing &&
256                     !smc_close_sent_any_close(    211                     !smc_close_sent_any_close(conn)) {
257                         /* just shutdown wr do    212                         /* just shutdown wr done, send close request */
258                         rc = smc_close_final(c    213                         rc = smc_close_final(conn);
                                                   >> 214                         if (rc)
                                                   >> 215                                 break;
259                 }                                 216                 }
260                 sk->sk_state = SMC_CLOSED;        217                 sk->sk_state = SMC_CLOSED;
261                 break;                            218                 break;
262         case SMC_APPCLOSEWAIT1:                   219         case SMC_APPCLOSEWAIT1:
263         case SMC_APPCLOSEWAIT2:                   220         case SMC_APPCLOSEWAIT2:
264                 if (!smc_cdc_rxed_any_close(co    221                 if (!smc_cdc_rxed_any_close(conn))
265                         smc_close_stream_wait(    222                         smc_close_stream_wait(smc, timeout);
266                 release_sock(sk);                 223                 release_sock(sk);
267                 cancel_delayed_work_sync(&conn    224                 cancel_delayed_work_sync(&conn->tx_work);
268                 lock_sock(sk);                    225                 lock_sock(sk);
269                 if (sk->sk_state != SMC_APPCLO    226                 if (sk->sk_state != SMC_APPCLOSEWAIT1 &&
270                     sk->sk_state != SMC_APPCLO    227                     sk->sk_state != SMC_APPCLOSEWAIT2)
271                         goto again;               228                         goto again;
272                 /* confirm close from peer */     229                 /* confirm close from peer */
273                 rc = smc_close_final(conn);       230                 rc = smc_close_final(conn);
                                                   >> 231                 if (rc)
                                                   >> 232                         break;
274                 if (smc_cdc_rxed_any_close(con    233                 if (smc_cdc_rxed_any_close(conn)) {
275                         /* peer has closed the    234                         /* peer has closed the socket already */
276                         sk->sk_state = SMC_CLO    235                         sk->sk_state = SMC_CLOSED;
277                         sock_put(sk); /* postp    236                         sock_put(sk); /* postponed passive closing */
278                 } else {                          237                 } else {
279                         /* peer has just issue    238                         /* peer has just issued a shutdown write */
280                         sk->sk_state = SMC_PEE    239                         sk->sk_state = SMC_PEERFINCLOSEWAIT;
281                 }                                 240                 }
282                 break;                            241                 break;
283         case SMC_PEERCLOSEWAIT1:                  242         case SMC_PEERCLOSEWAIT1:
284         case SMC_PEERCLOSEWAIT2:                  243         case SMC_PEERCLOSEWAIT2:
285                 if (txflags->peer_done_writing    244                 if (txflags->peer_done_writing &&
286                     !smc_close_sent_any_close(    245                     !smc_close_sent_any_close(conn)) {
287                         /* just shutdown wr do    246                         /* just shutdown wr done, send close request */
288                         rc = smc_close_final(c    247                         rc = smc_close_final(conn);
                                                   >> 248                         if (rc)
                                                   >> 249                                 break;
289                 }                                 250                 }
290                 /* peer sending PeerConnection    251                 /* peer sending PeerConnectionClosed will cause transition */
291                 break;                            252                 break;
292         case SMC_PEERFINCLOSEWAIT:                253         case SMC_PEERFINCLOSEWAIT:
293                 /* peer sending PeerConnection    254                 /* peer sending PeerConnectionClosed will cause transition */
294                 break;                            255                 break;
295         case SMC_PROCESSABORT:                    256         case SMC_PROCESSABORT:
296                 rc = smc_close_abort(conn);    !! 257                 smc_close_abort(conn);
297                 sk->sk_state = SMC_CLOSED;        258                 sk->sk_state = SMC_CLOSED;
298                 break;                            259                 break;
299         case SMC_PEERABORTWAIT:                   260         case SMC_PEERABORTWAIT:
300                 sk->sk_state = SMC_CLOSED;     << 
301                 break;                         << 
302         case SMC_CLOSED:                          261         case SMC_CLOSED:
303                 /* nothing to do, add tracing     262                 /* nothing to do, add tracing in future patch */
304                 break;                            263                 break;
305         }                                         264         }
306                                                   265 
307         if (old_state != sk->sk_state)            266         if (old_state != sk->sk_state)
308                 sk->sk_state_change(sk);          267                 sk->sk_state_change(sk);
309         return rc;                                268         return rc;
310 }                                                 269 }
311                                                   270 
312 static void smc_close_passive_abort_received(s    271 static void smc_close_passive_abort_received(struct smc_sock *smc)
313 {                                                 272 {
314         struct smc_cdc_conn_state_flags *txfla    273         struct smc_cdc_conn_state_flags *txflags =
315                 &smc->conn.local_tx_ctrl.conn_    274                 &smc->conn.local_tx_ctrl.conn_state_flags;
316         struct sock *sk = &smc->sk;               275         struct sock *sk = &smc->sk;
317                                                   276 
318         switch (sk->sk_state) {                   277         switch (sk->sk_state) {
319         case SMC_INIT:                            278         case SMC_INIT:
320         case SMC_ACTIVE:                          279         case SMC_ACTIVE:
321         case SMC_APPCLOSEWAIT1:                   280         case SMC_APPCLOSEWAIT1:
322                 sk->sk_state = SMC_PROCESSABOR    281                 sk->sk_state = SMC_PROCESSABORT;
323                 sock_put(sk); /* passive closi    282                 sock_put(sk); /* passive closing */
324                 break;                            283                 break;
325         case SMC_APPFINCLOSEWAIT:                 284         case SMC_APPFINCLOSEWAIT:
326                 sk->sk_state = SMC_PROCESSABOR    285                 sk->sk_state = SMC_PROCESSABORT;
327                 break;                            286                 break;
328         case SMC_PEERCLOSEWAIT1:                  287         case SMC_PEERCLOSEWAIT1:
329         case SMC_PEERCLOSEWAIT2:                  288         case SMC_PEERCLOSEWAIT2:
330                 if (txflags->peer_done_writing    289                 if (txflags->peer_done_writing &&
331                     !smc_close_sent_any_close(    290                     !smc_close_sent_any_close(&smc->conn))
332                         /* just shutdown, but     291                         /* just shutdown, but not yet closed locally */
333                         sk->sk_state = SMC_PRO    292                         sk->sk_state = SMC_PROCESSABORT;
334                 else                              293                 else
335                         sk->sk_state = SMC_CLO    294                         sk->sk_state = SMC_CLOSED;
336                 sock_put(sk); /* passive closi    295                 sock_put(sk); /* passive closing */
337                 break;                            296                 break;
338         case SMC_APPCLOSEWAIT2:                   297         case SMC_APPCLOSEWAIT2:
339         case SMC_PEERFINCLOSEWAIT:                298         case SMC_PEERFINCLOSEWAIT:
340                 sk->sk_state = SMC_CLOSED;        299                 sk->sk_state = SMC_CLOSED;
341                 sock_put(sk); /* passive closi    300                 sock_put(sk); /* passive closing */
342                 break;                            301                 break;
343         case SMC_PEERABORTWAIT:                   302         case SMC_PEERABORTWAIT:
344                 sk->sk_state = SMC_CLOSED;        303                 sk->sk_state = SMC_CLOSED;
345                 break;                            304                 break;
346         case SMC_PROCESSABORT:                    305         case SMC_PROCESSABORT:
347         /* nothing to do, add tracing in futur    306         /* nothing to do, add tracing in future patch */
348                 break;                            307                 break;
349         }                                         308         }
350 }                                                 309 }
351                                                   310 
352 /* Either some kind of closing has been receiv    311 /* Either some kind of closing has been received: peer_conn_closed,
353  * peer_conn_abort, or peer_done_writing          312  * peer_conn_abort, or peer_done_writing
354  * or the link group of the connection termina    313  * or the link group of the connection terminates abnormally.
355  */                                               314  */
356 static void smc_close_passive_work(struct work    315 static void smc_close_passive_work(struct work_struct *work)
357 {                                                 316 {
358         struct smc_connection *conn = containe    317         struct smc_connection *conn = container_of(work,
359                                                   318                                                    struct smc_connection,
360                                                   319                                                    close_work);
361         struct smc_sock *smc = container_of(co    320         struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
362         struct smc_cdc_conn_state_flags *rxfla    321         struct smc_cdc_conn_state_flags *rxflags;
363         bool release_clcsock = false;          << 
364         struct sock *sk = &smc->sk;               322         struct sock *sk = &smc->sk;
365         int old_state;                            323         int old_state;
366                                                   324 
367         lock_sock(sk);                            325         lock_sock(sk);
368         old_state = sk->sk_state;                 326         old_state = sk->sk_state;
369                                                   327 
                                                   >> 328         if (!conn->alert_token_local) {
                                                   >> 329                 /* abnormal termination */
                                                   >> 330                 smc_close_active_abort(smc);
                                                   >> 331                 goto wakeup;
                                                   >> 332         }
                                                   >> 333 
370         rxflags = &conn->local_rx_ctrl.conn_st    334         rxflags = &conn->local_rx_ctrl.conn_state_flags;
371         if (rxflags->peer_conn_abort) {           335         if (rxflags->peer_conn_abort) {
372                 /* peer has not received all d    336                 /* peer has not received all data */
373                 smc_close_passive_abort_receiv    337                 smc_close_passive_abort_received(smc);
374                 release_sock(sk);              !! 338                 release_sock(&smc->sk);
375                 cancel_delayed_work_sync(&conn    339                 cancel_delayed_work_sync(&conn->tx_work);
376                 lock_sock(sk);                 !! 340                 lock_sock(&smc->sk);
377                 goto wakeup;                      341                 goto wakeup;
378         }                                         342         }
379                                                   343 
380         switch (sk->sk_state) {                   344         switch (sk->sk_state) {
381         case SMC_INIT:                            345         case SMC_INIT:
382                 sk->sk_state = SMC_APPCLOSEWAI !! 346                 if (atomic_read(&conn->bytes_to_rcv) ||
                                                   >> 347                     (rxflags->peer_done_writing &&
                                                   >> 348                      !smc_cdc_rxed_any_close(conn))) {
                                                   >> 349                         sk->sk_state = SMC_APPCLOSEWAIT1;
                                                   >> 350                 } else {
                                                   >> 351                         sk->sk_state = SMC_CLOSED;
                                                   >> 352                         sock_put(sk); /* passive closing */
                                                   >> 353                 }
383                 break;                            354                 break;
384         case SMC_ACTIVE:                          355         case SMC_ACTIVE:
385                 sk->sk_state = SMC_APPCLOSEWAI    356                 sk->sk_state = SMC_APPCLOSEWAIT1;
386                 /* postpone sock_put() for pas    357                 /* postpone sock_put() for passive closing to cover
387                  * received SEND_SHUTDOWN as w    358                  * received SEND_SHUTDOWN as well
388                  */                               359                  */
389                 break;                            360                 break;
390         case SMC_PEERCLOSEWAIT1:                  361         case SMC_PEERCLOSEWAIT1:
391                 if (rxflags->peer_done_writing    362                 if (rxflags->peer_done_writing)
392                         sk->sk_state = SMC_PEE    363                         sk->sk_state = SMC_PEERCLOSEWAIT2;
393                 fallthrough;                   !! 364                 /* fall through */
394                 /* to check for closing */        365                 /* to check for closing */
395         case SMC_PEERCLOSEWAIT2:                  366         case SMC_PEERCLOSEWAIT2:
396                 if (!smc_cdc_rxed_any_close(co    367                 if (!smc_cdc_rxed_any_close(conn))
397                         break;                    368                         break;
398                 if (sock_flag(sk, SOCK_DEAD) &    369                 if (sock_flag(sk, SOCK_DEAD) &&
399                     smc_close_sent_any_close(c    370                     smc_close_sent_any_close(conn)) {
400                         /* smc_release has alr    371                         /* smc_release has already been called locally */
401                         sk->sk_state = SMC_CLO    372                         sk->sk_state = SMC_CLOSED;
402                 } else {                          373                 } else {
403                         /* just shutdown, but     374                         /* just shutdown, but not yet closed locally */
404                         sk->sk_state = SMC_APP    375                         sk->sk_state = SMC_APPFINCLOSEWAIT;
405                 }                                 376                 }
406                 sock_put(sk); /* passive closi    377                 sock_put(sk); /* passive closing */
407                 break;                            378                 break;
408         case SMC_PEERFINCLOSEWAIT:                379         case SMC_PEERFINCLOSEWAIT:
409                 if (smc_cdc_rxed_any_close(con    380                 if (smc_cdc_rxed_any_close(conn)) {
410                         sk->sk_state = SMC_CLO    381                         sk->sk_state = SMC_CLOSED;
411                         sock_put(sk); /* passi    382                         sock_put(sk); /* passive closing */
412                 }                                 383                 }
413                 break;                            384                 break;
414         case SMC_APPCLOSEWAIT1:                   385         case SMC_APPCLOSEWAIT1:
415         case SMC_APPCLOSEWAIT2:                   386         case SMC_APPCLOSEWAIT2:
416                 /* postpone sock_put() for pas    387                 /* postpone sock_put() for passive closing to cover
417                  * received SEND_SHUTDOWN as w    388                  * received SEND_SHUTDOWN as well
418                  */                               389                  */
419                 break;                            390                 break;
420         case SMC_APPFINCLOSEWAIT:                 391         case SMC_APPFINCLOSEWAIT:
421         case SMC_PEERABORTWAIT:                   392         case SMC_PEERABORTWAIT:
422         case SMC_PROCESSABORT:                    393         case SMC_PROCESSABORT:
423         case SMC_CLOSED:                          394         case SMC_CLOSED:
424                 /* nothing to do, add tracing     395                 /* nothing to do, add tracing in future patch */
425                 break;                            396                 break;
426         }                                         397         }
427                                                   398 
428 wakeup:                                           399 wakeup:
429         sk->sk_data_ready(sk); /* wakeup block    400         sk->sk_data_ready(sk); /* wakeup blocked rcvbuf consumers */
430         sk->sk_write_space(sk); /* wakeup bloc    401         sk->sk_write_space(sk); /* wakeup blocked sndbuf producers */
431                                                   402 
432         if (old_state != sk->sk_state) {          403         if (old_state != sk->sk_state) {
433                 sk->sk_state_change(sk);          404                 sk->sk_state_change(sk);
434                 if ((sk->sk_state == SMC_CLOSE    405                 if ((sk->sk_state == SMC_CLOSED) &&
435                     (sock_flag(sk, SOCK_DEAD)  !! 406                     (sock_flag(sk, SOCK_DEAD) || !sk->sk_socket))
436                         smc_conn_free(conn);      407                         smc_conn_free(conn);
437                         if (smc->clcsock)      << 
438                                 release_clcsoc << 
439                 }                              << 
440         }                                         408         }
441         release_sock(sk);                         409         release_sock(sk);
442         if (release_clcsock)                   << 
443                 smc_clcsock_release(smc);      << 
444         sock_put(sk); /* sock_hold done by sch    410         sock_put(sk); /* sock_hold done by schedulers of close_work */
445 }                                                 411 }
446                                                   412 
447 int smc_close_shutdown_write(struct smc_sock *    413 int smc_close_shutdown_write(struct smc_sock *smc)
448 {                                                 414 {
449         struct smc_connection *conn = &smc->co    415         struct smc_connection *conn = &smc->conn;
450         struct sock *sk = &smc->sk;               416         struct sock *sk = &smc->sk;
451         int old_state;                            417         int old_state;
452         long timeout;                             418         long timeout;
453         int rc = 0;                               419         int rc = 0;
454                                                   420 
455         timeout = current->flags & PF_EXITING     421         timeout = current->flags & PF_EXITING ?
456                   0 : sock_flag(sk, SOCK_LINGE    422                   0 : sock_flag(sk, SOCK_LINGER) ?
457                       sk->sk_lingertime : SMC_    423                       sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
458                                                   424 
459         old_state = sk->sk_state;                 425         old_state = sk->sk_state;
460 again:                                            426 again:
461         switch (sk->sk_state) {                   427         switch (sk->sk_state) {
462         case SMC_ACTIVE:                          428         case SMC_ACTIVE:
463                 smc_close_stream_wait(smc, tim    429                 smc_close_stream_wait(smc, timeout);
464                 release_sock(sk);                 430                 release_sock(sk);
465                 cancel_delayed_work_sync(&conn    431                 cancel_delayed_work_sync(&conn->tx_work);
466                 lock_sock(sk);                    432                 lock_sock(sk);
467                 if (sk->sk_state != SMC_ACTIVE    433                 if (sk->sk_state != SMC_ACTIVE)
468                         goto again;               434                         goto again;
469                 /* send close wr request */       435                 /* send close wr request */
470                 rc = smc_close_wr(conn);          436                 rc = smc_close_wr(conn);
                                                   >> 437                 if (rc)
                                                   >> 438                         break;
471                 sk->sk_state = SMC_PEERCLOSEWA    439                 sk->sk_state = SMC_PEERCLOSEWAIT1;
472                 break;                            440                 break;
473         case SMC_APPCLOSEWAIT1:                   441         case SMC_APPCLOSEWAIT1:
474                 /* passive close */               442                 /* passive close */
475                 if (!smc_cdc_rxed_any_close(co    443                 if (!smc_cdc_rxed_any_close(conn))
476                         smc_close_stream_wait(    444                         smc_close_stream_wait(smc, timeout);
477                 release_sock(sk);                 445                 release_sock(sk);
478                 cancel_delayed_work_sync(&conn    446                 cancel_delayed_work_sync(&conn->tx_work);
479                 lock_sock(sk);                    447                 lock_sock(sk);
480                 if (sk->sk_state != SMC_APPCLO    448                 if (sk->sk_state != SMC_APPCLOSEWAIT1)
481                         goto again;               449                         goto again;
482                 /* confirm close from peer */     450                 /* confirm close from peer */
483                 rc = smc_close_wr(conn);          451                 rc = smc_close_wr(conn);
                                                   >> 452                 if (rc)
                                                   >> 453                         break;
484                 sk->sk_state = SMC_APPCLOSEWAI    454                 sk->sk_state = SMC_APPCLOSEWAIT2;
485                 break;                            455                 break;
486         case SMC_APPCLOSEWAIT2:                   456         case SMC_APPCLOSEWAIT2:
487         case SMC_PEERFINCLOSEWAIT:                457         case SMC_PEERFINCLOSEWAIT:
488         case SMC_PEERCLOSEWAIT1:                  458         case SMC_PEERCLOSEWAIT1:
489         case SMC_PEERCLOSEWAIT2:                  459         case SMC_PEERCLOSEWAIT2:
490         case SMC_APPFINCLOSEWAIT:                 460         case SMC_APPFINCLOSEWAIT:
491         case SMC_PROCESSABORT:                    461         case SMC_PROCESSABORT:
492         case SMC_PEERABORTWAIT:                   462         case SMC_PEERABORTWAIT:
493                 /* nothing to do, add tracing     463                 /* nothing to do, add tracing in future patch */
494                 break;                            464                 break;
495         }                                         465         }
496                                                   466 
497         if (old_state != sk->sk_state)            467         if (old_state != sk->sk_state)
498                 sk->sk_state_change(sk);          468                 sk->sk_state_change(sk);
499         return rc;                                469         return rc;
500 }                                                 470 }
501                                                   471 
502 /* Initialize close properties on connection e    472 /* Initialize close properties on connection establishment. */
503 void smc_close_init(struct smc_sock *smc)         473 void smc_close_init(struct smc_sock *smc)
504 {                                                 474 {
505         INIT_WORK(&smc->conn.close_work, smc_c    475         INIT_WORK(&smc->conn.close_work, smc_close_passive_work);
506 }                                                 476 }
507                                                   477 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

sflogo.php