Whamcloud - gitweb
LU-3679 lnet: reflect down routes in /proc/sys/lnet/routes
[fs/lustre-release.git] / lnet / lnet / lib-move.c
index 41a701c..ce7f926 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2011, 2012, Intel Corporation.
+ * Copyright (c) 2012, 2013, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
@@ -163,6 +163,7 @@ lnet_iov_nob (unsigned int niov, struct iovec *iov)
 {
         unsigned int nob = 0;
 
+       LASSERT(niov == 0 || iov != NULL);
         while (niov-- > 0)
                 nob += (iov++)->iov_len;
 
@@ -323,6 +324,7 @@ lnet_kiov_nob (unsigned int niov, lnet_kiov_t *kiov)
 {
         unsigned int  nob = 0;
 
+       LASSERT(niov == 0 || kiov != NULL);
         while (niov-- > 0)
                 nob += (kiov++)->kiov_len;
 
@@ -335,17 +337,17 @@ lnet_copy_kiov2kiov (unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset
                      unsigned int nsiov, lnet_kiov_t *siov, unsigned int soffset,
                      unsigned int nob)
 {
-        /* NB diov, siov are READ-ONLY */
-        unsigned int    this_nob;
-        char           *daddr = NULL;
-        char           *saddr = NULL;
+       /* NB diov, siov are READ-ONLY */
+       unsigned int    this_nob;
+       char           *daddr = NULL;
+       char           *saddr = NULL;
 
-        if (nob == 0)
-                return;
+       if (nob == 0)
+               return;
 
-        LASSERT (!cfs_in_interrupt ());
+       LASSERT (!in_interrupt ());
 
-        LASSERT (ndiov > 0);
+       LASSERT (ndiov > 0);
         while (doffset >= diov->kiov_len) {
                 doffset -= diov->kiov_len;
                 diov++;
@@ -368,47 +370,47 @@ lnet_copy_kiov2kiov (unsigned int ndiov, lnet_kiov_t *diov, unsigned int doffset
                                siov->kiov_len - soffset);
                 this_nob = MIN(this_nob, nob);
 
-                if (daddr == NULL)
-                        daddr = ((char *)cfs_kmap(diov->kiov_page)) + 
-                                diov->kiov_offset + doffset;
-                if (saddr == NULL)
-                        saddr = ((char *)cfs_kmap(siov->kiov_page)) + 
-                                siov->kiov_offset + soffset;
+               if (daddr == NULL)
+                       daddr = ((char *)kmap(diov->kiov_page)) +
+                               diov->kiov_offset + doffset;
+               if (saddr == NULL)
+                       saddr = ((char *)kmap(siov->kiov_page)) +
+                               siov->kiov_offset + soffset;
 
-                /* Vanishing risk of kmap deadlock when mapping 2 pages.
-                 * However in practice at least one of the kiovs will be mapped
-                 * kernel pages and the map/unmap will be NOOPs */
+               /* Vanishing risk of kmap deadlock when mapping 2 pages.
+                * However in practice at least one of the kiovs will be mapped
+                * kernel pages and the map/unmap will be NOOPs */
 
-                memcpy (daddr, saddr, this_nob);
-                nob -= this_nob;
+               memcpy (daddr, saddr, this_nob);
+               nob -= this_nob;
 
-                if (diov->kiov_len > doffset + this_nob) {
-                        daddr += this_nob;
-                        doffset += this_nob;
-                } else {
-                        cfs_kunmap(diov->kiov_page);
-                        daddr = NULL;
-                        diov++;
-                        ndiov--;
-                        doffset = 0;
-                }
+               if (diov->kiov_len > doffset + this_nob) {
+                       daddr += this_nob;
+                       doffset += this_nob;
+               } else {
+                       kunmap(diov->kiov_page);
+                       daddr = NULL;
+                       diov++;
+                       ndiov--;
+                       doffset = 0;
+               }
 
-                if (siov->kiov_len > soffset + this_nob) {
-                        saddr += this_nob;
-                        soffset += this_nob;
-                } else {
-                        cfs_kunmap(siov->kiov_page);
-                        saddr = NULL;
-                        siov++;
-                        nsiov--;
-                        soffset = 0;
-                }
-        } while (nob > 0);
+               if (siov->kiov_len > soffset + this_nob) {
+                       saddr += this_nob;
+                       soffset += this_nob;
+               } else {
+                       kunmap(siov->kiov_page);
+                       saddr = NULL;
+                       siov++;
+                       nsiov--;
+                       soffset = 0;
+               }
+       } while (nob > 0);
 
-        if (daddr != NULL)
-                cfs_kunmap(diov->kiov_page);
-        if (saddr != NULL)
-                cfs_kunmap(siov->kiov_page);
+       if (daddr != NULL)
+               kunmap(diov->kiov_page);
+       if (saddr != NULL)
+               kunmap(siov->kiov_page);
 }
 EXPORT_SYMBOL(lnet_copy_kiov2kiov);
 
@@ -417,16 +419,16 @@ lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset
                     unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffset,
                     unsigned int nob)
 {
-        /* NB iov, kiov are READ-ONLY */
-        unsigned int    this_nob;
-        char           *addr = NULL;
+       /* NB iov, kiov are READ-ONLY */
+       unsigned int    this_nob;
+       char           *addr = NULL;
 
-        if (nob == 0)
-                return;
+       if (nob == 0)
+               return;
 
-        LASSERT (!cfs_in_interrupt ());
+       LASSERT (!in_interrupt ());
 
-        LASSERT (niov > 0);
+       LASSERT (niov > 0);
         while (iovoffset >= iov->iov_len) {
                 iovoffset -= iov->iov_len;
                 iov++;
@@ -450,7 +452,7 @@ lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset
                 this_nob = MIN(this_nob, nob);
 
                 if (addr == NULL)
-                        addr = ((char *)cfs_kmap(kiov->kiov_page)) + 
+                       addr = ((char *)kmap(kiov->kiov_page)) +
                                 kiov->kiov_offset + kiovoffset;
 
                 memcpy ((char *)iov->iov_base + iovoffset, addr, this_nob);
@@ -468,17 +470,17 @@ lnet_copy_kiov2iov (unsigned int niov, struct iovec *iov, unsigned int iovoffset
                         addr += this_nob;
                         kiovoffset += this_nob;
                 } else {
-                        cfs_kunmap(kiov->kiov_page);
-                        addr = NULL;
-                        kiov++;
-                        nkiov--;
-                        kiovoffset = 0;
-                }
+                       kunmap(kiov->kiov_page);
+                       addr = NULL;
+                       kiov++;
+                       nkiov--;
+                       kiovoffset = 0;
+               }
 
-        } while (nob > 0);
+       } while (nob > 0);
 
-        if (addr != NULL)
-                cfs_kunmap(kiov->kiov_page);
+       if (addr != NULL)
+               kunmap(kiov->kiov_page);
 }
 EXPORT_SYMBOL(lnet_copy_kiov2iov);
 
@@ -487,16 +489,16 @@ lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffs
                     unsigned int niov, struct iovec *iov, unsigned int iovoffset,
                     unsigned int nob)
 {
-        /* NB kiov, iov are READ-ONLY */
-        unsigned int    this_nob;
-        char           *addr = NULL;
+       /* NB kiov, iov are READ-ONLY */
+       unsigned int    this_nob;
+       char           *addr = NULL;
 
-        if (nob == 0)
-                return;
+       if (nob == 0)
+               return;
 
-        LASSERT (!cfs_in_interrupt ());
+       LASSERT (!in_interrupt ());
 
-        LASSERT (nkiov > 0);
+       LASSERT (nkiov > 0);
         while (kiovoffset >= kiov->kiov_len) {
                 kiovoffset -= kiov->kiov_len;
                 kiov++;
@@ -520,34 +522,34 @@ lnet_copy_iov2kiov (unsigned int nkiov, lnet_kiov_t *kiov, unsigned int kiovoffs
                 this_nob = MIN(this_nob, nob);
 
                 if (addr == NULL)
-                        addr = ((char *)cfs_kmap(kiov->kiov_page)) + 
-                                kiov->kiov_offset + kiovoffset;
+                       addr = ((char *)kmap(kiov->kiov_page)) +
+                               kiov->kiov_offset + kiovoffset;
 
-                memcpy (addr, (char *)iov->iov_base + iovoffset, this_nob);
-                nob -= this_nob;
+               memcpy (addr, (char *)iov->iov_base + iovoffset, this_nob);
+               nob -= this_nob;
 
-                if (kiov->kiov_len > kiovoffset + this_nob) {
-                        addr += this_nob;
-                        kiovoffset += this_nob;
-                } else {
-                        cfs_kunmap(kiov->kiov_page);
-                        addr = NULL;
-                        kiov++;
-                        nkiov--;
-                        kiovoffset = 0;
-                }
+               if (kiov->kiov_len > kiovoffset + this_nob) {
+                       addr += this_nob;
+                       kiovoffset += this_nob;
+               } else {
+                       kunmap(kiov->kiov_page);
+                       addr = NULL;
+                       kiov++;
+                       nkiov--;
+                       kiovoffset = 0;
+               }
 
-                if (iov->iov_len > iovoffset + this_nob) {
-                        iovoffset += this_nob;
-                } else {
-                        iov++;
-                        niov--;
-                        iovoffset = 0;
-                }
-        } while (nob > 0);
+               if (iov->iov_len > iovoffset + this_nob) {
+                       iovoffset += this_nob;
+               } else {
+                       iov++;
+                       niov--;
+                       iovoffset = 0;
+               }
+       } while (nob > 0);
 
-        if (addr != NULL)
-                cfs_kunmap(kiov->kiov_page);
+       if (addr != NULL)
+               kunmap(kiov->kiov_page);
 }
 EXPORT_SYMBOL(lnet_copy_iov2kiov);
 
@@ -582,14 +584,14 @@ lnet_extract_kiov (int dst_niov, lnet_kiov_t *dst,
                 dst->kiov_page = src->kiov_page;
                 dst->kiov_offset = src->kiov_offset + offset;
 
-                if (len <= frag_len) {
-                        dst->kiov_len = len;
-                        LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
-                        return (niov);
-                }
+               if (len <= frag_len) {
+                       dst->kiov_len = len;
+                       LASSERT (dst->kiov_offset + dst->kiov_len <= PAGE_CACHE_SIZE);
+                       return niov;
+               }
 
-                dst->kiov_len = frag_len;
-                LASSERT (dst->kiov_offset + dst->kiov_len <= CFS_PAGE_SIZE);
+               dst->kiov_len = frag_len;
+               LASSERT (dst->kiov_offset + dst->kiov_len <= PAGE_CACHE_SIZE);
 
                 len -= frag_len;
                 dst++;
@@ -606,13 +608,13 @@ void
 lnet_ni_recv(lnet_ni_t *ni, void *private, lnet_msg_t *msg, int delayed,
              unsigned int offset, unsigned int mlen, unsigned int rlen)
 {
-        unsigned int  niov = 0;
-        struct iovec *iov = NULL;
-        lnet_kiov_t  *kiov = NULL;
-        int           rc;
+       unsigned int  niov = 0;
+       struct iovec *iov = NULL;
+       lnet_kiov_t  *kiov = NULL;
+       int           rc;
 
-        LASSERT (!cfs_in_interrupt ());
-        LASSERT (mlen == 0 || msg != NULL);
+       LASSERT (!in_interrupt ());
+       LASSERT (mlen == 0 || msg != NULL);
 
         if (msg != NULL) {
                 LASSERT(msg->msg_receiving);
@@ -683,16 +685,16 @@ lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
 void
 lnet_ni_send(lnet_ni_t *ni, lnet_msg_t *msg)
 {
-        void   *priv = msg->msg_private;
-        int     rc;
+       void   *priv = msg->msg_private;
+       int     rc;
 
-        LASSERT (!cfs_in_interrupt ());
-        LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
-                 (msg->msg_txcredit && msg->msg_peertxcredit));
+       LASSERT (!in_interrupt ());
+       LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND ||
+                (msg->msg_txcredit && msg->msg_peertxcredit));
 
-        rc = (ni->ni_lnd->lnd_send)(ni, priv, msg);
-        if (rc < 0)
-                lnet_finalize(ni, msg, rc);
+       rc = (ni->ni_lnd->lnd_send)(ni, priv, msg);
+       if (rc < 0)
+               lnet_finalize(ni, msg, rc);
 }
 
 int
@@ -907,7 +909,7 @@ lnet_msg2bufpool(lnet_msg_t *msg)
        rbp = &the_lnet.ln_rtrpools[cpt][0];
 
        LASSERT(msg->msg_len <= LNET_MTU);
-       while (msg->msg_len > (unsigned int)rbp->rbp_npages * CFS_PAGE_SIZE) {
+       while (msg->msg_len > (unsigned int)rbp->rbp_npages * PAGE_CACHE_SIZE) {
                rbp++;
                LASSERT(rbp < &the_lnet.ln_rtrpools[cpt][LNET_NRBPOOLS]);
        }
@@ -1122,6 +1124,12 @@ lnet_compare_routes(lnet_route_t *r1, lnet_route_t *r2)
        lnet_peer_t *p1 = r1->lr_gateway;
        lnet_peer_t *p2 = r2->lr_gateway;
 
+       if (r1->lr_priority < r2->lr_priority)
+               return 1;
+
+       if (r1->lr_priority > r2->lr_priority)
+               return -1;
+
        if (r1->lr_hops < r2->lr_hops)
                return 1;
 
@@ -1150,9 +1158,9 @@ static lnet_peer_t *
 lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
 {
        lnet_remotenet_t        *rnet;
-       lnet_route_t            *rtr;
-       lnet_route_t            *rtr_best;
-       lnet_route_t            *rtr_last;
+       lnet_route_t            *route;
+       lnet_route_t            *best_route;
+       lnet_route_t            *last_route;
        struct lnet_peer        *lp_best;
        struct lnet_peer        *lp;
        int                     rc;
@@ -1165,13 +1173,11 @@ lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
                return NULL;
 
        lp_best = NULL;
-       rtr_best = rtr_last = NULL;
-       cfs_list_for_each_entry(rtr, &rnet->lrn_routes, lr_list) {
-               lp = rtr->lr_gateway;
+       best_route = last_route = NULL;
+       cfs_list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
+               lp = route->lr_gateway;
 
-               if (!lp->lp_alive || /* gateway is down */
-                   ((lp->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0 &&
-                    rtr->lr_downis != 0)) /* NI to target is down */
+               if (!lnet_is_route_alive(route))
                        continue;
 
                if (ni != NULL && lp->lp_ni != ni)
@@ -1181,28 +1187,28 @@ lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
                        return lp;
 
                if (lp_best == NULL) {
-                       rtr_best = rtr_last = rtr;
+                       best_route = last_route = route;
                        lp_best = lp;
                        continue;
                }
 
                /* no protection on below fields, but it's harmless */
-               if (rtr_last->lr_seq - rtr->lr_seq < 0)
-                       rtr_last = rtr;
+               if (last_route->lr_seq - route->lr_seq < 0)
+                       last_route = route;
 
-               rc = lnet_compare_routes(rtr, rtr_best);
+               rc = lnet_compare_routes(route, best_route);
                if (rc < 0)
                        continue;
 
-               rtr_best = rtr;
+               best_route = route;
                lp_best = lp;
        }
 
        /* set sequence number on the best router to the latest sequence + 1
         * so we can round-robin all routers, it's race and inaccurate but
         * harmless and functional  */
-       if (rtr_best != NULL)
-               rtr_best->lr_seq = rtr_last->lr_seq + 1;
+       if (best_route != NULL)
+               best_route->lr_seq = last_route->lr_seq + 1;
        return lp_best;
 }
 
@@ -1771,16 +1777,16 @@ lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
        struct lnet_msg *msg;
         lnet_pid_t     dest_pid;
         lnet_nid_t     dest_nid;
-        lnet_nid_t     src_nid;
-        __u32          payload_length;
-        __u32          type;
+       lnet_nid_t     src_nid;
+       __u32          payload_length;
+       __u32          type;
 
-        LASSERT (!cfs_in_interrupt ());
+       LASSERT (!in_interrupt ());
 
-        type = le32_to_cpu(hdr->type);
-        src_nid = le64_to_cpu(hdr->src_nid);
-        dest_nid = le64_to_cpu(hdr->dest_nid);
-        dest_pid = le32_to_cpu(hdr->dest_pid);
+       type = le32_to_cpu(hdr->type);
+       src_nid = le64_to_cpu(hdr->src_nid);
+       dest_nid = le64_to_cpu(hdr->dest_nid);
+       dest_pid = le32_to_cpu(hdr->dest_pid);
         payload_length = le32_to_cpu(hdr->payload_length);
 
         for_me = (ni->ni_nid == dest_nid);
@@ -2130,7 +2136,7 @@ LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack,
                        libcfs_id2str(target));
                 return -ENOMEM;
         }
-        msg->msg_vmflush = !!cfs_memory_pressure_get();
+       msg->msg_vmflush = !!memory_pressure_get();
 
        cpt = lnet_cpt_of_cookie(mdh.cookie);
        lnet_res_lock(cpt);