[RFC net-next 14/20] net/smc: allow to access the state of inet smc sock

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: "D. Wythe" <alibuda@xxxxxxxxxxxxxxxxx>

As we know, in inet version of smc, smc_sock and tcp_sock coexist,
this will result in the sk_state field has been accessed and modified by
both protocols, which can cause obvious exceptions. Therefore, this
patch modify the state macro for reading and setting the smc state,
using the icsk field to determine which is the very field needed to
be accessed or changed.

Signed-off-by: D. Wythe <alibuda@xxxxxxxxxxxxxxxxx>
---
 net/smc/smc.h | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/net/smc/smc.h b/net/smc/smc.h
index 932d61f..e54a30c 100644
--- a/net/smc/smc.h
+++ b/net/smc/smc.h
@@ -38,9 +38,6 @@
 #define KERNEL_HAS_ATOMIC64
 #endif
 
-#define smc_sk_state(sk)		((sk)->sk_state)
-#define smc_sk_set_state(sk, state)	(smc_sk_state(sk) = (state))
-
 enum smc_state {		/* possible states of an SMC socket */
 	SMC_ACTIVE	= 1,
 	SMC_INIT	= 2,
@@ -254,6 +251,7 @@ struct smc_sock {				/* smc sock container */
 		struct sock sk;
 	};
 	struct socket		*clcsock;	/* internal tcp socket */
+	unsigned char		smc_state;	/* smc state used in smc via inet_sk */
 	void			(*clcsk_state_change)(struct sock *sk);
 						/* original stat_change fct. */
 	void			(*clcsk_data_ready)(struct sock *sk);
@@ -397,6 +395,20 @@ static __always_inline bool smc_sock_is_inet_sock(const struct sock *sk)
 	return inet_test_bit(IS_ICSK, sk);
 }
 
+#define smc_sk_state(sk)	({				\
+	struct sock *__sk = (sk);				\
+	smc_sock_is_inet_sock(__sk) ?				\
+		smc_sk(__sk)->smc_state : (__sk)->sk_state;	\
+})
+
+static __always_inline void smc_sk_set_state(struct sock *sk, unsigned char state)
+{
+	if (smc_sock_is_inet_sock(sk))
+		smc_sk(sk)->smc_state = state;
+	else
+		sk->sk_state = state;
+}
+
 #define smc_sock_flag(sk, flag)	sock_flag(sk, flag)
 
 #endif	/* __SMC_H */
-- 
1.8.3.1





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux