X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filesetup.c;h=1a5a7eccb1b8c95c545c7b94923990d6a005e23c;hp=7ed47a25b5846108125e1028f30fa51d9cb87425;hb=8b5f73134cfaab8e3f72bea4166e57c59c635b69;hpb=d6aed795f2e3e403828abf60874dd2d6e8342a1b diff --git a/filesetup.c b/filesetup.c index 7ed47a25..1a5a7ecc 100644 --- a/filesetup.c +++ b/filesetup.c @@ -13,6 +13,12 @@ static int root_warn; +static inline void clear_error(struct thread_data *td) +{ + td->error = 0; + td->verror[0] = '\0'; +} + /* * Leaves f->fd open on success, caller must close */ @@ -126,7 +132,7 @@ static int extend_file(struct thread_data *td, struct fio_file *f) goto err; } } - if (td->o.fill_device) { + if (td->o.fill_device && !td_write(td)) { fio_file_clear_size_known(f); if (td_io_get_file_size(td, f)) goto err; @@ -150,6 +156,9 @@ static int pre_read_file(struct thread_data *td, struct fio_file *f) unsigned int bs; char *b; + if (td->io_ops->flags & FIO_PIPEIO) + return 0; + if (!fio_file_open(f)) { if (td->io_ops->open_file(td, f)) { log_err("fio: cannot pre-read, failed to open file\n"); @@ -240,6 +249,7 @@ static int bdev_size(struct thread_data *td, struct fio_file *f) } f->real_file_size = bytes; + td->io_ops->close_file(td, f); return 0; err: td->io_ops->close_file(td, f); @@ -284,6 +294,9 @@ static int __file_invalidate_cache(struct thread_data *td, struct fio_file *f, if (off == -1ULL) off = f->file_offset; + if (len == -1ULL || off == -1ULL) + return 0; + dprint(FD_IO, "invalidate cache %s: %llu/%llu\n", f->file_name, off, len); @@ -426,7 +439,7 @@ open_again: char buf[FIO_VERROR_SIZE]; int __e = errno; - if (errno == EPERM && (flags & FIO_O_NOATIME)) { + if (__e == EPERM && (flags & FIO_O_NOATIME)) { flags &= ~FIO_O_NOATIME; goto open_again; } @@ -700,8 +713,10 @@ void close_files(struct thread_data *td) struct fio_file *f; unsigned int i; - for_each_file(td, f, i) - td_io_close_file(td, f); + for_each_file(td, f, i) { + if (fio_file_open(f)) + td_io_close_file(td, f); + } } void close_and_free_files(struct thread_data *td) @@ -717,7 +732,9 @@ void close_and_free_files(struct thread_data *td) unlink(f->file_name); } - td_io_close_file(td, f); + if (fio_file_open(f)) + td_io_close_file(td, f); + remove_file_hash(f); sfree(f->file_name); @@ -838,8 +855,10 @@ int put_file(struct thread_data *td, struct fio_file *f) dprint(FD_FILE, "put file %s, ref=%d\n", f->file_name, f->references); - if (!fio_file_open(f)) + if (!fio_file_open(f)) { + assert(f->fd == -1); return 0; + } assert(f->references); if (--f->references) @@ -856,6 +875,7 @@ int put_file(struct thread_data *td, struct fio_file *f) td->nr_open_files--; fio_file_clear_open(f); + assert(f->fd == -1); return ret; } @@ -995,6 +1015,7 @@ void dup_files(struct thread_data *td, struct thread_data *org) log_err("fio: smalloc OOM\n"); assert(0); } + __f->fd = -1; if (f->file_name) { __f->file_name = smalloc_strdup(f->file_name);