From: James Simmons Date: Fri, 27 Jun 2014 22:05:04 +0000 (-0400) Subject: LU-4993 libcfs: convert nodemask_t to linux bitmask X-Git-Tag: 2.6.0-RC1~12 X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=commitdiff_plain;h=19075957acebe990aa124a68a27d5c1e9d5d20e0;hp=e64d9101cc8ebc61924d6e9db6d7ab3cfa94767c LU-4993 libcfs: convert nodemask_t to linux bitmask Starting in 3.14 kernels nodemask_t was changed from a a unsigned long to a linux bitmap so more than 32 cores could be supported. Using set_bit in cfs_cpt_table_alloc no longer compiles so this patch backports bits of the node management function that use a linux bitmap back end. Cleaned up libcfs bitmap.h to use the libcfs layers memory allocation function. This was pulling in lustre related code that was not defined. Change-Id: I7d08425bc09af2c3c04f7e5ed7d50e7c27d165df Signed-off-by: James Simmons Reviewed-on: http://review.whamcloud.com/10332 Tested-by: Jenkins Tested-by: Maloo Reviewed-by: Liang Zhen Reviewed-by: Bob Glossman Reviewed-by: Oleg Drokin --- diff --git a/libcfs/include/libcfs/bitmap.h b/libcfs/include/libcfs/bitmap.h index 4c86e8c..1ef4db7 100644 --- a/libcfs/include/libcfs/bitmap.h +++ b/libcfs/include/libcfs/bitmap.h @@ -36,6 +36,13 @@ #ifndef _LIBCFS_BITMAP_H_ #define _LIBCFS_BITMAP_H_ +#if !defined(__linux__) || !defined(__KERNEL__) +#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d)) +#define BITS_TO_LONGS(nr) DIV_ROUND_UP(nr, 8 * sizeof(long)) + +#define DECLARE_BITMAP(name, bits) \ + unsigned long name[BITS_TO_LONGS(bits)] +#endif typedef struct { int size; @@ -48,18 +55,18 @@ typedef struct { static inline cfs_bitmap_t *CFS_ALLOCATE_BITMAP(int size) { - cfs_bitmap_t *ptr; + cfs_bitmap_t *ptr; - OBD_ALLOC(ptr, CFS_BITMAP_SIZE(size)); - if (ptr == NULL) - RETURN(ptr); + LIBCFS_ALLOC(ptr, CFS_BITMAP_SIZE(size)); + if (ptr == NULL) + RETURN(ptr); - ptr->size = size; + ptr->size = size; - RETURN (ptr); + RETURN(ptr); } -#define CFS_FREE_BITMAP(ptr) OBD_FREE(ptr, CFS_BITMAP_SIZE(ptr->size)) +#define CFS_FREE_BITMAP(ptr) LIBCFS_FREE(ptr, CFS_BITMAP_SIZE(ptr->size)) static inline void cfs_bitmap_set(cfs_bitmap_t *bitmap, int nbit) diff --git a/libcfs/include/libcfs/libcfs.h b/libcfs/include/libcfs/libcfs.h index 8280eb1..98682d8 100644 --- a/libcfs/include/libcfs/libcfs.h +++ b/libcfs/include/libcfs/libcfs.h @@ -241,8 +241,9 @@ void cfs_get_random_bytes(void *buf, int size); #include #include -#include #include +#include +#include #include #include #include diff --git a/libcfs/include/libcfs/libcfs_cpu.h b/libcfs/include/libcfs/libcfs_cpu.h index 50aca83..891fc21 100644 --- a/libcfs/include/libcfs/libcfs_cpu.h +++ b/libcfs/include/libcfs/libcfs_cpu.h @@ -77,9 +77,15 @@ #ifndef HAVE_LIBCFS_CPT -#ifndef __KERNEL__ -typedef unsigned long cpumask_t; -typedef unsigned long nodemask_t; +#if !defined(__linux__) || !defined(__KERNEL__) +typedef struct nodemask { DECLARE_BITMAP(bits, 1); } nodemask_t; +typedef struct cpumask { DECLARE_BITMAP(bits, 1); } cpumask_t; + +#define node_set(node, dst) __node_set((node), &(dst)) +static __always_inline void __node_set(int node, nodemask_t *dstp) +{ + set_bit(node, dstp->bits); +} #endif struct cfs_cpt_table { diff --git a/libcfs/include/libcfs/libcfs_private.h b/libcfs/include/libcfs/libcfs_private.h index 45c4565..4afb764 100644 --- a/libcfs/include/libcfs/libcfs_private.h +++ b/libcfs/include/libcfs/libcfs_private.h @@ -320,6 +320,8 @@ int libcfs_debug_cleanup(void); /* !__KERNEL__ */ #endif +struct cfs_cpt_table; + /* * allocate per-cpu-partition data, returned value is an array of pointers, * variable can be indexed by CPU ID. @@ -474,11 +476,7 @@ struct cfs_percpt_lock { }; /* return number of private locks */ -static inline int -cfs_percpt_lock_num(struct cfs_percpt_lock *pcl) -{ - return cfs_cpt_number(pcl->pcl_cptab); -} +#define cfs_percpt_lock_num(pcl) cfs_cpt_number(pcl->pcl_cptab) #else /* !__KERNEL__ */ diff --git a/libcfs/libcfs/libcfs_cpu.c b/libcfs/libcfs/libcfs_cpu.c index 1fa5d65..0934061 100644 --- a/libcfs/libcfs/libcfs_cpu.c +++ b/libcfs/libcfs/libcfs_cpu.c @@ -58,7 +58,7 @@ cfs_cpt_table_alloc(unsigned int ncpt) LIBCFS_ALLOC(cptab, sizeof(*cptab)); if (cptab != NULL) { cptab->ctb_version = CFS_CPU_VERSION_MAGIC; - set_bit(0, &cptab->ctb_nodemask); + node_set(0, cptab->ctb_nodemask); cptab->ctb_nparts = ncpt; }