Whamcloud - gitweb
LU-13502 lnet: Ensure LNet pings and pushes are always tracked
[fs/lustre-release.git] / lnet / lnet / lib-move.c
index 50fc646..8c297f9 100644 (file)
@@ -338,54 +338,6 @@ lnet_copy_iov2iov(unsigned int ndiov, struct kvec *diov, unsigned int doffset,
 }
 EXPORT_SYMBOL(lnet_copy_iov2iov);
 
-int
-lnet_extract_iov(int dst_niov, struct kvec *dst,
-                int src_niov, struct kvec *src,
-                unsigned int offset, unsigned int len)
-{
-       /* Initialise 'dst' to the subset of 'src' starting at 'offset',
-        * for exactly 'len' bytes, and return the number of entries.
-        * NB not destructive to 'src' */
-       unsigned int    frag_len;
-       unsigned int    niov;
-
-       if (len == 0)                           /* no data => */
-               return (0);                     /* no frags */
-
-       LASSERT(src_niov > 0);
-       while (offset >= src->iov_len) {      /* skip initial frags */
-               offset -= src->iov_len;
-               src_niov--;
-               src++;
-               LASSERT(src_niov > 0);
-       }
-
-       niov = 1;
-       for (;;) {
-               LASSERT(src_niov > 0);
-               LASSERT((int)niov <= dst_niov);
-
-               frag_len = src->iov_len - offset;
-               dst->iov_base = ((char *)src->iov_base) + offset;
-
-               if (len <= frag_len) {
-                       dst->iov_len = len;
-                       return (niov);
-               }
-
-               dst->iov_len = frag_len;
-
-               len -= frag_len;
-               dst++;
-               src++;
-               niov++;
-               src_niov--;
-               offset = 0;
-       }
-}
-EXPORT_SYMBOL(lnet_extract_iov);
-
-
 unsigned int
 lnet_kiov_nob(unsigned int niov, struct bio_vec *kiov)
 {
@@ -707,7 +659,7 @@ lnet_ni_recv(struct lnet_ni *ni, void *private, struct lnet_msg *msg,
        }
 
        rc = (ni->ni_net->net_lnd->lnd_recv)(ni, private, msg, delayed,
-                                            niov, NULL, kiov, offset, mlen,
+                                            niov, kiov, offset, mlen,
                                             rlen);
        if (rc < 0)
                lnet_finalize(msg, rc);
@@ -753,12 +705,12 @@ lnet_prep_send(struct lnet_msg *msg, int type, struct lnet_process_id target,
 static void
 lnet_ni_send(struct lnet_ni *ni, struct lnet_msg *msg)
 {
-       void   *priv = msg->msg_private;
+       void *priv = msg->msg_private;
        int rc;
 
-       LASSERT (!in_interrupt ());
-       LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
-                (msg->msg_txcredit && msg->msg_peertxcredit));
+       LASSERT(!in_interrupt());
+       LASSERT(ni->ni_nid == LNET_NID_LO_0 ||
+               (msg->msg_txcredit && msg->msg_peertxcredit));
 
        rc = (ni->ni_net->net_lnd->lnd_send)(ni, priv, msg);
        if (rc < 0) {
@@ -1328,6 +1280,7 @@ lnet_compare_gw_lpnis(struct lnet_peer_ni *p1, struct lnet_peer_ni *p2)
 static struct lnet_peer_ni *
 lnet_select_peer_ni(struct lnet_ni *best_ni, lnet_nid_t dst_nid,
                    struct lnet_peer *peer,
+                   struct lnet_peer_ni *best_lpni,
                    struct lnet_peer_net *peer_net)
 {
        /*
@@ -1339,11 +1292,12 @@ lnet_select_peer_ni(struct lnet_ni *best_ni, lnet_nid_t dst_nid,
         * credits are equal, we round-robin over the peer_ni.
         */
        struct lnet_peer_ni *lpni = NULL;
-       struct lnet_peer_ni *best_lpni = NULL;
-       int best_lpni_credits = INT_MIN;
+       int best_lpni_credits = (best_lpni) ? best_lpni->lpni_txcredits :
+               INT_MIN;
+       int best_lpni_healthv = (best_lpni) ?
+               atomic_read(&best_lpni->lpni_healthv) : 0;
        bool preferred = false;
        bool ni_is_pref;
-       int best_lpni_healthv = 0;
        int lpni_healthv;
 
        while ((lpni = lnet_get_next_peer_ni_locked(peer, peer_net, lpni))) {
@@ -1423,20 +1377,41 @@ lnet_select_peer_ni(struct lnet_ni *best_ni, lnet_nid_t dst_nid,
 
 /*
  * Prerequisite: the best_ni should already be set in the sd
+ * Find the best lpni.
+ * If the net id is provided then restrict lpni selection on
+ * that particular net.
+ * Otherwise find any reachable lpni. When dealing with an MR
+ * gateway and it has multiple lpnis which we can use
+ * we want to select the best one from the list of reachable
+ * ones.
  */
 static inline struct lnet_peer_ni *
-lnet_find_best_lpni_on_net(struct lnet_ni *lni, lnet_nid_t dst_nid,
-                          struct lnet_peer *peer, __u32 net_id)
+lnet_find_best_lpni(struct lnet_ni *lni, lnet_nid_t dst_nid,
+                   struct lnet_peer *peer, __u32 net_id)
 {
        struct lnet_peer_net *peer_net;
+       __u32 any_net = LNET_NIDNET(LNET_NID_ANY);
+
+       /* find the best_lpni on any local network */
+       if (net_id == any_net) {
+               struct lnet_peer_ni *best_lpni = NULL;
+               struct lnet_peer_net *lpn;
+               list_for_each_entry(lpn, &peer->lp_peer_nets, lpn_peer_nets) {
+                       /* no net specified find any reachable peer ni */
+                       if (!lnet_islocalnet_locked(lpn->lpn_net_id))
+                               continue;
+                       best_lpni = lnet_select_peer_ni(lni, dst_nid, peer,
+                                                       best_lpni, lpn);
+               }
 
-       /*
-        * The gateway is Multi-Rail capable so now we must select the
-        * proper peer_ni
-        */
+               return best_lpni;
+       }
+       /* restrict on the specified net */
        peer_net = lnet_peer_get_net_locked(peer, net_id);
+       if (peer_net)
+               return lnet_select_peer_ni(lni, dst_nid, peer, NULL, peer_net);
 
-       return lnet_select_peer_ni(lni, dst_nid, peer, peer_net);
+       return NULL;
 }
 
 /* Compare route priorities and hop counts */
@@ -1472,6 +1447,9 @@ lnet_find_route_locked(struct lnet_remotenet *rnet, __u32 src_net,
        struct lnet_route *route;
        int rc;
 
+       CDEBUG(D_NET, "Looking up a route to %s, from %s\n",
+              libcfs_net2str(rnet->lrn_net), libcfs_net2str(src_net));
+
        best_route = last_route = NULL;
        list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
                if (!lnet_is_route_alive(route))
@@ -1483,16 +1461,17 @@ lnet_find_route_locked(struct lnet_remotenet *rnet, __u32 src_net,
                 * the best interface available.
                 */
                if (!best_route) {
-                       lpni = lnet_find_best_lpni_on_net(NULL, LNET_NID_ANY,
-                                                         route->lr_gateway,
-                                                         src_net);
+                       lpni = lnet_find_best_lpni(NULL, LNET_NID_ANY,
+                                                  route->lr_gateway,
+                                                  src_net);
                        if (lpni) {
                                best_route = last_route = route;
                                best_gw_ni = lpni;
-                       } else
-                               CERROR("Gateway %s does not have a peer NI on net %s\n",
+                       } else {
+                               CDEBUG(D_NET, "Gateway %s does not have a peer NI on net %s\n",
                                       libcfs_nid2str(route->lr_gateway->lp_primary_nid),
                                       libcfs_net2str(src_net));
+                       }
 
                        continue;
                }
@@ -1505,11 +1484,12 @@ lnet_find_route_locked(struct lnet_remotenet *rnet, __u32 src_net,
                if (rc == -1)
                        continue;
 
-               lpni = lnet_find_best_lpni_on_net(NULL, LNET_NID_ANY,
-                                                 route->lr_gateway,
-                                                 src_net);
+               lpni = lnet_find_best_lpni(NULL, LNET_NID_ANY,
+                                          route->lr_gateway,
+                                          src_net);
+               /* restrict the lpni on the src_net if specified */
                if (!lpni) {
-                       CERROR("Gateway %s does not have a peer NI on net %s\n",
+                       CDEBUG(D_NET, "Gateway %s does not have a peer NI on net %s\n",
                               libcfs_nid2str(route->lr_gateway->lp_primary_nid),
                               libcfs_net2str(src_net));
                        continue;
@@ -2001,7 +1981,13 @@ lnet_handle_find_routed_path(struct lnet_send_data *sd,
        struct lnet_route *last_route = NULL;
        struct lnet_peer_ni *lpni = NULL;
        struct lnet_peer_ni *gwni = NULL;
-       lnet_nid_t src_nid = sd->sd_src_nid;
+       bool route_found = false;
+       lnet_nid_t src_nid = (sd->sd_src_nid != LNET_NID_ANY) ? sd->sd_src_nid :
+               (sd->sd_best_ni != NULL) ? sd->sd_best_ni->ni_nid :
+               LNET_NID_ANY;
+
+       CDEBUG(D_NET, "using src nid %s for route restriction\n",
+              libcfs_nid2str(src_nid));
 
        /* If a router nid was specified then we are replying to a GET or
         * sending an ACK. In this case we use the gateway associated with the
@@ -2009,15 +1995,20 @@ lnet_handle_find_routed_path(struct lnet_send_data *sd,
         */
        if (sd->sd_rtr_nid != LNET_NID_ANY) {
                gwni = lnet_find_peer_ni_locked(sd->sd_rtr_nid);
-               if (!gwni) {
-                       CERROR("No peer NI for gateway %s\n",
+               if (gwni) {
+                       gw = gwni->lpni_peer_net->lpn_peer;
+                       lnet_peer_ni_decref_locked(gwni);
+                       if (gw->lp_rtr_refcount) {
+                               local_lnet = LNET_NIDNET(sd->sd_rtr_nid);
+                               route_found = true;
+                       }
+               } else {
+                       CWARN("No peer NI for gateway %s. Attempting to find an alternative route.\n",
                               libcfs_nid2str(sd->sd_rtr_nid));
-                       return -EHOSTUNREACH;
                }
-               gw = gwni->lpni_peer_net->lpn_peer;
-               lnet_peer_ni_decref_locked(gwni);
-               local_lnet = LNET_NIDNET(sd->sd_rtr_nid);
-       } else {
+       }
+
+       if (!route_found) {
                /* we've already looked up the initial lpni using dst_nid */
                lpni = sd->sd_best_lpni;
                /* the peer tree must be in existence */
@@ -2049,12 +2040,12 @@ lnet_handle_find_routed_path(struct lnet_send_data *sd,
                        return -EHOSTUNREACH;
                }
 
-               sd->sd_best_lpni = lnet_find_best_lpni_on_net(sd->sd_best_ni,
-                                                             sd->sd_dst_nid,
-                                                             lp,
-                                                             best_lpn->lpn_net_id);
+               sd->sd_best_lpni = lnet_find_best_lpni(sd->sd_best_ni,
+                                                      sd->sd_dst_nid,
+                                                      lp,
+                                                      best_lpn->lpn_net_id);
                if (!sd->sd_best_lpni) {
-                       CERROR("peer %s down\n",
+                       CERROR("peer %s is unreachable\n",
                               libcfs_nid2str(sd->sd_dst_nid));
                        return -EHOSTUNREACH;
                }
@@ -2404,9 +2395,9 @@ lnet_handle_any_mr_dsta(struct lnet_send_data *sd)
                                        lnet_msg_discovery(sd->sd_msg));
        if (sd->sd_best_ni) {
                sd->sd_best_lpni =
-                 lnet_find_best_lpni_on_net(sd->sd_best_ni, sd->sd_dst_nid,
-                                            sd->sd_peer,
-                                            sd->sd_best_ni->ni_net->net_id);
+                 lnet_find_best_lpni(sd->sd_best_ni, sd->sd_dst_nid,
+                                     sd->sd_peer,
+                                     sd->sd_best_ni->ni_net->net_id);
 
                /*
                 * if we're successful in selecting a peer_ni on the local
@@ -2623,12 +2614,14 @@ static int
 lnet_select_pathway(lnet_nid_t src_nid, lnet_nid_t dst_nid,
                    struct lnet_msg *msg, lnet_nid_t rtr_nid)
 {
-       struct lnet_peer_ni     *lpni;
-       struct lnet_peer        *peer;
-       struct lnet_send_data   send_data;
-       int                     cpt, rc;
-       int                     md_cpt;
-       __u32                   send_case = 0;
+       struct lnet_peer_ni *lpni;
+       struct lnet_peer *peer;
+       struct lnet_send_data send_data;
+       int cpt, rc;
+       int md_cpt;
+       __u32 send_case = 0;
+       bool final_hop;
+       bool mr_forwarding_allowed;
 
        memset(&send_data, 0, sizeof(send_data));
 
@@ -2656,7 +2649,7 @@ again:
         */
        send_data.sd_msg = msg;
        send_data.sd_cpt = cpt;
-       if (LNET_NETTYP(LNET_NIDNET(dst_nid)) == LOLND) {
+       if (dst_nid == LNET_NID_LO_0) {
                rc = lnet_handle_lo_send(&send_data);
                lnet_net_unlock(cpt);
                return rc;
@@ -2712,17 +2705,49 @@ again:
        else
                send_case |= REMOTE_DST;
 
+       final_hop = false;
+       if (msg->msg_routing && (send_case & LOCAL_DST))
+               final_hop = true;
+
+       /* Determine whether to allow MR forwarding for this message.
+        * NB: MR forwarding is allowed if the message originator and the
+        * destination are both MR capable, and the destination lpni that was
+        * originally chosen by the originator is unhealthy or down.
+        * We check the MR capability of the destination further below
+        */
+       mr_forwarding_allowed = false;
+       if (final_hop) {
+               struct lnet_peer *src_lp;
+               struct lnet_peer_ni *src_lpni;
+
+               src_lpni = lnet_nid2peerni_locked(msg->msg_hdr.src_nid,
+                                                 LNET_NID_ANY, cpt);
+               /* We don't fail the send if we hit any errors here. We'll just
+                * try to send it via non-multi-rail criteria
+                */
+               if (!IS_ERR(src_lpni)) {
+                       src_lp = lpni->lpni_peer_net->lpn_peer;
+                       if (lnet_peer_is_multi_rail(src_lp) &&
+                           !lnet_is_peer_ni_alive(lpni))
+                               mr_forwarding_allowed = true;
+
+               }
+               CDEBUG(D_NET, "msg %p MR forwarding %s\n", msg,
+                      mr_forwarding_allowed ? "allowed" : "not allowed");
+       }
+
        /*
         * Deal with the peer as NMR in the following cases:
         * 1. the peer is NMR
         * 2. We're trying to recover a specific peer NI
-        * 3. I'm a router sending to the final destination
+        * 3. I'm a router sending to the final destination and MR forwarding is
+        *    not allowed for this message (as determined above).
         *    In this case the source of the message would've
         *    already selected the final destination so my job
         *    is to honor the selection.
         */
        if (!lnet_peer_is_multi_rail(peer) || msg->msg_recovery ||
-           (msg->msg_routing && (send_case & LOCAL_DST)))
+           (final_hop && !mr_forwarding_allowed))
                send_case |= NMR_DST;
        else
                send_case |= MR_DST;
@@ -3584,11 +3609,11 @@ lnet_send_ping(lnet_nid_t dest_nid,
        md.length    = LNET_PING_INFO_SIZE(nnis);
        md.threshold = 2; /* GET/REPLY */
        md.max_size  = 0;
-       md.options   = LNET_MD_TRUNCATE;
+       md.options   = LNET_MD_TRUNCATE | LNET_MD_TRACK_RESPONSE;
        md.user_ptr  = user_data;
        md.handler   = handler;
 
-       rc = LNetMDBind(md, LNET_UNLINK, mdh);
+       rc = LNetMDBind(&md, LNET_UNLINK, mdh);
        if (rc) {
                lnet_ping_buffer_decref(pbuf);
                CERROR("Can't bind MD: %d\n", rc);
@@ -4737,7 +4762,7 @@ LNetPut(lnet_nid_t self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
                       libcfs_id2str(target));
                return -ENOMEM;
        }
-       msg->msg_vmflush = !!memory_pressure_get();
+       msg->msg_vmflush = !!(current->flags & PF_MEMALLOC);
 
        cpt = lnet_cpt_of_cookie(mdh.cookie);
 
@@ -5047,14 +5072,14 @@ EXPORT_SYMBOL(LNetGet);
 int
 LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
 {
-       struct list_head        *e;
+       struct list_head *e;
        struct lnet_ni *ni = NULL;
        struct lnet_remotenet *rnet;
-       __u32                   dstnet = LNET_NIDNET(dstnid);
-       int                     hops;
-       int                     cpt;
-       __u32                   order = 2;
-       struct list_head        *rn_list;
+       __u32 dstnet = LNET_NIDNET(dstnid);
+       int hops;
+       int cpt;
+       __u32 order = 2;
+       struct list_head *rn_list;
 
        /* if !local_nid_dist_zero, I don't return a distance of 0 ever
         * (when lustre sees a distance of 0, it substitutes 0@lo), so I
@@ -5070,7 +5095,7 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
                        if (srcnidp != NULL)
                                *srcnidp = dstnid;
                        if (orderp != NULL) {
-                               if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND)
+                               if (dstnid == LNET_NID_LO_0)
                                        *orderp = 0;
                                else
                                        *orderp = 1;