#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;
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)
#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>
#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 {
/* !__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.
};
/* 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__ */
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;
}