diff mbox series

[03/25] lustre: introduce class_parse_nid()

Message ID 20250130141115.950749-4-jsimmons@infradead.org (mailing list archive)
State New
Headers show
Series lustre: sync to OpenSFS branch April 30, 2023 | expand

Commit Message

James Simmons Jan. 30, 2025, 2:10 p.m. UTC
From: Mr NeilBrown <neilb@suse.de>

class_parse_nid() and class_parse_nid_quiet() can be used to parse
struct lnet_nid including nids with ipv6 addresses.

WC-bug-id: https://jira.whamcloud.com/browse/LU-10391
Lustre-commit: 163331cb81c9f7d7a ("LU-10391 lustre: introduce class_parse_nid()")
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Reviewed-on: https://review.whamcloud.com/c/fs/lustre-release/+/50089
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Frank Sehr <fsehr@whamcloud.com>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
 fs/lustre/include/obd_class.h   |  2 ++
 fs/lustre/obdclass/obd_config.c | 28 ++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+)
diff mbox series

Patch

diff --git a/fs/lustre/include/obd_class.h b/fs/lustre/include/obd_class.h
index eef9bfb91f4d..e91335e8cd70 100644
--- a/fs/lustre/include/obd_class.h
+++ b/fs/lustre/include/obd_class.h
@@ -146,6 +146,8 @@  struct cfg_interop_param *class_find_old_param(const char *param,
 int class_get_next_param(char **params, char *copy);
 int class_parse_nid4(char *buf, lnet_nid_t *nid4, char **endh);
 int class_parse_nid4_quiet(char *buf, lnet_nid_t *nid4, char **endh);
+int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh);
+int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh);
 int class_parse_net(char *buf, u32 *net, char **endh);
 int class_match_net(char *buf, char *key, u32 net);
 
diff --git a/fs/lustre/obdclass/obd_config.c b/fs/lustre/obdclass/obd_config.c
index eb14ca807f34..cc7810cae659 100644
--- a/fs/lustre/obdclass/obd_config.c
+++ b/fs/lustre/obdclass/obd_config.c
@@ -165,6 +165,18 @@  static int parse_nid4(char *buf, void *value, int quiet)
 	return -EINVAL;
 }
 
+static int parse_nid(char *buf, void *value, int quiet)
+{
+	struct lnet_nid *nid = value;
+
+	if (libcfs_strnid(nid, buf) == 0)
+		return 0;
+
+	if (!quiet)
+		LCONSOLE_ERROR_MSG(0x159, "Can't parse NID '%s'\n", buf);
+	return -EINVAL;
+}
+
 static int parse_net(char *buf, void *value)
 {
 	u32 *net = value;
@@ -176,6 +188,7 @@  static int parse_net(char *buf, void *value)
 
 enum {
 	CLASS_PARSE_NID4 = 1,
+	CLASS_PARSE_NID,
 	CLASS_PARSE_NET,
 };
 
@@ -211,6 +224,9 @@  static int class_parse_value(char *buf, int opc, void *value, char **endh,
 	case CLASS_PARSE_NID4:
 		rc = parse_nid4(buf, value, quiet);
 		break;
+	case CLASS_PARSE_NID:
+		rc = parse_nid(buf, value, quiet);
+		break;
 	case CLASS_PARSE_NET:
 		rc = parse_net(buf, value);
 		break;
@@ -235,6 +251,18 @@  int class_parse_nid4_quiet(char *buf, lnet_nid_t *nid4, char **endh)
 }
 EXPORT_SYMBOL(class_parse_nid4_quiet);
 
+int class_parse_nid(char *buf, struct lnet_nid *nid, char **endh)
+{
+	return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 0);
+}
+EXPORT_SYMBOL(class_parse_nid);
+
+int class_parse_nid_quiet(char *buf, struct lnet_nid *nid, char **endh)
+{
+	return class_parse_value(buf, CLASS_PARSE_NID, (void *)nid, endh, 1);
+}
+EXPORT_SYMBOL(class_parse_nid_quiet);
+
 char *lustre_cfg_string(struct lustre_cfg *lcfg, u32 index)
 {
 	char *s;