Turn file ->open and ->unlink into flags
authorJens Axboe <jens.axboe@oracle.com>
Tue, 13 Mar 2007 09:16:34 +0000 (10:16 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Tue, 13 Mar 2007 09:16:34 +0000 (10:16 +0100)
We'll need more flags in the next commits, so do this as a
preparatory patch.

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

index 948cecd..f6e9974 100644 (file)
@@ -148,9 +148,11 @@ static int create_files(struct thread_data *td)
                /*
                 * Only unlink files that we created.
                 */
-               f->unlink = 0;
+               f->flags &= ~FIO_FILE_UNLINK;
                if (file_ok(td, f)) {
-                       f->unlink = td->unlink;
+                       if (td->unlink)
+                               f->flags |= FIO_FILE_UNLINK;
+
                        err = create_file(td, f);
                        if (err)
                                break;
@@ -394,7 +396,7 @@ void close_files(struct thread_data *td)
        unsigned int i;
 
        for_each_file(td, f, i) {
-               if (!td->filename && f->unlink &&
+               if (!td->filename && (f->flags & FIO_FILE_UNLINK) &&
                    f->filetype == FIO_TYPE_FILE) {
                        unlink(f->file_name);
                        f->file_name = NULL;
diff --git a/fio.h b/fio.h
index 3b902a8..e451f95 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -218,6 +218,11 @@ enum fio_ioengine_flags {
        FIO_NODISKUTIL  = 1 << 4,       /* diskutil can't handle filename */
 };
 
+enum fio_file_flags {
+       FIO_FILE_OPEN           = 1 << 0,
+       FIO_FILE_UNLINK         = 1 << 1,
+};
+
 /*
  * Each thread_data structure has a number of files associated with it,
  * this structure holds state information for a single file.
@@ -247,8 +252,7 @@ struct fio_file {
        unsigned int num_maps;
        unsigned int last_free_lookup;
 
-       unsigned int unlink;
-       unsigned int open;
+       enum fio_file_flags flags;
 };
 
 /*
diff --git a/io_u.c b/io_u.c
index 69f2f19..c16128e 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -340,7 +340,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->open)
+               if (f->flags & FIO_FILE_OPEN)
                        return f;
        } while (1);
 }
@@ -360,7 +360,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->open)
+               if (f->flags & FIO_FILE_OPEN)
                        break;
 
                f = NULL;
@@ -377,7 +377,7 @@ static struct fio_file *get_next_file(struct thread_data *td)
                return NULL;
 
        f = td->file_service_file;
-       if (f && f->open && td->file_service_left--)
+       if (f && (f->flags & FIO_FILE_OPEN) && td->file_service_left--)
                return f;
 
        if (td->file_service_type == FIO_FSERVICE_RR)
index 88e91cc..02455b8 100644 (file)
@@ -259,7 +259,7 @@ int td_io_open_file(struct thread_data *td, struct fio_file *f)
        f->last_free_lookup = 0;
        f->last_completed_pos = 0;
        f->last_pos = 0;
-       f->open = 1;
+       f->flags |= FIO_FILE_OPEN;
 
        if (f->file_map)
                memset(f->file_map, 0, f->num_maps * sizeof(long));
@@ -270,10 +270,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 (f->open) {
+       if (f->flags & FIO_FILE_OPEN) {
                if (td->io_ops->close_file)
                        td->io_ops->close_file(td, f);
                td->nr_open_files--;
-               f->open = 0;
+               f->flags &= ~FIO_FILE_OPEN;
        }
 }