Whamcloud - gitweb
LU-4993 libcfs: convert nodemask_t to linux bitmask 32/10332/6
authorJames Simmons <uja.ornl@gmail.com>
Fri, 27 Jun 2014 22:05:04 +0000 (18:05 -0400)
committerOleg Drokin <oleg.drokin@intel.com>
Wed, 9 Jul 2014 15:34:56 +0000 (15:34 +0000)
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 <uja.ornl@gmail.com>
Reviewed-on: http://review.whamcloud.com/10332
Tested-by: Jenkins
Tested-by: Maloo <hpdd-maloo@intel.com>
Reviewed-by: Liang Zhen <liang.zhen@intel.com>
Reviewed-by: Bob Glossman <bob.glossman@intel.com>
Reviewed-by: Oleg Drokin <oleg.drokin@intel.com>
libcfs/include/libcfs/bitmap.h
libcfs/include/libcfs/libcfs.h
libcfs/include/libcfs/libcfs_cpu.h
libcfs/include/libcfs/libcfs_private.h
libcfs/libcfs/libcfs_cpu.c

index 4c86e8c..1ef4db7 100644 (file)
 #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)
index 8280eb1..98682d8 100644 (file)
@@ -241,8 +241,9 @@ void cfs_get_random_bytes(void *buf, int size);
 
 #include <libcfs/err.h>
 #include <libcfs/libcfs_debug.h>
-#include <libcfs/libcfs_cpu.h>
 #include <libcfs/libcfs_private.h>
+#include <libcfs/bitmap.h>
+#include <libcfs/libcfs_cpu.h>
 #include <libcfs/libcfs_ioctl.h>
 #include <libcfs/libcfs_prim.h>
 #include <libcfs/libcfs_time.h>
index 50aca83..891fc21 100644 (file)
 
 #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 {
index 45c4565..4afb764 100644 (file)
@@ -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__ */
 
index 1fa5d65..0934061 100644 (file)
@@ -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;
        }