From: Jens Axboe Date: Thu, 8 Mar 2007 13:29:03 +0000 (+0100) Subject: Get rid of reopen_files() X-Git-Tag: fio-1.14~62 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=a978ba684deb758465a0ccb18a008797636e8054;hp=640e94218b780e3d7b15758c760e59f3511f0933 Get rid of reopen_files() Move the full file state clear into td_io_open_file(), so a reopen is a plain close/open of that file. Signed-off-by: Jens Axboe --- diff --git a/filesetup.c b/filesetup.c index 48b5dcd1..af14c676 100644 --- a/filesetup.c +++ b/filesetup.c @@ -318,18 +318,6 @@ err: return 1; } -int reopen_file(struct thread_data *td, struct fio_file *f) -{ - f->last_free_lookup = 0; - f->last_completed_pos = 0; - f->last_pos = 0; - - if (f->file_map) - memset(f->file_map, 0, f->num_maps * sizeof(long)); - - return td_io_open_file(td, f); -} - int open_files(struct thread_data *td) { struct fio_file *f; diff --git a/fio.c b/fio.c index 43cc6af1..72cd02b4 100644 --- a/fio.c +++ b/fio.c @@ -656,10 +656,10 @@ static int switch_ioscheduler(struct thread_data *td) return 0; } -static void clear_io_state(struct thread_data *td) +static int clear_io_state(struct thread_data *td) { struct fio_file *f; - int i; + int i, ret; td->ts.stat_io_bytes[0] = td->ts.stat_io_bytes[1] = 0; td->this_io_bytes[0] = td->this_io_bytes[1] = 0; @@ -667,16 +667,17 @@ static void clear_io_state(struct thread_data *td) td->last_was_sync = 0; - for_each_file(td, f, i) { - f->last_completed_pos = 0; - - f->last_pos = 0; - if (td->io_ops->flags & FIO_SYNCIO) - lseek(f->fd, SEEK_SET, 0); + for_each_file(td, f, i) + td_io_close_file(td, f); - if (f->file_map) - memset(f->file_map, 0, f->num_maps * sizeof(long)); + ret = 0; + for_each_file(td, f, i) { + ret = td_io_open_file(td, f); + if (ret) + break; } + + return ret; } /* @@ -687,6 +688,7 @@ static void *thread_main(void *data) { unsigned long long runtime[2]; struct thread_data *td = data; + int clear_state; if (!td->use_thread) setsid(); @@ -751,6 +753,7 @@ static void *thread_main(void *data) getrusage(RUSAGE_SELF, &td->ts.ru_start); runtime[0] = runtime[1] = 0; + clear_state = 0; while (td->loops--) { fio_gettime(&td->start, NULL); memcpy(&td->ts.stat_sample_time, &td->start, sizeof(td->start)); @@ -758,7 +761,9 @@ static void *thread_main(void *data) if (td->ratemin) memcpy(&td->lastrate, &td->ts.stat_sample_time, sizeof(td->lastrate)); - clear_io_state(td); + if (clear_state && clear_io_state(td)) + break; + prune_io_piece_log(td); if (td->io_ops->flags & FIO_CPUIO) @@ -766,6 +771,8 @@ static void *thread_main(void *data) else do_io(td); + clear_state = 1; + if (td_read(td) && td->io_bytes[DDIR_READ]) runtime[DDIR_READ] += utime_since_now(&td->start); if (td_write(td) && td->io_bytes[DDIR_WRITE]) @@ -777,7 +784,9 @@ static void *thread_main(void *data) if (td->verify == VERIFY_NONE) continue; - clear_io_state(td); + if (clear_io_state(td)) + break; + fio_gettime(&td->start, NULL); do_verify(td); diff --git a/fio.h b/fio.h index ceeb6e6f..7f314def 100644 --- a/fio.h +++ b/fio.h @@ -634,7 +634,6 @@ extern int __must_check init_random_state(struct thread_data *); extern void close_files(struct thread_data *); extern int __must_check setup_files(struct thread_data *); extern int __must_check open_files(struct thread_data *); -extern int reopen_file(struct thread_data *, struct fio_file *); extern int __must_check file_invalidate_cache(struct thread_data *, struct fio_file *); extern int __must_check generic_open_file(struct thread_data *, struct fio_file *); extern void generic_close_file(struct thread_data *, struct fio_file *); diff --git a/io_u.c b/io_u.c index 94bf3003..e283e727 100644 --- a/io_u.c +++ b/io_u.c @@ -448,8 +448,14 @@ struct io_u *get_io_u(struct thread_data *td) * if we need to open a new file */ if (td->nr_open_files < td->nr_files && - td->open_files != td->nr_files) - reopen_file(td, f); + td->open_files != td->nr_files) { + int ret = td_io_open_file(td, f); + + if (ret) { + put_io_u(td, io_u); + return NULL; + } + } } while (1); if (td->zone_bytes >= td->zone_size) { diff --git a/ioengines.c b/ioengines.c index c1648a01..1a89ea76 100644 --- a/ioengines.c +++ b/ioengines.c @@ -260,13 +260,19 @@ int td_io_commit(struct thread_data *td) int td_io_open_file(struct thread_data *td, struct fio_file *f) { - if (!td->io_ops->open_file(td, f)) { - f->open = 1; - td->nr_open_files++; - return 0; - } + if (td->io_ops->open_file(td, f)) + return 1; - return 1; + f->last_free_lookup = 0; + f->last_completed_pos = 0; + f->last_pos = 0; + f->open = 1; + + if (f->file_map) + memset(f->file_map, 0, f->num_maps * sizeof(long)); + + td->nr_open_files++; + return 0; } void td_io_close_file(struct thread_data *td, struct fio_file *f)