lnet_nid_t pnid = 0;
bool mr;
int i, rc;
+ int flags = lock_prim_nid ? LNET_PEER_LOCK_PRIMARY : 0;
if (!nids || num_nids < 1)
return -EINVAL;
if (!pnid) {
pnid = nids[i];
rc = lnet_add_peer_ni(pnid, LNET_NID_ANY, mr,
- LNET_PEER_LOCK_PRIMARY);
+ flags);
if (rc == -EALREADY) {
struct lnet_peer *lp;
}
} else if (lnet_peer_discovery_disabled) {
rc = lnet_add_peer_ni(nids[i], LNET_NID_ANY, mr,
- LNET_PEER_LOCK_PRIMARY);
+ flags);
} else {
rc = lnet_add_peer_ni(pnid, nids[i], mr,
- LNET_PEER_LOCK_PRIMARY);
+ flags);
}
if (rc && rc != -EEXIST)
* down then this discovery can introduce long delays into the mount
* process, so skip it if it isn't necessary.
*/
+again:
spin_lock(&lp->lp_lock);
- if (!lnet_peer_discovery_disabled &&
- (!(lp->lp_state & LNET_PEER_LOCK_PRIMARY) ||
- !lnet_peer_is_uptodate_locked(lp))) {
- /* force a full discovery cycle */
- lp->lp_state |= LNET_PEER_FORCE_PING | LNET_PEER_FORCE_PUSH |
- LNET_PEER_LOCK_PRIMARY;
+ if (!(lp->lp_state & LNET_PEER_LOCK_PRIMARY) && lock_prim_nid)
+ lp->lp_state |= LNET_PEER_LOCK_PRIMARY;
+
+ /* DD disabled, nothing to do */
+ if (lnet_peer_discovery_disabled) {
+ nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
spin_unlock(&lp->lp_lock);
+ goto out_decref;
+ }
- /* start discovery in the background. Messages to that
- * peer will not go through until the discovery is
- * complete
- */
- rc = lnet_discover_peer_locked(lpni, cpt, false);
- if (rc)
- goto out_decref;
- /* The lpni (or lp) for this NID may have changed and our ref is
- * the only thing keeping the old one around. Release the ref
- * and lookup the lpni again
- */
- lnet_peer_ni_decref_locked(lpni);
- lpni = lnet_find_peer_ni_locked(nid);
- if (!lpni) {
- rc = -ENOENT;
- goto out_unlock;
- }
- lp = lpni->lpni_peer_net->lpn_peer;
- } else {
+ /* Peer already up to date, nothing to do */
+ if (lnet_peer_is_uptodate_locked(lp)) {
+ nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
spin_unlock(&lp->lp_lock);
+ goto out_decref;
+ }
+ spin_unlock(&lp->lp_lock);
+
+ /* If primary nid locking is enabled, discovery is performed
+ * in the background.
+ * If primary nid locking is disabled, discovery blocks here.
+ * Messages to the peer will not go through until the discovery is
+ * complete.
+ */
+ if (lock_prim_nid)
+ rc = lnet_discover_peer_locked(lpni, cpt, false);
+ else
+ rc = lnet_discover_peer_locked(lpni, cpt, true);
+ if (rc)
+ goto out_decref;
+
+ /* The lpni (or lp) for this NID may have changed and our ref is
+ * the only thing keeping the old one around. Release the ref
+ * and lookup the lpni again
+ */
+ lnet_peer_ni_decref_locked(lpni);
+ lpni = lnet_find_peer_ni_locked(nid);
+ if (!lpni) {
+ rc = -ENOENT;
+ goto out_unlock;
}
- primary_nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
+ lp = lpni->lpni_peer_net->lpn_peer;
+
+ if (!lock_prim_nid && !lnet_is_discovery_disabled(lp))
+ goto again;
+ nid = lnet_nid_to_nid4(&lp->lp_primary_nid);
out_decref:
lnet_peer_ni_decref_locked(lpni);
out_unlock:
ptable->pt_peers++;
}
-
/* Update peer state */
spin_lock(&lp->lp_lock);
if (flags & LNET_PEER_CONFIGURED) {
rc = -EPERM;
goto out;
} else if (lp->lp_state & LNET_PEER_LOCK_PRIMARY) {
- if (nid_same(&lp->lp_primary_nid, &nid)) {
+ if (nid_same(&lp->lp_primary_nid, &nid))
rc = -EEXIST;
- goto out;
- }
/* we're trying to recreate an existing peer which
* has already been created and its primary
* locked. This is likely due to two servers
* to that node with the primary NID which was
* first added by Lustre
*/
- rc = -EALREADY;
+ else
+ rc = -EALREADY;
goto out;
+ } else if (!(flags &
+ (LNET_PEER_LOCK_PRIMARY | LNET_PEER_CONFIGURED))) {
+ /* if not recreating peer as configured and
+ * not locking primary nid, no need to
+ * do anything if primary nid is not being changed
+ */
+ if (nid_same(&lp->lp_primary_nid, &nid)) {
+ rc = -EEXIST;
+ goto out;
+ }
}
/* Delete and recreate the peer.
* We can get here:
lnet_peer_ni_decref_locked(lpni);
lp = lpni->lpni_peer_net->lpn_peer;
+ /* Peer must have been configured. */
+ if ((flags & LNET_PEER_CONFIGURED) &&
+ !(lp->lp_state & LNET_PEER_CONFIGURED)) {
+ CDEBUG(D_NET, "peer %s was not configured\n",
+ libcfs_nid2str(prim_nid));
+ return -ENOENT;
+ }
+
/* Primary NID must match */
if (lnet_nid_to_nid4(&lp->lp_primary_nid) != prim_nid) {
CDEBUG(D_NET, "prim_nid %s is not primary for peer %s\n",
return -EPERM;
}
- if ((flags & LNET_PEER_LOCK_PRIMARY) &&
- (lnet_peer_is_uptodate(lp) &&
- (lp->lp_state & LNET_PEER_LOCK_PRIMARY))) {
+ if (lnet_peer_is_uptodate(lp) && !(flags & LNET_PEER_CONFIGURED)) {
CDEBUG(D_NET,
"Don't add temporary peer NI for uptodate peer %s\n",
libcfs_nidstr(&lp->lp_primary_nid));