X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=filesetup.c;h=483226ae56e5d488d4601a14c1ba29b93f91d360;hp=d10840a2374cad5d5cf8add743672756026c6d87;hb=126d65c6fc97d6acdc568aa5a969c012018daf15;hpb=982016d689dc7fedbb09646ba0df7e72a781b164 diff --git a/filesetup.c b/filesetup.c index d10840a2..483226ae 100644 --- a/filesetup.c +++ b/filesetup.c @@ -209,11 +209,16 @@ int file_invalidate_cache(struct thread_data *td, struct fio_file *f) return ret; } -void generic_close_file(struct thread_data fio_unused *td, struct fio_file *f) +int generic_close_file(struct thread_data fio_unused *td, struct fio_file *f) { + int ret = 0; + dprint(FD_FILE, "fd close %s\n", f->file_name); - close(f->fd); + if (close(f->fd) < 0) + ret = errno; + f->fd = -1; + return ret; } int generic_open_file(struct thread_data *td, struct fio_file *f) @@ -497,7 +502,7 @@ int init_random_map(struct thread_data *td) struct fio_file *f; unsigned int i; - if (td->o.norandommap) + if (td->o.norandommap || !td_random(td)) return 0; for_each_file(td, f, i) { @@ -520,6 +525,15 @@ 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); +} + +void close_and_free_files(struct thread_data *td) +{ + struct fio_file *f; + unsigned int i; + dprint(FD_FILE, "close files\n"); for_each_file(td, f, i) { @@ -571,12 +585,14 @@ int add_file(struct thread_data *td, const char *fname) dprint(FD_FILE, "add file %s\n", fname); - td->files = realloc(td->files, (cur_files + 1) * sizeof(*f)); - - f = &td->files[cur_files]; + f = malloc(sizeof(*f)); memset(f, 0, sizeof(*f)); f->fd = -1; + td->files = realloc(td->files, (cur_files + 1) * sizeof(f)); + + td->files[cur_files] = f; + /* * init function, io engine may not be loaded yet */ @@ -605,25 +621,28 @@ void get_file(struct fio_file *f) f->references++; } -void put_file(struct thread_data *td, struct fio_file *f) +int put_file(struct thread_data *td, struct fio_file *f) { + int ret = 0; + dprint(FD_FILE, "put file %s, ref=%d\n", f->file_name, f->references); if (!(f->flags & FIO_FILE_OPEN)) - return; + return 0; assert(f->references); if (--f->references) - return; + return 0; if (should_fsync(td) && td->o.fsync_on_close) fsync(f->fd); if (td->io_ops->close_file) - td->io_ops->close_file(td, f); + ret = td->io_ops->close_file(td, f); td->nr_open_files--; f->flags &= ~FIO_FILE_OPEN; + return ret; } static int recurse_dir(struct thread_data *td, const char *dirname)