From e1a285dfcc0bb70cc8c3dd0643c811a8c2cae57e Mon Sep 17 00:00:00 2001 From: Liang Zhen Date: Sun, 1 Jul 2012 15:17:34 +0800 Subject: [PATCH] LU-1589 lnet: read peers of /proc could be endless There is a chance that reading /proc/sys/lnet/peers could be endless because we didn't set correct condition for ending. This bug is introduced by commit a07e9d350b3e500c7be877f6dcf54380b86a9cbe of LU-56 Signed-off-by: Liang Zhen Change-Id: I25f6dad4a926bb7c62a4b1b1d4c3a86c783e3f7a Reviewed-on: http://review.whamcloud.com/3251 Tested-by: Hudson Reviewed-by: Doug Oucharek Reviewed-by: Bobi Jam Tested-by: Maloo Reviewed-by: Oleg Drokin --- lnet/lnet/router_proc.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/router_proc.c index f64bea2..6bf4773 100644 --- a/lnet/lnet/router_proc.c +++ b/lnet/lnet/router_proc.c @@ -58,7 +58,7 @@ enum { /* * NB: max allowed LNET_CPT_BITS is 8 on 64-bit system and 2 on 32-bit system */ -#define LNET_PROC_CPT_BITS LNET_CPT_BITS +#define LNET_PROC_CPT_BITS (LNET_CPT_BITS + 1) /* change version, 16 bits or 8 bits */ #define LNET_PROC_VER_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8) @@ -413,8 +413,8 @@ int LL_PROC_PROTO(proc_lnet_peers) char *s; int cpt = LNET_PROC_CPT_GET(*ppos); int ver = LNET_PROC_VER_GET(*ppos); - int hoff = LNET_PROC_HOFF_GET(*ppos); int hash = LNET_PROC_HASH_GET(*ppos); + int hoff = LNET_PROC_HOFF_GET(*ppos); int rc = 0; int len; @@ -424,8 +424,10 @@ int LL_PROC_PROTO(proc_lnet_peers) if (*lenp == 0) return 0; - if (cpt >= LNET_CPT_NUMBER) + if (cpt >= LNET_CPT_NUMBER) { + *lenp = 0; return 0; + } LIBCFS_ALLOC(tmpstr, tmpsiz); if (tmpstr == NULL) @@ -442,11 +444,14 @@ int LL_PROC_PROTO(proc_lnet_peers) hoff++; } else { - struct lnet_peer *peer = NULL; - cfs_list_t *p = NULL; - int skip = hoff - 1; - + struct lnet_peer *peer; + cfs_list_t *p; + int skip; again: + p = NULL; + peer = NULL; + skip = hoff - 1; + lnet_net_lock(cpt); ptable = the_lnet.ln_peer_tables[cpt]; if (hoff == 1) @@ -536,14 +541,14 @@ int LL_PROC_PROTO(proc_lnet_peers) } else { /* peer is NULL */ lnet_net_unlock(cpt); + } - if (hash == LNET_PEER_HASH_SIZE && - cpt < LNET_CPT_NUMBER - 1) { - cpt++; - hash = 0; - hoff = 1; + if (hash == LNET_PEER_HASH_SIZE) { + cpt++; + hash = 0; + hoff = 1; + if (peer == NULL && cpt < LNET_CPT_NUMBER) goto again; - } } } -- 1.8.3.1