Whamcloud - gitweb
LU-6142 lustre: Remove inappropriate uses of BIT() macro. 73/38373/2
authorMr NeilBrown <neilb@suse.de>
Mon, 27 Apr 2020 03:32:27 +0000 (13:32 +1000)
committerOleg Drokin <green@whamcloud.com>
Thu, 7 May 2020 05:43:05 +0000 (05:43 +0000)
The BIT() macro exists for identifying a specific bit in a word when
it is being used as a bitmap (or mask for set of flags etc).
While it uses "1 << ...." it is not a general replacement for that
construct and should not be used to simply to raise '2' to some power.

Varous places in lustre and libcfs use BIT() when a size, rather than
a BIT, are required.  Convert these to explicitly use "1 << exponent".

Test-Parameters: trivial
Signed-off-by: Mr NeilBrown <neilb@suse.de>
Change-Id: I41e1e188da4d2e5dff5b2c05cec607c1d104bcfa
Reviewed-on: https://review.whamcloud.com/38373
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/libcfs/module.c
lustre/ldlm/ldlm_resource.c
lustre/llite/lproc_llite.c
lustre/obdclass/class_obd.c

index 8b165cc..c51b493 100644 (file)
@@ -73,13 +73,14 @@ static inline size_t libcfs_ioctl_packlen(struct libcfs_ioctl_data *data)
 
 static bool libcfs_ioctl_is_invalid(struct libcfs_ioctl_data *data)
 {
-       if (data->ioc_hdr.ioc_len > BIT(30))
+       const int maxlen = 1 << 30;
+       if (data->ioc_hdr.ioc_len > maxlen)
                return true;
 
-       if (data->ioc_inllen1 > BIT(30))
+       if (data->ioc_inllen1 > maxlen)
                return true;
 
-       if (data->ioc_inllen2 > BIT(30))
+       if (data->ioc_inllen2 > maxlen)
                return true;
 
        if (data->ioc_inlbuf1 && !data->ioc_inllen1)
index 1bb742c..5410fb1 100644 (file)
@@ -880,8 +880,7 @@ struct ldlm_namespace *ldlm_namespace_new(struct obd_device *obd, char *name,
        ns->ns_bucket_bits = ldlm_ns_hash_defs[ns_type].nsd_all_bits -
                             ldlm_ns_hash_defs[ns_type].nsd_bkt_bits;
 
-       OBD_ALLOC_LARGE(ns->ns_rs_buckets,
-                       BIT(ns->ns_bucket_bits) * sizeof(ns->ns_rs_buckets[0]));
+       OBD_ALLOC_PTR_ARRAY_LARGE(ns->ns_rs_buckets, 1 << ns->ns_bucket_bits);
        if (!ns->ns_rs_buckets)
                goto out_hash;
 
@@ -951,8 +950,7 @@ out_sysfs:
        ldlm_namespace_sysfs_unregister(ns);
        ldlm_namespace_cleanup(ns, 0);
 out_hash:
-       OBD_FREE_LARGE(ns->ns_rs_buckets,
-                      BIT(ns->ns_bucket_bits) * sizeof(ns->ns_rs_buckets[0]));
+       OBD_FREE_PTR_ARRAY_LARGE(ns->ns_rs_buckets, 1 << ns->ns_bucket_bits);
        kfree(ns->ns_name);
        cfs_hash_putref(ns->ns_rs_hash);
 out_ns:
@@ -1221,8 +1219,7 @@ void ldlm_namespace_free_post(struct ldlm_namespace *ns)
        ldlm_namespace_debugfs_unregister(ns);
        ldlm_namespace_sysfs_unregister(ns);
        cfs_hash_putref(ns->ns_rs_hash);
-       OBD_FREE_LARGE(ns->ns_rs_buckets,
-                      BIT(ns->ns_bucket_bits) * sizeof(ns->ns_rs_buckets[0]));
+       OBD_FREE_PTR_ARRAY_LARGE(ns->ns_rs_buckets, 1 << ns->ns_bucket_bits);
        kfree(ns->ns_name);
        /* Namespace \a ns should be not on list at this time, otherwise
         * this will cause issues related to using freed \a ns in poold
index 3bb3de6..6f90377 100644 (file)
@@ -1759,26 +1759,26 @@ static void ll_display_extents_info(struct ll_rw_extents_info *io_extents,
                 write_tot += pp_info->pp_w_hist.oh_buckets[i];
         }
 
-        for(i = 0; i < LL_HIST_MAX; i++) {
-                r = pp_info->pp_r_hist.oh_buckets[i];
-                w = pp_info->pp_w_hist.oh_buckets[i];
-                read_cum += r;
-                write_cum += w;
-               end = BIT(i + LL_HIST_START - units);
+       for(i = 0; i < LL_HIST_MAX; i++) {
+               r = pp_info->pp_r_hist.oh_buckets[i];
+               w = pp_info->pp_w_hist.oh_buckets[i];
+               read_cum += r;
+               write_cum += w;
+               end = 1 << (i + LL_HIST_START - units);
                seq_printf(seq, "%4lu%c - %4lu%c%c: %14lu %4u %4u  | "
                           "%14lu %4u %4u\n", start, *unitp, end, *unitp,
-                           (i == LL_HIST_MAX - 1) ? '+' : ' ',
-                           r, pct(r, read_tot), pct(read_cum, read_tot),
-                           w, pct(w, write_tot), pct(write_cum, write_tot));
-                start = end;
-               if (start == BIT(10)) {
-                        start = 1;
-                        units += 10;
-                        unitp++;
-                }
-                if (read_cum == read_tot && write_cum == write_tot)
-                        break;
-        }
+                          (i == LL_HIST_MAX - 1) ? '+' : ' ',
+                          r, pct(r, read_tot), pct(read_cum, read_tot),
+                          w, pct(w, write_tot), pct(write_cum, write_tot));
+               start = end;
+               if (start == (1 << 10)) {
+                       start = 1;
+                       units += 10;
+                       unitp++;
+               }
+               if (read_cum == read_tot && write_cum == write_tot)
+                       break;
+       }
 }
 
 static int ll_rw_extents_stats_pp_seq_show(struct seq_file *seq, void *v)
@@ -1939,7 +1939,7 @@ void ll_rw_stats_tally(struct ll_sb_info *sbi, pid_t pid,
                 lprocfs_oh_clear(&io_extents->pp_extents[cur].pp_w_hist);
         }
 
-       for (i = 0; (count >= BIT(LL_HIST_START + i)) &&
+       for (i = 0; (count >= 1 << (LL_HIST_START + i)) &&
             (i < (LL_HIST_MAX - 1)); i++);
        if (rw == 0) {
                io_extents->pp_extents[cur].pp_r_hist.oh_buckets[i]++;
index 3871d32..a399698 100644 (file)
@@ -134,27 +134,28 @@ out:
 
 static int obd_ioctl_is_invalid(struct obd_ioctl_data *data)
 {
-       if (data->ioc_len > BIT(30)) {
+       const int maxlen = 1 << 30;
+       if (data->ioc_len > maxlen) {
                CERROR("OBD ioctl: ioc_len larger than 1<<30\n");
                return 1;
        }
 
-       if (data->ioc_inllen1 > BIT(30)) {
+       if (data->ioc_inllen1 > maxlen) {
                CERROR("OBD ioctl: ioc_inllen1 larger than 1<<30\n");
                return 1;
        }
 
-       if (data->ioc_inllen2 > BIT(30)) {
+       if (data->ioc_inllen2 > maxlen) {
                CERROR("OBD ioctl: ioc_inllen2 larger than 1<<30\n");
                return 1;
        }
 
-       if (data->ioc_inllen3 > BIT(30)) {
+       if (data->ioc_inllen3 > maxlen) {
                CERROR("OBD ioctl: ioc_inllen3 larger than 1<<30\n");
                return 1;
        }
 
-       if (data->ioc_inllen4 > BIT(30)) {
+       if (data->ioc_inllen4 > maxlen) {
                CERROR("OBD ioctl: ioc_inllen4 larger than 1<<30\n");
                return 1;
        }