diff mbox series

[RFC,net-next,11/20] net/smc: make __smc_accept can return the new accepted sock

Message ID 1708412505-34470-12-git-send-email-alibuda@linux.alibaba.com (mailing list archive)
State Superseded
Headers show
Series Introduce IPPROTO_SMC | expand

Commit Message

D. Wythe Feb. 20, 2024, 7:01 a.m. UTC
From: "D. Wythe" <alibuda@linux.alibaba.com>

This patch is a refactoring for smc_accept(), the extracted
__smc_accept() make it possible to obtain the accepted sock
when an NULL clcsock passed in. In that way, the inet version
of SMC can access the accepted sock without providing a faked
clcsock.

Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
---
 net/smc/af_smc.c | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
diff mbox series

Patch

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 484e981..e0505d6 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -2684,17 +2684,16 @@  static int smc_listen(struct socket *sock, int backlog)
 	return rc;
 }
 
-static int smc_accept(struct socket *sock, struct socket *new_sock,
-		      int flags, bool kern)
+static struct sock *__smc_accept(struct sock *sk, struct socket *new_sock,
+				 int flags, int *err, bool kern)
 {
-	struct sock *sk = sock->sk, *nsk;
 	DECLARE_WAITQUEUE(wait, current);
+	struct sock *nsk = NULL;
 	struct smc_sock *lsmc;
 	long timeo;
 	int rc = 0;
 
 	lsmc = smc_sk(sk);
-	sock_hold(sk); /* sock_put below */
 	lock_sock(sk);
 
 	if (smc_sk_state(&lsmc->sk) != SMC_LISTEN) {
@@ -2750,8 +2749,21 @@  static int smc_accept(struct socket *sock, struct socket *new_sock,
 	}
 
 out:
-	sock_put(sk); /* sock_hold above */
-	return rc;
+	*err = rc;
+	return nsk;
+}
+
+static int smc_accept(struct socket *sock, struct socket *new_sock,
+		      int flags, bool kern)
+{
+	struct sock *sk = sock->sk;
+	int error;
+
+	sock_hold(sk);
+	__smc_accept(sk, new_sock, flags, &error, kern);
+	sock_put(sk);
+
+	return error;
 }
 
 static int smc_getname(struct socket *sock, struct sockaddr *addr,