From c6ea46a7f402af2cd7033ec78282eb0eae7f3324 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 30 Nov 2005 10:05:59 +0100 Subject: [PATCH] [PATCH] fio: file vs bdev size fixes --- fio-ini.c | 1 + fio.c | 37 ++++++++++++++++++------------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/fio-ini.c b/fio-ini.c index 803b10a..6fb4415 100644 --- a/fio-ini.c +++ b/fio-ini.c @@ -30,6 +30,7 @@ #define DEF_NUMJOBS (1) #define DEF_USE_THREAD (0) #define DEF_USE_MMAP (0) +#define DEF_FILE_SIZE (1024 * 1024 * 1024UL) static int repeatable = DEF_RAND_REPEAT; static char *ini_file; diff --git a/fio.c b/fio.c index 52b3aae..3529d02 100644 --- a/fio.c +++ b/fio.c @@ -1322,13 +1322,8 @@ static int file_size(struct thread_data *td) return 1; } - if (td_read(td)) { - if (!td->file_size || (st.st_size > td->file_size)) - td->file_size = st.st_size; - } else { - if (!td->file_size) - td->file_size = 1024 * 1024 * 1024; - } + if (!td->file_size) + td->file_size = st.st_size; return 0; } @@ -1342,7 +1337,10 @@ static int bdev_size(struct thread_data *td) return 1; } - if (!td->file_size || (bytes > td->file_size)) + /* + * no extend possibilities, so limit size to device size if too large + */ + if (!td->file_size || td->file_size > bytes) td->file_size = bytes; return 0; @@ -1457,9 +1455,11 @@ static int setup_file(struct thread_data *td) } if (create_file(td, td->file_size, 0)) return 1; - } else if (st.st_size < td->file_size) { - if (create_file(td, td->file_size - st.st_size, 1)) - return 1; + } else if (td->filetype == FIO_TYPE_FILE) { + if (st.st_size < td->file_size) { + if (create_file(td, td->file_size - st.st_size, 1)) + return 1; + } } if (td->odirect) @@ -1468,14 +1468,18 @@ static int setup_file(struct thread_data *td) if (td_read(td)) td->fd = open(td->file_name, flags | O_RDONLY); else { - if (!td->overwrite) - flags |= O_TRUNC; + 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; - td->fd = open(td->file_name, flags | O_CREAT, 0600); + td->fd = open(td->file_name, flags, 0600); } if (td->fd == -1) { @@ -1486,11 +1490,6 @@ static int setup_file(struct thread_data *td) if (get_file_size(td)) return 1; - if (td_write(td) && ftruncate(td->fd, td->file_size) == -1) { - td->error = errno; - return 1; - } - if (!td->use_mmap) return setup_file_plain(td); else -- 2.25.1