X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filesetup.c;h=84cd7f7dfe2bffa93ed62d3ea7aaa790cd6e02b3;hp=75288706cdd2e09a8aa138a67d2d671668557e08;hb=bf0dc8fae8b21c666a0a927c1d473ad59101e7fd;hpb=745508ddfcb7b89b65d99a9dabc6b957aafb9a57 diff --git a/filesetup.c b/filesetup.c index 75288706..84cd7f7d 100644 --- a/filesetup.c +++ b/filesetup.c @@ -15,7 +15,7 @@ static int file_ok(struct thread_data *td, struct fio_file *f) { struct stat st; - if (td->filetype != FIO_TYPE_FILE) + if (td->filetype != FIO_TYPE_FILE || (td->io_ops->flags & FIO_NULLIO)) return 0; if (stat(f->file_name, &st) == -1) @@ -103,9 +103,19 @@ static int create_files(struct thread_data *td) return 0; need_create = 0; - if (td->filetype == FIO_TYPE_FILE) - for_each_file(td, f, i) - need_create += file_ok(td, f); + if (td->filetype == FIO_TYPE_FILE) { + for_each_file(td, f, i) { + int file_there = !file_ok(td, f); + + if (file_there && td->ddir == DDIR_WRITE && + !td->overwrite) { + unlink(f->file_name); + file_there = 0; + } + + need_create += !file_there; + } + } if (!need_create) return 0; @@ -144,6 +154,16 @@ static int file_size(struct thread_data *td, struct fio_file *f) { struct stat st; + /* + * if we are not doing real io, just pretend the file is as large + * as the size= given. this works fine with nrfiles > 1 as well, + * we only really care about it being at least as big as size= + */ + if (td->io_ops->flags & FIO_NULLIO) { + f->real_file_size = f->file_size = td->total_file_size; + return 0; + } + if (td->overwrite) { if (fstat(f->fd, &st) == -1) { td_verror(td, errno); @@ -320,29 +340,40 @@ static int setup_file(struct thread_data *td, struct fio_file *f) { int flags = 0; - if (td->odirect) - flags |= OS_O_DIRECT; - if (td->sync_io) - flags |= O_SYNC; + if (td->io_ops->flags & FIO_NETIO) + return 0; - if (td_write(td) || td_rw(td)) { - flags |= O_RDWR; + /* + * we need a valid file descriptor, but don't create a real file. + * lets just dup stdout, seems like a sensible approach. + */ + if (td->io_ops->flags & FIO_NULLIO) + f->fd = dup(STDOUT_FILENO); + else { + 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; + if (td->filetype == FIO_TYPE_FILE) { + if (!td->overwrite) + flags |= O_TRUNC; - flags |= O_CREAT; - } + flags |= O_CREAT; + } - f->fd = open(f->file_name, flags, 0600); - } else { - if (td->filetype == FIO_TYPE_CHAR) - flags |= O_RDWR; - else - flags |= O_RDONLY; + f->fd = open(f->file_name, flags, 0600); + } else { + if (td->filetype == FIO_TYPE_CHAR) + flags |= O_RDWR; + else + flags |= O_RDONLY; - f->fd = open(f->file_name, flags); + f->fd = open(f->file_name, flags); + } } if (f->fd == -1) {