From 56203e4ba0a64789e42ea45946e8c51f1db351fb Mon Sep 17 00:00:00 2001 From: Chris Horn Date: Wed, 22 Apr 2020 11:39:46 -0500 Subject: [PATCH] LU-12222 lnet: Introduce constant for the lolnd NID This patch adds a new constant, LNET_NID_LO_0, to represent the lolnd NID 0@lo. HPE-bug-id: LUS-8457 Signed-off-by: Chris Horn Change-Id: I3e57637f297b8de306905a447af8f025e31d1fcf Reviewed-on: https://review.whamcloud.com/38312 Tested-by: jenkins Reviewed-by: Andreas Dilger Tested-by: Maloo Reviewed-by: Serguei Smirnov Reviewed-by: Oleg Drokin --- lnet/include/uapi/linux/lnet/lnet-types.h | 3 ++ lnet/lnet/api-ni.c | 6 +-- lnet/lnet/config.c | 27 ++++++------- lnet/lnet/lib-move.c | 36 ++++++++--------- lnet/lnet/lib-msg.c | 5 +-- lnet/lnet/peer.c | 6 +-- lnet/lnet/router.c | 2 +- lnet/utils/lnetconfig/liblnetconfig.c | 3 +- lustre/llite/llite_lib.c | 2 +- lustre/lmv/lmv_obd.c | 4 +- lustre/mgc/mgc_request.c | 3 +- lustre/obdclass/obd_mount.c | 2 +- lustre/obdclass/obd_mount_server.c | 2 +- lustre/ptlrpc/events.c | 18 ++++----- lustre/ptlrpc/nodemap_handler.c | 8 ++-- lustre/target/tgt_handler.c | 9 ++--- lustre/utils/portals.c | 66 +++++++++++++++---------------- 17 files changed, 100 insertions(+), 102 deletions(-) diff --git a/lnet/include/uapi/linux/lnet/lnet-types.h b/lnet/include/uapi/linux/lnet/lnet-types.h index 616e80c..3280e1f 100644 --- a/lnet/include/uapi/linux/lnet/lnet-types.h +++ b/lnet/include/uapi/linux/lnet/lnet-types.h @@ -107,6 +107,9 @@ static inline __u32 LNET_MKNET(__u32 type, __u32 num) return (type << 16) | num; } +/** The lolnd NID (i.e. myself) */ +#define LNET_NID_LO_0 LNET_MKNID(LNET_MKNET(LOLND, 0), 0) + #define WIRE_ATTR __attribute__((packed)) /* Packed version of struct lnet_process_id to transfer via network */ diff --git a/lnet/lnet/api-ni.c b/lnet/lnet/api-ni.c index 5922a6af..3fda86b 100644 --- a/lnet/lnet/api-ni.c +++ b/lnet/lnet/api-ni.c @@ -1645,7 +1645,7 @@ lnet_ping_info_validate(struct lnet_ping_info *pinfo) /* Loopback is guaranteed to be present */ if (pinfo->pi_nnis < 1 || pinfo->pi_nnis > lnet_interfaces_max) return -ERANGE; - if (LNET_NETTYP(LNET_NIDNET(LNET_PING_INFO_LONI(pinfo))) != LOLND) + if (LNET_PING_INFO_LONI(pinfo) != LNET_NID_LO_0) return -EPROTO; return 0; } @@ -2807,7 +2807,7 @@ lnet_fill_ni_info(struct lnet_ni *ni, struct lnet_ioctl_config_ni *cfg_ni, } cfg_ni->lic_nid = ni->ni_nid; - if (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND) + if (ni->ni_nid == LNET_NID_LO_0) cfg_ni->lic_status = LNET_NI_STATUS_UP; else cfg_ni->lic_status = ni->ni_status->ns_status; @@ -2899,7 +2899,7 @@ lnet_fill_ni_info_legacy(struct lnet_ni *ni, config->cfg_config_u.cfg_net.net_peer_rtr_credits = ni->ni_net->net_tunables.lct_peer_rtr_credits; - if (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND) + if (ni->ni_nid == LNET_NID_LO_0) net_config->ni_status = LNET_NI_STATUS_UP; else net_config->ni_status = ni->ni_status->ns_status; diff --git a/lnet/lnet/config.c b/lnet/lnet/config.c index 7fea3999..b27306e 100644 --- a/lnet/lnet/config.c +++ b/lnet/lnet/config.c @@ -1101,7 +1101,7 @@ lnet_parse_priority(char *str, unsigned int *priority, char **token) } static int -lnet_parse_route (char *str, int *im_a_router) +lnet_parse_route(char *str, int *im_a_router) { /* static scratch buffer OK (single threaded) */ static char cmd[LNET_SINGLE_TEXTBUF_NOB]; @@ -1110,17 +1110,17 @@ lnet_parse_route (char *str, int *im_a_router) LIST_HEAD(gateways); struct list_head *tmp1; struct list_head *tmp2; - __u32 net; - lnet_nid_t nid; - struct lnet_text_buf *ltb; - int rc; - char *sep; - char *token = str; - int ntokens = 0; - int myrc = -1; - __u32 hops; - int got_hops = 0; - unsigned int priority = 0; + __u32 net; + lnet_nid_t nid; + struct lnet_text_buf *ltb; + int rc; + char *sep; + char *token = str; + int ntokens = 0; + int myrc = -1; + __u32 hops; + int got_hops = 0; + unsigned int priority = 0; /* save a copy of the string for error messages */ strncpy(cmd, str, sizeof(cmd)); @@ -1191,8 +1191,7 @@ lnet_parse_route (char *str, int *im_a_router) goto token_error; nid = libcfs_str2nid(ltb->ltb_text); - if (nid == LNET_NID_ANY || - LNET_NETTYP(LNET_NIDNET(nid)) == LOLND) + if (nid == LNET_NID_ANY || nid == LNET_NID_LO_0) goto token_error; } } diff --git a/lnet/lnet/lib-move.c b/lnet/lnet/lib-move.c index ca4f62d..9dee2f9 100644 --- a/lnet/lnet/lib-move.c +++ b/lnet/lnet/lib-move.c @@ -753,12 +753,12 @@ lnet_prep_send(struct lnet_msg *msg, int type, struct lnet_process_id target, static void lnet_ni_send(struct lnet_ni *ni, struct lnet_msg *msg) { - void *priv = msg->msg_private; + void *priv = msg->msg_private; int rc; - LASSERT (!in_interrupt ()); - LASSERT (LNET_NETTYP(LNET_NIDNET(ni->ni_nid)) == LOLND || - (msg->msg_txcredit && msg->msg_peertxcredit)); + LASSERT(!in_interrupt()); + LASSERT(ni->ni_nid == LNET_NID_LO_0 || + (msg->msg_txcredit && msg->msg_peertxcredit)); rc = (ni->ni_net->net_lnd->lnd_send)(ni, priv, msg); if (rc < 0) { @@ -2623,12 +2623,12 @@ static int lnet_select_pathway(lnet_nid_t src_nid, lnet_nid_t dst_nid, struct lnet_msg *msg, lnet_nid_t rtr_nid) { - struct lnet_peer_ni *lpni; - struct lnet_peer *peer; - struct lnet_send_data send_data; - int cpt, rc; - int md_cpt; - __u32 send_case = 0; + struct lnet_peer_ni *lpni; + struct lnet_peer *peer; + struct lnet_send_data send_data; + int cpt, rc; + int md_cpt; + __u32 send_case = 0; memset(&send_data, 0, sizeof(send_data)); @@ -2656,7 +2656,7 @@ again: */ send_data.sd_msg = msg; send_data.sd_cpt = cpt; - if (LNET_NETTYP(LNET_NIDNET(dst_nid)) == LOLND) { + if (dst_nid == LNET_NID_LO_0) { rc = lnet_handle_lo_send(&send_data); lnet_net_unlock(cpt); return rc; @@ -5047,14 +5047,14 @@ EXPORT_SYMBOL(LNetGet); int LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp) { - struct list_head *e; + struct list_head *e; struct lnet_ni *ni = NULL; struct lnet_remotenet *rnet; - __u32 dstnet = LNET_NIDNET(dstnid); - int hops; - int cpt; - __u32 order = 2; - struct list_head *rn_list; + __u32 dstnet = LNET_NIDNET(dstnid); + int hops; + int cpt; + __u32 order = 2; + struct list_head *rn_list; /* 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 @@ -5070,7 +5070,7 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp) if (srcnidp != NULL) *srcnidp = dstnid; if (orderp != NULL) { - if (LNET_NETTYP(LNET_NIDNET(dstnid)) == LOLND) + if (dstnid == LNET_NID_LO_0) *orderp = 0; else *orderp = 1; diff --git a/lnet/lnet/lib-msg.c b/lnet/lnet/lib-msg.c index e8c6025..d7e8436 100644 --- a/lnet/lnet/lib-msg.c +++ b/lnet/lnet/lib-msg.c @@ -791,11 +791,10 @@ lnet_health_check(struct lnet_msg *msg) * if we're sending to the LOLND then the msg_txpeer will not be * set. So no need to sanity check it. */ - if (msg->msg_tx_committed && - LNET_NETTYP(LNET_NIDNET(msg->msg_txni->ni_nid)) != LOLND) + if (msg->msg_tx_committed && msg->msg_txni->ni_nid != LNET_NID_LO_0) LASSERT(msg->msg_txpeer); else if (msg->msg_tx_committed && - LNET_NETTYP(LNET_NIDNET(msg->msg_txni->ni_nid)) == LOLND) + msg->msg_txni->ni_nid == LNET_NID_LO_0) lo = true; if (hstatus != LNET_MSG_STATUS_OK && diff --git a/lnet/lnet/peer.c b/lnet/lnet/peer.c index 37a76c8..8b32c2a 100644 --- a/lnet/lnet/peer.c +++ b/lnet/lnet/peer.c @@ -277,7 +277,7 @@ lnet_peer_alloc(lnet_nid_t nid) * to ever use a different interface when sending messages to * myself. */ - if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND) + if (nid == LNET_NID_LO_0) lp->lp_state = LNET_PEER_NO_DISCOVERY; lp->lp_cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER); @@ -2632,7 +2632,7 @@ static int lnet_peer_merge_data(struct lnet_peer *lp, * present in curnis[] then this peer is for this node. */ for (i = 0; i < ncurnis; i++) { - if (LNET_NETTYP(LNET_NIDNET(curnis[i])) == LOLND) + if (curnis[i] == LNET_NID_LO_0) continue; for (j = 1; j < pbuf->pb_info.pi_nnis; j++) { if (curnis[i] == pbuf->pb_info.pi_ni[j].ns_nid) { @@ -2855,7 +2855,7 @@ __must_hold(&lp->lp_lock) if (pbuf->pb_info.pi_nnis <= 1) goto out; nid = pbuf->pb_info.pi_ni[1].ns_nid; - if (LNET_NETTYP(LNET_NIDNET(lp->lp_primary_nid)) == LOLND) { + if (lp->lp_primary_nid == LNET_NID_LO_0) { rc = lnet_peer_set_primary_nid(lp, nid, flags); if (!rc) rc = lnet_peer_merge_data(lp, pbuf); diff --git a/lnet/lnet/router.c b/lnet/lnet/router.c index d573fa3..9d7a839 100644 --- a/lnet/lnet/router.c +++ b/lnet/lnet/router.c @@ -679,7 +679,7 @@ lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway, libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway)); if (gateway == LNET_NID_ANY || - LNET_NETTYP(LNET_NIDNET(gateway)) == LOLND || + gateway == LNET_NID_LO_0 || net == LNET_NIDNET(LNET_NID_ANY) || LNET_NETTYP(net) == LOLND || LNET_NIDNET(gateway) == net || diff --git a/lnet/utils/lnetconfig/liblnetconfig.c b/lnet/utils/lnetconfig/liblnetconfig.c index 5714b5c..2dd0a45 100644 --- a/lnet/utils/lnetconfig/liblnetconfig.c +++ b/lnet/utils/lnetconfig/liblnetconfig.c @@ -610,8 +610,7 @@ static int infra_ping_nid(char *ping_nids, char *oper, int param, int ioc_call, goto out; for (i = 0; i < ping.ping_count; i++) { - if (!strcmp(libcfs_nid2str(ping.ping_buf[i].nid), - "0@lo")) + if (ping.ping_buf[i].nid == LNET_NID_LO_0) continue; peer_ni = cYAML_create_seq_item(tmp); if (peer_ni == NULL) diff --git a/lustre/llite/llite_lib.c b/lustre/llite/llite_lib.c index a632430..6c6cc80 100644 --- a/lustre/llite/llite_lib.c +++ b/lustre/llite/llite_lib.c @@ -2914,7 +2914,7 @@ void ll_compute_rootsquash_state(struct ll_sb_info *sbi) matched = false; i = 0; while (LNetGetId(i++, &id) != -ENOENT) { - if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND) + if (id.nid == LNET_NID_LO_0) continue; if (cfs_match_nid(id.nid, &squash->rsi_nosquash_nids)) { matched = true; diff --git a/lustre/lmv/lmv_obd.c b/lustre/lmv/lmv_obd.c index e28cd46..25b09c4 100644 --- a/lustre/lmv/lmv_obd.c +++ b/lustre/lmv/lmv_obd.c @@ -1126,7 +1126,7 @@ static int lmv_setup(struct obd_device *obd, struct lustre_cfg *lcfg) * can distribute subdirs evenly from the beginning. */ while (LNetGetId(i++, &lnet_id) != -ENOENT) { - if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) { + if (lnet_id.nid != LNET_NID_LO_0) { lmv->lmv_qos_rr_index = (u32)lnet_id.nid; break; } @@ -1214,7 +1214,7 @@ static int lmv_select_statfs_mdt(struct lmv_obd *lmv, __u32 flags) if (LNetGetId(i, &lnet_id) == -ENOENT) break; - if (LNET_NETTYP(LNET_NIDNET(lnet_id.nid)) != LOLND) { + if (lnet_id.nid != LNET_NID_LO_0) { /* We dont need a full 64-bit modulus, just enough * to distribute the requests across MDTs evenly. */ diff --git a/lustre/mgc/mgc_request.c b/lustre/mgc/mgc_request.c index 1776eff..c0fed41 100644 --- a/lustre/mgc/mgc_request.c +++ b/lustre/mgc/mgc_request.c @@ -1605,8 +1605,7 @@ static int mgc_process_recover_nodemap_log(struct obd_device *obd, mgc_conn = class_exp2cliimp(cld->cld_mgcexp)->imp_connection; /* don't need to get local config */ - if (cld_is_nodemap(cld) && - (LNET_NETTYP(LNET_NIDNET(mgc_conn->c_peer.nid)) == LOLND)) + if (cld_is_nodemap(cld) && (mgc_conn->c_peer.nid == LNET_NID_LO_0)) GOTO(out, rc = 0); /* allocate buffer for bulk transfer. diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index d9122c5..0c68d2f 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -249,7 +249,7 @@ int lustre_start_mgc(struct super_block *sb) struct lnet_process_id id; while ((rc = LNetGetId(i++, &id)) != -ENOENT) { - if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND) + if (id.nid == LNET_NID_LO_0) continue; nid = id.nid; i++; diff --git a/lustre/obdclass/obd_mount_server.c b/lustre/obdclass/obd_mount_server.c index 24bf5c7..55bbddf 100644 --- a/lustre/obdclass/obd_mount_server.c +++ b/lustre/obdclass/obd_mount_server.c @@ -1161,7 +1161,7 @@ static int server_lsi2mti(struct lustre_sb_info *lsi, mti->mti_nid_count = 0; while (LNetGetId(i++, &id) != -ENOENT) { - if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND) + if (id.nid == LNET_NID_LO_0) continue; /* server use --servicenode param, only allow specified diff --git a/lustre/ptlrpc/events.c b/lustre/ptlrpc/events.c index 52be97b..147d406 100644 --- a/lustre/ptlrpc/events.c +++ b/lustre/ptlrpc/events.c @@ -506,14 +506,14 @@ static void ptlrpc_master_callback(struct lnet_event *ev) int ptlrpc_uuid_to_peer(struct obd_uuid *uuid, struct lnet_process_id *peer, lnet_nid_t *self) { - int best_dist = 0; - __u32 best_order = 0; - int count = 0; - int rc = -ENOENT; - int dist; - __u32 order; - lnet_nid_t dst_nid; - lnet_nid_t src_nid; + int best_dist = 0; + __u32 best_order = 0; + int count = 0; + int rc = -ENOENT; + int dist; + __u32 order; + lnet_nid_t dst_nid; + lnet_nid_t src_nid; peer->pid = LNET_PID_LUSTRE; @@ -528,7 +528,7 @@ int ptlrpc_uuid_to_peer(struct obd_uuid *uuid, continue; if (dist == 0) { /* local! use loopback LND */ - peer->nid = *self = LNET_MKNID(LNET_MKNET(LOLND, 0), 0); + peer->nid = *self = LNET_NID_LO_0; rc = 0; break; } diff --git a/lustre/ptlrpc/nodemap_handler.c b/lustre/ptlrpc/nodemap_handler.c index c847f40..a30cd9c 100644 --- a/lustre/ptlrpc/nodemap_handler.c +++ b/lustre/ptlrpc/nodemap_handler.c @@ -257,14 +257,14 @@ struct lu_nodemap *nodemap_lookup(const char *name) */ struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid) { - struct lu_nid_range *range; - struct lu_nodemap *nodemap; + struct lu_nid_range *range; + struct lu_nodemap *nodemap; int rc; ENTRY; /* don't use 0@lo, use the first non-lo local NID instead */ - if (LNET_NETTYP(LNET_NIDNET(nid)) == LOLND) { + if (nid == LNET_NID_LO_0) { struct lnet_process_id id; int i = 0; @@ -272,7 +272,7 @@ struct lu_nodemap *nodemap_classify_nid(lnet_nid_t nid) rc = LNetGetId(i++, &id); if (rc < 0) RETURN(ERR_PTR(-EINVAL)); - } while (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND); + } while (id.nid == LNET_NID_LO_0); nid = id.nid; CDEBUG(D_INFO, "found nid %s\n", libcfs_nid2str(nid)); diff --git a/lustre/target/tgt_handler.c b/lustre/target/tgt_handler.c index 7624a02..221342a 100644 --- a/lustre/target/tgt_handler.c +++ b/lustre/target/tgt_handler.c @@ -886,9 +886,9 @@ EXPORT_SYMBOL(tgt_counter_incr); int tgt_connect_check_sptlrpc(struct ptlrpc_request *req, struct obd_export *exp) { - struct lu_target *tgt = class_exp2tgt(exp); - struct sptlrpc_flavor flvr; - int rc = 0; + struct lu_target *tgt = class_exp2tgt(exp); + struct sptlrpc_flavor flvr; + int rc = 0; LASSERT(tgt); LASSERT(tgt->lut_obd); @@ -918,8 +918,7 @@ int tgt_connect_check_sptlrpc(struct ptlrpc_request *req, struct obd_export *exp if ((strcmp(exp->exp_obd->obd_type->typ_name, LUSTRE_MGS_NAME) == 0) && (exp->exp_flvr.sf_rpc == SPTLRPC_FLVR_NULL || - LNET_NETTYP(LNET_NIDNET(exp->exp_connection->c_peer.nid)) - == LOLND)) + exp->exp_connection->c_peer.nid == LNET_NID_LO_0)) exp->exp_flvr.sf_rpc = SPTLRPC_FLVR_ANY; if (exp->exp_flvr.sf_rpc != SPTLRPC_FLVR_ANY && diff --git a/lustre/utils/portals.c b/lustre/utils/portals.c index ca2eb34..abc7dba 100644 --- a/lustre/utils/portals.c +++ b/lustre/utils/portals.c @@ -352,44 +352,44 @@ int jt_ptl_network(int argc, char **argv) int jt_ptl_list_nids(int argc, char **argv) { - struct libcfs_ioctl_data data; - int all = 0, return_nid = 0; - int count; - int rc; + struct libcfs_ioctl_data data; + int all = 0, return_nid = 0; + int count; + int rc; - all = (argc == 2) && (strcmp(argv[1], "all") == 0); - /* Hack to pass back value */ - return_nid = (argc == 2) && (argv[1][0] == 1); + all = (argc == 2) && (strcmp(argv[1], "all") == 0); + /* Hack to pass back value */ + return_nid = (argc == 2) && (argv[1][0] == 1); - if ((argc > 2) && !(all || return_nid)) { - fprintf(stderr, "usage: %s [all]\n", argv[0]); - return 0; - } + if ((argc > 2) && !(all || return_nid)) { + fprintf(stderr, "usage: %s [all]\n", argv[0]); + return 0; + } - for (count = 0;; count++) { - LIBCFS_IOC_INIT (data); - data.ioc_count = count; - rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NI, &data); - - if (rc < 0) { - if ((count > 0) && (errno == ENOENT)) - /* We found them all */ - break; - fprintf(stderr,"IOC_LIBCFS_GET_NI error %d: %s\n", - errno, strerror(errno)); - return -1; - } + for (count = 0;; count++) { + LIBCFS_IOC_INIT(data); + data.ioc_count = count; + rc = l_ioctl(LNET_DEV_ID, IOC_LIBCFS_GET_NI, &data); + + if (rc < 0) { + if ((count > 0) && (errno == ENOENT)) + /* We found them all */ + break; + fprintf(stderr, "IOC_LIBCFS_GET_NI error %d: %s\n", + errno, strerror(errno)); + return -1; + } - if (all || (LNET_NETTYP(LNET_NIDNET(data.ioc_nid)) != LOLND)) { - printf("%s\n", libcfs_nid2str(data.ioc_nid)); - if (return_nid) { - *(__u64 *)(argv[1]) = data.ioc_nid; - return_nid--; - } - } - } + if (all || (data.ioc_nid != LNET_NID_LO_0)) { + printf("%s\n", libcfs_nid2str(data.ioc_nid)); + if (return_nid) { + *(__u64 *)(argv[1]) = data.ioc_nid; + return_nid--; + } + } + } - return 0; + return 0; } int -- 1.8.3.1