Add backend related data
authorJens Axboe <axboe@fb.com>
Thu, 10 Dec 2015 21:26:44 +0000 (14:26 -0700)
committerJens Axboe <axboe@fb.com>
Thu, 10 Dec 2015 21:26:44 +0000 (14:26 -0700)
Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c
fio.c
fio.h
server.c

index a2a6cec2ce267769a0a08891fe58dd60f807e2af..c8554bc1a102ec721b9f1d33b7e508680c0c094f 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -2220,8 +2220,12 @@ static void free_disk_util(void)
 
 static void *helper_thread_main(void *data)
 {
 
 static void *helper_thread_main(void *data)
 {
+       struct backend_data *d = data;
        int ret = 0;
 
        int ret = 0;
 
+       if (d)
+               pthread_setspecific(d->key, d->ptr);
+
        fio_mutex_up(startup_mutex);
 
        while (!ret) {
        fio_mutex_up(startup_mutex);
 
        while (!ret) {
@@ -2255,7 +2259,7 @@ static void *helper_thread_main(void *data)
        return NULL;
 }
 
        return NULL;
 }
 
-static int create_helper_thread(void)
+static int create_helper_thread(struct backend_data *data)
 {
        int ret;
 
 {
        int ret;
 
@@ -2264,7 +2268,7 @@ static int create_helper_thread(void)
        pthread_cond_init(&helper_cond, NULL);
        pthread_mutex_init(&helper_lock, NULL);
 
        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;
        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;
 }
 
        return 0;
 }
 
-int fio_backend(void)
+int fio_backend(struct backend_data *data)
 {
        struct thread_data *td;
        int i;
 {
        struct thread_data *td;
        int i;
@@ -2306,7 +2310,7 @@ int fio_backend(void)
 
        set_genesis_time();
        stat_init();
 
        set_genesis_time();
        stat_init();
-       create_helper_thread();
+       create_helper_thread(data);
 
        cgroup_list = smalloc(sizeof(*cgroup_list));
        INIT_FLIST_HEAD(cgroup_list);
 
        cgroup_list = smalloc(sizeof(*cgroup_list));
        INIT_FLIST_HEAD(cgroup_list);
diff --git a/fio.c b/fio.c
index bafbd48e7ae35c00782af205308ce89a8c665d4e..bd3e260b40cfd575030c3276e247f8f4f28ec0f0 100644 (file)
--- 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
                        goto done;
                ret = fio_handle_clients(&fio_client_ops);
        } else
-               ret = fio_backend();
+               ret = fio_backend(NULL);
 
 done:
        deinitialize_fio();
 
 done:
        deinitialize_fio();
diff --git a/fio.h b/fio.h
index 6f85266c2f695432cb405a6bc260f974a2ced2ea..63778b65cbae974d83fbfccc4d7c5ffecf683e28 100644 (file)
--- a/fio.h
+++ b/fio.h
@@ -107,6 +107,15 @@ enum {
        RATE_PROCESS_POISSON = 1,
 };
 
        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.
  */
 /*
  * 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 __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);
 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);
index 5871228d04b8878dd27c1514ea542055cfad9d4e..31f179493aabf949edb8870dff154f99afba19a1 100644 (file)
--- 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;
        }
 
                return 0;
        }
 
-       ret = fio_backend();
+       ret = fio_backend(NULL);
        free_threads_shm();
        _exit(ret);
 }
        free_threads_shm();
        _exit(ret);
 }