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 641ecdaf995d4e58d13f8567c1e572d5365e66bd..ceeb6e6f3551815fecdd8af022314b550790bf3b 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 4698b34d1baa9de6f1f406607c95b2b411dc0a43..94bf30034452277a91eaa2a0c9474b1174627abd 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 9d7453bafcaef77ce32b64d76d99c5d033600555..c1648a016ee29bcb46b7994b039cc1c652852e9d 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;
+       }
 }