Whamcloud - gitweb
LU-7623 lnet: Get rid of IOC_LIBCFS_DEBUG_PEER hack
[fs/lustre-release.git] / libcfs / include / libcfs / bitmap.h
index 4c86e8c..e6f156e 100644 (file)
@@ -27,7 +27,7 @@
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
  * Use is subject to license terms.
  *
- * Copyright (c) 2012, Intel Corporation.
+ * Copyright (c) 2012, 2014, Intel Corporation.
  */
 /*
  * This file is part of Lustre, http://www.lustre.org/
 #ifndef _LIBCFS_BITMAP_H_
 #define _LIBCFS_BITMAP_H_
 
-
 typedef struct {
-        int             size;
-        unsigned long   data[0];
+       unsigned int  size;
+       unsigned long data[0];
 } cfs_bitmap_t;
 
 #define CFS_BITMAP_SIZE(nbits) \
@@ -48,18 +47,28 @@ typedef struct {
 static inline
 cfs_bitmap_t *CFS_ALLOCATE_BITMAP(int size)
 {
-        cfs_bitmap_t *ptr;
+       cfs_bitmap_t *ptr;
+
+       LIBCFS_ALLOC(ptr, CFS_BITMAP_SIZE(size));
+       if (ptr == NULL)
+               RETURN(ptr);
 
-        OBD_ALLOC(ptr, CFS_BITMAP_SIZE(size));
-        if (ptr == NULL)
-                RETURN(ptr);
+       ptr->size = size;
 
-        ptr->size = size;
+       RETURN(ptr);
+}
+
+static inline void CFS_RESET_BITMAP(cfs_bitmap_t *bitmap)
+{
+       if (bitmap->size > 0) {
+               int nbits = bitmap->size;
 
-        RETURN (ptr);
+               memset(bitmap, 0, CFS_BITMAP_SIZE(nbits));
+               bitmap->size = nbits;
+       }
 }
 
-#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)
@@ -95,7 +104,7 @@ int cfs_bitmap_check_empty(cfs_bitmap_t *bitmap)
 static inline
 void cfs_bitmap_copy(cfs_bitmap_t *new, cfs_bitmap_t *old)
 {
-       int newsize;
+       size_t newsize;
 
        LASSERT(new->size >= old->size);
        newsize = new->size;