Use union for per file engine private data storage
authorTomohiro Kusumi <tkusumi@tuxera.com>
Tue, 7 Mar 2017 20:13:07 +0000 (22:13 +0200)
committerJens Axboe <axboe@fb.com>
Fri, 10 Mar 2017 21:43:37 +0000 (14:43 -0700)
fio_file::engine_data has been used by i/o engines to either keep
the offset or point to engine specific private data with casts.

This commit changes it to a union consists of void* and uint64_t
so get/set of offset/pointer can be done without casts (which is
a common technique used even within this same struct).

This may break external engines on compile time, but fio generally
doesn't care about breakage on external engines (no guarantees on
api/abi compatibility) anyway.

Also confirmed this compiles with pmemblk enabled.

Signed-off-by: Tomohiro Kusumi <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
engines/glusterfs_sync.c
engines/pmemblk.c
engines/sync.c
file.h
filesetup.c

index 05e184cb16465b8123381bde26c87e1f91aae80f..25d05b251fbbd44233ea47b0b138a554d2cec637 100644 (file)
@@ -7,7 +7,7 @@
 
 #include "gfapi.h"
 
-#define LAST_POS(f)    ((f)->engine_data)
+#define LAST_POS(f)    ((f)->engine_pos)
 static int fio_gf_prep(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
index e8476f99ab0782557387a79226dbb3edee4c36a8..52af9eda31cbe4a7a0e0c6b5bd20fd98a4f63d51 100644 (file)
@@ -86,10 +86,6 @@ struct fio_pmemblk_file {
        size_t pmb_bsize;
        size_t pmb_nblocks;
 };
-#define FIOFILEPMBSET(_f, _v)  do {                 \
-       (_f)->engine_data = (uint64_t)(uintptr_t)(_v);  \
-} while(0)
-#define FIOFILEPMBGET(_f)  ((fio_pmemblk_file_t)((_f)->engine_data))
 
 static fio_pmemblk_file_t Cache;
 
@@ -304,26 +300,26 @@ static int fio_pmemblk_open_file(struct thread_data *td, struct fio_file *f)
        if (!pmb)
                return 1;
 
-       FIOFILEPMBSET(f, pmb);
+       FILE_SET_ENG_DATA(f, pmb);
        return 0;
 }
 
 static int fio_pmemblk_close_file(struct thread_data fio_unused *td,
                                  struct fio_file *f)
 {
-       fio_pmemblk_file_t pmb = FIOFILEPMBGET(f);
+       fio_pmemblk_file_t pmb = FILE_ENG_DATA(f);
 
        if (pmb)
                pmb_close(pmb, false);
 
-       FIOFILEPMBSET(f, NULL);
+       FILE_SET_ENG_DATA(f, NULL);
        return 0;
 }
 
 static int fio_pmemblk_get_file_size(struct thread_data *td, struct fio_file *f)
 {
        uint64_t flags = 0;
-       fio_pmemblk_file_t pmb = FIOFILEPMBGET(f);
+       fio_pmemblk_file_t pmb = FILE_ENG_DATA(f);
 
        if (fio_file_size_known(f))
                return 0;
@@ -340,7 +336,7 @@ static int fio_pmemblk_get_file_size(struct thread_data *td, struct fio_file *f)
 
        fio_file_set_size_known(f);
 
-       if (!FIOFILEPMBGET(f))
+       if (!FILE_ENG_DATA(f))
                pmb_close(pmb, true);
 
        return 0;
@@ -349,7 +345,7 @@ static int fio_pmemblk_get_file_size(struct thread_data *td, struct fio_file *f)
 static int fio_pmemblk_queue(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
-       fio_pmemblk_file_t pmb = FIOFILEPMBGET(f);
+       fio_pmemblk_file_t pmb = FILE_ENG_DATA(f);
 
        unsigned long long off;
        unsigned long len;
index 1726b8e6b20e4bac77fef7e3aceaba4e0b6342ce..e76bbbb49e237b807c855d74dd0e40995ef7c0ad 100644 (file)
@@ -18,7 +18,7 @@
 /*
  * Sync engine uses engine_data to store last offset
  */
-#define LAST_POS(f)    ((f)->engine_data)
+#define LAST_POS(f)    ((f)->engine_pos)
 
 struct syncio_data {
        struct iovec *iovecs;
diff --git a/file.h b/file.h
index c403b176827740f10afbc9dd6391b78c928b681d..9801bb584007558da4d7c2a17e78f50133c22fb6 100644 (file)
--- a/file.h
+++ b/file.h
@@ -113,9 +113,12 @@ struct fio_file {
        unsigned int last_write_idx;
 
        /*
-        * For use by the io engine
+        * For use by the io engine for offset or private data storage
         */
-       uint64_t engine_data;
+       union {
+               uint64_t engine_pos;
+               void *engine_data;
+       };
 
        /*
         * if io is protected by a semaphore, this is set
@@ -147,9 +150,8 @@ struct fio_file {
        struct disk_util *du;
 };
 
-#define FILE_ENG_DATA(f)       ((void *) (uintptr_t) (f)->engine_data)
-#define FILE_SET_ENG_DATA(f, data)     \
-       ((f)->engine_data = (uintptr_t) (data))
+#define FILE_ENG_DATA(f)               ((f)->engine_data)
+#define FILE_SET_ENG_DATA(f, data)     ((f)->engine_data = (data))
 
 #define FILE_FLAG_FNS(name)                                            \
 static inline void fio_file_set_##name(struct fio_file *f)             \
index 68a3ab96c25fced92bbc463c2d93e27113a05986..4d0b12790eb6f6061c33f0a2cb7a31d0ee4d27ac 100644 (file)
@@ -519,7 +519,7 @@ int generic_close_file(struct thread_data fio_unused *td, struct fio_file *f)
                f->shadow_fd = -1;
        }
 
-       f->engine_data = 0;
+       f->engine_pos = 0;
        return ret;
 }