Merge branch 'fix-randtrimwrite' of https://github.com/minwooim/fio
[fio.git] / client.h
1 #ifndef CLIENT_H
2 #define CLIENT_H
3
4 #include <sys/un.h>
5 #include <netinet/in.h>
6 #include <arpa/inet.h>
7
8 #include "lib/types.h"
9 #include "stat.h"
10
11 struct fio_net_cmd;
12
13 enum {
14         Client_created          = 0,
15         Client_connected        = 1,
16         Client_started          = 2,
17         Client_running          = 3,
18         Client_stopped          = 4,
19         Client_exited           = 5,
20 };
21
22 struct client_file {
23         char *file;
24         bool remote;
25 };
26
27 struct fio_client {
28         struct flist_head list;
29         struct flist_head hash_list;
30         struct flist_head arg_list;
31         union {
32                 struct sockaddr_in addr;
33                 struct sockaddr_in6 addr6;
34                 struct sockaddr_un addr_un;
35         };
36         char *hostname;
37         int port;
38         int fd;
39         unsigned int refs;
40         unsigned int last_cmd;
41
42         char *name;
43
44         struct flist_head *opt_lists;
45         struct json_object *global_opts;
46
47         int state;
48
49         bool skip_newline;
50         bool is_sock;
51         bool disk_stats_shown;
52         unsigned int jobs;
53         unsigned int nr_stat;
54         int error;
55         int signal;
56         int ipv6;
57         bool sent_job;
58         bool did_stat;
59         uint32_t type;
60
61         uint32_t thread_number;
62         uint32_t groupid;
63
64         struct flist_head eta_list;
65         struct client_eta *eta_in_flight;
66         unsigned int eta_timeouts;
67
68         struct flist_head cmd_list;
69
70         uint16_t argc;
71         char **argv;
72
73         struct client_ops const *ops;
74         void *client_data;
75
76         struct client_file *files;
77         unsigned int nr_files;
78
79         struct buf_output buf;
80 };
81
82 typedef void (client_cmd_op)(struct fio_client *, struct fio_net_cmd *);
83 typedef void (client_op)(struct fio_client *);
84 typedef void (client_eta_op)(struct jobs_eta *je);
85 typedef void (client_timed_out_op)(struct fio_client *);
86 typedef void (client_jobs_eta_op)(struct fio_client *client, struct jobs_eta *je);
87
88 extern struct client_ops const fio_client_ops;
89
90 struct client_ops {
91         client_cmd_op           *text;
92         client_cmd_op           *disk_util;
93         client_cmd_op           *thread_status;
94         client_cmd_op           *group_stats;
95         client_jobs_eta_op      *jobs_eta;
96         client_eta_op           *eta;
97         client_cmd_op           *probe;
98         client_cmd_op           *quit;
99         client_cmd_op           *add_job;
100         client_cmd_op           *update_job;
101         client_timed_out_op     *timed_out;
102         client_op               *stop;
103         client_cmd_op           *start;
104         client_cmd_op           *job_start;
105         client_timed_out_op     *removed;
106
107         unsigned int eta_msec;
108         int stay_connected;
109         uint32_t client_type;
110 };
111
112 struct client_eta {
113         unsigned int pending;
114         struct jobs_eta eta;
115 };
116
117 extern int fio_handle_client(struct fio_client *);
118 extern void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je);
119
120 enum {
121         Fio_client_ipv4 = 1,
122         Fio_client_ipv6,
123         Fio_client_socket,
124 };
125
126 extern int fio_client_connect(struct fio_client *);
127 extern int fio_clients_connect(void);
128 extern int fio_start_client(struct fio_client *);
129 extern int fio_start_all_clients(void);
130 extern int fio_clients_send_ini(const char *);
131 extern int fio_client_send_ini(struct fio_client *, const char *, bool);
132 extern int fio_handle_clients(struct client_ops const*);
133 extern int fio_client_add(struct client_ops const*, const char *, void **);
134 extern struct fio_client *fio_client_add_explicit(struct client_ops *, const char *, int, int);
135 extern void fio_client_add_cmd_option(void *, const char *);
136 extern int fio_client_add_ini_file(void *, const char *, bool);
137 extern int fio_client_terminate(struct fio_client *);
138 extern struct fio_client *fio_get_client(struct fio_client *);
139 extern void fio_put_client(struct fio_client *);
140 extern int fio_client_update_options(struct fio_client *, struct thread_options *, uint64_t *);
141 extern int fio_client_wait_for_reply(struct fio_client *, uint64_t);
142 extern int fio_clients_send_trigger(const char *);
143
144 #define FIO_CLIENT_DEF_ETA_MSEC         900
145
146 enum {
147         FIO_CLIENT_TYPE_CLI             = 1,
148         FIO_CLIENT_TYPE_GUI             = 2,
149 };
150
151 extern int sum_stat_clients;
152 extern struct thread_stat client_ts;
153 extern struct group_run_stats client_gs;
154
155 #endif
156