diff options
author | Ilya Dryomov <idryomov@gmail.com> | 2018-04-27 18:58:47 +0200 |
---|---|---|
committer | Ilya Dryomov <idryomov@gmail.com> | 2018-06-04 20:45:55 +0200 |
commit | e5c9388399e012ed919ad5dac818a11ed1391b18 (patch) | |
tree | a5202c6a0b8546d344167796b299bef36b814763 /net/ceph | |
parent | libceph: get rid of more_kvec in try_write() (diff) | |
download | linux-e5c9388399e012ed919ad5dac818a11ed1391b18.tar.xz linux-e5c9388399e012ed919ad5dac818a11ed1391b18.zip |
libceph: use MSG_TRUNC for discarding received bytes
Avoid a copy into the "skip buffer".
Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
Diffstat (limited to 'net/ceph')
-rw-r--r-- | net/ceph/messenger.c | 21 |
1 files changed, 8 insertions, 13 deletions
diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c index 53d145637ed5..c6413c360771 100644 --- a/net/ceph/messenger.c +++ b/net/ceph/messenger.c @@ -168,12 +168,6 @@ static char tag_keepalive2 = CEPH_MSGR_TAG_KEEPALIVE2; static struct lock_class_key socket_class; #endif -/* - * When skipping (ignoring) a block of input we read it into a "skip - * buffer," which is this many bytes in size. - */ -#define SKIP_BUF_SIZE 1024 - static void queue_con(struct ceph_connection *con); static void cancel_con(struct ceph_connection *con); static void ceph_con_workfn(struct work_struct *); @@ -520,12 +514,18 @@ static int ceph_tcp_connect(struct ceph_connection *con) return 0; } +/* + * If @buf is NULL, discard up to @len bytes. + */ static int ceph_tcp_recvmsg(struct socket *sock, void *buf, size_t len) { struct kvec iov = {buf, len}; struct msghdr msg = { .msg_flags = MSG_DONTWAIT | MSG_NOSIGNAL }; int r; + if (!buf) + msg.msg_flags |= MSG_TRUNC; + iov_iter_kvec(&msg.msg_iter, READ | ITER_KVEC, &iov, 1, len); r = sock_recvmsg(sock, &msg, msg.msg_flags); if (r == -EAGAIN) @@ -2717,16 +2717,11 @@ more: if (con->in_base_pos < 0) { /* * skipping + discarding content. - * - * FIXME: there must be a better way to do this! */ - static char buf[SKIP_BUF_SIZE]; - int skip = min((int) sizeof (buf), -con->in_base_pos); - - dout("skipping %d / %d bytes\n", skip, -con->in_base_pos); - ret = ceph_tcp_recvmsg(con->sock, buf, skip); + ret = ceph_tcp_recvmsg(con->sock, NULL, -con->in_base_pos); if (ret <= 0) goto out; + dout("skipped %d / %d bytes\n", ret, -con->in_base_pos); con->in_base_pos += ret; if (con->in_base_pos) goto more; |