Skip to content

Commit db10538

Browse files
Christoph Hellwigdavem330
authored andcommitted
tcp: add tcp_sock_set_cork
Add a helper to directly set the TCP_CORK sockopt from kernel space without going through a fake uaccess. Cleanup the callers to avoid pointless wrappers now that this is a simple function call. Signed-off-by: Christoph Hellwig <hch@lst.de> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent fe31a32 commit db10538

7 files changed

Lines changed: 43 additions & 51 deletions

File tree

‎drivers/block/drbd/drbd_int.h‎

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1570,20 +1570,6 @@ extern void drbd_set_recv_tcq(struct drbd_device *device, int tcq_enabled);
15701570
extern void _drbd_clear_done_ee(struct drbd_device *device, struct list_head *to_be_freed);
15711571
extern int drbd_connected(struct drbd_peer_device *);
15721572

1573-
static inline void drbd_tcp_cork(struct socket *sock)
1574-
{
1575-
int val = 1;
1576-
(void) kernel_setsockopt(sock, SOL_TCP, TCP_CORK,
1577-
(char*)&val, sizeof(val));
1578-
}
1579-
1580-
static inline void drbd_tcp_uncork(struct socket *sock)
1581-
{
1582-
int val = 0;
1583-
(void) kernel_setsockopt(sock, SOL_TCP, TCP_CORK,
1584-
(char*)&val, sizeof(val));
1585-
}
1586-
15871573
static inline void drbd_tcp_nodelay(struct socket *sock)
15881574
{
15891575
int val = 1;

‎drivers/block/drbd/drbd_receiver.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6162,7 +6162,7 @@ void drbd_send_acks_wf(struct work_struct *ws)
61626162
rcu_read_unlock();
61636163

61646164
if (tcp_cork)
6165-
drbd_tcp_cork(connection->meta.socket);
6165+
tcp_sock_set_cork(connection->meta.socket->sk, true);
61666166

61676167
err = drbd_finish_peer_reqs(device);
61686168
kref_put(&device->kref, drbd_destroy_device);
@@ -6175,7 +6175,7 @@ void drbd_send_acks_wf(struct work_struct *ws)
61756175
}
61766176

61776177
if (tcp_cork)
6178-
drbd_tcp_uncork(connection->meta.socket);
6178+
tcp_sock_set_cork(connection->meta.socket->sk, false);
61796179

61806180
return;
61816181
}

‎drivers/block/drbd/drbd_worker.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,7 +2098,7 @@ static void wait_for_work(struct drbd_connection *connection, struct list_head *
20982098
if (uncork) {
20992099
mutex_lock(&connection->data.mutex);
21002100
if (connection->data.socket)
2101-
drbd_tcp_uncork(connection->data.socket);
2101+
tcp_sock_set_cork(connection->data.socket->sk, false);
21022102
mutex_unlock(&connection->data.mutex);
21032103
}
21042104

@@ -2153,9 +2153,9 @@ static void wait_for_work(struct drbd_connection *connection, struct list_head *
21532153
mutex_lock(&connection->data.mutex);
21542154
if (connection->data.socket) {
21552155
if (cork)
2156-
drbd_tcp_cork(connection->data.socket);
2156+
tcp_sock_set_cork(connection->data.socket->sk, true);
21572157
else if (!uncork)
2158-
drbd_tcp_uncork(connection->data.socket);
2158+
tcp_sock_set_cork(connection->data.socket->sk, false);
21592159
}
21602160
mutex_unlock(&connection->data.mutex);
21612161
}

‎fs/cifs/transport.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,6 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
325325
size_t total_len = 0, sent, size;
326326
struct socket *ssocket = server->ssocket;
327327
struct msghdr smb_msg;
328-
int val = 1;
329328
__be32 rfc1002_marker;
330329

331330
if (cifs_rdma_enabled(server)) {
@@ -345,8 +344,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
345344
}
346345

347346
/* cork the socket */
348-
kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,
349-
(char *)&val, sizeof(val));
347+
tcp_sock_set_cork(ssocket->sk, true);
350348

351349
for (j = 0; j < num_rqst; j++)
352350
send_length += smb_rqst_len(server, &rqst[j]);
@@ -435,9 +433,7 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
435433
}
436434

437435
/* uncork it */
438-
val = 0;
439-
kernel_setsockopt(ssocket, SOL_TCP, TCP_CORK,
440-
(char *)&val, sizeof(val));
436+
tcp_sock_set_cork(ssocket->sk, false);
441437

442438
if ((total_len > 0) && (total_len != send_length)) {
443439
cifs_dbg(FYI, "partial send (wanted=%u sent=%zu): terminating session\n",

‎include/linux/tcp.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,4 +497,6 @@ static inline u16 tcp_mss_clamp(const struct tcp_sock *tp, u16 mss)
497497
int tcp_skb_shift(struct sk_buff *to, struct sk_buff *from, int pcount,
498498
int shiftlen);
499499

500+
void tcp_sock_set_cork(struct sock *sk, bool on);
501+
500502
#endif /* _LINUX_TCP_H */

‎net/ipv4/tcp.c‎

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,37 @@ static void tcp_enable_tx_delay(void)
28012801
}
28022802
}
28032803

2804+
/* When set indicates to always queue non-full frames. Later the user clears
2805+
* this option and we transmit any pending partial frames in the queue. This is
2806+
* meant to be used alongside sendfile() to get properly filled frames when the
2807+
* user (for example) must write out headers with a write() call first and then
2808+
* use sendfile to send out the data parts.
2809+
*
2810+
* TCP_CORK can be set together with TCP_NODELAY and it is stronger than
2811+
* TCP_NODELAY.
2812+
*/
2813+
static void __tcp_sock_set_cork(struct sock *sk, bool on)
2814+
{
2815+
struct tcp_sock *tp = tcp_sk(sk);
2816+
2817+
if (on) {
2818+
tp->nonagle |= TCP_NAGLE_CORK;
2819+
} else {
2820+
tp->nonagle &= ~TCP_NAGLE_CORK;
2821+
if (tp->nonagle & TCP_NAGLE_OFF)
2822+
tp->nonagle |= TCP_NAGLE_PUSH;
2823+
tcp_push_pending_frames(sk);
2824+
}
2825+
}
2826+
2827+
void tcp_sock_set_cork(struct sock *sk, bool on)
2828+
{
2829+
lock_sock(sk);
2830+
__tcp_sock_set_cork(sk, on);
2831+
release_sock(sk);
2832+
}
2833+
EXPORT_SYMBOL(tcp_sock_set_cork);
2834+
28042835
/*
28052836
* Socket option code for TCP.
28062837
*/
@@ -2979,25 +3010,7 @@ static int do_tcp_setsockopt(struct sock *sk, int level,
29793010
break;
29803011

29813012
case TCP_CORK:
2982-
/* When set indicates to always queue non-full frames.
2983-
* Later the user clears this option and we transmit
2984-
* any pending partial frames in the queue. This is
2985-
* meant to be used alongside sendfile() to get properly
2986-
* filled frames when the user (for example) must write
2987-
* out headers with a write() call first and then use
2988-
* sendfile to send out the data parts.
2989-
*
2990-
* TCP_CORK can be set together with TCP_NODELAY and it is
2991-
* stronger than TCP_NODELAY.
2992-
*/
2993-
if (val) {
2994-
tp->nonagle |= TCP_NAGLE_CORK;
2995-
} else {
2996-
tp->nonagle &= ~TCP_NAGLE_CORK;
2997-
if (tp->nonagle&TCP_NAGLE_OFF)
2998-
tp->nonagle |= TCP_NAGLE_PUSH;
2999-
tcp_push_pending_frames(sk);
3000-
}
3013+
__tcp_sock_set_cork(sk, val);
30013014
break;
30023015

30033016
case TCP_KEEPIDLE:

‎net/rds/tcp_send.c‎

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,18 @@
3838
#include "rds.h"
3939
#include "tcp.h"
4040

41-
static void rds_tcp_cork(struct socket *sock, int val)
42-
{
43-
kernel_setsockopt(sock, SOL_TCP, TCP_CORK, (void *)&val, sizeof(val));
44-
}
45-
4641
void rds_tcp_xmit_path_prepare(struct rds_conn_path *cp)
4742
{
4843
struct rds_tcp_connection *tc = cp->cp_transport_data;
4944

50-
rds_tcp_cork(tc->t_sock, 1);
45+
tcp_sock_set_cork(tc->t_sock->sk, true);
5146
}
5247

5348
void rds_tcp_xmit_path_complete(struct rds_conn_path *cp)
5449
{
5550
struct rds_tcp_connection *tc = cp->cp_transport_data;
5651

57-
rds_tcp_cork(tc->t_sock, 0);
52+
tcp_sock_set_cork(tc->t_sock->sk, false);
5853
}
5954

6055
/* the core send_sem serializes this with other xmit and shutdown */

0 commit comments

Comments
 (0)