backend: fix potential division-by-zero
[fio.git] / libfio.c
index 1fd77e40770065f6c6dfcc0b8c7e80600f188b2e..5ed8c6073603d4edb0b381fb356694cce600e04b 100644 (file)
--- a/libfio.c
+++ b/libfio.c
@@ -27,6 +27,7 @@
 #include <signal.h>
 #include <stdint.h>
 #include <locale.h>
+#include <fcntl.h>
 
 #include "fio.h"
 #include "smalloc.h"
@@ -218,6 +219,36 @@ void fio_terminate_threads(int group_id)
        }
 }
 
+int fio_running_or_pending_io_threads(void)
+{
+       struct thread_data *td;
+       int i;
+
+       for_each_td(td, i) {
+               if (td->flags & TD_F_NOIO)
+                       continue;
+               if (td->runstate < TD_EXITED)
+                       return 1;
+       }
+
+       return 0;
+}
+
+void fio_set_fd_nonblocking(int fd, const char *who)
+{
+       int flags;
+
+       flags = fcntl(fd, F_GETFL);
+       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)
+                       log_err("fio: %s failed to get file flags: %s\n", who, strerror(errno));
+       }
+}
+
 static int endian_check(void)
 {
        union {