[PATCH] Always open the files from the job itself
authorJens Axboe <jens.axboe@oracle.com>
Thu, 23 Nov 2006 11:39:16 +0000 (12:39 +0100)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 23 Nov 2006 11:39:16 +0000 (12:39 +0100)
This way we don't fork or spawn threads and make them inherit the open
file.

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

index 705eb4a90cb3b12a2b98802718a1d5c3584c7ac5..4fa04ecd6310adcc88c69c53be3f88759557915b 100644 (file)
@@ -351,10 +351,24 @@ static int setup_file(struct thread_data *td, struct fio_file *f)
        return 0;
 }
 
+int open_files(struct thread_data *td)
+{
+       struct fio_file *f;
+       int i, err = 0;
+
+       for_each_file(td, f, i) {
+               err = setup_file(td, f);
+               if (err)
+                       break;
+       }
+
+       return err;
+}
+
 int setup_files(struct thread_data *td)
 {
        struct fio_file *f;
-       int i, err;
+       int err, i;
 
        /*
         * if ioengine defines a setup() method, it's responsible for
@@ -366,13 +380,7 @@ int setup_files(struct thread_data *td)
        if (create_files(td))
                return 1;
 
-       err = 0;
-       for_each_file(td, f, i) {
-               err = setup_file(td, f);
-               if (err)
-                       break;
-       }
-
+       err = open_files(td);
        if (err)
                return err;
 
@@ -396,9 +404,18 @@ int setup_files(struct thread_data *td)
        td->total_io_size = td->io_size * td->loops;
 
        if (td->io_ops->flags & FIO_MMAPIO)
-               return setup_files_mmap(td);
+               err = setup_files_mmap(td);
        else
-               return setup_files_plain(td);
+               err = setup_files_plain(td);
+
+       for_each_file(td, f, i) {
+               if (f->fd != -1) {
+                       close(f->fd);
+                       f->fd = -1;
+               }
+       }
+
+       return err;
 }
 
 void close_files(struct thread_data *td)
@@ -407,16 +424,15 @@ void close_files(struct thread_data *td)
        int i;
 
        for_each_file(td, f, i) {
-               if (f->fd != -1) {
-                       file_invalidate_cache(td, f);
-                       close(f->fd);
-                       f->fd = -1;
-               }
                if (td->unlink && td->filetype == FIO_TYPE_FILE) {
                        unlink(f->file_name);
                        free(f->file_name);
                        f->file_name = NULL;
                }
+               if (f->fd != -1) {
+                       close(f->fd);
+                       f->fd = -1;
+               }
                if (f->mmap) {
                        munmap(f->mmap, f->file_size);
                        f->mmap = NULL;
diff --git a/fio.c b/fio.c
index d005625a5dc7af2b03e257dabcdc4d4f395c7234..ed14c41f0c645bc5c9378b84d183e89c81955d34 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -656,6 +656,8 @@ static void *thread_main(void *data)
 
        if (!td->create_serialize && setup_files(td))
                goto err;
+       if (open_files(td))
+               goto err;
 
        gettimeofday(&td->epoch, NULL);
 
diff --git a/fio.h b/fio.h
index 9f5201b657ec219f078fde8c5a1a39354e84d88c..1115c62ea3b7555fdaf6e43368b15c6e3086099e 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -472,6 +472,7 @@ extern int init_random_state(struct thread_data *);
  */
 extern void close_files(struct thread_data *);
 extern int setup_files(struct thread_data *);
+extern int open_files(struct thread_data *);
 extern int file_invalidate_cache(struct thread_data *, struct fio_file *);
 
 /*