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 948cecda7fb56e70de64c0c00ef9723e7564be74..f6e997438c885e7d70aa07b36c212c8c39aa917e 100644 (file)
@@ -148,9 +148,11 @@ static int create_files(struct thread_data *td)
                /*
                 * Only unlink files that we created.
                 */
                /*
                 * Only unlink files that we created.
                 */
-               f->unlink = 0;
+               f->flags &= ~FIO_FILE_UNLINK;
                if (file_ok(td, f)) {
                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;
                        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) {
        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;
                    f->filetype == FIO_TYPE_FILE) {
                        unlink(f->file_name);
                        f->file_name = NULL;
diff --git a/fio.h b/fio.h
index 3b902a8da940ce20346a6e1d3a13c072735767b7..e451f95599cdea980d9c102506b393aae2341920 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 */
 };
 
        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.
 /*
  * 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 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 69f2f19d426053d8fc487affc991534a55c3f4f9..c16128e99ce0a539a029ef0cd9cb007fe5e346fb 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];
 
                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);
 }
                        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 (td->next_file >= td->open_files)
                        td->next_file = 0;
 
-               if (f->open)
+               if (f->flags & FIO_FILE_OPEN)
                        break;
 
                f = NULL;
                        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;
                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)
                return f;
 
        if (td->file_service_type == FIO_FSERVICE_RR)
index 88e91ccbbf0b2f29b422f9be5552930bf010dcfd..02455b8540af5644e98918abd4b2a8eb03e6b737 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->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));
 
        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)
 {
 
 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--;
                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;
        }
 }
        }
 }