From b2a151925a91f38aeb298d693687a47269ad4e94 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 18 Oct 2006 14:10:42 +0200 Subject: [PATCH] [PATCH Various fixes - Multiple files fixes - Fix for unaligned io issued for raw io Signed-off-by: Jens Axboe --- engines/fio-engine-sg.c | 2 +- filesetup.c | 31 +++++++++++++------------------ fio.c | 36 ++++++++++++++++++++++++++++++------ fio.h | 5 ++++- init.c | 4 ++++ 5 files changed, 52 insertions(+), 26 deletions(-) diff --git a/engines/fio-engine-sg.c b/engines/fio-engine-sg.c index 0db5ca93..5337068b 100644 --- a/engines/fio-engine-sg.c +++ b/engines/fio-engine-sg.c @@ -326,5 +326,5 @@ struct ioengine_ops ioengine = { .event = fio_sgio_event, .cleanup = fio_sgio_cleanup, .sync = fio_sgio_sync, - .flags = FIO_SYNCIO, + .flags = FIO_SYNCIO | FIO_RAWIO, }; diff --git a/filesetup.c b/filesetup.c index adfe940d..e1afeb9a 100644 --- a/filesetup.c +++ b/filesetup.c @@ -12,9 +12,21 @@ static int create_file(struct thread_data *td, struct fio_file *f) { unsigned long long left; unsigned int bs; + struct stat st; char *b; int r; + if (td->filetype != FIO_TYPE_FILE) + return 0; + + if (stat(f->file_name, &st) == -1) { + if (!td->create_file) { + td_verror(td, ENOENT); + return 1; + } + } else if (st.st_size >= (off_t) f->file_size) + return 0; + f->fd = open(f->file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644); if (f->fd < 0) { td_verror(td, errno); @@ -95,6 +107,7 @@ static int create_files(struct thread_data *td) for_each_file(td, f, i) { f->file_size = td->total_file_size / td->nr_files; err = create_file(td, f); + if (err) break; td->io_size += f->file_size; @@ -267,26 +280,8 @@ static int setup_files_plain(struct thread_data *td) static int setup_file(struct thread_data *td, struct fio_file *f) { - struct stat st; int flags = 0; - if (stat(f->file_name, &st) == -1) { - if (errno != ENOENT) { - td_verror(td, errno); - return 1; - } - if (!td->create_file) { - td_verror(td, ENOENT); - return 1; - } - if (create_file(td, f)) - return 1; - } else if (td->filetype == FIO_TYPE_FILE && - st.st_size < (off_t) f->file_size) { - if (create_file(td, f)) - return 1; - } - if (td->odirect) flags |= OS_O_DIRECT; diff --git a/fio.c b/fio.c index dc228a87..405346b6 100644 --- a/fio.c +++ b/fio.c @@ -219,8 +219,16 @@ static unsigned int get_next_buflen(struct thread_data *td) buflen = (buflen + td->min_bs - 1) & ~(td->min_bs - 1); } - if (buflen > td->io_size - td->this_io_bytes[td->ddir]) + if (buflen > td->io_size - td->this_io_bytes[td->ddir]) { + /* + * if using direct/raw io, we may not be able to + * shrink the size. so just fail it. + */ + if (td->io_ops->flags & FIO_RAWIO) + return 0; + buflen = td->io_size - td->this_io_bytes[td->ddir]; + } return buflen; } @@ -526,8 +534,14 @@ static struct io_u *get_io_u(struct thread_data *td, struct fio_file *f) return NULL; } - if (io_u->buflen + io_u->offset > f->file_size) + if (io_u->buflen + io_u->offset > f->file_size) { + if (td->io_ops->flags & FIO_RAWIO) { + put_io_u(td, io_u); + return NULL; + } + io_u->buflen = f->file_size - io_u->offset; + } if (!io_u->buflen) { put_io_u(td, io_u); @@ -577,11 +591,21 @@ static int get_next_verify(struct thread_data *td, struct io_u *io_u) static struct fio_file *get_next_file(struct thread_data *td) { - struct fio_file *f = &td->files[td->next_file]; + int old_next_file = td->next_file; + struct fio_file *f; + + do { + f = &td->files[td->next_file]; + + td->next_file++; + if (td->next_file >= td->nr_files) + td->next_file = 0; + + if (f->fd != -1) + break; - td->next_file++; - if (td->next_file >= td->nr_files) - td->next_file = 0; + f = NULL; + } while (td->next_file != old_next_file); return f; } diff --git a/fio.h b/fio.h index 915c0b53..4be037e9 100644 --- a/fio.h +++ b/fio.h @@ -131,6 +131,7 @@ enum fio_ioengine_flags { FIO_SYNCIO = 1 << 0, FIO_CPUIO = 1 << 1, FIO_MMAPIO = 1 << 2, + FIO_RAWIO = 1 << 3, }; struct fio_file { @@ -150,6 +151,8 @@ struct fio_file { unsigned long *file_map; unsigned int num_maps; + + int fileno; }; /* @@ -504,6 +507,6 @@ extern void close_ioengine(struct thread_data *); #define fio_unused __attribute((__unused__)) #define for_each_file(td, f, i) \ - for ((i) = 0, (f) = &(td)->files[(i)]; (i) < (td)->nr_files; (i)++, (f) = &(td)->files[(i)]) + for ((i) = 0, (f) = &(td)->files[0]; (i) < (td)->nr_files; (i)++, (f) = &(td)->files[(i)]) #endif diff --git a/init.c b/init.c index 967f0b50..20dd625d 100644 --- a/init.c +++ b/init.c @@ -163,6 +163,9 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) td->filetype = FIO_TYPE_CHAR; } + if (td->odirect) + td->io_ops->flags |= FIO_RAWIO; + if (td->filetype == FIO_TYPE_FILE) { char tmp[PATH_MAX]; int len = 0; @@ -176,6 +179,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num) for_each_file(td, f, i) { memset(f, 0, sizeof(*f)); f->fd = -1; + f->fileno = i; sprintf(tmp + len, "%s.%d.%d", jobname, td->thread_number, i); f->file_name = strdup(tmp); -- 2.25.1