engines/libaio: better protect against a busy loop in getevents()
[fio.git] / engines / binject.c
index 812b3c4269b83efb96197fe7b7ea19603e1f00c8..c0baf9d262c87376e10cfc43c7732a742c6b50e6 100644 (file)
@@ -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;
@@ -110,7 +111,9 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
                 * don't block for min events == 0
                 */
                if (!min)
-                       fio_set_fd_nonblocking(bf->fd, "binject");
+                       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;
@@ -154,6 +157,9 @@ static int fio_binject_getevents(struct thread_data *td, unsigned int min,
                for_each_file(td, f, 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));
                }