__u32 sd_send_case;
};
+static inline bool
+lnet_msg_is_response(struct lnet_msg *msg)
+{
+ return msg->msg_type == LNET_MSG_ACK || msg->msg_type == LNET_MSG_REPLY;
+}
+
static inline struct lnet_comm_count *
get_stats_counts(struct lnet_element_stats *stats,
enum lnet_stats_type stats_type)
unsigned int nob)
{
/* NB diov, siov are READ-ONLY */
- unsigned int this_nob;
+ unsigned int this_nob;
if (nob == 0)
return;
do {
LASSERT(ndiov > 0);
LASSERT(nsiov > 0);
- this_nob = MIN(diov->iov_len - doffset,
- siov->iov_len - soffset);
- this_nob = MIN(this_nob, nob);
+ this_nob = min3((unsigned int)diov->iov_len - doffset,
+ (unsigned int)siov->iov_len - soffset,
+ nob);
memcpy((char *)diov->iov_base + doffset,
(char *)siov->iov_base + soffset, this_nob);
do {
LASSERT(ndiov > 0);
LASSERT(nsiov > 0);
- this_nob = MIN(diov->kiov_len - doffset,
- siov->kiov_len - soffset);
- this_nob = MIN(this_nob, nob);
+ this_nob = min3(diov->kiov_len - doffset,
+ siov->kiov_len - soffset,
+ nob);
if (daddr == NULL)
daddr = ((char *)kmap(diov->kiov_page)) +
do {
LASSERT(niov > 0);
LASSERT(nkiov > 0);
- this_nob = MIN(iov->iov_len - iovoffset,
- kiov->kiov_len - kiovoffset);
- this_nob = MIN(this_nob, nob);
+ this_nob = min3((unsigned int)iov->iov_len - iovoffset,
+ (unsigned int)kiov->kiov_len - kiovoffset,
+ nob);
if (addr == NULL)
addr = ((char *)kmap(kiov->kiov_page)) +
do {
LASSERT(nkiov > 0);
LASSERT(niov > 0);
- this_nob = MIN(kiov->kiov_len - kiovoffset,
- iov->iov_len - iovoffset);
- this_nob = MIN(this_nob, nob);
+ this_nob = min3((unsigned int)kiov->kiov_len - kiovoffset,
+ (unsigned int)iov->iov_len - iovoffset,
+ nob);
if (addr == NULL)
addr = ((char *)kmap(kiov->kiov_page)) +
return 1;
/* always send any responses */
- if (msg->msg_type == LNET_MSG_ACK ||
- msg->msg_type == LNET_MSG_REPLY)
+ if (lnet_msg_is_response(msg))
return 1;
if (!lnet_is_peer_deadline_passed(lpni, now))
}
static inline void
-lnet_set_non_mr_pref_nid(struct lnet_send_data *sd)
+lnet_set_non_mr_pref_nid(struct lnet_peer_ni *lpni, struct lnet_ni *lni,
+ struct lnet_msg *msg)
{
- if (sd->sd_send_case & NMR_DST &&
- sd->sd_msg->msg_type != LNET_MSG_REPLY &&
- sd->sd_msg->msg_type != LNET_MSG_ACK &&
- sd->sd_best_lpni->lpni_pref_nnids == 0) {
+ if (!lnet_msg_is_response(msg) && lpni->lpni_pref_nnids == 0) {
CDEBUG(D_NET, "Setting preferred local NID %s on NMR peer %s\n",
- libcfs_nid2str(sd->sd_best_ni->ni_nid),
- libcfs_nid2str(sd->sd_best_lpni->lpni_nid));
- lnet_peer_ni_set_non_mr_pref_nid(sd->sd_best_lpni,
- sd->sd_best_ni->ni_nid);
+ libcfs_nid2str(lni->ni_nid),
+ libcfs_nid2str(lpni->lpni_nid));
+ lnet_peer_ni_set_non_mr_pref_nid(lpni, lni->ni_nid);
}
}
return -EINVAL;
}
- /*
- * the preferred NID will only be set for NMR peers
- */
- lnet_set_non_mr_pref_nid(sd);
+ lnet_set_non_mr_pref_nid(sd->sd_best_lpni, sd->sd_best_ni, sd->sd_msg);
return lnet_handle_send(sd);
}
}
static int
-lnet_initiate_peer_discovery(struct lnet_peer_ni *lpni,
- struct lnet_msg *msg, lnet_nid_t rtr_nid,
+lnet_initiate_peer_discovery(struct lnet_peer_ni *lpni, struct lnet_msg *msg,
int cpt)
{
struct lnet_peer *peer;
- lnet_nid_t primary_nid;
int rc;
lnet_peer_ni_addref_locked(lpni);
return 0;
}
/* queue message and return */
- msg->msg_rtr_nid_param = rtr_nid;
msg->msg_sending = 0;
msg->msg_txpeer = NULL;
list_add_tail(&msg->msg_list, &peer->lp_dc_pendq);
- primary_nid = peer->lp_primary_nid;
spin_unlock(&peer->lp_lock);
lnet_peer_ni_decref_locked(lpni);
CDEBUG(D_NET, "msg %p delayed. %s pending discovery\n",
- msg, libcfs_nid2str(primary_nid));
+ msg, libcfs_nid2str(peer->lp_primary_nid));
return LNET_DC_WAIT;
}
* completed
*/
sd->sd_msg->msg_src_nid_param = sd->sd_src_nid;
- rc = lnet_initiate_peer_discovery(gwni, sd->sd_msg, sd->sd_rtr_nid,
- sd->sd_cpt);
+ rc = lnet_initiate_peer_discovery(gwni, sd->sd_msg, sd->sd_cpt);
if (rc)
return rc;
if (sd->sd_send_case & NMR_DST)
/*
- * since the final destination is non-MR let's set its preferred
- * NID before we send
- */
- lnet_set_non_mr_pref_nid(sd);
+ * since the final destination is non-MR let's set its preferred
+ * NID before we send
+ */
+ lnet_set_non_mr_pref_nid(sd->sd_best_lpni, sd->sd_best_ni,
+ sd->sd_msg);
/*
* We're going to send to the gw found so let's set its
}
static struct lnet_ni *
-lnet_find_existing_preferred_best_ni(struct lnet_send_data *sd)
+lnet_find_existing_preferred_best_ni(struct lnet_peer_ni *lpni, int cpt)
{
struct lnet_ni *best_ni = NULL;
- struct lnet_peer_net *peer_net;
- struct lnet_peer *peer = sd->sd_peer;
- struct lnet_peer_ni *best_lpni = sd->sd_best_lpni;
- struct lnet_peer_ni *lpni;
- int cpt = sd->sd_cpt;
+ struct lnet_peer_net *peer_net = lpni->lpni_peer_net;
+ struct lnet_peer_ni *lpni_entry;
/*
* We must use a consistent source address when sending to a
* So we need to pick the NI the peer prefers for this
* particular network.
*/
-
- /* Get the target peer_ni */
- peer_net = lnet_peer_get_net_locked(peer,
- LNET_NIDNET(best_lpni->lpni_nid));
- LASSERT(peer_net != NULL);
- list_for_each_entry(lpni, &peer_net->lpn_peer_nis,
- lpni_peer_nis) {
- if (lpni->lpni_pref_nnids == 0)
+ LASSERT(peer_net);
+ list_for_each_entry(lpni_entry, &peer_net->lpn_peer_nis,
+ lpni_peer_nis) {
+ if (lpni_entry->lpni_pref_nnids == 0)
continue;
- LASSERT(lpni->lpni_pref_nnids == 1);
- best_ni = lnet_nid2ni_locked(
- lpni->lpni_pref.nid, cpt);
+ LASSERT(lpni_entry->lpni_pref_nnids == 1);
+ best_ni = lnet_nid2ni_locked(lpni_entry->lpni_pref.nid, cpt);
break;
}
* particular network.
*/
- best_ni = lnet_find_existing_preferred_best_ni(sd);
+ best_ni = lnet_find_existing_preferred_best_ni(sd->sd_best_lpni,
+ sd->sd_cpt);
/* if best_ni is still not set just pick one */
if (!best_ni) {
sd->sd_best_ni = best_ni;
/* Set preferred NI if necessary. */
- lnet_set_non_mr_pref_nid(sd);
+ lnet_set_non_mr_pref_nid(sd->sd_best_lpni, sd->sd_best_ni, sd->sd_msg);
return 0;
}
struct lnet_peer *gw_peer = NULL;
/*
- * Let's set if we have a preferred NI to talk to this NMR peer
+ * Let's see if we have a preferred NI to talk to this NMR peer
*/
- sd->sd_best_ni = lnet_find_existing_preferred_best_ni(sd);
+ sd->sd_best_ni = lnet_find_existing_preferred_best_ni(sd->sd_best_lpni,
+ sd->sd_cpt);
/*
* find the router and that'll find the best NI if we didn't find
* set the best_ni we've chosen as the preferred one for
* this peer
*/
- lnet_set_non_mr_pref_nid(sd);
+ lnet_set_non_mr_pref_nid(sd->sd_best_lpni, sd->sd_best_ni, sd->sd_msg);
/* we'll be sending to the gw */
sd->sd_best_lpni = gw_lpni;
}
/*
- * Cache the original src_nid. If we need to resend the message
- * then we'll need to know whether the src_nid was originally
+ * Cache the original src_nid and rtr_nid. If we need to resend the
+ * message then we'll need to know whether the src_nid was originally
* specified for this message. If it was originally specified,
* then we need to keep using the same src_nid since it's
- * continuing the same sequence of messages.
+ * continuing the same sequence of messages. Similarly, rtr_nid will
+ * affect our choice of next hop.
*/
msg->msg_src_nid_param = src_nid;
+ msg->msg_rtr_nid_param = rtr_nid;
/*
* If necessary, perform discovery on the peer that owns this peer_ni.
* Note, this can result in the ownership of this peer_ni changing
* to another peer object.
*/
- rc = lnet_initiate_peer_discovery(lpni, msg, rtr_nid, cpt);
+ rc = lnet_initiate_peer_discovery(lpni, msg, cpt);
if (rc) {
lnet_peer_ni_decref_locked(lpni);
lnet_net_unlock(cpt);
else
send_case |= MR_DST;
- if (msg->msg_type == LNET_MSG_REPLY ||
- msg->msg_type == LNET_MSG_ACK)
+ if (lnet_msg_is_response(msg))
send_case |= SND_RESP;
/* assign parameters to the send_data */
struct lnet_hdr *hdr = &msg->msg_hdr;
struct lnet_process_id src = {0};
struct lnet_libmd *md;
- int rlength;
- int mlength;
+ unsigned int rlength;
+ unsigned int mlength;
int cpt;
cpt = lnet_cpt_of_cookie(hdr->msg.reply.dst_wmd.wh_object_cookie);
LASSERT(md->md_offset == 0);
rlength = hdr->payload_length;
- mlength = MIN(rlength, (int)md->md_length);
+ mlength = min(rlength, md->md_length);
if (mlength < rlength &&
(md->md_options & LNET_MD_TRUNCATE) == 0) {