The nid in 'struct lnet_route' is now a struct lnet_nid'.
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 <neilb@suse.de>
Change-Id: I2e2f2e9c8d2cbdbc87b408ee4589952f2df02880
Reviewed-on: https://review.whamcloud.com/43593
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Chris Horn <chris.horn@hpe.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
time64_t when);
void lnet_notify_locked(struct lnet_peer_ni *lp, int notifylnd, int alive,
time64_t when);
-int lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway_nid,
+int lnet_add_route(__u32 net, __u32 hops, struct lnet_nid *gateway,
__u32 priority, __u32 sensitivity);
int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
void lnet_move_route(struct lnet_route *route, struct lnet_peer *lp,
void lnet_net_clr_pref_rtrs(struct lnet_net *net);
int lnet_net_add_pref_rtr(struct lnet_net *net, lnet_nid_t gw_nid);
-int lnet_islocalnid(lnet_nid_t nid);
+int lnet_islocalnid4(lnet_nid_t nid);
+int lnet_islocalnid(struct lnet_nid *nid);
int lnet_islocalnet(__u32 net);
int lnet_islocalnet_locked(__u32 net);
struct lnet_peer_ni *prev);
struct lnet_peer_ni *lnet_nid2peerni_locked(lnet_nid_t nid, lnet_nid_t pref,
int cpt);
-struct lnet_peer_ni *lnet_nid2peerni_ex(lnet_nid_t nid, int cpt);
+struct lnet_peer_ni *lnet_nid2peerni_ex(struct lnet_nid *nid, int cpt);
struct lnet_peer_ni *lnet_peer_get_ni_locked(struct lnet_peer *lp,
lnet_nid_t nid);
+struct lnet_peer_ni *lnet_peer_ni_get_locked(struct lnet_peer *lp,
+ struct lnet_nid *nid);
struct lnet_peer_ni *lnet_find_peer_ni_locked(lnet_nid_t nid);
struct lnet_peer_ni *lnet_peer_ni_find_locked(struct lnet_nid *nid);
struct lnet_peer *lnet_find_peer(lnet_nid_t nid);
struct list_head lr_list; /* chain on net */
struct list_head lr_gwlist; /* chain on gateway */
struct lnet_peer *lr_gateway; /* router node */
- lnet_nid_t lr_nid; /* NID used to add route */
+ struct lnet_nid lr_nid; /* NID used to add route */
__u32 lr_net; /* remote network number */
__u32 lr_lnet; /* local network number */
int lr_seq; /* sequence for round-robin */
EXPORT_SYMBOL(lnet_nid_to_ni_addref);
int
-lnet_islocalnid(lnet_nid_t nid)
+lnet_islocalnid4(lnet_nid_t nid)
{
struct lnet_ni *ni;
int cpt;
}
int
+lnet_islocalnid(struct lnet_nid *nid)
+{
+ struct lnet_ni *ni;
+ int cpt;
+
+ cpt = lnet_net_lock_current();
+ ni = lnet_nid_to_ni_locked(nid, cpt);
+ lnet_net_unlock(cpt);
+
+ return ni != NULL;
+}
+
+int
lnet_count_acceptor_nets(void)
{
/* Return the # of NIs that need the acceptor. */
struct lnet_ioctl_config_data *config;
struct lnet_process_id id = {0};
struct lnet_ni *ni;
+ struct lnet_nid nid;
int rc;
BUILD_BUG_ON(sizeof(struct lnet_ioctl_net_config) +
config->cfg_config_u.cfg_route.rtr_sensitivity;
}
+ lnet_nid4_to_nid(config->cfg_nid, &nid);
mutex_lock(&the_lnet.ln_api_mutex);
rc = lnet_add_route(config->cfg_net,
config->cfg_config_u.cfg_route.rtr_hop,
- config->cfg_nid,
+ &nid,
config->cfg_config_u.cfg_route.
rtr_priority, sensitivity);
mutex_unlock(&the_lnet.ln_api_mutex);
struct list_head *tmp1;
struct list_head *tmp2;
__u32 net;
- lnet_nid_t nid;
- struct lnet_text_buf *ltb;
+ struct lnet_nid nid;
+ struct lnet_text_buf *ltb;
int rc;
char *sep;
char *token = str;
if (rc < 0)
goto token_error;
- nid = libcfs_str2nid(ltb->ltb_text);
- if (nid == LNET_NID_ANY || nid == LNET_NID_LO_0)
+ if (libcfs_strnid(&nid, ltb->ltb_text) != 0 ||
+ nid_is_lo0(&nid))
goto token_error;
}
}
list_for_each(tmp2, &gateways) {
ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
- nid = libcfs_str2nid(ltb->ltb_text);
- LASSERT(nid != LNET_NID_ANY);
+ LASSERT(libcfs_strnid(&nid, ltb->ltb_text) == 0);
- if (lnet_islocalnid(nid)) {
+ if (lnet_islocalnid(&nid)) {
*im_a_router = 1;
continue;
}
- rc = lnet_add_route(net, hops, nid, priority, 1);
+ rc = lnet_add_route(net, hops, &nid, priority, 1);
if (rc != 0 && rc != -EEXIST && rc != -EHOSTUNREACH) {
CERROR("Can't create route "
"to %s via %s\n",
libcfs_net2str(net),
- libcfs_nid2str(nid));
+ libcfs_nidstr(&nid));
goto out;
}
}
return -EPROTO;
}
- if (lnet_islocalnid(dest_nid)) {
+ if (lnet_islocalnid4(dest_nid)) {
/* dest is another local NI; sender should have used
* this node's NID on its own network */
CERROR("%s, src %s: Bad dest nid %s "
}
static struct lnet_peer_ni *
-lnet_peer_ni_alloc(lnet_nid_t nid4)
+lnet_peer_ni_alloc(struct lnet_nid *nid)
{
struct lnet_peer_ni *lpni;
struct lnet_net *net;
- struct lnet_nid nid;
int cpt;
- lnet_nid4_to_nid(nid4, &nid);
- cpt = lnet_nid_cpt_hash(&nid, LNET_CPT_NUMBER);
+ cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
LIBCFS_CPT_ALLOC(lpni, lnet_cpt_table(), cpt, sizeof(*lpni));
if (!lpni)
else
lpni->lpni_ns_status = LNET_NI_STATUS_UP;
lpni->lpni_ping_feats = LNET_PING_FEAT_INVAL;
- lpni->lpni_nid = nid;
+ lpni->lpni_nid = *nid;
lpni->lpni_cpt = cpt;
atomic_set(&lpni->lpni_healthv, LNET_MAX_HEALTH_VALUE);
- net = lnet_get_net_locked(LNET_NID_NET(&nid));
+ net = lnet_get_net_locked(LNET_NID_NET(nid));
lpni->lpni_net = net;
if (net) {
lpni->lpni_txcredits = net->net_tunables.lct_peer_tx_credits;
}
static struct lnet_peer *
-lnet_peer_alloc(lnet_nid_t nid4)
+lnet_peer_alloc(struct lnet_nid *nid)
{
struct lnet_peer *lp;
- struct lnet_nid nid;
- lnet_nid4_to_nid(nid4, &nid);
LIBCFS_CPT_ALLOC(lp, lnet_cpt_table(), CFS_CPT_ANY, sizeof(*lp));
if (!lp)
return NULL;
INIT_LIST_HEAD(&lp->lp_rtr_list);
init_waitqueue_head(&lp->lp_dc_waitq);
spin_lock_init(&lp->lp_lock);
- lp->lp_primary_nid = nid;
+ lp->lp_primary_nid = *nid;
lp->lp_disc_src_nid = LNET_ANY_NID;
lp->lp_disc_dst_nid = LNET_ANY_NID;
if (lnet_peers_start_down())
* to ever use a different interface when sending messages to
* myself.
*/
- if (nid_is_lo0(&nid))
+ if (nid_is_lo0(nid))
lp->lp_state = LNET_PEER_NO_DISCOVERY;
- lp->lp_cpt = lnet_nid_cpt_hash(&nid, LNET_CPT_NUMBER);
+ lp->lp_cpt = lnet_nid_cpt_hash(nid, LNET_CPT_NUMBER);
CDEBUG(D_NET, "%p nid %s\n", lp, libcfs_nidstr(&lp->lp_primary_nid));
return NULL;
}
+struct lnet_peer_ni *
+lnet_peer_ni_get_locked(struct lnet_peer *lp, struct lnet_nid *nid)
+{
+ struct lnet_peer_net *lpn;
+ struct lnet_peer_ni *lpni;
+
+ lpn = lnet_peer_get_net_locked(lp, LNET_NID_NET(nid));
+ if (!lpn)
+ return NULL;
+
+ list_for_each_entry(lpni, &lpn->lpn_peer_nis, lpni_peer_nis) {
+ if (nid_same(&lpni->lpni_nid, nid))
+ return lpni;
+ }
+
+ return NULL;
+}
+
struct lnet_peer *
lnet_find_peer(lnet_nid_t nid)
{
* Call with the lnet_api_mutex held.
*/
static int
-lnet_peer_add(lnet_nid_t nid, unsigned flags)
+lnet_peer_add(lnet_nid_t nid4, unsigned int flags)
{
+ struct lnet_nid nid;
struct lnet_peer *lp;
struct lnet_peer_net *lpn;
struct lnet_peer_ni *lpni;
int rc = 0;
- LASSERT(nid != LNET_NID_ANY);
+ LASSERT(nid4 != LNET_NID_ANY);
/*
* No need for the lnet_net_lock here, because the
* lnet_api_mutex is held.
*/
- lpni = lnet_find_peer_ni_locked(nid);
+ lpni = lnet_find_peer_ni_locked(nid4);
if (lpni) {
/* A peer with this NID already exists. */
lp = lpni->lpni_peer_net->lpn_peer;
* that an existing peer is being modified.
*/
if (lp->lp_state & LNET_PEER_CONFIGURED) {
- if (lnet_nid_to_nid4(&lp->lp_primary_nid) != nid)
+ if (lnet_nid_to_nid4(&lp->lp_primary_nid) != nid4)
rc = -EEXIST;
else if ((lp->lp_state ^ flags) & LNET_PEER_MULTI_RAIL)
rc = -EPERM;
goto out;
} else if (!(flags & LNET_PEER_CONFIGURED)) {
- if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid) {
+ if (lnet_nid_to_nid4(&lp->lp_primary_nid) == nid4) {
rc = -EEXIST;
goto out;
}
/* Create peer, peer_net, and peer_ni. */
rc = -ENOMEM;
- lp = lnet_peer_alloc(nid);
+ lnet_nid4_to_nid(nid4, &nid);
+ lp = lnet_peer_alloc(&nid);
if (!lp)
goto out;
- lpn = lnet_peer_net_alloc(LNET_NIDNET(nid));
+ lpn = lnet_peer_net_alloc(LNET_NID_NET(&nid));
if (!lpn)
goto out_free_lp;
- lpni = lnet_peer_ni_alloc(nid);
+ lpni = lnet_peer_ni_alloc(&nid);
if (!lpni)
goto out_free_lpn;
LIBCFS_FREE(lp, sizeof(*lp));
out:
CDEBUG(D_NET, "peer %s NID flags %#x: %d\n",
- libcfs_nid2str(nid), flags, rc);
+ libcfs_nid2str(nid4), flags, rc);
return rc;
}
* non-multi-rail peer.
*/
static int
-lnet_peer_add_nid(struct lnet_peer *lp, lnet_nid_t nid, unsigned flags)
+lnet_peer_add_nid(struct lnet_peer *lp, lnet_nid_t nid4, unsigned int flags)
{
struct lnet_peer_net *lpn;
struct lnet_peer_ni *lpni;
+ struct lnet_nid nid;
int rc = 0;
LASSERT(lp);
- LASSERT(nid != LNET_NID_ANY);
+ LASSERT(nid4 != LNET_NID_ANY);
+
+ lnet_nid4_to_nid(nid4, &nid);
/* A configured peer can only be updated through configuration. */
if (!(flags & LNET_PEER_CONFIGURED)) {
goto out;
}
- lpni = lnet_find_peer_ni_locked(nid);
+ lpni = lnet_find_peer_ni_locked(nid4);
if (lpni) {
/*
* A peer_ni already exists. This is only a problem if
}
lnet_peer_del(lp2);
lnet_peer_ni_decref_locked(lpni);
- lpni = lnet_peer_ni_alloc(nid);
+ lpni = lnet_peer_ni_alloc(&nid);
if (!lpni) {
rc = -ENOMEM;
goto out_free_lpni;
}
}
} else {
- lpni = lnet_peer_ni_alloc(nid);
+ lpni = lnet_peer_ni_alloc(&nid);
if (!lpni) {
rc = -ENOMEM;
goto out_free_lpni;
* Get the peer_net. Check that we're not adding a second
* peer_ni on a peer_net of a non-multi-rail peer.
*/
- lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid));
+ lpn = lnet_peer_get_net_locked(lp, LNET_NIDNET(nid4));
if (!lpn) {
- lpn = lnet_peer_net_alloc(LNET_NIDNET(nid));
+ lpn = lnet_peer_net_alloc(LNET_NIDNET(nid4));
if (!lpn) {
rc = -ENOMEM;
goto out_free_lpni;
lnet_peer_ni_decref_locked(lpni);
out:
CDEBUG(D_NET, "peer %s NID %s flags %#x: %d\n",
- libcfs_nidstr(&lp->lp_primary_nid), libcfs_nid2str(nid),
+ libcfs_nidstr(&lp->lp_primary_nid), libcfs_nid2str(nid4),
flags, rc);
return rc;
}
* lpni creation initiated due to traffic either sending or receiving.
*/
static int
-lnet_peer_ni_traffic_add(lnet_nid_t nid, lnet_nid_t pref)
+lnet_peer_ni_traffic_add(struct lnet_nid *nid, lnet_nid_t pref)
{
struct lnet_peer *lp;
struct lnet_peer_net *lpn;
unsigned flags = 0;
int rc = 0;
- if (nid == LNET_NID_ANY) {
+ if (LNET_NID_IS_ANY(nid)) {
rc = -EINVAL;
goto out;
}
/* lnet_net_lock is not needed here because ln_api_lock is held */
- lpni = lnet_find_peer_ni_locked(nid);
+ lpni = lnet_peer_ni_find_locked(nid);
if (lpni) {
/*
* We must have raced with another thread. Since we
lp = lnet_peer_alloc(nid);
if (!lp)
goto out;
- lpn = lnet_peer_net_alloc(LNET_NIDNET(nid));
+ lpn = lnet_peer_net_alloc(LNET_NID_NET(nid));
if (!lpn)
goto out_free_lp;
lpni = lnet_peer_ni_alloc(nid);
out_free_lp:
LIBCFS_FREE(lp, sizeof(*lp));
out:
- CDEBUG(D_NET, "peer %s: %d\n", libcfs_nid2str(nid), rc);
+ CDEBUG(D_NET, "peer %s: %d\n", libcfs_nidstr(nid), rc);
return rc;
}
}
struct lnet_peer_ni *
-lnet_nid2peerni_ex(lnet_nid_t nid, int cpt)
+lnet_nid2peerni_ex(struct lnet_nid *nid, int cpt)
{
struct lnet_peer_ni *lpni = NULL;
int rc;
* find if a peer_ni already exists.
* If so then just return that.
*/
- lpni = lnet_find_peer_ni_locked(nid);
+ lpni = lnet_peer_ni_find_locked(nid);
if (lpni)
return lpni;
goto out_net_relock;
}
- lpni = lnet_find_peer_ni_locked(nid);
+ lpni = lnet_peer_ni_find_locked(nid);
LASSERT(lpni);
out_net_relock:
* hold on the peer_ni.
*/
struct lnet_peer_ni *
-lnet_nid2peerni_locked(lnet_nid_t nid, lnet_nid_t pref, int cpt)
+lnet_nid2peerni_locked(lnet_nid_t nid4, lnet_nid_t pref, int cpt)
{
struct lnet_peer_ni *lpni = NULL;
+ struct lnet_nid nid;
int rc;
if (the_lnet.ln_state != LNET_STATE_RUNNING)
return ERR_PTR(-ESHUTDOWN);
+ lnet_nid4_to_nid(nid4, &nid);
/*
* find if a peer_ni already exists.
* If so then just return that.
*/
- lpni = lnet_find_peer_ni_locked(nid);
+ lpni = lnet_find_peer_ni_locked(nid4);
if (lpni)
return lpni;
goto out_mutex_unlock;
}
- rc = lnet_peer_ni_traffic_add(nid, pref);
+ rc = lnet_peer_ni_traffic_add(&nid, pref);
if (rc) {
lpni = ERR_PTR(rc);
goto out_mutex_unlock;
}
- lpni = lnet_find_peer_ni_locked(nid);
+ lpni = lnet_find_peer_ni_locked(nid4);
LASSERT(lpni);
out_mutex_unlock:
/* re-add these routes */
lnet_add_route(route->lr_net,
route->lr_hops,
- route->lr_nid,
+ &route->lr_nid,
route->lr_priority,
sensitivity);
LIBCFS_FREE(route, sizeof(*route));
CDEBUG(D_NET, "deleting route %s->%s\n",
libcfs_net2str(route->lr_net),
- libcfs_nid2str(route->lr_nid));
+ libcfs_nidstr(&route->lr_nid));
/*
* use the gateway's lp_primary_nid to delete the route as the
CDEBUG(D_NET, "%s: %s->%s\n",
libcfs_nidstr(&src->lp_primary_nid),
libcfs_net2str(route->lr_net),
- libcfs_nid2str(route->lr_nid));
+ libcfs_nidstr(&route->lr_nid));
}
list_splice_init(&src->lp_rtrq, &target->lp_rtrq);
list_for_each_entry_safe(route, tmp, &src->lp_routes, lr_gwlist) {
* intent here is not to confuse the user who added the route.
*/
list_for_each_entry(route, &orig_lp->lp_routes, lr_gwlist) {
- lpni = lnet_peer_get_ni_locked(orig_lp, route->lr_nid);
+ lpni = lnet_peer_ni_get_locked(orig_lp, &route->lr_nid);
if (!lpni) {
lnet_net_lock(LNET_LOCK_EX);
list_move(&route->lr_gwlist, &new_lp->lp_routes);
}
int
-lnet_add_route(__u32 net, __u32 hops, lnet_nid_t gateway,
+lnet_add_route(__u32 net, __u32 hops, struct lnet_nid *gateway,
__u32 priority, __u32 sensitivity)
{
struct list_head *route_entry;
int rc;
CDEBUG(D_NET, "Add route: remote net %s hops %d priority %u gw %s\n",
- libcfs_net2str(net), hops, priority, libcfs_nid2str(gateway));
+ libcfs_net2str(net), hops, priority, libcfs_nidstr(gateway));
- if (gateway == LNET_NID_ANY ||
- gateway == LNET_NID_LO_0 ||
+ if (LNET_NID_IS_ANY(gateway) ||
+ nid_is_lo0(gateway) ||
net == LNET_NET_ANY ||
LNET_NETTYP(net) == LOLND ||
- LNET_NIDNET(gateway) == net ||
+ LNET_NID_NET(gateway) == net ||
(hops != LNET_UNDEFINED_HOPS && (hops < 1 || hops > 255)))
return -EINVAL;
if (lnet_islocalnet(net))
return -EEXIST;
- if (!lnet_islocalnet(LNET_NIDNET(gateway))) {
+ if (!lnet_islocalnet(LNET_NID_NET(gateway))) {
CERROR("Cannot add route with gateway %s. There is no local interface configured on LNet %s\n",
- libcfs_nid2str(gateway),
- libcfs_net2str(LNET_NIDNET(gateway)));
+ libcfs_nidstr(gateway),
+ libcfs_net2str(LNET_NID_NET(gateway)));
return -EHOSTUNREACH;
}
LIBCFS_ALLOC(rnet, sizeof(*rnet));
if (route == NULL || rnet == NULL) {
CERROR("Out of memory creating route %s %d %s\n",
- libcfs_net2str(net), hops, libcfs_nid2str(gateway));
+ libcfs_net2str(net), hops, libcfs_nidstr(gateway));
if (route != NULL)
LIBCFS_FREE(route, sizeof(*route));
if (rnet != NULL)
INIT_LIST_HEAD(&rnet->lrn_routes);
rnet->lrn_net = net;
/* store the local and remote net that the route represents */
- route->lr_lnet = LNET_NIDNET(gateway);
+ route->lr_lnet = LNET_NID_NET(gateway);
route->lr_net = net;
- route->lr_nid = gateway;
+ route->lr_nid = *gateway;
route->lr_priority = priority;
route->lr_hops = hops;
if (lnet_peers_start_down())
rc = PTR_ERR(lpni);
CERROR("Error %d creating route %s %d %s\n", rc,
libcfs_net2str(net), hops,
- libcfs_nid2str(gateway));
+ libcfs_nidstr(gateway));
return rc;
}
}
/* our lookups must be true */
- LASSERT(lnet_nid_to_nid4(&route2->lr_gateway->lp_primary_nid) !=
- gateway);
+ LASSERT(!nid_same(&route2->lr_gateway->lp_primary_nid,
+ gateway));
}
/*
}
int
-lnet_get_route(int idx, __u32 *net, __u32 *hops,
- lnet_nid_t *gateway, __u32 *flags, __u32 *priority, __u32 *sensitivity)
+lnet_get_route(int idx, __u32 *net, __u32 *hops, lnet_nid_t *gateway,
+ __u32 *flags, __u32 *priority, __u32 *sensitivity)
{
struct lnet_remotenet *rnet;
struct list_head *rn_list;
if (idx-- == 0) {
*net = rnet->lrn_net;
- *gateway = route->lr_nid;
+ *gateway = lnet_nid_to_nid4(&route->lr_nid);
*hops = route->lr_hops;
*priority = route->lr_priority;
*sensitivity = route->lr_gateway->
*/
if (lnet_is_discovery_disabled(lp)) {
list_for_each_entry(route, &lp->lp_routes, lr_gwlist) {
- if (route->lr_nid ==
- lnet_nid_to_nid4(&lpni->lpni_nid))
+ if (nid_same(&route->lr_nid, &lpni->lpni_nid))
lnet_set_route_aliveness(route, alive);
}
}
libcfs_net2str(net), hops,
priority,
alive ? "up" : "down",
- libcfs_nid2str(route->lr_nid));
+ libcfs_nidstr(&route->lr_nid));
LASSERT(tmpstr + tmpsiz - s > 0);
}