From c87f70acd86c59425c9fd89682cd46498dcaeef5 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Fri, 10 Jul 2020 15:04:03 +1000 Subject: [PATCH] LU-10391 lnet: Change LNetDist to work with struct lnet_nid LNetDist now takes and returns 'struct lnet_nid' lustre_uuid_to_peer() is also updated. The 'dst' and 'src' parameters to LNetDist are now both pointers, and that can point to the same 'struct lnet_nid'. Code needs to be careful not to set *src until after the last use of *dst. Test-Parameters: trivial Test-Parameters: serverversion=2.12 serverdistro=el7.9 testlist=runtests Test-Parameters: clientversion=2.12 testlist=runtests Signed-off-by: Mr NeilBrown Change-Id: I267f3333e3164778a7df39d6b90f0a9a913fcdcf Reviewed-on: https://review.whamcloud.com/43618 Reviewed-by: James Simmons Reviewed-by: Chris Horn Reviewed-by: Amir Shehata Tested-by: jenkins Tested-by: Maloo Reviewed-by: Oleg Drokin --- lnet/include/lnet/api.h | 2 +- lnet/lnet/api-ni.c | 4 +++- lnet/lnet/lib-move.c | 34 +++++++++++++++++----------------- lustre/include/obd_class.h | 3 ++- lustre/obdclass/lustre_peer.c | 4 ++-- lustre/ptlrpc/events.c | 12 ++++++------ 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/lnet/include/lnet/api.h b/lnet/include/lnet/api.h index 093854b..930485a 100644 --- a/lnet/include/lnet/api.h +++ b/lnet/include/lnet/api.h @@ -75,7 +75,7 @@ int LNetNIFini(void); * \see LNetMEAttach * @{ */ int LNetGetId(unsigned int index, struct lnet_processid *id); -int LNetDist(lnet_nid_t nid, lnet_nid_t *srcnid, __u32 *order); +int LNetDist(struct lnet_nid *nid, struct lnet_nid *srcnid, __u32 *order); void LNetPrimaryNID(struct lnet_nid *nid); bool LNetIsPeerLocal(lnet_nid_t nid); diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 76cac6e..b9fb05d 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -4328,10 +4328,12 @@ LNetCtl(unsigned int cmd, void *arg) } case IOC_LIBCFS_LNET_DIST: - rc = LNetDist(data->ioc_nid, &data->ioc_nid, &data->ioc_u32[1]); + lnet_nid4_to_nid(data->ioc_nid, &nid); + rc = LNetDist(&nid, &nid, &data->ioc_u32[1]); if (rc < 0 && rc != -EHOSTUNREACH) return rc; + data->ioc_nid = lnet_nid_to_nid4(&nid); data->ioc_u32[0] = rc; return 0; diff --git a/lnet/lnet/lib-move.c b/lnet/lnet/lib-move.c index cce4841..01aab3e 100644 --- a/lnet/lnet/lib-move.c +++ b/lnet/lnet/lib-move.c @@ -5333,54 +5333,53 @@ 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 @@ -5401,6 +5400,8 @@ 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; } @@ -5431,13 +5432,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; diff --git a/lustre/include/obd_class.h b/lustre/include/obd_class.h index cd2421b..c1a9172 100644 --- a/lustre/include/obd_class.h +++ b/lustre/include/obd_class.h @@ -1838,7 +1838,8 @@ void lustre_tgt_unregister_fs(void); int lustre_check_exclusion(struct super_block *sb, char *svname); /* lustre_peer.c */ -int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index); +int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid, + int index); int class_add_uuid(const char *uuid, __u64 nid); int class_del_uuid (const char *uuid); int class_add_nids_to_uuid(struct obd_uuid *uuid, lnet_nid_t *nids, diff --git a/lustre/obdclass/lustre_peer.c b/lustre/obdclass/lustre_peer.c index 16b50f9..5cef033 100644 --- a/lustre/obdclass/lustre_peer.c +++ b/lustre/obdclass/lustre_peer.c @@ -50,7 +50,7 @@ struct uuid_nid_data { static LIST_HEAD(g_uuid_list); static DEFINE_SPINLOCK(g_uuid_lock); -int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index) +int lustre_uuid_to_peer(const char *uuid, struct lnet_nid *peer_nid, int index) { struct uuid_nid_data *data; struct obd_uuid tmp; @@ -64,7 +64,7 @@ int lustre_uuid_to_peer(const char *uuid, lnet_nid_t *peer_nid, int index) break; rc = 0; - *peer_nid = data->un_nids[index]; + lnet_nid4_to_nid(data->un_nids[index], peer_nid); break; } } diff --git a/lustre/ptlrpc/events.c b/lustre/ptlrpc/events.c index 06e4aad..b4956cc 100644 --- a/lustre/ptlrpc/events.c +++ b/lustre/ptlrpc/events.c @@ -535,18 +535,18 @@ int ptlrpc_uuid_to_peer(struct obd_uuid *uuid, int rc = -ENOENT; int dist; __u32 order; - lnet_nid_t dst_nid; - lnet_nid_t src_nid; + struct lnet_nid dst_nid; + struct lnet_nid src_nid; peer->pid = LNET_PID_LUSTRE; /* Choose the matching UUID that's closest */ while (lustre_uuid_to_peer(uuid->uuid, &dst_nid, count++) == 0) { if (peer->nid != LNET_NID_ANY && LNET_NIDADDR(peer->nid) == 0 && - LNET_NIDNET(dst_nid) != LNET_NIDNET(peer->nid)) + LNET_NID_NET(&dst_nid) != LNET_NIDNET(peer->nid)) continue; - dist = LNetDist(dst_nid, &src_nid, &order); + dist = LNetDist(&dst_nid, &src_nid, &order); if (dist < 0) continue; @@ -562,8 +562,8 @@ int ptlrpc_uuid_to_peer(struct obd_uuid *uuid, best_dist = dist; best_order = order; - peer->nid = dst_nid; - *self = src_nid; + peer->nid = lnet_nid_to_nid4(&dst_nid); + *self = lnet_nid_to_nid4(&src_nid); rc = 0; } } -- 1.8.3.1