Skip to content

Commit 986ffdf

Browse files
laoardavem330
authored andcommitted
net: sock: replace sk_state_load with inet_sk_state_load and remove sk_state_store
sk_state_load is only used by AF_INET/AF_INET6, so rename it to inet_sk_state_load and move it into inet_sock.h. sk_state_store is removed as it is not used any more. Signed-off-by: Yafang Shao <laoar.shao@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 563e0bb commit 986ffdf

7 files changed

Lines changed: 30 additions & 32 deletions

File tree

‎include/net/inet_sock.h‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,32 @@ static inline void inet_sk_copy_descendant(struct sock *sk_to,
290290
#endif
291291

292292
int inet_sk_rebuild_header(struct sock *sk);
293-
void inet_sk_set_state(struct sock *sk, int state);
293+
294+
/**
295+
* inet_sk_state_load - read sk->sk_state for lockless contexts
296+
* @sk: socket pointer
297+
*
298+
* Paired with inet_sk_state_store(). Used in places we don't hold socket lock:
299+
* tcp_diag_get_info(), tcp_get_info(), tcp_poll(), get_tcp4_sock() ...
300+
*/
301+
static inline int inet_sk_state_load(const struct sock *sk)
302+
{
303+
/* state change might impact lockless readers. */
304+
return smp_load_acquire(&sk->sk_state);
305+
}
306+
307+
/**
308+
* inet_sk_state_store - update sk->sk_state
309+
* @sk: socket pointer
310+
* @newstate: new state
311+
*
312+
* Paired with inet_sk_state_load(). Should be used in contexts where
313+
* state change might impact lockless readers.
314+
*/
294315
void inet_sk_state_store(struct sock *sk, int newstate);
295316

317+
void inet_sk_set_state(struct sock *sk, int state);
318+
296319
static inline unsigned int __inet_ehashfn(const __be32 laddr,
297320
const __u16 lport,
298321
const __be32 faddr,

‎include/net/sock.h‎

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,31 +2333,6 @@ static inline bool sk_listener(const struct sock *sk)
23332333
return (1 << sk->sk_state) & (TCPF_LISTEN | TCPF_NEW_SYN_RECV);
23342334
}
23352335

2336-
/**
2337-
* sk_state_load - read sk->sk_state for lockless contexts
2338-
* @sk: socket pointer
2339-
*
2340-
* Paired with sk_state_store(). Used in places we do not hold socket lock :
2341-
* tcp_diag_get_info(), tcp_get_info(), tcp_poll(), get_tcp4_sock() ...
2342-
*/
2343-
static inline int sk_state_load(const struct sock *sk)
2344-
{
2345-
return smp_load_acquire(&sk->sk_state);
2346-
}
2347-
2348-
/**
2349-
* sk_state_store - update sk->sk_state
2350-
* @sk: socket pointer
2351-
* @newstate: new state
2352-
*
2353-
* Paired with sk_state_load(). Should be used in contexts where
2354-
* state change might impact lockless readers.
2355-
*/
2356-
static inline void sk_state_store(struct sock *sk, int newstate)
2357-
{
2358-
smp_store_release(&sk->sk_state, newstate);
2359-
}
2360-
23612336
void sock_enable_timestamp(struct sock *sk, int flag);
23622337
int sock_get_timestamp(struct sock *, struct timeval __user *);
23632338
int sock_get_timestampns(struct sock *, struct timespec __user *);

‎net/ipv4/inet_connection_sock.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ static void reqsk_timer_handler(struct timer_list *t)
685685
int max_retries, thresh;
686686
u8 defer_accept;
687687

688-
if (sk_state_load(sk_listener) != TCP_LISTEN)
688+
if (inet_sk_state_load(sk_listener) != TCP_LISTEN)
689689
goto drop;
690690

691691
max_retries = icsk->icsk_syn_retries ? : net->ipv4.sysctl_tcp_synack_retries;

‎net/ipv4/tcp.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ unsigned int tcp_poll(struct file *file, struct socket *sock, poll_table *wait)
502502

503503
sock_poll_wait(file, sk_sleep(sk), wait);
504504

505-
state = sk_state_load(sk);
505+
state = inet_sk_state_load(sk);
506506
if (state == TCP_LISTEN)
507507
return inet_csk_listen_poll(sk);
508508

@@ -2916,7 +2916,7 @@ void tcp_get_info(struct sock *sk, struct tcp_info *info)
29162916
if (sk->sk_type != SOCK_STREAM)
29172917
return;
29182918

2919-
info->tcpi_state = sk_state_load(sk);
2919+
info->tcpi_state = inet_sk_state_load(sk);
29202920

29212921
/* Report meaningful fields for all TCP states, including listeners */
29222922
rate = READ_ONCE(sk->sk_pacing_rate);

‎net/ipv4/tcp_diag.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ static void tcp_diag_get_info(struct sock *sk, struct inet_diag_msg *r,
2424
{
2525
struct tcp_info *info = _info;
2626

27-
if (sk_state_load(sk) == TCP_LISTEN) {
27+
if (inet_sk_state_load(sk) == TCP_LISTEN) {
2828
r->idiag_rqueue = sk->sk_ack_backlog;
2929
r->idiag_wqueue = sk->sk_max_ack_backlog;
3030
} else if (sk->sk_type == SOCK_STREAM) {

‎net/ipv4/tcp_ipv4.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2281,7 +2281,7 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i)
22812281
timer_expires = jiffies;
22822282
}
22832283

2284-
state = sk_state_load(sk);
2284+
state = inet_sk_state_load(sk);
22852285
if (state == TCP_LISTEN)
22862286
rx_queue = sk->sk_ack_backlog;
22872287
else

‎net/ipv6/tcp_ipv6.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1795,7 +1795,7 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
17951795
timer_expires = jiffies;
17961796
}
17971797

1798-
state = sk_state_load(sp);
1798+
state = inet_sk_state_load(sp);
17991799
if (state == TCP_LISTEN)
18001800
rx_queue = sp->sk_ack_backlog;
18011801
else

0 commit comments

Comments
 (0)