Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1253428 > unrolled thread
| Started by | James Simmons <jsimmons@infradead.org> |
|---|---|
| First post | 2015-10-22 04:10 +0200 |
| Last post | 2015-10-22 04:10 +0200 |
| Articles | 3 — 1 participant |
Back to article view | Back to linux.kernel
[PATCH 00/11] staging: lustre: update NID string handling James Simmons <jsimmons@infradead.org> - 2015-10-22 04:10 +0200
[PATCH 02/11] staging: lustre: move nidstring handling to LNet layer James Simmons <jsimmons@infradead.org> - 2015-10-22 04:10 +0200
[PATCH 01/11] staging: lustre: add a service that prints a nidlist James Simmons <jsimmons@infradead.org> - 2015-10-22 04:10 +0200
| From | James Simmons <jsimmons@infradead.org> |
|---|---|
| Date | 2015-10-22 04:10 +0200 |
| Subject | [PATCH 00/11] staging: lustre: update NID string handling |
| Message-ID | <qmduh-4Se-3@gated-at.bofh.it> |
Much of the LNet network setup is managed with modprobe configuration files. Those configurations are parse with the code in nidstring.c which currently located in the libcfs layer. This patch series moves nidstring.c to the LNet layer where it belongs and we update the source with all the changes that have occured on the OpenSFS lustre development branch. Gregoire Pichon (1): staging: lustre: add a service that prints a nidlist Joshua Walgenbach (1): staging: lustre: add in NID range management for libcfs Dmitry Eremin (1): staging: lustre: provide separate buffers for libcfs_*2str() Frederic Saunier (1): staging: lustre: remove last entry of libcfs_netstrfns[] James Simmons (7): staging: lustre: move nidstring handling to LNet layer staging: lustre: remove libcfs_init_string function staging: lustre: remove cfs_ip_addr_free wrapper staging: lustre: move struct netstrfns to nidstr.h staging: lustre: move cfs_ip_addr_* function from kernel libcfs to LNet staging: lustre: Avoid nid range related forward declarations in nidstring.c staging: lustre: add in NID range management for libcfs staging: lustre: Use C99 initializers for struct netstrfns .../staging/lustre/include/linux/libcfs/libcfs.h | 2 - .../lustre/include/linux/libcfs/libcfs_string.h | 5 +- drivers/staging/lustre/include/linux/lnet/nidstr.h | 47 +- drivers/staging/lustre/lnet/lnet/Makefile | 2 +- drivers/staging/lustre/lnet/lnet/api-ni.c | 6 +- drivers/staging/lustre/lnet/lnet/config.c | 2 +- drivers/staging/lustre/lnet/lnet/nidstrings.c | 1260 ++++++++++++++++++++ drivers/staging/lustre/lnet/lnet/router.c | 2 +- drivers/staging/lustre/lustre/libcfs/Makefile | 2 +- .../staging/lustre/lustre/libcfs/libcfs_string.c | 144 ++-- drivers/staging/lustre/lustre/libcfs/module.c | 2 - drivers/staging/lustre/lustre/libcfs/nidstrings.c | 842 ------------- .../lustre/lustre/obdclass/lprocfs_status.c | 11 +- .../staging/lustre/lustre/obdclass/obd_config.c | 9 +- drivers/staging/lustre/lustre/obdclass/obd_mount.c | 7 +- drivers/staging/lustre/lustre/osc/osc_request.c | 8 +- .../staging/lustre/lustre/ptlrpc/lproc_ptlrpc.c | 5 +- 17 files changed, 1408 insertions(+), 948 deletions(-) create mode 100644 drivers/staging/lustre/lnet/lnet/nidstrings.c delete mode 100644 drivers/staging/lustre/lustre/libcfs/nidstrings.c -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[toc] | [next] | [standalone]
| From | James Simmons <jsimmons@infradead.org> |
|---|---|
| Date | 2015-10-22 04:10 +0200 |
| Subject | [PATCH 02/11] staging: lustre: move nidstring handling to LNet layer |
| Message-ID | <qmduj-4Se-29@gated-at.bofh.it> |
| In reply to | #1253428 |
Moved the source file nidstring.c from libcfs to lnet
since that is the only place it is used. With the
move of nidstring to lnet some functions in libcfs
need to be exported. In later patches those functions
that are only used by LNet also will be moved to the
LNet layer. Also add in missing MAX_NUMERIC_VALUE
defination.
Signed-off-by: James Simmons <jsimmons@infradead.org>
---
drivers/staging/lustre/lnet/lnet/Makefile | 2 +-
.../{lustre/libcfs => lnet/lnet}/nidstrings.c | 13 +++++++++----
drivers/staging/lustre/lustre/libcfs/Makefile | 2 +-
.../staging/lustre/lustre/libcfs/libcfs_string.c | 4 ++++
4 files changed, 15 insertions(+), 6 deletions(-)
rename drivers/staging/lustre/{lustre/libcfs => lnet/lnet}/nidstrings.c (99%)
diff --git a/drivers/staging/lustre/lnet/lnet/Makefile b/drivers/staging/lustre/lnet/lnet/Makefile
index 52492fb..e276fe2 100644
--- a/drivers/staging/lustre/lnet/lnet/Makefile
+++ b/drivers/staging/lustre/lnet/lnet/Makefile
@@ -1,6 +1,6 @@
obj-$(CONFIG_LNET) += lnet.o
-lnet-y := api-ni.o config.o \
+lnet-y := api-ni.o config.o nidstrings.o \
lib-me.o lib-msg.o lib-eq.o lib-md.o lib-ptl.o \
lib-socket.o lib-move.o module.o lo.o \
router.o router_proc.o acceptor.o peer.o
diff --git a/drivers/staging/lustre/lustre/libcfs/nidstrings.c b/drivers/staging/lustre/lnet/lnet/nidstrings.c
similarity index 99%
rename from drivers/staging/lustre/lustre/libcfs/nidstrings.c
rename to drivers/staging/lustre/lnet/lnet/nidstrings.c
index a54594a..81ec3a8 100644
--- a/drivers/staging/lustre/lustre/libcfs/nidstrings.c
+++ b/drivers/staging/lustre/lnet/lnet/nidstrings.c
@@ -33,7 +33,7 @@
* This file is part of Lustre, http://www.lustre.org/
* Lustre is a trademark of Sun Microsystems, Inc.
*
- * libcfs/libcfs/nidstrings.c
+ * lnet/lnet/nidstrings.c
*
* Author: Phil Schwan <phil@clusterfs.com>
*/
@@ -43,6 +43,9 @@
#include "../../include/linux/libcfs/libcfs.h"
#include "../../include/linux/lnet/lnet.h"
+/* max value for numeric network address */
+#define MAX_NUMERIC_VALUE 0xffffffff
+
/* CAVEAT VENDITOR! Keep the canonical string representation of nets/nids
* consistent in all conversion functions. Some code fragments are copied
* around for the sake of clarity...
@@ -64,12 +67,13 @@ void libcfs_init_nidstrings(void)
{
spin_lock_init(&libcfs_nidstring_lock);
}
+EXPORT_SYMBOL(libcfs_init_nidstrings);
-static char *
+char *
libcfs_next_nidstring(void)
{
- char *str;
- unsigned long flags;
+ char *str;
+ unsigned long flags;
spin_lock_irqsave(&libcfs_nidstring_lock, flags);
@@ -80,6 +84,7 @@ libcfs_next_nidstring(void)
spin_unlock_irqrestore(&libcfs_nidstring_lock, flags);
return str;
}
+EXPORT_SYMBOL(libcfs_next_nidstring);
static int libcfs_lo_str2addr(const char *str, int nob, __u32 *addr)
{
diff --git a/drivers/staging/lustre/lustre/libcfs/Makefile b/drivers/staging/lustre/lustre/libcfs/Makefile
index ec98f44..03d3f3d 100644
--- a/drivers/staging/lustre/lustre/libcfs/Makefile
+++ b/drivers/staging/lustre/lustre/libcfs/Makefile
@@ -10,7 +10,7 @@ libcfs-linux-objs += linux-mem.o
libcfs-linux-objs := $(addprefix linux/,$(libcfs-linux-objs))
-libcfs-all-objs := debug.o fail.o nidstrings.o module.o tracefile.o \
+libcfs-all-objs := debug.o fail.o module.o tracefile.o \
libcfs_string.o hash.o kernel_user_comm.o \
prng.o workitem.o libcfs_cpu.o \
libcfs_mem.o libcfs_lock.o
diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
index bbfef98..896185f 100644
--- a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
+++ b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
@@ -214,6 +214,7 @@ cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res)
res->ls_len = end - res->ls_str + 1;
return 1;
}
+EXPORT_SYMBOL(cfs_gettok);
/**
* Converts string to integer.
@@ -242,6 +243,7 @@ cfs_str2num_check(char *str, int nob, unsigned *num,
return (*num >= min && *num <= max);
}
+EXPORT_SYMBOL(cfs_str2num_check);
/**
* Parses \<range_expr\> token of the syntax. If \a bracketed is false,
@@ -406,6 +408,7 @@ cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list)
return 0;
}
+EXPORT_SYMBOL(cfs_expr_list_match);
/**
* Convert express list (\a expr_list) to an array of all matched values
@@ -558,6 +561,7 @@ cfs_expr_list_free_list(struct list_head *list)
cfs_expr_list_free(el);
}
}
+EXPORT_SYMBOL(cfs_expr_list_free_list);
int
cfs_ip_addr_parse(char *str, int len, struct list_head *list)
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [next] | [standalone]
| From | James Simmons <jsimmons@infradead.org> |
|---|---|
| Date | 2015-10-22 04:10 +0200 |
| Subject | [PATCH 01/11] staging: lustre: add a service that prints a nidlist |
| Message-ID | <qmduj-4Se-33@gated-at.bofh.it> |
| In reply to | #1253428 |
From: Gregoire Pichon <gregoire.pichon@bull.net>
The libcfs already provides services to parse a string into a nidlist
and to match a nid into a nidlist. This patch implements a service
that prints a nidlist into a buffer.
This is required for instance to print the nosquash_nids parameter
of the MDT procfs component.
Additionally, this patch fixes a bug in return code of
parse_addrange() routine, so that parsing of nids including
a * character works fine ('*@elan' for instance).
Signed-off-by: Gregoire Pichon <gregoire.pichon@bull.net>
Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-1778
Reviewed-on: http://review.whamcloud.com/9221
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
Reviewed-by: Liang Zhen <liang.zhen@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
Signed-off-by: James Simmons <uja.ornl@yahoo.com>
---
.../lustre/include/linux/libcfs/libcfs_string.h | 2 +
drivers/staging/lustre/include/linux/lnet/nidstr.h | 2 +
.../staging/lustre/lustre/libcfs/libcfs_string.c | 71 +++++++++++-
drivers/staging/lustre/lustre/libcfs/nidstrings.c | 124 +++++++++++++++++++-
4 files changed, 193 insertions(+), 6 deletions(-)
diff --git a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
index 478e958..d178e43 100644
--- a/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
+++ b/drivers/staging/lustre/include/linux/libcfs/libcfs_string.h
@@ -83,6 +83,8 @@ int cfs_gettok(struct cfs_lstr *next, char delim, struct cfs_lstr *res);
int cfs_str2num_check(char *str, int nob, unsigned *num,
unsigned min, unsigned max);
int cfs_expr_list_match(__u32 value, struct cfs_expr_list *expr_list);
+int cfs_expr_list_print(char *buffer, int count,
+ struct cfs_expr_list *expr_list);
int cfs_expr_list_values(struct cfs_expr_list *expr_list,
int max, __u32 **values);
static inline void
diff --git a/drivers/staging/lustre/include/linux/lnet/nidstr.h b/drivers/staging/lustre/include/linux/lnet/nidstr.h
index a627be9..082782b 100644
--- a/drivers/staging/lustre/include/linux/lnet/nidstr.h
+++ b/drivers/staging/lustre/include/linux/lnet/nidstr.h
@@ -69,7 +69,9 @@ int libcfs_str2anynid(lnet_nid_t *nid, const char *str);
char *libcfs_id2str(lnet_process_id_t id);
void cfs_free_nidlist(struct list_head *list);
int cfs_parse_nidlist(char *str, int len, struct list_head *list);
+int cfs_print_nidlist(char *buffer, int count, struct list_head *list);
int cfs_match_nid(lnet_nid_t nid, struct list_head *list);
+
bool cfs_nidrange_is_contiguous(struct list_head *nidlist);
void cfs_nidrange_find_min_max(struct list_head *nidlist, char *min_nid,
char *max_nid, size_t nidstr_length);
diff --git a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
index efe5e66..bbfef98 100644
--- a/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
+++ b/drivers/staging/lustre/lustre/libcfs/libcfs_string.c
@@ -321,6 +321,73 @@ cfs_range_expr_parse(struct cfs_lstr *src, unsigned min, unsigned max,
}
/**
+ * Print the range expression \a re into specified \a buffer.
+ * If \a bracketed is true, expression does not need additional
+ * brackets.
+ *
+ * \retval number of characters written
+ */
+static int
+cfs_range_expr_print(char *buffer, int count, struct cfs_range_expr *expr,
+ bool bracketed)
+{
+ int i;
+ char s[] = "[";
+ char e[] = "]";
+
+ if (bracketed)
+ s[0] = e[0] = '\0';
+
+ if (expr->re_lo == expr->re_hi)
+ i = scnprintf(buffer, count, "%u", expr->re_lo);
+ else if (expr->re_stride == 1)
+ i = scnprintf(buffer, count, "%s%u-%u%s",
+ s, expr->re_lo, expr->re_hi, e);
+ else
+ i = scnprintf(buffer, count, "%s%u-%u/%u%s",
+ s, expr->re_lo, expr->re_hi,
+ expr->re_stride, e);
+ return i;
+}
+
+/**
+ * Print a list of range expressions (\a expr_list) into specified \a buffer.
+ * If the list contains several expressions, separate them with comma
+ * and surround the list with brackets.
+ *
+ * \retval number of characters written
+ */
+int
+cfs_expr_list_print(char *buffer, int count, struct cfs_expr_list *expr_list)
+{
+ struct cfs_range_expr *expr;
+ int i = 0, j = 0;
+ int numexprs = 0;
+
+ if (count <= 0)
+ return 0;
+
+ list_for_each_entry(expr, &expr_list->el_exprs, re_link)
+ numexprs++;
+
+ if (numexprs > 1)
+ i += scnprintf(buffer + i, count - i, "[");
+
+ list_for_each_entry(expr, &expr_list->el_exprs, re_link) {
+ if (j++ != 0)
+ i += scnprintf(buffer + i, count - i, ",");
+ i += cfs_range_expr_print(buffer + i, count - i, expr,
+ numexprs > 1);
+ }
+
+ if (numexprs > 1)
+ i += scnprintf(buffer + i, count - i, "]");
+
+ return i;
+}
+EXPORT_SYMBOL(cfs_expr_list_print);
+
+/**
* Matches value (\a value) against ranges expression list \a expr_list.
*
* \retval 1 if \a value matches
@@ -412,8 +479,8 @@ EXPORT_SYMBOL(cfs_expr_list_free);
/**
* Parses \<cfs_expr_list\> token of the syntax.
*
- * \retval 1 if \a str parses to \<number\> | \<expr_list\>
- * \retval 0 otherwise
+ * \retval 0 if \a str parses to \<number\> | \<expr_list\>
+ * \retval -errno otherwise
*/
int
cfs_expr_list_parse(char *str, int len, unsigned min, unsigned max,
diff --git a/drivers/staging/lustre/lustre/libcfs/nidstrings.c b/drivers/staging/lustre/lustre/libcfs/nidstrings.c
index 087449f..a54594a 100644
--- a/drivers/staging/lustre/lustre/libcfs/nidstrings.c
+++ b/drivers/staging/lustre/lustre/libcfs/nidstrings.c
@@ -114,6 +114,21 @@ static int libcfs_ip_str2addr(const char *str, int nob, __u32 *addr)
return 0;
}
+static int
+libcfs_ip_addr_range_print(char *buffer, int count, struct list_head *list)
+{
+ int i = 0, j = 0;
+ struct cfs_expr_list *el;
+
+ list_for_each_entry(el, list, el_link) {
+ LASSERT(j++ < 4);
+ if (i != 0)
+ i += scnprintf(buffer + i, count - i, ".");
+ i += cfs_expr_list_print(buffer + i, count - i, el);
+ }
+ return i;
+}
+
static void libcfs_decnum_addr2str(__u32 addr, char *str)
{
snprintf(str, LNET_NIDSTR_SIZE, "%u", addr);
@@ -164,6 +179,19 @@ libcfs_num_parse(char *str, int len, struct list_head *list)
return rc;
}
+static int
+libcfs_num_addr_range_print(char *buffer, int count, struct list_head *list)
+{
+ int i = 0, j = 0;
+ struct cfs_expr_list *el;
+
+ list_for_each_entry(el, list, el_link) {
+ LASSERT(j++ < 1);
+ i += cfs_expr_list_print(buffer + i, count - i, el);
+ }
+ return i;
+}
+
/*
* Nf_match_addr method for networks using numeric addresses
*
@@ -189,6 +217,8 @@ struct netstrfns {
int (*nf_str2addr)(const char *str, int nob, __u32 *addr);
int (*nf_parse_addrlist)(char *str, int len,
struct list_head *list);
+ int (*nf_print_addrlist)(char *buffer, int count,
+ struct list_head *list);
int (*nf_match_addr)(__u32 addr, struct list_head *list);
};
@@ -199,6 +229,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_decnum_addr2str,
/* .nf_str2addr */ libcfs_lo_str2addr,
/* .nf_parse_addr*/ libcfs_num_parse,
+ /* .nf_print_addrlist*/ libcfs_num_addr_range_print,
/* .nf_match_addr*/ libcfs_num_match},
{/* .nf_type */ SOCKLND,
/* .nf_name */ "tcp",
@@ -206,6 +237,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_ip_addr2str,
/* .nf_str2addr */ libcfs_ip_str2addr,
/* .nf_parse_addrlist*/ cfs_ip_addr_parse,
+ /* .nf_print_addrlist*/ libcfs_ip_addr_range_print,
/* .nf_match_addr*/ cfs_ip_addr_match},
{/* .nf_type */ O2IBLND,
/* .nf_name */ "o2ib",
@@ -213,6 +245,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_ip_addr2str,
/* .nf_str2addr */ libcfs_ip_str2addr,
/* .nf_parse_addrlist*/ cfs_ip_addr_parse,
+ /* .nf_print_addrlist*/ libcfs_ip_addr_range_print,
/* .nf_match_addr*/ cfs_ip_addr_match},
{/* .nf_type */ CIBLND,
/* .nf_name */ "cib",
@@ -220,6 +253,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_ip_addr2str,
/* .nf_str2addr */ libcfs_ip_str2addr,
/* .nf_parse_addrlist*/ cfs_ip_addr_parse,
+ /* .nf_print_addrlist*/ libcfs_ip_addr_range_print,
/* .nf_match_addr*/ cfs_ip_addr_match},
{/* .nf_type */ OPENIBLND,
/* .nf_name */ "openib",
@@ -227,6 +261,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_ip_addr2str,
/* .nf_str2addr */ libcfs_ip_str2addr,
/* .nf_parse_addrlist*/ cfs_ip_addr_parse,
+ /* .nf_print_addrlist*/ libcfs_ip_addr_range_print,
/* .nf_match_addr*/ cfs_ip_addr_match},
{/* .nf_type */ IIBLND,
/* .nf_name */ "iib",
@@ -234,6 +269,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_ip_addr2str,
/* .nf_str2addr */ libcfs_ip_str2addr,
/* .nf_parse_addrlist*/ cfs_ip_addr_parse,
+ /* .nf_print_addrlist*/ libcfs_ip_addr_range_print,
/* .nf_match_addr*/ cfs_ip_addr_match},
{/* .nf_type */ VIBLND,
/* .nf_name */ "vib",
@@ -241,6 +277,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_ip_addr2str,
/* .nf_str2addr */ libcfs_ip_str2addr,
/* .nf_parse_addrlist*/ cfs_ip_addr_parse,
+ /* .nf_print_addrlist*/ libcfs_ip_addr_range_print,
/* .nf_match_addr*/ cfs_ip_addr_match},
{/* .nf_type */ RALND,
/* .nf_name */ "ra",
@@ -248,6 +285,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_ip_addr2str,
/* .nf_str2addr */ libcfs_ip_str2addr,
/* .nf_parse_addrlist*/ cfs_ip_addr_parse,
+ /* .nf_print_addrlist*/ libcfs_ip_addr_range_print,
/* .nf_match_addr*/ cfs_ip_addr_match},
{/* .nf_type */ QSWLND,
/* .nf_name */ "elan",
@@ -255,6 +293,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_decnum_addr2str,
/* .nf_str2addr */ libcfs_num_str2addr,
/* .nf_parse_addrlist*/ libcfs_num_parse,
+ /* .nf_print_addrlist*/ libcfs_num_addr_range_print,
/* .nf_match_addr*/ libcfs_num_match},
{/* .nf_type */ GMLND,
/* .nf_name */ "gm",
@@ -262,6 +301,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_hexnum_addr2str,
/* .nf_str2addr */ libcfs_num_str2addr,
/* .nf_parse_addrlist*/ libcfs_num_parse,
+ /* .nf_print_addrlist*/ libcfs_num_addr_range_print,
/* .nf_match_addr*/ libcfs_num_match},
{/* .nf_type */ MXLND,
/* .nf_name */ "mx",
@@ -269,6 +309,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_ip_addr2str,
/* .nf_str2addr */ libcfs_ip_str2addr,
/* .nf_parse_addrlist*/ cfs_ip_addr_parse,
+ /* .nf_print_addrlist*/ libcfs_ip_addr_range_print,
/* .nf_match_addr*/ cfs_ip_addr_match},
{/* .nf_type */ PTLLND,
/* .nf_name */ "ptl",
@@ -276,6 +317,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_decnum_addr2str,
/* .nf_str2addr */ libcfs_num_str2addr,
/* .nf_parse_addrlist*/ libcfs_num_parse,
+ /* .nf_print_addrlist*/ libcfs_num_addr_range_print,
/* .nf_match_addr*/ libcfs_num_match},
{/* .nf_type */ GNILND,
/* .nf_name */ "gni",
@@ -283,6 +325,7 @@ static struct netstrfns libcfs_netstrfns[] = {
/* .nf_addr2str */ libcfs_decnum_addr2str,
/* .nf_str2addr */ libcfs_num_str2addr,
/* .nf_parse_addrlist*/ libcfs_num_parse,
+ /* .nf_print_addrlist*/ libcfs_num_addr_range_print,
/* .nf_match_addr*/ libcfs_num_match},
/* placeholder for net0 alias. It MUST BE THE LAST ENTRY */
{/* .nf_type */ -1},
@@ -612,8 +655,8 @@ struct addrrange {
* Allocates struct addrrange and links to \a nidrange via
* (nidrange::nr_addrranges)
*
- * \retval 1 if \a src parses to '*' | \<ipaddr_range\> | \<cfs_expr_list\>
- * \retval 0 otherwise
+ * \retval 0 if \a src parses to '*' | \<ipaddr_range\> | \<cfs_expr_list\>
+ * \retval -errno otherwise
*/
static int
parse_addrange(const struct cfs_lstr *src, struct nidrange *nidrange)
@@ -622,12 +665,12 @@ parse_addrange(const struct cfs_lstr *src, struct nidrange *nidrange)
if (src->ls_len == 1 && src->ls_str[0] == '*') {
nidrange->nr_all = 1;
- return 1;
+ return 0;
}
LIBCFS_ALLOC(addrrange, sizeof(struct addrrange));
if (addrrange == NULL)
- return 0;
+ return -ENOMEM;
list_add_tail(&addrrange->ar_link, &nidrange->nr_addrranges);
INIT_LIST_HEAD(&addrrange->ar_numaddr_ranges);
@@ -840,3 +883,76 @@ int cfs_match_nid(lnet_nid_t nid, struct list_head *nidlist)
return 0;
}
EXPORT_SYMBOL(cfs_match_nid);
+
+/**
+ * Print the network part of the nidrange \a nr into the specified \a buffer.
+ *
+ * \retval number of characters written
+ */
+static int
+cfs_print_network(char *buffer, int count, struct nidrange *nr)
+{
+ struct netstrfns *nf = nr->nr_netstrfns;
+
+ if (nr->nr_netnum == 0)
+ return scnprintf(buffer, count, "@%s", nf->nf_name);
+ else
+ return scnprintf(buffer, count, "@%s%u",
+ nf->nf_name, nr->nr_netnum);
+}
+
+/**
+ * Print a list of addrrange (\a addrranges) into the specified \a buffer.
+ * At max \a count characters can be printed into \a buffer.
+ *
+ * \retval number of characters written
+ */
+static int
+cfs_print_addrranges(char *buffer, int count, struct list_head *addrranges,
+ struct nidrange *nr)
+{
+ int i = 0;
+ struct addrrange *ar;
+ struct netstrfns *nf = nr->nr_netstrfns;
+
+ list_for_each_entry(ar, addrranges, ar_link) {
+ if (i != 0)
+ i += scnprintf(buffer + i, count - i, " ");
+ i += nf->nf_print_addrlist(buffer + i, count - i,
+ &ar->ar_numaddr_ranges);
+ i += cfs_print_network(buffer + i, count - i, nr);
+ }
+ return i;
+}
+
+/**
+ * Print a list of nidranges (\a nidlist) into the specified \a buffer.
+ * At max \a count characters can be printed into \a buffer.
+ * Nidranges are separated by a space character.
+ *
+ * \retval number of characters written
+ */
+int cfs_print_nidlist(char *buffer, int count, struct list_head *nidlist)
+{
+ int i = 0;
+ struct nidrange *nr;
+
+ if (count <= 0)
+ return 0;
+
+ list_for_each_entry(nr, nidlist, nr_link) {
+ if (i != 0)
+ i += scnprintf(buffer + i, count - i, " ");
+
+ if (nr->nr_all != 0) {
+ LASSERT(list_empty(&nr->nr_addrranges));
+ i += scnprintf(buffer + i, count - i, "*");
+ i += cfs_print_network(buffer + i, count - i, nr);
+ } else {
+ i += cfs_print_addrranges(buffer + i, count - i,
+ &nr->nr_addrranges, nr);
+ }
+ }
+ return i;
+}
+EXPORT_SYMBOL(cfs_print_nidlist);
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web