diff mbox series

[RFC,net-next,07/20] net/smc: refactor sock_flag/sock_set_flag

Message ID 1708412505-34470-8-git-send-email-alibuda@linux.alibaba.com (mailing list archive)
State RFC
Delegated to: Netdev Maintainers
Headers show
Series Introduce IPPROTO_SMC | expand

Checks

Context Check Description
netdev/series_format fail Series longer than 15 patches (and no cover letter)
netdev/tree_selection success Clearly marked for net-next, async
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 940 this patch: 940
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 957 this patch: 957
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 957 this patch: 957
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 94 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

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

Use a unified new macro to access the flag of the sock,
so that we can easily modify the behavior of a specific flag
instead of modifying the original function.

Signed-off-by: D. Wythe <alibuda@linux.alibaba.com>
---
 net/smc/af_smc.c    | 4 ++--
 net/smc/smc.h       | 2 ++
 net/smc/smc_cdc.c   | 2 +-
 net/smc/smc_close.c | 8 ++++----
 net/smc/smc_rx.c    | 8 ++++----
 5 files changed, 13 insertions(+), 11 deletions(-)
diff mbox series

Patch

diff --git a/net/smc/af_smc.c b/net/smc/af_smc.c
index 40cf0569..66306b7 100644
--- a/net/smc/af_smc.c
+++ b/net/smc/af_smc.c
@@ -358,7 +358,7 @@  static void smc_destruct(struct sock *sk)
 {
 	if (smc_sk_state(sk) != SMC_CLOSED)
 		return;
-	if (!sock_flag(sk, SOCK_DEAD))
+	if (!smc_sock_flag(sk, SOCK_DEAD))
 		return;
 }
 
@@ -1623,7 +1623,7 @@  static void smc_connect_work(struct work_struct *work)
 		smc->sk.sk_err = -rc;
 
 out:
-	if (!sock_flag(&smc->sk, SOCK_DEAD)) {
+	if (!smc_sock_flag(&smc->sk, SOCK_DEAD)) {
 		if (smc->sk.sk_err) {
 			smc->sk.sk_state_change(&smc->sk);
 		} else { /* allow polling before and after fallback decision */
diff --git a/net/smc/smc.h b/net/smc/smc.h
index 6b651b5..fce6a7a 100644
--- a/net/smc/smc.h
+++ b/net/smc/smc.h
@@ -388,4 +388,6 @@  static inline void smc_sock_set_flag(struct sock *sk, enum sock_flags flag)
 	set_bit(flag, &sk->sk_flags);
 }
 
+#define smc_sock_flag(sk, flag)	sock_flag(sk, flag)
+
 #endif	/* __SMC_H */
diff --git a/net/smc/smc_cdc.c b/net/smc/smc_cdc.c
index 3c06625..7614545 100644
--- a/net/smc/smc_cdc.c
+++ b/net/smc/smc_cdc.c
@@ -285,7 +285,7 @@  static void smc_cdc_handle_urg_data_arrival(struct smc_sock *smc,
 	/* new data included urgent business */
 	smc_curs_copy(&conn->urg_curs, &conn->local_rx_ctrl.prod, conn);
 	conn->urg_state = SMC_URG_VALID;
-	if (!sock_flag(&smc->sk, SOCK_URGINLINE))
+	if (!smc_sock_flag(&smc->sk, SOCK_URGINLINE))
 		/* we'll skip the urgent byte, so don't account for it */
 		(*diff_prod)--;
 	base = (char *)conn->rmb_desc->cpu_addr + conn->rx_off;
diff --git a/net/smc/smc_close.c b/net/smc/smc_close.c
index 9210d1f..8d9512e 100644
--- a/net/smc/smc_close.c
+++ b/net/smc/smc_close.c
@@ -202,7 +202,7 @@  int smc_close_active(struct smc_sock *smc)
 	int rc1 = 0;
 
 	timeout = current->flags & PF_EXITING ?
-		  0 : sock_flag(sk, SOCK_LINGER) ?
+		  0 : smc_sock_flag(sk, SOCK_LINGER) ?
 		      sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
 
 	old_state = smc_sk_state(sk);
@@ -395,7 +395,7 @@  static void smc_close_passive_work(struct work_struct *work)
 	case SMC_PEERCLOSEWAIT2:
 		if (!smc_cdc_rxed_any_close(conn))
 			break;
-		if (sock_flag(sk, SOCK_DEAD) &&
+		if (smc_sock_flag(sk, SOCK_DEAD) &&
 		    smc_close_sent_any_close(conn)) {
 			/* smc_release has already been called locally */
 			smc_sk_set_state(sk, SMC_CLOSED);
@@ -432,7 +432,7 @@  static void smc_close_passive_work(struct work_struct *work)
 	if (old_state != smc_sk_state(sk)) {
 		sk->sk_state_change(sk);
 		if ((smc_sk_state(sk) == SMC_CLOSED) &&
-		    (sock_flag(sk, SOCK_DEAD) || !sk->sk_socket)) {
+		    (smc_sock_flag(sk, SOCK_DEAD) || !sk->sk_socket)) {
 			smc_conn_free(conn);
 			if (smc->clcsock)
 				release_clcsock = true;
@@ -453,7 +453,7 @@  int smc_close_shutdown_write(struct smc_sock *smc)
 	int rc = 0;
 
 	timeout = current->flags & PF_EXITING ?
-		  0 : sock_flag(sk, SOCK_LINGER) ?
+		  0 : smc_sock_flag(sk, SOCK_LINGER) ?
 		      sk->sk_lingertime : SMC_MAX_STREAM_WAIT_TIMEOUT;
 
 	old_state = smc_sk_state(sk);
diff --git a/net/smc/smc_rx.c b/net/smc/smc_rx.c
index 32fd7db..684caae 100644
--- a/net/smc/smc_rx.c
+++ b/net/smc/smc_rx.c
@@ -70,7 +70,7 @@  static int smc_rx_update_consumer(struct smc_sock *smc,
 	if (conn->urg_state == SMC_URG_VALID || conn->urg_rx_skip_pend) {
 		diff = smc_curs_comp(conn->rmb_desc->len, &cons,
 				     &conn->urg_curs);
-		if (sock_flag(sk, SOCK_URGINLINE)) {
+		if (smc_sock_flag(sk, SOCK_URGINLINE)) {
 			if (diff == 0) {
 				force = true;
 				rc = 1;
@@ -286,7 +286,7 @@  static int smc_rx_recv_urg(struct smc_sock *smc, struct msghdr *msg, int len,
 	struct sock *sk = &smc->sk;
 	int rc = 0;
 
-	if (sock_flag(sk, SOCK_URGINLINE) ||
+	if (smc_sock_flag(sk, SOCK_URGINLINE) ||
 	    !(conn->urg_state == SMC_URG_VALID) ||
 	    conn->urg_state == SMC_URG_READ)
 		return -EINVAL;
@@ -408,7 +408,7 @@  int smc_rx_recvmsg(struct smc_sock *smc, struct msghdr *msg,
 				break;
 			}
 			if (smc_sk_state(sk) == SMC_CLOSED) {
-				if (!sock_flag(sk, SOCK_DONE)) {
+				if (!smc_sock_flag(sk, SOCK_DONE)) {
 					/* This occurs when user tries to read
 					 * from never connected socket.
 					 */
@@ -449,7 +449,7 @@  int smc_rx_recvmsg(struct smc_sock *smc, struct msghdr *msg,
 		if (splbytes)
 			smc_curs_add(conn->rmb_desc->len, &cons, splbytes);
 		if (conn->urg_state == SMC_URG_VALID &&
-		    sock_flag(&smc->sk, SOCK_URGINLINE) &&
+		    smc_sock_flag(&smc->sk, SOCK_URGINLINE) &&
 		    readable > 1)
 			readable--;	/* always stop at urgent Byte */
 		/* not more than what user space asked for */