Skip to contentSkip to conversation

Sync upstream lustre client LNet core

PATCH In review James Simmons 5 participants 65 messages Nov 20, 2015 – Dec 21, 2015 Staging

lore
Share & tools
lore
#0 lore raw

cover Sync upstream lustre client LNet core

This is the majority of the fixes that have gone into the LNet layer. Outside a few remaining patches this brings LNet close to what is running in production world wide.

This patch series needs the remove IOC_LIBCFS_PING_TEST ioctl patch landed first.

Amir Shehata (19):
staging: lustre: Dynamic LNet Configuration (DLC)
staging: lustre: Dynamic LNet Configuration (DLC) dynamic routing
staging: lustre: DLC Feature dynamic net config
staging: lustre: Dynamic LNet Configuration (DLC) IOCTL changes
staging: lustre: Dynamic LNet Configuration (DLC) show command
staging: lustre: fix crash due to NULL networks string
staging: lustre: DLC user/kernel space glue code
staging: lustre: fix kernel crash when network failed to start
staging: lustre: improve LNet clean up code and API
staging: lustre: return appropriate errno when adding route
staging: lustre: startup lnet acceptor thread dynamically
staging: lustre: reject invalid net configuration for lnet
staging: lustre: return -EEXIST if NI is not unique
staging: lustre: handle lnet_check_routes() errors
staging: lustre: improvement to router checker
staging: lustre: prevent assert on LNet module unload
staging: lustre: remove messages from lazy portal on NI shutdown
staging: lustre: remove unnecessary NULL check in IOC_LIBCFS_GET_NET
staging: lustre: Allocate the correct number of rtr buffers

Bruno Faccini (1):
staging: lustre: avoid race during lnet acceptor thread termination

Chris Horn (2):
staging: lustre: reflect down routes in /proc/sys/lnet/routes
staging: lustre: Use lnet_is_route_alive for router aliveness

Doug Oucharek (1):
staging: lustre: Remove LASSERTS from router checker

Frank Zago (1):
staging: lustre: do not memset after LIBCFS_ALLOC

James Simmons (4):
staging: lustre: drop *_t from end of struct lnet_text_buf
staging: lustre: eliminate obsolete Cray SeaStar support
staging: lustre: Fixes to make lnetctl function as expected.
staging: lustre: test for sk_sleep presence in compact-2.6.h

John L. Hammond (3):
staging: lustre: remove uses of IS_ERR_VALUE()
staging: lustre: remove LUSTRE_{,SRV_}LNET_PID
staging: lustre: assume a kernel build

Liang Zhen (3):
staging: lustre: fix failure handle of create reply
staging: lustre: return +ve for blocked lnet message
staging: lustre: copy out libcfs ioctl inline buffer

Sebastien Buisson (1):
staging: lustre: fix 'NULL pointer dereference' errors for LNet

frank zago (5):
staging: lustre: make local functions static for LNet ni
staging: lustre: add sparse annotation __user wherever needed for lnet
staging: lustre: make some lnet functions static
staging: lustre: missed a few cases of using NULL instead of 0
staging: lustre: remove unnecessary EXPORT_SYMBOL from lnet layer

 .../staging/lustre/include/linux/libcfs/libcfs.h   |    2 -
 .../lustre/include/linux/libcfs/libcfs_ioctl.h     |   89 ++-
 .../lustre/include/linux/libcfs/linux/libcfs.h     |    3 -
 .../staging/lustre/include/linux/lnet/lib-dlc.h    |  118 ++
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |   60 +-
 .../staging/lustre/include/linux/lnet/lib-types.h  |   38 +-
 drivers/staging/lustre/include/linux/lnet/lnetst.h |   96 +-
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |    4 +-
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |    7 +-
 drivers/staging/lustre/lnet/lnet/acceptor.c        |   30 +-
 drivers/staging/lustre/lnet/lnet/api-ni.c          | 1295 +++++++++++++------
 drivers/staging/lustre/lnet/lnet/config.c          |  113 +-
 drivers/staging/lustre/lnet/lnet/lib-eq.c          |    3 -
 drivers/staging/lustre/lnet/lnet/lib-md.c          |    3 -
 drivers/staging/lustre/lnet/lnet/lib-me.c          |    3 -
 drivers/staging/lustre/lnet/lnet/lib-move.c        |  195 ++-
 drivers/staging/lustre/lnet/lnet/lib-msg.c         |   20 +-
 drivers/staging/lustre/lnet/lnet/lib-ptl.c         |   54 +-
 drivers/staging/lustre/lnet/lnet/lib-socket.c      |    3 -
 drivers/staging/lustre/lnet/lnet/module.c          |   70 +-
 drivers/staging/lustre/lnet/lnet/peer.c            |  197 +++-
 drivers/staging/lustre/lnet/lnet/router.c          |  426 +++++--
 drivers/staging/lustre/lnet/lnet/router_proc.c     |    4 +-
 drivers/staging/lustre/lnet/selftest/conctl.c      |   62 +-
 drivers/staging/lustre/lnet/selftest/conrpc.c      |    4 +-
 drivers/staging/lustre/lnet/selftest/conrpc.h      |    5 +-
 drivers/staging/lustre/lnet/selftest/console.c     |   97 +-
 drivers/staging/lustre/lnet/selftest/console.h     |   55 +-
 drivers/staging/lustre/lnet/selftest/framework.c   |   10 -
 drivers/staging/lustre/lnet/selftest/module.c      |    4 +-
 drivers/staging/lustre/lnet/selftest/rpc.c         |    4 +-
 .../lustre/lustre/libcfs/linux/linux-module.c      |   74 +-
 drivers/staging/lustre/lustre/libcfs/module.c      |  104 +-
 drivers/staging/lustre/lustre/libcfs/tracefile.c   |    6 +-
 drivers/staging/lustre/lustre/llite/llite_lib.c    |    2 +-
 drivers/staging/lustre/lustre/llite/statahead.c    |    8 +-
 drivers/staging/lustre/lustre/mdc/mdc_request.c    |   18 +-
 drivers/staging/lustre/lustre/mgc/mgc_request.c    |    9 +-
 .../lustre/lustre/obdclass/linux/linux-module.c    |   17 +-
 drivers/staging/lustre/lustre/obdclass/llog.c      |   13 +-
 .../staging/lustre/lustre/obdclass/obd_config.c    |    4 +-
 drivers/staging/lustre/lustre/ptlrpc/events.c      |    4 +-
 drivers/staging/lustre/lustre/ptlrpc/pinger.c      |   10 +-
 drivers/staging/lustre/lustre/ptlrpc/service.c     |   29 +-
 44 files changed, 2297 insertions(+), 1075 deletions(-)
 create mode 100644 drivers/staging/lustre/include/linux/lnet/lib-dlc.h
#1 lore raw

PATCH 1/40 staging: lustre: drop *_t from end of struct lnet_text_buf

When lnet_text_buf data structure was transform from typedef to struct the *_t which is typical of typedef was not drop. This patch removes the *_t to be consistent.

---
 drivers/staging/lustre/lnet/lnet/config.c |   57 ++++++++++++++---------------
 1 files changed, 27 insertions(+), 30 deletions(-)
drivers/staging/lustre/lnet/lnet/config.c +27 -30
index 5390ee9..867c96e 100644
@@ -37,7 +37,7 @@
 #define DEBUG_SUBSYSTEM S_LNET
 #include "../../include/linux/lnet/lib-lnet.h"
 
-struct lnet_text_buf_t {	    /* tmp struct for parsing routes */
+struct lnet_text_buf {	    /* tmp struct for parsing routes */
 	struct list_head ltb_list;	/* stash on lists */
 	int ltb_size;	/* allocated size */
 	char ltb_text[0];     /* text buffer */
@@ -365,14 +365,14 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 	return -EINVAL;
 }
 
-static struct lnet_text_buf_t *
+static struct lnet_text_buf *
 lnet_new_text_buf(int str_len)
 {
-	struct lnet_text_buf_t *ltb;
+	struct lnet_text_buf *ltb;
 	int nob;
 
 	/* NB allocate space for the terminating 0 */
-	nob = offsetof(struct lnet_text_buf_t, ltb_text[str_len + 1]);
+	nob = offsetof(struct lnet_text_buf, ltb_text[str_len + 1]);
 	if (nob > LNET_SINGLE_TEXTBUF_NOB) {
 		/* _way_ conservative for "route net gateway..." */
 		CERROR("text buffer too big\n");
@@ -395,7 +395,7 @@ lnet_new_text_buf(int str_len)
 }
 
 static void
-lnet_free_text_buf(struct lnet_text_buf_t *ltb)
+lnet_free_text_buf(struct lnet_text_buf *ltb)
 {
 	lnet_tbnob -= ltb->ltb_size;
 	LIBCFS_FREE(ltb, ltb->ltb_size);
@@ -404,10 +404,10 @@ lnet_free_text_buf(struct lnet_text_buf_t *ltb)
 static void
 lnet_free_text_bufs(struct list_head *tbs)
 {
-	struct lnet_text_buf_t *ltb;
+	struct lnet_text_buf *ltb;
 
 	while (!list_empty(tbs)) {
-		ltb = list_entry(tbs->next, struct lnet_text_buf_t, ltb_list);
+		ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
 
 		list_del(&ltb->ltb_list);
 		lnet_free_text_buf(ltb);
@@ -421,7 +421,7 @@ lnet_str2tbs_sep(struct list_head *tbs, char *str)
 	char *sep;
 	int nob;
 	int i;
-	struct lnet_text_buf_t *ltb;
+	struct lnet_text_buf *ltb;
 
 	INIT_LIST_HEAD(&pending);
 
@@ -479,7 +479,7 @@ lnet_expand1tb(struct list_head *list,
 {
 	int len1 = (int)(sep1 - str);
 	int len2 = strlen(sep2 + 1);
-	struct lnet_text_buf_t *ltb;
+	struct lnet_text_buf *ltb;
 
 	LASSERT(*sep1 == '[');
 	LASSERT(*sep2 == ']');
@@ -636,7 +636,7 @@ lnet_parse_route(char *str, int *im_a_router)
 	struct list_head *tmp2;
 	__u32 net;
 	lnet_nid_t nid;
-	struct lnet_text_buf_t *ltb;
+	struct lnet_text_buf *ltb;
 	int rc;
 	char *sep;
 	char *token = str;
@@ -692,8 +692,7 @@ lnet_parse_route(char *str, int *im_a_router)
 		list_add_tail(tmp1, tmp2);
 
 		while (tmp1 != tmp2) {
-			ltb = list_entry(tmp1, struct lnet_text_buf_t,
-					 ltb_list);
+			ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
 
 			rc = lnet_str2tbs_expand(tmp1->next, ltb->ltb_text);
 			if (rc < 0)
@@ -733,13 +732,12 @@ lnet_parse_route(char *str, int *im_a_router)
 	LASSERT(!list_empty(&gateways));
 
 	list_for_each(tmp1, &nets) {
-		ltb = list_entry(tmp1, struct lnet_text_buf_t, ltb_list);
+		ltb = list_entry(tmp1, struct lnet_text_buf, ltb_list);
 		net = libcfs_str2net(ltb->ltb_text);
 		LASSERT(net != LNET_NIDNET(LNET_NID_ANY));
 
 		list_for_each(tmp2, &gateways) {
-			ltb = list_entry(tmp2, struct lnet_text_buf_t,
-					 ltb_list);
+			ltb = list_entry(tmp2, struct lnet_text_buf, ltb_list);
 			nid = libcfs_str2nid(ltb->ltb_text);
 			LASSERT(nid != LNET_NID_ANY);
 
@@ -772,10 +770,10 @@ lnet_parse_route(char *str, int *im_a_router)
 static int
 lnet_parse_route_tbs(struct list_head *tbs, int *im_a_router)
 {
-	struct lnet_text_buf_t *ltb;
+	struct lnet_text_buf *ltb;
 
 	while (!list_empty(tbs)) {
-		ltb = list_entry(tbs->next, struct lnet_text_buf_t, ltb_list);
+		ltb = list_entry(tbs->next, struct lnet_text_buf, ltb_list);
 
 		if (lnet_parse_route(ltb->ltb_text, im_a_router) < 0) {
 			lnet_free_text_bufs(tbs);
@@ -909,8 +907,8 @@ lnet_splitnets(char *source, struct list_head *nets)
 	int offset = 0;
 	int offset2;
 	int len;
-	struct lnet_text_buf_t *tb;
-	struct lnet_text_buf_t *tb2;
+	struct lnet_text_buf *tb;
+	struct lnet_text_buf *tb2;
 	struct list_head *t;
 	char *sep;
 	char *bracket;
@@ -919,7 +917,7 @@ lnet_splitnets(char *source, struct list_head *nets)
 	LASSERT(!list_empty(nets));
 	LASSERT(nets->next == nets->prev);     /* single entry */
 
-	tb = list_entry(nets->next, struct lnet_text_buf_t, ltb_list);
+	tb = list_entry(nets->next, struct lnet_text_buf, ltb_list);
 
 	for (;;) {
 		sep = strchr(tb->ltb_text, ',');
@@ -955,7 +953,7 @@ lnet_splitnets(char *source, struct list_head *nets)
 		}
 
 		list_for_each(t, nets) {
-			tb2 = list_entry(t, struct lnet_text_buf_t, ltb_list);
+			tb2 = list_entry(t, struct lnet_text_buf, ltb_list);
 
 			if (tb2 == tb)
 				continue;
@@ -996,8 +994,8 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 	struct list_head current_nets;
 	struct list_head *t;
 	struct list_head *t2;
-	struct lnet_text_buf_t *tb;
-	struct lnet_text_buf_t *tb2;
+	struct lnet_text_buf *tb;
+	struct lnet_text_buf *tb2;
 	__u32 net1;
 	__u32 net2;
 	int len;
@@ -1020,9 +1018,8 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 	rc = 0;
 
 	while (!list_empty(&raw_entries)) {
-		tb = list_entry(raw_entries.next, struct lnet_text_buf_t,
-				    ltb_list);
-
+		tb = list_entry(raw_entries.next, struct lnet_text_buf,
+				ltb_list);
 		strncpy(source, tb->ltb_text, sizeof(source));
 		source[sizeof(source)-1] = '\0';
 
@@ -1047,13 +1044,13 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 
 		dup = 0;
 		list_for_each(t, &current_nets) {
-			tb = list_entry(t, struct lnet_text_buf_t, ltb_list);
+			tb = list_entry(t, struct lnet_text_buf, ltb_list);
 			net1 = lnet_netspec2net(tb->ltb_text);
 			LASSERT(net1 != LNET_NIDNET(LNET_NID_ANY));
 
 			list_for_each(t2, &matched_nets) {
-				tb2 = list_entry(t2, struct lnet_text_buf_t,
-						     ltb_list);
+				tb2 = list_entry(t2, struct lnet_text_buf,
+						 ltb_list);
 				net2 = lnet_netspec2net(tb2->ltb_text);
 				LASSERT(net2 != LNET_NIDNET(LNET_NID_ANY));
 
@@ -1073,7 +1070,7 @@ lnet_match_networks(char **networksp, char *ip2nets, __u32 *ipaddrs, int nip)
 		}
 
 		list_for_each_safe(t, t2, &current_nets) {
-			tb = list_entry(t, struct lnet_text_buf_t, ltb_list);
+			tb = list_entry(t, struct lnet_text_buf, ltb_list);
 
 			list_del(&tb->ltb_list);
 			list_add_tail(&tb->ltb_list, &matched_nets);
Signature · 1 line
1.7.1
#2 lore raw

PATCH 2/40 staging: lustre: fix 'NULL pointer dereference' errors for LNet

In reply to James Simmons

From: Sebastien Buisson <[email protected]>

Fix 'NULL pointer dereference' defects found by Coverity version 6.5.3:
Dereference after null check (FORWARD_NULL)
For instance, Passing null pointer to a function which dereferences it.
Dereference before null check (REVERSE_INULL) Null-checking variable suggests that it may be null, but it has already been dereferenced on all paths leading to the check. Dereference null return value (NULL_RETURNS)

The following fixes for the LNet layer are broken out of patch
http://review.whamcloud.com/4720.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2217
Reviewed-on: http://review.whamcloud.com/4720

---
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |    2 +-
 drivers/staging/lustre/lnet/lnet/lib-move.c        |    2 +
 drivers/staging/lustre/lnet/selftest/conctl.c      |   51 ++++++++++----------
 3 files changed, 29 insertions(+), 26 deletions(-)
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +1 -1
index de0f85f..0f4154c 100644
@@ -2829,7 +2829,7 @@ int kiblnd_startup(lnet_ni_t *ni)
 	return 0;
 
 failed:
-	if (net->ibn_dev == NULL && ibdev != NULL)
+	if (net && net->ibn_dev == NULL && ibdev != NULL)
 		kiblnd_destroy_dev(ibdev);
 
 net_failed:
drivers/staging/lustre/lnet/lnet/lib-move.c +2 -0
index 5631f60..7a68382 100644
@@ -162,6 +162,7 @@ lnet_iov_nob(unsigned int niov, struct kvec *iov)
 {
 	unsigned int nob = 0;
 
+	LASSERT(niov == 0 || iov);
 	while (niov-- > 0)
 		nob += (iov++)->iov_len;
 
@@ -280,6 +281,7 @@ lnet_kiov_nob(unsigned int niov, lnet_kiov_t *kiov)
 {
 	unsigned int nob = 0;
 
+	LASSERT(niov == 0 || kiov);
 	while (niov-- > 0)
 		nob += (kiov++)->kiov_len;
 
drivers/staging/lustre/lnet/selftest/conctl.c +26 -25

71 lines not on this page · raw message

Signature · 1 line
1.7.1
#3 lore raw

Re: [PATCH 02/40] staging: lustre: fix 'NULL pointer dereference' errors for LNet

Quoted 31 lines · James Simmons

From: Sebastien Buisson <[email protected]>

Fix 'NULL pointer dereference' defects found by Coverity version 6.5.3:
Dereference after null check (FORWARD_NULL)
For instance, Passing null pointer to a function which dereferences it.
Dereference before null check (REVERSE_INULL) Null-checking variable suggests that it may be null, but it has already been dereferenced on all paths leading to the check. Dereference null return value (NULL_RETURNS)

The following fixes for the LNet layer are broken out of patch
http://review.whamcloud.com/4720.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2217
Reviewed-on: http://review.whamcloud.com/4720

---
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |    2 +-
 drivers/staging/lustre/lnet/lnet/lib-move.c        |    2 +
 drivers/staging/lustre/lnet/selftest/conctl.c      |   51 ++++++++++----------
 3 files changed, 29 insertions(+), 26 deletions(-)
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +0 -0
index de0f85f..0f4154c 100644

drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c int kiblnd_startup(lnet_ni_t *ni) · line 2835

Quoted 8 lines
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +1 -1
@@ -2829,7 +2829,7 @@ int kiblnd_startup(lnet_ni_t *ni)
 	return 0;
 
 failed:
-	if (net->ibn_dev == NULL && ibdev != NULL)
+	if (net && net->ibn_dev == NULL && ibdev != NULL)
 		kiblnd_destroy_dev(ibdev);
 
 net_failed:

I think the warning must be for a really really old version. This was fixed in: 3247c4e5ef5d ('staging: lustre: lnet: klnds: o2iblnd: fix null dereference on failed path in o2iblnd.c').

The new NULL check is superflous.

Quoted 13 lines
drivers/staging/lustre/lnet/lnet/lib-move.c +1 -0
index 5631f60..7a68382 100644
@@ -162,6 +162,7 @@ lnet_iov_nob(unsigned int niov, struct kvec *iov)
 {
 	unsigned int nob = 0;
 
+	LASSERT(niov == 0 || iov);
 	while (niov-- > 0)
 		nob += (iov++)->iov_len;
 

drivers/staging/lustre/lnet/lnet/lib-move.c lnet_kiov_nob(unsigned int niov, lnet_kiov_t *kiov) · line 287

Quoted 7 lines
drivers/staging/lustre/lnet/lnet/lib-move.c +1 -0
@@ -280,6 +281,7 @@ lnet_kiov_nob(unsigned int niov, lnet_kiov_t *kiov)
 {
 	unsigned int nob = 0;
 
+	LASSERT(niov == 0 || kiov);
 	while (niov-- > 0)
 		nob += (kiov++)->kiov_len;
 

Fine, I suppose.

Quoted 63 lines
drivers/staging/lustre/lnet/selftest/conctl.c +17 -25
index 556c837..2ca7d0e 100644
@@ -679,45 +679,46 @@ static int
 lst_stat_query_ioctl(lstio_stat_args_t *args)
 {
 	int rc;
-	char *name;
+	char *name = NULL;
 
 	/* TODO: not finished */
 	if (args->lstio_sta_key != console_session.ses_key)
 		return -EACCES;
 
-	if (args->lstio_sta_resultp == NULL ||
-	    (args->lstio_sta_namep  == NULL &&
-	     args->lstio_sta_idsp   == NULL) ||
-	    args->lstio_sta_nmlen <= 0 ||
-	    args->lstio_sta_nmlen > LST_NAME_SIZE)
-		return -EINVAL;
-
-	if (args->lstio_sta_idsp != NULL &&
-	    args->lstio_sta_count <= 0)
+	if (!args->lstio_sta_resultp)
 		return -EINVAL;
 
-	LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
-	if (name == NULL)
-		return -ENOMEM;
-
-	if (copy_from_user(name, args->lstio_sta_namep,
-			       args->lstio_sta_nmlen)) {
-		LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
-		return -EFAULT;
-	}
+	if (args->lstio_sta_idsp) {
+		if (args->lstio_sta_count <= 0)
+			return -EINVAL;
 
-	if (args->lstio_sta_idsp == NULL) {
-		rc = lstcon_group_stat(name, args->lstio_sta_timeout,
-				       args->lstio_sta_resultp);
-	} else {
 		rc = lstcon_nodes_stat(args->lstio_sta_count,
 				       args->lstio_sta_idsp,
 				       args->lstio_sta_timeout,
 				       args->lstio_sta_resultp);
-	}
+	} else if (args->lstio_sta_namep) {
+		if (args->lstio_sta_nmlen <= 0 ||
+		    args->lstio_sta_nmlen > LST_NAME_SIZE)
+			return -EINVAL;
+
+		LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
+		if (!name)
+			return -ENOMEM;
 
-	LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
+		rc = copy_from_user(name, args->lstio_sta_namep,
+				    args->lstio_sta_nmlen);
+		if (!rc)
+			rc = lstcon_group_stat(name, args->lstio_sta_timeout,

drivers/staging/lustre/lnet/selftest/conctl.c static int · line 721

Quoted 10 lines
drivers/staging/lustre/lnet/selftest/conctl.c +9 -0
+					       args->lstio_sta_resultp);
+		else
+			rc = -EFAULT;
 
+	} else {
+		rc = -EINVAL;
+	}
+
+	if (name)
+		LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);

There is no bug fix here. This code was fine when it was merged into the kernel in 2013 so I have no idea how out of date the static checker warning is... The new code doesn't do unnecessary allocations so that's good but "name" should be declared in the block where it is used instead of at the start of the function. Btw, we assume that the user gives us a NUL terminated string for "name" so we should fix that bug as well.

TODO: lustre: don't assume "name" is NUL terminated

regards,
dan carpenter

#4 lore raw

RE: [PATCH 02/40] staging: lustre: fix 'NULL pointer dereference' errors for LNet

Quoted 81 lines
Quoted 63 lines
drivers/staging/lustre/lnet/selftest/conctl.c +17 -25
index 556c837..2ca7d0e 100644
@@ -679,45 +679,46 @@ static int
 lst_stat_query_ioctl(lstio_stat_args_t *args)
 {
 	int rc;
-	char *name;
+	char *name = NULL;
 
 	/* TODO: not finished */
 	if (args->lstio_sta_key != console_session.ses_key)
 		return -EACCES;
 
-	if (args->lstio_sta_resultp == NULL ||
-	    (args->lstio_sta_namep  == NULL &&
-	     args->lstio_sta_idsp   == NULL) ||
-	    args->lstio_sta_nmlen <= 0 ||
-	    args->lstio_sta_nmlen > LST_NAME_SIZE)
-		return -EINVAL;
-
-	if (args->lstio_sta_idsp != NULL &&
-	    args->lstio_sta_count <= 0)
+	if (!args->lstio_sta_resultp)
 		return -EINVAL;
 
-	LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
-	if (name == NULL)
-		return -ENOMEM;
-
-	if (copy_from_user(name, args->lstio_sta_namep,
-			       args->lstio_sta_nmlen)) {
-		LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
-		return -EFAULT;
-	}
+	if (args->lstio_sta_idsp) {
+		if (args->lstio_sta_count <= 0)
+			return -EINVAL;
 
-	if (args->lstio_sta_idsp == NULL) {
-		rc = lstcon_group_stat(name, args->lstio_sta_timeout,
-				       args->lstio_sta_resultp);
-	} else {
 		rc = lstcon_nodes_stat(args->lstio_sta_count,
 				       args->lstio_sta_idsp,
 				       args->lstio_sta_timeout,
 				       args->lstio_sta_resultp);
-	}
+	} else if (args->lstio_sta_namep) {
+		if (args->lstio_sta_nmlen <= 0 ||
+		    args->lstio_sta_nmlen > LST_NAME_SIZE)
+			return -EINVAL;
+
+		LIBCFS_ALLOC(name, args->lstio_sta_nmlen + 1);
+		if (!name)
+			return -ENOMEM;
 
-	LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);
+		rc = copy_from_user(name, args->lstio_sta_namep,
+				    args->lstio_sta_nmlen);
+		if (!rc)
+			rc = lstcon_group_stat(name, args->lstio_sta_timeout,

drivers/staging/lustre/lnet/selftest/conctl.c static int · line 721

Quoted 10 lines
drivers/staging/lustre/lnet/selftest/conctl.c +9 -0
+					       args->lstio_sta_resultp);
+		else
+			rc = -EFAULT;
 
+	} else {
+		rc = -EINVAL;
+	}
+
+	if (name)
+		LIBCFS_FREE(name, args->lstio_sta_nmlen + 1);

There is no bug fix here. This code was fine when it was merged into the kernel in 2013 so I have no idea how out of date the static checker warning is... The new code doesn't do unnecessary allocations so that's good but "name" should be declared in the block where it is used instead of at the start of the function. Btw, we assume that the user gives us a NUL terminated string for "name" so we should fix that bug as well.

Quoted 1 line

TODO: lustre: don't assume "name" is NUL terminated

Ugh. I see breakage everywhere in this code :-( Need to address. I think we should convert that to strcpy_to_user as well.

#5 lore raw

PATCH 3/40 staging: lustre: reflect down routes in /proc/sys/lnet/routes

In reply to James Simmons

From: Chris Horn <[email protected]>

We consider routes "down" if the router is down or the router NI for the target network is down. This should be reflected in the output of /proc/sys/lnet/routes

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-3679
Reviewed-on: http://review.whamcloud.com/7857

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |   13 ++++++++
 drivers/staging/lustre/lnet/lnet/lib-move.c        |   32 ++++++++++----------
 drivers/staging/lustre/lnet/lnet/router_proc.c     |    2 +-
 3 files changed, 30 insertions(+), 17 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +13 -0
index b61d504..09c6bfe 100644
@@ -64,6 +64,19 @@ extern lnet_t	the_lnet;	/* THE network */
 /** exclusive lock */
 #define LNET_LOCK_EX		CFS_PERCPT_LOCK_EX
 
+static inline int lnet_is_route_alive(lnet_route_t *route)
+{
+	/* gateway is down */
+	if (!route->lr_gateway->lp_alive)
+		return 0;
+	/* no NI status, assume it's alive */
+	if ((route->lr_gateway->lp_ping_feats &
+	     LNET_PING_FEAT_NI_STATUS) == 0)
+		return 1;
+	/* has NI status, check # down NIs */
+	return route->lr_downis == 0;
+}
+
 static inline int lnet_is_wire_handle_none(lnet_handle_wire_t *wh)
 {
 	return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE &&
drivers/staging/lustre/lnet/lnet/lib-move.c +16 -16
index 7a68382..c56de44 100644
@@ -1122,9 +1122,9 @@ static lnet_peer_t *
 lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
 {
 	lnet_remotenet_t *rnet;
-	lnet_route_t *rtr;
-	lnet_route_t *rtr_best;
-	lnet_route_t *rtr_last;
+	lnet_route_t *route;
+	lnet_route_t *best_route;
+	lnet_route_t *last_route;
 	struct lnet_peer *lp_best;
 	struct lnet_peer *lp;
 	int rc;
@@ -1137,13 +1137,12 @@ lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
 		return NULL;
 
 	lp_best = NULL;
-	rtr_best = rtr_last = NULL;
-	list_for_each_entry(rtr, &rnet->lrn_routes, lr_list) {
-		lp = rtr->lr_gateway;
+	best_route = NULL;
+	last_route = NULL;
+	list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
+		lp = route->lr_gateway;
 
-		if (!lp->lp_alive || /* gateway is down */
-		    ((lp->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0 &&
-		     rtr->lr_downis != 0)) /* NI to target is down */
+		if (!lnet_is_route_alive(route))
 			continue;
 
 		if (ni != NULL && lp->lp_ni != ni)
@@ -1153,28 +1152,29 @@ lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
 			return lp;
 
 		if (lp_best == NULL) {
-			rtr_best = rtr_last = rtr;
+			best_route = route;
+			last_route = route;
 			lp_best = lp;
 			continue;
 		}
 
 		/* no protection on below fields, but it's harmless */
-		if (rtr_last->lr_seq - rtr->lr_seq < 0)
-			rtr_last = rtr;
+		if (last_route->lr_seq - route->lr_seq < 0)
+			last_route = route;
 
-		rc = lnet_compare_routes(rtr, rtr_best);
+		rc = lnet_compare_routes(route, best_route);
 		if (rc < 0)
 			continue;
 
-		rtr_best = rtr;
+		best_route = route;
 		lp_best = lp;
 	}
 
 	/* set sequence number on the best router to the latest sequence + 1
 	 * so we can round-robin all routers, it's race and inaccurate but
 	 * harmless and functional  */
-	if (rtr_best != NULL)
-		rtr_best->lr_seq = rtr_last->lr_seq + 1;
+	if (best_route)
+		best_route->lr_seq = last_route->lr_seq + 1;
 	return lp_best;
 }
 
drivers/staging/lustre/lnet/lnet/router_proc.c +1 -1
index 396c7c4..af7423f 100644
@@ -240,7 +240,7 @@ static int proc_lnet_routes(struct ctl_table *table, int write,
 			unsigned int hops = route->lr_hops;
 			unsigned int priority = route->lr_priority;
 			lnet_nid_t nid = route->lr_gateway->lp_nid;
-			int alive = route->lr_gateway->lp_alive;
+			int alive = lnet_is_route_alive(route);
 
 			s += snprintf(s, tmpstr + tmpsiz - s,
 				      "%-8s %4u %8u %7s %s\n",
Signature · 1 line
1.7.1
#6 lore raw

Re: [PATCH 03/40] staging: lustre: reflect down routes in /proc/sys/lnet/routes

Quoted 47 lines · James Simmons

From: Chris Horn <[email protected]>

We consider routes "down" if the router is down or the router NI for the target network is down. This should be reflected in the output of /proc/sys/lnet/routes

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-3679
Reviewed-on: http://review.whamcloud.com/7857

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |   13 ++++++++
 drivers/staging/lustre/lnet/lnet/lib-move.c        |   32 ++++++++++----------
 drivers/staging/lustre/lnet/lnet/router_proc.c     |    2 +-
 3 files changed, 30 insertions(+), 17 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +13 -0
index b61d504..09c6bfe 100644
@@ -64,6 +64,19 @@ extern lnet_t	the_lnet;	/* THE network */
 /** exclusive lock */
 #define LNET_LOCK_EX		CFS_PERCPT_LOCK_EX
 
+static inline int lnet_is_route_alive(lnet_route_t *route)
+{
+	/* gateway is down */
+	if (!route->lr_gateway->lp_alive)
+		return 0;
+	/* no NI status, assume it's alive */
+	if ((route->lr_gateway->lp_ping_feats &
+	     LNET_PING_FEAT_NI_STATUS) == 0)
+		return 1;
+	/* has NI status, check # down NIs */
+	return route->lr_downis == 0;
+}
+
 static inline int lnet_is_wire_handle_none(lnet_handle_wire_t *wh)
 {
 	return (wh->wh_interface_cookie == LNET_WIRE_HANDLE_COOKIE_NONE &&
drivers/staging/lustre/lnet/lnet/lib-move.c +0 -0
index 7a68382..c56de44 100644

drivers/staging/lustre/lnet/lnet/lib-move.c static lnet_peer_t * · line 1127

Quoted 9 lines
drivers/staging/lustre/lnet/lnet/lib-move.c +3 -3
@@ -1122,9 +1122,9 @@ static lnet_peer_t *
 lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
 {
 	lnet_remotenet_t *rnet;
-	lnet_route_t *rtr;
-	lnet_route_t *rtr_best;
-	lnet_route_t *rtr_last;
+	lnet_route_t *route;
+	lnet_route_t *best_route;
+	lnet_route_t *last_route;

Unrelated variable renaming.

drivers/staging/lustre/lnet/lnet/lib-move.c lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid) · line 1141

Quoted 12 lines
drivers/staging/lustre/lnet/lnet/lib-move.c +2 -3
 	struct lnet_peer *lp_best;
 	struct lnet_peer *lp;
 	int rc;
@@ -1137,13 +1137,12 @@ lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
 		return NULL;
 
 	lp_best = NULL;
-	rtr_best = rtr_last = NULL;
-	list_for_each_entry(rtr, &rnet->lrn_routes, lr_list) {
-		lp = rtr->lr_gateway;
+	best_route = NULL;
+	last_route = NULL;

Unrelated checkpatch fixes.

drivers/staging/lustre/lnet/lnet/lib-move.c lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid) · line 1145

Quoted 7 lines
drivers/staging/lustre/lnet/lnet/lib-move.c +3 -3
+	list_for_each_entry(route, &rnet->lrn_routes, lr_list) {
+		lp = route->lr_gateway;
 
-		if (!lp->lp_alive || /* gateway is down */
-		    ((lp->lp_ping_feats & LNET_PING_FEAT_NI_STATUS) != 0 &&
-		     rtr->lr_downis != 0)) /* NI to target is down */
+		if (!lnet_is_route_alive(route))

This section is related to the patch, we moved the check out into its own function.

drivers/staging/lustre/lnet/lnet/lib-move.c lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid) · line 1156

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/lib-move.c +2 -1
 			continue;
 
 		if (ni != NULL && lp->lp_ni != ni)
@@ -1153,28 +1152,29 @@ lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid)
 			return lp;
 
 		if (lp_best == NULL) {
-			rtr_best = rtr_last = rtr;
+			best_route = route;
+			last_route = route;

More unrelated checkpatch fixes.

Quoted 16 lines
drivers/staging/lustre/lnet/lnet/lib-move.c +3 -4
 			lp_best = lp;
 			continue;
 		}
 
 		/* no protection on below fields, but it's harmless */
-		if (rtr_last->lr_seq - rtr->lr_seq < 0)
-			rtr_last = rtr;
+		if (last_route->lr_seq - route->lr_seq < 0)
+			last_route = route;
 
-		rc = lnet_compare_routes(rtr, rtr_best);
+		rc = lnet_compare_routes(route, best_route);
 		if (rc < 0)
 			continue;
 
-		rtr_best = rtr;

drivers/staging/lustre/lnet/lnet/lib-move.c lnet_find_route_locked(lnet_ni_t *ni, lnet_nid_t target, lnet_nid_t rtr_nid) · line 1176

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/lib-move.c +2 -2
+		best_route = route;
 		lp_best = lp;
 	}
 
 	/* set sequence number on the best router to the latest sequence + 1
 	 * so we can round-robin all routers, it's race and inaccurate but
 	 * harmless and functional  */
-	if (rtr_best != NULL)
-		rtr_best->lr_seq = rtr_last->lr_seq + 1;
+	if (best_route)

More checkpatch fixes.

Quoted 9 lines
drivers/staging/lustre/lnet/lnet/lib-move.c +1 -0
+		best_route->lr_seq = last_route->lr_seq + 1;
 	return lp_best;
 }
 
drivers/staging/lustre/lnet/lnet/router_proc.c +0 -0
index 396c7c4..af7423f 100644

drivers/staging/lustre/lnet/lnet/router_proc.c static int proc_lnet_routes(struct ctl_table *table, int write, · line 243

Quoted 5 lines
drivers/staging/lustre/lnet/lnet/router_proc.c +1 -1
@@ -240,7 +240,7 @@ static int proc_lnet_routes(struct ctl_table *table, int write,
 			unsigned int hops = route->lr_hops;
 			unsigned int priority = route->lr_priority;
 			lnet_nid_t nid = route->lr_gateway->lp_nid;
-			int alive = route->lr_gateway->lp_alive;
+			int alive = lnet_is_route_alive(route);

This line is the bugfix.

I know that people hate breaking patches up into reviewable patches but this is a one line fix which is hidden behind 30 lines of unrelated changes. It makes it very hard to follow what is going on.

I have scripts to review checkpatch fixes basically automatically so it really really helps me when people do one thing per patch.

regards,
dan carpenter

#7 lore raw

PATCH 4/40 staging: lustre: fix failure handle of create reply

In reply to James Simmons

From: Liang Zhen <[email protected]>

error handler of lnet_create_reply_msg() didn't release lnet_res_lock if lnet_msg_alloc() failed.
It can be fixed by moving validation check of msg out from lock.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2745
Reviewed-on: http://review.whamcloud.com/5542

---
 drivers/staging/lustre/lnet/lnet/lib-move.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
drivers/staging/lustre/lnet/lnet/lib-move.c +6 -6
index c56de44..03fcddc 100644
@@ -2160,17 +2160,17 @@ lnet_create_reply_msg(lnet_ni_t *ni, lnet_msg_t *getmsg)
 	LASSERT(!getmsg->msg_target_is_router);
 	LASSERT(!getmsg->msg_routing);
 
-	cpt = lnet_cpt_of_cookie(getmd->md_lh.lh_cookie);
-	lnet_res_lock(cpt);
-
-	LASSERT(getmd->md_refcount > 0);
-
 	if (msg == NULL) {
 		CERROR("%s: Dropping REPLY from %s: can't allocate msg\n",
-			libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
+		       libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id));
 		goto drop;
 	}
 
+	cpt = lnet_cpt_of_cookie(getmd->md_lh.lh_cookie);
+	lnet_res_lock(cpt);
+
+	LASSERT(getmd->md_refcount > 0);
+
 	if (getmd->md_threshold == 0) {
 		CERROR("%s: Dropping REPLY from %s for inactive MD %p\n",
 			libcfs_nid2str(ni->ni_nid), libcfs_id2str(peer_id),
Signature · 1 line
1.7.1
#8 lore raw

PATCH 5/40 staging: lustre: eliminate obsolete Cray SeaStar support

In reply to James Simmons

Remove the bulk of code for the no longer supported SeaStar interconnect found on older Cray systems.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-1422
Reviewed-on: http://review.whamcloud.com/7469

---
 drivers/staging/lustre/lnet/lnet/router.c |   12 ++----------
 1 files changed, 2 insertions(+), 10 deletions(-)
drivers/staging/lustre/lnet/lnet/router.c +2 -10
index 4ea651c..fa61ec9 100644
@@ -631,7 +631,6 @@ lnet_parse_rc_info(lnet_rc_data_t *rcd)
 		return; /* can't carry NI status info */
 
 	list_for_each_entry(rtr, &gw->lp_routes, lr_gwlist) {
-		int ptl_status = LNET_NI_STATUS_INVALID;
 		int down = 0;
 		int up = 0;
 		int i;
@@ -651,10 +650,7 @@ lnet_parse_rc_info(lnet_rc_data_t *rcd)
 				continue;
 
 			if (stat->ns_status == LNET_NI_STATUS_DOWN) {
-				if (LNET_NETTYP(LNET_NIDNET(nid)) != PTLLND)
-					down++;
-				else if (ptl_status != LNET_NI_STATUS_UP)
-					ptl_status = LNET_NI_STATUS_DOWN;
+				down++;
 				continue;
 			}
 
@@ -663,10 +659,6 @@ lnet_parse_rc_info(lnet_rc_data_t *rcd)
 					up = 1;
 					break;
 				}
-				/* ptl NIs are considered down only when
-				 * they're all down */
-				if (LNET_NETTYP(LNET_NIDNET(nid)) == PTLLND)
-					ptl_status = LNET_NI_STATUS_UP;
 				continue;
 			}
 
@@ -680,7 +672,7 @@ lnet_parse_rc_info(lnet_rc_data_t *rcd)
 			rtr->lr_downis = 0;
 			continue;
 		}
-		rtr->lr_downis = down + (ptl_status == LNET_NI_STATUS_DOWN);
+		rtr->lr_downis = down;
 	}
 }
 
Signature · 1 line
1.7.1
#9 lore raw

PATCH 6/40 staging: lustre: remove uses of IS_ERR_VALUE()

In reply to James Simmons

From: John L. Hammond <[email protected]>

Remove most uses of IS_ERR_VALUE(). This macro was often given an int argument coming from PTR_ERR(). This invokes implementation defined behavior since the long value gotten by applying PTR_ERR() to a kernel pointer will usually not be representable as an int. Moreover it may be just plain wrong to do this since the expressions IS_ERR(p) and IS_ERR_VALUE((int) PTR_ERR(p)) are not equivalent for a general pointer p.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-3498
Reviewed-on: http://review.whamcloud.com/6759

---
 drivers/staging/lustre/lnet/lnet/acceptor.c      |    9 ++++---
 drivers/staging/lustre/lnet/lnet/router.c        |    7 +++--
 drivers/staging/lustre/lustre/libcfs/tracefile.c |    6 +++-
 drivers/staging/lustre/lustre/llite/statahead.c  |    8 ++++--
 drivers/staging/lustre/lustre/mdc/mdc_request.c  |   18 +++++++++----
 drivers/staging/lustre/lustre/mgc/mgc_request.c  |    9 ++++---
 drivers/staging/lustre/lustre/obdclass/llog.c    |   13 ++++++----
 drivers/staging/lustre/lustre/ptlrpc/pinger.c    |   10 ++++---
 drivers/staging/lustre/lustre/ptlrpc/service.c   |   29 +++++++++++++---------
 9 files changed, 66 insertions(+), 43 deletions(-)
drivers/staging/lustre/lnet/lnet/acceptor.c +5 -4
index 92ca1dd..d05754d 100644
@@ -436,6 +436,7 @@ accept2secure(const char *acc, long *sec)
 int
 lnet_acceptor_start(void)
 {
+	struct task_struct *task;
 	int rc;
 	long rc2;
 	long secure;
@@ -454,10 +455,10 @@ lnet_acceptor_start(void)
 	if (lnet_count_acceptor_nis() == 0)  /* not required */
 		return 0;
 
-	rc2 = PTR_ERR(kthread_run(lnet_acceptor,
-				  (void *)(ulong_ptr_t)secure,
-				  "acceptor_%03ld", secure));
-	if (IS_ERR_VALUE(rc2)) {
+	task = kthread_run(lnet_acceptor, (void *)(ulong_ptr_t)secure,
+			   "acceptor_%03ld", secure);
+	if (IS_ERR(task)) {
+		rc2 = PTR_ERR(task);
 		CERROR("Can't start acceptor thread: %ld\n", rc2);
 
 		return -ESRCH;
drivers/staging/lustre/lnet/lnet/router.c +4 -3
index fa61ec9..47f80aa 100644
@@ -993,6 +993,7 @@ lnet_ping_router_locked(lnet_peer_t *rtr)
 int
 lnet_router_checker_start(void)
 {
+	struct task_struct *task;
 	int rc;
 	int eqsz;
 
@@ -1021,9 +1022,9 @@ lnet_router_checker_start(void)
 	}
 
 	the_lnet.ln_rc_state = LNET_RC_STATE_RUNNING;
-	rc = PTR_ERR(kthread_run(lnet_router_checker,
-				 NULL, "router_checker"));
-	if (IS_ERR_VALUE(rc)) {
+	task = kthread_run(lnet_router_checker, NULL, "router_checker");
+	if (IS_ERR(task)) {
+		rc = PTR_ERR(task);
 		CERROR("Can't start router checker thread: %d\n", rc);
 		/* block until event callback signals exit */
 		down(&the_lnet.ln_rc_signal);
drivers/staging/lustre/lustre/libcfs/tracefile.c +4 -2
index 65c4f1a..bc5d0ee 100644
@@ -1056,6 +1056,7 @@ end_loop:
 int cfs_trace_start_thread(void)
 {
 	struct tracefiled_ctl *tctl = &trace_tctl;
+	struct task_struct *task;
 	int rc = 0;
 
 	mutex_lock(&cfs_trace_thread_mutex);
@@ -1067,8 +1068,9 @@ int cfs_trace_start_thread(void)
 	init_waitqueue_head(&tctl->tctl_waitq);
 	atomic_set(&tctl->tctl_shutdown, 0);
 
-	if (IS_ERR(kthread_run(tracefiled, tctl, "ktracefiled"))) {
-		rc = -ECHILD;
+	task = kthread_run(tracefiled, tctl, "ktracefiled");
+	if (IS_ERR(task)) {
+		rc = PTR_ERR(task);
 		goto out;
 	}
 
drivers/staging/lustre/lustre/llite/statahead.c +5 -3
index 18f5f2b..e17daf8 100644
@@ -1512,6 +1512,7 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
 	struct ll_sa_entry       *entry;
 	struct ptlrpc_thread     *thread;
 	struct l_wait_info	lwi   = { 0 };
+	struct task_struct *task;
 	int		       rc    = 0;
 	struct ll_inode_info     *plli;
 
@@ -1670,10 +1671,11 @@ int do_statahead_enter(struct inode *dir, struct dentry **dentryp,
 	lli->lli_sai = sai;
 
 	plli = ll_i2info(d_inode(parent));
-	rc = PTR_ERR(kthread_run(ll_statahead_thread, parent,
-				 "ll_sa_%u", plli->lli_opendir_pid));
+	task = kthread_run(ll_statahead_thread, parent, "ll_sa_%u",
+			   plli->lli_opendir_pid);
 	thread = &sai->sai_thread;
-	if (IS_ERR_VALUE(rc)) {
+	if (IS_ERR(task)) {
+		rc = PTR_ERR(task);
 		CERROR("can't start ll_sa thread, rc: %d\n", rc);
 		dput(parent);
 		lli->lli_opendir_key = NULL;
drivers/staging/lustre/lustre/mdc/mdc_request.c +12 -6
index 294c050..ef25ccd 100644
@@ -1560,6 +1560,7 @@ static int mdc_ioc_changelog_send(struct obd_device *obd,
 				  struct ioc_changelog *icc)
 {
 	struct changelog_show *cs;
+	struct task_struct *task;
 	int rc;
 
 	/* Freed in mdc_changelog_send_thread */
@@ -1577,15 +1578,20 @@ static int mdc_ioc_changelog_send(struct obd_device *obd,
 	 * New thread because we should return to user app before
 	 * writing into our pipe
 	 */
-	rc = PTR_ERR(kthread_run(mdc_changelog_send_thread, cs,
-				 "mdc_clg_send_thread"));
-	if (!IS_ERR_VALUE(rc)) {
-		CDEBUG(D_CHANGELOG, "start changelog thread\n");
-		return 0;
+	task = kthread_run(mdc_changelog_send_thread, cs,
+			   "mdc_clg_send_thread");
+	if (IS_ERR(task)) {
+		rc = PTR_ERR(task);
+		CERROR("%s: can't start changelog thread: rc = %d\n",
+		       obd->obd_name, rc);
+		kfree(cs);
+	} else {
+		rc = 0;
+		CDEBUG(D_CHANGELOG, "%s: started changelog thread\n",
+		       obd->obd_name);
 	}
 
 	CERROR("Failed to start changelog thread: %d\n", rc);
-	kfree(cs);
 	return rc;
 }
 
drivers/staging/lustre/lustre/mgc/mgc_request.c +5 -4
index 2c48847..1395a1a 100644
@@ -711,6 +711,7 @@ static int mgc_cleanup(struct obd_device *obd)
 static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 {
 	struct lprocfs_static_vars lvars = { NULL };
+	struct task_struct *task;
 	int rc;
 
 	ptlrpcd_addref();
@@ -734,10 +735,10 @@ static int mgc_setup(struct obd_device *obd, struct lustre_cfg *lcfg)
 		init_waitqueue_head(&rq_waitq);
 
 		/* start requeue thread */
-		rc = PTR_ERR(kthread_run(mgc_requeue_thread, NULL,
-					     "ll_cfg_requeue"));
-		if (IS_ERR_VALUE(rc)) {
-			CERROR("%s: Cannot start requeue thread (%d),no more log updates!\n",
+		task = kthread_run(mgc_requeue_thread, NULL, "ll_cfg_requeue");
+		if (IS_ERR(task)) {
+			rc = PTR_ERR(task);
+			CERROR("%s: cannot start requeue thread: rc = %d; no more log updates\n",
 			       obd->obd_name, rc);
 			goto err_cleanup;
 		}
drivers/staging/lustre/lustre/obdclass/llog.c +8 -5
index 7cb55ef..741c258 100644
@@ -376,17 +376,19 @@ int llog_process_or_fork(const struct lu_env *env,
 	lpi->lpi_catdata   = catdata;
 
 	if (fork) {
+		struct task_struct *task;
+
 		/* The new thread can't use parent env,
 		 * init the new one in llog_process_thread_daemonize. */
 		lpi->lpi_env = NULL;
 		init_completion(&lpi->lpi_completion);
-		rc = PTR_ERR(kthread_run(llog_process_thread_daemonize, lpi,
-					     "llog_process_thread"));
-		if (IS_ERR_VALUE(rc)) {
+		task = kthread_run(llog_process_thread_daemonize, lpi,
+				   "llog_process_thread");
+		if (IS_ERR(task)) {
+			rc = PTR_ERR(task);
 			CERROR("%s: cannot start thread: rc = %d\n",
 			       loghandle->lgh_ctxt->loc_obd->obd_name, rc);
-			kfree(lpi);
-			return rc;
+			goto out_lpi;
 		}
 		wait_for_completion(&lpi->lpi_completion);
 	} else {
@@ -394,6 +396,7 @@ int llog_process_or_fork(const struct lu_env *env,
 		llog_process_thread(lpi);
 	}
 	rc = lpi->lpi_rc;
+out_lpi:
 	kfree(lpi);
 	return rc;
 }
drivers/staging/lustre/lustre/ptlrpc/pinger.c +6 -4
index 5c719f1..a94265a 100644
@@ -293,6 +293,7 @@ static struct ptlrpc_thread pinger_thread;
 int ptlrpc_start_pinger(void)
 {
 	struct l_wait_info lwi = { 0 };
+	struct task_struct *task;
 	int rc;
 
 	if (!thread_is_init(&pinger_thread) &&
@@ -303,10 +304,11 @@ int ptlrpc_start_pinger(void)
 
 	strcpy(pinger_thread.t_name, "ll_ping");
 
-	rc = PTR_ERR(kthread_run(ptlrpc_pinger_main, &pinger_thread,
-				 "%s", pinger_thread.t_name));
-	if (IS_ERR_VALUE(rc)) {
-		CERROR("cannot start thread: %d\n", rc);
+	task = kthread_run(ptlrpc_pinger_main, &pinger_thread,
+			   pinger_thread.t_name);
+	if (IS_ERR(task)) {
+		rc = PTR_ERR(task);
+		CERROR("cannot start pinger thread: rc = %d\n", rc);
 		return rc;
 	}
 	l_wait_event(pinger_thread.t_ctl_waitq,
drivers/staging/lustre/lustre/ptlrpc/service.c +17 -12
index f45898f..5d02055 100644
@@ -2255,24 +2255,27 @@ static int ptlrpc_start_hr_threads(void)
 
 		for (j = 0; j < hrp->hrp_nthrs; j++) {
 			struct	ptlrpc_hr_thread *hrt = &hrp->hrp_thrs[j];
+			struct task_struct *task;
 
-			rc = PTR_ERR(kthread_run(ptlrpc_hr_main,
+			task = kthread_run(ptlrpc_hr_main,
 						 &hrp->hrp_thrs[j],
 						 "ptlrpc_hr%02d_%03d",
 						 hrp->hrp_cpt,
-						 hrt->hrt_id));
-			if (IS_ERR_VALUE(rc))
+						 hrt->hrt_id);
+			if (IS_ERR(task)) {
+				rc = PTR_ERR(task);
 				break;
+			}
 		}
 		wait_event(ptlrpc_hr.hr_waitq,
 			       atomic_read(&hrp->hrp_nstarted) == j);
-		if (!IS_ERR_VALUE(rc))
-			continue;
 
-		CERROR("Reply handling thread %d:%d Failed on starting: rc = %d\n",
-		       i, j, rc);
-		ptlrpc_stop_hr_threads();
-		return rc;
+		if (rc < 0) {
+			CERROR("cannot start reply handler thread %d:%d: rc = %d\n",
+			       i, j, rc);
+			ptlrpc_stop_hr_threads();
+			return rc;
+		}
 	}
 	return 0;
 }
@@ -2374,6 +2377,7 @@ int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait)
 	struct l_wait_info lwi = { 0 };
 	struct ptlrpc_thread *thread;
 	struct ptlrpc_service *svc;
+	struct task_struct *task;
 	int rc;
 
 	LASSERT(svcpt != NULL);
@@ -2442,9 +2446,10 @@ int ptlrpc_start_thread(struct ptlrpc_service_part *svcpt, int wait)
 	}
 
 	CDEBUG(D_RPCTRACE, "starting thread '%s'\n", thread->t_name);
-	rc = PTR_ERR(kthread_run(ptlrpc_main, thread, "%s", thread->t_name));
-	if (IS_ERR_VALUE(rc)) {
-		CERROR("cannot start thread '%s': rc %d\n",
+	task = kthread_run(ptlrpc_main, thread, "%s", thread->t_name);
+	if (IS_ERR(task)) {
+		rc = PTR_ERR(task);
+		CERROR("cannot start thread '%s': rc = %d\n",
 		       thread->t_name, rc);
 		spin_lock(&svcpt->scp_lock);
 		--svcpt->scp_nthrs_starting;
Signature · 1 line
1.7.1
#10 lore raw

Re: [PATCH 06/40] staging: lustre: remove uses of IS_ERR_VALUE()

Quoted 17 lines · James Simmons
drivers/staging/lustre/lustre/mdc/mdc_request.c +8 -5
@@ -1577,15 +1578,20 @@ static int mdc_ioc_changelog_send(struct obd_device *obd,
 	 * New thread because we should return to user app before
 	 * writing into our pipe
 	 */
-	rc = PTR_ERR(kthread_run(mdc_changelog_send_thread, cs,
-				 "mdc_clg_send_thread"));
-	if (!IS_ERR_VALUE(rc)) {
-		CDEBUG(D_CHANGELOG, "start changelog thread\n");
-		return 0;
+	task = kthread_run(mdc_changelog_send_thread, cs,
+			   "mdc_clg_send_thread");
+	if (IS_ERR(task)) {
+		rc = PTR_ERR(task);
+		CERROR("%s: can't start changelog thread: rc = %d\n",
+		       obd->obd_name, rc);
+		kfree(cs);
+	} else {

drivers/staging/lustre/lustre/mdc/mdc_request.c static int mdc_ioc_changelog_send(struct obd_device *obd, · line 1597

Quoted 10 lines
drivers/staging/lustre/lustre/mdc/mdc_request.c +3 -1
+		rc = 0;
+		CDEBUG(D_CHANGELOG, "%s: started changelog thread\n",
+		       obd->obd_name);
 	}
 
 	CERROR("Failed to start changelog thread: %d\n", rc);
-	kfree(cs);
 	return rc;
 }
 

This will print an error when it succeeds.

It better to keep the error path and the success path as separate as possible. For the normal case, the success path is at indent level 1 and the fail path is at indent level 2. Like this:

	ret = one();
	if (ret)
		return ret;
	ret = two();
	if (ret)
		return ret;

	return 0;

When it's written that way it is:

	success;
	if (ret)
		fail_path;

	success;
	if (ret)
		fail_path;
	success;

The current code looks like:

	success;
	if (ret) {
		fail;
	} else {
		success;
	}
	mixed;

You see what I mean? Ideally the function should look like a list of directives in a row at indent level 1 with only minimal indenting for errors.

regards,
dan carpenter

#11 lore raw

PATCH 7/40 staging: lustre: return +ve for blocked lnet message

In reply to James Simmons

From: Liang Zhen <[email protected]>

returned value of lnet_post_send_locked and lnet_post_routed_recv_locked are changed to -ve by:
http://review.whamcloud.com/#/c/9369/

this is wrong because callers rely on +ve to identify blocked message which is not a failure.

To respect linux kernel coding style and not use positive error code, this patch adds two macros as non-error returned values of these functions:
LNET_CREDIT_OK has credit for message
LNET_CREDIT_WAIT no credit and message is blocked

both these functions will return these two values instead of 0 and EAGAIN

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5151
Reviewed-on: http://review.whamcloud.com/10625

---
 drivers/staging/lustre/lnet/lnet/lib-move.c |   51 +++++++++++++++++----------
 1 files changed, 32 insertions(+), 19 deletions(-)
drivers/staging/lustre/lnet/lnet/lib-move.c +32 -19
index 03fcddc..021a81d 100644
@@ -42,6 +42,11 @@
 
 #include "../../include/linux/lnet/lib-lnet.h"
 
+/** lnet message has credit and can be submitted to lnd for send/receive */
+#define LNET_CREDIT_OK		0
+/** lnet message is waiting for credit */
+#define LNET_CREDIT_WAIT	1
+
 static int local_nid_dist_zero = 1;
 module_param(local_nid_dist_zero, int, 0444);
 MODULE_PARM_DESC(local_nid_dist_zero, "Reserved");
@@ -777,10 +782,10 @@ lnet_peer_alive_locked(lnet_peer_t *lp)
  *	  lnet_send() is going to lnet_net_unlock immediately after this, so
  *	  it sets do_send FALSE and I don't do the unlock/send/lock bit.
  *
- * \retval 0 If \a msg sent or OK to send.
- * \retval EAGAIN If \a msg blocked for credit.
- * \retval EHOSTUNREACH If the next hop of the message appears dead.
- * \retval ECANCELED If the MD of the message has been unlinked.
+ * \retval LNET_CREDIT_OK If \a msg sent or OK to send.
+ * \retval LNET_CREDIT_WAIT If \a msg blocked for credit.
+ * \retval -EHOSTUNREACH If the next hop of the message appears dead.
+ * \retval -ECANCELED If the MD of the message has been unlinked.
  */
 static int
 lnet_post_send_locked(lnet_msg_t *msg, int do_send)
@@ -808,7 +813,7 @@ lnet_post_send_locked(lnet_msg_t *msg, int do_send)
 			lnet_finalize(ni, msg, -EHOSTUNREACH);
 
 		lnet_net_lock(cpt);
-		return EHOSTUNREACH;
+		return -EHOSTUNREACH;
 	}
 
 	if (msg->msg_md != NULL &&
@@ -821,7 +826,7 @@ lnet_post_send_locked(lnet_msg_t *msg, int do_send)
 			lnet_finalize(ni, msg, -ECANCELED);
 
 		lnet_net_lock(cpt);
-		return ECANCELED;
+		return -ECANCELED;
 	}
 
 	if (!msg->msg_peertxcredit) {
@@ -838,7 +843,7 @@ lnet_post_send_locked(lnet_msg_t *msg, int do_send)
 		if (lp->lp_txcredits < 0) {
 			msg->msg_tx_delayed = 1;
 			list_add_tail(&msg->msg_list, &lp->lp_txq);
-			return EAGAIN;
+			return LNET_CREDIT_WAIT;
 		}
 	}
 
@@ -855,7 +860,7 @@ lnet_post_send_locked(lnet_msg_t *msg, int do_send)
 		if (tq->tq_credits < 0) {
 			msg->msg_tx_delayed = 1;
 			list_add_tail(&msg->msg_list, &tq->tq_delayed);
-			return EAGAIN;
+			return LNET_CREDIT_WAIT;
 		}
 	}
 
@@ -864,7 +869,7 @@ lnet_post_send_locked(lnet_msg_t *msg, int do_send)
 		lnet_ni_send(ni, msg);
 		lnet_net_lock(cpt);
 	}
-	return 0;
+	return LNET_CREDIT_OK;
 }
 
 static lnet_rtrbufpool_t *
@@ -891,8 +896,10 @@ static int
 lnet_post_routed_recv_locked(lnet_msg_t *msg, int do_recv)
 {
 	/* lnet_parse is going to lnet_net_unlock immediately after this, so it
-	 * sets do_recv FALSE and I don't do the unlock/send/lock bit.  I
-	 * return EAGAIN if msg blocked and 0 if received or OK to receive */
+	 * sets do_recv FALSE and I don't do the unlock/send/lock bit.
+	 * I return LNET_CREDIT_WAIT if msg blocked and LNET_CREDIT_OK if
+	 * received or OK to receive
+	 */
 	lnet_peer_t *lp = msg->msg_rxpeer;
 	lnet_rtrbufpool_t *rbp;
 	lnet_rtrbuf_t *rb;
@@ -921,7 +928,7 @@ lnet_post_routed_recv_locked(lnet_msg_t *msg, int do_recv)
 			LASSERT(msg->msg_rx_ready_delay);
 			msg->msg_rx_delayed = 1;
 			list_add_tail(&msg->msg_list, &lp->lp_rtrq);
-			return EAGAIN;
+			return LNET_CREDIT_WAIT;
 		}
 	}
 
@@ -941,7 +948,7 @@ lnet_post_routed_recv_locked(lnet_msg_t *msg, int do_recv)
 			LASSERT(msg->msg_rx_ready_delay);
 			msg->msg_rx_delayed = 1;
 			list_add_tail(&msg->msg_list, &rbp->rbp_msgs);
-			return EAGAIN;
+			return LNET_CREDIT_WAIT;
 		}
 	}
 
@@ -960,7 +967,7 @@ lnet_post_routed_recv_locked(lnet_msg_t *msg, int do_recv)
 			     0, msg->msg_len, msg->msg_len);
 		lnet_net_lock(cpt);
 	}
-	return 0;
+	return LNET_CREDIT_OK;
 }
 
 void
@@ -1340,13 +1347,13 @@ lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid)
 	rc = lnet_post_send_locked(msg, 0);
 	lnet_net_unlock(cpt);
 
-	if (rc == EHOSTUNREACH || rc == ECANCELED)
-		return -rc;
+	if (rc < 0)
+		return rc;
 
-	if (rc == 0)
+	if (rc == LNET_CREDIT_OK)
 		lnet_ni_send(src_ni, msg);
 
-	return 0; /* rc == 0 or EAGAIN */
+	return 0; /* rc == LNET_CREDIT_OK or LNET_CREDIT_WAIT */
 }
 
 static void
@@ -1608,6 +1615,11 @@ lnet_parse_ack(lnet_ni_t *ni, lnet_msg_t *msg)
 	return 0;
 }
 
+/**
+ * \retval LNET_CREDIT_OK	If \a msg is forwarded
+ * \retval LNET_CREDIT_WAIT	If \a msg is blocked because w/o buffer
+ * \retval -ve			error code
+ */
 static int
 lnet_parse_forward_locked(lnet_ni_t *ni, lnet_msg_t *msg)
 {
@@ -1897,7 +1909,8 @@ lnet_parse(lnet_ni_t *ni, lnet_hdr_t *hdr, lnet_nid_t from_nid,
 
 		if (rc < 0)
 			goto free_drop;
-		if (rc == 0) {
+
+		if (rc == LNET_CREDIT_OK) {
 			lnet_ni_recv(ni, msg->msg_private, msg, 0,
 				     0, payload_length, payload_length);
 		}
Signature · 1 line
1.7.1
#12 lore raw

PATCH 8/40 staging: lustre: do not memset after LIBCFS_ALLOC

In reply to James Simmons

From: Frank Zago <[email protected]>

LIBCFS_ALLOC already zero out the memory allocated, so there is no need to zero out the memory again.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5304
Reviewed-on: http://review.whamcloud.com/11012

---
 .../staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c    |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
drivers/staging/lustre/lnet/klnds/o2iblnd/o2iblnd.c +0 -2
index 0f4154c..f3cbc3b 100644
@@ -335,8 +335,6 @@ int kiblnd_create_peer(lnet_ni_t *ni, kib_peer_t **peerp, lnet_nid_t nid)
 		return -ENOMEM;
 	}
 
-	memset(peer, 0, sizeof(*peer));	 /* zero flags etc */
-
 	peer->ibp_ni = ni;
 	peer->ibp_nid = nid;
 	peer->ibp_error = 0;
Signature · 1 line
1.7.1
#13 lore raw

PATCH 9/40 staging: lustre: Dynamic LNet Configuration (DLC)

In reply to James Simmons

From: Amir Shehata <[email protected]>

This is the first patch of a set of patches that enables DLC.

This patch adds some cleanup in the config.c as well as some preparatory changes in peer.c to enable dynamic network configuration

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2456
Change-Id: I8c8bbf3b55acf4d76f22a8be587b553a70d31889
Reviewed-on: http://review.whamcloud.com/9830

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    2 +-
 .../staging/lustre/include/linux/lnet/lib-types.h  |    5 +-
 drivers/staging/lustre/lnet/lnet/api-ni.c          |    8 +-
 drivers/staging/lustre/lnet/lnet/config.c          |   29 ++++-
 drivers/staging/lustre/lnet/lnet/peer.c            |  134 ++++++++++++++------
 5 files changed, 124 insertions(+), 54 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +1 -1
index 09c6bfe..1e0b236 100644
@@ -685,7 +685,7 @@ int lnet_parse_networks(struct list_head *nilist, char *networks);
 int lnet_nid2peer_locked(lnet_peer_t **lpp, lnet_nid_t nid, int cpt);
 lnet_peer_t *lnet_find_peer_locked(struct lnet_peer_table *ptable,
 				   lnet_nid_t nid);
-void lnet_peer_tables_cleanup(void);
+void lnet_peer_tables_cleanup(lnet_ni_t *ni);
 void lnet_peer_tables_destroy(void);
 int lnet_peer_tables_create(void);
 void lnet_debug_peer(lnet_nid_t nid);
drivers/staging/lustre/include/linux/lnet/lib-types.h +2 -3
index d792c4a..39381d9 100644
@@ -343,6 +343,8 @@ typedef struct lnet_peer {
 struct lnet_peer_table {
 	int			 pt_version;	/* /proc validity stamp */
 	int			 pt_number;	/* # peers extant */
+	/* # zombies to go to deathrow (and not there yet) */
+	int			 pt_zombies;
 	struct list_head	 pt_deathrow;	/* zombie peers */
 	struct list_head	*pt_hash;	/* NID->peer hash */
 };
@@ -600,9 +602,6 @@ typedef struct {
 	/* registered LNDs */
 	struct list_head		  ln_lnds;
 
-	/* space for network names */
-	char				 *ln_network_tokens;
-	int				  ln_network_tokens_nob;
 	/* test protocol compatibility flags */
 	int				  ln_testprotocompat;
 
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -7
index 284150f..f3c9937 100644
@@ -882,7 +882,7 @@ lnet_shutdown_lndnis(void)
 
 	/* Clear the peer table and wait for all peers to go (they hold refs on
 	 * their NIs) */
-	lnet_peer_tables_cleanup();
+	lnet_peer_tables_cleanup(NULL);
 
 	lnet_net_lock(LNET_LOCK_EX);
 	/* Now wait for the NI's I just nuked to show up on ln_zombie_nis
@@ -939,12 +939,6 @@ lnet_shutdown_lndnis(void)
 
 	the_lnet.ln_shutdown = 0;
 	lnet_net_unlock(LNET_LOCK_EX);
-
-	if (the_lnet.ln_network_tokens != NULL) {
-		LIBCFS_FREE(the_lnet.ln_network_tokens,
-			    the_lnet.ln_network_tokens_nob);
-		the_lnet.ln_network_tokens = NULL;
-	}
 }
 
 static int
drivers/staging/lustre/lnet/lnet/config.c +25 -4
index 867c96e..7bb140b 100644
@@ -96,6 +96,8 @@ lnet_net_unique(__u32 net, struct list_head *nilist)
 void
 lnet_ni_free(struct lnet_ni *ni)
 {
+	int i;
+
 	if (ni->ni_refs != NULL)
 		cfs_percpt_free(ni->ni_refs);
 
@@ -105,6 +107,10 @@ lnet_ni_free(struct lnet_ni *ni)
 	if (ni->ni_cpts != NULL)
 		cfs_expr_list_values_free(ni->ni_cpts, ni->ni_ncpts);
 
+	for (i = 0; i < LNET_MAX_INTERFACES && ni->ni_interfaces[i]; i++) {
+		LIBCFS_FREE(ni->ni_interfaces[i],
+			    strlen(ni->ni_interfaces[i]) + 1);
+	}
 	LIBCFS_FREE(ni, sizeof(*ni));
 }
 
@@ -199,8 +205,6 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 		return -ENOMEM;
 	}
 
-	the_lnet.ln_network_tokens = tokens;
-	the_lnet.ln_network_tokens_nob = tokensize;
 	memcpy(tokens, networks, tokensize);
 	str = tmp = tokens;
 
@@ -319,7 +323,23 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 				goto failed;
 			}
 
-			ni->ni_interfaces[niface++] = iface;
+			/*
+			 * Allocate a separate piece of memory and copy
+			 * into it the string, so we don't have
+			 * a depencency on the tokens string.  This way we
+			 * can free the tokens at the end of the function.
+			 * The newly allocated ni_interfaces[] can be
+			 * freed when freeing the NI
+			 */
+			LIBCFS_ALLOC(ni->ni_interfaces[niface],
+				     strlen(iface) + 1);
+			if (!ni->ni_interfaces[niface]) {
+				CERROR("Can't allocate net interface name\n");
+				goto failed;
+			}
+			strncpy(ni->ni_interfaces[niface], iface,
+				strlen(iface));
+			niface++;
 			iface = comma;
 		} while (iface != NULL);
 
@@ -344,6 +364,8 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 	}
 
 	LASSERT(!list_empty(nilist));
+
+	LIBCFS_FREE(tokens, tokensize);
 	return 0;
 
  failed_syntax:
@@ -360,7 +382,6 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 		cfs_expr_list_free(el);
 
 	LIBCFS_FREE(tokens, tokensize);
-	the_lnet.ln_network_tokens = NULL;
 
 	return -EINVAL;
 }
drivers/staging/lustre/lnet/lnet/peer.c +95 -39

163 lines not on this page · raw message

Signature · 1 line
1.7.1
#14 lore raw

PATCH 10/40 staging: lustre: Dynamic LNet Configuration (DLC) dynamic routing

In reply to James Simmons

From: Amir Shehata <[email protected]>

This is the second patch of a set of patches that enables DLC.

This patch adds the following features to LNET. Currently these features are not driven by user space.
- Enabling Routing on Demand. The default number of router buffers are allocated.
- Disable Routing on demand. Unused router buffers are freed and used router buffers are freed when they are no longer in use. The following time routing is enabled the default router buffer values are used. It has been decided that remembering the user set router buffer values should be remembered and re-set by user space scripts.
- Increase the number of router buffers on demand, by allocating new ones.
- Decrease the number of router buffers. Exccess buffers are freed if they are not in use. Otherwise they are freed once they are no longer in use.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2456
Change-Id: Id07d4ad424d8f5ba72475d4149380afe2ac54e77
Reviewed-on: http://review.whamcloud.com/9831

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    8 +-
 .../staging/lustre/include/linux/lnet/lib-types.h  |    8 +-
 drivers/staging/lustre/lnet/lnet/api-ni.c          |    4 +-
 drivers/staging/lustre/lnet/lnet/lib-move.c        |   89 +++++--
 drivers/staging/lustre/lnet/lnet/router.c          |  276 +++++++++++++++-----
 5 files changed, 304 insertions(+), 81 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +7 -1
index 1e0b236..60accdf 100644
@@ -459,7 +459,11 @@ int lnet_get_route(int idx, __u32 *net, __u32 *hops,
 void lnet_router_debugfs_init(void);
 void lnet_router_debugfs_fini(void);
 int  lnet_rtrpools_alloc(int im_a_router);
-void lnet_rtrpools_free(void);
+void lnet_destroy_rtrbuf(lnet_rtrbuf_t *rb, int npages);
+int lnet_rtrpools_adjust(int tiny, int small, int large);
+int lnet_rtrpools_enable(void);
+void lnet_rtrpools_disable(void);
+void lnet_rtrpools_free(int keep_pools);
 lnet_remotenet_t *lnet_find_net_locked(__u32 net);
 
 int lnet_islocalnid(lnet_nid_t nid);
@@ -479,6 +483,8 @@ void lnet_prep_send(lnet_msg_t *msg, int type, lnet_process_id_t target,
 int lnet_send(lnet_nid_t nid, lnet_msg_t *msg, lnet_nid_t rtr_nid);
 void lnet_return_tx_credits_locked(lnet_msg_t *msg);
 void lnet_return_rx_credits_locked(lnet_msg_t *msg);
+void lnet_schedule_blocked_locked(lnet_rtrbufpool_t *rbp);
+void lnet_drop_routed_msgs_locked(struct list_head *list, int cpt);
 
 /* portals functions */
 /* portals attributes */
drivers/staging/lustre/include/linux/lnet/lib-types.h +7 -1
index 39381d9..e7585b9 100644
@@ -277,6 +277,7 @@ typedef struct lnet_ni {
 #define LNET_PING_FEAT_INVAL		(0)		/* no feature */
 #define LNET_PING_FEAT_BASE		(1 << 0)	/* just a ping */
 #define LNET_PING_FEAT_NI_STATUS	(1 << 1)	/* return NI status */
+#define LNET_PING_FEAT_RTE_DISABLED	(1 << 2)	/* Routing enabled */
 
 #define LNET_PING_FEAT_MASK		(LNET_PING_FEAT_BASE | \
 					 LNET_PING_FEAT_NI_STATUS)
@@ -400,7 +401,12 @@ typedef struct {
 
 #define LNET_PEER_HASHSIZE	503	/* prime! */
 
-#define LNET_NRBPOOLS		3	/* # different router buffer pools */
+#define LNET_TINY_BUF_IDX	0
+#define LNET_SMALL_BUF_IDX	1
+#define LNET_LARGE_BUF_IDX	2
+
+/* # different router buffer pools */
+#define LNET_NRBPOOLS		(LNET_LARGE_BUF_IDX + 1)
 
 enum {
 	/* Didn't match anything */
drivers/staging/lustre/lnet/lnet/api-ni.c +3 -1
index f3c9937..0338537 100644
@@ -632,7 +632,7 @@ lnet_unprepare(void)
 
 	lnet_msg_containers_destroy();
 	lnet_peer_tables_destroy();
-	lnet_rtrpools_free();
+	lnet_rtrpools_free(0);
 
 	if (the_lnet.ln_counters != NULL) {
 		cfs_percpt_free(the_lnet.ln_counters);
@@ -1515,6 +1515,8 @@ lnet_create_ping_info(void)
 	pinfo->pi_pid     = the_lnet.ln_pid;
 	pinfo->pi_magic   = LNET_PROTO_PING_MAGIC;
 	pinfo->pi_features = LNET_PING_FEAT_NI_STATUS;
+	if (!the_lnet.ln_routing)
+		pinfo->pi_features |= LNET_PING_FEAT_RTE_DISABLED;
 
 	for (i = 0; i < n; i++) {
 		lnet_ni_status_t *ns = &pinfo->pi_ni[i];
drivers/staging/lustre/lnet/lnet/lib-move.c +73 -16

137 lines not on this page · raw message

drivers/staging/lustre/lnet/lnet/router.c +214 -62

435 lines not on this page · raw message

Signature · 1 line
1.7.1
#15 lore raw

PATCH 11/40 staging: lustre: DLC Feature dynamic net config

In reply to James Simmons

From: Amir Shehata <[email protected]>

This is the third patch of a set of patches that enables DLC.

This patch adds the following features to LNET. Currently these features are not driven by user space.
- Adding/Deleting Networks dynamically
Two new functions were added:
- lnet_dyn_add_ni()
add an NI. if the NI is already added then fail with appropriate error code
- lnet_dyn_del_ni()
delete an existing NI. If NI doesn't exist fail with appropriate failure code.
These functions shall be called from IOCTL.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2456
Reviewed-on: http://review.whamcloud.com/9832

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    3 +-
 drivers/staging/lustre/lnet/lnet/api-ni.c          |  795 +++++++++++++-------
 drivers/staging/lustre/lnet/lnet/config.c          |    2 +-
 3 files changed, 517 insertions(+), 283 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +1 -2
index 60accdf..94d0dc5 100644
@@ -679,14 +679,13 @@ void lnet_router_checker_stop(void);
 void lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net);
 void lnet_swap_pinginfo(lnet_ping_info_t *info);
 
-int lnet_ping_target_init(void);
-void lnet_ping_target_fini(void);
 int lnet_ping(lnet_process_id_t id, int timeout_ms,
 	      lnet_process_id_t *ids, int n_ids);
 
 int lnet_parse_ip2nets(char **networksp, char *ip2nets);
 int lnet_parse_routes(char *route_str, int *im_a_router);
 int lnet_parse_networks(struct list_head *nilist, char *networks);
+int lnet_net_unique(__u32 net, struct list_head *nilist);
 
 int lnet_nid2peer_locked(lnet_peer_t **lpp, lnet_nid_t nid, int cpt);
 lnet_peer_t *lnet_find_peer_locked(struct lnet_peer_table *ptable,
drivers/staging/lustre/lnet/lnet/api-ni.c +515 -280

973 lines not on this page · raw message

drivers/staging/lustre/lnet/lnet/config.c +1 -1
index 7bb140b..1c7ad7c 100644
@@ -77,7 +77,7 @@ lnet_issep(char c)
 	}
 }
 
-static int
+int
 lnet_net_unique(__u32 net, struct list_head *nilist)
 {
 	struct list_head *tmp;
Signature · 1 line
1.7.1
#16 lore raw

Re: [PATCH 11/40] staging: lustre: DLC Feature dynamic net config

drivers/staging/lustre/lnet/lnet/api-ni.c LNetNIInit(lnet_pid_t requested_pid) · line 1604

Quoted 13 lines · James Simmons
drivers/staging/lustre/lnet/lnet/api-ni.c +7 -2
+
+	return 0;
 
  failed4:
-	lnet_ping_target_fini();
- failed3:
 	the_lnet.ln_refcount = 0;
+	lnet_ping_md_unlink(pinfo, &md_handle);
+	lnet_ping_info_free(pinfo);
+ failed3:
 	lnet_acceptor_stop();
+	rc = LNetEQFree(the_lnet.ln_ping_target_eq);
+	LASSERT(rc == 0);
        ^^^^^^^^^^^^^^^^

drivers/staging/lustre/lnet/lnet/api-ni.c LNetNIInit(lnet_pid_t requested_pid) · line 1611

Quoted 7 lines

failed2:

drivers/staging/lustre/lnet/lnet/api-ni.c +0 -0
 	lnet_destroy_routes();
 	lnet_shutdown_lndnis();
@@ -1263,8 +1609,12 @@ LNetNIInit(lnet_pid_t requested_pid)
 	lnet_unprepare();
  failed0:
 	LASSERT(rc < 0);
        ^^^^^^^^^^^^^^^

These asserts contradict each other.

But mostly please remove all the GW-BASIC style numbered labeled names from this patch. You wouldn't name your variables "int var1, var2, var3" so for label names you should give them meaningful names as well. Don't name them after the goto location, name them after the label location to say the first thing that the label does.

err_fini:
err_acceptor_stop:
err_destroy_routes:
err_empty_list:

regards,
dan carpenter

#17 lore raw

PATCH 12/40 staging: lustre: Dynamic LNet Configuration (DLC) IOCTL changes

In reply to James Simmons

From: Amir Shehata <[email protected]>

This is the fourth patch of a set of patches that enables DLC.

This patch changes the IOCTL infrastructure in preparation of adding extra IOCTL communication between user and kernel space. The changes include:
- adding a common header to be passed to ioctl infra functions instead of passing an exact structure. This header is meant to be included in all structures to be passed through that interface. The IOCTL handler casts this header to a particular type that it expects
- All sanity testing on the past in structure is performed in the generic ioctl infrastructure code.
- All ioctl handlers changed to take the header instead of a particular structure type

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2456
Change-Id: I144706a14293637cd5f381d2c020faa0e9c21f6b
Reviewed-on: http://review.whamcloud.com/8021

---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h     |   29 +++++----
 drivers/staging/lustre/lnet/lnet/module.c          |    4 +-
 drivers/staging/lustre/lnet/selftest/conctl.c      |    9 ++-
 drivers/staging/lustre/lnet/selftest/console.c     |    2 +-
 drivers/staging/lustre/lnet/selftest/console.h     |    1 -
 .../lustre/lustre/libcfs/linux/linux-module.c      |   60 +++++++++----------
 drivers/staging/lustre/lustre/libcfs/module.c      |   50 ++++++++++++----
 7 files changed, 91 insertions(+), 64 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +16 -13
index 485ab26..e14788c 100644
@@ -43,9 +43,13 @@
 
 #define LIBCFS_IOCTL_VERSION 0x0001000a
 
-struct libcfs_ioctl_data {
+struct libcfs_ioctl_hdr {
 	__u32 ioc_len;
 	__u32 ioc_version;
+};
+
+struct libcfs_ioctl_data {
+	struct libcfs_ioctl_hdr ioc_hdr;
 
 	__u64 ioc_nid;
 	__u64 ioc_u64[1];
@@ -70,11 +74,6 @@ struct libcfs_ioctl_data {
 
 #define ioc_priority ioc_u32[0]
 
-struct libcfs_ioctl_hdr {
-	__u32 ioc_len;
-	__u32 ioc_version;
-};
-
 struct libcfs_debug_ioctl_data {
 	struct libcfs_ioctl_hdr hdr;
 	unsigned int subs;
@@ -84,13 +83,13 @@ struct libcfs_debug_ioctl_data {
 #define LIBCFS_IOC_INIT(data)			   \
 do {						    \
 	memset(&data, 0, sizeof(data));		 \
-	data.ioc_version = LIBCFS_IOCTL_VERSION;	\
-	data.ioc_len = sizeof(data);		    \
+	data.ioc_hdr.ioc_version = LIBCFS_IOCTL_VERSION;	\
+	data.ioc_hdr.ioc_len = sizeof(data);			\
 } while (0)
 
 struct libcfs_ioctl_handler {
 	struct list_head item;
-	int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_data *data);
+	int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
 };
 
 #define DECLARE_IOCTL_HANDLER(ident, func)		      \
@@ -149,9 +148,9 @@ static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
 	return len;
 }
 
-static inline int libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
+static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
 {
-	if (data->ioc_len > (1<<30)) {
+	if (data->ioc_hdr.ioc_len > (1 << 30)) {
 		CERROR("LIBCFS ioctl: ioc_len larger than 1<<30\n");
 		return 1;
 	}
@@ -187,7 +186,7 @@ static inline int libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
 		CERROR("LIBCFS ioctl: plen2 nonzero but no pbuf2 pointer\n");
 		return 1;
 	}
-	if ((__u32)libcfs_ioctl_packlen(data) != data->ioc_len) {
+	if ((__u32)libcfs_ioctl_packlen(data) != data->ioc_hdr.ioc_len) {
 		CERROR("LIBCFS ioctl: packlen != ioc_len\n");
 		return 1;
 	}
@@ -207,7 +206,11 @@ static inline int libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
 
 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
-int libcfs_ioctl_getdata(char *buf, char *end, void *arg);
+int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr *buf, __u32 buf_len,
+			 const void __user *arg);
+int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
+			     __u32 *buf_len);
 int libcfs_ioctl_popdata(void *arg, void *buf, int size);
+int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
 
 #endif /* __LIBCFS_IOCTL_H__ */
drivers/staging/lustre/lnet/lnet/module.c +2 -2
index ac2fdf0..0afdad0 100644
@@ -84,7 +84,7 @@ lnet_unconfigure(void)
 }
 
 static int
-lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
+lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
 {
 	int rc;
 
@@ -101,7 +101,7 @@ lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_data *data)
 		 * I'm called into it */
 		rc = LNetNIInit(LNET_PID_ANY);
 		if (rc >= 0) {
-			rc = LNetCtl(cmd, data);
+			rc = LNetCtl(cmd, hdr);
 			LNetNIFini();
 		}
 		return rc;
drivers/staging/lustre/lnet/selftest/conctl.c +7 -2
index 2ca7d0e..3dc8ea7 100644
@@ -814,15 +814,20 @@ out:
 }
 
 int
-lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data)
+lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
 {
 	char   *buf;
-	int     opc = data->ioc_u32[0];
+	struct libcfs_ioctl_data *data;
+	int     opc;
 	int     rc;
 
 	if (cmd != IOC_LIBCFS_LNETST)
 		return -EINVAL;
 
+	data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr);
+
+	opc = data->ioc_u32[0];
+
 	if (data->ioc_plen1 > PAGE_CACHE_SIZE)
 		return -EINVAL;
 
drivers/staging/lustre/lnet/selftest/console.c +1 -1
index 5619fc4..898912b 100644
@@ -1977,7 +1977,7 @@ static void lstcon_init_acceptor_service(void)
 	lstcon_acceptor_service.sv_wi_total = SFW_FRWK_WI_MAX;
 }
 
-extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
+extern int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
 
 static DECLARE_IOCTL_HANDLER(lstcon_ioctl_handler, lstcon_ioctl_entry);
 
drivers/staging/lustre/lnet/selftest/console.h +0 -1
index 3f3286c..7af3540 100644
@@ -184,7 +184,6 @@ lstcon_id2hash (lnet_process_id_t id, struct list_head *hash)
 }
 
 int lstcon_console_init(void);
-int lstcon_ioctl_entry(unsigned int cmd, struct libcfs_ioctl_data *data);
 int lstcon_console_fini(void);
 int lstcon_session_match(lst_sid_t sid);
 int lstcon_session_new(char *name, int key, unsigned version,
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +28 -32

79 lines not on this page · raw message

drivers/staging/lustre/lustre/libcfs/module.c +37 -13

91 lines not on this page · raw message

Signature · 1 line
1.7.1
#18 lore raw

Re: [PATCH 12/40] staging: lustre: Dynamic LNet Configuration (DLC) IOCTL changes

drivers/staging/lustre/lustre/libcfs/linux/linux-module.c line 74

Quoted 11 lines · James Simmons
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +5 -4
+int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
+			     __u32 *len)
+{
+	struct libcfs_ioctl_hdr hdr;
 
-	orig_len = hdr->ioc_len;
-	if (copy_from_user(buf, arg, hdr->ioc_len))
+	if (copy_from_user(&hdr, arg, sizeof(hdr)))
 		return -EFAULT;
-	if (orig_len != data->ioc_len)
-		return -EINVAL;

This check was actually important. I don't see where it was moved to so it looks like this patch introduces a serious information leak.

Quoted 16 lines
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +4 -7
-	if (libcfs_ioctl_is_invalid(data)) {
-		CERROR("PORTALS: ioctl not correctly formatted\n");
+	if (hdr.ioc_version != LIBCFS_IOCTL_VERSION) {
+		CERROR("LNET: version mismatch expected %#x, got %#x\n",
+		       LIBCFS_IOCTL_VERSION, hdr.ioc_version);
 		return -EINVAL;
 	}
 
-	if (data->ioc_inllen1)
-		data->ioc_inlbuf1 = &data->ioc_bulk[0];
+	*len = hdr.ioc_len;
 
-	if (data->ioc_inllen2)
-		data->ioc_inlbuf2 = &data->ioc_bulk[0] +
-			cfs_size_round(data->ioc_inllen1);

drivers/staging/lustre/lustre/libcfs/linux/linux-module.c line 85

Quoted 10 lines
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +7 -0
+	return 0;
+}
 
+int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr *buf, __u32 buf_len,
+			  const void __user *arg)
+{
+	if (copy_from_user(buf, arg, buf_len))
+		return -EFAULT;
 	return 0;
 }

Don't introduce this wrapper. Abstraction layers just make the code harder to read and obscures bugs. Also the caller changes -EFAULT to -EINVAL so right away it starts to be buggy.

Quoted 21 lines
drivers/staging/lustre/lustre/libcfs/module.c +3 -2
index 75247e9..5348699 100644
@@ -54,6 +54,8 @@
 
 # define DEBUG_SUBSYSTEM S_LNET
 
+#define LIBCFS_MAX_IOCTL_BUF_LEN 2048
+
 #include "../../include/linux/libcfs/libcfs.h"
 #include <asm/div64.h>
 
@@ -241,11 +243,21 @@ int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand)
 }
 EXPORT_SYMBOL(libcfs_deregister_ioctl);
 
-static int libcfs_ioctl_int(struct cfs_psdev_file *pfile, unsigned long cmd,
-			    void *arg, struct libcfs_ioctl_data *data)
+static int libcfs_ioctl_handle(struct cfs_psdev_file *pfile, unsigned long cmd,

drivers/staging/lustre/lustre/libcfs/module.c int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand) · line 256

Quoted 10 lines
drivers/staging/lustre/lustre/libcfs/module.c +7 -0
+			       void *arg, struct libcfs_ioctl_hdr *hdr)
 {
+	struct libcfs_ioctl_data *data = NULL;
 	int err = -EINVAL;
 
+	if ((cmd <= IOC_LIBCFS_LNETST) ||
+	    (cmd >= IOC_LIBCFS_REGISTER_MYNID)) {
+		data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr);
+		err = libcfs_ioctl_data_adjust(data);
+		if (err != 0) {

Generally, remove pointless double negatives like this. It should be just "if (err) " instead of "if (err != 0 != 0 != 0 != 0) " or whatever.

Quoted 8 lines
drivers/staging/lustre/lustre/libcfs/module.c +4 -0
+			return err;
+		}
+	}
+
 	switch (cmd) {
 	case IOC_LIBCFS_CLEAR_DEBUG:
 		libcfs_debug_clear_buffer();

drivers/staging/lustre/lustre/libcfs/module.c static int libcfs_ioctl_int(struct cfs_psdev_file *pfile, unsigned long cmd, · line 299

Quoted 10 lines
drivers/staging/lustre/lustre/libcfs/module.c +2 -2
@@ -280,11 +292,11 @@ static int libcfs_ioctl_int(struct cfs_psdev_file *pfile, unsigned long cmd,
 		err = -EINVAL;
 		down_read(&ioctl_list_sem);
 		list_for_each_entry(hand, &ioctl_list, item) {
-			err = hand->handle_ioctl(cmd, data);
+			err = hand->handle_ioctl(cmd, hdr);
 			if (err != -EINVAL) {
 				if (err == 0)
 					err = libcfs_ioctl_popdata(arg,
-							data, sizeof(*data));
+							hdr, hdr->ioc_len);

This variable has not been verified since the user wrote to it last so here is the information leak.

regards,
dan carpenter

#19 lore raw

PATCH 13/40 staging: lustre: Dynamic LNet Configuration (DLC) show command

In reply to James Simmons

From: Amir Shehata <[email protected]>

This is the fifth patch of a set of patches that enables DLC.

This patch adds the new structures which will be used in the IOCTL communication. It also added a set of show operations to show buffers, networks, statistics and peer information.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2456
Change-Id: I96e5cb3dcf07289c6cd1deb46f4acb3c263ae21e
Reviewed-on: http://review.whamcloud.com/8022

---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h     |   44 +++++++-
 .../staging/lustre/include/linux/lnet/lib-dlc.h    |  118 ++++++++++++++++++++
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    5 +
 drivers/staging/lustre/lnet/lnet/api-ni.c          |   47 +++++++-
 drivers/staging/lustre/lnet/lnet/module.c          |    4 +
 drivers/staging/lustre/lnet/lnet/peer.c            |   61 ++++++++++
 .../lustre/lustre/libcfs/linux/linux-module.c      |    3 +-
 drivers/staging/lustre/lustre/libcfs/module.c      |   15 ++-
 8 files changed, 282 insertions(+), 15 deletions(-)
 create mode 100644 drivers/staging/lustre/include/linux/lnet/lib-dlc.h
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +39 -5
index e14788c..f24330d 100644
@@ -41,7 +41,8 @@
 #ifndef __LIBCFS_IOCTL_H__
 #define __LIBCFS_IOCTL_H__
 
-#define LIBCFS_IOCTL_VERSION 0x0001000a
+#define LIBCFS_IOCTL_VERSION	0x0001000a
+#define LIBCFS_IOCTL_VERSION2	0x0001000b
 
 struct libcfs_ioctl_hdr {
 	__u32 ioc_len;
@@ -87,6 +88,13 @@ do {						    \
 	data.ioc_hdr.ioc_len = sizeof(data);			\
 } while (0)
 
+#define LIBCFS_IOC_INIT_V2(data, hdr)			\
+do {							\
+	memset(&(data), 0, sizeof(data));		\
+	(data).hdr.ioc_version = LIBCFS_IOCTL_VERSION2;	\
+	(data).hdr.ioc_len = sizeof(data);		\
+} while (0)
+
 struct libcfs_ioctl_handler {
 	struct list_head item;
 	int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
@@ -112,9 +120,6 @@ struct libcfs_ioctl_handler {
 /* lnet ioctls */
 #define IOC_LIBCFS_GET_NI		  _IOWR('e', 50, long)
 #define IOC_LIBCFS_FAIL_NID		_IOWR('e', 51, long)
-#define IOC_LIBCFS_ADD_ROUTE	       _IOWR('e', 52, long)
-#define IOC_LIBCFS_DEL_ROUTE	       _IOWR('e', 53, long)
-#define IOC_LIBCFS_GET_ROUTE	       _IOWR('e', 54, long)
 #define IOC_LIBCFS_NOTIFY_ROUTER	   _IOWR('e', 55, long)
 #define IOC_LIBCFS_UNCONFIGURE	     _IOWR('e', 56, long)
 #define IOC_LIBCFS_PORTALS_COMPATIBILITY   _IOWR('e', 57, long)
@@ -137,7 +142,36 @@ struct libcfs_ioctl_handler {
 #define IOC_LIBCFS_DEL_INTERFACE	   _IOWR('e', 79, long)
 #define IOC_LIBCFS_GET_INTERFACE	   _IOWR('e', 80, long)
 
-#define IOC_LIBCFS_MAX_NR			     80
+/*
+ * DLC Specific IOCTL numbers.
+ * In order to maintain backward compatibility with any possible external
+ * tools which might be accessing the IOCTL numbers, a new group of IOCTL
+ * number have been allocated.
+ */
+#define IOCTL_CONFIG_SIZE		struct lnet_ioctl_config_data
+#define IOC_LIBCFS_ADD_ROUTE		_IOWR(IOC_LIBCFS_TYPE, 81, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_DEL_ROUTE		_IOWR(IOC_LIBCFS_TYPE, 82, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_ROUTE		_IOWR(IOC_LIBCFS_TYPE, 83, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_ADD_NET		_IOWR(IOC_LIBCFS_TYPE, 84, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_DEL_NET		_IOWR(IOC_LIBCFS_TYPE, 85, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_NET		_IOWR(IOC_LIBCFS_TYPE, 86, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_CONFIG_RTR		_IOWR(IOC_LIBCFS_TYPE, 87, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_ADD_BUF		_IOWR(IOC_LIBCFS_TYPE, 88, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_BUF		_IOWR(IOC_LIBCFS_TYPE, 89, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_PEER_INFO	_IOWR(IOC_LIBCFS_TYPE, 90, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_LNET_STATS	_IOWR(IOC_LIBCFS_TYPE, 91, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_MAX_NR		91
 
 static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
 {
drivers/staging/lustre/include/linux/lnet/lib-dlc.h new file +118 -0

118 lines not on this page · raw message

drivers/staging/lustre/include/linux/lnet/lib-lnet.h +5 -0
index 94d0dc5..f2874e0 100644
@@ -694,6 +694,11 @@ void lnet_peer_tables_cleanup(lnet_ni_t *ni);
 void lnet_peer_tables_destroy(void);
 int lnet_peer_tables_create(void);
 void lnet_debug_peer(lnet_nid_t nid);
+int lnet_get_peers(int count, __u64 *nid, char *alivness,
+		   int *ncpt, int *refcount,
+		   int *ni_peer_tx_credits, int *peer_tx_credits,
+		   int *peer_rtr_credits, int *peer_min_rtr_credtis,
+		   int *peer_tx_qnob);
 
 static inline void
 lnet_peer_set_alive(lnet_peer_t *lp)
drivers/staging/lustre/lnet/lnet/api-ni.c +42 -5

70 lines not on this page · raw message

drivers/staging/lustre/lnet/lnet/module.c +4 -0
index 0afdad0..ffc5700 100644
@@ -36,6 +36,7 @@
 
 #define DEBUG_SUBSYSTEM S_LNET
 #include "../../include/linux/lnet/lib-lnet.h"
+#include "../../include/linux/lnet/lib-dlc.h"
 
 static int config_on_load;
 module_param(config_on_load, int, 0444);
@@ -95,6 +96,9 @@ lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
 	case IOC_LIBCFS_UNCONFIGURE:
 		return lnet_unconfigure();
 
+	case IOC_LIBCFS_ADD_NET:
+		return LNetCtl(cmd, hdr);
+
 	default:
 		/* Passing LNET_PID_ANY only gives me a ref if the net is up
 		 * already; I'll need it to ensure the net can't go down while
drivers/staging/lustre/lnet/lnet/peer.c +61 -0

70 lines not on this page · raw message

drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +2 -1
index ef1c247..1c31e2e 100644
@@ -65,7 +65,8 @@ int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
 	if (copy_from_user(&hdr, arg, sizeof(hdr)))
 		return -EFAULT;
 
-	if (hdr.ioc_version != LIBCFS_IOCTL_VERSION) {
+	if (hdr.ioc_version != LIBCFS_IOCTL_VERSION &&
+	    hdr.ioc_version != LIBCFS_IOCTL_VERSION2) {
 		CERROR("LNET: version mismatch expected %#x, got %#x\n",
 		       LIBCFS_IOCTL_VERSION, hdr.ioc_version);
 		return -EINVAL;
drivers/staging/lustre/lustre/libcfs/module.c +11 -4
index 5348699..992ff3c 100644
@@ -54,13 +54,15 @@
 
 # define DEBUG_SUBSYSTEM S_LNET
 
-#define LIBCFS_MAX_IOCTL_BUF_LEN 2048
+#define LNET_MAX_IOCTL_BUF_LEN (sizeof(struct lnet_ioctl_net_config) + \
+				sizeof(struct lnet_ioctl_config_data))
 
 #include "../../include/linux/libcfs/libcfs.h"
 #include <asm/div64.h>
 
 #include "../../include/linux/libcfs/libcfs_crypto.h"
 #include "../../include/linux/lnet/lib-lnet.h"
+#include "../../include/linux/lnet/lib-dlc.h"
 #include "../../include/linux/lnet/lnet.h"
 #include "tracefile.h"
 
@@ -249,8 +251,13 @@ static int libcfs_ioctl_handle(struct cfs_psdev_file *pfile, unsigned long cmd,
 	struct libcfs_ioctl_data *data = NULL;
 	int err = -EINVAL;
 
-	if ((cmd <= IOC_LIBCFS_LNETST) ||
-	    (cmd >= IOC_LIBCFS_REGISTER_MYNID)) {
+	/*
+	 * The libcfs_ioctl_data_adjust() function performs adjustment
+	 * operations on the libcfs_ioctl_data structure to make
+	 * it usable by the code.  This doesn't need to be called
+	 * for new data structures added.
+	 */
+	if (hdr->ioc_version == LIBCFS_IOCTL_VERSION) {
 		data = container_of(hdr, struct libcfs_ioctl_data, ioc_hdr);
 		err = libcfs_ioctl_data_adjust(data);
 		if (err != 0) {
@@ -322,7 +329,7 @@ static int libcfs_ioctl(struct cfs_psdev_file *pfile, unsigned long cmd, void *a
 	 * do a check here to restrict the size of the memory
 	 * to allocate to guard against DoS attacks.
 	 */
-	if (buf_len > LIBCFS_MAX_IOCTL_BUF_LEN) {
+	if (buf_len > LNET_MAX_IOCTL_BUF_LEN) {
 		CERROR("LNET: user buffer exceeds kernel buffer\n");
 		return -EINVAL;
 	}
Signature · 1 line
1.7.1
#20 lore raw

Re: [PATCH 13/40] staging: lustre: Dynamic LNet Configuration (DLC) show command

Quoted 44 lines · James Simmons

From: Amir Shehata <[email protected]>

This is the fifth patch of a set of patches that enables DLC.

This patch adds the new structures which will be used in the IOCTL communication. It also added a set of show operations to show buffers, networks, statistics and peer information.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2456
Change-Id: I96e5cb3dcf07289c6cd1deb46f4acb3c263ae21e
Reviewed-on: http://review.whamcloud.com/8022

---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h     |   44 +++++++-
 .../staging/lustre/include/linux/lnet/lib-dlc.h    |  118 ++++++++++++++++++++
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    5 +
 drivers/staging/lustre/lnet/lnet/api-ni.c          |   47 +++++++-
 drivers/staging/lustre/lnet/lnet/module.c          |    4 +
 drivers/staging/lustre/lnet/lnet/peer.c            |   61 ++++++++++
 .../lustre/lustre/libcfs/linux/linux-module.c      |    3 +-
 drivers/staging/lustre/lustre/libcfs/module.c      |   15 ++-
 8 files changed, 282 insertions(+), 15 deletions(-)
 create mode 100644 drivers/staging/lustre/include/linux/lnet/lib-dlc.h
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +2 -1
index e14788c..f24330d 100644
@@ -41,7 +41,8 @@
 #ifndef __LIBCFS_IOCTL_H__
 #define __LIBCFS_IOCTL_H__
 
-#define LIBCFS_IOCTL_VERSION 0x0001000a
+#define LIBCFS_IOCTL_VERSION	0x0001000a
+#define LIBCFS_IOCTL_VERSION2	0x0001000b
 
 struct libcfs_ioctl_hdr {
 	__u32 ioc_len;

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h do { \ · line 97

Quoted 10 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +7 -0
@@ -87,6 +88,13 @@ do {						    \
 	data.ioc_hdr.ioc_len = sizeof(data);			\
 } while (0)
 
+#define LIBCFS_IOC_INIT_V2(data, hdr)			\
+do {							\
+	memset(&(data), 0, sizeof(data));		\
+	(data).hdr.ioc_version = LIBCFS_IOCTL_VERSION2;	\
+	(data).hdr.ioc_len = sizeof(data);		\
+} while (0)
+

Do we really need this?

Quoted 38 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +20 -4
 struct libcfs_ioctl_handler {
 	struct list_head item;
 	int (*handle_ioctl)(unsigned int cmd, struct libcfs_ioctl_hdr *hdr);
@@ -112,9 +120,6 @@ struct libcfs_ioctl_handler {
 /* lnet ioctls */
 #define IOC_LIBCFS_GET_NI		  _IOWR('e', 50, long)
 #define IOC_LIBCFS_FAIL_NID		_IOWR('e', 51, long)
-#define IOC_LIBCFS_ADD_ROUTE	       _IOWR('e', 52, long)
-#define IOC_LIBCFS_DEL_ROUTE	       _IOWR('e', 53, long)
-#define IOC_LIBCFS_GET_ROUTE	       _IOWR('e', 54, long)
 #define IOC_LIBCFS_NOTIFY_ROUTER	   _IOWR('e', 55, long)
 #define IOC_LIBCFS_UNCONFIGURE	     _IOWR('e', 56, long)
 #define IOC_LIBCFS_PORTALS_COMPATIBILITY   _IOWR('e', 57, long)
@@ -137,7 +142,36 @@ struct libcfs_ioctl_handler {
 #define IOC_LIBCFS_DEL_INTERFACE	   _IOWR('e', 79, long)
 #define IOC_LIBCFS_GET_INTERFACE	   _IOWR('e', 80, long)
 
-#define IOC_LIBCFS_MAX_NR			     80
+/*
+ * DLC Specific IOCTL numbers.
+ * In order to maintain backward compatibility with any possible external
+ * tools which might be accessing the IOCTL numbers, a new group of IOCTL
+ * number have been allocated.
+ */
+#define IOCTL_CONFIG_SIZE		struct lnet_ioctl_config_data
+#define IOC_LIBCFS_ADD_ROUTE		_IOWR(IOC_LIBCFS_TYPE, 81, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_DEL_ROUTE		_IOWR(IOC_LIBCFS_TYPE, 82, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_ROUTE		_IOWR(IOC_LIBCFS_TYPE, 83, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_ADD_NET		_IOWR(IOC_LIBCFS_TYPE, 84, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_DEL_NET		_IOWR(IOC_LIBCFS_TYPE, 85, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_NET		_IOWR(IOC_LIBCFS_TYPE, 86, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_CONFIG_RTR		_IOWR(IOC_LIBCFS_TYPE, 87, \

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h struct libcfs_ioctl_handler { · line 174

Quoted 10 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +10 -0
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_ADD_BUF		_IOWR(IOC_LIBCFS_TYPE, 88, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_BUF		_IOWR(IOC_LIBCFS_TYPE, 89, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_PEER_INFO	_IOWR(IOC_LIBCFS_TYPE, 90, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_GET_LNET_STATS	_IOWR(IOC_LIBCFS_TYPE, 91, \
+					      IOCTL_CONFIG_SIZE)
+#define IOC_LIBCFS_MAX_NR		91

Do it like this:

#define IOC_LIBCFS_DEL_ROUTE    _IOWR(IOC_LIBCFS_TYPE, 82, IOCTL_CONFIG_SIZE)
#define IOC_LIBCFS_GET_ROUTE    _IOWR(IOC_LIBCFS_TYPE, 83, IOCTL_CONFIG_SIZE)
#define IOC_LIBCFS_ADD_NET      _IOWR(IOC_LIBCFS_TYPE, 84, IOCTL_CONFIG_SIZE)
#define IOC_LIBCFS_DEL_NET      _IOWR(IOC_LIBCFS_TYPE, 85, IOCTL_CONFIG_SIZE)
#define IOC_LIBCFS_GET_NET      _IOWR(IOC_LIBCFS_TYPE, 86, IOCTL_CONFIG_SIZE)
#define IOC_LIBCFS_CONFIG_RTR   _IOWR(IOC_LIBCFS_TYPE, 87, IOCTL_CONFIG_SIZE)
#define IOC_LIBCFS_ADD_BUF      _IOWR(IOC_LIBCFS_TYPE, 88, IOCTL_CONFIG_SIZE)
#define IOC_LIBCFS_GET_BUF      _IOWR(IOC_LIBCFS_TYPE, 89, IOCTL_CONFIG_SIZE)

#define IOC_LIBCFS_GET_PEER_INFO _IOWR(IOC_LIBCFS_TYPE, 90, IOCTL_CONFIG_SIZE) #define IOC_LIBCFS_GET_LNET_STATS _IOWR(IOC_LIBCFS_TYPE, 91, IOCTL_CONFIG_SIZE)
#define IOC_LIBCFS_MAX_NR 91

Quoted 164 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +0 -0
 static inline int libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
 {
drivers/staging/lustre/include/linux/lnet/lib-dlc.h new file +118 -0
new file mode 100644
index 0000000..b6a2e91
@@ -0,0 +1,118 @@
+/*
+ * GPL HEADER START
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 only,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License version 2 for more details (a copy is included
+ * in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; If not, see
+ * http://www.gnu.org/licenses/gpl-2.0.html
+ *
+ * GPL HEADER END
+ *
+ * Contributers:
+ *   Amir Shehata
+ */
+
+#ifndef LNET_DLC_H
+#define LNET_DLC_H
+
+#include "../libcfs/libcfs_ioctl.h"
+#include "types.h"
+
+#define MAX_NUM_SHOW_ENTRIES	32
+#define LNET_MAX_STR_LEN	128
+#define LNET_MAX_SHOW_NUM_CPT	128
+
+struct lnet_ioctl_net_config {
+	char ni_interfaces[LNET_MAX_INTERFACES][LNET_MAX_STR_LEN];
+	__u32 ni_status;
+	__u32 ni_cpts[LNET_MAX_SHOW_NUM_CPT];
+};
+
+#define LNET_TINY_BUF_IDX	0
+#define LNET_SMALL_BUF_IDX	1
+#define LNET_LARGE_BUF_IDX	2
+
+/* # different router buffer pools */
+#define LNET_NRBPOOLS		(LNET_LARGE_BUF_IDX + 1)
+
+struct lnet_ioctl_pool_cfg {
+	struct {
+		__u32 pl_npages;
+		__u32 pl_nbuffers;
+		__u32 pl_credits;
+		__u32 pl_mincredits;
+	} pl_pools[LNET_NRBPOOLS];
+	__u32 pl_routing;
+};
+
+struct lnet_ioctl_config_data {
+	struct libcfs_ioctl_hdr cfg_hdr;
+
+	__u32 cfg_net;
+	__u32 cfg_count;
+	__u64 cfg_nid;
+	__u32 cfg_ncpts;
+
+	union {
+		struct {
+			__u32 rtr_hop;
+			__u32 rtr_priority;
+			__u32 rtr_flags;
+		} cfg_route;
+		struct {
+			char net_intf[LNET_MAX_STR_LEN];
+			__s32 net_peer_timeout;
+			__s32 net_peer_tx_credits;
+			__s32 net_peer_rtr_credits;
+			__s32 net_max_tx_credits;
+			__u32 net_cksum_algo;
+			__u32 net_pad;
+		} cfg_net;
+		struct {
+			__u32 buf_enable;
+			__s32 buf_tiny;
+			__s32 buf_small;
+			__s32 buf_large;
+		} cfg_buffers;
+	} cfg_config_u;
+
+	char cfg_bulk[0];
+};
+
+struct lnet_ioctl_peer {
+	struct libcfs_ioctl_hdr pr_hdr;
+	__u32 pr_count;
+	__u32 pr_pad;
+	__u64 pr_nid;
+
+	union {
+		struct {
+			char cr_aliveness[LNET_MAX_STR_LEN];
+			__u32 cr_refcount;
+			__u32 cr_ni_peer_tx_credits;
+			__u32 cr_peer_tx_credits;
+			__u32 cr_peer_rtr_credits;
+			__u32 cr_peer_min_rtr_credits;
+			__u32 cr_peer_tx_qnob;
+			__u32 cr_ncpt;
+		} pr_peer_credits;
+	} pr_lnd_u;
+};
+
+struct lnet_ioctl_lnet_stats {
+	struct libcfs_ioctl_hdr st_hdr;
+	struct lnet_counters st_cntrs;
+};
+
+#endif /* LNET_DLC_H */
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +5 -0
index 94d0dc5..f2874e0 100644
@@ -694,6 +694,11 @@ void lnet_peer_tables_cleanup(lnet_ni_t *ni);
 void lnet_peer_tables_destroy(void);
 int lnet_peer_tables_create(void);
 void lnet_debug_peer(lnet_nid_t nid);
+int lnet_get_peers(int count, __u64 *nid, char *alivness,
+		   int *ncpt, int *refcount,
+		   int *ni_peer_tx_credits, int *peer_tx_credits,
+		   int *peer_rtr_credits, int *peer_min_rtr_credtis,
+		   int *peer_tx_qnob);
 
 static inline void
 lnet_peer_set_alive(lnet_peer_t *lp)
drivers/staging/lustre/lnet/lnet/api-ni.c +2 -0
index 9661f6a..165345c 100644
@@ -39,6 +39,7 @@
 #include <linux/ktime.h>
 
 #include "../../include/linux/lnet/lib-lnet.h"
+#include "../../include/linux/lnet/lib-dlc.h"
 
 #define D_LNI D_CONSOLE
 
@@ -1741,6 +1742,7 @@ int
 LNetCtl(unsigned int cmd, void *arg)
 {
 	struct libcfs_ioctl_data *data = arg;
+	struct lnet_ioctl_config_data *config;
 	lnet_process_id_t id = {0};
 	lnet_ni_t *ni;
 	int rc;

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1770

Quoted 4 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -0
@@ -1765,16 +1767,51 @@ LNetCtl(unsigned int cmd, void *arg)
 		return (rc != 0) ? rc : lnet_check_routes();
 
 	case IOC_LIBCFS_DEL_ROUTE:
+		config = arg;

I think you need to verify:

		if (config->cfg_hdr->ioc_len < sizeof(*config))
			return -EINVAL;

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1777

Quoted 12 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +2 -5
 		mutex_lock(&the_lnet.ln_api_mutex);
-		rc = lnet_del_route(data->ioc_net, data->ioc_nid);
+		rc = lnet_del_route(config->cfg_net, config->cfg_nid);
 		mutex_unlock(&the_lnet.ln_api_mutex);
 		return rc;
 
 	case IOC_LIBCFS_GET_ROUTE:
-		return lnet_get_route(data->ioc_count,
-				      &data->ioc_net, &data->ioc_count,
-				      &data->ioc_nid, &data->ioc_flags,
-				      &data->ioc_priority);
+		config = arg;

Verify ioc_len.

Quoted 9 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +9 -0
+		return lnet_get_route(config->cfg_count,
+				      &config->cfg_net,
+				      &config->cfg_config_u.cfg_route.rtr_hop,
+				      &config->cfg_nid,
+				      &config->cfg_config_u.cfg_route.rtr_flags,
+				      &config->cfg_config_u.cfg_route.
+					rtr_priority);
+
+	case IOC_LIBCFS_ADD_NET:

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1796

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +10 -0
+		return 0;
+
+	case IOC_LIBCFS_DEL_NET:
+		return 0;
+
+	case IOC_LIBCFS_GET_NET:
+		return 0;
+
+	case IOC_LIBCFS_GET_LNET_STATS:
+	{

Put this curly brace on the line before.

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1798

Quoted 2 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +2 -0
+		struct lnet_ioctl_lnet_stats *lnet_stats = arg;
+

Verify ioc_len is large enough.

Quoted 68 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +16 -0
+		lnet_counters_get(&lnet_stats->st_cntrs);
+		return 0;
+	}
+
+	case IOC_LIBCFS_CONFIG_RTR:
+		return 0;
+
+	case IOC_LIBCFS_ADD_BUF:
+		return 0;
+
+	case IOC_LIBCFS_GET_BUF:
+		return 0;
+
+	case IOC_LIBCFS_GET_PEER_INFO:
+		return 0;
+
 	case IOC_LIBCFS_NOTIFY_ROUTER:
 		secs_passed = (ktime_get_real_seconds() - data->ioc_u64[0]);
 		return lnet_notify(NULL, data->ioc_nid, data->ioc_flags,
drivers/staging/lustre/lnet/lnet/module.c +4 -0
index 0afdad0..ffc5700 100644
@@ -36,6 +36,7 @@
 
 #define DEBUG_SUBSYSTEM S_LNET
 #include "../../include/linux/lnet/lib-lnet.h"
+#include "../../include/linux/lnet/lib-dlc.h"
 
 static int config_on_load;
 module_param(config_on_load, int, 0444);
@@ -95,6 +96,9 @@ lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
 	case IOC_LIBCFS_UNCONFIGURE:
 		return lnet_unconfigure();
 
+	case IOC_LIBCFS_ADD_NET:
+		return LNetCtl(cmd, hdr);
+
 	default:
 		/* Passing LNET_PID_ANY only gives me a ref if the net is up
 		 * already; I'll need it to ensure the net can't go down while
drivers/staging/lustre/lnet/lnet/peer.c +12 -0
index bb5a0bb..1402e27 100644
@@ -39,6 +39,7 @@
 #define DEBUG_SUBSYSTEM S_LNET
 
 #include "../../include/linux/lnet/lib-lnet.h"
+#include "../../include/linux/lnet/lib-dlc.h"
 
 int
 lnet_peer_tables_create(void)
@@ -392,3 +393,63 @@ lnet_debug_peer(lnet_nid_t nid)
 
 	lnet_net_unlock(cpt);
 }
+
+int lnet_get_peers(int count, __u64 *nid, char *aliveness,
+		   int *ncpt, int *refcount,
+		   int *ni_peer_tx_credits, int *peer_tx_credits,
+		   int *peer_rtr_credits, int *peer_min_rtr_credits,
+		   int *peer_tx_qnob)
+{
+	struct lnet_peer_table *peer_table;
+	lnet_peer_t *lp;
+	int j;
+	int lncpt, found = 0;

drivers/staging/lustre/lnet/lnet/peer.c lnet_debug_peer(lnet_nid_t nid) · line 416

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/peer.c +10 -0
+
+	/* get the number of CPTs */
+	lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
+
+	/*
+	 * if the cpt number to be examined is >= the number of cpts in
+	 * the system then indicate that there are no more cpts to examin
+	 */
+	if (*ncpt > lncpt)
+		return -1;

Add some documentation to the start of the function to say what -1 means here. Or reading below it looks like normal error codes were intended.

Quoted 29 lines
drivers/staging/lustre/lnet/lnet/peer.c +29 -0
+
+	/* get the current table */
+	peer_table = the_lnet.ln_peer_tables[*ncpt];
+	/* if the ptable is NULL then there are no more cpts to examine */
+	if (!peer_table)
+		return -1;
+
+	lnet_net_lock(*ncpt);
+
+	for (j = 0; j < LNET_PEER_HASH_SIZE && !found; j++) {
+		struct list_head *peers = &peer_table->pt_hash[j];
+
+		list_for_each_entry(lp, peers, lp_hashlist) {
+			if (count-- > 0)
+				continue;
+
+			snprintf(aliveness, LNET_MAX_STR_LEN, "NA");
+			if (lnet_isrouter(lp) ||
+			    lnet_peer_aliveness_enabled(lp))
+				snprintf(aliveness, LNET_MAX_STR_LEN,
+					 lp->lp_alive ? "up" : "down");
+
+			*nid = lp->lp_nid;
+			*refcount = lp->lp_refcount;
+			*ni_peer_tx_credits = lp->lp_ni->ni_peertxcredits;
+			*peer_tx_credits = lp->lp_txcredits;
+			*peer_rtr_credits = lp->lp_rtrcredits;
+			*peer_min_rtr_credits = lp->lp_mintxcredits;
+			*peer_tx_qnob = lp->lp_txqnob;

drivers/staging/lustre/lnet/lnet/peer.c lnet_debug_peer(lnet_nid_t nid) · line 455

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/peer.c +10 -0
+
+			found = 1;
+		}
+	}
+	lnet_net_unlock(*ncpt);
+
+	*ncpt = lncpt;
+
+	return found ? 0 : -ENOENT;
+}

regards,
dan carpenter

#21 lore raw

RE: [PATCH 13/40] staging: lustre: Dynamic LNet Configuration (DLC) show command

Quoted 7 lines
Quoted 7 lines

struct libcfs_ioctl_hdr {

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +0 -0
 	__u32 ioc_len;
@@ -87,6 +88,13 @@ do {						    \
 	data.ioc_hdr.ioc_len = sizeof(data);			\
 } while (0)
 
Quoted 9 lines

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h do { \ · line 97

Quoted 7 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +7 -0
+#define LIBCFS_IOC_INIT_V2(data, hdr)			\
+do {							\
+	memset(&(data), 0, sizeof(data));		\
+	(data).hdr.ioc_version = LIBCFS_IOCTL_VERSION2;	\
+	(data).hdr.ioc_len = sizeof(data);		\
+} while (0)
+

Do we really need this?

Would you be okay if this was a inline function? This is used by user land and kernel space code.

#22 lore raw

Re: [PATCH 13/40] staging: lustre: Dynamic LNet Configuration (DLC) show command

Quoted 17 lines · James A.
Quoted 7 lines
Quoted 7 lines

struct libcfs_ioctl_hdr {

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +0 -0
 	__u32 ioc_len;
@@ -87,6 +88,13 @@ do {						    \
 	data.ioc_hdr.ioc_len = sizeof(data);			\
 } while (0)
 
Quoted 9 lines

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h do { \ · line 97

Quoted 7 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +7 -0
+#define LIBCFS_IOC_INIT_V2(data, hdr)			\
+do {							\
+	memset(&(data), 0, sizeof(data));		\
+	(data).hdr.ioc_version = LIBCFS_IOCTL_VERSION2;	\
+	(data).hdr.ioc_len = sizeof(data);		\
+} while (0)
+

Do we really need this?

Quoted 2 lines

Would you be okay if this was a inline function? This is used by user land and kernel space code.

I try (not very hard) to sound like a broken record but this business of sharing code with userland is a pain in the butt. It's not used in the kernel or in any patches you have sent.

It would look better as an inline function though so I wouldn't have even noticed it.

regards,
dan carpenter

#23 lore raw

RE: [PATCH 13/40] staging: lustre: Dynamic LNet Configuration (DLC) show command

Quoted 21 lines · James A.
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines

struct libcfs_ioctl_hdr {

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +0 -0
 	__u32 ioc_len;
@@ -87,6 +88,13 @@ do {						    \
 	data.ioc_hdr.ioc_len = sizeof(data);			\
 } while (0)
 
Quoted 9 lines

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h do { \ · line 97

Quoted 7 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +7 -0
+#define LIBCFS_IOC_INIT_V2(data, hdr)			\
+do {							\
+	memset(&(data), 0, sizeof(data));		\
+	(data).hdr.ioc_version = LIBCFS_IOCTL_VERSION2;	\
+	(data).hdr.ioc_len = sizeof(data);		\
+} while (0)
+

Do we really need this?

Quoted 2 lines

Would you be okay if this was a inline function? This is used by user land and kernel space code.

Quoted 6 lines

I try (not very hard) to sound like a broken record but this business of sharing code with userland is a pain in the butt. It's not used in the kernel or in any patches you have sent.

It would look better as an inline function though so I wouldn't have even noticed it.

I'm glad you noticed. I just looked at the production source code and yep it is only used in the userland tools code. I need to update our tools so they don't break. Then we can remove these macros.

#24 lore raw

Re: [PATCH 13/40] staging: lustre: Dynamic LNet Configuration (DLC) show command

In reply to Simmons, James A.
Quoted 17 lines · James A.
Quoted 7 lines
Quoted 7 lines

struct libcfs_ioctl_hdr {

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +0 -0
 	__u32 ioc_len;
@@ -87,6 +88,13 @@ do {						    \
 	data.ioc_hdr.ioc_len = sizeof(data);			\
 } while (0)
 
Quoted 9 lines

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h do { \ · line 97

Quoted 7 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +7 -0
+#define LIBCFS_IOC_INIT_V2(data, hdr)			\
+do {							\
+	memset(&(data), 0, sizeof(data));		\
+	(data).hdr.ioc_version = LIBCFS_IOCTL_VERSION2;	\
+	(data).hdr.ioc_len = sizeof(data);		\
+} while (0)
+

Do we really need this?

Quoted 2 lines

Would you be okay if this was a inline function? This is used by user land and kernel space code.

Then your code is broken, please never do that.

#25 lore raw

RE: [PATCH 13/40] staging: lustre: Dynamic LNet Configuration (DLC) show command

Quoted 18 lines · James A.
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines

struct libcfs_ioctl_hdr {

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +0 -0
 	__u32 ioc_len;

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h do { \ · line 97

Quoted 10 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +7 -0
@@ -87,6 +88,13 @@ do {						    \
 	data.ioc_hdr.ioc_len = sizeof(data);			\
 } while (0)
 
+#define LIBCFS_IOC_INIT_V2(data, hdr)			\
+do {							\
+	memset(&(data), 0, sizeof(data));		\
+	(data).hdr.ioc_version = LIBCFS_IOCTL_VERSION2;	\
+	(data).hdr.ioc_len = sizeof(data);		\
+} while (0)
+

Do we really need this?

Quoted 4 lines
Quoted 2 lines

Would you be okay if this was a inline function? This is used by user land and kernel space code.

Then your code is broken, please never do that.

This brings up a good point. This header doesn't contain structures for userland so it is a uapi type header. Should such headers only contain data structures?

#26 lore raw

Re: [PATCH 13/40] staging: lustre: Dynamic LNet Configuration (DLC) show command

Quoted 18 lines · James A.
Quoted 18 lines · James A.
Quoted 17 lines
Quoted 16 lines
Quoted 4 lines

struct libcfs_ioctl_hdr {

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +0 -0
 	__u32 ioc_len;

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h do { \ · line 97

Quoted 10 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +7 -0
@@ -87,6 +88,13 @@ do {						    \
 	data.ioc_hdr.ioc_len = sizeof(data);			\
 } while (0)
 
+#define LIBCFS_IOC_INIT_V2(data, hdr)			\
+do {							\
+	memset(&(data), 0, sizeof(data));		\
+	(data).hdr.ioc_version = LIBCFS_IOCTL_VERSION2;	\
+	(data).hdr.ioc_len = sizeof(data);		\
+} while (0)
+

Do we really need this?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

Would you be okay if this was a inline function? This is used by user land and kernel space code.

Then your code is broken, please never do that.

This brings up a good point. This header doesn't contain structures for userland so it is a uapi type header. Should such headers only contain data structures?

Yes, that would make more sense.

thanks,

greg k-h

#27 lore raw

Re: [PATCH 13/40] staging: lustre: Dynamic LNet Configuration (DLC) show command

In reply to James Simmons
Quoted 10 lines · James Simmons
drivers/staging/lustre/lnet/lnet/peer.c +10 -0
+int lnet_get_peers(int count, __u64 *nid, char *aliveness,
+		   int *ncpt, int *refcount,
+		   int *ni_peer_tx_credits, int *peer_tx_credits,
+		   int *peer_rtr_credits, int *peer_min_rtr_credits,
+		   int *peer_tx_qnob)
+{
+	struct lnet_peer_table *peer_table;
+	lnet_peer_t *lp;
+	int j;
+	int lncpt, found = 0;

drivers/staging/lustre/lnet/lnet/peer.c lnet_debug_peer(lnet_nid_t nid) · line 416

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/peer.c +10 -0
+
+	/* get the number of CPTs */
+	lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
+
+	/*
+	 * if the cpt number to be examined is >= the number of cpts in
+	 * the system then indicate that there are no more cpts to examin
+	 */
+	if (*ncpt > lncpt)
+		return -1;

The comment is correct but the code is off by one.

	if (*ncpt >= lncpt)
		return -EINVAL;

Also not a correct error code. I assume that you will review the whole patchset again and fix all the -1 returns, of course.

regards,
dan carpenter

#28 lore raw

PATCH 14/40 staging: lustre: fix crash due to NULL networks string

In reply to James Simmons

From: Amir Shehata <[email protected]>

If there is an invalid networks or ip2nets lnet_parse_networks() gets called with a NULL 'network' string parameter

lnet_parse_networks() needs to sanitize its input string now that it's being called from multiple places. Instead, check for a NULL string everytime the function is called, which reduces the probability of errors with other code modifications.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5540
Reviewed-on: http://review.whamcloud.com/11626

---
 drivers/staging/lustre/lnet/lnet/api-ni.c |    5 +----
 drivers/staging/lustre/lnet/lnet/config.c |    9 ++++++++-
 2 files changed, 9 insertions(+), 5 deletions(-)
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -4
index 165345c..cc87900 100644
@@ -1524,7 +1524,6 @@ LNetNIInit(lnet_pid_t requested_pid)
 	lnet_ping_info_t *pinfo;
 	lnet_handle_md_t md_handle;
 	struct list_head net_head;
-	char *nets;
 
 	INIT_LIST_HEAD(&net_head);
 
@@ -1539,13 +1538,11 @@ LNetNIInit(lnet_pid_t requested_pid)
 		return rc;
 	}
 
-	nets = lnet_get_networks();
-
 	rc = lnet_prepare(requested_pid);
 	if (rc != 0)
 		goto failed0;
 
-	rc = lnet_parse_networks(&net_head, nets);
+	rc = lnet_parse_networks(&net_head, lnet_get_networks());
 	if (rc < 0)
 		goto failed1;
 
drivers/staging/lustre/lnet/lnet/config.c +8 -1
index 1c7ad7c..d1e0217 100644
@@ -184,7 +184,7 @@ int
 lnet_parse_networks(struct list_head *nilist, char *networks)
 {
 	struct cfs_expr_list *el = NULL;
-	int tokensize = strlen(networks) + 1;
+	int tokensize;
 	char *tokens;
 	char *str;
 	char *tmp;
@@ -192,6 +192,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 	__u32 net;
 	int nnets = 0;
 
+	if (!networks) {
+		CERROR("networks string is undefined\n");
+		return -EINVAL;
+	}
+
 	if (strlen(networks) > LNET_SINGLE_TEXTBUF_NOB) {
 		/* _WAY_ conservative */
 		LCONSOLE_ERROR_MSG(0x112,
@@ -199,6 +204,8 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 		return -EINVAL;
 	}
 
+	tokensize = strlen(networks) + 1;
+
 	LIBCFS_ALLOC(tokens, tokensize);
 	if (tokens == NULL) {
 		CERROR("Can't allocate net tokens\n");
Signature · 1 line
1.7.1
#29 lore raw

Re: [PATCH 14/40] staging: lustre: fix crash due to NULL networks string

This feels like we are fixing a bug introduce in PATCH 11 when we removed a NULL check. Don't introduce bugs and then fix them in the same patchset; the fix has to be folded into the original patch.

regards,
dan carpenter

#30 lore raw

PATCH 15/40 staging: lustre: DLC user/kernel space glue code

In reply to James Simmons

From: Amir Shehata <[email protected]>

This is the sixth patch of a set of patches that enables DLC.

This patch enables the user space to call into the kernel space DLC code. Added handlers in the LNetCtl function to call the new functions added for Dynamic Lnet Configuration

ntel-bug-id: https://jira.hpdd.intel.com/browse/LU-2456
Reviewed-on: http://review.whamcloud.com/8023

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |   22 ++-
 .../staging/lustre/include/linux/lnet/lib-types.h  |    8 +
 drivers/staging/lustre/lnet/lnet/api-ni.c          |  172 ++++++++++++++++++--
 drivers/staging/lustre/lnet/lnet/module.c          |   53 ++++++-
 drivers/staging/lustre/lnet/lnet/peer.c            |   34 ++--
 drivers/staging/lustre/lnet/lnet/router.c          |   71 +++++++--
 6 files changed, 307 insertions(+), 53 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +17 -5
index f2874e0..63919dd 100644
@@ -39,6 +39,7 @@
 #include "api.h"
 #include "lnet.h"
 #include "lib-types.h"
+#include "lib-dlc.h"
 
 extern lnet_t	the_lnet;	/* THE network */
 
@@ -456,6 +457,12 @@ int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
 void lnet_destroy_routes(void);
 int lnet_get_route(int idx, __u32 *net, __u32 *hops,
 		   lnet_nid_t *gateway, __u32 *alive, __u32 *priority);
+int lnet_get_net_config(int idx, __u32 *cpt_count, __u64 *nid,
+			int *peer_timeout, int *peer_tx_credits,
+			int *peer_rtr_cr, int *max_tx_credits,
+			struct lnet_ioctl_net_config *net_config);
+int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg);
+
 void lnet_router_debugfs_init(void);
 void lnet_router_debugfs_fini(void);
 int  lnet_rtrpools_alloc(int im_a_router);
@@ -465,6 +472,10 @@ int lnet_rtrpools_enable(void);
 void lnet_rtrpools_disable(void);
 void lnet_rtrpools_free(int keep_pools);
 lnet_remotenet_t *lnet_find_net_locked(__u32 net);
+int lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
+		    __s32 peer_timeout, __s32 peer_cr, __s32 peer_buf_cr,
+		    __s32 credits);
+int lnet_dyn_del_ni(__u32 net);
 
 int lnet_islocalnid(lnet_nid_t nid);
 int lnet_islocalnet(__u32 net);
@@ -694,11 +705,12 @@ void lnet_peer_tables_cleanup(lnet_ni_t *ni);
 void lnet_peer_tables_destroy(void);
 int lnet_peer_tables_create(void);
 void lnet_debug_peer(lnet_nid_t nid);
-int lnet_get_peers(int count, __u64 *nid, char *alivness,
-		   int *ncpt, int *refcount,
-		   int *ni_peer_tx_credits, int *peer_tx_credits,
-		   int *peer_rtr_credits, int *peer_min_rtr_credtis,
-		   int *peer_tx_qnob);
+int lnet_get_peer_info(__u32 peer_index, __u64 *nid,
+		       char alivness[LNET_MAX_STR_LEN],
+		       __u32 *cpt_iter, __u32 *refcount,
+		       __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
+		       __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credtis,
+		       __u32 *peer_tx_qnob);
 
 static inline void
 lnet_peer_set_alive(lnet_peer_t *lp)
drivers/staging/lustre/include/linux/lnet/lib-types.h +8 -0
index e7585b9..3282782 100644
@@ -611,6 +611,14 @@ typedef struct {
 	/* test protocol compatibility flags */
 	int				  ln_testprotocompat;
 
+	/*
+	 * 0 - load the NIs from the mod params
+	 * 1 - do not load the NIs from the mod params
+	 * Reverse logic to ensure that other calls to LNetNIInit
+	 * need no change
+	 */
+	bool				  ln_nis_from_mod_params;
+
 } lnet_t;
 
 #endif
drivers/staging/lustre/lnet/lnet/api-ni.c +157 -15

209 lines not on this page · raw message

drivers/staging/lustre/lnet/lnet/module.c +51 -2

71 lines not on this page · raw message

drivers/staging/lustre/lnet/lnet/peer.c +18 -16
index 1402e27..3b71812 100644
@@ -394,16 +394,18 @@ lnet_debug_peer(lnet_nid_t nid)
 	lnet_net_unlock(cpt);
 }
 
-int lnet_get_peers(int count, __u64 *nid, char *aliveness,
-		   int *ncpt, int *refcount,
-		   int *ni_peer_tx_credits, int *peer_tx_credits,
-		   int *peer_rtr_credits, int *peer_min_rtr_credits,
-		   int *peer_tx_qnob)
+int
+lnet_get_peer_info(__u32 peer_index, __u64 *nid,
+		   char aliveness[LNET_MAX_STR_LEN],
+		   __u32 *cpt_iter, __u32 *refcount,
+		   __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
+		   __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credits,
+		   __u32 *peer_tx_qnob)
 {
 	struct lnet_peer_table *peer_table;
 	lnet_peer_t *lp;
-	int j;
-	int lncpt, found = 0;
+	bool found = false;
+	int lncpt, j;
 
 	/* get the number of CPTs */
 	lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
@@ -412,22 +414,22 @@ int lnet_get_peers(int count, __u64 *nid, char *aliveness,
 	 * if the cpt number to be examined is >= the number of cpts in
 	 * the system then indicate that there are no more cpts to examin
 	 */
-	if (*ncpt > lncpt)
-		return -1;
+	if (*cpt_iter > lncpt)
+		return -ENOENT;
 
 	/* get the current table */
-	peer_table = the_lnet.ln_peer_tables[*ncpt];
+	peer_table = the_lnet.ln_peer_tables[*cpt_iter];
 	/* if the ptable is NULL then there are no more cpts to examine */
 	if (!peer_table)
-		return -1;
+		return -ENOENT;
 
-	lnet_net_lock(*ncpt);
+	lnet_net_lock(*cpt_iter);
 
 	for (j = 0; j < LNET_PEER_HASH_SIZE && !found; j++) {
 		struct list_head *peers = &peer_table->pt_hash[j];
 
 		list_for_each_entry(lp, peers, lp_hashlist) {
-			if (count-- > 0)
+			if (peer_index-- > 0)
 				continue;
 
 			snprintf(aliveness, LNET_MAX_STR_LEN, "NA");
@@ -444,12 +446,12 @@ int lnet_get_peers(int count, __u64 *nid, char *aliveness,
 			*peer_min_rtr_credits = lp->lp_mintxcredits;
 			*peer_tx_qnob = lp->lp_txqnob;
 
-			found = 1;
+			found = true;
 		}
 	}
-	lnet_net_unlock(*ncpt);
+	lnet_net_unlock(*cpt_iter);
 
-	*ncpt = lncpt;
+	*cpt_iter = lncpt;
 
 	return found ? 0 : -ENOENT;
 }
drivers/staging/lustre/lnet/lnet/router.c +56 -15

116 lines not on this page · raw message

Signature · 1 line
1.7.1
#31 lore raw

Re: [PATCH 15/40] staging: lustre: DLC user/kernel space glue code

Quoted 135 lines · James Simmons

From: Amir Shehata <[email protected]>

This is the sixth patch of a set of patches that enables DLC.

This patch enables the user space to call into the kernel space DLC code. Added handlers in the LNetCtl function to call the new functions added for Dynamic Lnet Configuration

ntel-bug-id: https://jira.hpdd.intel.com/browse/LU-2456
Reviewed-on: http://review.whamcloud.com/8023

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |   22 ++-
 .../staging/lustre/include/linux/lnet/lib-types.h  |    8 +
 drivers/staging/lustre/lnet/lnet/api-ni.c          |  172 ++++++++++++++++++--
 drivers/staging/lustre/lnet/lnet/module.c          |   53 ++++++-
 drivers/staging/lustre/lnet/lnet/peer.c            |   34 ++--
 drivers/staging/lustre/lnet/lnet/router.c          |   71 +++++++--
 6 files changed, 307 insertions(+), 53 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +17 -5
index f2874e0..63919dd 100644
@@ -39,6 +39,7 @@
 #include "api.h"
 #include "lnet.h"
 #include "lib-types.h"
+#include "lib-dlc.h"
 
 extern lnet_t	the_lnet;	/* THE network */
 
@@ -456,6 +457,12 @@ int lnet_del_route(__u32 net, lnet_nid_t gw_nid);
 void lnet_destroy_routes(void);
 int lnet_get_route(int idx, __u32 *net, __u32 *hops,
 		   lnet_nid_t *gateway, __u32 *alive, __u32 *priority);
+int lnet_get_net_config(int idx, __u32 *cpt_count, __u64 *nid,
+			int *peer_timeout, int *peer_tx_credits,
+			int *peer_rtr_cr, int *max_tx_credits,
+			struct lnet_ioctl_net_config *net_config);
+int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg);
+
 void lnet_router_debugfs_init(void);
 void lnet_router_debugfs_fini(void);
 int  lnet_rtrpools_alloc(int im_a_router);
@@ -465,6 +472,10 @@ int lnet_rtrpools_enable(void);
 void lnet_rtrpools_disable(void);
 void lnet_rtrpools_free(int keep_pools);
 lnet_remotenet_t *lnet_find_net_locked(__u32 net);
+int lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
+		    __s32 peer_timeout, __s32 peer_cr, __s32 peer_buf_cr,
+		    __s32 credits);
+int lnet_dyn_del_ni(__u32 net);
 
 int lnet_islocalnid(lnet_nid_t nid);
 int lnet_islocalnet(__u32 net);
@@ -694,11 +705,12 @@ void lnet_peer_tables_cleanup(lnet_ni_t *ni);
 void lnet_peer_tables_destroy(void);
 int lnet_peer_tables_create(void);
 void lnet_debug_peer(lnet_nid_t nid);
-int lnet_get_peers(int count, __u64 *nid, char *alivness,
-		   int *ncpt, int *refcount,
-		   int *ni_peer_tx_credits, int *peer_tx_credits,
-		   int *peer_rtr_credits, int *peer_min_rtr_credtis,
-		   int *peer_tx_qnob);
+int lnet_get_peer_info(__u32 peer_index, __u64 *nid,
+		       char alivness[LNET_MAX_STR_LEN],
+		       __u32 *cpt_iter, __u32 *refcount,
+		       __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
+		       __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credtis,
+		       __u32 *peer_tx_qnob);
 
 static inline void
 lnet_peer_set_alive(lnet_peer_t *lp)
drivers/staging/lustre/include/linux/lnet/lib-types.h +8 -0
index e7585b9..3282782 100644
@@ -611,6 +611,14 @@ typedef struct {
 	/* test protocol compatibility flags */
 	int				  ln_testprotocompat;
 
+	/*
+	 * 0 - load the NIs from the mod params
+	 * 1 - do not load the NIs from the mod params
+	 * Reverse logic to ensure that other calls to LNetNIInit
+	 * need no change
+	 */
+	bool				  ln_nis_from_mod_params;
+
 } lnet_t;
 
 #endif
drivers/staging/lustre/lnet/lnet/api-ni.c +22 -1
index cc87900..125d018 100644
@@ -1542,7 +1542,9 @@ LNetNIInit(lnet_pid_t requested_pid)
 	if (rc != 0)
 		goto failed0;
 
-	rc = lnet_parse_networks(&net_head, lnet_get_networks());
+	rc = lnet_parse_networks(&net_head,
+				 !the_lnet.ln_nis_from_mod_params ?
+				 lnet_get_networks() : "");
 	if (rc < 0)
 		goto failed1;
 
@@ -1657,6 +1659,93 @@ LNetNIFini(void)
 }
 EXPORT_SYMBOL(LNetNIFini);
 
+/**
+ * Grabs the ni data from the ni structure and fills the out
+ * parameters
+ *
+ * \param[in] ni network       interface structure
+ * \param[out] cpt_count       the number of cpts the ni is on
+ * \param[out] nid             Network Interface ID
+ * \param[out] peer_timeout    NI peer timeout
+ * \param[out] peer_tx_crdits  NI peer transmit credits
+ * \param[out] peer_rtr_credits NI peer router credits
+ * \param[out] max_tx_credits  NI max transmit credit
+ * \param[out] net_config      Network configuration
+ */
+static void
+lnet_fill_ni_info(struct lnet_ni *ni, __u32 *cpt_count, __u64 *nid,
+		  int *peer_timeout, int *peer_tx_credits,
+		  int *peer_rtr_credits, int *max_tx_credits,
+		  struct lnet_ioctl_net_config *net_config)
+{

drivers/staging/lustre/lnet/lnet/api-ni.c LNetNIFini(void) · line 1690

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +10 -0
+	int i;
+
+	if (!ni)
+		return;
+
+	if (!net_config)
+		return;
+
+	CLASSERT(ARRAY_SIZE(ni->ni_interfaces) ==
+		 ARRAY_SIZE(net_config->ni_interfaces));

The kernel has a macro for this BUILD_BUG_ON().

drivers/staging/lustre/lnet/lnet/api-ni.c LNetNIFini(void) · line 1692

Quoted 2 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +2 -0
+
+	if (ni->ni_interfaces[0]) {

Couldn't we just break at the first NULL?

drivers/staging/lustre/lnet/lnet/api-ni.c LNetNIFini(void) · line 1701

Quoted 9 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +9 -0
+		for (i = 0; i < ARRAY_SIZE(ni->ni_interfaces); i++) {
+			if (ni->ni_interfaces[i]) {
+				strncpy(net_config->ni_interfaces[i],
+					ni->ni_interfaces[i],
+					sizeof(net_config->ni_interfaces[i]));
+			}
+		}
+	}
+
	for (i = 0; i < ARRAY_SIZE(ni->ni_interfaces); i++) {
		if (!ni->ni_interfaces[i])
			break;
		strncpy(net_config->ni_interfaces[i],
			ni->ni_interfaces[i],
			sizeof(net_config->ni_interfaces[i]));
	}

drivers/staging/lustre/lnet/lnet/api-ni.c LNetNIFini(void) · line 1712

Quoted 11 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +11 -0
+	*nid = ni->ni_nid;
+	*peer_timeout = ni->ni_peertimeout;
+	*peer_tx_credits = ni->ni_peertxcredits;
+	*peer_rtr_credits = ni->ni_peerrtrcredits;
+	*max_tx_credits = ni->ni_maxtxcredits;
+
+	net_config->ni_status = ni->ni_status->ns_status;
+
+	for (i = 0;
+	     ni->ni_cpts && i < ni->ni_ncpts &&
+	     i < LNET_MAX_SHOW_NUM_CPT;

This is really sort of a crap condition and either you are doing it to please an inferior static checker (don't write nonsense code to please the static checker) or there is something very confused about your code and you should fix it elsewhere. The loop here should be:

	for (i = 0; i < ni->ni_ncpts; i++)
		net_config->ni_cpts[i] = ni->ni_cpts[i];
Quoted 21 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +21 -0
+	     i++)
+		net_config->ni_cpts[i] = ni->ni_cpts[i];
+
+	*cpt_count = ni->ni_ncpts;
+}
+
+int
+lnet_get_net_config(int idx, __u32 *cpt_count, __u64 *nid, int *peer_timeout,
+		    int *peer_tx_credits, int *peer_rtr_credits,
+		    int *max_tx_credits,
+		    struct lnet_ioctl_net_config *net_config)
+{
+	struct lnet_ni *ni;
+	struct list_head *tmp;
+	int cpt;
+	int rc = -ENOENT;
+
+	cpt = lnet_net_lock_current();
+
+	list_for_each(tmp, &the_lnet.ln_nis) {
+		ni = list_entry(tmp, lnet_ni_t, ni_list);

drivers/staging/lustre/lnet/lnet/api-ni.c LNetNIFini(void) · line 1743

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +10 -0
+		if (idx-- == 0) {
+			rc = 0;
+			lnet_ni_lock(ni);
+			lnet_fill_ni_info(ni, cpt_count, nid, peer_timeout,
+					  peer_tx_credits, peer_rtr_credits,
+					  max_tx_credits, net_config);
+			lnet_ni_unlock(ni);
+			break;
+		}
+	}

Write it something like this:

	i = 0;
	list_for_each(tmp, &the_lnet.ln_nis) {
		if (i++ != idx)
			continue;

		ni = list_entry(tmp, lnet_ni_t, ni_list);
		lnet_ni_lock(ni);
		lnet_fill_ni_info(ni, cpt_count, nid, peer_timeout,
				  peer_tx_credits, peer_rtr_credits,
				  max_tx_credits, net_config);
		lnet_ni_unlock(ni);
		rc = 0;
		break;
	}

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1849

Quoted 13 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +6 -0
+
+	lnet_net_unlock(cpt);
+	return rc;
+}
+
 int
 lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
 		__s32 peer_timeout, __s32 peer_cr, __s32 peer_buf_cr,
@@ -1757,9 +1846,13 @@ LNetCtl(unsigned int cmd, void *arg)
 		return lnet_fail_nid(data->ioc_nid, data->ioc_count);
 
 	case IOC_LIBCFS_ADD_ROUTE:
+		config = arg;

Check ioc_len.

Quoted 16 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +5 -3
 		mutex_lock(&the_lnet.ln_api_mutex);
-		rc = lnet_add_route(data->ioc_net, data->ioc_count,
-				    data->ioc_nid, data->ioc_priority);
+		rc = lnet_add_route(config->cfg_net,
+				    config->cfg_config_u.cfg_route.rtr_hop,
+				    config->cfg_nid,
+				    config->cfg_config_u.cfg_route.
+					rtr_priority);
 		mutex_unlock(&the_lnet.ln_api_mutex);
 		return (rc != 0) ? rc : lnet_check_routes();
 
@@ -1780,14 +1873,28 @@ LNetCtl(unsigned int cmd, void *arg)
 				      &config->cfg_config_u.cfg_route.
 					rtr_priority);
 
-	case IOC_LIBCFS_ADD_NET:

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1879

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +3 -6
-		return 0;
-
-	case IOC_LIBCFS_DEL_NET:
-		return 0;
+	case IOC_LIBCFS_GET_NET: {
+		struct lnet_ioctl_net_config *net_config;
 
-	case IOC_LIBCFS_GET_NET:
-		return 0;
+		config = arg;

Check ioc_len.

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1882

Quoted 3 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +3 -0
+		net_config = (struct lnet_ioctl_net_config *)
+				config->cfg_bulk;
+		if (!config || !net_config)

We already dereferenced "config" so it's a bit late to check for NULL. But that's an interesting question if we need to add NULL checks every where. I forget. Please check this and reply to the email thread.

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1883

Quoted 1 line
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -0
+			return -1;

This is not a correct error code. return -EINVAL.

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1896

Quoted 13 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +13 -0
+
+		return lnet_get_net_config(config->cfg_count,
+					   &config->cfg_ncpts,
+					   &config->cfg_nid,
+					   &config->cfg_config_u.cfg_net.
+						net_peer_timeout,
+					   &config->cfg_config_u.cfg_net.
+						net_peer_tx_credits,
+					   &config->cfg_config_u.cfg_net.
+						net_peer_rtr_credits,
+					   &config->cfg_config_u.cfg_net.
+						net_max_tx_credits,
+					   net_config);

Breaking it up like this is nasty.

		return lnet_get_net_config(
				config->cfg_count,
				&config->cfg_ncpts,
				&config->cfg_nid,
				&config->cfg_config_u.cfg_net.net_peer_timeout,
				&config->cfg_config_u.cfg_net.net_peer_tx_credits,
				&config->cfg_config_u.cfg_net.net_peer_rtr_credits,
				&config->cfg_config_u.cfg_net.net_max_tx_credits,
				net_config);

It violates checkpatch.pl rules, but don't write ugly code just to make a tool happy.

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1908

Quoted 9 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +2 -0
+	}
 
 	case IOC_LIBCFS_GET_LNET_STATS:
 	{
@@ -1798,16 +1905,51 @@ LNetCtl(unsigned int cmd, void *arg)
 	}
 
 	case IOC_LIBCFS_CONFIG_RTR:
+		config = arg;

ioc_len.

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1920

Quoted 13 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +9 -1
+		mutex_lock(&the_lnet.ln_api_mutex);
+		if (config->cfg_config_u.cfg_buffers.buf_enable) {
+			rc = lnet_rtrpools_enable();
+			mutex_unlock(&the_lnet.ln_api_mutex);
+			return rc;
+		}
+		lnet_rtrpools_disable();
+		mutex_unlock(&the_lnet.ln_api_mutex);
 		return 0;
 
 	case IOC_LIBCFS_ADD_BUF:
-		return 0;
+		config = arg;

ioc_len.

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1927

Quoted 7 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +7 -0
+		mutex_lock(&the_lnet.ln_api_mutex);
+		rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
+						buf_tiny,
+					  config->cfg_config_u.cfg_buffers.
+						buf_small,
+					  config->cfg_config_u.cfg_buffers.
+						buf_large);

Ugh.

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1934

Quoted 11 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +5 -4
+		mutex_unlock(&the_lnet.ln_api_mutex);
+		return rc;
 
-	case IOC_LIBCFS_GET_BUF:
-		return 0;
+	case IOC_LIBCFS_GET_BUF: {
+		struct lnet_ioctl_pool_cfg *pool_cfg;
 
-	case IOC_LIBCFS_GET_PEER_INFO:
-		return 0;
+		config = arg;

ioc_len.

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1940

Quoted 6 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +6 -0
+		pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
+		return lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
+	}
+
+	case IOC_LIBCFS_GET_PEER_INFO: {
+		struct lnet_ioctl_peer *peer_info = arg;

ioc_len.

Quoted 20 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +12 -0
+
+		return lnet_get_peer_info(peer_info->pr_count,
+			&peer_info->pr_nid,
+			peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
+			&peer_info->pr_lnd_u.pr_peer_credits.cr_ncpt,
+			&peer_info->pr_lnd_u.pr_peer_credits.cr_refcount,
+			&peer_info->pr_lnd_u.pr_peer_credits.cr_ni_peer_tx_credits,
+			&peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_credits,
+			&peer_info->pr_lnd_u.pr_peer_credits.cr_peer_rtr_credits,
+			&peer_info->pr_lnd_u.pr_peer_credits.cr_peer_min_rtr_credits,
+			&peer_info->pr_lnd_u.pr_peer_credits.cr_peer_tx_qnob);
+	}
 
 	case IOC_LIBCFS_NOTIFY_ROUTER:
 		secs_passed = (ktime_get_real_seconds() - data->ioc_u64[0]);
drivers/staging/lustre/lnet/lnet/module.c +0 -0
index ffc5700..281315c 100644

drivers/staging/lustre/lnet/lnet/module.c lnet_unconfigure(void) · line 93

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/module.c +7 -0
@@ -84,20 +84,69 @@ lnet_unconfigure(void)
 	return (refcount == 0) ? 0 : -EBUSY;
 }
 
+int
+lnet_dyn_configure(struct libcfs_ioctl_hdr *hdr)
+{
+	struct lnet_ioctl_config_data *conf =
+		(struct lnet_ioctl_config_data *)hdr;
+	int rc;
+

We never checked ioc_len before calling this function so it could oops if we read unmapped memory.

drivers/staging/lustre/lnet/lnet/module.c lnet_unconfigure(void) · line 95

Quoted 2 lines
drivers/staging/lustre/lnet/lnet/module.c +2 -0
+	mutex_lock(&lnet_config_mutex);
+	if (the_lnet.ln_niinit_self)

Flip this around:

	if (!the_lnet.ln_niinit_self) {
		rc = -EINVAL;
		goto unlock;
	}

	rc = lnet_dyn_add_ni(LUSTRE_SRV_LNET_PID, ...
Quoted 15 lines
drivers/staging/lustre/lnet/lnet/module.c +15 -0
+		rc = lnet_dyn_add_ni(LUSTRE_SRV_LNET_PID,
+				     conf->cfg_config_u.cfg_net.net_intf,
+				     conf->cfg_config_u.cfg_net.
+					net_peer_timeout,
+				     conf->cfg_config_u.cfg_net.
+					net_peer_tx_credits,
+				     conf->cfg_config_u.cfg_net.
+					net_peer_rtr_credits,
+				     conf->cfg_config_u.cfg_net.
+					net_max_tx_credits);
+	else
+		rc = -EINVAL;
+	mutex_unlock(&lnet_config_mutex);
+	return rc;
+}

drivers/staging/lustre/lnet/lnet/module.c lnet_unconfigure(void) · line 120

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/module.c +10 -0
+
+int
+lnet_dyn_unconfigure(struct libcfs_ioctl_hdr *hdr)
+{
+	struct lnet_ioctl_config_data *conf =
+		(struct lnet_ioctl_config_data *)hdr;
+	int rc;
+
+	mutex_lock(&lnet_config_mutex);
+	if (the_lnet.ln_niinit_self)

Always consistently do error handling instead of success handling.

	if (!the_lnet.ln_niinit_self) {
		rc = -EINVAL;
		goto unlock;
	}
Quoted 8 lines
drivers/staging/lustre/lnet/lnet/module.c +8 -0
+		rc = lnet_dyn_del_ni(conf->cfg_net);
+	else
+		rc = -EINVAL;
+	mutex_unlock(&lnet_config_mutex);
+
+	return rc;
+}
+

drivers/staging/lustre/lnet/lnet/module.c lnet_unconfigure(void) · line 137

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/module.c +3 -1
 static int
 lnet_ioctl(unsigned int cmd, struct libcfs_ioctl_hdr *hdr)
 {
 	int rc;
 
 	switch (cmd) {
-	case IOC_LIBCFS_CONFIGURE:
+	case IOC_LIBCFS_CONFIGURE: {
+		struct libcfs_ioctl_data *data =
+			(struct libcfs_ioctl_data *)hdr;

ioc_len.

drivers/staging/lustre/lnet/lnet/module.c lnet_unconfigure(void) · line 149

Quoted 13 lines
drivers/staging/lustre/lnet/lnet/module.c +6 -1
+		the_lnet.ln_nis_from_mod_params = data->ioc_flags;
 		return lnet_configure(NULL);
+	}
 
 	case IOC_LIBCFS_UNCONFIGURE:
 		return lnet_unconfigure();
 
 	case IOC_LIBCFS_ADD_NET:
-		return LNetCtl(cmd, hdr);
+		return lnet_dyn_configure(hdr);
+
+	case IOC_LIBCFS_DEL_NET:
+		return lnet_dyn_unconfigure(hdr);

ioc_len etc.

Quoted 19 lines
drivers/staging/lustre/lnet/lnet/module.c +0 -0
 	default:
 		/* Passing LNET_PID_ANY only gives me a ref if the net is up
drivers/staging/lustre/lnet/lnet/peer.c +3 -5
index 1402e27..3b71812 100644
@@ -394,16 +394,18 @@ lnet_debug_peer(lnet_nid_t nid)
 	lnet_net_unlock(cpt);
 }
 
-int lnet_get_peers(int count, __u64 *nid, char *aliveness,
-		   int *ncpt, int *refcount,
-		   int *ni_peer_tx_credits, int *peer_tx_credits,
-		   int *peer_rtr_credits, int *peer_min_rtr_credits,
-		   int *peer_tx_qnob)
+int
+lnet_get_peer_info(__u32 peer_index, __u64 *nid,
+		   char aliveness[LNET_MAX_STR_LEN],

drivers/staging/lustre/lnet/lnet/peer.c lnet_debug_peer(lnet_nid_t nid) · line 407

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/peer.c +5 -2
+		   __u32 *cpt_iter, __u32 *refcount,
+		   __u32 *ni_peer_tx_credits, __u32 *peer_tx_credits,
+		   __u32 *peer_rtr_credits, __u32 *peer_min_rtr_credits,
+		   __u32 *peer_tx_qnob)
 {
 	struct lnet_peer_table *peer_table;
 	lnet_peer_t *lp;
-	int j;
-	int lncpt, found = 0;
+	bool found = false;

Unrelated.

drivers/staging/lustre/lnet/lnet/peer.c int lnet_get_peers(int count, __u64 *nid, char *aliveness, · line 418

Quoted 12 lines
drivers/staging/lustre/lnet/lnet/peer.c +3 -2
+	int lncpt, j;
 
 	/* get the number of CPTs */
 	lncpt = cfs_percpt_number(the_lnet.ln_peer_tables);
@@ -412,22 +414,22 @@ int lnet_get_peers(int count, __u64 *nid, char *aliveness,
 	 * if the cpt number to be examined is >= the number of cpts in
 	 * the system then indicate that there are no more cpts to examin
 	 */
-	if (*ncpt > lncpt)
-		return -1;
+	if (*cpt_iter > lncpt)
+		return -ENOENT;

Don't mix unrelated changes.

Quoted 42 lines
drivers/staging/lustre/lnet/lnet/peer.c +7 -7
 	/* get the current table */
-	peer_table = the_lnet.ln_peer_tables[*ncpt];
+	peer_table = the_lnet.ln_peer_tables[*cpt_iter];
 	/* if the ptable is NULL then there are no more cpts to examine */
 	if (!peer_table)
-		return -1;
+		return -ENOENT;
 
-	lnet_net_lock(*ncpt);
+	lnet_net_lock(*cpt_iter);
 
 	for (j = 0; j < LNET_PEER_HASH_SIZE && !found; j++) {
 		struct list_head *peers = &peer_table->pt_hash[j];
 
 		list_for_each_entry(lp, peers, lp_hashlist) {
-			if (count-- > 0)
+			if (peer_index-- > 0)
 				continue;
 
 			snprintf(aliveness, LNET_MAX_STR_LEN, "NA");
@@ -444,12 +446,12 @@ int lnet_get_peers(int count, __u64 *nid, char *aliveness,
 			*peer_min_rtr_credits = lp->lp_mintxcredits;
 			*peer_tx_qnob = lp->lp_txqnob;
 
-			found = 1;
+			found = true;
 		}
 	}
-	lnet_net_unlock(*ncpt);
+	lnet_net_unlock(*cpt_iter);
 
-	*ncpt = lncpt;
+	*cpt_iter = lncpt;
 
 	return found ? 0 : -ENOENT;
 }
drivers/staging/lustre/lnet/lnet/router.c +0 -0
index 749085f..17e6795 100644

drivers/staging/lustre/lnet/lnet/router.c lnet_destroy_routes(void) · line 549

Quoted 9 lines
drivers/staging/lustre/lnet/lnet/router.c +6 -0
@@ -541,6 +541,42 @@ lnet_destroy_routes(void)
 	lnet_del_route(LNET_NIDNET(LNET_NID_ANY), LNET_NID_ANY);
 }
 
+int lnet_get_rtr_pool_cfg(int idx, struct lnet_ioctl_pool_cfg *pool_cfg)
+{
+	int i, rc = -ENOENT, lidx, j;
+
+	if (!the_lnet.ln_rtrpools)
+		return rc;

Use literals where ever possible.

		return -ENOENT;

drivers/staging/lustre/lnet/lnet/router.c lnet_destroy_routes(void) · line 557

Quoted 8 lines
drivers/staging/lustre/lnet/lnet/router.c +8 -0
+
+	for (i = 0; i < LNET_NRBPOOLS; i++) {
+		lnet_rtrbufpool_t *rbp;
+
+		lnet_net_lock(LNET_LOCK_EX);
+		lidx = idx;
+		cfs_percpt_for_each(rbp, j, the_lnet.ln_rtrpools) {
+			if (lidx-- == 0) {

Flip this around so you're not smooshed against the right side of the screen.

			if (i++ != idx)
				continue;

Don't modify the original parameter. That way you can use it again and also it makes the code easier to understand.

drivers/staging/lustre/lnet/lnet/router.c lnet_destroy_routes(void) · line 558

Quoted 1 line
drivers/staging/lustre/lnet/lnet/router.c +1 -0
+				rc = 0;

Put the rc = 0 at the end next to the break. rc is used by the return keep them near together so that the code is easier to understand.

Quoted 43 lines
drivers/staging/lustre/lnet/lnet/router.c +23 -6
+				pool_cfg->pl_pools[i].pl_npages =
+					rbp[i].rbp_npages;
+				pool_cfg->pl_pools[i].pl_nbuffers =
+					rbp[i].rbp_nbuffers;
+				pool_cfg->pl_pools[i].pl_credits =
+					rbp[i].rbp_credits;
+				pool_cfg->pl_pools[i].pl_mincredits =
+					rbp[i].rbp_mincredits;
+				break;
+			}
+		}
+		lnet_net_unlock(LNET_LOCK_EX);
+	}
+
+	lnet_net_lock(LNET_LOCK_EX);
+	pool_cfg->pl_routing = the_lnet.ln_routing;
+	lnet_net_unlock(LNET_LOCK_EX);
+
+	return rc;
+}
+
 int
 lnet_get_route(int idx, __u32 *net, __u32 *hops,
 	       lnet_nid_t *gateway, __u32 *alive, __u32 *priority)
@@ -1531,8 +1567,8 @@ lnet_rtrpools_alloc(int im_a_router)
 	return rc;
 }
 
-int
-lnet_rtrpools_adjust(int tiny, int small, int large)
+static int
+lnet_rtrpools_adjust_helper(int tiny, int small, int large)
 {
 	int nrb = 0;
 	int rc = 0;
@@ -1540,19 +1576,10 @@ lnet_rtrpools_adjust(int tiny, int small, int large)
 	lnet_rtrbufpool_t *rtrp;
 
 	/*
-	 * this function doesn't revert the changes if adding new buffers
-	 * failed.  It's up to the user space caller to revert the
-	 * changes.
-	 */

drivers/staging/lustre/lnet/lnet/router.c lnet_rtrpools_adjust(int tiny, int small, int large) · line 1582

Quoted 10 lines
drivers/staging/lustre/lnet/lnet/router.c +1 -6
-
-	if (!the_lnet.ln_routing)
-		return 0;
-
-	/*
 	 * If the provided values for each buffer pool are different than the
 	 * configured values, we need to take action.
 	 */
-	if (tiny >= 0 && tiny != tiny_router_buffers) {
+	if (tiny >= 0) {

Unrelated cleanups. And below.

regards,
dan carpenter

#32 lore raw

PATCH 16/40 staging: lustre: make local functions static for LNet ni

In reply to James Simmons

From: frank zago <[email protected]>

This reduces the code size by about 400 bytes.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5396
Reviewed-on: http://review.whamcloud.com/11306

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    3 ---
 drivers/staging/lustre/lnet/lnet/api-ni.c          |   10 +++++++---
 2 files changed, 7 insertions(+), 6 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +0 -3
index 63919dd..874af17 100644
@@ -690,9 +690,6 @@ void lnet_router_checker_stop(void);
 void lnet_router_ni_update_locked(lnet_peer_t *gw, __u32 net);
 void lnet_swap_pinginfo(lnet_ping_info_t *info);
 
-int lnet_ping(lnet_process_id_t id, int timeout_ms,
-	      lnet_process_id_t *ids, int n_ids);
-
 int lnet_parse_ip2nets(char **networksp, char *ip2nets);
 int lnet_parse_routes(char *route_str, int *im_a_router);
 int lnet_parse_networks(struct list_head *nilist, char *networks);
drivers/staging/lustre/lnet/lnet/api-ni.c +7 -3
index 125d018..3b2bfd5 100644
@@ -62,6 +62,10 @@ static int rnet_htable_size = LNET_REMOTE_NETS_HASH_DEFAULT;
 module_param(rnet_htable_size, int, 0444);
 MODULE_PARM_DESC(rnet_htable_size, "size of remote network hash table");
 
+static void lnet_ping_target_fini(void);
+static int lnet_ping(lnet_process_id_t id, int timeout_ms,
+		     lnet_process_id_t *ids, int n_ids);
+
 static char *
 lnet_get_routes(void)
 {
@@ -520,7 +524,7 @@ lnet_res_lh_initialize(struct lnet_res_container *rec, lnet_libhandle_t *lh)
 	list_add(&lh->lh_hash_chain, &rec->rec_lh_hash[hash]);
 }
 
-int lnet_unprepare(void);
+static int lnet_unprepare(void);
 
 static int
 lnet_prepare(lnet_pid_t requested_pid)
@@ -606,7 +610,7 @@ lnet_prepare(lnet_pid_t requested_pid)
 	return rc;
 }
 
-int
+static int
 lnet_unprepare(void)
 {
 	/* NB no LNET_LOCK since this is the last reference.  All LND instances
@@ -2080,7 +2084,7 @@ LNetSnprintHandle(char *str, int len, lnet_handle_any_t h)
 }
 EXPORT_SYMBOL(LNetSnprintHandle);
 
-int
+static int
 lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t *ids, int n_ids)
 {
 	lnet_handle_eq_t eqh;
Signature · 1 line
1.7.1
#33 lore raw

PATCH 17/40 staging: lustre: add sparse annotation __user wherever needed for lnet

In reply to James Simmons

From: frank zago <[email protected]>

This fixes sparse warnings such as:

.../api-ni.c:1639:33: warning: incorrect type in argument 3
(different address spaces)
.../api-ni.c:1639:33: expected struct lnet_process_id_t

                                 [noderef] [usertype] <asn:1>*ids

.../api-ni.c:1639:33: got struct lnet_process_id_t
[usertype] *<noident>

There is no code change.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5396
Reviewed-on: http://review.whamcloud.com/11819

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    9 +-
 drivers/staging/lustre/include/linux/lnet/lnetst.h |   96 ++++++++++----------
 drivers/staging/lustre/lnet/lnet/api-ni.c          |    5 +-
 drivers/staging/lustre/lnet/selftest/conrpc.c      |    4 +-
 drivers/staging/lustre/lnet/selftest/conrpc.h      |    5 +-
 drivers/staging/lustre/lnet/selftest/console.c     |   91 ++++++++++---------
 drivers/staging/lustre/lnet/selftest/console.h     |   54 ++++++-----
 7 files changed, 140 insertions(+), 124 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +5 -4
index 874af17..a1f94db 100644
@@ -602,7 +602,7 @@ void lnet_copy_kiov2kiov(unsigned int ndkiov, lnet_kiov_t *dkiov,
 			  unsigned int soffset, unsigned int nob);
 
 static inline void
-lnet_copy_iov2flat(int dlen, void *dest, unsigned int doffset,
+lnet_copy_iov2flat(int dlen, void __user *dest, unsigned int doffset,
 		   unsigned int nsiov, struct kvec *siov, unsigned int soffset,
 		   unsigned int nob)
 {
@@ -613,7 +613,7 @@ lnet_copy_iov2flat(int dlen, void *dest, unsigned int doffset,
 }
 
 static inline void
-lnet_copy_kiov2flat(int dlen, void *dest, unsigned int doffset,
+lnet_copy_kiov2flat(int dlen, void __user *dest, unsigned int doffset,
 		    unsigned int nsiov, lnet_kiov_t *skiov,
 		    unsigned int soffset, unsigned int nob)
 {
@@ -625,7 +625,8 @@ lnet_copy_kiov2flat(int dlen, void *dest, unsigned int doffset,
 
 static inline void
 lnet_copy_flat2iov(unsigned int ndiov, struct kvec *diov, unsigned int doffset,
-		   int slen, void *src, unsigned int soffset, unsigned int nob)
+		   int slen, void __user *src, unsigned int soffset,
+		   unsigned int nob)
 {
 	struct kvec siov = {/*.iov_base = */ src, /*.iov_len = */slen};
 
@@ -635,7 +636,7 @@ lnet_copy_flat2iov(unsigned int ndiov, struct kvec *diov, unsigned int doffset,
 
 static inline void
 lnet_copy_flat2kiov(unsigned int ndiov, lnet_kiov_t *dkiov,
-		    unsigned int doffset, int slen, void *src,
+		    unsigned int doffset, int slen, void __user *src,
 		    unsigned int soffset, unsigned int nob)
 {
 	struct kvec siov = {/* .iov_base = */ src, /* .iov_len = */ slen};
drivers/staging/lustre/include/linux/lnet/lnetst.h +48 -48

229 lines not on this page · raw message

drivers/staging/lustre/lnet/lnet/api-ni.c +3 -2
index 3b2bfd5..acc216e 100644
@@ -1982,7 +1982,7 @@ LNetCtl(unsigned int cmd, void *arg)
 		id.nid = data->ioc_nid;
 		id.pid = data->ioc_u32[0];
 		rc = lnet_ping(id, data->ioc_u32[1], /* timeout */
-			       (lnet_process_id_t *)data->ioc_pbuf1,
+			       (lnet_process_id_t __user *)data->ioc_pbuf1,
 			       data->ioc_plen1/sizeof(lnet_process_id_t));
 		if (rc < 0)
 			return rc;
@@ -2085,7 +2085,8 @@ LNetSnprintHandle(char *str, int len, lnet_handle_any_t h)
 EXPORT_SYMBOL(LNetSnprintHandle);
 
 static int
-lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t *ids, int n_ids)
+lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t __user *ids,
+	  int n_ids)
 {
 	lnet_handle_eq_t eqh;
 	lnet_handle_md_t mdh;
drivers/staging/lustre/lnet/selftest/conrpc.c +2 -2
index 1066c70..15a61de 100644
@@ -466,11 +466,11 @@ lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans, lstcon_trans_stat_t *stat)
 
 int
 lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
-			     struct list_head *head_up,
+			     struct list_head __user *head_up,
 			     lstcon_rpc_readent_func_t readent)
 {
 	struct list_head tmp;
-	struct list_head *next;
+	struct list_head __user *next;
 	lstcon_rpc_ent_t *ent;
 	srpc_generic_reply_t *rep;
 	lstcon_rpc_t *crpc;
drivers/staging/lustre/lnet/selftest/conrpc.h +3 -2
index 95c832f..d2133bc 100644
@@ -106,7 +106,8 @@ typedef struct lstcon_rpc_trans {
 #define LST_TRANS_STATQRY       0x21
 
 typedef int (*lstcon_rpc_cond_func_t)(int, struct lstcon_node *, void *);
-typedef int (*lstcon_rpc_readent_func_t)(int, srpc_msg_t *, lstcon_rpc_ent_t *);
+typedef int (*lstcon_rpc_readent_func_t)(int, srpc_msg_t *,
+					 lstcon_rpc_ent_t __user *);
 
 int  lstcon_sesrpc_prep(struct lstcon_node *nd, int transop,
 			unsigned version, lstcon_rpc_t **crpc);
@@ -128,7 +129,7 @@ int  lstcon_rpc_trans_ndlist(struct list_head *ndlist,
 void lstcon_rpc_trans_stat(lstcon_rpc_trans_t *trans,
 			   lstcon_trans_stat_t *stat);
 int  lstcon_rpc_trans_interpreter(lstcon_rpc_trans_t *trans,
-				  struct list_head *head_up,
+				  struct list_head __user *head_up,
 				  lstcon_rpc_readent_func_t readent);
 void lstcon_rpc_trans_abort(lstcon_rpc_trans_t *trans, int error);
 void lstcon_rpc_trans_destroy(lstcon_rpc_trans_t *trans);
drivers/staging/lustre/lnet/selftest/console.c +49 -42

259 lines not on this page · raw message

drivers/staging/lustre/lnet/selftest/console.h +30 -24

77 lines not on this page · raw message

Signature · 1 line
1.7.1
#34 lore raw

PATCH 18/40 staging: lustre: remove LUSTRE_{,SRV_}LNET_PID

In reply to James Simmons

From: John L. Hammond <[email protected]>

Remove LUSTRE_LNET_PID (12354) and LUSTRE_SRV_LNET_PID (12345) from the libcfs headers and replace their uses with a new macro LNET_PID_LUSTRE (also 12345) in lnet/types.h.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2675
Reviewed-on: http://review.whamcloud.com/11985

---
 .../staging/lustre/include/linux/libcfs/libcfs.h   |    2 --
 .../lustre/include/linux/libcfs/linux/libcfs.h     |    3 ---
 .../staging/lustre/lnet/klnds/socklnd/socklnd.c    |    7 +++++--
 drivers/staging/lustre/lnet/lnet/api-ni.c          |    2 +-
 drivers/staging/lustre/lnet/lnet/lib-move.c        |    2 +-
 drivers/staging/lustre/lnet/lnet/module.c          |    4 ++--
 drivers/staging/lustre/lnet/lnet/router.c          |    2 +-
 drivers/staging/lustre/lnet/selftest/rpc.c         |    2 +-
 drivers/staging/lustre/lustre/ptlrpc/events.c      |    4 ++--
 9 files changed, 13 insertions(+), 15 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs.h +0 -2
index 4d74e8a..1cca6c7 100644
@@ -58,8 +58,6 @@ static inline int __is_po2(unsigned long long val)
 #define LERRCHKSUM(hexnum) (((hexnum) & 0xf) ^ ((hexnum) >> 4 & 0xf) ^ \
 			   ((hexnum) >> 8 & 0xf))
 
-#define LUSTRE_SRV_LNET_PID      LUSTRE_LNET_PID
-
 #include <linux/list.h>
 
 /* need both kernel and user-land acceptor */
drivers/staging/lustre/include/linux/libcfs/linux/libcfs.h +0 -3
index aac5900..d94b266 100644
@@ -118,9 +118,6 @@ do {								    \
 #define CDEBUG_STACK() (0L)
 #endif /* __x86_64__ */
 
-/* initial pid  */
-#define LUSTRE_LNET_PID	  12345
-
 #define __current_nesting_level() (0)
 
 /**
drivers/staging/lustre/lnet/klnds/socklnd/socklnd.c +5 -2
index ebde036..6b88902 100644
@@ -1788,7 +1788,10 @@ ksocknal_query(lnet_ni_t *ni, lnet_nid_t nid, unsigned long *when)
 	unsigned long now = cfs_time_current();
 	ksock_peer_t *peer = NULL;
 	rwlock_t *glock = &ksocknal_data.ksnd_global_lock;
-	lnet_process_id_t id = {.nid = nid, .pid = LUSTRE_SRV_LNET_PID};
+	lnet_process_id_t id = {
+		.nid = nid,
+		.pid = LNET_PID_LUSTRE,
+	};
 
 	read_lock(glock);
 
@@ -2136,7 +2139,7 @@ ksocknal_ctl(lnet_ni_t *ni, unsigned int cmd, void *arg)
 
 	case IOC_LIBCFS_ADD_PEER:
 		id.nid = data->ioc_nid;
-		id.pid = LUSTRE_SRV_LNET_PID;
+		id.pid = LNET_PID_LUSTRE;
 		return ksocknal_add_peer(ni, id,
 					  data->ioc_u32[0], /* IP */
 					  data->ioc_u32[1]); /* port */
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -1
index acc216e..949fa2f 100644
@@ -2114,7 +2114,7 @@ lnet_ping(lnet_process_id_t id, int timeout_ms, lnet_process_id_t __user *ids,
 		return -EINVAL;
 
 	if (id.pid == LNET_PID_ANY)
-		id.pid = LUSTRE_SRV_LNET_PID;
+		id.pid = LNET_PID_LUSTRE;
 
 	LIBCFS_ALLOC(info, infosz);
 	if (info == NULL)
drivers/staging/lustre/lnet/lnet/lib-move.c +1 -1
index e1461af..b9388ed 100644
@@ -1388,7 +1388,7 @@ lnet_send(lnet_nid_t src_nid, lnet_msg_t *msg, lnet_nid_t rtr_nid)
 
 		msg->msg_target_is_router = 1;
 		msg->msg_target.nid = lp->lp_nid;
-		msg->msg_target.pid = LUSTRE_SRV_LNET_PID;
+		msg->msg_target.pid = LNET_PID_LUSTRE;
 	}
 
 	/* 'lp' is our best choice of peer */
drivers/staging/lustre/lnet/lnet/module.c +2 -2
index 281315c..48eb085 100644
@@ -53,7 +53,7 @@ lnet_configure(void *arg)
 	mutex_lock(&lnet_config_mutex);
 
 	if (!the_lnet.ln_niinit_self) {
-		rc = LNetNIInit(LUSTRE_SRV_LNET_PID);
+		rc = LNetNIInit(LNET_PID_LUSTRE);
 		if (rc >= 0) {
 			the_lnet.ln_niinit_self = 1;
 			rc = 0;
@@ -93,7 +93,7 @@ lnet_dyn_configure(struct libcfs_ioctl_hdr *hdr)
 
 	mutex_lock(&lnet_config_mutex);
 	if (the_lnet.ln_niinit_self)
-		rc = lnet_dyn_add_ni(LUSTRE_SRV_LNET_PID,
+		rc = lnet_dyn_add_ni(LNET_PID_LUSTRE,
 				     conf->cfg_config_u.cfg_net.net_intf,
 				     conf->cfg_config_u.cfg_net.
 					net_peer_timeout,
drivers/staging/lustre/lnet/lnet/router.c +1 -1
index 17e6795..1f5a4b1 100644
@@ -1009,7 +1009,7 @@ lnet_ping_router_locked(lnet_peer_t *rtr)
 		lnet_handle_md_t mdh;
 
 		id.nid = rtr->lp_nid;
-		id.pid = LUSTRE_SRV_LNET_PID;
+		id.pid = LNET_PID_LUSTRE;
 		CDEBUG(D_NET, "Check: %s\n", libcfs_id2str(id));
 
 		rtr->lp_ping_notsent   = 1;
drivers/staging/lustre/lnet/selftest/rpc.c +1 -1
index 86de680..2212199 100644
@@ -1587,7 +1587,7 @@ srpc_startup(void)
 
 	srpc_data.rpc_state = SRPC_STATE_NONE;
 
-	rc = LNetNIInit(LUSTRE_SRV_LNET_PID);
+	rc = LNetNIInit(LNET_PID_LUSTRE);
 	if (rc < 0) {
 		CERROR("LNetNIInit() has failed: %d\n", rc);
 		return rc;
drivers/staging/lustre/lustre/ptlrpc/events.c +2 -2
index 9c2fd34..2a0dfa5 100644
@@ -446,7 +446,7 @@ int ptlrpc_uuid_to_peer(struct obd_uuid *uuid,
 
 	portals_compatibility = LNetCtl(IOC_LIBCFS_PORTALS_COMPATIBILITY, NULL);
 
-	peer->pid = LUSTRE_SRV_LNET_PID;
+	peer->pid = LNET_PID_LUSTRE;
 
 	/* Choose the matching UUID that's closest */
 	while (lustre_uuid_to_peer(uuid->uuid, &dst_nid, count++) == 0) {
@@ -524,7 +524,7 @@ static lnet_pid_t ptl_get_pid(void)
 {
 	lnet_pid_t pid;
 
-	pid = LUSTRE_SRV_LNET_PID;
+	pid = LNET_PID_LUSTRE;
 	return pid;
 }
 
Signature · 1 line
1.7.1
#35 lore raw

PATCH 19/40 staging: lustre: copy out libcfs ioctl inline buffer

In reply to James Simmons

From: Liang Zhen <[email protected]>

- libcfs_ioctl_popdata should copy out inline buffers.
- code cleanup for libcfs ioctl handler
- error number fix for obd_ioctl_getdata
- add new function libcfs_ioctl_unpack for upcoming patches

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313

---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h     |   24 +++-
 drivers/staging/lustre/lnet/lnet/api-ni.c          |    2 +
 .../lustre/lustre/libcfs/linux/linux-module.c      |   45 +++++---
 drivers/staging/lustre/lustre/libcfs/module.c      |  119 ++++++++------------
 .../lustre/lustre/obdclass/linux/linux-module.c    |   17 +--
 5 files changed, 97 insertions(+), 110 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +19 -5
index f24330d..3468933 100644
@@ -49,6 +49,9 @@ struct libcfs_ioctl_hdr {
 	__u32 ioc_version;
 };
 
+/** max size to copy from userspace */
+#define LIBCFS_IOC_DATA_MAX	(128 * 1024)
+
 struct libcfs_ioctl_data {
 	struct libcfs_ioctl_hdr ioc_hdr;
 
@@ -240,11 +243,22 @@ static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
 
 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
-int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr *buf, __u32 buf_len,
-			 const void __user *arg);
-int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
-			     __u32 *buf_len);
-int libcfs_ioctl_popdata(void *arg, void *buf, int size);
+int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
+			 struct libcfs_ioctl_hdr __user *uparam);
+
+static inline int libcfs_ioctl_popdata(struct libcfs_ioctl_hdr *hdr,
+				       struct libcfs_ioctl_hdr __user *uparam)
+{
+	if (copy_to_user(uparam, hdr, hdr->ioc_len))
+		return -EFAULT;
+	return 0;
+}
+
+static inline void libcfs_ioctl_freedata(struct libcfs_ioctl_hdr *hdr)
+{
+	LIBCFS_FREE(hdr, hdr->ioc_len);
+}
+
 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
 
 #endif /* __LIBCFS_IOCTL_H__ */
drivers/staging/lustre/lnet/lnet/api-ni.c +2 -0
index 949fa2f..4c4e6d3 100644
@@ -1838,6 +1838,8 @@ LNetCtl(unsigned int cmd, void *arg)
 	int rc;
 	unsigned long secs_passed;
 
+	CLASSERT(sizeof(struct lnet_ioctl_net_config) +
+		 sizeof(struct lnet_ioctl_config_data) < LIBCFS_IOC_DATA_MAX);
 	LASSERT(the_lnet.ln_init);
 
 	switch (cmd) {
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +26 -19

72 lines not on this page · raw message

drivers/staging/lustre/lustre/libcfs/module.c +45 -74

161 lines not on this page · raw message

drivers/staging/lustre/lustre/obdclass/linux/linux-module.c +5 -12
index a055cbb..4e9b0c4 100644
@@ -74,14 +74,14 @@
 #include "../../include/lustre/lustre_build_version.h"
 
 /* buffer MUST be at least the size of obd_ioctl_hdr */
-int obd_ioctl_getdata(char **buf, int *len, void *arg)
+int obd_ioctl_getdata(char **buf, int *len, void __user *arg)
 {
 	struct obd_ioctl_hdr hdr;
 	struct obd_ioctl_data *data;
 	int err;
 	int offset = 0;
 
-	if (copy_from_user(&hdr, (void *)arg, sizeof(hdr)))
+	if (copy_from_user(&hdr, arg, sizeof(hdr)))
 		return -EFAULT;
 
 	if (hdr.ioc_version != OBD_IOCTL_VERSION) {
@@ -114,14 +114,10 @@ int obd_ioctl_getdata(char **buf, int *len, void *arg)
 	*len = hdr.ioc_len;
 	data = (struct obd_ioctl_data *)*buf;
 
-	if (copy_from_user(*buf, (void *)arg, hdr.ioc_len)) {
+	if (copy_from_user(*buf, arg, hdr.ioc_len)) {
 		err = -EFAULT;
 		goto free_buf;
 	}
-	if (hdr.ioc_len != data->ioc_len) {
-		err = -EINVAL;
-		goto free_buf;
-	}
 
 	if (obd_ioctl_is_invalid(data)) {
 		CERROR("ioctl not correctly formatted\n");
@@ -144,9 +140,8 @@ int obd_ioctl_getdata(char **buf, int *len, void *arg)
 		offset += cfs_size_round(data->ioc_inllen3);
 	}
 
-	if (data->ioc_inllen4) {
+	if (data->ioc_inllen4)
 		data->ioc_inlbuf4 = &data->ioc_bulk[0] + offset;
-	}
 
 	return 0;
 
@@ -160,9 +155,7 @@ int obd_ioctl_popdata(void *arg, void *data, int len)
 {
 	int err;
 
-	err = copy_to_user(arg, data, len);
-	if (err)
-		err = -EFAULT;
+	err = copy_to_user(arg, data, len) ? -EFAULT : 0;
 	return err;
 }
 EXPORT_SYMBOL(obd_ioctl_popdata);
Signature · 1 line
1.7.1
#36 lore raw

Re: [PATCH 19/40] staging: lustre: copy out libcfs ioctl inline buffer

Quoted 7 lines · James Simmons

From: Liang Zhen <[email protected]>

- libcfs_ioctl_popdata should copy out inline buffers.
- code cleanup for libcfs ioctl handler
- error number fix for obd_ioctl_getdata
- add new function libcfs_ioctl_unpack for upcoming patches

Without looking at the patch, I can already tell you it should be four separate patches instead of one. Don't mix bug fixes and cleanups. This should not be a new rule for anyone.

Guys, what the actual heck is going on??? This patchset is making me really depressed and I'm not even half way through.

Quoted 37 lines

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5435
Reviewed-on: http://review.whamcloud.com/11313

---
 .../lustre/include/linux/libcfs/libcfs_ioctl.h     |   24 +++-
 drivers/staging/lustre/lnet/lnet/api-ni.c          |    2 +
 .../lustre/lustre/libcfs/linux/linux-module.c      |   45 +++++---
 drivers/staging/lustre/lustre/libcfs/module.c      |  119 ++++++++------------
 .../lustre/lustre/obdclass/linux/linux-module.c    |   17 +--
 5 files changed, 97 insertions(+), 110 deletions(-)
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +3 -5
index f24330d..3468933 100644
@@ -49,6 +49,9 @@ struct libcfs_ioctl_hdr {
 	__u32 ioc_version;
 };
 
+/** max size to copy from userspace */
+#define LIBCFS_IOC_DATA_MAX	(128 * 1024)
+
 struct libcfs_ioctl_data {
 	struct libcfs_ioctl_hdr ioc_hdr;
 
@@ -240,11 +243,22 @@ static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
 
 int libcfs_register_ioctl(struct libcfs_ioctl_handler *hand);
 int libcfs_deregister_ioctl(struct libcfs_ioctl_handler *hand);
-int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr *buf, __u32 buf_len,
-			 const void __user *arg);
-int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
-			     __u32 *buf_len);
-int libcfs_ioctl_popdata(void *arg, void *buf, int size);

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data) · line 255

Quoted 10 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +10 -0
+int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
+			 struct libcfs_ioctl_hdr __user *uparam);
+
+static inline int libcfs_ioctl_popdata(struct libcfs_ioctl_hdr *hdr,
+				       struct libcfs_ioctl_hdr __user *uparam)
+{
+	if (copy_to_user(uparam, hdr, hdr->ioc_len))
+		return -EFAULT;
+	return 0;
+}

No. Don't do this.

drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h static inline bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data) · line 260

Quoted 5 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +5 -0
+
+static inline void libcfs_ioctl_freedata(struct libcfs_ioctl_hdr *hdr)
+{
+	LIBCFS_FREE(hdr, hdr->ioc_len);
+}

No. We need to transition to kmalloc() and kfree() instead of adding even more abstraction layers. In this patchset we add new calls to ALLOC() when we should be using normal kernel functions like kstrdup() but we can't because then we wouldn't have a size parameter to pass to LIBCFS_FREE().

Quoted 9 lines
drivers/staging/lustre/include/linux/libcfs/libcfs_ioctl.h +1 -0
+
 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data);
 
 #endif /* __LIBCFS_IOCTL_H__ */
drivers/staging/lustre/lnet/lnet/api-ni.c +0 -0
index 949fa2f..4c4e6d3 100644

drivers/staging/lustre/lnet/lnet/api-ni.c LNetCtl(unsigned int cmd, void *arg) · line 1842

Quoted 5 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +2 -0
@@ -1838,6 +1838,8 @@ LNetCtl(unsigned int cmd, void *arg)
 	int rc;
 	unsigned long secs_passed;
 
+	CLASSERT(sizeof(struct lnet_ioctl_net_config) +
+		 sizeof(struct lnet_ioctl_config_data) < LIBCFS_IOC_DATA_MAX);

BUILD_BUG_ON().

Quoted 35 lines
drivers/staging/lustre/lnet/lnet/api-ni.c +0 -0
 	LASSERT(the_lnet.ln_init);
 
 	switch (cmd) {
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +5 -5
index 1c31e2e..50a5464 100644
@@ -43,7 +43,7 @@
 int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data)
 {
 	if (libcfs_ioctl_is_invalid(data)) {
-		CERROR("LNET: ioctl not correctly formatted\n");
+		CERROR("libcfs ioctl: parameter not correctly formatted\n");
 		return -EINVAL;
 	}
 
@@ -57,39 +57,46 @@ int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data)
 	return 0;
 }
 
-int libcfs_ioctl_getdata_len(const struct libcfs_ioctl_hdr __user *arg,
-			     __u32 *len)
+int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
+			 struct libcfs_ioctl_hdr __user *uhdr)
 {
 	struct libcfs_ioctl_hdr hdr;
+	int err = 0;
 
-	if (copy_from_user(&hdr, arg, sizeof(hdr)))
+	if (copy_from_user(&hdr, uhdr, sizeof(hdr)))
 		return -EFAULT;
 
 	if (hdr.ioc_version != LIBCFS_IOCTL_VERSION &&
 	    hdr.ioc_version != LIBCFS_IOCTL_VERSION2) {
-		CERROR("LNET: version mismatch expected %#x, got %#x\n",

drivers/staging/lustre/lustre/libcfs/linux/linux-module.c int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data) · line 79

Quoted 10 lines
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +5 -1
+		CERROR("libcfs ioctl: version mismatch expected %#x, got %#x\n",
 		       LIBCFS_IOCTL_VERSION, hdr.ioc_version);
 		return -EINVAL;
 	}
 
-	*len = hdr.ioc_len;
+	if (hdr.ioc_len < sizeof(struct libcfs_ioctl_data)) {
+		CERROR("libcfs ioctl: user buffer too small for ioctl\n");
+		return -EINVAL;
+	}

It's sort of good to check here, but we will need to add all the other checks I mentioned as well. Also don't fix introduce bugs and fix them in the same patchset, the fix has to be folded into the buggy patch.

Quoted 14 lines
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +5 -7
-	return 0;
-}
+	if (hdr.ioc_len > LIBCFS_IOC_DATA_MAX) {
+		CERROR("libcfs ioctl: user buffer is too large %d/%d\n",
+		       hdr.ioc_len, LIBCFS_IOC_DATA_MAX);
+		return -EINVAL;
+	}
 
-int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr *buf, __u32 buf_len,
-			  const void __user *arg)
-{
-	if (copy_from_user(buf, arg, buf_len))
-		return -EFAULT;

drivers/staging/lustre/lustre/libcfs/linux/linux-module.c int libcfs_ioctl_data_adjust(struct libcfs_ioctl_data *data) · line 94

Quoted 10 lines
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +8 -2
-	return 0;
-}
+	LIBCFS_ALLOC(*hdr_pp, hdr.ioc_len);
+	if (!*hdr_pp)
+		return -ENOMEM;
+
+	if (copy_from_user(*hdr_pp, uhdr, hdr.ioc_len)) {
+		err = -EFAULT;
+		goto failed;
+	}

We still need to re-check hdr.ioc_len after re-reading it from the user.

Anyway, break this patch up and I will review it properly.

regards,
dan carpenter

#37 lore raw

PATCH 20/40 staging: lustre: fix kernel crash when network failed to start

In reply to James Simmons

From: Amir Shehata <[email protected]>

When loading Lustre modules without proper network configuration, it always hit the following kernel panic:
LNetError: 105-4: Error -100 starting up LNI tcp
LNetError: 2145:0:(api-ni.c:823:lnet_unprepare()) ASSERTION( list_empty(&the_lnet.ln_nis) ) failed:
NetError: 2145:0:(api-ni.c:823:lnet_unprepare()) LBUG
Pid: 2145, comm: modprobe
x0aCall Trace:

[<ffffffffa044f853>] libcfs_debug_dumpstack+0x53/0x80 [libcfs]
[<ffffffffa044fdf5>] lbug_with_loc+0x45/0xc0 [libcfs]
[<ffffffffa04f3267>] lnet_unprepare+0x297/0x340 [lnet]
[<ffffffffa04f3b5c>] LNetNIInit+0x25c/0x3e0 [lnet]
[<ffffffff81061bc6>] ? put_online_cpus+0x56/0x80
[<ffffffffa0983000>] ? init_module+0x0/0x1000 [ptlrpc]
[<ffffffffa081310c>] ptlrpc_ni_init+0x2c/0x1a0 [ptlrpc]
[<ffffffffa0983000>] ? init_module+0x0/0x1000 [ptlrpc]
[<ffffffffa0813291>] ptlrpc_init_portals+0x11/0xf0 [ptlrpc]
[<ffffffffa0983000>] ? init_module+0x0/0x1000 [ptlrpc]
[<ffffffffa09831c4>] init_module+0x1c4/0x1000 [ptlrpc]
[<ffffffff810020e2>] do_one_initcall+0xe2/0x190
[<ffffffff810ca7fb>] load_module+0x129b/0x1a90
[<ffffffff812da590>] ? ddebug_dyndbg_module_param_cb+0x0/0x60
[<ffffffff810c7133>] ? copy_module_from_fd.isra.43+0x53/0x150
[<ffffffff810cb1a6>] SyS_finit_module+0xa6/0xd0
[<ffffffff815f2119>] system_call_fastpath+0x16/0x1b

...
This is because in lnet_startup_lndnis(), we may add list items to @the_lnet.ln_nis and @the_lnet.ln_nis_cpt before it failed. But in lnet_startup_lndis() failure path,it did not cleanup list thus causing assertion in lnet_unprepare().

Fix the assertion by cleaning up using lnet_shutdown_lndnis() if the startup fails.

In a future enahancement the ni startup API will be modified to cleanup after itself in case of failure.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5568
Reviewed-on: http://review.whamcloud.com/12512

---
 drivers/staging/lustre/lnet/lnet/api-ni.c |    6 +++++-
 1 files changed, 5 insertions(+), 1 deletions(-)
drivers/staging/lustre/lnet/lnet/api-ni.c +5 -1
index 4c4e6d3..bfc1f13 100644
@@ -1246,6 +1246,10 @@ lnet_shutdown_lndni(__u32 net)
 	return 0;
 }
 
+/*
+ * Callers of lnet_startup_lndnis need to clean up using
+ * lnet_shutdown_lndnis if startup fails
+ */
 static int
 lnet_startup_lndnis(struct list_head *nilist, __s32 peer_timeout,
 		    __s32 peer_cr, __s32 peer_buf_cr, __s32 credits,
@@ -1554,7 +1558,7 @@ LNetNIInit(lnet_pid_t requested_pid)
 
 	rc = lnet_startup_lndnis(&net_head, -1, -1, -1, -1, &ni_count);
 	if (rc != 0)
-		goto failed1;
+		goto failed2;
 
 	if (the_lnet.ln_eq_waitni && ni_count > 1) {
 		lnd_type = the_lnet.ln_eq_waitni->ni_lnd->lnd_type;
Signature · 1 line
1.7.1
#38 lore raw

Re: [PATCH 20/40] staging: lustre: fix kernel crash when network failed to start

Fold this into the original patch. (Which you're going to have to redo anyway to fix the other bug and because of the GW-BASIC label names).

regards,
dan carpenter

#39 lore raw

PATCH 21/40 staging: lustre: improve LNet clean up code and API

In reply to James Simmons

From: Amir Shehata <[email protected]>

This patch addresses a set of related issues: LU-5734, LU-5839, LU-5849, LU-5850.

Create the local lnet_startup_lndni() API. This function starts up one LND. lnet_startup_lndnis() calls this function in a loop on every ni in the list passed in. lnet_startup_lndni() is responsible for cleaning up after itself in case of failure. It calls lnet_free_ni() if the ni fails to start. It calls lnet_shutdown_lndni() if it successfully called the lnd startup function, but fails later on.

lnet_startup_lndnis() also cleans up after itself. If lnet_startup_lndni() fails then lnet_shutdown_lndnis() is called to clean up all nis that might have been started, and then free the rest of the nis on the list which have not been started yet.

To facilitate the above changes lnet_dyn_del_ni() now manages the ping info. It calls lnet_shutdown_lndni(), to shutdown the NI. lnet_shutdown_lndni() is no longer an exposed API and doesn't manage the ping info, making it callable from lnet_startup_lndni() as well.

There are two scenarios for calling lnet_startup_lndni()

1. from lnet_startup_lndnis()
If lnet_startup_lndni() fails it requires to shutdown the ni without doing anything with the ping information as it hasn't been created yet.

2. from lnet_dyn_add_ni()
As above it will shutdown the ni, and then lnet_dyn_add_ni() will take care of managing the ping info

The second part of this change is to ensure that the LOLND is not added by lnet_parse_networks(), but the caller which needs to do it (IE: LNetNIInit)

This change ensures that lnet_dyn_add_ni() need only check if there is only one net that's being added, if not then it frees everything, otherwise it proceeds to startup the requested net.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5734
Reviewed-on: http://review.whamcloud.com/12658

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    2 +
 drivers/staging/lustre/lnet/lnet/api-ni.c          |  461 ++++++++++----------
 drivers/staging/lustre/lnet/lnet/config.c          |   14 +-
 3 files changed, 245 insertions(+), 232 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +2 -0
index a1f94db..4c2d824 100644
@@ -420,6 +420,8 @@ lnet_ni_decref(lnet_ni_t *ni)
 }
 
 void lnet_ni_free(lnet_ni_t *ni);
+lnet_ni_t *
+lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist);
 
 static inline int
 lnet_nid2peerhash(lnet_nid_t nid)
drivers/staging/lustre/lnet/lnet/api-ni.c +238 -223

586 lines not on this page · raw message

drivers/staging/lustre/lnet/lnet/config.c +5 -9
index d1e0217..7b7412b 100644
@@ -114,7 +114,7 @@ lnet_ni_free(struct lnet_ni *ni)
 	LIBCFS_FREE(ni, sizeof(*ni));
 }
 
-static lnet_ni_t *
+lnet_ni_t *
 lnet_ni_alloc(__u32 net, struct cfs_expr_list *el, struct list_head *nilist)
 {
 	struct lnet_tx_queue *tq;
@@ -191,6 +191,7 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 	struct lnet_ni *ni;
 	__u32 net;
 	int nnets = 0;
+	struct list_head *temp_node;
 
 	if (!networks) {
 		CERROR("networks string is undefined\n");
@@ -215,11 +216,6 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 	memcpy(tokens, networks, tokensize);
 	str = tmp = tokens;
 
-	/* Add in the loopback network */
-	ni = lnet_ni_alloc(LNET_MKNET(LOLND, 0), NULL, nilist);
-	if (ni == NULL)
-		goto failed;
-
 	while (str != NULL && *str != 0) {
 		char *comma = strchr(str, ',');
 		char *bracket = strchr(str, '(');
@@ -292,7 +288,6 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 			goto failed_syntax;
 		}
 
-		nnets++;
 		ni = lnet_ni_alloc(net, el, nilist);
 		if (ni == NULL)
 			goto failed;
@@ -370,10 +365,11 @@ lnet_parse_networks(struct list_head *nilist, char *networks)
 		}
 	}
 
-	LASSERT(!list_empty(nilist));
+	list_for_each(temp_node, nilist)
+		nnets++;
 
 	LIBCFS_FREE(tokens, tokensize);
-	return 0;
+	return nnets;
 
  failed_syntax:
 	lnet_syntax("networks", networks, (int)(tmp - tokens), strlen(tmp));
Signature · 1 line
1.7.1
#40 lore raw

Re: [PATCH 21/40] staging: lustre: improve LNet clean up code and API

Actually we're going to have to redo so much code that it's not worth it for me to review the rest of these patches. Please just look over everything again:

BAD: return -1;
GOOD: return -EINVAL;

BAD: failed0:
GOOD: free_something:

BAD: if (rc != 0)
GOOD: if (rc)

Do one thing per patch.
Do not introduce a bug and then fix it in a later patch. Check ioc_len more carefully.
Don't make the code look ugly just to please checkpatch.pl. Do error handling not success handling.
Try to avoid indenting a far to the right.

regards,
dan carpenter

#41 lore raw

Re: [lustre-devel] [PATCH 21/40] staging: lustre: improve LNet clean up code and API

Hello,

Quoted 4 lines · Dan Carpenter

Actually we're going to have to redo so much code that it's not worth it for me to review the rest of these patches. Please just look over everything again:

Quoted 8 lines

BAD: return -1;
GOOD: return -EINVAL;

BAD: failed0:
GOOD: free_something:

BAD: if (rc != 0)
GOOD: if (rc)

The latest suggestion is not correct,
from http://wiki.lustre.org/Lustre_Coding_Guidelines :
Conditional boolean (if (expr)), scalar (if (val != 0)) and pointer (if (ptr != NULL)) expressions should be written consistently.

Thanks,

Signature · 3 lines
Alexander Zarochentsev
Seagate Technology, LLC
www.seagate.com
#42 lore raw

Re: [lustre-devel] [PATCH 21/40] staging: lustre: improve LNet clean up code and API

Quoted 7 lines · Alexander Zarochentsev
Quoted 2 lines

BAD: if (rc != 0)
GOOD: if (rc)

The latest suggestion is not correct,
from http://wiki.lustre.org/Lustre_Coding_Guidelines :
Conditional boolean (if (expr)), scalar (if (val != 0)) and pointer (if (ptr != NULL)) expressions should be written consistently.

Kernel style trumps Lustre style. Double negative don't not hurt readability. != NULL is a checkpatch.pl warning. Also comparisons like == false or == true are checkpatch warnings.

I can think of two places where comparing with zero is appropriate and those are:

1) If you are talking about the numer zero.

	if (x == 0 || x == 2)

2) strcmp() and other *cmp() functions.

	if (strcmp(foo, bar) == 0)   /* foo and bar are the same */
	if (strcmp(foo, bar) < 0)    /* foo less than bar */
	if (strcmp(foo, bar) != 0)   /* foo not the same as bar */

For "if (rc) {" a zero return doesn't mean zero, it means success so comparing against zero is bad style.

regards,
dan carpenter

#43 lore raw

RE: [PATCH 21/40] staging: lustre: improve LNet clean up code and API

In reply to Dan Carpenter
Quoted 2 lines

Actually we're going to have to redo so much code that it's not worth it for me to review the rest of these patches.

Sorry I didn't get back to you sooner but I was on vacation. Thanks for reviewing this work. Especially since this is the first major bug fixing merge for the lustre client which means a lot of pain involved to iron out how to do this. I have been pondering if pushing bug fixes before style cleanups is the right thing to do. I pushed a bunch of bug fixes earlier and none got merged which either means Greg is just backed up and hasn't the time to merge them or style issues are higher priority. Assuming these bug fixes are in scope of the staging tree. Should I continue to push this work first? Well either way I should update this patch series so it ready to merge at some point.

Quoted 11 lines

Please just look over everything again:

BAD: return -1;
GOOD: return -EINVAL;

BAD:  failed0:
GOOD:  free_something:

BAD: if (rc != 0)
GOOD: if (rc)

Quoted 6 lines

Do one thing per patch.
Do not introduce a bug and then fix it in a later patch. Check ioc_len more carefully.
Don't make the code look ugly just to please checkpatch.pl. Do error handling not success handling.
Try to avoid indenting a far to the right.

Okay. Will start to do the patch cleanup.

#44 lore raw

Re: [PATCH 21/40] staging: lustre: improve LNet clean up code and API

Quoted 2 lines · James A.

I have been pondering if pushing bug fixes before style cleanups is the right thing to do.

Generally push the least controversial patches first so that if you have to redo one patch, then the rest are already applied and don't need to be changed.

Quoted 3 lines

I pushed a bunch of bug fixes earlier and none got
merged which either means Greg is just backed up and hasn't the time to merge them or style issues are higher priority

I have no idea which patchset you are talking about so I can't comment. Greg always (except if there is a mistake) applies things in first come first serve order. He doesn't sort them.

Quoted 2 lines

Assuming these bug fixes are in scope of the staging tree. Should I continue to push this work first?

You've pushed a bunch of stuff. I don't know which stuff has been applied and which has not. If no one replied to it and there isn't a dire issue such as a compile failure or it doesn't apply then Greg is likely to apply it. He doesn't silently patches, so you will get an email either way.

regards,
dan carpenter

#45 lore raw

PATCH 22/40 staging: lustre: Fixes to make lnetctl function as expected.

In reply to James Simmons

During testing of the lnetctl utility I ran into some issues. One of the problems is when you print out help for peer_credits you get help for stats. With this patch the help option for peer_credits is set to return the proper help message.

The second problem was for grabbing stats data. No data was returned but instead it reported a error. The reason for this is that libcfs_ioctl_getdata() test to see if the size of the data passed in is less than the struct libcfs_ioctl_data in size. For the stats function its data structure struct lnet_ioctl_lnet_stats is smaller than what is allowed. Instead of checking if the data is less than libcfs_ioctl_data in size we check to ensure that the data is not smaller than the ioctl hdr data which is universal.

The bug in libcfs_ioctl_getdata() exposed a bunch of cases with new ioctls that don't check to see if the data imported from userland equals the size reported in the ioctl hdr data. We address those cases in this patch as well.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5935
Reviewed-on: http://review.whamcloud.com/12782

---
 drivers/staging/lustre/lnet/lnet/api-ni.c          |   36 ++++++++++++++++++++
 .../lustre/lustre/libcfs/linux/linux-module.c      |    2 +-
 2 files changed, 37 insertions(+), 1 deletions(-)
drivers/staging/lustre/lnet/lnet/api-ni.c +36 -0
index e40c657..7657f88 100644
@@ -1872,6 +1872,10 @@ LNetCtl(unsigned int cmd, void *arg)
 
 	case IOC_LIBCFS_ADD_ROUTE:
 		config = arg;
+
+		if (config->cfg_hdr.ioc_len < sizeof(*config))
+			return -EINVAL;
+
 		mutex_lock(&the_lnet.ln_api_mutex);
 		rc = lnet_add_route(config->cfg_net,
 				    config->cfg_config_u.cfg_route.rtr_hop,
@@ -1883,6 +1887,10 @@ LNetCtl(unsigned int cmd, void *arg)
 
 	case IOC_LIBCFS_DEL_ROUTE:
 		config = arg;
+
+		if (config->cfg_hdr.ioc_len < sizeof(*config))
+			return -EINVAL;
+
 		mutex_lock(&the_lnet.ln_api_mutex);
 		rc = lnet_del_route(config->cfg_net, config->cfg_nid);
 		mutex_unlock(&the_lnet.ln_api_mutex);
@@ -1890,6 +1898,10 @@ LNetCtl(unsigned int cmd, void *arg)
 
 	case IOC_LIBCFS_GET_ROUTE:
 		config = arg;
+
+		if (config->cfg_hdr.ioc_len < sizeof(*config))
+			return -EINVAL;
+
 		return lnet_get_route(config->cfg_count,
 				      &config->cfg_net,
 				      &config->cfg_config_u.cfg_route.rtr_hop,
@@ -1900,8 +1912,13 @@ LNetCtl(unsigned int cmd, void *arg)
 
 	case IOC_LIBCFS_GET_NET: {
 		struct lnet_ioctl_net_config *net_config;
+		size_t total = sizeof(*config) + sizeof(*net_config);
 
 		config = arg;
+
+		if (config->cfg_hdr.ioc_len < total)
+			return -EINVAL;
+
 		net_config = (struct lnet_ioctl_net_config *)
 				config->cfg_bulk;
 		if (!config || !net_config)
@@ -1925,12 +1942,19 @@ LNetCtl(unsigned int cmd, void *arg)
 	{
 		struct lnet_ioctl_lnet_stats *lnet_stats = arg;
 
+		if (lnet_stats->st_hdr.ioc_len < sizeof(*lnet_stats))
+			return -EINVAL;
+
 		lnet_counters_get(&lnet_stats->st_cntrs);
 		return 0;
 	}
 
 	case IOC_LIBCFS_CONFIG_RTR:
 		config = arg;
+
+		if (config->cfg_hdr.ioc_len < sizeof(*config))
+			return -EINVAL;
+
 		mutex_lock(&the_lnet.ln_api_mutex);
 		if (config->cfg_config_u.cfg_buffers.buf_enable) {
 			rc = lnet_rtrpools_enable();
@@ -1943,6 +1967,10 @@ LNetCtl(unsigned int cmd, void *arg)
 
 	case IOC_LIBCFS_ADD_BUF:
 		config = arg;
+
+		if (config->cfg_hdr.ioc_len < sizeof(*config))
+			return -EINVAL;
+
 		mutex_lock(&the_lnet.ln_api_mutex);
 		rc = lnet_rtrpools_adjust(config->cfg_config_u.cfg_buffers.
 						buf_tiny,
@@ -1955,8 +1983,13 @@ LNetCtl(unsigned int cmd, void *arg)
 
 	case IOC_LIBCFS_GET_BUF: {
 		struct lnet_ioctl_pool_cfg *pool_cfg;
+		size_t total = sizeof(*config) + sizeof(*pool_cfg);
 
 		config = arg;
+
+		if (config->cfg_hdr.ioc_len < total)
+			return -EINVAL;
+
 		pool_cfg = (struct lnet_ioctl_pool_cfg *)config->cfg_bulk;
 		return lnet_get_rtr_pool_cfg(config->cfg_count, pool_cfg);
 	}
@@ -1964,6 +1997,9 @@ LNetCtl(unsigned int cmd, void *arg)
 	case IOC_LIBCFS_GET_PEER_INFO: {
 		struct lnet_ioctl_peer *peer_info = arg;
 
+		if (peer_info->pr_hdr.ioc_len < sizeof(*peer_info))
+			return -EINVAL;
+
 		return lnet_get_peer_info(peer_info->pr_count,
 			&peer_info->pr_nid,
 			peer_info->pr_lnd_u.pr_peer_credits.cr_aliveness,
drivers/staging/lustre/lustre/libcfs/linux/linux-module.c +1 -1
index 50a5464..9414746 100644
@@ -73,7 +73,7 @@ int libcfs_ioctl_getdata(struct libcfs_ioctl_hdr **hdr_pp,
 		return -EINVAL;
 	}
 
-	if (hdr.ioc_len < sizeof(struct libcfs_ioctl_data)) {
+	if (hdr.ioc_len < sizeof(struct libcfs_ioctl_hdr)) {
 		CERROR("libcfs ioctl: user buffer too small for ioctl\n");
 		return -EINVAL;
 	}
Signature · 1 line
1.7.1
#46 lore raw

PATCH 23/40 staging: lustre: return appropriate errno when adding route

In reply to James Simmons

From: Amir Shehata <[email protected]>

When adding route it ignored specific scenarios, namely:
1. route already exists
2. route is on a local net
3. route is unreacheable

This patch returns the appropriate return codes from the lower level function lnet_add_route(), and then ignores the above case from the calling function, lnet_parse_route(). This is needed so we don't halt processing routes in the module parameters.

However, we can now add routes dynamically, and it should be returned to the user whether adding the requested route succeeded or failed.

In userspace it is determined whether to continue adding routes or to halt processing. Currently "lnetctl import < config" continues adding the rest of the configuration and reports at the end which operations passed and which ones failed.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6045
Reviewed-on: http://review.whamcloud.com/13116

---
 drivers/staging/lustre/lnet/lnet/config.c |    2 +-
 drivers/staging/lustre/lnet/lnet/router.c |   11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)
drivers/staging/lustre/lnet/lnet/config.c +1 -1
index 7b7412b..1028195 100644
@@ -771,7 +771,7 @@ lnet_parse_route(char *str, int *im_a_router)
 			}
 
 			rc = lnet_add_route(net, hops, nid, priority);
-			if (rc != 0) {
+			if (rc != 0 && rc != -EEXIST && rc != -EHOSTUNREACH) {
 				CERROR("Can't create route to %s via %s\n",
 				       libcfs_net2str(net),
 				       libcfs_nid2str(nid));
drivers/staging/lustre/lnet/lnet/router.c +7 -4
index 1f5a4b1..9271be6 100644
@@ -315,7 +315,7 @@ lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway,
 		return -EINVAL;
 
 	if (lnet_islocalnet(net))	       /* it's a local network */
-		return 0;		       /* ignore the route entry */
+		return -EEXIST;
 
 	/* Assume net, route, all new */
 	LIBCFS_ALLOC(route, sizeof(*route));
@@ -346,7 +346,7 @@ lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway,
 		LIBCFS_FREE(rnet, sizeof(*rnet));
 
 		if (rc == -EHOSTUNREACH) /* gateway is not on a local net */
-			return 0;	/* ignore the route entry */
+			return rc;	/* ignore the route entry */
 		CERROR("Error %d creating route %s %d %s\n", rc,
 		       libcfs_net2str(net), hops,
 		       libcfs_nid2str(gateway));
@@ -394,14 +394,17 @@ lnet_add_route(__u32 net, unsigned int hops, lnet_nid_t gateway,
 	/* -1 for notify or !add_route */
 	lnet_peer_decref_locked(route->lr_gateway);
 	lnet_net_unlock(LNET_LOCK_EX);
+	rc = 0;
 
-	if (!add_route)
+	if (!add_route) {
+		rc = -EEXIST;
 		LIBCFS_FREE(route, sizeof(*route));
+	}
 
 	if (rnet != rnet2)
 		LIBCFS_FREE(rnet, sizeof(*rnet));
 
-	return 0;
+	return rc;
 }
 
 int
Signature · 1 line
1.7.1
#47 lore raw

PATCH 24/40 staging: lustre: make some lnet functions static

In reply to James Simmons

From: frank zago <[email protected]>

Some functions and variables are only used in their C file, so reduce their scope. This reduces the code size, and fixes sparse warnings such as:

warning: symbol 'proc_lnet_routes' was not declared.
Should it be static?
warning: symbol 'proc_lnet_routers' was not declared.
Should it be static?

Some prototypes were removed from C files and added to the proper header.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5396
Reviewed-on: http://review.whamcloud.com/12206

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    2 ++
 drivers/staging/lustre/lnet/lnet/router_proc.c     |    2 --
 drivers/staging/lustre/lnet/selftest/console.c     |    4 +---
 drivers/staging/lustre/lnet/selftest/framework.c   |   10 ----------
 drivers/staging/lustre/lnet/selftest/module.c      |    4 +---
 drivers/staging/lustre/lnet/selftest/rpc.c         |    2 +-
 6 files changed, 5 insertions(+), 19 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +2 -0
index 4c2d824..00ef4d0 100644
@@ -446,6 +446,8 @@ lnet_ni_t *lnet_nid2ni_locked(lnet_nid_t nid, int cpt);
 lnet_ni_t *lnet_net2ni_locked(__u32 net, int cpt);
 lnet_ni_t *lnet_net2ni(__u32 net);
 
+extern int portal_rotor;
+
 int lnet_init(void);
 void lnet_fini(void);
 
drivers/staging/lustre/lnet/lnet/router_proc.c +0 -2
index af7423f..73183f1 100644
@@ -795,8 +795,6 @@ static struct lnet_portal_rotors	portal_rotors[] = {
 	},
 };
 
-extern int portal_rotor;
-
 static int __proc_lnet_portal_rotor(void *data, int write,
 				    loff_t pos, void __user *buffer, int nob)
 {
drivers/staging/lustre/lnet/selftest/console.c +1 -3
index f8d6dfe..551d664 100644
@@ -1694,8 +1694,6 @@ lstcon_new_session_id(lst_sid_t *sid)
 	sid->ses_stamp = cfs_time_current();
 }
 
-extern srpc_service_t lstcon_acceptor_service;
-
 int
 lstcon_session_new(char *name, int key, unsigned feats,
 		   int timeout, int force, lst_sid_t __user *sid_up)
@@ -1974,7 +1972,7 @@ out:
 	return rc;
 }
 
-srpc_service_t lstcon_acceptor_service;
+static srpc_service_t lstcon_acceptor_service;
 static void lstcon_init_acceptor_service(void)
 {
 	/* initialize selftest console acceptor service table */
drivers/staging/lustre/lnet/selftest/framework.c +0 -10
index 1a2da74..b04c147 100644
@@ -1622,16 +1622,6 @@ static srpc_service_t sfw_services[] = {
 	}
 };
 
-extern sfw_test_client_ops_t ping_test_client;
-extern srpc_service_t	ping_test_service;
-extern void ping_init_test_client(void);
-extern void ping_init_test_service(void);
-
-extern sfw_test_client_ops_t brw_test_client;
-extern srpc_service_t	brw_test_service;
-extern void brw_init_test_client(void);
-extern void brw_init_test_service(void);
-
 int
 sfw_startup(void)
 {
drivers/staging/lustre/lnet/selftest/module.c +1 -3
index 46cbdf0..91564e5 100644
@@ -37,6 +37,7 @@
 #define DEBUG_SUBSYSTEM S_LNET
 
 #include "selftest.h"
+#include "console.h"
 
 enum {
 	LST_INIT_NONE = 0,
@@ -47,9 +48,6 @@ enum {
 	LST_INIT_CONSOLE
 };
 
-extern int lstcon_console_init(void);
-extern int lstcon_console_fini(void);
-
 static int lst_init_step = LST_INIT_NONE;
 
 struct cfs_wi_sched *lst_sched_serial;
drivers/staging/lustre/lnet/selftest/rpc.c +1 -1
index 2212199..9b823be 100644
@@ -1082,7 +1082,7 @@ srpc_client_rpc_expired(void *data)
 	spin_unlock(&srpc_data.rpc_glock);
 }
 
-inline void
+static void
 srpc_add_client_rpc_timer(srpc_client_rpc_t *rpc)
 {
 	stt_timer_t *timer = &rpc->crpc_timer;
Signature · 1 line
1.7.1
#48 lore raw

PATCH 25/40 staging: lustre: missed a few cases of using NULL instead of 0

In reply to James Simmons

From: frank zago <[email protected]>

It is preferable to use NULL instead of 0 for pointers. This fixes sparse warnings such as:

lustre/fld/fld_request.c:126:17: warning: Using plain integer as NULL pointer

The second parameter of class_match_param() was changed to a const, to be able to remove a cast in one user, to prevent splitting a long line. No other code change.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5396
Reviewed-on: http://review.whamcloud.com/12567

---
 drivers/staging/lustre/lnet/lnet/api-ni.c          |    2 +-
 drivers/staging/lustre/lustre/llite/llite_lib.c    |    2 +-
 .../staging/lustre/lustre/obdclass/obd_config.c    |    4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -1
index 7657f88..89b390a 100644
@@ -902,7 +902,7 @@ lnet_ping_info_setup(lnet_ping_info_t **ppinfo, lnet_handle_md_t *md_handle,
 {
 	lnet_process_id_t id = {LNET_NID_ANY, LNET_PID_ANY};
 	lnet_handle_me_t me_handle;
-	lnet_md_t md = {0};
+	lnet_md_t md = { NULL };
 	int rc, rc2;
 
 	if (set_eq) {
drivers/staging/lustre/lustre/llite/llite_lib.c +1 -1
index 4a8c759..2109297 100644
@@ -1941,7 +1941,7 @@ int ll_prep_inode(struct inode **inode, struct ptlrpc_request *req,
 		  struct super_block *sb, struct lookup_intent *it)
 {
 	struct ll_sb_info *sbi = NULL;
-	struct lustre_md md;
+	struct lustre_md md = { NULL };
 	int rc;
 
 	LASSERT(*inode || sb);
drivers/staging/lustre/lustre/obdclass/obd_config.c +2 -2
index c231e0d..db8e12d 100644
@@ -72,7 +72,7 @@ EXPORT_SYMBOL(class_find_param);
 
 /* returns 0 if this is the first key in the buffer, else 1.
    valp points to first char after key. */
-static int class_match_param(char *buf, char *key, char **valp)
+static int class_match_param(char *buf, const char *key, char **valp)
 {
 	if (!buf)
 		return 1;
@@ -1008,7 +1008,7 @@ int class_process_proc_param(char *prefix, struct lprocfs_vars *lvars,
 		/* Search proc entries */
 		while (lvars[j].name) {
 			var = &lvars[j];
-			if (class_match_param(key, (char *)var->name, NULL) == 0
+			if (class_match_param(key, var->name, NULL) == 0
 			    && keylen == strlen(var->name)) {
 				matched++;
 				rc = -EROFS;
Signature · 1 line
1.7.1
#49 lore raw

PATCH 26/40 staging: lustre: startup lnet acceptor thread dynamically

In reply to James Simmons

From: Amir Shehata <[email protected]>

With DLC it's possible to start up a system with no NIs that require the acceptor thread, and thus it won't start. Later on the user can add an NI that requires the acceptor thread to start, it is then necessary to start it up.

If the user removes a NI and as a result there are no more NIs that require the acceptor thread then it should be stopped. This patch adds logic in the dynamically adding and removing NIs code to ensure the above logic is implemented.

ntel-bug-id: https://jira.hpdd.intel.com/browse/LU-6002
Reviewed-on: http://review.whamcloud.com/13010

---
 drivers/staging/lustre/lnet/lnet/acceptor.c |   10 ++++++++--
 drivers/staging/lustre/lnet/lnet/api-ni.c   |   14 ++++++++++++++
 2 files changed, 22 insertions(+), 2 deletions(-)
drivers/staging/lustre/lnet/lnet/acceptor.c +8 -2
index d05754d..112b166 100644
@@ -46,7 +46,9 @@ static struct {
 	int			pta_shutdown;
 	struct socket		*pta_sock;
 	struct completion	pta_signal;
-} lnet_acceptor_state;
+} lnet_acceptor_state = {
+	.pta_shutdown = 1
+};
 
 int
 lnet_acceptor_port(void)
@@ -441,6 +443,10 @@ lnet_acceptor_start(void)
 	long rc2;
 	long secure;
 
+	/* if acceptor is already running return immediately */
+	if (!lnet_acceptor_state.pta_shutdown)
+		return 0;
+
 	LASSERT(lnet_acceptor_state.pta_sock == NULL);
 
 	rc = lnet_acceptor_get_tunables();
@@ -481,7 +487,7 @@ lnet_acceptor_start(void)
 void
 lnet_acceptor_stop(void)
 {
-	if (lnet_acceptor_state.pta_sock == NULL) /* not running */
+	if (lnet_acceptor_state.pta_shutdown) /* not running */
 		return;
 
 	lnet_acceptor_state.pta_shutdown = 1;
drivers/staging/lustre/lnet/lnet/api-ni.c +14 -0
index 89b390a..7d6e59f 100644
@@ -1776,6 +1776,16 @@ lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
 	if (rc != 0)
 		goto failed1;
 
+	if (ni->ni_lnd->lnd_accept) {
+		rc = lnet_acceptor_start();
+		if (rc < 0) {
+			/* shutdown the ni that we just started */
+			CERROR("Failed to start up acceptor thread\n");
+			lnet_shutdown_lndni(ni);
+			goto failed1;
+		}
+	}
+
 	lnet_ping_target_update(pinfo, md_handle);
 	mutex_unlock(&the_lnet.ln_api_mutex);
 
@@ -1823,6 +1833,10 @@ lnet_dyn_del_ni(__u32 net)
 	lnet_ni_decref_locked(ni, 0);
 
 	lnet_shutdown_lndni(ni);
+
+	if (lnet_count_acceptor_nis() == 0)
+		lnet_acceptor_stop();
+
 	lnet_ping_target_update(pinfo, md_handle);
 	goto out;
 failed:
Signature · 1 line
1.7.1
#50 lore raw

PATCH 27/40 staging: lustre: reject invalid net configuration for lnet

In reply to James Simmons

From: Amir Shehata <[email protected]>

Currently if there exists a route that goes over a remote net and then this net is added dynamically as a local net, then traffic stops because the code in lnet_send() determines that the destination nid can be reached from another local_ni, but the src_nid is still stuck on the earlier NI, because the src_nid is stored in the ptlrpc layer and is not updated when a local NI is configured.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5874
Reviewed-on: http://review.whamcloud.com/12912

---
 drivers/staging/lustre/lnet/lnet/api-ni.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)
drivers/staging/lustre/lnet/lnet/api-ni.c +17 -1
index 7d6e59f..9b00bc1 100644
@@ -1747,6 +1747,7 @@ lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
 	lnet_handle_md_t md_handle;
 	struct lnet_ni *ni;
 	struct list_head net_head;
+	lnet_remotenet_t *rnet;
 	int rc;
 
 	INIT_LIST_HEAD(&net_head);
@@ -1763,12 +1764,27 @@ lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
 		goto failed0;
 	}
 
+	ni = list_entry(net_head.next, struct lnet_ni, ni_list);
+
+	lnet_net_lock(LNET_LOCK_EX);
+	rnet = lnet_find_net_locked(LNET_NIDNET(ni->ni_nid));
+	lnet_net_unlock(LNET_LOCK_EX);
+	/*
+	 * make sure that the net added doesn't invalidate the current
+	 * configuration LNet is keeping
+	 */
+	if (rnet) {
+		CERROR("Adding net %s will invalidate routing configuration\n",
+		       nets);
+		rc = -EUSERS;
+		goto failed0;
+	}
+
 	rc = lnet_ping_info_setup(&pinfo, &md_handle, 1 + lnet_get_ni_count(),
 				  false);
 	if (rc != 0)
 		goto failed0;
 
-	ni = list_entry(net_head.next, struct lnet_ni, ni_list);
 	list_del_init(&ni->ni_list);
 
 	rc = lnet_startup_lndni(ni, peer_timeout, peer_cr,
Signature · 1 line
1.7.1
#51 lore raw

PATCH 28/40 staging: lustre: return -EEXIST if NI is not unique

In reply to James Simmons

From: Amir Shehata <[email protected]>

Return -EEXIST and not -EINVAL when trying to add a network interface which is not unique.

Some minor cleanup in api-ni.c

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5875
Reviewed-on: http://review.whamcloud.com/13056

---
 drivers/staging/lustre/lnet/lnet/api-ni.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)
drivers/staging/lustre/lnet/lnet/api-ni.c +9 -11
index 9b00bc1..ed167c8 100644
@@ -1213,7 +1213,7 @@ static int
 lnet_startup_lndni(struct lnet_ni *ni, __s32 peer_timeout,
 		   __s32 peer_cr, __s32 peer_buf_cr, __s32 credits)
 {
-	int rc = 0;
+	int rc = -EINVAL;
 	__u32 lnd_type;
 	lnd_t *lnd;
 	struct lnet_tx_queue *tq;
@@ -1231,19 +1231,19 @@ lnet_startup_lndni(struct lnet_ni *ni, __s32 peer_timeout,
 
 	/* Make sure this new NI is unique. */
 	lnet_net_lock(LNET_LOCK_EX);
-	if (!lnet_net_unique(LNET_NIDNET(ni->ni_nid), &the_lnet.ln_nis)) {
+	rc = lnet_net_unique(LNET_NIDNET(ni->ni_nid), &the_lnet.ln_nis);
+	lnet_net_unlock(LNET_LOCK_EX);
+	if (!rc) {
 		if (lnd_type == LOLND) {
-			lnet_net_unlock(LNET_LOCK_EX);
 			lnet_ni_free(ni);
 			return 0;
 		}
-		lnet_net_unlock(LNET_LOCK_EX);
 
 		CERROR("Net %s is not unique\n",
 		       libcfs_net2str(LNET_NIDNET(ni->ni_nid)));
+		rc = -EEXIST;
 		goto failed0;
 	}
-	lnet_net_unlock(LNET_LOCK_EX);
 
 	mutex_lock(&the_lnet.ln_lnd_mutex);
 	lnd = lnet_find_lnd_by_type(lnd_type);
@@ -1259,6 +1259,7 @@ lnet_startup_lndni(struct lnet_ni *ni, __s32 peer_timeout,
 			CERROR("Can't load LND %s, module %s, rc=%d\n",
 			       libcfs_lnd2str(lnd_type),
 			       libcfs_lnd2modname(lnd_type), rc);
+			rc = -EINVAL;
 			goto failed0;
 		}
 	}
@@ -1348,7 +1349,7 @@ lnet_startup_lndni(struct lnet_ni *ni, __s32 peer_timeout,
 	return 0;
 failed0:
 	lnet_ni_free(ni);
-	return -EINVAL;
+	return rc;
 }
 
 static int
@@ -1495,7 +1496,7 @@ int
 LNetNIInit(lnet_pid_t requested_pid)
 {
 	int im_a_router = 0;
-	int rc, rc2;
+	int rc;
 	int ni_count;
 	lnet_ping_info_t *pinfo;
 	lnet_handle_md_t md_handle;
@@ -1584,10 +1585,7 @@ LNetNIInit(lnet_pid_t requested_pid)
 	return 0;
 
  failed4:
-	lnet_ping_md_unlink(pinfo, &md_handle);
-	lnet_ping_info_free(pinfo);
-	rc2 = LNetEQFree(the_lnet.ln_ping_target_eq);
-	LASSERT(rc2 == 0);
+	lnet_ping_target_fini();
  failed3:
 	the_lnet.ln_refcount = 0;
 	lnet_acceptor_stop();
Signature · 1 line
1.7.1
#52 lore raw

PATCH 29/40 staging: lustre: handle lnet_check_routes() errors

In reply to James Simmons

From: Amir Shehata <[email protected]>

After adding a route, lnet_check_routes() is called to ensure that the route added doesn't invalidate the routing configuration. If lnet_check_routes() fails then the route just added, which caused the current configuration to be invalidated is deleted, and an error is returned to the user.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6218
Reviewed-on: http://review.whamcloud.com/13445

---
 drivers/staging/lustre/lnet/lnet/api-ni.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/staging/lustre/lnet/lnet/api-ni.c +7 -1
index ed167c8..b119c6c 100644
@@ -1910,8 +1910,14 @@ LNetCtl(unsigned int cmd, void *arg)
 				    config->cfg_nid,
 				    config->cfg_config_u.cfg_route.
 					rtr_priority);
+		if (rc == 0) {
+			rc = lnet_check_routes();
+			if (rc != 0)
+				lnet_del_route(config->cfg_net,
+					       config->cfg_nid);
+		}
 		mutex_unlock(&the_lnet.ln_api_mutex);
-		return (rc != 0) ? rc : lnet_check_routes();
+		return rc;
 
 	case IOC_LIBCFS_DEL_ROUTE:
 		config = arg;
Signature · 1 line
1.7.1
#53 lore raw

PATCH 30/40 staging: lustre: improvement to router checker

In reply to James Simmons

From: Amir Shehata <[email protected]>

This patch starts router checker thread all the time.

The router checker only checks routes by ping if live_router_check_interval or dead_router_check_interval are set to something other than 0, and there are routes configured.

If these conditions are not met the router checker sleeps until woken up when a route is added. It is also woken up whenever the RC is being stopped to ensure the thread doesn't hang.

In the future when DLC starts configuring the live and dead router_check_interval parameters, then by manipulating them the router checker can be turned on and off by the user.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6003
Reviewed-on: http://review.whamcloud.com/13035

---
 .../staging/lustre/include/linux/lnet/lib-types.h  |    7 +++
 drivers/staging/lustre/lnet/lnet/api-ni.c          |    1 +
 drivers/staging/lustre/lnet/lnet/router.c          |   51 +++++++++++++++++---
 3 files changed, 52 insertions(+), 7 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-types.h +7 -0
index 3282782..574de55 100644
@@ -619,6 +619,13 @@ typedef struct {
 	 */
 	bool				  ln_nis_from_mod_params;
 
+	/*
+	 * waitq for router checker.  As long as there are no routes in
+	 * the list, the router checker will sleep on this queue.  when
+	 * routes are added the thread will wake up
+	 */
+	wait_queue_head_t		  ln_rc_waitq;
+
 } lnet_t;
 
 #endif
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -0
index b119c6c..09656a1 100644
@@ -99,6 +99,7 @@ lnet_init_locks(void)
 {
 	spin_lock_init(&the_lnet.ln_eq_wait_lock);
 	init_waitqueue_head(&the_lnet.ln_eq_waitq);
+	init_waitqueue_head(&the_lnet.ln_rc_waitq);
 	mutex_init(&the_lnet.ln_lnd_mutex);
 	mutex_init(&the_lnet.ln_api_mutex);
 }
drivers/staging/lustre/lnet/lnet/router.c +44 -7

81 lines not on this page · raw message

Signature · 1 line
1.7.1
#54 lore raw

PATCH 31/40 staging: lustre: assume a kernel build

In reply to James Simmons

From: John L. Hammond <[email protected]>

In lnet/lnet/ and lnet/selftest/ assume a kernel build (assume that
__KERNEL__ is defined). Remove some common code only needed for user
space LNet.

Only part of the work of this patch got merged. This is the final bits.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-2675
Reviewed-on: http://review.whamcloud.com/13121

---
 .../staging/lustre/include/linux/lnet/lib-types.h  |    4 --
 drivers/staging/lustre/lnet/lnet/acceptor.c        |    2 -
 drivers/staging/lustre/lnet/lnet/api-ni.c          |   38 ++------------------
 drivers/staging/lustre/lnet/lnet/lib-eq.c          |    3 --
 drivers/staging/lustre/lnet/lnet/lib-md.c          |    3 --
 drivers/staging/lustre/lnet/lnet/lib-me.c          |    3 --
 drivers/staging/lustre/lnet/lnet/lib-move.c        |    5 ---
 drivers/staging/lustre/lnet/lnet/lib-msg.c         |   20 +----------
 drivers/staging/lustre/lnet/lnet/router.c          |    9 ++---
 9 files changed, 7 insertions(+), 80 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-types.h +0 -4
index 574de55..dbfb069 100644
@@ -561,8 +561,6 @@ typedef struct {
 	/* dying LND instances */
 	struct list_head		  ln_nis_zombie;
 	lnet_ni_t			 *ln_loni;	/* the loopback NI */
-	/* NI to wait for events in */
-	lnet_ni_t			 *ln_eq_waitni;
 
 	/* remote networks with routes to them */
 	struct list_head		 *ln_remote_nets_hash;
@@ -592,8 +590,6 @@ typedef struct {
 
 	struct mutex			  ln_api_mutex;
 	struct mutex			  ln_lnd_mutex;
-	int				  ln_init;	/* lnet_init()
-							   called? */
 	/* Have I called LNetNIInit myself? */
 	int				  ln_niinit_self;
 	/* LNetNIInit/LNetNIFini counter */
drivers/staging/lustre/lnet/lnet/acceptor.c +0 -2
index 112b166..ffa2b19 100644
@@ -204,8 +204,6 @@ lnet_connect(struct socket **sockp, lnet_nid_t peer_nid,
 }
 EXPORT_SYMBOL(lnet_connect);
 
-/* Below is the code common for both kernel and MT user-space */
-
 static int
 lnet_accept(struct socket *sock, __u32 magic)
 {
drivers/staging/lustre/lnet/lnet/api-ni.c +3 -35
index 09656a1..e78b079 100644
@@ -290,7 +290,6 @@ lnet_register_lnd(lnd_t *lnd)
 {
 	mutex_lock(&the_lnet.ln_lnd_mutex);
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(libcfs_isknown_lnd(lnd->lnd_type));
 	LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == NULL);
 
@@ -308,7 +307,6 @@ lnet_unregister_lnd(lnd_t *lnd)
 {
 	mutex_lock(&the_lnet.ln_lnd_mutex);
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(lnet_find_lnd_by_type(lnd->lnd_type) == lnd);
 	LASSERT(lnd->lnd_refcount == 0);
 
@@ -1164,12 +1162,6 @@ lnet_shutdown_lndnis(void)
 		lnet_ni_unlink_locked(ni);
 	}
 
-	/* Drop the cached eqwait NI. */
-	if (the_lnet.ln_eq_waitni != NULL) {
-		lnet_ni_decref_locked(the_lnet.ln_eq_waitni, 0);
-		the_lnet.ln_eq_waitni = NULL;
-	}
-
 	/* Drop the cached loopback NI. */
 	if (the_lnet.ln_loni != NULL) {
 		lnet_ni_decref_locked(the_lnet.ln_loni, 0);
@@ -1358,7 +1350,6 @@ lnet_startup_lndnis(struct list_head *nilist)
 {
 	struct lnet_ni *ni;
 	int rc;
-	int lnd_type;
 	int ni_count = 0;
 
 	while (!list_empty(nilist)) {
@@ -1372,14 +1363,6 @@ lnet_startup_lndnis(struct list_head *nilist)
 		ni_count++;
 	}
 
-	if (the_lnet.ln_eq_waitni && ni_count > 1) {
-		lnd_type = the_lnet.ln_eq_waitni->ni_lnd->lnd_type;
-		LCONSOLE_ERROR_MSG(0x109, "LND %s can only run single-network\n",
-				   libcfs_lnd2str(lnd_type));
-		rc = -EINVAL;
-		goto failed;
-	}
-
 	return ni_count;
 failed:
 	lnet_shutdown_lndnis();
@@ -1390,10 +1373,9 @@ failed:
 /**
  * Initialize LNet library.
  *
- * Only userspace program needs to call this function - it's automatically
- * called in the kernel at module loading time. Caller has to call lnet_fini()
- * after a call to lnet_init(), if and only if the latter returned 0. It must
- * be called exactly once.
+ * Automatically called at module loading time. Caller has to call
+ * lnet_exit() after a call to lnet_init(), if and only if the
+ * latter returned 0. It must be called exactly once.
  *
  * \return 0 on success, and -ve on failures.
  */
@@ -1403,7 +1385,6 @@ lnet_init(void)
 	int rc;
 
 	lnet_assert_wire_constants();
-	LASSERT(!the_lnet.ln_init);
 
 	memset(&the_lnet, 0, sizeof(the_lnet));
 
@@ -1429,7 +1410,6 @@ lnet_init(void)
 	}
 
 	the_lnet.ln_refcount = 0;
-	the_lnet.ln_init = 1;
 	LNetInvalidateHandle(&the_lnet.ln_rc_eqh);
 	INIT_LIST_HEAD(&the_lnet.ln_lnds);
 	INIT_LIST_HEAD(&the_lnet.ln_rcd_zombie);
@@ -1456,31 +1436,24 @@ EXPORT_SYMBOL(lnet_init);
 /**
  * Finalize LNet library.
  *
- * Only userspace program needs to call this function. It can be called
- * at most once.
- *
  * \pre lnet_init() called with success.
  * \pre All LNet users called LNetNIFini() for matching LNetNIInit() calls.
  */
 void
 lnet_fini(void)
 {
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount == 0);
 
 	while (!list_empty(&the_lnet.ln_lnds))
 		lnet_unregister_lnd(list_entry(the_lnet.ln_lnds.next,
 						   lnd_t, lnd_list));
 	lnet_destroy_locks();
-
-	the_lnet.ln_init = 0;
 }
 EXPORT_SYMBOL(lnet_fini);
 
 /**
  * Set LNet PID and start LNet interfaces, routing, and forwarding.
  *
- * Userspace program should call this after a successful call to lnet_init().
  * Users must call this function at least once before any other functions.
  * For each successful call there must be a corresponding call to
  * LNetNIFini(). For subsequent calls to LNetNIInit(), \a requested_pid is
@@ -1507,7 +1480,6 @@ LNetNIInit(lnet_pid_t requested_pid)
 
 	mutex_lock(&the_lnet.ln_api_mutex);
 
-	LASSERT(the_lnet.ln_init);
 	CDEBUG(D_OTHER, "refs %d\n", the_lnet.ln_refcount);
 
 	if (the_lnet.ln_refcount > 0) {
@@ -1624,7 +1596,6 @@ LNetNIFini(void)
 {
 	mutex_lock(&the_lnet.ln_api_mutex);
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	if (the_lnet.ln_refcount != 1) {
@@ -1888,7 +1859,6 @@ LNetCtl(unsigned int cmd, void *arg)
 
 	CLASSERT(sizeof(struct lnet_ioctl_net_config) +
 		 sizeof(struct lnet_ioctl_config_data) < LIBCFS_IOC_DATA_MAX);
-	LASSERT(the_lnet.ln_init);
 
 	switch (cmd) {
 	case IOC_LIBCFS_GET_NI:
@@ -2140,8 +2110,6 @@ LNetGetId(unsigned int index, lnet_process_id_t *id)
 	int cpt;
 	int rc = -ENOENT;
 
-	LASSERT(the_lnet.ln_init);
-
 	/* LNetNI initilization failed? */
 	if (the_lnet.ln_refcount == 0)
 		return rc;
drivers/staging/lustre/lnet/lnet/lib-eq.c +0 -3
index 60889eb..5deefaf 100644
@@ -72,7 +72,6 @@ LNetEQAlloc(unsigned int count, lnet_eq_handler_t callback,
 {
 	lnet_eq_t *eq;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	/* We need count to be a power of 2 so that when eq_{enq,deq}_seq
@@ -159,7 +158,6 @@ LNetEQFree(lnet_handle_eq_t eqh)
 	int size = 0;
 	int i;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	lnet_res_lock(LNET_LOCK_EX);
@@ -390,7 +388,6 @@ LNetEQPoll(lnet_handle_eq_t *eventqs, int neq, int timeout_ms,
 	int rc;
 	int i;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	if (neq < 1)
drivers/staging/lustre/lnet/lnet/lib-md.c +0 -3
index 758f5be..dc35f2d 100644
@@ -273,7 +273,6 @@ LNetMDAttach(lnet_handle_me_t meh, lnet_md_t umd,
 	int cpt;
 	int rc;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	if (lnet_md_validate(&umd) != 0)
@@ -350,7 +349,6 @@ LNetMDBind(lnet_md_t umd, lnet_unlink_t unlink, lnet_handle_md_t *handle)
 	int cpt;
 	int rc;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	if (lnet_md_validate(&umd) != 0)
@@ -425,7 +423,6 @@ LNetMDUnlink(lnet_handle_md_t mdh)
 	lnet_libmd_t *md;
 	int cpt;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	cpt = lnet_cpt_of_cookie(mdh.cookie);
drivers/staging/lustre/lnet/lnet/lib-me.c +0 -3
index 42fc99e..69a9314 100644
@@ -83,7 +83,6 @@ LNetMEAttach(unsigned int portal,
 	struct lnet_me *me;
 	struct list_head *head;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	if ((int)portal >= the_lnet.ln_nportals)
@@ -156,7 +155,6 @@ LNetMEInsert(lnet_handle_me_t current_meh,
 	struct lnet_portal *ptl;
 	int cpt;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	if (pos == LNET_INS_LOCAL)
@@ -233,7 +231,6 @@ LNetMEUnlink(lnet_handle_me_t meh)
 	lnet_event_t ev;
 	int cpt;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	cpt = lnet_cpt_of_cookie(meh.cookie);
drivers/staging/lustre/lnet/lnet/lib-move.c +0 -5
index b9388ed..c2cc8c8 100644
@@ -59,8 +59,6 @@ lnet_fail_nid(lnet_nid_t nid, unsigned int threshold)
 	struct list_head *next;
 	struct list_head cull;
 
-	LASSERT(the_lnet.ln_init);
-
 	/* NB: use lnet_net_lock(0) to serialize operations on test peers */
 	if (threshold != 0) {
 		/* Adding a new entry */
@@ -2137,7 +2135,6 @@ LNetPut(lnet_nid_t self, lnet_handle_md_t mdh, lnet_ack_req_t ack,
 	int cpt;
 	int rc;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
@@ -2337,7 +2334,6 @@ LNetGet(lnet_nid_t self, lnet_handle_md_t mdh,
 	int cpt;
 	int rc;
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	if (!list_empty(&the_lnet.ln_test_peers) && /* normally we don't */
@@ -2436,7 +2432,6 @@ LNetDist(lnet_nid_t dstnid, lnet_nid_t *srcnidp, __u32 *orderp)
 	 * keep order 0 free for 0 at lo and order 1 free for a local NID
 	 * match */
 
-	LASSERT(the_lnet.ln_init);
 	LASSERT(the_lnet.ln_refcount > 0);
 
 	cpt = lnet_net_lock_current();
drivers/staging/lustre/lnet/lnet/lib-msg.c +1 -19
index 43977e8..5751dc4 100644
@@ -559,35 +559,17 @@ lnet_msg_container_cleanup(struct lnet_msg_container *container)
 			    sizeof(*container->msc_finalizers));
 		container->msc_finalizers = NULL;
 	}
-#ifdef LNET_USE_LIB_FREELIST
-	lnet_freelist_fini(&container->msc_freelist);
-#endif
 	container->msc_init = 0;
 }
 
 int
 lnet_msg_container_setup(struct lnet_msg_container *container, int cpt)
 {
-	int rc;
-
 	container->msc_init = 1;
 
 	INIT_LIST_HEAD(&container->msc_active);
 	INIT_LIST_HEAD(&container->msc_finalizing);
 
-#ifdef LNET_USE_LIB_FREELIST
-	memset(&container->msc_freelist, 0, sizeof(lnet_freelist_t));
-
-	rc = lnet_freelist_init(&container->msc_freelist,
-				LNET_FL_MAX_MSGS, sizeof(lnet_msg_t));
-	if (rc != 0) {
-		CERROR("Failed to init freelist for message container\n");
-		lnet_msg_container_cleanup(container);
-		return rc;
-	}
-#else
-	rc = 0;
-#endif
 	/* number of CPUs */
 	container->msc_nfinalizers = cfs_cpt_weight(lnet_cpt_table(), cpt);
 
@@ -601,7 +583,7 @@ lnet_msg_container_setup(struct lnet_msg_container *container, int cpt)
 		return -ENOMEM;
 	}
 
-	return rc;
+	return 0;
 }
 
 void
drivers/staging/lustre/lnet/lnet/router.c +3 -6
index b4ac670..91f3f09 100644
@@ -1046,7 +1046,7 @@ lnet_router_checker_start(void)
 {
 	struct task_struct *task;
 	int rc;
-	int eqsz;
+	int eqsz = 0;
 
 	LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_SHUTDOWN);
 
@@ -1057,11 +1057,8 @@ lnet_router_checker_start(void)
 	}
 
 	sema_init(&the_lnet.ln_rc_signal, 0);
-	/* EQ size doesn't matter; the callback is guaranteed to get every
-	 * event */
-	eqsz = 0;
-	rc = LNetEQAlloc(eqsz, lnet_router_checker_event,
-			 &the_lnet.ln_rc_eqh);
+
+	rc = LNetEQAlloc(0, lnet_router_checker_event, &the_lnet.ln_rc_eqh);
 	if (rc != 0) {
 		CERROR("Can't allocate EQ(%d): %d\n", eqsz, rc);
 		return -ENOMEM;
Signature · 1 line
1.7.1
#55 lore raw

PATCH 32/40 staging: lustre: prevent assert on LNet module unload

In reply to James Simmons

From: Amir Shehata <[email protected]>

There is a use case where lnet can be unloaded while there are no NIs configured. Removing lnet in this case will cause LNetFini() to be called without a prior call to LNetNIFini(). This will cause the LASSERT(the_lnet.ln_refcount == 0) to be triggered.

To deal with this use case when LNet is configured a reference count on the module is taken using try_module_get(). This way LNet must be unconfigured before it could be removed; therefore avoiding the above case. When LNet is unconfigured module_put() is called to return the reference count.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6010
Reviewed-on: http://review.whamcloud.com/13110

---
 drivers/staging/lustre/lnet/lnet/module.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)
drivers/staging/lustre/lnet/lnet/module.c +9 -0
index 48eb085..b1f32a6 100644
@@ -53,13 +53,21 @@ lnet_configure(void *arg)
 	mutex_lock(&lnet_config_mutex);
 
 	if (!the_lnet.ln_niinit_self) {
+		rc = try_module_get(THIS_MODULE);
+
+		if (rc != 1)
+			goto out;
+
 		rc = LNetNIInit(LNET_PID_LUSTRE);
 		if (rc >= 0) {
 			the_lnet.ln_niinit_self = 1;
 			rc = 0;
+		} else {
+			module_put(THIS_MODULE);
 		}
 	}
 
+out:
 	mutex_unlock(&lnet_config_mutex);
 	return rc;
 }
@@ -74,6 +82,7 @@ lnet_unconfigure(void)
 	if (the_lnet.ln_niinit_self) {
 		the_lnet.ln_niinit_self = 0;
 		LNetNIFini();
+		module_put(THIS_MODULE);
 	}
 
 	mutex_lock(&the_lnet.ln_api_mutex);
Signature · 1 line
1.7.1
#56 lore raw

PATCH 33/40 staging: lustre: remove messages from lazy portal on NI shutdown

In reply to James Simmons

From: Amir Shehata <[email protected]>

When shutting down an NI in a busy system, some messages received on this NI, might be on the lazy portal. They would have grabbed a ref count on the NI. Therefore NI will not be removed until messages are processed.

In order to avoid this scenario, when an NI is shutdown go through all messages queued on the lazy portal and drop messages for the NI being shutdown

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6040
Reviewed-on: http://review.whamcloud.com/13836

---
 .../staging/lustre/include/linux/lnet/lib-lnet.h   |    1 +
 drivers/staging/lustre/lnet/lnet/api-ni.c          |    6 ++
 drivers/staging/lustre/lnet/lnet/lib-ptl.c         |   54 +++++++++++++-------
 3 files changed, 43 insertions(+), 18 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-lnet.h +1 -0
index 00ef4d0..6dce2c9 100644
@@ -480,6 +480,7 @@ int lnet_dyn_add_ni(lnet_pid_t requested_pid, char *nets,
 		    __s32 peer_timeout, __s32 peer_cr, __s32 peer_buf_cr,
 		    __s32 credits);
 int lnet_dyn_del_ni(__u32 net);
+int lnet_clear_lazy_portal(struct lnet_ni *ni, int portal, char *reason);
 
 int lnet_islocalnid(lnet_nid_t nid);
 int lnet_islocalnet(__u32 net);
drivers/staging/lustre/lnet/lnet/api-ni.c +6 -0
index e78b079..34f8c1b 100644
@@ -1190,10 +1190,16 @@ lnet_shutdown_lndnis(void)
 static void
 lnet_shutdown_lndni(struct lnet_ni *ni)
 {
+	int i;
+
 	lnet_net_lock(LNET_LOCK_EX);
 	lnet_ni_unlink_locked(ni);
 	lnet_net_unlock(LNET_LOCK_EX);
 
+	/* clear messages for this NI on the lazy portal */
+	for (i = 0; i < the_lnet.ln_nportals; i++)
+		lnet_clear_lazy_portal(ni, i, "Shutting down NI");
+
 	/* Do peer table cleanup for this ni */
 	lnet_peer_tables_cleanup(ni);
 
drivers/staging/lustre/lnet/lnet/lib-ptl.c +36 -18

74 lines not on this page · raw message

Signature · 1 line
1.7.1
#57 lore raw

PATCH 34/40 staging: lustre: remove unnecessary EXPORT_SYMBOL from lnet layer

In reply to James Simmons

From: frank zago <[email protected]>

A lot of symbols don't need to be exported at all because they are only used in the module they belong to.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5829
Reviewed-on: http://review.whamcloud.com/13320

---
 drivers/staging/lustre/lnet/lnet/api-ni.c     |    1 -
 drivers/staging/lustre/lnet/lnet/lib-move.c   |    1 -
 drivers/staging/lustre/lnet/lnet/lib-socket.c |    3 ---
 drivers/staging/lustre/lnet/selftest/conctl.c |    2 --
 4 files changed, 0 insertions(+), 7 deletions(-)
drivers/staging/lustre/lnet/lnet/api-ni.c +0 -1
index 34f8c1b..7f5e0e8 100644
@@ -358,7 +358,6 @@ lnet_counters_reset(void)
 
 	lnet_net_unlock(LNET_LOCK_EX);
 }
-EXPORT_SYMBOL(lnet_counters_reset);
 
 static char *
 lnet_res_type2str(int type)
drivers/staging/lustre/lnet/lnet/lib-move.c +0 -1
index c2cc8c8..430cb9a 100644
@@ -1715,7 +1715,6 @@ lnet_msgtyp2str(int type)
 		return "<UNKNOWN>";
 	}
 }
-EXPORT_SYMBOL(lnet_msgtyp2str);
 
 void
 lnet_print_hdr(lnet_hdr_t *hdr)
drivers/staging/lustre/lnet/lnet/lib-socket.c +0 -3
index 6f7ef4c..ccb425d 100644
@@ -513,7 +513,6 @@ lnet_sock_listen(struct socket **sockp, __u32 local_ip, int local_port,
 	sock_release(*sockp);
 	return rc;
 }
-EXPORT_SYMBOL(lnet_sock_listen);
 
 int
 lnet_sock_accept(struct socket **newsockp, struct socket *sock)
@@ -555,7 +554,6 @@ failed:
 	sock_release(newsock);
 	return rc;
 }
-EXPORT_SYMBOL(lnet_sock_accept);
 
 int
 lnet_sock_connect(struct socket **sockp, int *fatal, __u32 local_ip,
@@ -591,4 +589,3 @@ lnet_sock_connect(struct socket **sockp, int *fatal, __u32 local_ip,
 	sock_release(*sockp);
 	return rc;
 }
-EXPORT_SYMBOL(lnet_sock_connect);
drivers/staging/lustre/lnet/selftest/conctl.c +0 -2
index 3dc8ea7..73e71cd 100644
@@ -931,5 +931,3 @@ out:
 
 	return rc;
 }
-
-EXPORT_SYMBOL(lstcon_ioctl_entry);
Signature · 1 line
1.7.1
#58 lore raw

PATCH 35/40 staging: lustre: avoid race during lnet acceptor thread termination

In reply to James Simmons

From: Bruno Faccini <[email protected]>

This patch will avoid potential race, around socket sleepers wait list, during acceptor thread termination and using sk_callback_lock RW-Lock protection.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6476
Reviewed-on: http://review.whamcloud.com/14503

---
 drivers/staging/lustre/lnet/lnet/acceptor.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)
drivers/staging/lustre/lnet/lnet/acceptor.c +7 -1
index ffa2b19..61806ce 100644
@@ -485,11 +485,17 @@ lnet_acceptor_start(void)
 void
 lnet_acceptor_stop(void)
 {
+	struct sock *sk;
+
 	if (lnet_acceptor_state.pta_shutdown) /* not running */
 		return;
 
 	lnet_acceptor_state.pta_shutdown = 1;
-	wake_up_all(sk_sleep(lnet_acceptor_state.pta_sock->sk));
+
+	sk = lnet_acceptor_state.pta_sock->sk;
+
+	/* awake any sleepers using safe method */
+	sk->sk_state_change(sk);
 
 	/* block until acceptor signals exit */
 	wait_for_completion(&lnet_acceptor_state.pta_signal);
Signature · 1 line
1.7.1
#59 lore raw

PATCH 36/40 staging: lustre: test for sk_sleep presence in compact-2.6.h

In reply to James Simmons

Like Lustre external infiniband stacks create a compatibility layer to handle various distributions and kernel versions. Due to this besides the linux kernel sk_sleep can also be defined by the external infiniband stack. We need to examine the infiniband stack's headers to see if sk_sleep is available there as well.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6763
Reviewed-on: http://review.whamcloud.com/15386

---
 .../staging/lustre/include/linux/lnet/lib-types.h  |    1 -
 drivers/staging/lustre/lnet/lnet/acceptor.c        |    1 +
 2 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-types.h +0 -1
index dbfb069..695b5be 100644
@@ -38,7 +38,6 @@
 #include <linux/kthread.h>
 #include <linux/uio.h>
 #include <linux/types.h>
-#include <net/sock.h>
 
 #include "types.h"
 
drivers/staging/lustre/lnet/lnet/acceptor.c +1 -0
index 61806ce..05eb5b2 100644
@@ -36,6 +36,7 @@
 
 #define DEBUG_SUBSYSTEM S_LNET
 #include <linux/completion.h>
+#include <net/sock.h>
 #include "../../include/linux/lnet/lib-lnet.h"
 
 static int   accept_port    = 988;
Signature · 1 line
1.7.1
#60 lore raw

PATCH 37/40 staging: lustre: remove unnecessary NULL check in IOC_LIBCFS_GET_NET

In reply to James Simmons

From: Amir Shehata <[email protected]>

In LNetCtl():IOC_LIBCFS_GET_NET there is a check for config == NULL This is not necessary as it'll never be NULL. That's ensured before the call to LNetCtl.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6502
Reviewed-on: http://review.whamcloud.com/15779

---
 drivers/staging/lustre/lnet/lnet/api-ni.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
drivers/staging/lustre/lnet/lnet/api-ni.c +1 -1
index 7f5e0e8..6373de0 100644
@@ -1931,7 +1931,7 @@ LNetCtl(unsigned int cmd, void *arg)
 
 		net_config = (struct lnet_ioctl_net_config *)
 				config->cfg_bulk;
-		if (!config || !net_config)
+		if (!net_config)
 			return -1;
 
 		return lnet_get_net_config(config->cfg_count,
Signature · 1 line
1.7.1
#61 lore raw

PATCH 38/40 staging: lustre: Allocate the correct number of rtr buffers

In reply to James Simmons

From: Amir Shehata <[email protected]>

This patch ensures that the correct number of router buffers are allocated. It keeps a count that keeps track of the number of buffers allocated. Another count keeps the number of buffers requested. The number of buffers allocated is set when creating new buffers and reduced when buffers are freed.

The number of requested buffer is set when the buffers are allocated and is checked when credits are returned to determine whether the buffer should be freed or kept.

In lnet_rtrpool_adjust_bufs() grab lnet_net_lock() before using rbp_nbuffers to ensure that it doesn't change by lnet_return_rx_credits_locked() during the process of allocating new buffers. All other access to rbp_nbuffers is already being protected by lnet_net_lock().

This avoids the case where we allocate less than the desired number of buffers.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-6122
Reviewed-on: http://review.whamcloud.com/13519

---
 .../staging/lustre/include/linux/lnet/lib-types.h  |    5 ++-
 drivers/staging/lustre/lnet/lnet/lib-move.c        |    3 +-
 drivers/staging/lustre/lnet/lnet/router.c          |   32 +++++++++++++++-----
 3 files changed, 30 insertions(+), 10 deletions(-)
drivers/staging/lustre/include/linux/lnet/lib-types.h +4 -1
index 695b5be..24b3c1a 100644
@@ -386,7 +386,10 @@ typedef struct {
 	struct list_head	rbp_msgs;	/* messages blocking
 						   for a buffer */
 	int			rbp_npages;	/* # pages in each buffer */
-	int			rbp_nbuffers;	/* # buffers */
+	/* requested number of buffers */
+	int			rbp_req_nbuffers;
+	/* # buffers actually allocated */
+	int			rbp_nbuffers;
 	int			rbp_credits;	/* # free buffers /
 						     blocked messages */
 	int			rbp_mincredits;	/* low water mark */
drivers/staging/lustre/lnet/lnet/lib-move.c +2 -1
index 430cb9a..21a7c6f 100644
@@ -1101,9 +1101,10 @@ lnet_return_rx_credits_locked(lnet_msg_t *msg)
 		 * buffers in this pool.  Make sure we never put back
 		 * more buffers than the stated number.
 		 */
-		if (rbp->rbp_credits >= rbp->rbp_nbuffers) {
+		if (unlikely(rbp->rbp_credits >= rbp->rbp_req_nbuffers)) {
 			/* Discard this buffer so we don't have too many. */
 			lnet_destroy_rtrbuf(rb, rbp->rbp_npages);
+			rbp->rbp_nbuffers--;
 		} else {
 			list_add(&rb->rb_list, &rbp->rbp_bufs);
 			rbp->rbp_credits++;
drivers/staging/lustre/lnet/lnet/router.c +24 -8
index 91f3f09..35cfced 100644
@@ -1352,6 +1352,7 @@ lnet_rtrpool_free_bufs(lnet_rtrbufpool_t *rbp, int cpt)
 	lnet_net_lock(cpt);
 	lnet_drop_routed_msgs_locked(&rbp->rbp_msgs, cpt);
 	list_splice_init(&rbp->rbp_bufs, &tmp);
+	rbp->rbp_req_nbuffers = 0;
 	rbp->rbp_nbuffers = 0;
 	rbp->rbp_credits = 0;
 	rbp->rbp_mincredits = 0;
@@ -1372,20 +1373,33 @@ lnet_rtrpool_adjust_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt)
 	lnet_rtrbuf_t *rb;
 	int num_rb;
 	int num_buffers = 0;
+	int old_req_nbufs;
 	int npages = rbp->rbp_npages;
 
+	lnet_net_lock(cpt);
 	/*
 	 * If we are called for less buffers than already in the pool, we
-	 * just lower the nbuffers number and excess buffers will be
+	 * just lower the req_nbuffers number and excess buffers will be
 	 * thrown away as they are returned to the free list.  Credits
 	 * then get adjusted as well.
+	 * If we already have enough buffers allocated to serve the
+	 * increase requested, then we can treat that the same way as we
+	 * do the decrease.
 	 */
-	if (nbufs <= rbp->rbp_nbuffers) {
-		lnet_net_lock(cpt);
-		rbp->rbp_nbuffers = nbufs;
+	num_rb = nbufs - rbp->rbp_nbuffers;
+	if (nbufs <= rbp->rbp_req_nbuffers || num_rb <= 0) {
+		rbp->rbp_req_nbuffers = nbufs;
 		lnet_net_unlock(cpt);
 		return 0;
 	}
+	/*
+	 * store the older value of rbp_req_nbuffers and then set it to
+	 * the new request to prevent lnet_return_rx_credits_locked() from
+	 * freeing buffers that we need to keep around
+	 */
+	old_req_nbufs = rbp->rbp_req_nbuffers;
+	rbp->rbp_req_nbuffers = nbufs;
+	lnet_net_unlock(cpt);
 
 	INIT_LIST_HEAD(&rb_list);
 
@@ -1394,19 +1408,21 @@ lnet_rtrpool_adjust_bufs(lnet_rtrbufpool_t *rbp, int nbufs, int cpt)
 	 * allocated successfully then join this list to the rbp buffer
 	 * list. If not then free all allocated buffers.
 	 */
-	num_rb = rbp->rbp_nbuffers;
-
-	while (num_rb < nbufs) {
+	while (num_rb-- > 0) {
 		rb = lnet_new_rtrbuf(rbp, cpt);
 		if (rb == NULL) {
 			CERROR("Failed to allocate %d route bufs of %d pages\n",
 			       nbufs, npages);
+
+			lnet_net_lock(cpt);
+			rbp->rbp_req_nbuffers = old_req_nbufs;
+			lnet_net_unlock(cpt);
+
 			goto failed;
 		}
 
 		list_add(&rb->rb_list, &rb_list);
 		num_buffers++;
-		num_rb++;
 	}
 
 	lnet_net_lock(cpt);
Signature · 1 line
1.7.1
#62 lore raw

PATCH 39/40 staging: lustre: Use lnet_is_route_alive for router aliveness

In reply to James Simmons

From: Chris Horn <[email protected]>

lctl show_route and lctl route_list will output router aliveness information via lnet_get_route(). lnet_get_route() should use the lnet_is_route_alive() function, introduced in e8a1124
http://review.whamcloud.com/7857, to determine route aliveness.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5733
Reviewed-on: http://review.whamcloud.com/14055

---
 drivers/staging/lustre/lnet/lnet/router.c |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
drivers/staging/lustre/lnet/lnet/router.c +1 -2
index 35cfced..83d233b 100644
@@ -611,8 +611,7 @@ lnet_get_route(int idx, __u32 *net, __u32 *hops,
 					*hops     = route->lr_hops;
 					*priority = route->lr_priority;
 					*gateway  = route->lr_gateway->lp_nid;
-					*alive = route->lr_gateway->lp_alive &&
-						 !route->lr_downis;
+					*alive = lnet_is_route_alive(route);
 					lnet_net_unlock(cpt);
 					return 0;
 				}
Signature · 1 line
1.7.1
#63 lore raw

PATCH 40/40 staging: lustre: Remove LASSERTS from router checker

In reply to James Simmons

From: Doug Oucharek <[email protected]>

In lnet_router_checker(), there are two LASSERTS. Neither protects us from anything and one of them triggered for a customer crashing the system unecessarily. This patch removes them.

Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-7362
Reviewed-on: http://review.whamcloud.com/17003

---
 drivers/staging/lustre/lnet/lnet/router.c |    4 ----
 1 files changed, 0 insertions(+), 4 deletions(-)
drivers/staging/lustre/lnet/lnet/router.c +0 -4
index 83d233b..476b4dd 100644
@@ -1223,8 +1223,6 @@ lnet_router_checker(void *arg)
 
 	cfs_block_allsigs();
 
-	LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING);
-
 	while (the_lnet.ln_rc_state == LNET_RC_STATE_RUNNING) {
 		__u64 version;
 		int cpt;
@@ -1280,8 +1278,6 @@ rescan:
 							 cfs_time_seconds(1));
 	}
 
-	LASSERT(the_lnet.ln_rc_state == LNET_RC_STATE_STOPPING);
-
 	lnet_prune_rc_data(1); /* wait for UNLINK */
 
 	the_lnet.ln_rc_state = LNET_RC_STATE_SHUTDOWN;
Signature · 1 line
1.7.1
#64 lore raw
In reply to James Simmons
Quoted 6 lines · James Simmons

This is the majority of the fixes that have gone into the LNet layer. Outside a few remaining patches this brings LNet close to what is running in production world wide.

This patch series needs the remove IOC_LIBCFS_PING_TEST ioctl patch landed first.

Please resend an updated version of this series based on the review it had.

thanks,

greg k-h