Add helpers for getting/setting file engine data
authorJens Axboe <axboe@fb.com>
Mon, 15 Dec 2014 15:26:11 +0000 (08:26 -0700)
committerJens Axboe <axboe@fb.com>
Mon, 15 Dec 2014 15:26:11 +0000 (08:26 -0700)
Since it's a uint64_t, we need casting to get/set the engine data
or some platforms will complain. Encapsulate that in helper macros.

Signed-off-by: Jens Axboe <axboe@fb.com>
engines/binject.c
engines/fusion-aw.c
engines/mmap.c
file.h

index c0baf9d262c87376e10cfc43c7732a742c6b50e6..f8e83cd2b14426c08a1cd263cf376b757a7eb95a 100644 (file)
@@ -62,14 +62,14 @@ static int pollin_events(struct pollfd *pfds, int fds)
 static unsigned int binject_read_commands(struct thread_data *td, void *p,
                                          int left, int *err)
 {
 static unsigned int binject_read_commands(struct thread_data *td, void *p,
                                          int left, int *err)
 {
-       struct binject_file *bf;
        struct fio_file *f;
        int i, ret, events;
 
 one_more:
        events = 0;
        for_each_file(td, f, i) {
        struct fio_file *f;
        int i, ret, events;
 
 one_more:
        events = 0;
        for_each_file(td, f, i) {
-               bf = (struct binject_file *) (uintptr_t) f->engine_data;
+               struct binject_file *bf = FILE_ENG_DATA(f);
+
                ret = read(bf->fd, p, left * sizeof(struct b_user_cmd));
                if (ret < 0) {
                        if (errno == EAGAIN)
                ret = read(bf->fd, p, left * sizeof(struct b_user_cmd));
                if (ret < 0) {
                        if (errno == EAGAIN)
@@ -99,13 +99,12 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
        void *buf = bd->cmds;
        unsigned int i, events;
        struct fio_file *f;
        void *buf = bd->cmds;
        unsigned int i, events;
        struct fio_file *f;
-       struct binject_file *bf;
 
        /*
         * Fill in the file descriptors
         */
        for_each_file(td, f, i) {
 
        /*
         * Fill in the file descriptors
         */
        for_each_file(td, f, i) {
-               bf = (struct binject_file *) (uintptr_t) f->engine_data;
+               struct binject_file *bf = FILE_ENG_DATA(f);
 
                /*
                 * don't block for min events == 0
 
                /*
                 * don't block for min events == 0
@@ -155,7 +154,7 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
 
        if (!min) {
                for_each_file(td, f, i) {
 
        if (!min) {
                for_each_file(td, f, i) {
-                       bf = (struct binject_file *) (uintptr_t) f->engine_data;
+                       struct binject_file *bf = FILE_ENG_DATA(f);
 
                        if (bd->fd_flags[i] == -1)
                                continue;
 
                        if (bd->fd_flags[i] == -1)
                                continue;
@@ -174,7 +173,7 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
 static int fio_binject_doio(struct thread_data *td, struct io_u *io_u)
 {
        struct b_user_cmd *buc = &io_u->buc;
 static int fio_binject_doio(struct thread_data *td, struct io_u *io_u)
 {
        struct b_user_cmd *buc = &io_u->buc;
-       struct binject_file *bf = (struct binject_file *) (uintptr_t) io_u->file->engine_data;
+       struct binject_file *bf = FILE_ENG_DATA(io_u->file);
        int ret;
 
        ret = write(bf->fd, buc, sizeof(*buc));
        int ret;
 
        ret = write(bf->fd, buc, sizeof(*buc));
@@ -188,7 +187,7 @@ static int fio_binject_prep(struct thread_data *td, struct io_u *io_u)
 {
        struct binject_data *bd = td->io_ops->data;
        struct b_user_cmd *buc = &io_u->buc;
 {
        struct binject_data *bd = td->io_ops->data;
        struct b_user_cmd *buc = &io_u->buc;
-       struct binject_file *bf = (struct binject_file *) (uintptr_t) io_u->file->engine_data;
+       struct binject_file *bf = FILE_ENG_DATA(io_u->file);
 
        if (io_u->xfer_buflen & (bf->bs - 1)) {
                log_err("read/write not sector aligned\n");
 
        if (io_u->xfer_buflen & (bf->bs - 1)) {
                log_err("read/write not sector aligned\n");
@@ -330,12 +329,12 @@ err_unmap:
 
 static int fio_binject_close_file(struct thread_data *td, struct fio_file *f)
 {
 
 static int fio_binject_close_file(struct thread_data *td, struct fio_file *f)
 {
-       struct binject_file *bf = (struct binject_file *) (uintptr_t) f->engine_data;
+       struct binject_file *bf = FILE_ENG_DATA(f);
 
        if (bf) {
                binject_unmap_dev(td, bf);
                free(bf);
 
        if (bf) {
                binject_unmap_dev(td, bf);
                free(bf);
-               f->engine_data = 0;
+               FILE_SET_ENG_DATA(f, NULL);
                return generic_close_file(td, f);
        }
 
                return generic_close_file(td, f);
        }
 
@@ -364,7 +363,7 @@ static int fio_binject_open_file(struct thread_data *td, struct fio_file *f)
        bf = malloc(sizeof(*bf));
        bf->bs = bs;
        bf->minor = bf->fd = -1;
        bf = malloc(sizeof(*bf));
        bf->bs = bs;
        bf->minor = bf->fd = -1;
-       f->engine_data = (uintptr_t) bf;
+       FILE_SET_ENG_DATA(f, bf);
 
        if (binject_map_dev(td, bf, f->fd)) {
 err_close:
 
        if (binject_map_dev(td, bf, f->fd)) {
 err_close:
index 23f623abd016ff9f49ac71a149b57a0b2e70b4da..77844ffe4b724fa7420ea51f1b2c1b8d78c1caf6 100644 (file)
@@ -36,8 +36,8 @@ struct fas_data {
 
 static int queue(struct thread_data *td, struct io_u *io_u)
 {
 
 static int queue(struct thread_data *td, struct io_u *io_u)
 {
+       struct fas_data *d = FILE_ENG_DATA(io_u->file);
        int rc;
        int rc;
-       struct fas_data *d = (struct fas_data *) io_u->file->engine_data;
 
        if (io_u->ddir != DDIR_WRITE) {
                td_vmsg(td, EINVAL, "only writes supported", "io_u->ddir");
 
        if (io_u->ddir != DDIR_WRITE) {
                td_vmsg(td, EINVAL, "only writes supported", "io_u->ddir");
@@ -94,7 +94,7 @@ static int open_file(struct thread_data *td, struct fio_file *f)
                goto error;
        }
        d->nvm_handle = -1;
                goto error;
        }
        d->nvm_handle = -1;
-       f->engine_data = (uintptr_t) d;
+       FILE_SET_ENG_DATA(f, d);
 
        rc = generic_open_file(td, f);
 
 
        rc = generic_open_file(td, f);
 
@@ -144,19 +144,19 @@ free_engine_data:
        free(d);
 error:
        f->fd = -1;
        free(d);
 error:
        f->fd = -1;
-       f->engine_data = 0;
+       FILE_SET_ENG_DATA(f, NULL);
        goto out;
 }
 
 static int close_file(struct thread_data *td, struct fio_file *f)
 {
        goto out;
 }
 
 static int close_file(struct thread_data *td, struct fio_file *f)
 {
-       struct fas_data *d = (struct fas_data *) f->engine_data;
+       struct fas_data *d = FILE_ENG_DATA(f);
 
        if (d) {
                if (d->nvm_handle != -1)
                        nvm_release_handle(d->nvm_handle);
                free(d);
 
        if (d) {
                if (d->nvm_handle != -1)
                        nvm_release_handle(d->nvm_handle);
                free(d);
-               f->engine_data = 0;
+               FILE_SET_ENG_DATA(f, NULL);
        }
 
        return generic_close_file(td, f);
        }
 
        return generic_close_file(td, f);
index 29ac5db24f585e46938fe83e8eb5fabbbee54222..6464cbada7f2cc189abbb23a282be37e6fbac7c9 100644 (file)
@@ -31,7 +31,7 @@ struct fio_mmap_data {
 static int fio_mmap_file(struct thread_data *td, struct fio_file *f,
                         size_t length, off_t off)
 {
 static int fio_mmap_file(struct thread_data *td, struct fio_file *f,
                         size_t length, off_t off)
 {
-       struct fio_mmap_data *fmd = (struct fio_mmap_data *) (uintptr_t) f->engine_data;
+       struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
        int flags = 0;
 
        if (td_rw(td))
        int flags = 0;
 
        if (td_rw(td))
@@ -76,7 +76,7 @@ err:
 static int fio_mmapio_prep_limited(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
 static int fio_mmapio_prep_limited(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
-       struct fio_mmap_data *fmd = (struct fio_mmap_data *) (uintptr_t) f->engine_data;
+       struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
 
        if (io_u->buflen > mmap_map_size) {
                log_err("fio: bs too big for mmap engine\n");
 
        if (io_u->buflen > mmap_map_size) {
                log_err("fio: bs too big for mmap engine\n");
@@ -98,7 +98,7 @@ static int fio_mmapio_prep_limited(struct thread_data *td, struct io_u *io_u)
 static int fio_mmapio_prep_full(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
 static int fio_mmapio_prep_full(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
-       struct fio_mmap_data *fmd = (struct fio_mmap_data *) (uintptr_t) f->engine_data;
+       struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
        int ret;
 
        if (fio_file_partial_mmap(f))
        int ret;
 
        if (fio_file_partial_mmap(f))
@@ -117,7 +117,7 @@ static int fio_mmapio_prep_full(struct thread_data *td, struct io_u *io_u)
 static int fio_mmapio_prep(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
 static int fio_mmapio_prep(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
-       struct fio_mmap_data *fmd = (struct fio_mmap_data *) (uintptr_t) f->engine_data;
+       struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
        int ret;
 
        /*
        int ret;
 
        /*
@@ -152,7 +152,7 @@ done:
 static int fio_mmapio_queue(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
 static int fio_mmapio_queue(struct thread_data *td, struct io_u *io_u)
 {
        struct fio_file *f = io_u->file;
-       struct fio_mmap_data *fmd = (struct fio_mmap_data *) (uintptr_t) f->engine_data;
+       struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
 
        fio_ro_check(td, io_u);
 
 
        fio_ro_check(td, io_u);
 
@@ -232,16 +232,15 @@ static int fio_mmapio_open_file(struct thread_data *td, struct fio_file *f)
                return 1;
        }
 
                return 1;
        }
 
-       f->engine_data = (uintptr_t) fmd;
+       FILE_SET_ENG_DATA(f, fmd);
        return 0;
 }
 
 static int fio_mmapio_close_file(struct thread_data *td, struct fio_file *f)
 {
        return 0;
 }
 
 static int fio_mmapio_close_file(struct thread_data *td, struct fio_file *f)
 {
-       struct fio_mmap_data *fmd;
+       struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
 
 
-       fmd = (struct fio_mmap_data *) (uintptr_t) f->engine_data;
-       f->engine_data = 0;
+       FILE_SET_ENG_DATA(f, NULL);
        free(fmd);
 
        return generic_close_file(td, f);
        free(fmd);
 
        return generic_close_file(td, f);
@@ -249,7 +248,7 @@ static int fio_mmapio_close_file(struct thread_data *td, struct fio_file *f)
 
 static int fio_mmapio_invalidate(struct thread_data *td, struct fio_file *f)
 {
 
 static int fio_mmapio_invalidate(struct thread_data *td, struct fio_file *f)
 {
-       struct fio_mmap_data *fmd = (struct fio_mmap_data *) (uintptr_t) f->engine_data;
+       struct fio_mmap_data *fmd = FILE_ENG_DATA(f);
        int ret;
 
        ret = posix_madvise(fmd->mmap_ptr, fmd->mmap_sz, POSIX_MADV_DONTNEED);
        int ret;
 
        ret = posix_madvise(fmd->mmap_ptr, fmd->mmap_sz, POSIX_MADV_DONTNEED);
diff --git a/file.h b/file.h
index bfb571b69b46d1c3495e09edaec92af2bd71d730..4d24bdc563399c02a7be6c2e431759ac1203ae87 100644 (file)
--- a/file.h
+++ b/file.h
@@ -124,6 +124,10 @@ struct fio_file {
        struct disk_util *du;
 };
 
        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))
+
 struct file_name {
        struct flist_head list;
        char *filename;
 struct file_name {
        struct flist_head list;
        char *filename;