Whamcloud - gitweb
LU-6142 lnet: use list_first_entry() in lnet/lnet subdirectory.
[fs/lustre-release.git] / lnet / lnet / net_fault.c
index 56365fd..98f9b31 100644 (file)
@@ -25,7 +25,6 @@
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
- * Lustre is a trademark of Sun Microsystems, Inc.
  *
  * lnet/lnet/net_fault.c
  *
@@ -66,12 +65,16 @@ struct lnet_drop_rule {
 };
 
 static bool
-lnet_fault_nid_match(lnet_nid_t nid, lnet_nid_t msg_nid)
+lnet_fault_nid_match(lnet_nid_t nid, struct lnet_nid *msg_nid)
 {
-       if (nid == msg_nid || nid == LNET_NID_ANY)
+       if (nid == LNET_NID_ANY)
+               return true;
+       if (!msg_nid)
+               return false;
+       if (lnet_nid_to_nid4(msg_nid) == nid)
                return true;
 
-       if (LNET_NIDNET(nid) != LNET_NIDNET(msg_nid))
+       if (LNET_NIDNET(nid) != LNET_NID_NET(msg_nid))
                return false;
 
        /* 255.255.255.255@net is wildcard for all addresses in a network */
@@ -79,8 +82,10 @@ lnet_fault_nid_match(lnet_nid_t nid, lnet_nid_t msg_nid)
 }
 
 static bool
-lnet_fault_attr_match(struct lnet_fault_attr *attr, lnet_nid_t src,
-                     lnet_nid_t local_nid, lnet_nid_t dst,
+lnet_fault_attr_match(struct lnet_fault_attr *attr,
+                     struct lnet_nid *src,
+                     struct lnet_nid *local_nid,
+                     struct lnet_nid *dst,
                      unsigned int type, unsigned int portal)
 {
        if (!lnet_fault_nid_match(attr->fa_src, src) ||
@@ -88,7 +93,7 @@ lnet_fault_attr_match(struct lnet_fault_attr *attr, lnet_nid_t src,
            !lnet_fault_nid_match(attr->fa_local_nid, local_nid))
                return false;
 
-       if (!(attr->fa_msg_mask & (1 << type)))
+       if (!(attr->fa_msg_mask & BIT(type)))
                return false;
 
        /* NB: ACK and REPLY have no portal, but they should have been
@@ -313,7 +318,7 @@ lnet_fault_match_health(enum lnet_msg_hstatus *hstatus, __u32 mask)
                return;
        }
 
-       if (mask & (1 << choice)) {
+       if (mask & BIT(choice)) {
                *hstatus = choice;
                return;
        }
@@ -322,7 +327,7 @@ lnet_fault_match_health(enum lnet_msg_hstatus *hstatus, __u32 mask)
        i = HSTATUS_END;
        best_delta = HSTATUS_END;
        while (i > 0) {
-               if (mask & (1 << i)) {
+               if (mask & BIT(i)) {
                        delta = choice - i;
                        if (delta < 0)
                                delta *= -1;
@@ -342,8 +347,10 @@ lnet_fault_match_health(enum lnet_msg_hstatus *hstatus, __u32 mask)
  * decide whether should drop this message or not
  */
 static bool
-drop_rule_match(struct lnet_drop_rule *rule, lnet_nid_t src,
-               lnet_nid_t local_nid, lnet_nid_t dst,
+drop_rule_match(struct lnet_drop_rule *rule,
+               struct lnet_nid *src,
+               struct lnet_nid *local_nid,
+               struct lnet_nid *dst,
                unsigned int type, unsigned int portal,
                enum lnet_msg_hstatus *hstatus)
 {
@@ -427,12 +434,10 @@ drop_matched:
  */
 bool
 lnet_drop_rule_match(struct lnet_hdr *hdr,
-                    lnet_nid_t local_nid,
+                    struct lnet_nid *local_nid,
                     enum lnet_msg_hstatus *hstatus)
 {
-       lnet_nid_t src = le64_to_cpu(hdr->src_nid);
-       lnet_nid_t dst = le64_to_cpu(hdr->dest_nid);
-       unsigned int typ = le32_to_cpu(hdr->type);
+       unsigned int typ = hdr->type;
        struct lnet_drop_rule *rule;
        unsigned int ptl = -1;
        bool drop = false;
@@ -447,7 +452,8 @@ lnet_drop_rule_match(struct lnet_hdr *hdr,
 
        cpt = lnet_net_lock_current();
        list_for_each_entry(rule, &the_lnet.ln_drop_rules, dr_link) {
-               drop = drop_rule_match(rule, src, local_nid, dst, typ, ptl,
+               drop = drop_rule_match(rule, &hdr->src_nid, local_nid,
+                                      &hdr->dest_nid, typ, ptl,
                                       hstatus);
                if (drop)
                        break;
@@ -531,22 +537,21 @@ delay_rule_decref(struct lnet_delay_rule *rule)
  * decide whether should delay this message or not
  */
 static bool
-delay_rule_match(struct lnet_delay_rule *rule, lnet_nid_t src,
-               lnet_nid_t dst, unsigned int type, unsigned int portal,
-               struct lnet_msg *msg)
+delay_rule_match(struct lnet_delay_rule *rule, struct lnet_nid *src,
+                struct lnet_nid *dst, unsigned int type, unsigned int portal,
+                struct lnet_msg *msg)
 {
-       struct lnet_fault_attr  *attr = &rule->dl_attr;
-       bool                     delay;
+       struct lnet_fault_attr *attr = &rule->dl_attr;
+       bool delay;
+       time64_t now = ktime_get_seconds();
 
-       if (!lnet_fault_attr_match(attr, src, LNET_NID_ANY,
+       if (!lnet_fault_attr_match(attr, src, NULL,
                                   dst, type, portal))
                return false;
 
        /* match this rule, check delay rate now */
        spin_lock(&rule->dl_lock);
        if (rule->dl_delay_time != 0) { /* time based delay */
-               time64_t now = ktime_get_seconds();
-
                rule->dl_stat.fs_count++;
                delay = now >= rule->dl_delay_time;
                if (delay) {
@@ -588,11 +593,11 @@ delay_rule_match(struct lnet_delay_rule *rule, lnet_nid_t src,
        rule->dl_stat.u.delay.ls_delayed++;
 
        list_add_tail(&msg->msg_list, &rule->dl_msg_list);
-       msg->msg_delay_send = ktime_get_seconds() + attr->u.delay.la_latency;
+       msg->msg_delay_send = now + attr->u.delay.la_latency;
        if (rule->dl_msg_send == -1) {
                rule->dl_msg_send = msg->msg_delay_send;
                mod_timer(&rule->dl_timer,
-                         jiffies + cfs_time_seconds(rule->dl_msg_send));
+                         jiffies + cfs_time_seconds(attr->u.delay.la_latency));
        }
 
        spin_unlock(&rule->dl_lock);
@@ -607,9 +612,7 @@ bool
 lnet_delay_rule_match_locked(struct lnet_hdr *hdr, struct lnet_msg *msg)
 {
        struct lnet_delay_rule  *rule;
-       lnet_nid_t               src = le64_to_cpu(hdr->src_nid);
-       lnet_nid_t               dst = le64_to_cpu(hdr->dest_nid);
-       unsigned int             typ = le32_to_cpu(hdr->type);
+       unsigned int             typ = hdr->type;
        unsigned int             ptl = -1;
 
        /* NB: called with hold of lnet_net_lock */
@@ -622,7 +625,8 @@ lnet_delay_rule_match_locked(struct lnet_hdr *hdr, struct lnet_msg *msg)
                ptl = le32_to_cpu(hdr->msg.get.ptl_index);
 
        list_for_each_entry(rule, &the_lnet.ln_delay_rules, dl_link) {
-               if (delay_rule_match(rule, src, dst, typ, ptl, msg))
+               if (delay_rule_match(rule, &hdr->src_nid, &hdr->dest_nid,
+                                    typ, ptl, msg))
                        return true;
        }
 
@@ -638,7 +642,7 @@ delayed_msg_check(struct lnet_delay_rule *rule, bool all,
        struct lnet_msg *tmp;
        time64_t now = ktime_get_seconds();
 
-       if (!all && cfs_time_seconds(rule->dl_msg_send) > now)
+       if (!all && rule->dl_msg_send > now)
                return;
 
        spin_lock(&rule->dl_lock);
@@ -657,11 +661,12 @@ delayed_msg_check(struct lnet_delay_rule *rule, bool all,
        } else if (!list_empty(msg_list)) {
                /* dequeued some timedout messages, update timer for the
                 * next delayed message on rule */
-               msg = list_entry(rule->dl_msg_list.next,
-                                struct lnet_msg, msg_list);
+               msg = list_first_entry(&rule->dl_msg_list,
+                                      struct lnet_msg, msg_list);
                rule->dl_msg_send = msg->msg_delay_send;
                mod_timer(&rule->dl_timer,
-                         jiffies + cfs_time_seconds(rule->dl_msg_send));
+                         jiffies +
+                         cfs_time_seconds(msg->msg_delay_send - now));
        }
        spin_unlock(&rule->dl_lock);
 }
@@ -671,12 +676,25 @@ delayed_msg_process(struct list_head *msg_list, bool drop)
 {
        struct lnet_msg *msg;
 
-       while (!list_empty(msg_list)) {
+       while ((msg = list_first_entry_or_null(msg_list, struct lnet_msg,
+                                              msg_list)) != NULL) {
                struct lnet_ni *ni;
                int             cpt;
                int             rc;
 
-               msg = list_entry(msg_list->next, struct lnet_msg, msg_list);
+               if (msg->msg_sending) {
+                       /* Delayed send */
+                       list_del_init(&msg->msg_list);
+                       ni = msg->msg_txni;
+                       CDEBUG(D_NET, "TRACE: msg %p %s -> %s : %s\n", msg,
+                              libcfs_nidstr(&ni->ni_nid),
+                              libcfs_nidstr(&msg->msg_txpeer->lpni_nid),
+                              lnet_msgtyp2str(msg->msg_type));
+                       lnet_ni_send(ni, msg);
+                       continue;
+               }
+
+               /* Delayed receive */
                LASSERT(msg->msg_rxpeer != NULL);
                LASSERT(msg->msg_rxni != NULL);
 
@@ -701,7 +719,7 @@ delayed_msg_process(struct list_head *msg_list, bool drop)
                        case LNET_CREDIT_OK:
                                lnet_ni_recv(ni, msg->msg_private, msg, 0,
                                             0, msg->msg_len, msg->msg_len);
-                               /* fallthrough */
+                               fallthrough;
                        case LNET_CREDIT_WAIT:
                                continue;
                        default: /* failures */
@@ -735,8 +753,8 @@ lnet_delay_rule_check(void)
                        break;
                }
 
-               rule = list_entry(delay_dd.dd_sched_rules.next,
-                                 struct lnet_delay_rule, dl_sched_link);
+               rule = list_first_entry(&delay_dd.dd_sched_rules,
+                                       struct lnet_delay_rule, dl_sched_link);
                list_del_init(&rule->dl_sched_link);
                spin_unlock_bh(&delay_dd.dd_lock);
 
@@ -1075,10 +1093,10 @@ lnet_fault_ctl(int opc, struct libcfs_ioctl_data *data)
 int
 lnet_fault_init(void)
 {
-       BUILD_BUG_ON(LNET_PUT_BIT != 1 << LNET_MSG_PUT);
-       BUILD_BUG_ON(LNET_ACK_BIT != 1 << LNET_MSG_ACK);
-       BUILD_BUG_ON(LNET_GET_BIT != 1 << LNET_MSG_GET);
-       BUILD_BUG_ON(LNET_REPLY_BIT != 1 << LNET_MSG_REPLY);
+       BUILD_BUG_ON(LNET_PUT_BIT != BIT(LNET_MSG_PUT));
+       BUILD_BUG_ON(LNET_ACK_BIT != BIT(LNET_MSG_ACK));
+       BUILD_BUG_ON(LNET_GET_BIT != BIT(LNET_MSG_GET));
+       BUILD_BUG_ON(LNET_REPLY_BIT != BIT(LNET_MSG_REPLY));
 
        mutex_init(&delay_dd.dd_mutex);
        spin_lock_init(&delay_dd.dd_lock);