Whamcloud - gitweb
LU-10391 lnet: extend lnet_is_nid_in_ping_info() 29/44629/16
authorMr NeilBrown <neilb@suse.de>
Mon, 15 Aug 2022 15:57:57 +0000 (11:57 -0400)
committerOleg Drokin <green@whamcloud.com>
Thu, 17 Nov 2022 06:54:47 +0000 (06:54 +0000)
lnet_is_nid_in_ping_info() now checks the ping_info for both
nid4 and larger nids.

Test-Parameters: trivial testlist=sanity-lnet
Test-Parameters: serverversion=2.12 serverdistro=el7.9 testlist=runtests
Test-Parameters: clientversion=2.12 testlist=runtests
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I7555947203acb5e5c6025ccb1ec5fba60bbf2f31
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/44629
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
lnet/include/lnet/lib-lnet.h
lnet/lnet/peer.c

index e2f3560..cab038a 100644 (file)
@@ -963,6 +963,15 @@ static inline void lnet_ping_buffer_decref(struct lnet_ping_buffer *pbuf)
        }
 }
 
+struct lnet_ping_iter {
+       struct lnet_ping_info   *pinfo;
+       void                    *pos, *end;
+};
+
+u32 *ping_iter_first(struct lnet_ping_iter *pi, struct lnet_ping_buffer *pbuf,
+                    struct lnet_nid *nid);
+u32 *ping_iter_next(struct lnet_ping_iter *pi, struct lnet_nid *nid);
+
 static inline int lnet_push_target_resize_needed(void)
 {
        return the_lnet.ln_push_target->pb_nbytes < the_lnet.ln_push_target_nbytes;
index b93f8dd..7be3eb4 100644 (file)
@@ -2889,6 +2889,56 @@ static void lnet_discovery_event_handler(struct lnet_event *event)
        lnet_net_unlock(LNET_LOCK_EX);
 }
 
+u32 *ping_iter_first(struct lnet_ping_iter *pi,
+                    struct lnet_ping_buffer *pbuf,
+                    struct lnet_nid *nid)
+{
+       pi->pinfo = &pbuf->pb_info;
+       pi->pos = &pbuf->pb_info.pi_ni;
+       pi->end = (void *)pi->pinfo +
+                 min_t(int, pbuf->pb_nbytes,
+                       lnet_ping_info_size(pi->pinfo));
+       /* lnet_ping_info_validiate ensures there will be one
+        * lnet_ni_status at the start
+        */
+       if (nid)
+               lnet_nid4_to_nid(pbuf->pb_info.pi_ni[0].ns_nid, nid);
+       return &pbuf->pb_info.pi_ni[0].ns_status;
+}
+
+u32 *ping_iter_next(struct lnet_ping_iter *pi, struct lnet_nid *nid)
+{
+       int off = offsetof(struct lnet_ping_info, pi_ni[pi->pinfo->pi_nnis]);
+
+       if (pi->pos < ((void *)pi->pinfo + off)) {
+               struct lnet_ni_status *ns = pi->pos;
+
+               pi->pos = ns + 1;
+               if (pi->pos > pi->end)
+                       return NULL;
+               if (nid)
+                       lnet_nid4_to_nid(ns->ns_nid, nid);
+               return &ns->ns_status;
+       }
+
+       while (pi->pinfo->pi_features & LNET_PING_FEAT_LARGE_ADDR) {
+               struct lnet_ni_large_status *lns = pi->pos;
+
+               if (pi->pos + 8 > pi->end)
+                       /* Not safe to examine next */
+                       return NULL;
+               pi->pos = lnet_ping_sts_next(lns);
+               if (pi->pos > pi->end)
+                       return NULL;
+               if (NID_BYTES(&lns->ns_nid) > sizeof(struct lnet_nid))
+                       continue;
+               if (nid)
+                       *nid = lns->ns_nid;
+               return &lns->ns_status;
+       }
+       return NULL;
+}
+
 /*
  * Build a peer from incoming data.
  *
@@ -3157,15 +3207,18 @@ lnet_peer_set_primary_data(struct lnet_peer *lp, struct lnet_ping_buffer *pbuf)
        return 0;
 }
 
-static bool lnet_is_nid_in_ping_info(lnet_nid_t nid, struct lnet_ping_info *pinfo)
+static bool lnet_is_nid_in_ping_info(struct lnet_nid *nid,
+                                    struct lnet_ping_buffer *pbuf)
 {
-       int i;
-
-       for (i = 0; i < pinfo->pi_nnis; i++) {
-               if (pinfo->pi_ni[i].ns_nid == nid)
+       struct lnet_ping_iter pi;
+       struct lnet_nid pnid;
+       u32 *st;
+
+       for (st = ping_iter_first(&pi, pbuf, &pnid);
+            st;
+            st = ping_iter_next(&pi, &pnid))
+               if (nid_same(nid, &pnid))
                        return true;
-       }
-
        return false;
 }
 
@@ -3325,8 +3378,7 @@ __must_hold(&lp->lp_lock)
         * recorded in that peer.
         */
        } else if (nid_same(&lp->lp_primary_nid, &nid) ||
-                  (lnet_is_nid_in_ping_info(lnet_nid_to_nid4(&lp->lp_primary_nid),
-                                            &pbuf->pb_info) &&
+                  (lnet_is_nid_in_ping_info(&lp->lp_primary_nid, pbuf) &&
                    lnet_is_discovery_disabled(lp))) {
                rc = lnet_peer_merge_data(lp, pbuf);
        } else {