[PATCH] fio: collate some common code
authorJens Axboe <axboe@suse.de>
Mon, 24 Oct 2005 13:46:24 +0000 (15:46 +0200)
committerJens Axboe <axboe@suse.de>
Mon, 24 Oct 2005 13:46:24 +0000 (15:46 +0200)
fio.c

diff --git a/fio.c b/fio.c
index f3d18b1e0f3fc88115545c8a66a10acb3bf4a83e..44d5e573efe26fbf0cd6f4f2354079ff5b9309a0 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -827,8 +827,6 @@ static void *thread_main(int shm_id, int offset, char *argv[])
        td = data + offset * sizeof(struct thread_data);
        td->pid = getpid();
 
-       td->fd = -1;
-
        if (sched_setaffinity(td->pid, sizeof(td->cpumask), &td->cpumask) == -1) {
                td->error = errno;
                goto err;
@@ -854,6 +852,13 @@ static void *thread_main(int shm_id, int offset, char *argv[])
        if (setup_file(td))
                goto err;
 
+       if (td->use_aio)
+               ptr = malloc(td->bs * td->aio_depth + MASK);
+       else
+               ptr = malloc(td->bs + MASK);
+
+       td->buf = ALIGN(ptr);
+
        sem_post(&startup_sem);
        sem_wait(&td->mutex);
 
@@ -864,15 +869,10 @@ static void *thread_main(int shm_id, int offset, char *argv[])
 
        memcpy(&td->stat_sample_time, &td->start, sizeof(td->start));
 
-       if (!td->use_aio) {
-               ptr = malloc(td->bs + MASK);
-               td->buf = ALIGN(ptr);
+       if (!td->use_aio)
                do_sync_io(td);
-       } else {
-               ptr = malloc(td->bs * td->aio_depth + MASK);
-               td->buf = ALIGN(ptr);
+       else
                do_async_io(td);
-       }
 
        td->runtime = mtime_since_now(&td->start);
        ret = 0;
@@ -955,6 +955,7 @@ static struct thread_data *get_new_job(int global)
        td = &threads[thread_number++];
        memset(td, 0, sizeof(*td));
 
+       td->fd = -1;
        td->thread_number = thread_number;
        td->ddir = def_thread.ddir;
        td->bs = def_thread.bs;