]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
switch ksocknal_lib_recv_...() to use of iov_iter_for_each_range()
authorAl Viro <viro@zeniv.linux.org.uk>
Mon, 25 Sep 2017 17:58:39 +0000 (13:58 -0400)
committerAl Viro <viro@zeniv.linux.org.uk>
Thu, 12 Oct 2017 02:37:49 +0000 (22:37 -0400)
... and fold kvec and bio_vec variants in one

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.h
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_cb.c
drivers/staging/lustre/lnet/klnds/socklnd/socklnd_lib.c

index 694d45b45976b6c2cba1b044fbb9261ad5b30cfa..a18a57c4de81ed2776b8a7f471bd57b36908dc12 100644 (file)
@@ -696,8 +696,7 @@ int ksocknal_lib_setup_sock(struct socket *so);
 int ksocknal_lib_send_iov(struct ksock_conn *conn, struct ksock_tx *tx);
 int ksocknal_lib_send_kiov(struct ksock_conn *conn, struct ksock_tx *tx);
 void ksocknal_lib_eager_ack(struct ksock_conn *conn);
-int ksocknal_lib_recv_iov(struct ksock_conn *conn);
-int ksocknal_lib_recv_kiov(struct ksock_conn *conn);
+int ksocknal_lib_recv(struct ksock_conn *conn);
 int ksocknal_lib_get_conn_tunables(struct ksock_conn *conn, int *txmem,
                                   int *rxmem, int *nagle);
 
index c79aeb463a5c593e6125cf381eb719b58d24eb12..b12c3b0f39e19b121e9f190c8ff6d2cd9753b1ad 100644 (file)
@@ -249,16 +249,16 @@ ksocknal_transmit(struct ksock_conn *conn, struct ksock_tx *tx)
 }
 
 static int
-ksocknal_recv_iov(struct ksock_conn *conn)
+ksocknal_recv_iter(struct ksock_conn *conn)
 {
        int nob;
        int rc;
 
        /*
         * Never touch conn->ksnc_rx_to or change connection
-        * status inside ksocknal_lib_recv_iov
+        * status inside ksocknal_lib_recv
         */
-       rc = ksocknal_lib_recv_iov(conn);
+       rc = ksocknal_lib_recv(conn);
 
        if (rc <= 0)
                return rc;
@@ -274,38 +274,6 @@ ksocknal_recv_iov(struct ksock_conn *conn)
 
        conn->ksnc_rx_nob_left -= nob;
 
-       iov_iter_advance(&conn->ksnc_rx_to, nob);
-       if (iov_iter_count(&conn->ksnc_rx_to))
-               return -EAGAIN;
-
-       return rc;
-}
-
-static int
-ksocknal_recv_kiov(struct ksock_conn *conn)
-{
-       int nob;
-       int rc;
-
-       /*
-        * Never touch conn->ksnc_rx_to or change connection
-        * status inside ksocknal_lib_recv_iov
-        */
-       rc = ksocknal_lib_recv_kiov(conn);
-
-       if (rc <= 0)
-               return rc;
-
-       /* received something... */
-       nob = rc;
-
-       conn->ksnc_peer->ksnp_last_alive = cfs_time_current();
-       conn->ksnc_rx_deadline =
-               cfs_time_shift(*ksocknal_tunables.ksnd_timeout);
-       mb();                  /* order with setting rx_started */
-       conn->ksnc_rx_started = 1;
-
-       conn->ksnc_rx_nob_left -= nob;
        iov_iter_advance(&conn->ksnc_rx_to, nob);
        if (iov_iter_count(&conn->ksnc_rx_to))
                return -EAGAIN;
@@ -335,11 +303,7 @@ ksocknal_receive(struct ksock_conn *conn)
        }
 
        for (;;) {
-               if (conn->ksnc_rx_to.type & ITER_KVEC)
-                       rc = ksocknal_recv_iov(conn);
-               else
-                       rc = ksocknal_recv_kiov(conn);
-
+               rc = ksocknal_recv_iter(conn);
                if (rc <= 0) {
                        /* error/EOF or partial receive */
                        if (rc == -EAGAIN) {
index 0ec032373497cfb311a0cf5c981111ea1f596328..2e3e2dd70baaf29afde2a7c2fd48558af7e756e5 100644 (file)
@@ -161,86 +161,39 @@ ksocknal_lib_eager_ack(struct ksock_conn *conn)
                          sizeof(opt));
 }
 
-int
-ksocknal_lib_recv_iov(struct ksock_conn *conn)
+static int lustre_csum(struct kvec *v, void *context)
 {
-       unsigned int niov = conn->ksnc_rx_to.nr_segs;
-       const struct iovec *iov = conn->ksnc_rx_to.iov;
-       struct msghdr msg = {
-               .msg_flags = 0
-       };
-       int i;
-       int rc;
-       int fragnob;
-       int sum;
-       __u32 saved_csum;
-       int off = conn->ksnc_rx_to.iov_offset;
-
-       msg.msg_iter = conn->ksnc_rx_to;
-       rc = sock_recvmsg(conn->ksnc_sock, &msg, MSG_DONTWAIT);
-
-       saved_csum = 0;
-       if (conn->ksnc_proto == &ksocknal_protocol_v2x) {
-               saved_csum = conn->ksnc_msg.ksm_csum;
-               conn->ksnc_msg.ksm_csum = 0;
-       }
-
-       if (saved_csum) {
-               /* accumulate checksum */
-               for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) {
-                       LASSERT(i < niov);
-
-                       fragnob = iov[i].iov_len - off;
-                       if (fragnob > sum)
-                               fragnob = sum;
-
-                       conn->ksnc_rx_csum = crc32_le(conn->ksnc_rx_csum,
-                                                     iov[i].iov_base + off,
-                                                     fragnob);
-                       off = 0;
-               }
-               conn->ksnc_msg.ksm_csum = saved_csum;
-       }
-
-       return rc;
+       struct ksock_conn *conn = context;
+       conn->ksnc_rx_csum = crc32_le(conn->ksnc_rx_csum,
+                                     v->iov_base, v->iov_len);
+       return 0;
 }
 
 int
-ksocknal_lib_recv_kiov(struct ksock_conn *conn)
+ksocknal_lib_recv(struct ksock_conn *conn)
 {
-       unsigned int niov = conn->ksnc_rx_to.nr_segs;
-       const struct bio_vec *kiov = conn->ksnc_rx_to.bvec;
-       int off = conn->ksnc_rx_to.iov_offset;
-       struct msghdr msg = {
-               .msg_flags = 0
-       };
-       int i;
+       struct msghdr msg = { .msg_iter = conn->ksnc_rx_to };
+       __u32 saved_csum;
        int rc;
-       void *base;
-       int sum;
-       int fragnob;
 
-       msg.msg_iter = conn->ksnc_rx_to;
        rc = sock_recvmsg(conn->ksnc_sock, &msg, MSG_DONTWAIT);
        if (rc <= 0)
                return rc;
 
-       if (conn->ksnc_msg.ksm_csum) {
-               for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) {
-                       LASSERT(i < niov);
-
-                       base = kmap(kiov[i].bv_page) + kiov[i].bv_offset + off;
-                       fragnob = kiov[i].bv_len - off;
-                       if (fragnob > sum)
-                               fragnob = sum;
+       saved_csum = conn->ksnc_msg.ksm_csum;
+       if (!saved_csum)
+               return rc;
 
-                       conn->ksnc_rx_csum = crc32_le(conn->ksnc_rx_csum,
-                                                     base, fragnob);
+       /* header is included only in V2 - V3 checksums only the bulk data */
+       if (!(conn->ksnc_rx_to.type & ITER_BVEC) &&
+            conn->ksnc_proto != &ksocknal_protocol_v2x)
+               return rc;
+               
+       /* accumulate checksum */
+       conn->ksnc_msg.ksm_csum = 0;
+       iov_iter_for_each_range(&conn->ksnc_rx_to, rc, lustre_csum, conn);
+       conn->ksnc_msg.ksm_csum = saved_csum;
 
-                       kunmap(kiov[i].bv_page);
-                       off = 0;
-               }
-       }
        return rc;
 }