libceph: use MSG_TRUNC for discarding received bytes
authorIlya Dryomov <idryomov@gmail.com>
Fri, 27 Apr 2018 16:58:47 +0000 (18:58 +0200)
committerIlya Dryomov <idryomov@gmail.com>
Mon, 4 Jun 2018 18:45:55 +0000 (20:45 +0200)
Avoid a copy into the "skip buffer".

Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
net/ceph/messenger.c

index 53d145637ed5ff3185c49fa27b0ad8b509a460ce..c6413c3607712de1d20e2b6010433434395020be 100644 (file)
@@ -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;