net: Modify sock_set_keepalive() for more scenarios
Subsystems (13)
PATCH v2 1/1 net: Modify sock_set_keepalive() for more scenarios
Add 2nd parameter in sock_set_keepalive(), let the caller decide whether to set. This can be applied to more scenarios.
v2:
- add the change in fs/dlm.
Signed-off-by Yajun Deng <[email protected]>
--- fs/dlm/lowcomms.c | 2 +- include/net/sock.h | 2 +- net/core/filter.c | 4 +--- net/core/sock.c | 10 ++++------ net/mptcp/sockopt.c | 4 +--- net/rds/tcp_listen.c | 2 +- net/smc/af_smc.c | 2 +- net/sunrpc/xprtsock.c | 2 +- 8 files changed, 11 insertions(+), 17 deletions(-)
fs/dlm/lowcomms.c +1 -1
@@ -1356,7 +1356,7 @@ static int tcp_create_listen_sock(struct listen_connection *con,log_print ("Can't bind to port %d" , dlm_config.ci_tcp_port); goto create_out; } -sock_set_keepalive (sock->sk); +sock_set_keepalive (sock->sk, true); result = sock->ops->listen (sock,5 );if (result <0 ) {
include/net/sock.h +1 -1
@@ -2772,7 +2772,7 @@ int sock_set_timestamping(struct sock *sk, int optname,void sock_enable_timestamps (struct sock *sk);void sock_no_linger (struct sock *sk); -void sock_set_keepalive (struct sock *sk); +void sock_set_keepalive (struct sock *sk,bool valbool);void sock_set_priority (struct sock *sk,u32 priority);void sock_set_rcvbuf (struct sock *sk,int val);void sock_set_mark (struct sock *sk,u32 val);
net/core/filter.c +1 -3
@@ -4752,9 +4752,7 @@ static int _bpf_setsockopt(struct sock *sk, int level, int optname, ret =sock_bindtoindex (sk, ifindex, false);break ;case SO_KEEPALIVE : -if (sk->sk_prot->keepalive) - sk->sk_prot->keepalive (sk, valbool); -sock_valbool_flag (sk,SOCK_KEEPOPEN , valbool); +sock_set_keepalive (sk, !!valbool);break ;case SO_REUSEPORT : sk->sk_reuseport = valbool;
net/core/sock.c +4 -6
@@ -892,12 +892,12 @@ int sock_set_timestamping(struct sock *sk, int optname,return 0 ; } -void sock_set_keepalive (struct sock *sk) +void sock_set_keepalive (struct sock *sk,bool valbool) {lock_sock (sk);if (sk->sk_prot->keepalive) - sk->sk_prot->keepalive (sk, true); -sock_valbool_flag (sk,SOCK_KEEPOPEN , true); + sk->sk_prot->keepalive (sk, valbool); +sock_valbool_flag (sk,SOCK_KEEPOPEN , valbool);release_sock (sk); }EXPORT_SYMBOL (sock_set_keepalive);
@@ -1060,9 +1060,7 @@ int sock_setsockopt(struct socket *sock, int level, int optname,break ;case SO_KEEPALIVE : -if (sk->sk_prot->keepalive) - sk->sk_prot->keepalive (sk, valbool); -sock_valbool_flag (sk,SOCK_KEEPOPEN , valbool); +sock_set_keepalive (sk, !!valbool);break ;case SO_OOBINLINE :
net/mptcp/sockopt.c +1 -3
@@ -81,9 +81,7 @@ static void mptcp_sol_socket_sync_intval(struct mptcp_sock *msk, int optname, insock_valbool_flag (ssk,SOCK_DBG , !!val);break ;case SO_KEEPALIVE : -if (ssk->sk_prot->keepalive) - ssk->sk_prot->keepalive (ssk, !!val); -sock_valbool_flag (ssk,SOCK_KEEPOPEN , !!val); +sock_set_keepalive (ssk, !!val);break ;case SO_PRIORITY : ssk->sk_priority = val;
net/rds/tcp_listen.c +1 -1
@@ -44,7 +44,7 @@ void rds_tcp_keepalive(struct socket *sock)int keepidle =5 ;/* send a probe 'keepidle' secs after last data */ int keepcnt =5 ;/* number of unack'ed probes before declaring dead */ -sock_set_keepalive (sock->sk); +sock_set_keepalive (sock->sk, true);tcp_sock_set_keepcnt (sock->sk, keepcnt);tcp_sock_set_keepidle (sock->sk, keepidle);/* KEEPINTVL is the interval between successive probes. We follow
net/smc/af_smc.c +1 -1
@@ -68,7 +68,7 @@ static void smc_set_keepalive(struct sock *sk, int val) {struct smc_sock *smc =smc_sk (sk); - smc->clcsock->sk->sk_prot->keepalive (smc->clcsock->sk, val); +sock_set_keepalive (smc->clcsock->sk, !!val); }static struct smc_hashinfo smc_v4_hashinfo = {
net/sunrpc/xprtsock.c +1 -1
@@ -2127,7 +2127,7 @@ static void xs_tcp_set_socket_timeouts(struct rpc_xprt *xprt,spin_unlock (&xprt->transport_lock);/* TCP Keepalive options */ -sock_set_keepalive (sock->sk); +sock_set_keepalive (sock->sk, true);tcp_sock_set_keepidle (sock->sk, keepidle);tcp_sock_set_keepintvl (sock->sk, keepidle);tcp_sock_set_keepcnt (sock->sk, keepcnt);
Signature · 1 line
2.32.0
Quoted 7 lines · Yajun Deng
Add 2nd parameter in
sock_set_keepalive(), let the caller decide whether to set. This can be applied to more scenarios.v2:
- add the change in fs/dlm.Signed-off-by Yajun Deng <[email protected]>
Quoted 10 lines
--- fs/dlm/lowcomms.c | 2 +- include/net/sock.h | 2 +- net/core/filter.c | 4 +--- net/core/sock.c | 10 ++++------ net/mptcp/sockopt.c | 4 +--- net/rds/tcp_listen.c | 2 +- net/smc/af_smc.c | 2 +- net/sunrpc/xprtsock.c | 2 +- 8 files changed, 11 insertions(+), 17 deletions(-)
1. Don't add changelogs in the commit messages and put them under --- marker.
2. Add an explanation to the commit message WHY this change is necessary and HOW will it be used.
3. Drop all your double NOT in front of values (!!val) and rely on C that casts int to bool naturally.
Thanks