Whamcloud - gitweb
LU-13004 lnet: remove lnet_extract_iov()
[fs/lustre-release.git] / lnet / klnds / socklnd / socklnd_cb.c
index 8439652..c878b2b 100644 (file)
@@ -24,6 +24,7 @@
  *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+#include <libcfs/linux/linux-mem.h>
 #include "socklnd.h"
 
 struct ksock_tx *
@@ -982,17 +983,17 @@ ksocknal_launch_packet(struct lnet_ni *ni, struct ksock_tx *tx,
 int
 ksocknal_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg)
 {
-       int mpflag = 1;
+       /* '1' for consistency with code that checks !mpflag to restore */
+       unsigned int mpflag = 1;
        int type = lntmsg->msg_type;
        struct lnet_process_id target = lntmsg->msg_target;
-       unsigned int     payload_niov = lntmsg->msg_niov;
-       struct kvec *payload_iov = lntmsg->msg_iov;
-       struct bio_vec  *payload_kiov = lntmsg->msg_kiov;
-       unsigned int     payload_offset = lntmsg->msg_offset;
-       unsigned int     payload_nob = lntmsg->msg_len;
-       struct ksock_tx *tx;
-       int              desc_size;
-       int              rc;
+       unsigned int payload_niov = lntmsg->msg_niov;
+       struct bio_vec *payload_kiov = lntmsg->msg_kiov;
+       unsigned int payload_offset = lntmsg->msg_offset;
+       unsigned int payload_nob = lntmsg->msg_len;
+       struct ksock_tx *tx;
+       int desc_size;
+       int rc;
 
         /* NB 'private' is different depending on what we're sending.
          * Just ignore it... */
@@ -1002,60 +1003,49 @@ ksocknal_send(struct lnet_ni *ni, void *private, struct lnet_msg *lntmsg)
 
        LASSERT (payload_nob == 0 || payload_niov > 0);
        LASSERT (payload_niov <= LNET_MAX_IOV);
-       /* payload is either all vaddrs or all pages */
-       LASSERT (!(payload_kiov != NULL && payload_iov != NULL));
        LASSERT (!in_interrupt ());
 
-       if (payload_iov != NULL)
-               desc_size = offsetof(struct ksock_tx,
-                                    tx_frags.virt.iov[1 + payload_niov]);
-       else
-               desc_size = offsetof(struct ksock_tx,
-                                    tx_frags.paged.kiov[payload_niov]);
+       desc_size = offsetof(struct ksock_tx,
+                            tx_frags.paged.kiov[payload_niov]);
 
         if (lntmsg->msg_vmflush)
-                mpflag = cfs_memory_pressure_get_and_set();
-        tx = ksocknal_alloc_tx(KSOCK_MSG_LNET, desc_size);
-        if (tx == NULL) {
-                CERROR("Can't allocate tx desc type %d size %d\n",
-                       type, desc_size);
-                if (lntmsg->msg_vmflush)
-                        cfs_memory_pressure_restore(mpflag);
-                return (-ENOMEM);
-        }
+               mpflag = memalloc_noreclaim_save();
 
-        tx->tx_conn = NULL;                     /* set when assigned a conn */
-        tx->tx_lnetmsg = lntmsg;
-
-        if (payload_iov != NULL) {
-                tx->tx_kiov = NULL;
-                tx->tx_nkiov = 0;
-                tx->tx_iov = tx->tx_frags.virt.iov;
-                tx->tx_niov = 1 +
-                              lnet_extract_iov(payload_niov, &tx->tx_iov[1],
-                                               payload_niov, payload_iov,
-                                               payload_offset, payload_nob);
-        } else {
-                tx->tx_niov = 1;
-                tx->tx_iov = &tx->tx_frags.paged.iov;
-                tx->tx_kiov = tx->tx_frags.paged.kiov;
-                tx->tx_nkiov = lnet_extract_kiov(payload_niov, tx->tx_kiov,
-                                                 payload_niov, payload_kiov,
-                                                 payload_offset, payload_nob);
-
-                if (payload_nob >= *ksocknal_tunables.ksnd_zc_min_payload)
-                        tx->tx_zc_capable = 1;
-        }
+       tx = ksocknal_alloc_tx(KSOCK_MSG_LNET, desc_size);
+       if (tx == NULL) {
+               CERROR("Can't allocate tx desc type %d size %d\n",
+                      type, desc_size);
+               if (lntmsg->msg_vmflush)
+                       memalloc_noreclaim_restore(mpflag);
+               return -ENOMEM;
+       }
+
+       tx->tx_conn = NULL;                     /* set when assigned a conn */
+       tx->tx_lnetmsg = lntmsg;
+
+       tx->tx_niov = 1;
+       tx->tx_iov = &tx->tx_frags.paged.iov;
+       tx->tx_kiov = tx->tx_frags.paged.kiov;
+       tx->tx_nkiov = lnet_extract_kiov(payload_niov, tx->tx_kiov,
+                                        payload_niov, payload_kiov,
+                                        payload_offset, payload_nob);
+
+       if (payload_nob >= *ksocknal_tunables.ksnd_zc_min_payload)
+               tx->tx_zc_capable = 1;
 
        tx->tx_msg.ksm_csum = 0;
        tx->tx_msg.ksm_type = KSOCK_MSG_LNET;
        tx->tx_msg.ksm_zc_cookies[0] = 0;
        tx->tx_msg.ksm_zc_cookies[1] = 0;
 
-        /* The first fragment will be set later in pro_pack */
-        rc = ksocknal_launch_packet(ni, tx, target);
-        if (!mpflag)
-                cfs_memory_pressure_restore(mpflag);
+       /* The first fragment will be set later in pro_pack */
+       rc = ksocknal_launch_packet(ni, tx, target);
+       /*
+        * We can't test lntsmg->msg_vmflush again as lntmsg may
+        * have been freed.
+        */
+       if (!mpflag)
+               memalloc_noreclaim_restore(mpflag);
 
         if (rc == 0)
                 return (0);
@@ -1384,7 +1374,7 @@ ksocknal_process_receive(struct ksock_conn *conn,
 
 int
 ksocknal_recv(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
-             int delayed, unsigned int niov, struct kvec *iov,
+             int delayed, unsigned int niov,
              struct bio_vec *kiov, unsigned int offset, unsigned int mlen,
              unsigned int rlen)
 {
@@ -1398,21 +1388,19 @@ ksocknal_recv(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
        conn->ksnc_rx_nob_wanted = mlen;
        conn->ksnc_rx_nob_left   = rlen;
 
-        if (mlen == 0 || iov != NULL) {
-                conn->ksnc_rx_nkiov = 0;
-                conn->ksnc_rx_kiov = NULL;
-                conn->ksnc_rx_iov = conn->ksnc_rx_iov_space.iov;
-                conn->ksnc_rx_niov =
-                        lnet_extract_iov(LNET_MAX_IOV, conn->ksnc_rx_iov,
-                                         niov, iov, offset, mlen);
-        } else {
-                conn->ksnc_rx_niov = 0;
-                conn->ksnc_rx_iov  = NULL;
-                conn->ksnc_rx_kiov = conn->ksnc_rx_iov_space.kiov;
-                conn->ksnc_rx_nkiov =
-                        lnet_extract_kiov(LNET_MAX_IOV, conn->ksnc_rx_kiov,
-                                          niov, kiov, offset, mlen);
-        }
+       if (mlen == 0) {
+               conn->ksnc_rx_nkiov = 0;
+               conn->ksnc_rx_kiov = NULL;
+               conn->ksnc_rx_iov = conn->ksnc_rx_iov_space.iov;
+               conn->ksnc_rx_niov = 0;
+       } else {
+               conn->ksnc_rx_niov = 0;
+               conn->ksnc_rx_iov  = NULL;
+               conn->ksnc_rx_kiov = conn->ksnc_rx_iov_space.kiov;
+               conn->ksnc_rx_nkiov =
+                       lnet_extract_kiov(LNET_MAX_IOV, conn->ksnc_rx_kiov,
+                                         niov, kiov, offset, mlen);
+       }
 
         LASSERT (mlen ==
                  lnet_iov_nob (conn->ksnc_rx_niov, conn->ksnc_rx_iov) +
@@ -1942,48 +1930,48 @@ ksocknal_connect(struct ksock_route *route)
 
         route->ksnr_connecting = 1;
 
-        for (;;) {
-                wanted = ksocknal_route_mask() & ~route->ksnr_connected;
+       for (;;) {
+               wanted = ksocknal_route_mask() & ~route->ksnr_connected;
 
-                /* stop connecting if peer_ni/route got closed under me, or
-                 * route got connected while queued */
-                if (peer_ni->ksnp_closing || route->ksnr_deleted ||
-                    wanted == 0) {
-                        retry_later = 0;
-                        break;
-                }
+               /* stop connecting if peer_ni/route got closed under me, or
+                * route got connected while queued */
+               if (peer_ni->ksnp_closing || route->ksnr_deleted ||
+                   wanted == 0) {
+                       retry_later = 0;
+                       break;
+               }
 
-                /* reschedule if peer_ni is connecting to me */
-                if (peer_ni->ksnp_accepting > 0) {
-                        CDEBUG(D_NET,
-                               "peer_ni %s(%d) already connecting to me, retry later.\n",
-                               libcfs_nid2str(peer_ni->ksnp_id.nid), peer_ni->ksnp_accepting);
-                        retry_later = 1;
-                }
+               /* reschedule if peer_ni is connecting to me */
+               if (peer_ni->ksnp_accepting > 0) {
+                       CDEBUG(D_NET,
+                              "peer_ni %s(%d) already connecting to me, retry later.\n",
+                              libcfs_nid2str(peer_ni->ksnp_id.nid), peer_ni->ksnp_accepting);
+                       retry_later = 1;
+               }
 
-                if (retry_later) /* needs reschedule */
-                        break;
+               if (retry_later) /* needs reschedule */
+                       break;
 
-                if ((wanted & (1 << SOCKLND_CONN_ANY)) != 0) {
-                        type = SOCKLND_CONN_ANY;
-                } else if ((wanted & (1 << SOCKLND_CONN_CONTROL)) != 0) {
-                        type = SOCKLND_CONN_CONTROL;
-                } else if ((wanted & (1 << SOCKLND_CONN_BULK_IN)) != 0) {
-                        type = SOCKLND_CONN_BULK_IN;
-                } else {
-                        LASSERT ((wanted & (1 << SOCKLND_CONN_BULK_OUT)) != 0);
-                        type = SOCKLND_CONN_BULK_OUT;
-                }
+               if ((wanted & BIT(SOCKLND_CONN_ANY)) != 0) {
+                       type = SOCKLND_CONN_ANY;
+               } else if ((wanted & BIT(SOCKLND_CONN_CONTROL)) != 0) {
+                       type = SOCKLND_CONN_CONTROL;
+               } else if ((wanted & BIT(SOCKLND_CONN_BULK_IN)) != 0) {
+                       type = SOCKLND_CONN_BULK_IN;
+               } else {
+                       LASSERT ((wanted & BIT(SOCKLND_CONN_BULK_OUT)) != 0);
+                       type = SOCKLND_CONN_BULK_OUT;
+               }
 
                write_unlock_bh(&ksocknal_data.ksnd_global_lock);
 
                if (ktime_get_seconds() >= deadline) {
-                        rc = -ETIMEDOUT;
-                        lnet_connect_console_error(rc, peer_ni->ksnp_id.nid,
-                                                   route->ksnr_ipaddr,
-                                                   route->ksnr_port);
-                        goto failed;
-                }
+                       rc = -ETIMEDOUT;
+                       lnet_connect_console_error(rc, peer_ni->ksnp_id.nid,
+                                                  route->ksnr_ipaddr,
+                                                  route->ksnr_port);
+                       goto failed;
+               }
 
                sock = lnet_connect(peer_ni->ksnp_id.nid,
                                    route->ksnr_myiface,
@@ -1994,23 +1982,23 @@ ksocknal_connect(struct ksock_route *route)
                        goto failed;
                }
 
-                rc = ksocknal_create_conn(peer_ni->ksnp_ni, route, sock, type);
-                if (rc < 0) {
-                        lnet_connect_console_error(rc, peer_ni->ksnp_id.nid,
-                                                   route->ksnr_ipaddr,
-                                                   route->ksnr_port);
-                        goto failed;
-                }
+               rc = ksocknal_create_conn(peer_ni->ksnp_ni, route, sock, type);
+               if (rc < 0) {
+                       lnet_connect_console_error(rc, peer_ni->ksnp_id.nid,
+                                                  route->ksnr_ipaddr,
+                                                  route->ksnr_port);
+                       goto failed;
+               }
 
-                /* A +ve RC means I have to retry because I lost the connection
-                 * race or I have to renegotiate protocol version */
-                retry_later = (rc != 0);
-                if (retry_later)
-                        CDEBUG(D_NET, "peer_ni %s: conn race, retry later.\n",
-                               libcfs_nid2str(peer_ni->ksnp_id.nid));
+               /* A +ve RC means I have to retry because I lost the connection
+                * race or I have to renegotiate protocol version */
+               retry_later = (rc != 0);
+               if (retry_later)
+                       CDEBUG(D_NET, "peer_ni %s: conn race, retry later.\n",
+                              libcfs_nid2str(peer_ni->ksnp_id.nid));
 
                write_lock_bh(&ksocknal_data.ksnd_global_lock);
-        }
+       }
 
         route->ksnr_scheduled = 0;
         route->ksnr_connecting = 0;