From: Jens Axboe Date: Tue, 29 Aug 2017 21:35:49 +0000 (-0600) Subject: Merge branch 'asmfix' of https://github.com/oohal/fio X-Git-Tag: fio-3.1~31 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=63463983ce10e9678c5ad309608630eea873b4df;hp=e8bf784a034fe73aeed99a3360e803af38728126 Merge branch 'asmfix' of https://github.com/oohal/fio --- diff --git a/HOWTO b/HOWTO index f36d4a77..3a720c35 100644 --- a/HOWTO +++ b/HOWTO @@ -947,7 +947,7 @@ I/O type .. option:: direct=bool If value is true, use non-buffered I/O. This is usually O_DIRECT. Note that - ZFS on Solaris doesn't support direct I/O. On Windows the synchronous + OpenBSD and ZFS on Solaris don't support direct I/O. On Windows the synchronous ioengines don't support direct I/O. Default: false. .. option:: atomic=bool diff --git a/file.h b/file.h index 84daa5f6..ad8802d3 100644 --- a/file.h +++ b/file.h @@ -211,5 +211,6 @@ extern void filesetup_mem_free(void); extern void fio_file_reset(struct thread_data *, struct fio_file *); extern bool fio_files_done(struct thread_data *); extern bool exists_and_not_regfile(const char *); +extern int fio_set_directio(struct thread_data *, struct fio_file *); #endif diff --git a/filesetup.c b/filesetup.c index a6a94ee1..c4240d2a 100644 --- a/filesetup.c +++ b/filesetup.c @@ -196,6 +196,9 @@ static int extend_file(struct thread_data *td, struct fio_file *f) } } + if (td->o.odirect && !OS_O_DIRECT && fio_set_directio(td, f)) + goto err; + left = f->real_file_size; bs = td->o.max_bs[DDIR_WRITE]; if (bs > left) @@ -1852,3 +1855,31 @@ void filesetup_mem_free(void) { free_already_allocated(); } + +/* + * This function is for platforms which support direct I/O but not O_DIRECT. + */ +int fio_set_directio(struct thread_data *td, struct fio_file *f) +{ +#ifdef FIO_OS_DIRECTIO + int ret = fio_set_odirect(f); + + if (ret) { + td_verror(td, ret, "fio_set_directio"); +#if defined(__sun__) + if (ret == ENOTTY) { /* ENOTTY suggests RAW device or ZFS */ + log_err("fio: doing directIO to RAW devices or ZFS not supported\n"); + } else { + log_err("fio: the file system does not seem to support direct IO\n"); + } +#else + log_err("fio: the file system does not seem to support direct IO\n"); +#endif + return -1; + } + + return 0; +#else + return -1; +#endif +} diff --git a/fio.1 b/fio.1 index b8b3da2f..5b63dfd7 100644 --- a/fio.1 +++ b/fio.1 @@ -717,7 +717,7 @@ read. The two zone options can be used to only do I/O on zones of a file. .TP .BI direct \fR=\fPbool If value is true, use non\-buffered I/O. This is usually O_DIRECT. Note that -ZFS on Solaris doesn't support direct I/O. On Windows the synchronous +OpenBSD and ZFS on Solaris don't support direct I/O. On Windows the synchronous ioengines don't support direct I/O. Default: false. .TP .BI atomic \fR=\fPbool diff --git a/io_u.c b/io_u.c index ed8e84ab..db043e4a 100644 --- a/io_u.c +++ b/io_u.c @@ -2188,7 +2188,7 @@ int do_io_u_trim(const struct thread_data *td, struct io_u *io_u) struct fio_file *f = io_u->file; int ret; - ret = os_trim(f->fd, io_u->offset, io_u->xfer_buflen); + ret = os_trim(f, io_u->offset, io_u->xfer_buflen); if (!ret) return io_u->xfer_buflen; diff --git a/ioengines.c b/ioengines.c index 6e6e3dea..919781c4 100644 --- a/ioengines.c +++ b/ioengines.c @@ -495,26 +495,8 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f) } #endif -#ifdef FIO_OS_DIRECTIO - /* - * Some OS's have a distinct call to mark the file non-buffered, - * instead of using O_DIRECT (Solaris) - */ - if (td->o.odirect) { - int ret = fio_set_odirect(f->fd); - - if (ret) { - td_verror(td, ret, "fio_set_odirect"); - if (ret == ENOTTY) { /* ENOTTY suggests RAW device or ZFS */ - log_err("fio: doing directIO to RAW devices or ZFS not supported\n"); - } else { - log_err("fio: the file system does not seem to support direct IO\n"); - } - - goto err; - } - } -#endif + if (td->o.odirect && !OS_O_DIRECT && fio_set_directio(td, f)) + goto err; done: log_file(td, f, FIO_LOG_OPEN_FILE); diff --git a/os/os-android.h b/os/os-android.h index b217daa9..bb590e47 100644 --- a/os/os-android.h +++ b/os/os-android.h @@ -274,7 +274,7 @@ static inline unsigned long long get_fs_free_size(const char *path) return ret; } -static inline int os_trim(int fd, unsigned long long start, +static inline int os_trim(struct fio_file *f, unsigned long long start, unsigned long long len) { uint64_t range[2]; @@ -282,7 +282,7 @@ static inline int os_trim(int fd, unsigned long long start, range[0] = start; range[1] = len; - if (!ioctl(fd, BLKDISCARD, range)) + if (!ioctl(f->fd, BLKDISCARD, range)) return 0; return errno; diff --git a/os/os-dragonfly.h b/os/os-dragonfly.h index 8d158335..423b2369 100644 --- a/os/os-dragonfly.h +++ b/os/os-dragonfly.h @@ -216,7 +216,7 @@ static inline unsigned long long get_fs_free_size(const char *path) return ret; } -static inline int os_trim(int fd, unsigned long long start, +static inline int os_trim(struct fio_file *f, unsigned long long start, unsigned long long len) { off_t range[2]; @@ -224,7 +224,7 @@ static inline int os_trim(int fd, unsigned long long start, range[0] = start; range[1] = len; - if (!ioctl(fd, IOCTLTRIM, range)) + if (!ioctl(f->fd, IOCTLTRIM, range)) return 0; return errno; diff --git a/os/os-freebsd.h b/os/os-freebsd.h index e6da286e..4a7cdeb7 100644 --- a/os/os-freebsd.h +++ b/os/os-freebsd.h @@ -117,7 +117,7 @@ static inline unsigned long long get_fs_free_size(const char *path) return ret; } -static inline int os_trim(int fd, unsigned long long start, +static inline int os_trim(struct fio_file *f, unsigned long long start, unsigned long long len) { off_t range[2]; @@ -125,7 +125,7 @@ static inline int os_trim(int fd, unsigned long long start, range[0] = start; range[1] = len; - if (!ioctl(fd, DIOCGDELETE, range)) + if (!ioctl(f->fd, DIOCGDELETE, range)) return 0; return errno; diff --git a/os/os-linux.h b/os/os-linux.h index e7d600dd..1ad6ebd2 100644 --- a/os/os-linux.h +++ b/os/os-linux.h @@ -281,7 +281,7 @@ static inline unsigned long long get_fs_free_size(const char *path) return ret; } -static inline int os_trim(int fd, unsigned long long start, +static inline int os_trim(struct fio_file *f, unsigned long long start, unsigned long long len) { uint64_t range[2]; @@ -289,7 +289,7 @@ static inline int os_trim(int fd, unsigned long long start, range[0] = start; range[1] = len; - if (!ioctl(fd, BLKDISCARD, range)) + if (!ioctl(f->fd, BLKDISCARD, range)) return 0; return errno; diff --git a/os/os-mac.h b/os/os-mac.h index a1536c70..92a60ee9 100644 --- a/os/os-mac.h +++ b/os/os-mac.h @@ -41,9 +41,9 @@ typedef unsigned int clockid_t; #endif #define FIO_OS_DIRECTIO -static inline int fio_set_odirect(int fd) +static inline int fio_set_odirect(struct fio_file *f) { - if (fcntl(fd, F_NOCACHE, 1) == -1) + if (fcntl(f->fd, F_NOCACHE, 1) == -1) return errno; return 0; } diff --git a/os/os-netbsd.h b/os/os-netbsd.h index eac76cf2..682a11c9 100644 --- a/os/os-netbsd.h +++ b/os/os-netbsd.h @@ -11,9 +11,9 @@ #include #include #include -/* XXX hack to avoid confilcts between rbtree.h and */ -#define rb_node _rb_node #include + +/* XXX hack to avoid confilcts between rbtree.h and */ #undef rb_node #undef rb_left #undef rb_right @@ -26,8 +26,6 @@ #define FIO_HAVE_FS_STAT #define FIO_HAVE_GETTID -#undef FIO_HAVE_CPU_AFFINITY /* doesn't exist */ - #define OS_MAP_ANON MAP_ANON #ifndef PTHREAD_STACK_MIN diff --git a/os/os-openbsd.h b/os/os-openbsd.h index 675bf892..b4c02c9b 100644 --- a/os/os-openbsd.h +++ b/os/os-openbsd.h @@ -11,23 +11,21 @@ #include #include #include -/* XXX hack to avoid conflicts between rbtree.h and */ #include + +/* XXX hack to avoid conflicts between rbtree.h and */ #undef RB_BLACK #undef RB_RED #undef RB_ROOT #include "../file.h" -#undef FIO_HAVE_ODIRECT #define FIO_USE_GENERIC_RAND #define FIO_USE_GENERIC_INIT_RANDOM_STATE #define FIO_HAVE_FS_STAT #define FIO_HAVE_GETTID #define FIO_HAVE_SHM_ATTACH_REMOVED -#undef FIO_HAVE_CPU_AFFINITY /* doesn't exist */ - #define OS_MAP_ANON MAP_ANON #ifndef PTHREAD_STACK_MIN diff --git a/os/os-solaris.h b/os/os-solaris.h index 8f8f53b6..6af25d2a 100644 --- a/os/os-solaris.h +++ b/os/os-solaris.h @@ -85,9 +85,9 @@ static inline long os_random_long(os_random_state_t *rs) #define FIO_OS_DIRECTIO extern int directio(int, int); -static inline int fio_set_odirect(int fd) +static inline int fio_set_odirect(struct fio_file *f) { - if (directio(fd, DIRECTIO_ON) < 0) + if (directio(f->fd, DIRECTIO_ON) < 0) return errno; return 0;