Whamcloud - gitweb
LU-6142 lnet: use list_first_entry() in lnet/lnet subdirectory.
[fs/lustre-release.git] / lnet / lnet / lib-move.c
index 34873e8..81261c9 100644 (file)
@@ -229,9 +229,9 @@ lnet_fail_nid(lnet_nid_t nid4, unsigned int threshold)
 
        lnet_net_unlock(0);
 
-       while (!list_empty(&cull)) {
-               tp = list_entry(cull.next, struct lnet_test_peer, tp_list);
-
+       while ((tp = list_first_entry_or_null(&cull,
+                                             struct lnet_test_peer,
+                                             tp_list)) != NULL) {
                list_del(&tp->tp_list);
                LIBCFS_FREE(tp, sizeof(*tp));
        }
@@ -282,10 +282,10 @@ fail_peer(struct lnet_nid *nid, int outgoing)
 
        lnet_net_unlock(0);
 
-       while (!list_empty(&cull)) {
-               tp = list_entry(cull.next, struct lnet_test_peer, tp_list);
+       while ((tp = list_first_entry_or_null(&cull,
+                                             struct lnet_test_peer,
+                                             tp_list)) != NULL) {
                list_del(&tp->tp_list);
-
                LIBCFS_FREE(tp, sizeof(*tp));
        }
 
@@ -1034,7 +1034,7 @@ lnet_post_routed_recv_locked(struct lnet_msg *msg, int do_recv)
        }
 
        LASSERT(!list_empty(&rbp->rbp_bufs));
-       rb = list_entry(rbp->rbp_bufs.next, struct lnet_rtrbuf, rb_list);
+       rb = list_first_entry(&rbp->rbp_bufs, struct lnet_rtrbuf, rb_list);
        list_del(&rb->rb_list);
 
        msg->msg_niov = rbp->rbp_npages;
@@ -1074,8 +1074,8 @@ lnet_return_tx_credits_locked(struct lnet_msg *msg)
                tq->tq_credits++;
                atomic_inc(&ni->ni_tx_credits);
                if (tq->tq_credits <= 0) {
-                       msg2 = list_entry(tq->tq_delayed.next,
-                                         struct lnet_msg, msg_list);
+                       msg2 = list_first_entry(&tq->tq_delayed,
+                                               struct lnet_msg, msg_list);
                        list_del(&msg2->msg_list);
 
                        LASSERT(msg2->msg_txni == ni);
@@ -1102,8 +1102,8 @@ lnet_return_tx_credits_locked(struct lnet_msg *msg)
                if (txpeer->lpni_txcredits <= 0) {
                        int msg2_cpt;
 
-                       msg2 = list_entry(txpeer->lpni_txq.next,
-                                             struct lnet_msg, msg_list);
+                       msg2 = list_first_entry(&txpeer->lpni_txq,
+                                               struct lnet_msg, msg_list);
                        list_del(&msg2->msg_list);
                        spin_unlock(&txpeer->lpni_lock);
 
@@ -1155,8 +1155,8 @@ lnet_schedule_blocked_locked(struct lnet_rtrbufpool *rbp)
 
        if (list_empty(&rbp->rbp_msgs))
                return;
-       msg = list_entry(rbp->rbp_msgs.next,
-                        struct lnet_msg, msg_list);
+       msg = list_first_entry(&rbp->rbp_msgs,
+                              struct lnet_msg, msg_list);
        list_del(&msg->msg_list);
 
        (void)lnet_post_routed_recv_locked(msg, 1);
@@ -1260,8 +1260,8 @@ routing_off:
                } else if (!list_empty(&lp->lp_rtrq)) {
                        int msg2_cpt;
 
-                       msg2 = list_entry(lp->lp_rtrq.next,
-                                         struct lnet_msg, msg_list);
+                       msg2 = list_first_entry(&lp->lp_rtrq,
+                                               struct lnet_msg, msg_list);
                        list_del(&msg2->msg_list);
                        msg2_cpt = msg2->msg_rx_cpt;
                        spin_unlock(&lp->lp_lock);
@@ -1636,11 +1636,13 @@ lnet_get_best_ni(struct lnet_net *local_net, struct lnet_ni *best_ni,
        __u32 best_sel_prio;
        unsigned int best_dev_prio;
        unsigned int dev_idx = UINT_MAX;
-       struct page *page = lnet_get_first_page(md, offset);
-       msg->msg_rdma_force = lnet_is_rdma_only_page(page);
+       bool gpu = md ? (md->md_flags & LNET_MD_FLAG_GPU) : false;
+
+       if (gpu) {
+               struct page *page = lnet_get_first_page(md, offset);
 
-       if (msg->msg_rdma_force)
                dev_idx = lnet_get_dev_idx(page);
+       }
 
        /*
         * If there is no peer_ni that we can send to on this network,
@@ -1692,7 +1694,7 @@ lnet_get_best_ni(struct lnet_net *local_net, struct lnet_ni *best_ni,
                 * All distances smaller than the NUMA range
                 * are treated equally.
                 */
-               if (distance < lnet_numa_range)
+               if (!gpu && distance < lnet_numa_range)
                        distance = lnet_numa_range;
 
                /*
@@ -1837,15 +1839,18 @@ lnet_handle_send(struct lnet_send_data *sd)
        __u32 send_case = sd->sd_send_case;
        int rc;
        __u32 routing = send_case & REMOTE_DST;
-        struct lnet_rsp_tracker *rspt;
+       struct lnet_rsp_tracker *rspt;
 
        /* Increment sequence number of the selected peer, peer net,
         * local ni and local net so that we pick the next ones
         * in Round Robin.
         */
-       best_lpni->lpni_peer_net->lpn_seq++;
+       best_lpni->lpni_peer_net->lpn_peer->lp_send_seq++;
+       best_lpni->lpni_peer_net->lpn_seq =
+               best_lpni->lpni_peer_net->lpn_peer->lp_send_seq;
        best_lpni->lpni_seq = best_lpni->lpni_peer_net->lpn_seq;
-       best_ni->ni_net->net_seq++;
+       the_lnet.ln_net_seq++;
+       best_ni->ni_net->net_seq = the_lnet.ln_net_seq;
        best_ni->ni_seq = best_ni->ni_net->net_seq;
 
        CDEBUG(D_NET, "%s NI seq info: [%d:%d:%d:%u] %s LPNI seq info [%d:%d:%d:%u]\n",
@@ -1934,6 +1939,11 @@ lnet_handle_send(struct lnet_send_data *sd)
                 * lnet_select_pathway() function and is never changed.
                 * It's safe to use it here.
                 */
+               final_dst_lpni->lpni_peer_net->lpn_peer->lp_send_seq++;
+               final_dst_lpni->lpni_peer_net->lpn_seq =
+                       final_dst_lpni->lpni_peer_net->lpn_peer->lp_send_seq;
+               final_dst_lpni->lpni_seq =
+                       final_dst_lpni->lpni_peer_net->lpn_seq;
                msg->msg_hdr.dest_nid = final_dst_lpni->lpni_nid;
        } else {
                /*
@@ -2104,7 +2114,7 @@ lnet_initiate_peer_discovery(struct lnet_peer_ni *lpni, struct lnet_msg *msg,
                return rc;
        }
 
-       new_lpni = lnet_find_peer_ni_locked(lnet_nid_to_nid4(&lpni->lpni_nid));
+       new_lpni = lnet_peer_ni_find_locked(&lpni->lpni_nid);
        if (!new_lpni) {
                lnet_peer_ni_decref_locked(lpni);
                return -ENOENT;
@@ -2166,8 +2176,10 @@ lnet_handle_find_routed_path(struct lnet_send_data *sd,
        int best_lpn_healthv = 0;
        __u32 best_lpn_sel_prio = LNET_MAX_SELECTION_PRIORITY;
 
-       CDEBUG(D_NET, "using src nid %s for route restriction\n",
-              src_nid ? libcfs_nidstr(src_nid) : "ANY");
+       CDEBUG(D_NET, "%s route (%s) from local NI %s to destination %s\n",
+              LNET_NID_IS_ANY(&sd->sd_rtr_nid) ? "Lookup" : "Specified",
+              libcfs_nidstr(&sd->sd_rtr_nid), libcfs_nidstr(src_nid),
+              libcfs_nidstr(&sd->sd_dst_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
@@ -2182,12 +2194,12 @@ lnet_handle_find_routed_path(struct lnet_send_data *sd,
                                route_found = true;
                } else {
                        CWARN("No peer NI for gateway %s. Attempting to find an alternative route.\n",
-                              libcfs_nidstr(&sd->sd_rtr_nid));
+                             libcfs_nidstr(&sd->sd_rtr_nid));
                }
        }
 
        if (!route_found) {
-               if (sd->sd_msg->msg_routing || (src_nid && !LNET_NID_IS_ANY(src_nid))) {
+               if (sd->sd_msg->msg_routing || !LNET_NID_IS_ANY(src_nid)) {
                        /* If I'm routing this message then I need to find the
                         * next hop based on the destination NID
                         *
@@ -2203,6 +2215,8 @@ lnet_handle_find_routed_path(struct lnet_send_data *sd,
                                       libcfs_nidstr(&sd->sd_dst_nid));
                                return -EHOSTUNREACH;
                        }
+                       CDEBUG(D_NET, "best_rnet %s\n",
+                              libcfs_net2str(best_rnet->lrn_net));
                } else {
                        /* we've already looked up the initial lpni using
                         * dst_nid
@@ -2219,10 +2233,18 @@ lnet_handle_find_routed_path(struct lnet_send_data *sd,
                                if (!rnet)
                                        continue;
 
-                               if (!best_lpn) {
-                                       best_lpn = lpn;
-                                       best_rnet = rnet;
-                               }
+                               if (!best_lpn)
+                                       goto use_lpn;
+                               else
+                                       CDEBUG(D_NET, "n[%s, %s] h[%d, %d], p[%u, %u], s[%d, %d]\n",
+                                              libcfs_net2str(lpn->lpn_net_id),
+                                              libcfs_net2str(best_lpn->lpn_net_id),
+                                              lpn->lpn_healthv,
+                                              best_lpn->lpn_healthv,
+                                              lpn->lpn_sel_priority,
+                                              best_lpn->lpn_sel_priority,
+                                              lpn->lpn_seq,
+                                              best_lpn->lpn_seq);
 
                                /* select the preferred peer net */
                                if (best_lpn_healthv > lpn->lpn_healthv)
@@ -2250,6 +2272,9 @@ use_lpn:
                                return -EHOSTUNREACH;
                        }
 
+                       CDEBUG(D_NET, "selected best_lpn %s\n",
+                              libcfs_net2str(best_lpn->lpn_net_id));
+
                        sd->sd_best_lpni = lnet_find_best_lpni(sd->sd_best_ni,
                                                               lnet_nid_to_nid4(&sd->sd_dst_nid),
                                                               lp,
@@ -2264,12 +2289,6 @@ use_lpn:
                         * NI's so update the final destination we selected
                         */
                        sd->sd_final_dst_lpni = sd->sd_best_lpni;
-
-                       /* Increment the sequence number of the remote lpni so
-                        * we can round robin over the different interfaces of
-                        * the remote lpni
-                        */
-                       sd->sd_best_lpni->lpni_seq++;
                }
 
                /*
@@ -2339,14 +2358,12 @@ use_lpn:
        *gw_peer = gw;
 
        /*
-        * increment the sequence numbers since now we're sure we're
-        * going to use this path
+        * increment the sequence number since now we're sure we're
+        * going to use this route
         */
        if (LNET_NID_IS_ANY(&sd->sd_rtr_nid)) {
                LASSERT(best_route && last_route);
                best_route->lr_seq = last_route->lr_seq + 1;
-               if (best_lpn)
-                       best_lpn->lpn_seq++;
        }
 
        return 0;
@@ -2423,7 +2440,15 @@ lnet_find_best_ni_on_local_net(struct lnet_peer *peer, int md_cpt,
        __u32 lpn_sel_prio;
        __u32 best_net_sel_prio = LNET_MAX_SELECTION_PRIORITY;
        __u32 net_sel_prio;
-       bool exit = false;
+
+       /* if this is a discovery message and lp_disc_net_id is
+        * specified then use that net to send the discovery on.
+        */
+       if (discovery && peer->lp_disc_net_id) {
+               best_lpn = lnet_peer_get_net_locked(peer, peer->lp_disc_net_id);
+               if (best_lpn && lnet_get_net_locked(best_lpn->lpn_net_id))
+                       goto select_best_ni;
+       }
 
        /*
         * The peer can have multiple interfaces, some of them can be on
@@ -2446,18 +2471,25 @@ lnet_find_best_ni_on_local_net(struct lnet_peer *peer, int md_cpt,
                net_healthv = lnet_get_net_healthv_locked(net);
                net_sel_prio = net->net_sel_priority;
 
-               /*
-                * if this is a discovery message and lp_disc_net_id is
-                * specified then use that net to send the discovery on.
-                */
-               if (peer->lp_disc_net_id == lpn->lpn_net_id &&
-                   discovery) {
-                       exit = true;
-                       goto select_lpn;
-               }
-
                if (!best_lpn)
                        goto select_lpn;
+               else
+                       CDEBUG(D_NET,
+                              "n[%s, %s] ph[%d, %d], pp[%u, %u], nh[%d, %d], np[%u, %u], ps[%u, %u], ns[%u, %u]\n",
+                              libcfs_net2str(lpn->lpn_net_id),
+                              libcfs_net2str(best_lpn->lpn_net_id),
+                              lpn->lpn_healthv,
+                              best_lpn_healthv,
+                              lpn_sel_prio,
+                              best_lpn_sel_prio,
+                              net_healthv,
+                              best_net_healthv,
+                              net_sel_prio,
+                              best_net_sel_prio,
+                              lpn->lpn_seq,
+                              best_lpn->lpn_seq,
+                              net->net_seq,
+                              best_net->net_seq);
 
                /* always select the lpn with the best health */
                if (best_lpn_healthv > lpn->lpn_healthv)
@@ -2497,15 +2529,15 @@ select_lpn:
                best_lpn_sel_prio = lpn_sel_prio;
                best_lpn = lpn;
                best_net = net;
-
-               if (exit)
-                       break;
        }
 
        if (best_lpn) {
                /* Select the best NI on the same net as best_lpn chosen
                 * above
                 */
+select_best_ni:
+               CDEBUG(D_NET, "selected best_lpn %s\n",
+                      libcfs_net2str(best_lpn->lpn_net_id));
                best_ni = lnet_find_best_ni_on_spec_net(NULL, peer, best_lpn,
                                                        msg, md_cpt);
        }
@@ -3033,7 +3065,7 @@ again:
                 * try to send it via non-multi-rail criteria
                 */
                if (!IS_ERR(src_lpni)) {
-                       /* Drop ref taken by lnet_nid2peerni_locked() */
+                       /* Drop ref taken by lnet_peerni_by_nid_locked() */
                        lnet_peer_ni_decref_locked(src_lpni);
                        src_lp = lpni->lpni_peer_net->lpn_peer;
                        if (lnet_peer_is_multi_rail(src_lp) &&
@@ -3605,9 +3637,9 @@ lnet_clean_local_ni_recoveryq(void)
        /* This is only called when the monitor thread has stopped */
        lnet_net_lock(0);
 
-       while (!list_empty(&the_lnet.ln_mt_localNIRecovq)) {
-               ni = list_entry(the_lnet.ln_mt_localNIRecovq.next,
-                               struct lnet_ni, ni_recovery);
+       while ((ni = list_first_entry_or_null(&the_lnet.ln_mt_localNIRecovq,
+                                             struct lnet_ni,
+                                             ni_recovery)) != NULL) {
                list_del_init(&ni->ni_recovery);
                lnet_ni_lock(ni);
                lnet_unlink_ni_recovery_mdh_locked(ni, 0, true);
@@ -3778,7 +3810,7 @@ lnet_recover_peer_nis(void)
                                            true);
                        lnet_net_lock(0);
                        /*
-                        * lnet_find_peer_ni_locked() grabs a refcount for
+                        * lnet_peer_ni_find_locked() grabs a refcount for
                         * us. No need to take it explicitly.
                         */
                        lpni = lnet_peer_ni_find_locked(&nid);
@@ -3801,7 +3833,7 @@ lnet_recover_peer_nis(void)
                                spin_unlock(&lpni->lpni_lock);
                        }
 
-                       /* Drop the ref taken by lnet_find_peer_ni_locked() */
+                       /* Drop the ref taken by lnet_peer_ni_find_locked() */
                        lnet_peer_ni_decref_locked(lpni);
                        lnet_net_unlock(0);
                } else
@@ -3889,7 +3921,7 @@ lnet_send_ping(struct lnet_nid *dest_nid,
               void *user_data, lnet_handler_t handler, bool recovery)
 {
        struct lnet_md md = { NULL };
-       struct lnet_process_id id;
+       struct lnet_processid id;
        struct lnet_ping_buffer *pbuf;
        int rc;
 
@@ -3921,9 +3953,9 @@ lnet_send_ping(struct lnet_nid *dest_nid,
                goto fail_error;
        }
        id.pid = LNET_PID_LUSTRE;
-       id.nid = lnet_nid_to_nid4(dest_nid);
+       id.nid = *dest_nid;
 
-       rc = LNetGet(LNET_NID_ANY, *mdh, id,
+       rc = LNetGet(NULL, *mdh, &id,
                     LNET_RESERVED_PORTAL,
                     LNET_PROTO_PING_MATCHBITS, 0, recovery);
 
@@ -4134,7 +4166,9 @@ void lnet_monitor_thr_stop(void)
        complete(&the_lnet.ln_mt_wait_complete);
 
        /* block until monitor thread signals that it's done */
+       mutex_unlock(&the_lnet.ln_api_mutex);
        down(&the_lnet.ln_mt_signal);
+       mutex_lock(&the_lnet.ln_api_mutex);
        LASSERT(the_lnet.ln_mt_state == LNET_MT_STATE_SHUTDOWN);
 
        /* perform cleanup tasks */
@@ -4643,9 +4677,8 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr,
                goto drop;
        }
 
-       /* FIXME need to support large-addr nid */
        if (!list_empty(&the_lnet.ln_drop_rules) &&
-           lnet_drop_rule_match(hdr, lnet_nid_to_nid4(&ni->ni_nid), NULL)) {
+           lnet_drop_rule_match(hdr, &ni->ni_nid, NULL)) {
                CDEBUG(D_NET,
                       "%s, src %s, dst %s: Dropping %s to simulate silent message loss\n",
                       libcfs_nidstr(from_nid), libcfs_nidstr(&src_nid),
@@ -4690,7 +4723,7 @@ lnet_parse(struct lnet_ni *ni, struct lnet_hdr *hdr,
                lnet_msg_free(msg);
                if (rc == -ESHUTDOWN)
                        /* We are shutting down.  Don't do anything more */
-                       return 0;
+                       return rc;
                goto drop;
        }
 
@@ -4812,11 +4845,12 @@ EXPORT_SYMBOL(lnet_parse);
 void
 lnet_drop_delayed_msg_list(struct list_head *head, char *reason)
 {
-       while (!list_empty(head)) {
+       struct lnet_msg *msg;
+
+       while ((msg = list_first_entry_or_null(head, struct lnet_msg,
+                                              msg_list)) != NULL) {
                struct lnet_processid id = {};
-               struct lnet_msg *msg;
 
-               msg = list_entry(head->next, struct lnet_msg, msg_list);
                list_del(&msg->msg_list);
 
                id.nid = msg->msg_hdr.src_nid;
@@ -4856,11 +4890,12 @@ lnet_drop_delayed_msg_list(struct list_head *head, char *reason)
 void
 lnet_recv_delayed_msg_list(struct list_head *head)
 {
-       while (!list_empty(head)) {
-               struct lnet_msg *msg;
+       struct lnet_msg *msg;
+
+       while ((msg = list_first_entry_or_null(head, struct lnet_msg,
+                                              msg_list)) != NULL) {
                struct lnet_processid id;
 
-               msg = list_entry(head->next, struct lnet_msg, msg_list);
                list_del(&msg->msg_list);
 
                /* md won't disappear under me, since each msg
@@ -4975,8 +5010,8 @@ lnet_attach_rsp_tracker(struct lnet_rsp_tracker *rspt, int cpt,
  * \see struct lnet_event::hdr_data and lnet_event_kind_t.
  */
 int
-LNetPut(lnet_nid_t self4, struct lnet_handle_md mdh, enum lnet_ack_req ack,
-       struct lnet_process_id target4, unsigned int portal,
+LNetPut(struct lnet_nid *self, struct lnet_handle_md mdh, enum lnet_ack_req ack,
+       struct lnet_processid *target, unsigned int portal,
        __u64 match_bits, unsigned int offset,
        __u64 hdr_data)
 {
@@ -4984,27 +5019,21 @@ LNetPut(lnet_nid_t self4, struct lnet_handle_md mdh, enum lnet_ack_req ack,
        struct lnet_libmd *md;
        int cpt;
        int rc;
-       struct lnet_processid target;
        struct lnet_rsp_tracker *rspt = NULL;
-       struct lnet_nid self;
 
        LASSERT(the_lnet.ln_refcount > 0);
 
-       lnet_nid4_to_nid(self4, &self);
-       lnet_nid4_to_nid(target4.nid, &target.nid);
-       target.pid = target4.pid;
-
        if (!list_empty(&the_lnet.ln_test_peers) &&     /* normally we don't */
-           fail_peer(&target.nid, 1)) {                /* shall we now? */
+           fail_peer(&target->nid, 1)) {               /* shall we now? */
                CERROR("Dropping PUT to %s: simulated failure\n",
-                      libcfs_id2str(target4));
+                      libcfs_idstr(target));
                return -EIO;
        }
 
        msg = lnet_msg_alloc();
        if (msg == NULL) {
                CERROR("Dropping PUT to %s: ENOMEM on struct lnet_msg\n",
-                      libcfs_id2str(target4));
+                      libcfs_idstr(target));
                return -ENOMEM;
        }
        msg->msg_vmflush = !!(current->flags & PF_MEMALLOC);
@@ -5015,7 +5044,7 @@ LNetPut(lnet_nid_t self4, struct lnet_handle_md mdh, enum lnet_ack_req ack,
                rspt = lnet_rspt_alloc(cpt);
                if (!rspt) {
                        CERROR("Dropping PUT to %s: ENOMEM on response tracker\n",
-                               libcfs_id2str(target4));
+                               libcfs_idstr(target));
                        return -ENOMEM;
                }
                INIT_LIST_HEAD(&rspt->rspt_on_list);
@@ -5026,7 +5055,7 @@ LNetPut(lnet_nid_t self4, struct lnet_handle_md mdh, enum lnet_ack_req ack,
        md = lnet_handle2md(&mdh);
        if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
                CERROR("Dropping PUT (%llu:%d:%s): MD (%d) invalid\n",
-                      match_bits, portal, libcfs_id2str(target4),
+                      match_bits, portal, libcfs_idstr(target),
                       md == NULL ? -1 : md->md_threshold);
                if (md != NULL && md->md_me != NULL)
                        CERROR("Source MD also attached to portal %d\n",
@@ -5040,11 +5069,11 @@ LNetPut(lnet_nid_t self4, struct lnet_handle_md mdh, enum lnet_ack_req ack,
                return -ENOENT;
        }
 
-       CDEBUG(D_NET, "%s -> %s\n", __func__, libcfs_id2str(target4));
+       CDEBUG(D_NET, "%s -> %s\n", __func__, libcfs_idstr(target));
 
        lnet_msg_attach_md(msg, md, 0, 0);
 
-       lnet_prep_send(msg, LNET_MSG_PUT, &target, 0, md->md_length);
+       lnet_prep_send(msg, LNET_MSG_PUT, target, 0, md->md_length);
 
        msg->msg_hdr.msg.put.match_bits = cpu_to_le64(match_bits);
        msg->msg_hdr.msg.put.ptl_index = cpu_to_le32(portal);
@@ -5078,11 +5107,11 @@ LNetPut(lnet_nid_t self4, struct lnet_handle_md mdh, enum lnet_ack_req ack,
                                 CFS_FAIL_ONCE))
                rc = -EIO;
        else
-               rc = lnet_send(&self, msg, NULL);
+               rc = lnet_send(self, msg, NULL);
 
        if (rc != 0) {
                CNETERR("Error sending PUT to %s: %d\n",
-                       libcfs_id2str(target4), rc);
+                       libcfs_idstr(target), rc);
                msg->msg_no_resend = true;
                lnet_finalize(msg, rc);
        }
@@ -5213,8 +5242,8 @@ EXPORT_SYMBOL(lnet_set_reply_msg_len);
  * \retval -ENOENT Invalid MD object.
  */
 int
-LNetGet(lnet_nid_t self4, struct lnet_handle_md mdh,
-       struct lnet_process_id target4, unsigned int portal,
+LNetGet(struct lnet_nid *self, struct lnet_handle_md mdh,
+       struct lnet_processid *target, unsigned int portal,
        __u64 match_bits, unsigned int offset, bool recovery)
 {
        struct lnet_msg *msg;
@@ -5222,27 +5251,21 @@ LNetGet(lnet_nid_t self4, struct lnet_handle_md mdh,
        struct lnet_rsp_tracker *rspt;
        int cpt;
        int rc;
-       struct lnet_nid self;
-       struct lnet_processid target;
 
        LASSERT(the_lnet.ln_refcount > 0);
 
-       lnet_nid4_to_nid(self4, &self);
-       lnet_nid4_to_nid(target4.nid, &target.nid);
-       target.pid = target4.pid;
-
        if (!list_empty(&the_lnet.ln_test_peers) &&     /* normally we don't */
-           fail_peer(&target.nid, 1))          /* shall we now? */
+           fail_peer(&target->nid, 1))         /* shall we now? */
        {
                CERROR("Dropping GET to %s: simulated failure\n",
-                      libcfs_id2str(target4));
+                      libcfs_idstr(target));
                return -EIO;
        }
 
        msg = lnet_msg_alloc();
        if (!msg) {
                CERROR("Dropping GET to %s: ENOMEM on struct lnet_msg\n",
-                      libcfs_id2str(target4));
+                      libcfs_idstr(target));
                return -ENOMEM;
        }
 
@@ -5251,7 +5274,7 @@ LNetGet(lnet_nid_t self4, struct lnet_handle_md mdh,
        rspt = lnet_rspt_alloc(cpt);
        if (!rspt) {
                CERROR("Dropping GET to %s: ENOMEM on response tracker\n",
-                      libcfs_id2str(target4));
+                      libcfs_idstr(target));
                return -ENOMEM;
        }
        INIT_LIST_HEAD(&rspt->rspt_on_list);
@@ -5263,7 +5286,7 @@ LNetGet(lnet_nid_t self4, struct lnet_handle_md mdh,
        md = lnet_handle2md(&mdh);
        if (md == NULL || md->md_threshold == 0 || md->md_me != NULL) {
                CERROR("Dropping GET (%llu:%d:%s): MD (%d) invalid\n",
-                      match_bits, portal, libcfs_id2str(target4),
+                      match_bits, portal, libcfs_idstr(target),
                       md == NULL ? -1 : md->md_threshold);
                if (md != NULL && md->md_me != NULL)
                        CERROR("REPLY MD also attached to portal %d\n",
@@ -5276,11 +5299,11 @@ LNetGet(lnet_nid_t self4, struct lnet_handle_md mdh,
                return -ENOENT;
        }
 
-       CDEBUG(D_NET, "%s -> %s\n", __func__, libcfs_id2str(target4));
+       CDEBUG(D_NET, "%s -> %s\n", __func__, libcfs_idstr(target));
 
        lnet_msg_attach_md(msg, md, 0, 0);
 
-       lnet_prep_send(msg, LNET_MSG_GET, &target, 0, 0);
+       lnet_prep_send(msg, LNET_MSG_GET, target, 0, 0);
 
        msg->msg_hdr.msg.get.match_bits = cpu_to_le64(match_bits);
        msg->msg_hdr.msg.get.ptl_index = cpu_to_le32(portal);
@@ -5302,10 +5325,10 @@ LNetGet(lnet_nid_t self4, struct lnet_handle_md mdh,
        else
                lnet_rspt_free(rspt, cpt);
 
-       rc = lnet_send(&self, msg, NULL);
+       rc = lnet_send(self, msg, NULL);
        if (rc < 0) {
                CNETERR("Error sending GET to %s: %d\n",
-                       libcfs_id2str(target4), rc);
+                       libcfs_idstr(target), rc);
                msg->msg_no_resend = true;
                lnet_finalize(msg, rc);
        }
@@ -5330,54 +5353,52 @@ EXPORT_SYMBOL(LNetGet);
  * \retval -EHOSTUNREACH If \a dstnid is not reachable.
  */
 int
-LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
+LNetDist(struct lnet_nid *dstnid, struct lnet_nid *srcnid, __u32 *orderp)
 {
-       struct list_head *e;
        struct lnet_ni *ni = NULL;
        struct lnet_remotenet *rnet;
-       __u32 dstnet = LNET_NIDNET(dstnid);
+       __u32 dstnet = LNET_NID_NET(dstnid);
        int hops;
        int cpt;
        __u32 order = 2;
        struct list_head *rn_list;
-       bool matched_dstnet = false;
+       struct lnet_ni *matched_dstnet = NULL;
 
        /* 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
         * keep order 0 free for 0@lo and order 1 free for a local NID
-        * match */
+        * match
+        * WARNING: dstnid and srcnid might point to same place.
+        * Don't set *srcnid until late.
+        */
 
        LASSERT(the_lnet.ln_refcount > 0);
 
        cpt = lnet_net_lock_current();
 
        while ((ni = lnet_get_next_ni_locked(NULL, ni))) {
-               /* FIXME support large-addr nid */
-               if (lnet_nid_to_nid4(&ni->ni_nid) == dstnid) {
-                       if (srcnidp != NULL)
-                               *srcnidp = dstnid;
+               if (nid_same(&ni->ni_nid, dstnid)) {
                        if (orderp != NULL) {
-                               if (dstnid == LNET_NID_LO_0)
+                               if (nid_is_lo0(dstnid))
                                        *orderp = 0;
                                else
                                        *orderp = 1;
                        }
+                       if (srcnid)
+                               *srcnid = *dstnid;
                        lnet_net_unlock(cpt);
 
                        return local_nid_dist_zero ? 0 : 1;
                }
 
                if (!matched_dstnet && LNET_NID_NET(&ni->ni_nid) == dstnet) {
-                       matched_dstnet = true;
+                       matched_dstnet = ni;
                        /* We matched the destination net, but we may have
                         * additional local NIs to inspect.
                         *
-                        * We record the nid and order as appropriate, but
+                        * We record the order as appropriate, but
                         * they may be overwritten if we match local NI above.
                         */
-                       if (srcnidp)
-                               /* FIXME support large-addr nids */
-                               *srcnidp = lnet_nid_to_nid4(&ni->ni_nid);
 
                        if (orderp) {
                                /* Check if ni was originally created in
@@ -5398,14 +5419,14 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
        }
 
        if (matched_dstnet) {
+               if (srcnid)
+                       *srcnid = matched_dstnet->ni_nid;
                lnet_net_unlock(cpt);
                return 1;
        }
 
        rn_list = lnet_net2rnethash(dstnet);
-       list_for_each(e, rn_list) {
-               rnet = list_entry(e, struct lnet_remotenet, lrn_list);
-
+       list_for_each_entry(rnet, rn_list, lrn_list) {
                if (rnet->lrn_net == dstnet) {
                        struct lnet_route *route;
                        struct lnet_route *shortest = NULL;
@@ -5428,13 +5449,12 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
 
                        LASSERT(shortest != NULL);
                        hops = shortest_hops;
-                       if (srcnidp != NULL) {
+                       if (srcnid) {
                                struct lnet_net *net;
                                net = lnet_get_net_locked(shortest->lr_lnet);
                                LASSERT(net);
                                ni = lnet_get_next_ni_locked(net, NULL);
-                               /* FIXME support large-addr nids */
-                               *srcnidp = lnet_nid_to_nid4(&ni->ni_nid);
+                               *srcnid = ni->ni_nid;
                        }
                        if (orderp != NULL)
                                *orderp = order;