[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 d54f48b02d3da29b3577dbf0c03f82c3379427f3..aec8207ce27c980e70ebbdb49abffc4af7e0a9f1 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 315622d5b1271f66db29fcb50f051a3fbb68584f..0c874085f466002c5893c994914ead475d412f4a 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 82a18fb89f4d05c8b8f2821e0cbaf82b677dc75b..79c11d5cdcee503d879c510e8e57036df421d895 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 8ad311efa3a9971526ac55952f2999d490c6de45..d765ac6e2ebda32595940375ee8767a39322d65f 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;
 };