License cleanup: add SPDX GPL-2.0 license identifier to files with no license
Many source files in the tree are missing licensing information, which
makes it harder for compliance tools to determine the correct license.
By default all files without license information are under the default
license of the kernel, which is GPL version 2.
Update the files which contain no license information with the 'GPL-2.0'
SPDX license identifier. The SPDX identifier is a legally binding
shorthand, which can be used instead of the full boiler plate text.
This patch is based on work done by Thomas Gleixner and Kate Stewart and
Philippe Ombredanne.
How this work was done:
Patches were generated and checked against linux-4.14-rc6 for a subset of
the use cases:
- file had no licensing information it it.
- file was a */uapi/* one with no licensing information in it,
- file was a */uapi/* one with existing licensing information,
Further patches will be generated in subsequent months to fix up cases
where non-standard license headers were used, and references to license
had to be inferred by heuristics based on keywords.
The analysis to determine which SPDX License Identifier to be applied to
a file was done in a spreadsheet of side by side results from of the
output of two independent scanners (ScanCode & Windriver) producing SPDX
tag:value files created by Philippe Ombredanne. Philippe prepared the
base worksheet, and did an initial spot review of a few 1000 files.
The 4.13 kernel was the starting point of the analysis with 60,537 files
assessed. Kate Stewart did a file by file comparison of the scanner
results in the spreadsheet to determine which SPDX license identifier(s)
to be applied to the file. She confirmed any determination that was not
immediately clear with lawyers working with the Linux Foundation.
Criteria used to select files for SPDX license identifier tagging was:
- Files considered eligible had to be source code files.
- Make and config files were included as candidates if they contained >5
lines of source
- File already had some variant of a license header in it (even if <5
lines).
All documentation files were explicitly excluded.
The following heuristics were used to determine which SPDX license
identifiers to apply.
- when both scanners couldn't find any license traces, file was
considered to have no license information in it, and the top level
COPYING file license applied.
For non */uapi/* files that summary was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 11139
and resulted in the first patch in this series.
If that file was a */uapi/* path one, it was "GPL-2.0 WITH
Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was:
SPDX license identifier # files
---------------------------------------------------|-------
GPL-2.0 WITH Linux-syscall-note 930
and resulted in the second patch in this series.
- if a file had some form of licensing information in it, and was one
of the */uapi/* ones, it was denoted with the Linux-syscall-note if
any GPL family license was found in the file or had no licensing in
it (per prior point). Results summary:
SPDX license identifier # files
---------------------------------------------------|------
GPL-2.0 WITH Linux-syscall-note 270
GPL-2.0+ WITH Linux-syscall-note 169
((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21
((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17
LGPL-2.1+ WITH Linux-syscall-note 15
GPL-1.0+ WITH Linux-syscall-note 14
((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5
LGPL-2.0+ WITH Linux-syscall-note 4
LGPL-2.1 WITH Linux-syscall-note 3
((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3
((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1
and that resulted in the third patch in this series.
- when the two scanners agreed on the detected license(s), that became
the concluded license(s).
- when there was disagreement between the two scanners (one detected a
license but the other didn't, or they both detected different
licenses) a manual inspection of the file occurred.
- In most cases a manual inspection of the information in the file
resulted in a clear resolution of the license that should apply (and
which scanner probably needed to revisit its heuristics).
- When it was not immediately clear, the license identifier was
confirmed with lawyers working with the Linux Foundation.
- If there was any question as to the appropriate license identifier,
the file was flagged for further research and to be revisited later
in time.
In total, over 70 hours of logged manual review was done on the
spreadsheet to determine the SPDX license identifiers to apply to the
source files by Kate, Philippe, Thomas and, in some cases, confirmation
by lawyers working with the Linux Foundation.
Kate also obtained a third independent scan of the 4.13 code base from
FOSSology, and compared selected files where the other two scanners
disagreed against that SPDX file, to see if there was new insights. The
Windriver scanner is based on an older version of FOSSology in part, so
they are related.
Thomas did random spot checks in about 500 files from the spreadsheets
for the uapi headers and agreed with SPDX license identifier in the
files he inspected. For the non-uapi files Thomas did random spot checks
in about 15000 files.
In initial set of patches against 4.14-rc6, 3 files were found to have
copy/paste license identifier errors, and have been fixed to reflect the
correct identifier.
Additionally Philippe spent 10 hours this week doing a detailed manual
inspection and review of the 12,461 patched files from the initial patch
version early this week with:
- a full scancode scan run, collecting the matched texts, detected
license ids and scores
- reviewing anything where there was a license detected (about 500+
files) to ensure that the applied SPDX license was correct
- reviewing anything where there was no detection but the patch license
was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied
SPDX license was correct
This produced a worksheet with 20 files needing minor correction. This
worksheet was then exported into 3 different .csv files for the
different types of files to be modified.
These .csv files were then reviewed by Greg. Thomas wrote a script to
parse the csv files and add the proper SPDX tag to the file, in the
format that the file expected. This script was further refined by Greg
based on the output to detect more types of files automatically and to
distinguish between header and source .c files (which need different
comment types.) Finally Greg ran the script using the .csv files to
generate the patches.
Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org>
Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com>
Reviewed-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 22:07:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-01-09 23:55:25 +08:00
|
|
|
/*
|
|
|
|
* Shared Memory Communications over RDMA (SMC-R) and RoCE
|
|
|
|
*
|
|
|
|
* Socket Closing - normal and abnormal
|
|
|
|
*
|
|
|
|
* Copyright IBM Corp. 2016
|
|
|
|
*
|
|
|
|
* Author(s): Ursula Braun <ubraun@linux.vnet.ibm.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/workqueue.h>
|
2017-02-02 15:35:14 +08:00
|
|
|
#include <linux/sched/signal.h>
|
|
|
|
|
2017-01-09 23:55:25 +08:00
|
|
|
#include <net/sock.h>
|
2019-10-21 22:13:12 +08:00
|
|
|
#include <net/tcp.h>
|
2017-01-09 23:55:25 +08:00
|
|
|
|
|
|
|
#include "smc.h"
|
|
|
|
#include "smc_tx.h"
|
|
|
|
#include "smc_cdc.h"
|
|
|
|
#include "smc_close.h"
|
|
|
|
|
2019-04-11 17:17:30 +08:00
|
|
|
/* release the clcsock that is assigned to the smc_sock */
|
|
|
|
void smc_clcsock_release(struct smc_sock *smc)
|
|
|
|
{
|
|
|
|
struct socket *tcp;
|
|
|
|
|
|
|
|
if (smc->listen_smc && current_work() != &smc->smc_listen_work)
|
|
|
|
cancel_work_sync(&smc->smc_listen_work);
|
|
|
|
mutex_lock(&smc->clcsock_release_lock);
|
|
|
|
if (smc->clcsock) {
|
|
|
|
tcp = smc->clcsock;
|
|
|
|
smc->clcsock = NULL;
|
|
|
|
sock_release(tcp);
|
|
|
|
}
|
|
|
|
mutex_unlock(&smc->clcsock_release_lock);
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:25 +08:00
|
|
|
static void smc_close_cleanup_listen(struct sock *parent)
|
|
|
|
{
|
|
|
|
struct sock *sk;
|
|
|
|
|
|
|
|
/* Close non-accepted connections */
|
|
|
|
while ((sk = smc_accept_dequeue(parent, NULL)))
|
|
|
|
smc_close_non_accepted(sk);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait for sndbuf data being transmitted */
|
|
|
|
static void smc_close_stream_wait(struct smc_sock *smc, long timeout)
|
|
|
|
{
|
|
|
|
DEFINE_WAIT_FUNC(wait, woken_wake_function);
|
|
|
|
struct sock *sk = &smc->sk;
|
|
|
|
|
|
|
|
if (!timeout)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!smc_tx_prepared_sends(&smc->conn))
|
|
|
|
return;
|
|
|
|
|
|
|
|
smc->wait_close_tx_prepared = 1;
|
|
|
|
add_wait_queue(sk_sleep(sk), &wait);
|
|
|
|
while (!signal_pending(current) && timeout) {
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = sk_wait_event(sk, &timeout,
|
|
|
|
!smc_tx_prepared_sends(&smc->conn) ||
|
2019-10-09 16:07:47 +08:00
|
|
|
sk->sk_err == ECONNABORTED ||
|
2019-10-21 22:13:08 +08:00
|
|
|
sk->sk_err == ECONNRESET ||
|
|
|
|
smc->conn.killed,
|
2017-01-09 23:55:25 +08:00
|
|
|
&wait);
|
|
|
|
if (rc)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
remove_wait_queue(sk_sleep(sk), &wait);
|
|
|
|
smc->wait_close_tx_prepared = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void smc_close_wake_tx_prepared(struct smc_sock *smc)
|
|
|
|
{
|
|
|
|
if (smc->wait_close_tx_prepared)
|
|
|
|
/* wake up socket closing */
|
|
|
|
smc->sk.sk_state_change(&smc->sk);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smc_close_wr(struct smc_connection *conn)
|
|
|
|
{
|
|
|
|
conn->local_tx_ctrl.conn_state_flags.peer_done_writing = 1;
|
|
|
|
|
|
|
|
return smc_cdc_get_slot_and_msg_send(conn);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int smc_close_final(struct smc_connection *conn)
|
|
|
|
{
|
|
|
|
if (atomic_read(&conn->bytes_to_rcv))
|
|
|
|
conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1;
|
|
|
|
else
|
|
|
|
conn->local_tx_ctrl.conn_state_flags.peer_conn_closed = 1;
|
2019-10-21 22:13:08 +08:00
|
|
|
if (conn->killed)
|
|
|
|
return -EPIPE;
|
2017-01-09 23:55:25 +08:00
|
|
|
|
|
|
|
return smc_cdc_get_slot_and_msg_send(conn);
|
|
|
|
}
|
|
|
|
|
2019-10-21 22:13:12 +08:00
|
|
|
int smc_close_abort(struct smc_connection *conn)
|
2017-01-09 23:55:25 +08:00
|
|
|
{
|
|
|
|
conn->local_tx_ctrl.conn_state_flags.peer_conn_abort = 1;
|
|
|
|
|
|
|
|
return smc_cdc_get_slot_and_msg_send(conn);
|
|
|
|
}
|
|
|
|
|
2019-11-14 20:02:41 +08:00
|
|
|
static void smc_close_cancel_work(struct smc_sock *smc)
|
|
|
|
{
|
|
|
|
struct sock *sk = &smc->sk;
|
|
|
|
|
|
|
|
release_sock(sk);
|
|
|
|
cancel_work_sync(&smc->conn.close_work);
|
|
|
|
cancel_delayed_work_sync(&smc->conn.tx_work);
|
|
|
|
lock_sock(sk);
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:25 +08:00
|
|
|
/* terminate smc socket abnormally - active abort
|
2018-01-25 18:15:35 +08:00
|
|
|
* link group is terminated, i.e. RDMA communication no longer possible
|
2017-01-09 23:55:25 +08:00
|
|
|
*/
|
2019-10-21 22:13:15 +08:00
|
|
|
void smc_close_active_abort(struct smc_sock *smc)
|
2017-01-09 23:55:25 +08:00
|
|
|
{
|
2018-01-24 17:28:12 +08:00
|
|
|
struct sock *sk = &smc->sk;
|
2019-10-21 22:13:15 +08:00
|
|
|
bool release_clcsock = false;
|
2018-01-24 17:28:12 +08:00
|
|
|
|
2018-09-18 21:46:36 +08:00
|
|
|
if (sk->sk_state != SMC_INIT && smc->clcsock && smc->clcsock->sk) {
|
|
|
|
sk->sk_err = ECONNABORTED;
|
2019-10-21 22:13:12 +08:00
|
|
|
if (smc->clcsock && smc->clcsock->sk)
|
|
|
|
tcp_abort(smc->clcsock->sk, ECONNABORTED);
|
2017-01-09 23:55:25 +08:00
|
|
|
}
|
2018-01-24 17:28:12 +08:00
|
|
|
switch (sk->sk_state) {
|
2017-04-10 20:58:01 +08:00
|
|
|
case SMC_ACTIVE:
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_APPCLOSEWAIT1:
|
|
|
|
case SMC_APPCLOSEWAIT2:
|
2020-09-04 03:53:18 +08:00
|
|
|
sk->sk_state = SMC_PEERABORTWAIT;
|
2019-11-14 20:02:41 +08:00
|
|
|
smc_close_cancel_work(smc);
|
2020-09-04 03:53:18 +08:00
|
|
|
if (sk->sk_state != SMC_PEERABORTWAIT)
|
|
|
|
break;
|
2019-10-09 16:07:47 +08:00
|
|
|
sk->sk_state = SMC_CLOSED;
|
2020-09-04 03:53:18 +08:00
|
|
|
sock_put(sk); /* (postponed) passive closing */
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
|
|
|
case SMC_PEERCLOSEWAIT1:
|
|
|
|
case SMC_PEERCLOSEWAIT2:
|
2019-10-09 16:07:47 +08:00
|
|
|
case SMC_PEERFINCLOSEWAIT:
|
2019-11-14 20:02:41 +08:00
|
|
|
sk->sk_state = SMC_PEERABORTWAIT;
|
|
|
|
smc_close_cancel_work(smc);
|
2020-09-04 03:53:18 +08:00
|
|
|
if (sk->sk_state != SMC_PEERABORTWAIT)
|
|
|
|
break;
|
2019-10-09 16:07:47 +08:00
|
|
|
sk->sk_state = SMC_CLOSED;
|
2019-10-21 22:13:15 +08:00
|
|
|
smc_conn_free(&smc->conn);
|
|
|
|
release_clcsock = true;
|
2018-01-26 16:28:48 +08:00
|
|
|
sock_put(sk); /* passive closing */
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
|
|
|
case SMC_PROCESSABORT:
|
|
|
|
case SMC_APPFINCLOSEWAIT:
|
2019-11-14 20:02:41 +08:00
|
|
|
sk->sk_state = SMC_PEERABORTWAIT;
|
|
|
|
smc_close_cancel_work(smc);
|
2020-09-04 03:53:18 +08:00
|
|
|
if (sk->sk_state != SMC_PEERABORTWAIT)
|
|
|
|
break;
|
2018-01-24 17:28:12 +08:00
|
|
|
sk->sk_state = SMC_CLOSED;
|
2019-11-14 20:02:41 +08:00
|
|
|
smc_conn_free(&smc->conn);
|
|
|
|
release_clcsock = true;
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
2018-09-18 21:46:36 +08:00
|
|
|
case SMC_INIT:
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_PEERABORTWAIT:
|
|
|
|
case SMC_CLOSED:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-01-24 17:28:12 +08:00
|
|
|
sock_set_flag(sk, SOCK_DEAD);
|
|
|
|
sk->sk_state_change(sk);
|
2019-10-21 22:13:15 +08:00
|
|
|
|
|
|
|
if (release_clcsock) {
|
|
|
|
release_sock(sk);
|
|
|
|
smc_clcsock_release(smc);
|
|
|
|
lock_sock(sk);
|
|
|
|
}
|
2017-01-09 23:55:25 +08:00
|
|
|
}
|
|
|
|
|
2017-04-10 20:58:02 +08:00
|
|
|
static inline bool smc_close_sent_any_close(struct smc_connection *conn)
|
|
|
|
{
|
|
|
|
return conn->local_tx_ctrl.conn_state_flags.peer_conn_abort ||
|
|
|
|
conn->local_tx_ctrl.conn_state_flags.peer_conn_closed;
|
|
|
|
}
|
|
|
|
|
2017-01-09 23:55:25 +08:00
|
|
|
int smc_close_active(struct smc_sock *smc)
|
|
|
|
{
|
|
|
|
struct smc_cdc_conn_state_flags *txflags =
|
|
|
|
&smc->conn.local_tx_ctrl.conn_state_flags;
|
|
|
|
struct smc_connection *conn = &smc->conn;
|
|
|
|
struct sock *sk = &smc->sk;
|
|
|
|
int old_state;
|
2017-09-21 15:16:34 +08:00
|
|
|
long timeout;
|
2017-01-09 23:55:25 +08:00
|
|
|
int rc = 0;
|
|
|
|
|
2017-09-21 15:16:34 +08:00
|
|
|
timeout = current->flags & PF_EXITING ?
|
|
|
|
0 : sock_flag(sk, SOCK_LINGER) ?
|
|
|
|
sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
|
2017-01-09 23:55:25 +08:00
|
|
|
|
|
|
|
old_state = sk->sk_state;
|
2018-01-24 17:28:16 +08:00
|
|
|
again:
|
|
|
|
switch (sk->sk_state) {
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_INIT:
|
|
|
|
sk->sk_state = SMC_CLOSED;
|
|
|
|
break;
|
|
|
|
case SMC_LISTEN:
|
|
|
|
sk->sk_state = SMC_CLOSED;
|
|
|
|
sk->sk_state_change(sk); /* wake up accept */
|
2020-09-16 04:57:09 +08:00
|
|
|
if (smc->clcsock && smc->clcsock->sk) {
|
|
|
|
smc->clcsock->sk->sk_data_ready = smc->clcsk_data_ready;
|
|
|
|
smc->clcsock->sk->sk_user_data = NULL;
|
2017-01-09 23:55:25 +08:00
|
|
|
rc = kernel_sock_shutdown(smc->clcsock, SHUT_RDWR);
|
2020-09-16 04:57:09 +08:00
|
|
|
}
|
2017-01-09 23:55:25 +08:00
|
|
|
smc_close_cleanup_listen(sk);
|
2018-03-13 17:41:54 +08:00
|
|
|
release_sock(sk);
|
|
|
|
flush_work(&smc->tcp_listen_work);
|
|
|
|
lock_sock(sk);
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
|
|
|
case SMC_ACTIVE:
|
|
|
|
smc_close_stream_wait(smc, timeout);
|
|
|
|
release_sock(sk);
|
2017-09-21 15:16:33 +08:00
|
|
|
cancel_delayed_work_sync(&conn->tx_work);
|
2017-01-09 23:55:25 +08:00
|
|
|
lock_sock(sk);
|
|
|
|
if (sk->sk_state == SMC_ACTIVE) {
|
|
|
|
/* send close request */
|
|
|
|
rc = smc_close_final(conn);
|
|
|
|
sk->sk_state = SMC_PEERCLOSEWAIT1;
|
|
|
|
} else {
|
|
|
|
/* peer event has changed the state */
|
|
|
|
goto again;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SMC_APPFINCLOSEWAIT:
|
|
|
|
/* socket already shutdown wr or both (active close) */
|
|
|
|
if (txflags->peer_done_writing &&
|
2017-04-10 20:58:02 +08:00
|
|
|
!smc_close_sent_any_close(conn)) {
|
2017-01-09 23:55:25 +08:00
|
|
|
/* just shutdown wr done, send close request */
|
|
|
|
rc = smc_close_final(conn);
|
|
|
|
}
|
|
|
|
sk->sk_state = SMC_CLOSED;
|
|
|
|
break;
|
|
|
|
case SMC_APPCLOSEWAIT1:
|
|
|
|
case SMC_APPCLOSEWAIT2:
|
|
|
|
if (!smc_cdc_rxed_any_close(conn))
|
|
|
|
smc_close_stream_wait(smc, timeout);
|
|
|
|
release_sock(sk);
|
2017-09-21 15:16:33 +08:00
|
|
|
cancel_delayed_work_sync(&conn->tx_work);
|
2017-01-09 23:55:25 +08:00
|
|
|
lock_sock(sk);
|
2018-01-24 17:28:16 +08:00
|
|
|
if (sk->sk_state != SMC_APPCLOSEWAIT1 &&
|
|
|
|
sk->sk_state != SMC_APPCLOSEWAIT2)
|
|
|
|
goto again;
|
|
|
|
/* confirm close from peer */
|
|
|
|
rc = smc_close_final(conn);
|
2018-01-26 16:28:48 +08:00
|
|
|
if (smc_cdc_rxed_any_close(conn)) {
|
2017-01-09 23:55:25 +08:00
|
|
|
/* peer has closed the socket already */
|
|
|
|
sk->sk_state = SMC_CLOSED;
|
2018-01-26 16:28:48 +08:00
|
|
|
sock_put(sk); /* postponed passive closing */
|
|
|
|
} else {
|
2017-01-09 23:55:25 +08:00
|
|
|
/* peer has just issued a shutdown write */
|
|
|
|
sk->sk_state = SMC_PEERFINCLOSEWAIT;
|
2018-01-26 16:28:48 +08:00
|
|
|
}
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
|
|
|
case SMC_PEERCLOSEWAIT1:
|
|
|
|
case SMC_PEERCLOSEWAIT2:
|
2017-04-10 20:58:02 +08:00
|
|
|
if (txflags->peer_done_writing &&
|
|
|
|
!smc_close_sent_any_close(conn)) {
|
|
|
|
/* just shutdown wr done, send close request */
|
|
|
|
rc = smc_close_final(conn);
|
|
|
|
}
|
|
|
|
/* peer sending PeerConnectionClosed will cause transition */
|
|
|
|
break;
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_PEERFINCLOSEWAIT:
|
|
|
|
/* peer sending PeerConnectionClosed will cause transition */
|
|
|
|
break;
|
|
|
|
case SMC_PROCESSABORT:
|
2019-10-09 16:07:47 +08:00
|
|
|
rc = smc_close_abort(conn);
|
2017-01-09 23:55:25 +08:00
|
|
|
sk->sk_state = SMC_CLOSED;
|
|
|
|
break;
|
|
|
|
case SMC_PEERABORTWAIT:
|
2019-10-09 16:07:47 +08:00
|
|
|
sk->sk_state = SMC_CLOSED;
|
|
|
|
break;
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_CLOSED:
|
|
|
|
/* nothing to do, add tracing in future patch */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_state != sk->sk_state)
|
2018-01-24 17:28:12 +08:00
|
|
|
sk->sk_state_change(sk);
|
2017-01-09 23:55:25 +08:00
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void smc_close_passive_abort_received(struct smc_sock *smc)
|
|
|
|
{
|
|
|
|
struct smc_cdc_conn_state_flags *txflags =
|
|
|
|
&smc->conn.local_tx_ctrl.conn_state_flags;
|
|
|
|
struct sock *sk = &smc->sk;
|
|
|
|
|
|
|
|
switch (sk->sk_state) {
|
2018-01-26 16:28:48 +08:00
|
|
|
case SMC_INIT:
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_ACTIVE:
|
|
|
|
case SMC_APPCLOSEWAIT1:
|
2018-01-26 16:28:48 +08:00
|
|
|
sk->sk_state = SMC_PROCESSABORT;
|
|
|
|
sock_put(sk); /* passive closing */
|
|
|
|
break;
|
|
|
|
case SMC_APPFINCLOSEWAIT:
|
2017-01-09 23:55:25 +08:00
|
|
|
sk->sk_state = SMC_PROCESSABORT;
|
|
|
|
break;
|
|
|
|
case SMC_PEERCLOSEWAIT1:
|
|
|
|
case SMC_PEERCLOSEWAIT2:
|
|
|
|
if (txflags->peer_done_writing &&
|
2018-01-26 16:28:48 +08:00
|
|
|
!smc_close_sent_any_close(&smc->conn))
|
2017-01-09 23:55:25 +08:00
|
|
|
/* just shutdown, but not yet closed locally */
|
|
|
|
sk->sk_state = SMC_PROCESSABORT;
|
2018-01-26 16:28:48 +08:00
|
|
|
else
|
2017-01-09 23:55:25 +08:00
|
|
|
sk->sk_state = SMC_CLOSED;
|
2018-01-26 16:28:48 +08:00
|
|
|
sock_put(sk); /* passive closing */
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
2018-01-26 16:28:48 +08:00
|
|
|
case SMC_APPCLOSEWAIT2:
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_PEERFINCLOSEWAIT:
|
2018-01-26 16:28:48 +08:00
|
|
|
sk->sk_state = SMC_CLOSED;
|
|
|
|
sock_put(sk); /* passive closing */
|
|
|
|
break;
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_PEERABORTWAIT:
|
|
|
|
sk->sk_state = SMC_CLOSED;
|
|
|
|
break;
|
|
|
|
case SMC_PROCESSABORT:
|
|
|
|
/* nothing to do, add tracing in future patch */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-25 18:15:35 +08:00
|
|
|
/* Either some kind of closing has been received: peer_conn_closed,
|
|
|
|
* peer_conn_abort, or peer_done_writing
|
|
|
|
* or the link group of the connection terminates abnormally.
|
2017-01-09 23:55:25 +08:00
|
|
|
*/
|
2017-04-10 20:58:01 +08:00
|
|
|
static void smc_close_passive_work(struct work_struct *work)
|
2017-01-09 23:55:25 +08:00
|
|
|
{
|
2017-04-10 20:58:01 +08:00
|
|
|
struct smc_connection *conn = container_of(work,
|
|
|
|
struct smc_connection,
|
|
|
|
close_work);
|
|
|
|
struct smc_sock *smc = container_of(conn, struct smc_sock, conn);
|
|
|
|
struct smc_cdc_conn_state_flags *rxflags;
|
2019-04-11 17:17:30 +08:00
|
|
|
bool release_clcsock = false;
|
2017-01-09 23:55:25 +08:00
|
|
|
struct sock *sk = &smc->sk;
|
|
|
|
int old_state;
|
|
|
|
|
2018-01-24 17:28:12 +08:00
|
|
|
lock_sock(sk);
|
2017-01-09 23:55:25 +08:00
|
|
|
old_state = sk->sk_state;
|
|
|
|
|
2018-01-24 17:28:12 +08:00
|
|
|
rxflags = &conn->local_rx_ctrl.conn_state_flags;
|
2017-01-09 23:55:25 +08:00
|
|
|
if (rxflags->peer_conn_abort) {
|
2018-01-25 18:15:35 +08:00
|
|
|
/* peer has not received all data */
|
2017-01-09 23:55:25 +08:00
|
|
|
smc_close_passive_abort_received(smc);
|
2018-01-25 18:15:31 +08:00
|
|
|
release_sock(&smc->sk);
|
|
|
|
cancel_delayed_work_sync(&conn->tx_work);
|
|
|
|
lock_sock(&smc->sk);
|
2017-01-09 23:55:25 +08:00
|
|
|
goto wakeup;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sk->sk_state) {
|
|
|
|
case SMC_INIT:
|
2019-02-04 20:44:47 +08:00
|
|
|
sk->sk_state = SMC_APPCLOSEWAIT1;
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
|
|
|
case SMC_ACTIVE:
|
|
|
|
sk->sk_state = SMC_APPCLOSEWAIT1;
|
2018-01-26 16:28:48 +08:00
|
|
|
/* postpone sock_put() for passive closing to cover
|
|
|
|
* received SEND_SHUTDOWN as well
|
|
|
|
*/
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
|
|
|
case SMC_PEERCLOSEWAIT1:
|
|
|
|
if (rxflags->peer_done_writing)
|
|
|
|
sk->sk_state = SMC_PEERCLOSEWAIT2;
|
2020-08-24 06:36:59 +08:00
|
|
|
fallthrough;
|
2017-10-22 09:35:30 +08:00
|
|
|
/* to check for closing */
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_PEERCLOSEWAIT2:
|
2018-01-24 17:28:12 +08:00
|
|
|
if (!smc_cdc_rxed_any_close(conn))
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
|
|
|
if (sock_flag(sk, SOCK_DEAD) &&
|
2017-04-10 20:58:02 +08:00
|
|
|
smc_close_sent_any_close(conn)) {
|
2017-01-09 23:55:25 +08:00
|
|
|
/* smc_release has already been called locally */
|
|
|
|
sk->sk_state = SMC_CLOSED;
|
|
|
|
} else {
|
|
|
|
/* just shutdown, but not yet closed locally */
|
|
|
|
sk->sk_state = SMC_APPFINCLOSEWAIT;
|
|
|
|
}
|
2018-01-26 16:28:48 +08:00
|
|
|
sock_put(sk); /* passive closing */
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
2018-01-25 18:15:32 +08:00
|
|
|
case SMC_PEERFINCLOSEWAIT:
|
2018-01-26 16:28:48 +08:00
|
|
|
if (smc_cdc_rxed_any_close(conn)) {
|
2018-01-25 18:15:32 +08:00
|
|
|
sk->sk_state = SMC_CLOSED;
|
2018-01-26 16:28:48 +08:00
|
|
|
sock_put(sk); /* passive closing */
|
|
|
|
}
|
2018-01-25 18:15:32 +08:00
|
|
|
break;
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_APPCLOSEWAIT1:
|
|
|
|
case SMC_APPCLOSEWAIT2:
|
2018-01-26 16:28:48 +08:00
|
|
|
/* postpone sock_put() for passive closing to cover
|
|
|
|
* received SEND_SHUTDOWN as well
|
|
|
|
*/
|
|
|
|
break;
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_APPFINCLOSEWAIT:
|
|
|
|
case SMC_PEERABORTWAIT:
|
|
|
|
case SMC_PROCESSABORT:
|
|
|
|
case SMC_CLOSED:
|
|
|
|
/* nothing to do, add tracing in future patch */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
wakeup:
|
|
|
|
sk->sk_data_ready(sk); /* wakeup blocked rcvbuf consumers */
|
|
|
|
sk->sk_write_space(sk); /* wakeup blocked sndbuf producers */
|
|
|
|
|
2017-04-10 20:58:02 +08:00
|
|
|
if (old_state != sk->sk_state) {
|
|
|
|
sk->sk_state_change(sk);
|
|
|
|
if ((sk->sk_state == SMC_CLOSED) &&
|
2019-02-07 22:56:15 +08:00
|
|
|
(sock_flag(sk, SOCK_DEAD) || !sk->sk_socket)) {
|
2018-01-24 17:28:12 +08:00
|
|
|
smc_conn_free(conn);
|
2019-04-11 17:17:30 +08:00
|
|
|
if (smc->clcsock)
|
|
|
|
release_clcsock = true;
|
2019-02-07 22:56:15 +08:00
|
|
|
}
|
2017-01-09 23:55:25 +08:00
|
|
|
}
|
2018-01-24 17:28:12 +08:00
|
|
|
release_sock(sk);
|
2019-04-11 17:17:30 +08:00
|
|
|
if (release_clcsock)
|
|
|
|
smc_clcsock_release(smc);
|
2018-01-26 16:28:48 +08:00
|
|
|
sock_put(sk); /* sock_hold done by schedulers of close_work */
|
2017-01-09 23:55:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int smc_close_shutdown_write(struct smc_sock *smc)
|
|
|
|
{
|
|
|
|
struct smc_connection *conn = &smc->conn;
|
|
|
|
struct sock *sk = &smc->sk;
|
|
|
|
int old_state;
|
2017-09-21 15:16:34 +08:00
|
|
|
long timeout;
|
2017-01-09 23:55:25 +08:00
|
|
|
int rc = 0;
|
|
|
|
|
2017-09-21 15:16:34 +08:00
|
|
|
timeout = current->flags & PF_EXITING ?
|
|
|
|
0 : sock_flag(sk, SOCK_LINGER) ?
|
|
|
|
sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
|
2017-01-09 23:55:25 +08:00
|
|
|
|
|
|
|
old_state = sk->sk_state;
|
2018-01-24 17:28:16 +08:00
|
|
|
again:
|
|
|
|
switch (sk->sk_state) {
|
2017-01-09 23:55:25 +08:00
|
|
|
case SMC_ACTIVE:
|
|
|
|
smc_close_stream_wait(smc, timeout);
|
|
|
|
release_sock(sk);
|
2017-09-21 15:16:33 +08:00
|
|
|
cancel_delayed_work_sync(&conn->tx_work);
|
2017-01-09 23:55:25 +08:00
|
|
|
lock_sock(sk);
|
2018-01-24 17:28:16 +08:00
|
|
|
if (sk->sk_state != SMC_ACTIVE)
|
|
|
|
goto again;
|
2017-01-09 23:55:25 +08:00
|
|
|
/* send close wr request */
|
|
|
|
rc = smc_close_wr(conn);
|
2018-01-24 17:28:16 +08:00
|
|
|
sk->sk_state = SMC_PEERCLOSEWAIT1;
|
2017-01-09 23:55:25 +08:00
|
|
|
break;
|
|
|
|
case SMC_APPCLOSEWAIT1:
|
|
|
|
/* passive close */
|
|
|
|
if (!smc_cdc_rxed_any_close(conn))
|
|
|
|
smc_close_stream_wait(smc, timeout);
|
|
|
|
release_sock(sk);
|
2017-09-21 15:16:33 +08:00
|
|
|
cancel_delayed_work_sync(&conn->tx_work);
|
2017-01-09 23:55:25 +08:00
|
|
|
lock_sock(sk);
|
2018-01-24 17:28:16 +08:00
|
|
|
if (sk->sk_state != SMC_APPCLOSEWAIT1)
|
|
|
|
goto again;
|
2017-01-09 23:55:25 +08:00
|
|
|
/* confirm close from peer */
|
|
|
|
rc = smc_close_wr(conn);
|
|
|
|
sk->sk_state = SMC_APPCLOSEWAIT2;
|
|
|
|
break;
|
|
|
|
case SMC_APPCLOSEWAIT2:
|
|
|
|
case SMC_PEERFINCLOSEWAIT:
|
|
|
|
case SMC_PEERCLOSEWAIT1:
|
|
|
|
case SMC_PEERCLOSEWAIT2:
|
|
|
|
case SMC_APPFINCLOSEWAIT:
|
|
|
|
case SMC_PROCESSABORT:
|
|
|
|
case SMC_PEERABORTWAIT:
|
|
|
|
/* nothing to do, add tracing in future patch */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (old_state != sk->sk_state)
|
2018-01-24 17:28:12 +08:00
|
|
|
sk->sk_state_change(sk);
|
2017-01-09 23:55:25 +08:00
|
|
|
return rc;
|
|
|
|
}
|
2017-04-10 20:58:01 +08:00
|
|
|
|
|
|
|
/* Initialize close properties on connection establishment. */
|
|
|
|
void smc_close_init(struct smc_sock *smc)
|
|
|
|
{
|
|
|
|
INIT_WORK(&smc->conn.close_work, smc_close_passive_work);
|
|
|
|
}
|