rbd: various fixes and cleanups
[fio.git] / engines / binject.c
index 7b8522a466b421071ffb9842de9635138ba3c577..c0baf9d262c87376e10cfc43c7732a742c6b50e6 100644 (file)
@@ -69,7 +69,7 @@ static unsigned int binject_read_commands(struct thread_data *td, void *p,
 one_more:
        events = 0;
        for_each_file(td, f, i) {
-               bf = (struct binject_file *) f->engine_data;
+               bf = (struct binject_file *) (uintptr_t) f->engine_data;
                ret = read(bf->fd, p, left * sizeof(struct b_user_cmd));
                if (ret < 0) {
                        if (errno == EAGAIN)
@@ -91,7 +91,8 @@ one_more:
 }
 
 static int fio_binject_getevents(struct thread_data *td, unsigned int min,
-                             unsigned int max, struct timespec fio_unused *t)
+                                unsigned int max,
+                                const struct timespec fio_unused *t)
 {
        struct binject_data *bd = td->io_ops->data;
        int left = max, ret, r = 0, ev_index = 0;
@@ -104,15 +105,16 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
         * Fill in the file descriptors
         */
        for_each_file(td, f, i) {
-               bf = (struct binject_file *) f->engine_data;
+               bf = (struct binject_file *) (uintptr_t) f->engine_data;
 
                /*
                 * don't block for min events == 0
                 */
-               if (!min) {
-                       bd->fd_flags[i] = fcntl(bf->fd, F_GETFL);
-                       fcntl(bf->fd, F_SETFL, bd->fd_flags[i] | O_NONBLOCK);
-               }
+               if (!min)
+                       bd->fd_flags[i] = fio_set_fd_nonblocking(bf->fd, "binject");
+               else
+                       bd->fd_flags[i] = -1;
+
                bd->pfds[i].fd = bf->fd;
                bd->pfds[i].events = POLLIN;
        }
@@ -153,8 +155,13 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
 
        if (!min) {
                for_each_file(td, f, i) {
-                       bf = (struct binject_file *) f->engine_data;
-                       fcntl(bf->fd, F_SETFL, bd->fd_flags[i]);
+                       bf = (struct binject_file *) (uintptr_t) f->engine_data;
+
+                       if (bd->fd_flags[i] == -1)
+                               continue;
+
+                       if (fcntl(bf->fd, F_SETFL, bd->fd_flags[i]) < 0)
+                               log_err("fio: binject failed to restore fcntl flags: %s\n", strerror(errno));
                }
        }
 
@@ -167,7 +174,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;
-       struct binject_file *bf = (struct binject_file *) io_u->file->engine_data;
+       struct binject_file *bf = (struct binject_file *) (uintptr_t) io_u->file->engine_data;
        int ret;
 
        ret = write(bf->fd, buc, sizeof(*buc));
@@ -181,7 +188,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_file *bf = (struct binject_file *) io_u->file->engine_data;
+       struct binject_file *bf = (struct binject_file *) (uintptr_t) io_u->file->engine_data;
 
        if (io_u->xfer_buflen & (bf->bs - 1)) {
                log_err("read/write not sector aligned\n");
@@ -323,7 +330,7 @@ err_unmap:
 
 static int fio_binject_close_file(struct thread_data *td, struct fio_file *f)
 {
-       struct binject_file *bf = (struct binject_file *) f->engine_data;
+       struct binject_file *bf = (struct binject_file *) (uintptr_t) f->engine_data;
 
        if (bf) {
                binject_unmap_dev(td, bf);