Whamcloud - gitweb
LU-6142 libcfs: use BIT() macro where appropriate 74/38374/2
authorMr NeilBrown <neilb@suse.de>
Mon, 27 Apr 2020 03:36:17 +0000 (13:36 +1000)
committerOleg Drokin <green@whamcloud.com>
Thu, 14 May 2020 05:39:06 +0000 (05:39 +0000)
When accessing a bit in a bitmap/mask/flags-word it can be more
readable to use BIT(num) rather than "1 << num".

This patch makes that change to various places in libcfs.

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I5e945358d2385599f8fe6f1ddff310efe17b589f
Reviewed-on: https://review.whamcloud.com/38374
Tested-by: jenkins <devops@whamcloud.com>
Reviewed-by: Olaf Faaland-LLNL <faaland1@llnl.gov>
Tested-by: Maloo <maloo@whamcloud.com>
Reviewed-by: James Simmons <jsimmons@infradead.org>
Reviewed-by: Oleg Drokin <green@whamcloud.com>
libcfs/include/libcfs/curproc.h
libcfs/include/libcfs/libcfs_fail.h
libcfs/include/libcfs/libcfs_hash.h
libcfs/libcfs/debug.c
libcfs/libcfs/hash.c
libcfs/libcfs/libcfs_string.c

index 6a2b09a..cf2be32 100644 (file)
@@ -51,15 +51,15 @@ typedef __u32 cfs_cap_t;
 #define CFS_CAP_SYS_BOOT               23
 #define CFS_CAP_SYS_RESOURCE           24
 
 #define CFS_CAP_SYS_BOOT               23
 #define CFS_CAP_SYS_RESOURCE           24
 
-#define CFS_CAP_FS_MASK ((1 << CFS_CAP_CHOWN) |                 \
-                         (1 << CFS_CAP_DAC_OVERRIDE) |          \
-                         (1 << CFS_CAP_DAC_READ_SEARCH) |       \
-                         (1 << CFS_CAP_FOWNER) |                \
-                         (1 << CFS_CAP_FSETID ) |               \
-                         (1 << CFS_CAP_LINUX_IMMUTABLE) |       \
-                         (1 << CFS_CAP_SYS_ADMIN) |             \
-                         (1 << CFS_CAP_SYS_BOOT) |              \
-                         (1 << CFS_CAP_SYS_RESOURCE))
+#define CFS_CAP_FS_MASK        (BIT(CFS_CAP_CHOWN)             |       \
+                        BIT(CFS_CAP_DAC_OVERRIDE)      |       \
+                        BIT(CFS_CAP_DAC_READ_SEARCH)   |       \
+                        BIT(CFS_CAP_FOWNER)            |       \
+                        BIT(CFS_CAP_FSETID )           |       \
+                        BIT(CFS_CAP_LINUX_IMMUTABLE)   |       \
+                        BIT(CFS_CAP_SYS_ADMIN)         |       \
+                        BIT(CFS_CAP_SYS_BOOT)          |       \
+                        BIT(CFS_CAP_SYS_RESOURCE))
 
 cfs_cap_t cfs_curproc_cap_pack(void);
 void cfs_curproc_cap_unpack(cfs_cap_t cap);
 
 cfs_cap_t cfs_curproc_cap_pack(void);
 void cfs_curproc_cap_unpack(cfs_cap_t cap);
index 79eda2d..18a51d9 100644 (file)
@@ -59,11 +59,11 @@ enum {
 
 #define CFS_FAILED_BIT       30
 /* CFS_FAILED is 0x40000000 */
 
 #define CFS_FAILED_BIT       30
 /* CFS_FAILED is 0x40000000 */
-#define CFS_FAILED          (1 << CFS_FAILED_BIT)
+#define CFS_FAILED          BIT(CFS_FAILED_BIT)
 
 #define CFS_FAIL_ONCE_BIT    31
 /* CFS_FAIL_ONCE is 0x80000000 */
 
 #define CFS_FAIL_ONCE_BIT    31
 /* CFS_FAIL_ONCE is 0x80000000 */
-#define CFS_FAIL_ONCE       (1 << CFS_FAIL_ONCE_BIT)
+#define CFS_FAIL_ONCE       BIT(CFS_FAIL_ONCE_BIT)
 
 /* The following flags aren't made to be combined */
 #define CFS_FAIL_SKIP        0x20000000 /* skip N times then fail */
 
 /* The following flags aren't made to be combined */
 #define CFS_FAIL_SKIP        0x20000000 /* skip N times then fail */
index b541fe3..d0e452c 100644 (file)
@@ -118,48 +118,49 @@ struct cfs_hash_bd {
  * common hash attributes.
  */
 enum cfs_hash_tag {
  * common hash attributes.
  */
 enum cfs_hash_tag {
-        /**
-         * don't need any lock, caller will protect operations with it's
-         * own lock. With this flag:
-         *  . CFS_HASH_NO_BKTLOCK, CFS_HASH_RW_BKTLOCK, CFS_HASH_SPIN_BKTLOCK
-         *    will be ignored.
-         *  . Some functions will be disabled with this flag, i.e:
-         *    cfs_hash_for_each_empty, cfs_hash_rehash
-         */
-        CFS_HASH_NO_LOCK        = 1 << 0,
-        /** no bucket lock, use one spinlock to protect the whole hash */
-        CFS_HASH_NO_BKTLOCK     = 1 << 1,
-        /** rwlock to protect bucket */
-        CFS_HASH_RW_BKTLOCK     = 1 << 2,
+       /**
+        * don't need any lock, caller will protect operations with it's
+        * own lock. With this flag:
+        *  . CFS_HASH_NO_BKTLOCK, CFS_HASH_RW_BKTLOCK, CFS_HASH_SPIN_BKTLOCK
+        *    will be ignored.
+        *  . Some functions will be disabled with this flag, i.e:
+        *    cfs_hash_for_each_empty, cfs_hash_rehash
+        */
+       CFS_HASH_NO_LOCK        = BIT(0),
+       /** no bucket lock, use one spinlock to protect the whole hash */
+       CFS_HASH_NO_BKTLOCK     = BIT(1),
+       /** rwlock to protect bucket */
+       CFS_HASH_RW_BKTLOCK     = BIT(2),
        /** spinlock to protect bucket */
        /** spinlock to protect bucket */
-        CFS_HASH_SPIN_BKTLOCK   = 1 << 3,
-        /** always add new item to tail */
-        CFS_HASH_ADD_TAIL       = 1 << 4,
-        /** hash-table doesn't have refcount on item */
-        CFS_HASH_NO_ITEMREF     = 1 << 5,
-        /** big name for param-tree */
-        CFS_HASH_BIGNAME        = 1 << 6,
-        /** track global count */
-        CFS_HASH_COUNTER        = 1 << 7,
-        /** rehash item by new key */
-        CFS_HASH_REHASH_KEY     = 1 << 8,
-        /** Enable dynamic hash resizing */
-        CFS_HASH_REHASH         = 1 << 9,
-        /** can shrink hash-size */
-        CFS_HASH_SHRINK         = 1 << 10,
-        /** assert hash is empty on exit */
-        CFS_HASH_ASSERT_EMPTY   = 1 << 11,
-        /** record hlist depth */
-        CFS_HASH_DEPTH          = 1 << 12,
-        /**
-         * rehash is always scheduled in a different thread, so current
-         * change on hash table is non-blocking
-         */
-        CFS_HASH_NBLK_CHANGE    = 1 << 13,
+       CFS_HASH_SPIN_BKTLOCK   = BIT(3),
+       /** always add new item to tail */
+       CFS_HASH_ADD_TAIL       = BIT(4),
+       /** hash-table doesn't have refcount on item */
+       CFS_HASH_NO_ITEMREF     = BIT(5),
+       /** big name for param-tree */
+       CFS_HASH_BIGNAME        = BIT(6),
+       /** track global count */
+       CFS_HASH_COUNTER        = BIT(7),
+       /** rehash item by new key */
+       CFS_HASH_REHASH_KEY     = BIT(8),
+       /** Enable dynamic hash resizing */
+       CFS_HASH_REHASH         = BIT(9),
+       /** can shrink hash-size */
+       CFS_HASH_SHRINK         = BIT(10),
+       /** assert hash is empty on exit */
+       CFS_HASH_ASSERT_EMPTY   = BIT(11),
+       /** record hlist depth */
+       CFS_HASH_DEPTH          = BIT(12),
+       /**
+        * rehash is always scheduled in a different thread, so current
+        * change on hash table is non-blocking
+        */
+       CFS_HASH_NBLK_CHANGE    = BIT(13),
        /** rw semaphore lock to protect bucket */
        /** rw semaphore lock to protect bucket */
-       CFS_HASH_RW_SEM_BKTLOCK = 1 << 14,
-        /** NB, we typed hs_flags as  __u16, please change it
-         * if you need to extend >=16 flags */
+       CFS_HASH_RW_SEM_BKTLOCK = BIT(14),
+       /** NB, we typed hs_flags as  __u16, please change it
+        * if you need to extend >=16 flags
+        */
 };
 
 /** most used attributes */
 };
 
 /** most used attributes */
index de58fa6..280ada3 100644 (file)
@@ -299,7 +299,7 @@ libcfs_debug_mask2str(char *str, int size, int mask, int is_subsys)
                len = 1;
        } else {                                /* space-separated tokens */
                for (i = 0; i < 32; i++) {
                len = 1;
        } else {                                /* space-separated tokens */
                for (i = 0; i < 32; i++) {
-                       if ((mask & (1 << i)) == 0)
+                       if ((mask & BIT(i)) == 0)
                                continue;
 
                        token = fn(i);
                                continue;
 
                        token = fn(i);
index 55a61fd..aa2c7b3 100644 (file)
@@ -636,14 +636,14 @@ cfs_hash_bd_move_locked(struct cfs_hash *hs, struct cfs_hash_bd *bd_old,
 }
 
 enum {
 }
 
 enum {
-        /** always set, for sanity (avoid ZERO intent) */
-        CFS_HS_LOOKUP_MASK_FIND     = 1 << 0,
-        /** return entry with a ref */
-        CFS_HS_LOOKUP_MASK_REF      = 1 << 1,
-        /** add entry if not existing */
-        CFS_HS_LOOKUP_MASK_ADD      = 1 << 2,
-        /** delete entry, ignore other masks */
-        CFS_HS_LOOKUP_MASK_DEL      = 1 << 3,
+       /** always set, for sanity (avoid ZERO intent) */
+       CFS_HS_LOOKUP_MASK_FIND         = BIT(0),
+       /** return entry with a ref */
+       CFS_HS_LOOKUP_MASK_REF          = BIT(1),
+       /** add entry if not existing */
+       CFS_HS_LOOKUP_MASK_ADD          = BIT(2),
+       /** delete entry, ignore other masks */
+       CFS_HS_LOOKUP_MASK_DEL          = BIT(3),
 };
 
 enum cfs_hash_lookup_intent {
 };
 
 enum cfs_hash_lookup_intent {
index c6368de..f559701 100644 (file)
@@ -103,21 +103,21 @@ int cfs_str2mask(const char *str, const char *(*bit2str)(int bit),
 
                 /* match token */
                 found = 0;
 
                 /* match token */
                 found = 0;
-                for (i = 0; i < 32; i++) {
-                        debugstr = bit2str(i);
-                        if (debugstr != NULL &&
-                            strlen(debugstr) == len &&
+               for (i = 0; i < 32; i++) {
+                       debugstr = bit2str(i);
+                       if (debugstr != NULL &&
+                           strlen(debugstr) == len &&
                            strncasecmp(str, debugstr, len) == 0) {
                            strncasecmp(str, debugstr, len) == 0) {
-                                if (op == '-')
-                                        newmask &= ~(1 << i);
-                                else
-                                        newmask |= (1 << i);
-                                found = 1;
-                                break;
-                        }
-                }
+                               if (op == '-')
+                                       newmask &= ~BIT(i);
+                               else
+                                       newmask |= BIT(i);
+                               found = 1;
+                               break;
+                       }
+               }
                 if (!found && len == 3 &&
                 if (!found && len == 3 &&
-                   (strncasecmp(str, "ALL", len) == 0)) {
+                    (strncasecmp(str, "ALL", len) == 0)) {
                         if (op == '-')
                                 newmask = minmask;
                         else
                         if (op == '-')
                                 newmask = minmask;
                         else