Allow termination during io_u building
authorJens Axboe <jens.axboe@oracle.com>
Thu, 26 Apr 2007 11:47:07 +0000 (13:47 +0200)
committerJens Axboe <jens.axboe@oracle.com>
Thu, 26 Apr 2007 11:47:07 +0000 (13:47 +0200)
If we are setting up gigabytes of io buffers, it can take many seconds
for that operation to complete. If the user wishes to abort, fio wont
honor that request. Fix that.

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

diff --git a/fio.c b/fio.c
index d8c143332823bf2c488ef0799951c8ce70c71fe3..75b448d5e56ad684dd561a54b8b0fc033cb1d4c5 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -645,6 +645,8 @@ static int init_io_u(struct thread_data *td)
 
        p = ALIGN(td->orig_buffer);
        for (i = 0; i < max_units; i++) {
+               if (td->terminate)
+                       return 1;
                io_u = malloc(sizeof(*io_u));
                memset(io_u, 0, sizeof(*io_u));
                INIT_LIST_HEAD(&io_u->list);
@@ -770,41 +772,41 @@ static void *thread_main(void *data)
        INIT_LIST_HEAD(&td->io_hist_list);
        td->io_hist_tree = RB_ROOT;
 
+       td_set_runstate(td, TD_INITIALIZED);
+       fio_sem_up(startup_sem);
+       fio_sem_down(td->mutex);
+
+       /*
+        * the ->mutex semaphore is now no longer used, close it to avoid
+        * eating a file descriptor
+        */
+       fio_sem_remove(td->mutex);
+
        if (init_io_u(td))
-               goto err_sem;
+               goto err;
 
        if (fio_setaffinity(td) == -1) {
                td_verror(td, errno, "cpu_set_affinity");
-               goto err_sem;
+               goto err;
        }
 
        if (init_iolog(td))
-               goto err_sem;
+               goto err;
 
        if (td->ioprio) {
                if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
                        td_verror(td, errno, "ioprio_set");
-                       goto err_sem;
+                       goto err;
                }
        }
 
        if (nice(td->o.nice) == -1) {
                td_verror(td, errno, "nice");
-               goto err_sem;
+               goto err;
        }
 
        if (td->o.ioscheduler && switch_ioscheduler(td))
-               goto err_sem;
-
-       td_set_runstate(td, TD_INITIALIZED);
-       fio_sem_up(startup_sem);
-       fio_sem_down(td->mutex);
-
-       /*
-        * the ->mutex semaphore is now no longer used, close it to avoid
-        * eating a file descriptor
-        */
-       fio_sem_remove(td->mutex);
+               goto err;
 
        if (!td->o.create_serialize && setup_files(td))
                goto err;
@@ -913,9 +915,6 @@ err:
        options_mem_free(td);
        td_set_runstate(td, TD_EXITED);
        return (void *) (unsigned long) td->error;
-err_sem:
-       fio_sem_up(startup_sem);
-       goto err;
 }
 
 /*