From 6c3b50434b321cc16c9d08bdf22be1ffbdaf9264 Mon Sep 17 00:00:00 2001 From: Mr NeilBrown Date: Wed, 12 Apr 2023 09:27:16 -0400 Subject: [PATCH] LU-13340 mgs: convert class_parse_nid4 to class_parse_nid All callers of class_parse_nid4() now use class_parse_nid() and so much handle a large nid. do_lcfg_nid() is introduced to help with this. Signed-off-by: Mr NeilBrown Change-Id: I502fa16871d689a8248e4243679918d58464efcd Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50094 Tested-by: jenkins Tested-by: Maloo Reviewed-by: James Simmons Reviewed-by: Alex Zhuravlev Reviewed-by: Oleg Drokin --- lustre/mgs/mgs_handler.c | 11 +++++---- lustre/mgs/mgs_llog.c | 54 +++++++++++++++++++-------------------------- lustre/obdclass/obd_mount.c | 48 ++++++++++++++++++++++++---------------- 3 files changed, 59 insertions(+), 54 deletions(-) diff --git a/lustre/mgs/mgs_handler.c b/lustre/mgs/mgs_handler.c index 20201ca..0d8b4ec 100644 --- a/lustre/mgs/mgs_handler.c +++ b/lustre/mgs/mgs_handler.c @@ -307,17 +307,20 @@ static int mgs_check_target(const struct lu_env *env, /* Ensure this is not a failover node that is connecting first*/ static int mgs_check_failover_reg(struct mgs_target_info *mti) { - lnet_nid_t nid; + struct lnet_nid nid; char *ptr; int i; ptr = mti->mti_params; while (class_find_param(ptr, PARAM_FAILNODE, &ptr) == 0) { - while (class_parse_nid4_quiet(ptr, &nid, &ptr) == 0) { + while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) { for (i = 0; i < mti->mti_nid_count; i++) { - if (nid == mti->mti_nids[i]) { + struct lnet_nid nid2; + + lnet_nid4_to_nid(mti->mti_nids[i], &nid2); + if (nid_same(&nid, &nid2)) { LCONSOLE_WARN("Denying initial registration attempt from nid %s, specified as failover\n", - libcfs_nid2str(nid)); + libcfs_nidstr(&nid)); return -EADDRNOTAVAIL; } } diff --git a/lustre/mgs/mgs_llog.c b/lustre/mgs/mgs_llog.c index 8a24473..de8dfc5 100644 --- a/lustre/mgs/mgs_llog.c +++ b/lustre/mgs/mgs_llog.c @@ -1130,7 +1130,7 @@ static int process_command(const struct lu_env *env, struct lustre_cfg *lcfg, struct mgs_replace_data *mrd) { int nids_added = 0; - lnet_nid_t nid; + struct lnet_nid nid; char *ptr; int rc = 0; @@ -1139,32 +1139,29 @@ static int process_command(const struct lu_env *env, struct lustre_cfg *lcfg, /* LCFG_ADD_UUID command found. Let's skip original command and add passed nids */ ptr = mrd->target.mti_params; - while (class_parse_nid4(ptr, &nid, &ptr) == 0) { - struct lnet_nid lnid; - + while (class_parse_nid(ptr, &nid, &ptr) == 0) { if (!mrd->nodeuuid) { rc = name_create(&mrd->nodeuuid, - libcfs_nid2str(nid), ""); + libcfs_nidstr(&nid), ""); if (rc) { CERROR("Can't create uuid for " "nid %s, device %s\n", - libcfs_nid2str(nid), + libcfs_nidstr(&nid), mrd->target.mti_svname); return rc; } } - CDEBUG(D_MGS, "add nid %s with uuid %s, " - "device %s\n", libcfs_nid2str(nid), - mrd->target.mti_params, - mrd->nodeuuid); - lnet_nid4_to_nid(nid, &lnid); + CDEBUG(D_MGS, "add nid %s with uuid %s, device %s\n", + libcfs_nidstr(&nid), + mrd->target.mti_params, + mrd->nodeuuid); rc = record_add_uuid(env, - mrd->temp_llh, &lnid, + mrd->temp_llh, &nid, mrd->nodeuuid); if (rc) CWARN("%s: Can't add nid %s for uuid %s :rc=%d\n", mrd->target.mti_svname, - libcfs_nid2str(nid), + libcfs_nidstr(&nid), mrd->nodeuuid, rc); else nids_added++; @@ -1176,8 +1173,8 @@ static int process_command(const struct lu_env *env, struct lustre_cfg *lcfg, } if (nids_added == 0) { - CERROR("No new nids were added, nid %s with uuid %s, " - "device %s\n", libcfs_nid2str(nid), + CERROR("No new nids were added, nid %s with uuid %s, device %s\n", + libcfs_nidstr(&nid), mrd->nodeuuid ? mrd->nodeuuid : "NULL", mrd->target.mti_svname); name_destroy(&mrd->nodeuuid); @@ -1209,26 +1206,23 @@ static int process_command(const struct lu_env *env, struct lustre_cfg *lcfg, if (mrd->failover) { ptr = mrd->failover; - while (class_parse_nid4(ptr, &nid, &ptr) == 0) { - struct lnet_nid lnid; - + while (class_parse_nid(ptr, &nid, &ptr) == 0) { if (mrd->nodeuuid == NULL) { rc = name_create(&mrd->nodeuuid, - libcfs_nid2str(nid), + libcfs_nidstr(&nid), ""); if (rc) return rc; } CDEBUG(D_MGS, "add nid %s for failover %s\n", - libcfs_nid2str(nid), mrd->nodeuuid); - lnet_nid4_to_nid(nid, &lnid); - rc = record_add_uuid(env, mrd->temp_llh, &lnid, + libcfs_nidstr(&nid), mrd->nodeuuid); + rc = record_add_uuid(env, mrd->temp_llh, &nid, mrd->nodeuuid); if (rc) { CWARN("%s: Can't add nid %s for failover %s :rc = %d\n", mrd->target.mti_svname, - libcfs_nid2str(nid), + libcfs_nidstr(&nid), mrd->nodeuuid, rc); name_destroy(&mrd->nodeuuid); return rc; @@ -2497,7 +2491,7 @@ static int mgs_write_log_failnids(const struct lu_env *env, { char *failnodeuuid = NULL; char *ptr = mti->mti_params; - lnet_nid_t nid; + struct lnet_nid nid; int rc = 0; /* @@ -2511,29 +2505,27 @@ static int mgs_write_log_failnids(const struct lu_env *env, /* * Pull failnid info out of params string, which may contain something - * like ",:,". class_parse_nid4() does not + * like ",:,". class_parse_nid() does not * complain about abnormal inputs like ",:", ":,", * etc. However, convert_hostnames() should have caught those. */ while (class_find_param(ptr, PARAM_FAILNODE, &ptr) == 0) { - while (class_parse_nid4(ptr, &nid, &ptr) == 0) { + while (class_parse_nid(ptr, &nid, &ptr) == 0) { char nidstr[LNET_NIDSTR_SIZE]; - struct lnet_nid lnid; if (failnodeuuid == NULL) { /* We don't know the failover node name, * so just use the first nid as the uuid */ - libcfs_nid2str_r(nid, nidstr, sizeof(nidstr)); + libcfs_nidstr_r(&nid, nidstr, sizeof(nidstr)); rc = name_create(&failnodeuuid, nidstr, ""); if (rc != 0) return rc; } CDEBUG(D_MGS, "add nid %s for failover uuid %s, client %s\n", - libcfs_nid2str_r(nid, nidstr, sizeof(nidstr)), + libcfs_nidstr_r(&nid, nidstr, sizeof(nidstr)), failnodeuuid, cliname); - lnet_nid4_to_nid(nid, &lnid); - rc = record_add_uuid(env, llh, &lnid, failnodeuuid); + rc = record_add_uuid(env, llh, &nid, failnodeuuid); /* * If *ptr is ':', we have added all NIDs for * failnodeuuid. diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index 04ddbc5..3fc205d 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -180,6 +180,15 @@ static int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd, return rc; } +static int do_lcfg_nid(char *cfgname, struct lnet_nid *nid, int cmd, + char *s1) +{ + if (nid_is_nid4(nid)) + return do_lcfg(cfgname, lnet_nid_to_nid4(nid), cmd, s1, + NULL, NULL, NULL); + return -EINVAL; +} + /** * Call class_attach and class_setup. These methods in turn call * OBD type-specific methods. @@ -222,7 +231,7 @@ int lustre_start_mgc(struct super_block *sb) struct obd_export *exp; struct obd_uuid *uuid = NULL; uuid_t uuidc; - lnet_nid_t nid; + struct lnet_nid nid; char nidstr[LNET_NIDSTR_SIZE]; char *mgcname = NULL, *niduuid = NULL, *mgssec = NULL; char *ptr; @@ -238,7 +247,7 @@ int lustre_start_mgc(struct super_block *sb) /* mount -o mgsnode=nid */ ptr = lsi->lsi_lmd->lmd_mgs; if (lsi->lsi_lmd->lmd_mgs && - (class_parse_nid4(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) { + (class_parse_nid(lsi->lsi_lmd->lmd_mgs, &nid, &ptr) == 0)) { i++; } else if (IS_MGS(lsi)) { struct lnet_processid id; @@ -246,7 +255,7 @@ int lustre_start_mgc(struct super_block *sb) while ((rc = LNetGetId(i++, &id)) != -ENOENT) { if (nid_is_lo0(&id.nid)) continue; - nid = lnet_nid_to_nid4(&id.nid); + nid = id.nid; i++; break; } @@ -254,7 +263,7 @@ int lustre_start_mgc(struct super_block *sb) } else { /* client */ /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */ ptr = lsi->lsi_lmd->lmd_dev; - if (class_parse_nid4(ptr, &nid, &ptr) == 0) + if (class_parse_nid(ptr, &nid, &ptr) == 0) i++; } if (i == 0) { @@ -264,7 +273,7 @@ int lustre_start_mgc(struct super_block *sb) mutex_lock(&mgc_start_lock); - libcfs_nid2str_r(nid, nidstr, sizeof(nidstr)); + libcfs_nidstr_r(&nid, nidstr, sizeof(nidstr)); len = strlen(LUSTRE_MGC_OBDNAME) + strlen(nidstr) + 1; OBD_ALLOC(mgcname, len); OBD_ALLOC(niduuid, len + 2); @@ -352,9 +361,9 @@ int lustre_start_mgc(struct super_block *sb) struct lnet_processid id; while ((rc = LNetGetId(i++, &id)) != -ENOENT) { - rc = do_lcfg(mgcname, lnet_nid_to_nid4(&id.nid), - LCFG_ADD_UUID, - niduuid, NULL, NULL, NULL); + rc = do_lcfg_nid(mgcname, &id.nid, + LCFG_ADD_UUID, + niduuid); } } else { /* Use mgsnode= nids */ @@ -371,9 +380,10 @@ int lustre_start_mgc(struct super_block *sb) * Multiple NIDs on one MGS node are separated * by commas. */ - while (class_parse_nid4(ptr, &nid, &ptr) == 0) { - rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID, - niduuid, NULL, NULL, NULL); + while (class_parse_nid(ptr, &nid, &ptr) == 0) { + rc = do_lcfg_nid(mgcname, &nid, + LCFG_ADD_UUID, + niduuid); if (rc == 0) ++i; /* Stop at the first failover NID */ @@ -384,9 +394,9 @@ int lustre_start_mgc(struct super_block *sb) } else { /* client */ /* Use NIDs from mount line: uml1,1@elan:uml2,2@elan:/lustre */ ptr = lsi->lsi_lmd->lmd_dev; - while (class_parse_nid4(ptr, &nid, &ptr) == 0) { - rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID, - niduuid, NULL, NULL, NULL); + while (class_parse_nid(ptr, &nid, &ptr) == 0) { + rc = do_lcfg_nid(mgcname, &nid, LCFG_ADD_UUID, + niduuid); if (rc == 0) ++i; /* Stop at the first failover NID */ @@ -422,9 +432,9 @@ int lustre_start_mgc(struct super_block *sb) /* New failover node */ sprintf(niduuid, "%s_%x", mgcname, i); j = 0; - while (class_parse_nid4_quiet(ptr, &nid, &ptr) == 0) { - rc = do_lcfg(mgcname, nid, LCFG_ADD_UUID, - niduuid, NULL, NULL, NULL); + while (class_parse_nid_quiet(ptr, &nid, &ptr) == 0) { + rc = do_lcfg_nid(mgcname, &nid, LCFG_ADD_UUID, + niduuid); if (rc == 0) ++j; if (*ptr == ':') @@ -1149,14 +1159,14 @@ static int lmd_parse_string(char **handle, char *ptr) /* Collect multiple values for mgsnid specifiers */ static int lmd_parse_mgs(struct lustre_mount_data *lmd, char **ptr) { - lnet_nid_t nid; + struct lnet_nid nid; char *tail = *ptr; char *mgsnid; int length; int oldlen = 0; /* Find end of NID-list */ - while (class_parse_nid4_quiet(tail, &nid, &tail) == 0) + while (class_parse_nid_quiet(tail, &nid, &tail) == 0) ; /* do nothing */ length = tail - *ptr; -- 1.8.3.1