From 4e0ba8af8f0bfe0f194122661c8a659c2ac748e6 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 6 Jun 2006 09:36:28 +0200 Subject: [PATCH] [PATCH] Add exec_prerun/exec_postrun options Allows one to specify a command line program to run before and after job io has finished. --- README | 2 ++ fio-ini.c | 20 ++++++++++++++++++++ fio.c | 9 +++++++++ fio.h | 6 ++++++ 4 files changed, 37 insertions(+) diff --git a/README b/README index d54f48b0..aec8207c 100644 --- a/README +++ b/README @@ -111,6 +111,8 @@ The 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 ------------------------- diff --git a/fio-ini.c b/fio-ini.c index 315622d5..0c874085 100644 --- 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 82a18fb8..79c11d5c 100644 --- 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 8ad311ef..d765ac6e 100644 --- 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; }; -- 2.25.1