From 0263882a95b9213d3afe285ae8adb5d0310d5039 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Mon, 12 Mar 2007 09:25:55 +0100 Subject: [PATCH] File truncation and extend fixes Signed-off-by: Jens Axboe --- engines/mmap.c | 30 +++--------------------------- filesetup.c | 17 ++++++----------- fio.h | 1 + 3 files changed, 10 insertions(+), 38 deletions(-) diff --git a/engines/mmap.c b/engines/mmap.c index 27d5d255..bb4a81a5 100644 --- a/engines/mmap.c +++ b/engines/mmap.c @@ -42,28 +42,6 @@ static int fio_mmapio_queue(struct thread_data *td, struct io_u *io_u) return FIO_Q_COMPLETED; } -static int fio_mmapio_init(struct thread_data *td) -{ - struct fio_file *f; - int i; - - if (!td_write(td)) - return 0; - - /* - * We need to truncate the files to the right size, if - * we are writing to it. - */ - for_each_file(td, f, i) { - if (ftruncate(f->fd, f->file_size) < 0) { - td_verror(td, errno, "ftruncate"); - return 1; - } - } - - return 0; -} - static int fio_mmapio_open(struct thread_data *td, struct fio_file *f) { int ret, flags; @@ -107,9 +85,7 @@ static int fio_mmapio_open(struct thread_data *td, struct fio_file *f) return 0; err: - if (f->mmap) - munmap(f->mmap, f->file_size); - generic_close_file(td, f); + td->io_ops->close_file(td, f); return 1; } @@ -120,16 +96,16 @@ static void fio_mmapio_close(struct thread_data fio_unused *td, munmap(f->mmap, f->file_size); f->mmap = NULL; } + generic_close_file(td, f); } static struct ioengine_ops ioengine = { .name = "mmap", .version = FIO_IOOPS_VERSION, .queue = fio_mmapio_queue, - .init = fio_mmapio_init, .open_file = fio_mmapio_open, .close_file = fio_mmapio_close, - .flags = FIO_SYNCIO, + .flags = FIO_SYNCIO | FIO_NOEXTEND, }; static void fio_init fio_mmapio_register(void) diff --git a/filesetup.c b/filesetup.c index 49c4504f..a85c08f6 100644 --- a/filesetup.c +++ b/filesetup.c @@ -98,7 +98,7 @@ err: static int create_files(struct thread_data *td) { struct fio_file *f; - int i, err, need_create; + int i, err, need_create, can_extend; for_each_file(td, f, i) f->file_size = td->total_file_size / td->nr_files; @@ -106,7 +106,8 @@ static int create_files(struct thread_data *td) /* * unless specifically asked for overwrite, let normal io extend it */ - if (!td->overwrite) + can_extend = !td->overwrite && !(td->io_ops->flags & FIO_NOEXTEND); + if (can_extend) return 0; need_create = 0; @@ -114,7 +115,7 @@ static int create_files(struct thread_data *td) for_each_file(td, f, i) { int file_there = !file_ok(td, f); - if (file_there && td_write(td) && !td->overwrite) { + if (file_there && td_write(td) && !can_extend) { unlink(f->file_name); file_there = 0; } @@ -225,8 +226,6 @@ int file_invalidate_cache(struct thread_data *td, struct fio_file *f) { int ret = 0; - if (!td->invalidate_cache) - return 0; if (td->odirect) return 0; @@ -268,12 +267,8 @@ int generic_open_file(struct thread_data *td, struct fio_file *f) if (td_write(td) || td_rw(td)) { flags |= O_RDWR; - if (td->filetype == FIO_TYPE_FILE) { - if (!td->overwrite) - flags |= O_TRUNC; - + if (td->filetype == FIO_TYPE_FILE) flags |= O_CREAT; - } f->fd = open(f->file_name, flags, 0600); } else { @@ -297,7 +292,7 @@ int generic_open_file(struct thread_data *td, struct fio_file *f) if (get_file_size(td, f)) goto err; - if (file_invalidate_cache(td, f)) + if (td->invalidate_cache && file_invalidate_cache(td, f)) goto err; if (!td_random(td)) { diff --git a/fio.h b/fio.h index 41a1790d..b085cd1e 100644 --- a/fio.h +++ b/fio.h @@ -214,6 +214,7 @@ enum fio_ioengine_flags { FIO_SYNCIO = 1 << 0, /* io engine has synchronous ->queue */ FIO_RAWIO = 1 << 1, /* some sort of direct/raw io */ FIO_DISKLESSIO = 1 << 2, /* no disk involved */ + FIO_NOEXTEND = 1 << 3, /* engine can't extend file */ }; /* -- 2.25.1