From 3f9acf5544cd6bb46012d9d517183d3af7378a32 Mon Sep 17 00:00:00 2001 From: Liang Zhen Date: Sat, 12 Jun 2010 11:48:13 -0700 Subject: [PATCH] b=22078 Bind ost/mdt to specific nids The goal of the patch attached to this bug is to make NUMIOA factor management easier, by giving the ability to restrict the NIDs that a target (mdt or ost) registers on the MGS. i=nathan i=sebastien --- lustre/doc/mkfs.lustre.8 | 3 ++ lustre/doc/tunefs.lustre.8 | 3 ++ lustre/include/lustre_param.h | 3 ++ lustre/obdclass/obd_config.c | 77 ++++++++++++++++++++++++++++++++++++++----- lustre/obdclass/obd_mount.c | 10 +++++- lustre/utils/mkfs_lustre.c | 18 ++++++++++ 6 files changed, 104 insertions(+), 10 deletions(-) diff --git a/lustre/doc/mkfs.lustre.8 b/lustre/doc/mkfs.lustre.8 index 32a4098..ea32c54 100644 --- a/lustre/doc/mkfs.lustre.8 +++ b/lustre/doc/mkfs.lustre.8 @@ -68,6 +68,9 @@ OST: \fIerrors=remount-ro,mballoc,extents\fR; MGS/MDT: \fIerrors=remount-ro,iopen_nopriv,user_xattr\fR. \fBDO NOT\fR alter the default mount options unless you know what you are doing. .TP +.BI \--network= net,... +Network(s) to restrict this ost/mdt to. This option can be repeated as desired. +.TP .BI \--mgsnode= nid,... Set the NID(s) of the MGS node, required for all targets other than the MGS. .TP diff --git a/lustre/doc/tunefs.lustre.8 b/lustre/doc/tunefs.lustre.8 index ec4db1a..16b40a8 100644 --- a/lustre/doc/tunefs.lustre.8 +++ b/lustre/doc/tunefs.lustre.8 @@ -52,6 +52,9 @@ OST: \fIerrors=remount-ro,mballoc,extents\fR; MGS/MDT: \fIerrors=remount-ro,iopen_nopriv,user_xattr\fR. \fBDO NOT\fR alter the default mount options unless you know what you are doing. .TP +.BI \--network= net,... +Network(s) to restrict this ost/mdt to. This option can be repeated as desired. +.TP .BI \--mgs Add a configuration management service to this target .TP diff --git a/lustre/include/lustre_param.h b/lustre/include/lustre_param.h index 883eae3..cfc510c 100644 --- a/lustre/include/lustre_param.h +++ b/lustre/include/lustre_param.h @@ -53,6 +53,8 @@ int class_find_param(char *buf, char *key, char **valp); int class_get_next_param(char **params, char *copy); int class_match_param(char *buf, char *key, char **valp); int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh); +int class_parse_net(char *buf, __u32 *net, char **endh); +int class_match_net(char *buf, lnet_nid_t nid); /* obd_mount.c */ int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd, char *s1, char *s2, char *s3, char *s4); @@ -83,6 +85,7 @@ int do_lcfg(char *cfgname, lnet_nid_t nid, int cmd, #define PARAM_FAILNODE "failover.node=" /* add failover nid */ #define PARAM_FAILMODE "failover.mode=" /* initial mount only */ #define PARAM_ACTIVE "active=" /* activate/deactivate */ +#define PARAM_NETWORK "network=" /* bind on nid */ /* Prefixes for parameters handled by obd's proc methods (XXX_process_config) */ #define PARAM_OST "ost." diff --git a/lustre/obdclass/obd_config.c b/lustre/obdclass/obd_config.c index 1fdfb12..96c853a 100644 --- a/lustre/obdclass/obd_config.c +++ b/lustre/obdclass/obd_config.c @@ -157,13 +157,41 @@ int class_match_param(char *buf, char *key, char **valp) return 0; } +static int parse_nid(char *buf, void *value) +{ + lnet_nid_t *nid = (lnet_nid_t *)value; + + *nid = libcfs_str2nid(buf); + if (*nid != LNET_NID_ANY) + return 0; + + LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf); + return -EINVAL; +} + +static int parse_net(char *buf, void *value) +{ + __u32 *net = (__u32 *)net; + + *net = libcfs_str2net(buf); + CDEBUG(D_INFO, "Net %s\n", libcfs_net2str(*net)); + return 0; +} + +enum { + CLASS_PARSE_NID = 1, + CLASS_PARSE_NET, +}; + /* 0 is good nid, 1 not found < 0 error endh is set to next separator */ -int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh) +static int class_parse_value(char *buf, int opc, void *value, char **endh) { - char tmp, *endp; + char *endp; + char tmp; + int rc = 0; if (!buf) return 1; @@ -179,17 +207,46 @@ int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh) tmp = *endp; *endp = '\0'; - *nid = libcfs_str2nid(buf); - if (*nid == LNET_NID_ANY) { - LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf); - *endp = tmp; - return -EINVAL; + switch (opc) { + default: + LBUG(); + case CLASS_PARSE_NID: + rc = parse_nid(buf, value); + break; + case CLASS_PARSE_NET: + rc = parse_net(buf, value); + break; } *endp = tmp; - + if (rc != 0) + return rc; if (endh) *endh = endp; - CDEBUG(D_INFO, "Nid %s\n", libcfs_nid2str(*nid)); + return 0; +} + +int class_parse_nid(char *buf, lnet_nid_t *nid, char **endh) +{ + return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh); +} + +int class_parse_net(char *buf, __u32 *net, char **endh) +{ + return class_parse_value(buf, CLASS_PARSE_NET, (void *)net, endh); +} + +int class_match_net(char *buf, lnet_nid_t nid) +{ + __u32 net; + + while (class_find_param(buf, PARAM_NETWORK, &buf) == 0) { + /* please restrict to the nids pertaining to + * the specified networks */ + while (class_parse_net(buf, &net, &buf) == 0) { + if (LNET_NIDNET(nid) == net) + return 1; + } + } return 0; } @@ -197,6 +254,8 @@ EXPORT_SYMBOL(class_find_param); EXPORT_SYMBOL(class_get_next_param); EXPORT_SYMBOL(class_match_param); EXPORT_SYMBOL(class_parse_nid); +EXPORT_SYMBOL(class_parse_net); +EXPORT_SYMBOL(class_match_net); /********************** class fns **********************/ diff --git a/lustre/obdclass/obd_mount.c b/lustre/obdclass/obd_mount.c index c48f8b4..8531464 100644 --- a/lustre/obdclass/obd_mount.c +++ b/lustre/obdclass/obd_mount.c @@ -964,7 +964,7 @@ static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti) struct lustre_sb_info *lsi = s2lsi(sb); struct lustre_disk_data *ldd = lsi->lsi_ldd; lnet_process_id_t id; - int i = 0; + int i = 0; ENTRY; if (!(lsi->lsi_flags & LSI_SERVER)) @@ -979,6 +979,14 @@ static int server_sb2mti(struct super_block *sb, struct mgs_target_info *mti) while (LNetGetId(i++, &id) != -ENOENT) { if (LNET_NETTYP(LNET_NIDNET(id.nid)) == LOLND) continue; + + if (class_find_param(ldd->ldd_params, + PARAM_NETWORK, NULL) == 0 && + !class_match_net(ldd->ldd_params, id.nid)) { + /* can't match specified network */ + continue; + } + mti->mti_nids[mti->mti_nid_count] = id.nid; mti->mti_nid_count++; if (mti->mti_nid_count >= MTI_NIDS_MAX) { diff --git a/lustre/utils/mkfs_lustre.c b/lustre/utils/mkfs_lustre.c index c4fc9ff..f3e0b55 100644 --- a/lustre/utils/mkfs_lustre.c +++ b/lustre/utils/mkfs_lustre.c @@ -130,6 +130,7 @@ void usage(FILE *out) */ "\t\t--comment=: arbitrary user string (%d bytes)\n" "\t\t--mountfsoptions= : permanent mount options\n" + "\t\t--network=[,<...>] : network(s) to restrict this ost/mdt to\n" #ifndef TUNEFS "\t\t--backfstype= : backing fs type (ext3, ldiskfs)\n" "\t\t--device-size=#N(KB) : device size for loop devices\n" @@ -1224,6 +1225,7 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop, {"verbose", 0, 0, 'v'}, {"writeconf", 0, 0, 'w'}, {"upgrade_to_18", 0, 0, 'U'}, + {"network", 1, 0, 't'}, {0, 0, 0, 0} }; char *optstring = "b:c:C:d:ef:Ghi:k:L:m:MnNo:Op:Pqru:vw"; @@ -1379,6 +1381,22 @@ int parse_opts(int argc, char *const argv[], struct mkfs_opts *mop, case 'r': mop->mo_flags |= MO_FORCEFORMAT; break; + case 't': + if (!IS_MDT(&mop->mo_ldd) && !IS_OST(&mop->mo_ldd)) { + badopt(long_opt[longidx].name, "MDT,OST"); + return 1; + } + + if (!optarg) + return 1; + + rc = add_param(mop->mo_ldd.ldd_params, + PARAM_NETWORK, optarg); + if (rc != 0) + return rc; + /* Must update the mgs logs */ + mop->mo_ldd.ldd_flags |= LDD_F_UPDATE; + break; case 'u': strscpy(mop->mo_ldd.ldd_userdata, optarg, sizeof(mop->mo_ldd.ldd_userdata)); -- 1.8.3.1