[PATCH] Add exec_prerun/exec_postrun options
authorJens Axboe <axboe@suse.de>
Tue, 6 Jun 2006 07:36:28 +0000 (09:36 +0200)
committerJens Axboe <axboe@suse.de>
Tue, 6 Jun 2006 07:36:28 +0000 (09:36 +0200)
Allows one to specify a command line program to run before and
after job io has finished.

README
fio-ini.c
fio.c
fio.h

diff --git a/README b/README
index d54f48b..aec8207 100644 (file)
--- a/README
+++ b/README
@@ -111,6 +111,8 @@ The <jobs> format is as follows:
                        simulate a machine with less memory available. x can
                        include k/m/g suffix.
        nice=x          Run job at given nice value.
+       exec_prerun=x   Run 'x' before job io is begun.
+       exec_postrun=x  Run 'x' after job io has finished.
 
 Examples using a job file
 -------------------------
index 315622d..0c87408 100644 (file)
--- a/fio-ini.c
+++ b/fio-ini.c
@@ -652,6 +652,18 @@ static int str_iolog_cb(struct thread_data *td, char *file)
        return 0;
 }
 
+static int str_prerun_cb(struct thread_data *td, char *file)
+{
+       td->exec_prerun = strdup(file);
+       return 0;
+}
+
+static int str_postrun_cb(struct thread_data *td, char *file)
+{
+       td->exec_postrun = strdup(file);
+       return 0;
+}
+
 int parse_jobs_ini(char *file)
 {
        unsigned int prioclass, prio, cpu, global, il;
@@ -907,6 +919,14 @@ int parse_jobs_ini(char *file)
                                fgetpos(f, &off);
                                continue;
                        }
+                       if (!check_str(p, "exec_prerun", str_prerun_cb, td)) {
+                               fgetpos(f, &off);
+                               continue;
+                       }
+                       if (!check_str(p, "exec_postrun", str_postrun_cb, td)) {
+                               fgetpos(f, &off);
+                               continue;
+                       }
 
                        printf("Client%d: bad option %s\n",td->thread_number,p);
                        return 1;
diff --git a/fio.c b/fio.c
index 82a18fb..79c11d5 100644 (file)
--- a/fio.c
+++ b/fio.c
@@ -1878,6 +1878,9 @@ static void *thread_main(void *data)
 
        gettimeofday(&td->epoch, NULL);
 
+       if (td->exec_prerun)
+               system(td->exec_prerun);
+
        while (td->loops--) {
                getrusage(RUSAGE_SELF, &td->ru_start);
                gettimeofday(&td->start, NULL);
@@ -1922,6 +1925,8 @@ static void *thread_main(void *data)
                finish_log(td, td->clat_log, "clat");
        if (td->write_iolog)
                write_iolog_close(td);
+       if (td->exec_postrun)
+               system(td->exec_postrun);
 
        if (exitall_on_terminate)
                terminate_threads(td->groupid);
@@ -1937,6 +1942,10 @@ err:
                free(td->directory);
        if (td->iolog_file)
                free(td->iolog_file);
+       if (td->exec_prerun)
+               free(td->exec_prerun);
+       if (td->exec_postrun)
+               free(td->exec_postrun);
        cleanup_io(td);
        cleanup_io_u(td);
        td_set_runstate(td, TD_EXITED);
diff --git a/fio.h b/fio.h
index 8ad311e..d765ac6 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -233,6 +233,12 @@ struct thread_data {
        struct timeval rwmix_switch;
        int rwmix_ddir;
 
+       /*
+        * Pre-run and post-run shell
+        */
+       char *exec_prerun;
+       char *exec_postrun;
+
        struct list_head io_hist_list;
        struct list_head io_log_list;
 };