Get rid of reopen_files()
authorJens Axboe <jens.axboe@oracle.com>
Thu, 8 Mar 2007 13:29:03 +0000 (14:29 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 8 Mar 2007 13:29:03 +0000 (14:29 +0100)
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 <jens.axboe@oracle.com>
filesetup.c
fio.c
fio.h
io_u.c
ioengines.c

index 48b5dcd1cdfbbf68c0d9a83f483569c916dc01d0..af14c6760566e53a786ce46a1ba78996edd9505e 100644 (file)
@@ -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 43cc6af14e8ab632f731ae4106fce2b4e27ce5e7..72cd02b42d5ca36402bc1dda6b32c9350225b58a 100644 (file)
--- 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 ceeb6e6f3551815fecdd8af022314b550790bf3b..7f314defb83e303f64c6fd710ce8670f9901840c 100644 (file)
--- 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 94bf30034452277a91eaa2a0c9474b1174627abd..e283e7276a84ca75b6a11de4d3c40d9dcd93e716 100644 (file)
--- 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) {
index c1648a016ee29bcb46b7994b039cc1c652852e9d..1a89ea7691ce7c7f82d71302e966c4377b27f0e9 100644 (file)
@@ -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)