sg/binject: only restore file flags if they have been set
authorJens Axboe <axboe@fb.com>
Tue, 15 Apr 2014 15:07:44 +0000 (09:07 -0600)
committerJens Axboe <axboe@fb.com>
Tue, 15 Apr 2014 15:07:44 +0000 (09:07 -0600)
Signed-off-by: Jens Axboe <axboe@fb.com>
engines/binject.c
engines/sg.c
fio.h
libfio.c

index 812b3c4269b83efb96197fe7b7ea19603e1f00c8..43e316950be45a3f9c9a183c6e7619b60b980b98 100644 (file)
@@ -110,7 +110,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 +156,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));
                }
index 87fe88352f2fd0d4eb77430e827cb4ffab8dbc92..1a027daeb353fca972da13cf8796983024364463 100644 (file)
@@ -78,7 +78,9 @@ static int fio_sgio_getevents(struct thread_data *td, unsigned int min,
                 * don't block for min events == 0
                 */
                if (!min)
-                       fio_set_fd_nonblocking(f->fd, "sg");
+                       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,6 +145,9 @@ re_read:
 
        if (!min) {
                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));
                }
diff --git a/fio.h b/fio.h
index 544916f209bafe8317d54c970da5b3f321c58e8a..9eecba36af12231c5a6d76ec09c3e4ab12dc3b0b 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -441,7 +441,7 @@ extern char *num2str(unsigned long, int, int, int, int);
 extern int ioengine_load(struct thread_data *);
 extern int parse_dryrun(void);
 extern int fio_running_or_pending_io_threads(void);
-extern void fio_set_fd_nonblocking(int, const char *);
+extern int fio_set_fd_nonblocking(int, const char *);
 
 extern uintptr_t page_mask;
 extern uintptr_t page_size;
index 5ed8c6073603d4edb0b381fb356694cce600e04b..8af11297e17c5eed31bd3e23df72ed40c1bfab25 100644 (file)
--- a/libfio.c
+++ b/libfio.c
@@ -234,7 +234,7 @@ int fio_running_or_pending_io_threads(void)
        return 0;
 }
 
-void fio_set_fd_nonblocking(int fd, const char *who)
+int fio_set_fd_nonblocking(int fd, const char *who)
 {
        int flags;
 
@@ -242,11 +242,14 @@ void fio_set_fd_nonblocking(int fd, const char *who)
        if (flags < 0)
                log_err("fio: %s failed to get file flags: %s\n", who, strerror(errno));
        else {
-               flags |= O_NONBLOCK;
-               flags = fcntl(fd, F_SETFL, flags);
-               if (flags < 0)
+               int new_flags = flags | O_NONBLOCK;
+
+               new_flags = fcntl(fd, F_SETFL, new_flags);
+               if (new_flags < 0)
                        log_err("fio: %s failed to get file flags: %s\n", who, strerror(errno));
        }
+
+       return flags;
 }
 
 static int endian_check(void)