mmap backend invalidate fix
[fio.git] / engines / sg.c
index 88d91258d22c89e78298c6084e7dd277b51aa23e..6272b79b568242239ae93cd028e919029b83c7b7 100644 (file)
@@ -62,7 +62,8 @@ static int pollin_events(struct pollfd *pfds, int fds)
 }
 
 static int fio_sgio_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 sgio_data *sd = td->io_ops->data;
        int left = max, ret, r = 0;
@@ -77,10 +78,11 @@ static int fio_sgio_getevents(struct thread_data *td, unsigned int min,
                /*
                 * don't block for min events == 0
                 */
-               if (!min) {
-                       sd->fd_flags[i] = fcntl(f->fd, F_GETFL);
-                       fcntl(f->fd, F_SETFL, sd->fd_flags[i] | O_NONBLOCK);
-               }
+               if (!min)
+                       sd->fd_flags[i] = fio_set_fd_nonblocking(f->fd, "sg");
+               else
+                       sd->fd_flags[i] = -1;
+
                sd->pfds[i].fd = f->fd;
                sd->pfds[i].events = POLLIN;
        }
@@ -143,8 +145,13 @@ re_read:
        }
 
        if (!min) {
-               for_each_file(td, f, i)
-                       fcntl(f->fd, F_SETFL, sd->fd_flags[i]);
+               for_each_file(td, f, i) {
+                       if (sd->fd_flags[i] == -1)
+                               continue;
+
+                       if (fcntl(f->fd, F_SETFL, sd->fd_flags[i]) < 0)
+                               log_err("fio: sg failed to restore fcntl flags: %s\n", strerror(errno));
+               }
        }
 
        return r;