}
/* Called with ln_api_mutex */
-static int lnet_parse_peer_nis(struct nlattr *rlist, struct lnet_nid *pnid,
- bool mr, struct genl_info *info)
+static int lnet_parse_peer_nis(struct nlattr *rlist, struct genl_info *info,
+ struct lnet_nid *pnid, bool mr,
+ bool *create_some)
{
struct lnet_nid snid = LNET_ANY_NID;
struct nlattr *props;
- bool all = false;
int rem, rc = 0;
s64 num = -1;
GOTO(report_err, rc);
}
- if (LNET_NID_IS_ANY(&snid))
- all = true;
+ if (LNET_NID_IS_ANY(&snid) || nid_same(&snid, pnid))
+ *create_some = false;
} else if (nla_strcmp(props, "health stats") == 0) {
struct nlattr *health;
int rem2;
}
if (info->nlhdr->nlmsg_flags & NLM_F_REPLACE && num != -1) {
- lnet_peer_ni_set_healthv(pnid, num, all);
+ lnet_peer_ni_set_healthv(pnid, num, !*create_some);
} else if (info->nlhdr->nlmsg_flags & NLM_F_CREATE) {
bool lock_prim = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
if (rc < 0)
GENL_SET_ERR_MSG(info,
"failed to add peer");
- } else if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE)) {
+ } else if (!(info->nlhdr->nlmsg_flags & NLM_F_CREATE) && *create_some) {
bool force = info->nlhdr->nlmsg_flags & NLM_F_EXCL;
rc = lnet_del_peer_ni(pnid, &snid, force);
struct genlmsghdr *gnlh = nlmsg_data(nlh);
struct nlattr *params = genlmsg_data(gnlh);
int msg_len, rem, rc = 0;
+ struct lnet_nid pnid;
struct nlattr *attr;
mutex_lock(&the_lnet.ln_api_mutex);
}
nla_for_each_nested(attr, params, rem) {
- struct lnet_nid pnid = LNET_ANY_NID;
bool parse_peer_nis = false;
struct nlattr *pnid_prop;
int rem2;
if (nla_type(attr) != LN_SCALAR_ATTR_LIST)
continue;
+ pnid = LNET_ANY_NID;
nla_for_each_nested(pnid_prop, attr, rem2) {
bool mr = true;
GOTO(report_err, rc = -EINVAL);
}
+ parse_peer_nis = true;
nla_for_each_nested(rlist, pnid_prop, rem3) {
- rc = lnet_parse_peer_nis(rlist, &pnid,
- mr, info);
+ rc = lnet_parse_peer_nis(rlist, info,
+ &pnid, mr,
+ &parse_peer_nis);
if (rc < 0)
GOTO(report_err, rc);
}
- parse_peer_nis = true;
}
}
force);
if (rc < 0) {
GENL_SET_ERR_MSG(info,
- "failed to del peer");
+ "failed to del primary peer");
GOTO(report_err, rc);
}
}
}
report_err:
+ /* If we failed on creation and encounter a latter error then
+ * delete the primary nid.
+ */
+ if (rc < 0 && info->nlhdr->nlmsg_flags & NLM_F_CREATE &&
+ !LNET_NID_IS_ANY(&pnid))
+ lnet_del_peer_ni(&pnid, &LNET_ANY_NID,
+ info->nlhdr->nlmsg_flags & NLM_F_EXCL);
mutex_unlock(&the_lnet.ln_api_mutex);
return rc;
--nid [8-12]@gni,7.7.7.[1-4]@tcp,7.7.7.[5-9]@o2ib,[1-5]@kfi ||
error "Peer add failed $?"
compare_peer_del "7@gni"
+
+ echo "Delete peer that contains nid equal to primary nid"
+ do_lnetctl peer add --prim 1.1.1.1@tcp \
+ --nid 1.1.1.1@tcp,2.2.2.2@tcp,3.3.3.3@tcp,4.4.4.4@tcp ||
+ error "Peer add failed $?"
+ compare_peer_del "1.1.1.1@tcp" "1.1.1.1@tcp,2.2.2.2@tcp,3.3.3.3@tcp,4.4.4.4@tcp"
}
run_test 7 "Various peer delete tests"