From: Geliang Tang <tanggeliang@kylinos.cn>
This patch implements the .splice_eof interface for MPTCP, namely
mptcp_splice_eof(), which calls do_tcp_splice_eof() for each active
subflow when a sendfile() operation reaches end-of-file.
do_tcp_splice_eof() flushes any remaining data in the TCP send queue.
MPTCP operates over multiple TCP subflows, and each subflow may have
pending data in its send buffer that needs to be properly finalized
when splicing data through an MPTCP socket.
sock_splice_eof() calls the .splice_eof interface from struct proto_ops.
To maintain consistency with regular TCP behavior, the .splice_eof
interface of mptcp_stream_ops is set to inet_splice_eof, which will
switch to the protocol-specific implementation (sk->sk_prot->splice_eof)
- for MPTCP, that is mptcp_splice_eof().
This is an improvement; nothing was broken before. MPTCP previously did not
handle the splice EOF notification, while TCP did. Without .splice_eof()
support, the queue is not flushed immediately when sendfile() reaches EOF,
but it will eventually be flushed after a small delay.
Suggested-by: Matthieu Baerts <matttbe@kernel.org>
Signed-off-by: Geliang Tang <tanggeliang@kylinos.cn>
---
net/mptcp/protocol.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/net/mptcp/protocol.c b/net/mptcp/protocol.c
index c88882062c40..e4c5fe285f97 100644
--- a/net/mptcp/protocol.c
+++ b/net/mptcp/protocol.c
@@ -4018,6 +4018,27 @@ static int mptcp_connect(struct sock *sk, struct sockaddr_unsized *uaddr,
return 0;
}
+static void mptcp_splice_eof(struct socket *sock)
+{
+ struct mptcp_subflow_context *subflow;
+ struct sock *sk = sock->sk, *ssk;
+ struct mptcp_sock *msk;
+
+ msk = mptcp_sk(sk);
+
+ lock_sock(sk);
+ mptcp_rps_record_subflows(msk);
+ mptcp_for_each_subflow(msk, subflow) {
+ ssk = mptcp_subflow_tcp_sock(subflow);
+
+ if (ssk->sk_state == TCP_CLOSE)
+ continue;
+
+ do_tcp_splice_eof(ssk);
+ }
+ release_sock(sk);
+}
+
static struct proto mptcp_prot = {
.name = "MPTCP",
.owner = THIS_MODULE,
@@ -4049,6 +4070,7 @@ static struct proto mptcp_prot = {
.obj_size = sizeof(struct mptcp_sock),
.slab_flags = SLAB_TYPESAFE_BY_RCU,
.no_autobind = true,
+ .splice_eof = mptcp_splice_eof,
};
static int mptcp_bind(struct socket *sock, struct sockaddr_unsized *uaddr, int addr_len)
@@ -4540,6 +4562,7 @@ static const struct proto_ops mptcp_stream_ops = {
.set_rcvlowat = mptcp_set_rcvlowat,
.read_sock = mptcp_read_sock,
.splice_read = mptcp_splice_read,
+ .splice_eof = inet_splice_eof,
};
static struct inet_protosw mptcp_protosw = {
--
2.52.0