From ca317243d755f88f194202e1eb5db53d3810df6d Mon Sep 17 00:00:00 2001 From: yangsheng Date: Sat, 22 May 2010 08:44:53 +0800 Subject: [PATCH] b=21951 proc_handler() just want 5 parameters since 2.6.32. i=zhen.liang i=sebastien.buisson --- lnet/autoconf/lustre-lnet.m4 | 26 +++++++ lnet/include/libcfs/linux/portals_compat25.h | 13 ++++ lnet/lnet/router_proc.c | 101 ++++++++++++++++++--------- 3 files changed, 106 insertions(+), 34 deletions(-) diff --git a/lnet/autoconf/lustre-lnet.m4 b/lnet/autoconf/lustre-lnet.m4 index 6011fb6..855baf3 100644 --- a/lnet/autoconf/lustre-lnet.m4 +++ b/lnet/autoconf/lustre-lnet.m4 @@ -1510,6 +1510,30 @@ LB_LINUX_TRY_COMPILE([ EXTRA_KCFLAGS="$tmp_flags" ]) +# See if sysctl proc_handler wants only 5 arguments (since 2.6.32) +AC_DEFUN([LN_5ARGS_SYSCTL_PROC_HANDLER], +[AC_MSG_CHECKING([if sysctl proc_handler wants 5 args]) +LB_LINUX_TRY_COMPILE([ + #include +],[ + struct ctl_table *table = NULL; + int write = 1; + void __user *buffer = NULL; + size_t *lenp = NULL; + loff_t *ppos = NULL; + + proc_handler *proc_handler; + proc_handler(table, write, buffer, lenp, ppos); + +],[ + AC_MSG_RESULT(yes) + AC_DEFINE(HAVE_5ARGS_SYSCTL_PROC_HANDLER, 1, + [sysctl proc_handler wants 5 args]) +],[ + AC_MSG_RESULT(no) +]) +]) + # # LN_PROG_LINUX # @@ -1567,6 +1591,8 @@ LN_HAVE_LINUX_CRED_H LN_STRUCT_CRED_IN_TASK # 2.6.30 LN_FUNC_UNSHARE_FS_STRUCT +# 2.6.32 +LN_5ARGS_SYSCTL_PROC_HANDLER ]) # diff --git a/lnet/include/libcfs/linux/portals_compat25.h b/lnet/include/libcfs/linux/portals_compat25.h index 2ad4d1a..37798cd 100644 --- a/lnet/include/libcfs/linux/portals_compat25.h +++ b/lnet/include/libcfs/linux/portals_compat25.h @@ -145,6 +145,18 @@ typedef unsigned long cpumask_t; void __user *buffer, size_t *lenp) #define DECLARE_LL_PROC_PPOS_DECL loff_t *ppos = &filp->f_pos #else +#ifdef HAVE_5ARGS_SYSCTL_PROC_HANDLER +#define ll_proc_dointvec(table, write, filp, buffer, lenp, ppos) \ + proc_dointvec(table, write, buffer, lenp, ppos); + +#define ll_proc_dolongvec(table, write, filp, buffer, lenp, ppos) \ + proc_doulongvec_minmax(table, write, buffer, lenp, ppos); +#define ll_proc_dostring(table, write, filp, buffer, lenp, ppos) \ + proc_dostring(table, write, buffer, lenp, ppos); +#define LL_PROC_PROTO(name) \ + name(cfs_sysctl_table_t *table, int write, \ + void __user *buffer, size_t *lenp, loff_t *ppos) +#else #define ll_proc_dointvec(table, write, filp, buffer, lenp, ppos) \ proc_dointvec(table, write, filp, buffer, lenp, ppos); #define ll_proc_dostring(table, write, filp, buffer, lenp, ppos) \ @@ -152,6 +164,7 @@ typedef unsigned long cpumask_t; #define LL_PROC_PROTO(name) \ name(cfs_sysctl_table_t *table, int write, struct file *filp, \ void __user *buffer, size_t *lenp, loff_t *ppos) +#endif #define DECLARE_LL_PROC_PPOS_DECL #endif diff --git a/lnet/lnet/router_proc.c b/lnet/lnet/router_proc.c index f04f7ba..b9e3d5f 100644 --- a/lnet/lnet/router_proc.c +++ b/lnet/lnet/router_proc.c @@ -51,6 +51,40 @@ enum { #define PSDEV_LNET_NIS CTL_UNNUMBERED #endif +/* + * NB: we don't use the highest bit of *ppos because it's signed; + * next 9 bits is used to stash idx (assuming that + * LNET_PEER_HASHSIZE < 512) + */ +#define LNET_LOFFT_BITS (sizeof(loff_t) * 8) +#define LNET_VERSION_BITS MAX(((MIN(LNET_LOFFT_BITS, 64)) / 4), 8) +#define LNET_PHASH_IDX_BITS 9 +#define LNET_PHASH_NUM_BITS (LNET_LOFFT_BITS - 1 -\ + LNET_VERSION_BITS - LNET_PHASH_IDX_BITS) +#define LNET_PHASH_BITS (LNET_PHASH_IDX_BITS + LNET_PHASH_NUM_BITS) + +#define LNET_VERSION_BITMASK ((1ULL << LNET_VERSION_BITS) - 1) +#define LNET_PHASH_IDX_BITMASK ((1ULL << LNET_PHASH_IDX_BITS) - 1) +#define LNET_PHASH_NUM_BITMASK ((1ULL << LNET_PHASH_NUM_BITS) - 1) + +#define LNET_VERSION_MASK (LNET_VERSION_BITMASK << LNET_PHASH_BITS) +#define LNET_PHASH_IDX_MASK (LNET_PHASH_IDX_BITMASK << LNET_PHASH_NUM_BITS) +#define LNET_PHASH_NUM_MASK (LNET_PHASH_NUM_BITMASK) + +#define LNET_VERSION_GET(pos) (int)(((pos) & LNET_VERSION_MASK) >> \ + LNET_PHASH_BITS) +#define LNET_PHASH_IDX_GET(pos) (int)(((pos) & LNET_PHASH_IDX_MASK) >> \ + LNET_PHASH_NUM_BITS) +#define LNET_PHASH_NUM_GET(pos) (int)((pos) & LNET_PHASH_NUM_MASK) +#define LNET_VERSION_VALID_MASK(ver) \ + ((unsigned int)((ver) & LNET_VERSION_BITMASK)) +#define LNET_PHASH_POS_MAKE(ver, idx, num) \ + (((((loff_t)(ver)) & LNET_VERSION_BITMASK) << \ + LNET_PHASH_BITS) | \ + ((((loff_t)(idx)) & LNET_PHASH_IDX_BITMASK) <<\ + LNET_PHASH_NUM_BITS) | \ + ((num) & LNET_PHASH_NUM_BITMASK)) + static int __proc_lnet_stats(void *data, int write, loff_t pos, void *buffer, int nob) { @@ -113,10 +147,14 @@ int LL_PROC_PROTO(proc_lnet_routes) char *s; const int tmpsiz = 256; int len; - int *ver_p = (unsigned int *)(&filp->private_data); + int ver; + int num; DECLARE_LL_PROC_PPOS_DECL; + num = LNET_PHASH_NUM_GET(*ppos); + ver = LNET_VERSION_GET(*ppos); + LASSERT (!write); if (*lenp == 0) @@ -138,18 +176,19 @@ int LL_PROC_PROTO(proc_lnet_routes) LASSERT (tmpstr + tmpsiz - s > 0); LNET_LOCK(); - *ver_p = (unsigned int)the_lnet.ln_remote_nets_version; + ver = (unsigned int)the_lnet.ln_remote_nets_version; LNET_UNLOCK(); + *ppos = LNET_PHASH_POS_MAKE(ver, 0, num); } else { struct list_head *n; struct list_head *r; lnet_route_t *route = NULL; lnet_remotenet_t *rnet = NULL; - int skip = *ppos - 1; + int skip = num - 1; LNET_LOCK(); - if (*ver_p != (unsigned int)the_lnet.ln_remote_nets_version) { + if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_remote_nets_version)) { LNET_UNLOCK(); LIBCFS_FREE(tmpstr, tmpsiz); return -ESTALE; @@ -199,8 +238,10 @@ int LL_PROC_PROTO(proc_lnet_routes) } else if (len > 0) { /* wrote something */ if (copy_to_user(buffer, tmpstr, len)) rc = -EFAULT; - else - *ppos += 1; + else { + num += 1; + *ppos = LNET_PHASH_POS_MAKE(ver, 0, num); + } } LIBCFS_FREE(tmpstr, tmpsiz); @@ -218,10 +259,14 @@ int LL_PROC_PROTO(proc_lnet_routers) char *s; const int tmpsiz = 256; int len; - int *ver_p = (unsigned int *)(&filp->private_data); + int ver; + int num; DECLARE_LL_PROC_PPOS_DECL; + num = LNET_PHASH_NUM_GET(*ppos); + ver = LNET_VERSION_GET(*ppos); + LASSERT (!write); if (*lenp == 0) @@ -241,16 +286,17 @@ int LL_PROC_PROTO(proc_lnet_routers) LASSERT (tmpstr + tmpsiz - s > 0); LNET_LOCK(); - *ver_p = (unsigned int)the_lnet.ln_routers_version; + ver = (unsigned int)the_lnet.ln_routers_version; LNET_UNLOCK(); + *ppos = LNET_PHASH_POS_MAKE(ver, 0, num); } else { struct list_head *r; lnet_peer_t *peer = NULL; - int skip = *ppos - 1; + int skip = num - 1; LNET_LOCK(); - if (*ver_p != (unsigned int)the_lnet.ln_routers_version) { + if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_routers_version)) { LNET_UNLOCK(); LIBCFS_FREE(tmpstr, tmpsiz); return -ESTALE; @@ -313,8 +359,10 @@ int LL_PROC_PROTO(proc_lnet_routers) } else if (len > 0) { /* wrote something */ if (copy_to_user(buffer, tmpstr, len)) rc = -EFAULT; - else - *ppos += 1; + else { + num += 1; + *ppos = LNET_PHASH_POS_MAKE(ver, 0, num); + } } LIBCFS_FREE(tmpstr, tmpsiz); @@ -325,23 +373,6 @@ int LL_PROC_PROTO(proc_lnet_routers) return rc; } -/* - * NB: we don't use the highest bit of *ppos because it's signed; - * next 9 bits is used to stash idx (assuming that - * LNET_PEER_HASHSIZE < 512) - */ -#define LNET_LOFFT_BITS (sizeof(loff_t) * 8) -#define LNET_PHASH_BITS 9 -#define LNET_PHASH_IDX_MASK (((1ULL << LNET_PHASH_BITS) - 1) << \ - (LNET_LOFFT_BITS - LNET_PHASH_BITS - 1)) -#define LNET_PHASH_NUM_MASK ((1ULL << \ - (LNET_LOFFT_BITS - LNET_PHASH_BITS -1)) - 1) -#define LNET_PHASH_IDX_GET(pos) (int)(((pos) & LNET_PHASH_IDX_MASK) >> \ - (LNET_LOFFT_BITS - LNET_PHASH_BITS -1)) -#define LNET_PHASH_NUM_GET(pos) (int)((pos) & LNET_PHASH_NUM_MASK) -#define LNET_PHASH_POS_MAKE(idx, num) ((((loff_t)idx) << (LNET_LOFFT_BITS - \ - LNET_PHASH_BITS -1)) | (num)) - int LL_PROC_PROTO(proc_lnet_peers) { int rc = 0; @@ -349,7 +380,7 @@ int LL_PROC_PROTO(proc_lnet_peers) char *s; const int tmpsiz = 256; int len; - int *ver_p = (unsigned int *)(&filp->private_data); + int ver; int idx; int num; @@ -357,8 +388,9 @@ int LL_PROC_PROTO(proc_lnet_peers) idx = LNET_PHASH_IDX_GET(*ppos); num = LNET_PHASH_NUM_GET(*ppos); + ver = LNET_VERSION_GET(*ppos); - CLASSERT ((1 << LNET_PHASH_BITS) > LNET_PEER_HASHSIZE); + CLASSERT ((1ULL << LNET_PHASH_BITS) > LNET_PEER_HASHSIZE); LASSERT (!write); @@ -379,8 +411,9 @@ int LL_PROC_PROTO(proc_lnet_peers) LASSERT (tmpstr + tmpsiz - s > 0); LNET_LOCK(); - *ver_p = (unsigned int)the_lnet.ln_peertable_version; + ver = (unsigned int)the_lnet.ln_peertable_version; LNET_UNLOCK(); + *ppos = LNET_PHASH_POS_MAKE(ver, idx, num); num++; } else { @@ -390,7 +423,7 @@ int LL_PROC_PROTO(proc_lnet_peers) LNET_LOCK(); - if (*ver_p != (unsigned int)the_lnet.ln_peertable_version) { + if (ver != LNET_VERSION_VALID_MASK(the_lnet.ln_peertable_version)) { LNET_UNLOCK(); LIBCFS_FREE(tmpstr, tmpsiz); return -ESTALE; @@ -466,7 +499,7 @@ int LL_PROC_PROTO(proc_lnet_peers) if (copy_to_user(buffer, tmpstr, len)) rc = -EFAULT; else - *ppos = LNET_PHASH_POS_MAKE(idx, num); + *ppos = LNET_PHASH_POS_MAKE(ver, idx, num); } LIBCFS_FREE(tmpstr, tmpsiz); -- 1.8.3.1