From: Jens Axboe Date: Tue, 27 Mar 2007 13:52:46 +0000 (+0200) Subject: Only overwrite in layout if needed X-Git-Tag: fio-1.15~17 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=507a702f6a61fa461c2566d01dcc46380ee7dffa Only overwrite in layout if needed Signed-off-by: Jens Axboe --- diff --git a/filesetup.c b/filesetup.c index f6b4855b..2da29d15 100644 --- a/filesetup.c +++ b/filesetup.c @@ -12,19 +12,31 @@ static int extend_file(struct thread_data *td, struct fio_file *f) { + int r, new_layout = 0, flags; unsigned long long left; unsigned int bs; char *b; - int r; - if (f->flags & FIO_FILE_EXISTS) { + /* + * check if we need to lay the file out complete again. fio + * does that for operations involving reads, or for writes + * where overwrite is set + */ + if (td_read(td) || (td_write(td) && td->o.overwrite)) + new_layout = 1; + + if (new_layout && (f->flags & FIO_FILE_EXISTS)) { if (unlink(f->file_name) < 0) { td_verror(td, errno, "unlink"); return 1; } } - f->fd = open(f->file_name, O_WRONLY | O_CREAT | O_TRUNC, 0644); + flags = O_WRONLY | O_CREAT; + if (new_layout) + flags |= O_TRUNC; + + f->fd = open(f->file_name, flags, 0644); if (f->fd < 0) { td_verror(td, errno, "open"); return 1; @@ -40,6 +52,9 @@ static int extend_file(struct thread_data *td, struct fio_file *f) goto err; } + if (!new_layout) + goto done; + b = malloc(td->o.max_bs[DDIR_WRITE]); memset(b, 0, td->o.max_bs[DDIR_WRITE]); @@ -70,6 +85,7 @@ static int extend_file(struct thread_data *td, struct fio_file *f) fsync(f->fd); free(b); +done: close(f->fd); f->fd = -1; return 0;