Whamcloud - gitweb
LU-4423 lnet: don't open-code kernel_recvmsg()
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_lib-linux.c
index 1710cb2..df56998 100644 (file)
@@ -534,24 +534,17 @@ int
 ksocknal_lib_recv_iov (ksock_conn_t *conn)
 {
 #if SOCKNAL_SINGLE_FRAG_RX
-        struct iovec  scratch;
-        struct iovec *scratchiov = &scratch;
-        unsigned int  niov = 1;
+       struct iovec  scratch;
+       struct iovec *scratchiov = &scratch;
+       unsigned int  niov = 1;
 #else
-        struct iovec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
-        unsigned int  niov = conn->ksnc_rx_niov;
+       struct iovec *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
+       unsigned int  niov = conn->ksnc_rx_niov;
 #endif
-        struct iovec *iov = conn->ksnc_rx_iov;
-        struct msghdr msg = {
-                .msg_name       = NULL,
-                .msg_namelen    = 0,
-                .msg_iov        = scratchiov,
-                .msg_iovlen     = niov,
-                .msg_control    = NULL,
-                .msg_controllen = 0,
-                .msg_flags      = 0
-        };
-        mm_segment_t oldmm = get_fs();
+       struct iovec *iov = conn->ksnc_rx_iov;
+       struct msghdr msg = {
+               .msg_flags      = 0
+       };
         int          nob;
         int          i;
         int          rc;
@@ -569,10 +562,8 @@ ksocknal_lib_recv_iov (ksock_conn_t *conn)
         }
         LASSERT (nob <= conn->ksnc_rx_nob_wanted);
 
-        set_fs (KERNEL_DS);
-        rc = sock_recvmsg (conn->ksnc_sock, &msg, nob, MSG_DONTWAIT);
-        /* NB this is just a boolean..........................^ */
-        set_fs (oldmm);
+       rc = kernel_recvmsg(conn->ksnc_sock, &msg,
+               (struct kvec *)scratchiov, niov, nob, MSG_DONTWAIT);
 
         saved_csum = 0;
         if (conn->ksnc_proto == &ksocknal_protocol_v2x) {
@@ -656,20 +647,14 @@ ksocknal_lib_recv_kiov (ksock_conn_t *conn)
 #ifdef CONFIG_HIGHMEM
 #warning "XXX risk of kmap deadlock on multiple frags..."
 #endif
-        struct iovec  *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
-        struct page  **pages      = conn->ksnc_scheduler->kss_rx_scratch_pgs;
-        unsigned int   niov       = conn->ksnc_rx_nkiov;
+       struct iovec  *scratchiov = conn->ksnc_scheduler->kss_scratch_iov;
+       struct page  **pages      = conn->ksnc_scheduler->kss_rx_scratch_pgs;
+       unsigned int   niov       = conn->ksnc_rx_nkiov;
 #endif
-        lnet_kiov_t   *kiov = conn->ksnc_rx_kiov;
-        struct msghdr msg = {
-                .msg_name       = NULL,
-                .msg_namelen    = 0,
-                .msg_iov        = scratchiov,
-                .msg_control    = NULL,
-                .msg_controllen = 0,
-                .msg_flags      = 0
-        };
-        mm_segment_t oldmm = get_fs();
+       lnet_kiov_t   *kiov = conn->ksnc_rx_kiov;
+       struct msghdr msg = {
+               .msg_flags      = 0
+       };
         int          nob;
         int          i;
         int          rc;
@@ -677,28 +662,27 @@ ksocknal_lib_recv_kiov (ksock_conn_t *conn)
         void        *addr;
         int          sum;
         int          fragnob;
+       int n;
 
         /* NB we can't trust socket ops to either consume our iovs
          * or leave them alone. */
-        if ((addr = ksocknal_lib_kiov_vmap(kiov, niov, scratchiov, pages)) != NULL) {
-                nob = scratchiov[0].iov_len;
-                msg.msg_iovlen = 1;
-
-        } else {
-                for (nob = i = 0; i < niov; i++) {
-                        nob += scratchiov[i].iov_len = kiov[i].kiov_len;
-                        scratchiov[i].iov_base = kmap(kiov[i].kiov_page) +
-                                                 kiov[i].kiov_offset;
-                }
-                msg.msg_iovlen = niov;
-        }
+       if ((addr = ksocknal_lib_kiov_vmap(kiov, niov, scratchiov, pages)) != NULL) {
+               nob = scratchiov[0].iov_len;
+               n = 1;
+
+       } else {
+               for (nob = i = 0; i < niov; i++) {
+                       nob += scratchiov[i].iov_len = kiov[i].kiov_len;
+                       scratchiov[i].iov_base = kmap(kiov[i].kiov_page) +
+                                                kiov[i].kiov_offset;
+               }
+               n = niov;
+       }
 
-        LASSERT (nob <= conn->ksnc_rx_nob_wanted);
+       LASSERT (nob <= conn->ksnc_rx_nob_wanted);
 
-        set_fs (KERNEL_DS);
-        rc = sock_recvmsg (conn->ksnc_sock, &msg, nob, MSG_DONTWAIT);
-        /* NB this is just a boolean.......................^ */
-        set_fs (oldmm);
+       rc = kernel_recvmsg(conn->ksnc_sock, &msg,
+                       (struct kvec *)scratchiov, n, nob, MSG_DONTWAIT);
 
         if (conn->ksnc_msg.ksm_csum != 0) {
                 for (i = 0, sum = rc; sum > 0; i++, sum -= fragnob) {