From 7abf833d25ab6cc866308fe37483dfe2fde28efc Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 23 Nov 2006 15:01:19 +0100 Subject: [PATCH] [PATCH] Close files on error The error path doesn't close already opened files. Also set O_SYNC regardless of file type. Signed-off-by: Jens Axboe --- filesetup.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/filesetup.c b/filesetup.c index 4fa04ecd..50434e64 100644 --- a/filesetup.c +++ b/filesetup.c @@ -317,18 +317,18 @@ static int setup_file(struct thread_data *td, struct fio_file *f) if (td->odirect) flags |= OS_O_DIRECT; + if (td->sync_io) + flags |= O_SYNC; if (td_write(td) || td_rw(td)) { + flags |= O_RDWR; + if (td->filetype == FIO_TYPE_FILE) { if (!td->overwrite) flags |= O_TRUNC; flags |= O_CREAT; } - if (td->sync_io) - flags |= O_SYNC; - - flags |= O_RDWR; f->fd = open(f->file_name, flags, 0600); } else { @@ -362,6 +362,16 @@ int open_files(struct thread_data *td) break; } + if (!err) + return 0; + + for_each_file(td, f, i) { + if (f->fd != -1) { + close(f->fd); + f->fd = -1; + } + } + return err; } -- 2.25.1