Don't stack allocate file name
[fio.git] / io_u.c
diff --git a/io_u.c b/io_u.c
index c9a344f27aff5ebcb4a405a34e2da72d0b0b0d4a..477f3877ac3c62289fd46fad0b273a65adb6b094 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -265,10 +265,13 @@ static int fill_io_u(struct thread_data *td, struct io_u *io_u)
        return 0;
 }
 
-static void io_u_mark_depth(struct thread_data *td)
+void io_u_mark_depth(struct thread_data *td, struct io_u *io_u)
 {
        int index = 0;
 
+       if (io_u->ddir == DDIR_SYNC)
+               return;
+
        switch (td->cur_depth) {
        default:
                index++;
@@ -287,7 +290,7 @@ static void io_u_mark_depth(struct thread_data *td)
        }
 
        td->ts.io_u_map[index]++;
-       td->ts.total_io_u++;
+       td->ts.total_io_u[io_u->ddir]++;
 }
 
 static void io_u_mark_latency(struct thread_data *td, unsigned long msec)
@@ -337,7 +340,8 @@ 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) &&
+                   !(f->flags & FIO_FILE_CLOSING))
                        return f;
        } while (1);
 }
@@ -357,7 +361,8 @@ 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) &&
+                   !(f->flags & FIO_FILE_CLOSING))
                        break;
 
                f = NULL;
@@ -374,7 +379,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)
@@ -410,7 +415,6 @@ struct io_u *__get_io_u(struct thread_data *td)
                list_del(&io_u->list);
                list_add(&io_u->list, &td->io_u_busylist);
                td->cur_depth++;
-               io_u_mark_depth(td);
        }
 
        return io_u;
@@ -535,6 +539,8 @@ static void io_completed(struct thread_data *td, struct io_u *io_u,
        assert(io_u->flags & IO_U_F_FLIGHT);
        io_u->flags &= ~IO_U_F_FLIGHT;
 
+       put_file(td, io_u->file);
+
        if (io_u->ddir == DDIR_SYNC) {
                td->last_was_sync = 1;
                return;