Change ARRAY_SIZE to FIO_ARRAY_SIZE
authorJens Axboe <axboe@kernel.dk>
Wed, 6 Jan 2021 18:32:59 +0000 (11:32 -0700)
committerJens Axboe <axboe@kernel.dk>
Wed, 6 Jan 2021 18:32:59 +0000 (11:32 -0700)
Ensures that we don't clash with external symbols/macros.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
16 files changed:
compiler/compiler.h
diskutil.c
engines/io_uring.c
filesetup.c
gclient.c
gfio.c
helper_thread.c
lib/num2str.c
lib/prio_tree.c
options.c
oslib/libmtd.c
oslib/libmtd_common.h
parse.c
td_error.c
unittests/lib/num2str.c
zbd.c

index 8988236c828a909bca94df49891508fcfc8d8945..44fa87b90cf8c5959ec76c8544aa90480b89f318 100644 (file)
@@ -62,8 +62,8 @@
 #endif
 
 #ifdef FIO_INTERNAL
-#define ARRAY_SIZE(x)    (sizeof((x)) / (sizeof((x)[0])))
-#define FIELD_SIZE(s, f) (sizeof(((__typeof__(s))0)->f))
+#define FIO_ARRAY_SIZE(x)    (sizeof((x)) / (sizeof((x)[0])))
+#define FIO_FIELD_SIZE(s, f) (sizeof(((__typeof__(s))0)->f))
 #endif
 
 #ifndef __has_attribute
index 6c6380bbc774e7b4dca76f6882dac9008008538b..0051a7a035875b3a51493ac527125b413ad1bb7d 100644 (file)
@@ -181,7 +181,7 @@ static int get_device_numbers(char *file_name, int *maj, int *min)
                /*
                 * must be a file, open "." in that path
                 */
-               snprintf(tempname, ARRAY_SIZE(tempname), "%s", file_name);
+               snprintf(tempname, FIO_ARRAY_SIZE(tempname), "%s", file_name);
                p = dirname(tempname);
                if (stat(p, &st)) {
                        perror("disk util stat");
@@ -313,7 +313,7 @@ static struct disk_util *disk_util_add(struct thread_data *td, int majdev,
                sfree(du);
                return NULL;
        }
-       snprintf((char *) du->dus.name, ARRAY_SIZE(du->dus.name), "%s",
+       snprintf((char *) du->dus.name, FIO_ARRAY_SIZE(du->dus.name), "%s",
                 basename(path));
        du->sysfs_root = strdup(path);
        du->major = majdev;
@@ -435,7 +435,7 @@ static struct disk_util *__init_per_file_disk_util(struct thread_data *td,
                        log_err("unknown sysfs layout\n");
                        return NULL;
                }
-               snprintf(tmp, ARRAY_SIZE(tmp), "%s", p);
+               snprintf(tmp, FIO_ARRAY_SIZE(tmp), "%s", p);
                sprintf(path, "%s", tmp);
        }
 
index b997c8d8f9d1d717aa8cfb43b019cd0c4d685fe6..9ce2ae80df59f54dea66630b1182bc7b5fec35e3 100644 (file)
@@ -507,7 +507,7 @@ static void fio_ioring_unmap(struct ioring_data *ld)
 {
        int i;
 
-       for (i = 0; i < ARRAY_SIZE(ld->mmap); i++)
+       for (i = 0; i < FIO_ARRAY_SIZE(ld->mmap); i++)
                munmap(ld->mmap[i].ptr, ld->mmap[i].len);
        close(ld->ring_fd);
 }
index d3c370ca49613805876d70e252d61f6b1b806e44..76b3f9359bad79b44b21d17a8edb74f869b15b7a 100644 (file)
@@ -815,7 +815,7 @@ static unsigned long long get_fs_free_counts(struct thread_data *td)
                } else if (f->filetype != FIO_TYPE_FILE)
                        continue;
 
-               snprintf(buf, ARRAY_SIZE(buf), "%s", f->file_name);
+               snprintf(buf, FIO_ARRAY_SIZE(buf), "%s", f->file_name);
 
                if (stat(buf, &sb) < 0) {
                        if (errno != ENOENT)
@@ -838,7 +838,7 @@ static unsigned long long get_fs_free_counts(struct thread_data *td)
                        continue;
 
                fm = calloc(1, sizeof(*fm));
-               snprintf(fm->__base, ARRAY_SIZE(fm->__base), "%s", buf);
+               snprintf(fm->__base, FIO_ARRAY_SIZE(fm->__base), "%s", buf);
                fm->base = basename(fm->__base);
                fm->key = sb.st_dev;
                flist_add(&fm->list, &list);
index fe83382f32a7566f8e6199e010eae48390b09830..e0e0e7bf920cd0bc3933e5c9f62ae024be4437b4 100644 (file)
--- a/gclient.c
+++ b/gclient.c
@@ -48,7 +48,7 @@ static GtkActionEntry results_menu_items[] = {
        { "PrintFile", GTK_STOCK_PRINT, "Print", "<Control>P", NULL, G_CALLBACK(results_print) },
        { "CloseFile", GTK_STOCK_CLOSE, "Close", "<Control>W", NULL, G_CALLBACK(results_close) },
 };
-static gint results_nmenu_items = ARRAY_SIZE(results_menu_items);
+static gint results_nmenu_items = FIO_ARRAY_SIZE(results_menu_items);
 
 static const gchar *results_ui_string = " \
        <ui> \
@@ -755,7 +755,7 @@ static void gfio_show_io_depths(GtkWidget *vbox, struct thread_stat *ts)
        GtkListStore *model;
        int i;
        const char *labels[] = { "Depth", "0", "1", "2", "4", "8", "16", "32", "64", ">= 64" };
-       const int nr_labels = ARRAY_SIZE(labels);
+       const int nr_labels = FIO_ARRAY_SIZE(labels);
        GType types[nr_labels];
 
        frame = gtk_frame_new("IO depths");
diff --git a/gfio.c b/gfio.c
index 734651b676c99bac87e4e6fd1c46a22eb03a1860..22c5314d3d1d5f93141dd7bedd8b7e902a848cba 100644 (file)
--- a/gfio.c
+++ b/gfio.c
@@ -1274,7 +1274,7 @@ static GtkActionEntry menu_items[] = {
        { "Quit", GTK_STOCK_QUIT, NULL,   "<Control>Q", NULL, G_CALLBACK(quit_clicked) },
        { "About", GTK_STOCK_ABOUT, NULL,  NULL, NULL, G_CALLBACK(about_dialog) },
 };
-static gint nmenu_items = ARRAY_SIZE(menu_items);
+static gint nmenu_items = FIO_ARRAY_SIZE(menu_items);
 
 static const gchar *ui_string = " \
        <ui> \
@@ -1447,7 +1447,7 @@ static GtkWidget *new_client_page(struct gui_entry *ge)
        gtk_container_add(GTK_CONTAINER(bottom_align), ge->buttonbox);
        gtk_box_pack_start(GTK_BOX(main_vbox), bottom_align, FALSE, FALSE, 0);
 
-       add_buttons(ge, buttonspeclist, ARRAY_SIZE(buttonspeclist));
+       add_buttons(ge, buttonspeclist, FIO_ARRAY_SIZE(buttonspeclist));
 
        /*
         * Set up thread status progress bar
index 2d553654c0814d29bc76a4038d97d547e5558adc..d8e7ebfe573ef5531fb2c60d00e87e4cb2127308 100644 (file)
@@ -311,7 +311,7 @@ static void *helper_thread_main(void *data)
        block_signals();
 
        fio_get_mono_time(&ts);
-       msec_to_next_event = reset_timers(timer, ARRAY_SIZE(timer), &ts);
+       msec_to_next_event = reset_timers(timer, FIO_ARRAY_SIZE(timer), &ts);
 
        fio_sem_up(hd->startup_sem);
 
@@ -329,9 +329,9 @@ static void *helper_thread_main(void *data)
 
                if (action == A_RESET)
                        msec_to_next_event = reset_timers(timer,
-                                               ARRAY_SIZE(timer), &ts);
+                                               FIO_ARRAY_SIZE(timer), &ts);
 
-               for (i = 0; i < ARRAY_SIZE(timer); ++i)
+               for (i = 0; i < FIO_ARRAY_SIZE(timer); ++i)
                        ret = eval_timer(&timer[i], &ts, &msec_to_next_event);
 
                if (action == A_DO_STAT)
index 726f1c44159fd8a16379777411030b262eeb6cb1..3597de2f10903b461d890a536b55033ede87237f 100644 (file)
@@ -7,8 +7,6 @@
 #include "../oslib/asprintf.h"
 #include "num2str.h"
 
-#define ARRAY_SIZE(x)    (sizeof((x)) / (sizeof((x)[0])))
-
 /**
  * num2str() - Cheesy number->string conversion, complete with carry rounding error.
  * @num: quantity (e.g., number of blocks, bytes or bits)
@@ -38,7 +36,7 @@ char *num2str(uint64_t num, int maxlen, int base, int pow2, enum n2s_unit units)
        char *buf;
 
        compiletime_assert(sizeof(sistr) == sizeof(iecstr), "unit prefix arrays must be identical sizes");
-       assert(units < ARRAY_SIZE(unitstr));
+       assert(units < FIO_ARRAY_SIZE(unitstr));
 
        if (pow2)
                unitprefix = iecstr;
@@ -69,7 +67,7 @@ char *num2str(uint64_t num, int maxlen, int base, int pow2, enum n2s_unit units)
         * Divide by K/Ki until string length of num <= maxlen.
         */
        modulo = -1U;
-       while (post_index < ARRAY_SIZE(sistr)) {
+       while (post_index < FIO_ARRAY_SIZE(sistr)) {
                sprintf(tmp, "%llu", (unsigned long long) num);
                if (strlen(tmp) <= maxlen)
                        break;
@@ -80,7 +78,7 @@ char *num2str(uint64_t num, int maxlen, int base, int pow2, enum n2s_unit units)
                post_index++;
        }
 
-       if (post_index >= ARRAY_SIZE(sistr))
+       if (post_index >= FIO_ARRAY_SIZE(sistr))
                post_index = 0;
 
        /*
index d8e1b89a94038c2df63e2a0f7435f8184ecd2ba0..c4f66a49299188a45d0dcd2d6f9ef099b8d0e1ac 100644 (file)
@@ -18,8 +18,6 @@
 #include "../compiler/compiler.h"
 #include "prio_tree.h"
 
-#define ARRAY_SIZE(x)    (sizeof((x)) / (sizeof((x)[0])))
-
 /*
  * A clever mix of heap and radix trees forms a radix priority search tree (PST)
  * which is useful for storing intervals, e.g, we can consider a vma as a closed
@@ -57,9 +55,9 @@ static void fio_init prio_tree_init(void)
 {
        unsigned int i;
 
-       for (i = 0; i < ARRAY_SIZE(index_bits_to_maxindex) - 1; i++)
+       for (i = 0; i < FIO_ARRAY_SIZE(index_bits_to_maxindex) - 1; i++)
                index_bits_to_maxindex[i] = (1UL << (i + 1)) - 1;
-       index_bits_to_maxindex[ARRAY_SIZE(index_bits_to_maxindex) - 1] = ~0UL;
+       index_bits_to_maxindex[FIO_ARRAY_SIZE(index_bits_to_maxindex) - 1] = ~0UL;
 }
 
 /*
index 1e91b3e9e23a79eb780b35c22e9cd7681e82ab58..4c4725897db46c2f5d336468bd7b4b3c55cd63c1 100644 (file)
--- a/options.c
+++ b/options.c
@@ -22,7 +22,7 @@ char client_sockaddr_str[INET6_ADDRSTRLEN] = { 0 };
 static const struct pattern_fmt_desc fmt_desc[] = {
        {
                .fmt   = "%o",
-               .len   = FIELD_SIZE(struct io_u *, offset),
+               .len   = FIO_FIELD_SIZE(struct io_u *, offset),
                .paste = paste_blockoff
        },
        { }
@@ -1387,7 +1387,7 @@ static int str_verify_pattern_cb(void *data, const char *input)
        struct thread_data *td = cb_data_to_td(data);
        int ret;
 
-       td->o.verify_fmt_sz = ARRAY_SIZE(td->o.verify_fmt);
+       td->o.verify_fmt_sz = FIO_ARRAY_SIZE(td->o.verify_fmt);
        ret = parse_and_fill_pattern(input, strlen(input), td->o.verify_pattern,
                                     MAX_PATTERN_SIZE, fmt_desc,
                                     td->o.verify_fmt, &td->o.verify_fmt_sz);
index 385b9d2fa6b376b79ca06aa9690b9167aada2cbc..5fca3a01b81d734a01c9d0dc4f8f873cdd3ba258 100644 (file)
@@ -35,6 +35,8 @@
 #include <sys/ioctl.h>
 #include <inttypes.h>
 
+#include "../compiler/compiler.h"
+
 #include <mtd/mtd-user.h>
 #include "libmtd.h"
 
@@ -960,7 +962,7 @@ int mtd_torture(libmtd_t desc, const struct mtd_dev_info *mtd, int fd, int eb)
        void *buf;
 
        normsg("run torture test for PEB %d", eb);
-       patt_count = ARRAY_SIZE(patterns);
+       patt_count = FIO_ARRAY_SIZE(patterns);
 
        buf = xmalloc(mtd->eb_size);
 
index 4ed9f0ba8fde036807f163297a333a191aeb623f..db0494dda3587247efd97335983ca63e11d5b387 100644 (file)
@@ -47,7 +47,6 @@ extern "C" {
 #define MAX(a, b) ((a) > (b) ? (a) : (b))
 #endif
 #define min(a, b) MIN(a, b) /* glue for linux kernel source */
-#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
 
 #define ALIGN(x,a) __ALIGN_MASK(x,(__typeof__(x))(a)-1)
 #define __ALIGN_MASK(x,mask) (((x)+(mask))&~(mask))
diff --git a/parse.c b/parse.c
index f4cefcf6243edbd911cb4f274611912c440a5f07..c28d82efb0932a5cb37c8b2b9f715c09b78fbfb3 100644 (file)
--- a/parse.c
+++ b/parse.c
@@ -501,7 +501,7 @@ static int str_match_len(const struct value_pair *vp, const char *str)
 
 static const char *opt_type_name(const struct fio_option *o)
 {
-       compiletime_assert(ARRAY_SIZE(opt_type_names) - 1 == FIO_OPT_UNSUPPORTED,
+       compiletime_assert(FIO_ARRAY_SIZE(opt_type_names) - 1 == FIO_OPT_UNSUPPORTED,
                                "opt_type_names[] index");
 
        if (o->type <= FIO_OPT_UNSUPPORTED)
index 9d58a31471d03f3f7db70fb6660432750f5c882c..13408f2ebd455b242c966c67d6f2b7c23aeabbfa 100644 (file)
@@ -20,7 +20,7 @@ int td_non_fatal_error(struct thread_data *td, enum error_type_bit etype,
 
        if (!td->o.ignore_error[etype]) {
                td->o.ignore_error[etype] = __NON_FATAL_ERR;
-               td->o.ignore_error_nr[etype] = ARRAY_SIZE(__NON_FATAL_ERR);
+               td->o.ignore_error_nr[etype] = FIO_ARRAY_SIZE(__NON_FATAL_ERR);
        }
 
        if (!(td->o.continue_on_error & (1 << etype)))
index a3492a8d925aa0d24b4e8f33f9402a36777165d0..8f12cf83fea368987af06eddbfa0d9b9cf0b8dd5 100644 (file)
@@ -29,7 +29,7 @@ static void test_num2str(void)
        char *str;
        int i;
 
-       for (i = 0; i < ARRAY_SIZE(testcases); ++i) {
+       for (i = 0; i < FIO_ARRAY_SIZE(testcases); ++i) {
                p = &testcases[i];
                str = num2str(p->num, p->maxlen, p->base, p->pow2, p->unit);
                CU_ASSERT_STRING_EQUAL(str, p->expected);
diff --git a/zbd.c b/zbd.c
index 9327816aaf8f8eb68f7f971eb8958b9fbcf0e616..f2599bd4871cd97e7028654d04083fd5eba64d90 100644 (file)
--- a/zbd.c
+++ b/zbd.c
@@ -338,7 +338,7 @@ static bool zbd_verify_bs(void)
                        if (!f->zbd_info)
                                continue;
                        zone_size = f->zbd_info->zone_size;
-                       for (k = 0; k < ARRAY_SIZE(td->o.bs); k++) {
+                       for (k = 0; k < FIO_ARRAY_SIZE(td->o.bs); k++) {
                                if (td->o.verify != VERIFY_NONE &&
                                    zone_size % td->o.bs[k] != 0) {
                                        log_info("%s: block size %llu is not a divisor of the zone size %d\n",