From 2a2804c95571c5bc9f3fc9e6e5b422fa90aa5670 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 10 Dec 2015 14:26:44 -0700 Subject: [PATCH] Add backend related data Signed-off-by: Jens Axboe --- backend.c | 12 ++++++++---- fio.c | 2 +- fio.h | 11 ++++++++++- server.c | 2 +- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/backend.c b/backend.c index a2a6cec2..c8554bc1 100644 --- a/backend.c +++ b/backend.c @@ -2220,8 +2220,12 @@ static void free_disk_util(void) static void *helper_thread_main(void *data) { + struct backend_data *d = data; int ret = 0; + if (d) + pthread_setspecific(d->key, d->ptr); + fio_mutex_up(startup_mutex); while (!ret) { @@ -2255,7 +2259,7 @@ static void *helper_thread_main(void *data) return NULL; } -static int create_helper_thread(void) +static int create_helper_thread(struct backend_data *data) { int ret; @@ -2264,7 +2268,7 @@ static int create_helper_thread(void) pthread_cond_init(&helper_cond, NULL); pthread_mutex_init(&helper_lock, NULL); - ret = pthread_create(&helper_thread, NULL, helper_thread_main, NULL); + ret = pthread_create(&helper_thread, NULL, helper_thread_main, data); if (ret) { log_err("Can't create helper thread: %s\n", strerror(ret)); return 1; @@ -2276,7 +2280,7 @@ static int create_helper_thread(void) return 0; } -int fio_backend(void) +int fio_backend(struct backend_data *data) { struct thread_data *td; int i; @@ -2306,7 +2310,7 @@ int fio_backend(void) set_genesis_time(); stat_init(); - create_helper_thread(); + create_helper_thread(data); cgroup_list = smalloc(sizeof(*cgroup_list)); INIT_FLIST_HEAD(cgroup_list); diff --git a/fio.c b/fio.c index bafbd48e..bd3e260b 100644 --- a/fio.c +++ b/fio.c @@ -57,7 +57,7 @@ int main(int argc, char *argv[], char *envp[]) goto done; ret = fio_handle_clients(&fio_client_ops); } else - ret = fio_backend(); + ret = fio_backend(NULL); done: deinitialize_fio(); diff --git a/fio.h b/fio.h index 6f85266c..63778b65 100644 --- a/fio.h +++ b/fio.h @@ -107,6 +107,15 @@ enum { RATE_PROCESS_POISSON = 1, }; +/* + * Per-thread/process specific data. Only used for the network client + * for now. + */ +struct backend_data { + pthread_key_t key; + void *ptr; +}; + /* * This describes a single thread/process executing a fio job. */ @@ -468,7 +477,7 @@ extern int __must_check fio_init_options(void); extern int __must_check parse_options(int, char **); extern int parse_jobs_ini(char *, int, int, int); extern int parse_cmd_line(int, char **, int); -extern int fio_backend(void); +extern int fio_backend(struct backend_data *); extern void reset_fio_state(void); extern void clear_io_state(struct thread_data *, int); extern int fio_options_parse(struct thread_data *, char **, int, int); diff --git a/server.c b/server.c index 5871228d..31f17949 100644 --- a/server.c +++ b/server.c @@ -601,7 +601,7 @@ static int handle_run_cmd(struct flist_head *job_list, struct fio_net_cmd *cmd) return 0; } - ret = fio_backend(); + ret = fio_backend(NULL); free_threads_shm(); _exit(ret); } -- 2.25.1