Add ->open to struct fio_file
authorJens Axboe <jens.axboe@oracle.com>
Thu, 8 Mar 2007 13:09:18 +0000 (14:09 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 8 Mar 2007 13:09:18 +0000 (14:09 +0100)
Don't use ->fd == -1 to check for the file being open or not,
an io engine could be non-fd based.

Signed-off-by: Jens Axboe <jens.axboe@oracle.com>
fio.h
io_u.c
ioengines.c

diff --git a/fio.h b/fio.h
index 641ecda..ceeb6e6 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -244,6 +244,7 @@ struct fio_file {
        unsigned int last_free_lookup;
 
        unsigned int unlink;
+       unsigned int open;
 };
 
 /*
diff --git a/io_u.c b/io_u.c
index 4698b34..94bf300 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -337,7 +337,7 @@ static struct fio_file *get_next_file_rand(struct thread_data *td)
 
                fileno = (unsigned int) ((double) (td->open_files * r) / (RAND_MAX + 1.0));
                f = &td->files[fileno];
-               if (f->fd != -1)
+               if (f->open)
                        return f;
        } while (1);
 }
@@ -357,7 +357,7 @@ static struct fio_file *get_next_file_rr(struct thread_data *td)
                if (td->next_file >= td->open_files)
                        td->next_file = 0;
 
-               if (f->fd != -1)
+               if (f->open)
                        break;
 
                f = NULL;
index 9d7453b..c1648a0 100644 (file)
@@ -261,6 +261,7 @@ 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;
        }
@@ -270,7 +271,10 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f)
 
 void td_io_close_file(struct thread_data *td, struct fio_file *f)
 {
-       if (td->io_ops->close_file)
-               td->io_ops->close_file(td, f);
-       td->nr_open_files--;
+       if (f->open) {
+               if (td->io_ops->close_file)
+                       td->io_ops->close_file(td, f);
+               td->nr_open_files--;
+               f->open = 0;
+       }
 }