Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
| 3 | #include <unistd.h> |
| 4 | #include <limits.h> |
| 5 | #include <errno.h> |
| 6 | #include <fcntl.h> |
| 7 | #include <sys/poll.h> |
| 8 | #include <sys/types.h> |
| 9 | #include <sys/stat.h> |
| 10 | #include <sys/wait.h> |
Jens Axboe | d05c4a0 | 2011-10-05 00:16:11 +0200 | [diff] [blame] | 11 | #include <sys/socket.h> |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 12 | #include <sys/un.h> |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 13 | #include <netinet/in.h> |
| 14 | #include <arpa/inet.h> |
| 15 | #include <netdb.h> |
Jens Axboe | 9e22ecb | 2011-10-04 14:50:21 +0200 | [diff] [blame] | 16 | #include <signal.h> |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 17 | #ifdef CONFIG_ZLIB |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 18 | #include <zlib.h> |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 19 | #endif |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 20 | |
| 21 | #include "fio.h" |
Stephen M. Cameron | dd36672 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 22 | #include "client.h" |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 23 | #include "server.h" |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 24 | #include "flist.h" |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 25 | #include "hash.h" |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 26 | #include "verify.h" |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 27 | |
Stephen M. Cameron | dd36672 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 28 | static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd); |
Jens Axboe | 89e5fad | 2012-03-05 09:21:12 +0100 | [diff] [blame] | 29 | static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd); |
| 30 | static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd); |
Stephen M. Cameron | dd36672 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 31 | static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd); |
Jens Axboe | 084d1c6 | 2012-03-03 20:28:07 +0100 | [diff] [blame] | 32 | static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd); |
Jens Axboe | 6b79c80 | 2012-03-08 10:51:36 +0100 | [diff] [blame] | 33 | static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd); |
Jens Axboe | 85dd01e | 2012-03-12 14:33:16 +0100 | [diff] [blame] | 34 | static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd); |
Stephen M. Cameron | dd36672 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 35 | |
| 36 | struct client_ops fio_client_ops = { |
Jens Axboe | 35c0ba7 | 2012-03-14 10:56:40 +0100 | [diff] [blame] | 37 | .text = handle_text, |
Jens Axboe | 0420ba6 | 2012-02-29 11:16:52 +0100 | [diff] [blame] | 38 | .disk_util = handle_du, |
| 39 | .thread_status = handle_ts, |
| 40 | .group_stats = handle_gs, |
Jens Axboe | 6b79c80 | 2012-03-08 10:51:36 +0100 | [diff] [blame] | 41 | .stop = handle_stop, |
Jens Axboe | 85dd01e | 2012-03-12 14:33:16 +0100 | [diff] [blame] | 42 | .start = handle_start, |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 43 | .eta = display_thread_status, |
Jens Axboe | 0420ba6 | 2012-02-29 11:16:52 +0100 | [diff] [blame] | 44 | .probe = handle_probe, |
Jens Axboe | 6433ee0 | 2012-03-09 20:10:51 +0100 | [diff] [blame] | 45 | .eta_msec = FIO_CLIENT_DEF_ETA_MSEC, |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 46 | .client_type = FIO_CLIENT_TYPE_CLI, |
Stephen M. Cameron | dd36672 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 49 | static struct timeval eta_tv; |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 50 | |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 51 | static FLIST_HEAD(client_list); |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 52 | static FLIST_HEAD(eta_list); |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 53 | |
Jens Axboe | 3f3a454 | 2011-10-10 21:11:09 +0200 | [diff] [blame] | 54 | static FLIST_HEAD(arg_list); |
| 55 | |
Jens Axboe | 3650a3c | 2012-03-05 14:09:03 +0100 | [diff] [blame] | 56 | struct thread_stat client_ts; |
| 57 | struct group_run_stats client_gs; |
| 58 | int sum_stat_clients; |
| 59 | |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 60 | static int sum_stat_nr; |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 61 | static struct json_object *root = NULL; |
| 62 | static struct json_array *clients_array = NULL; |
| 63 | static struct json_array *du_array = NULL; |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 64 | |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 65 | #define FIO_CLIENT_HASH_BITS 7 |
| 66 | #define FIO_CLIENT_HASH_SZ (1 << FIO_CLIENT_HASH_BITS) |
| 67 | #define FIO_CLIENT_HASH_MASK (FIO_CLIENT_HASH_SZ - 1) |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 68 | static struct flist_head client_hash[FIO_CLIENT_HASH_SZ]; |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 69 | |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 70 | static void fio_client_add_hash(struct fio_client *client) |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 71 | { |
| 72 | int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS); |
| 73 | |
| 74 | bucket &= FIO_CLIENT_HASH_MASK; |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 75 | flist_add(&client->hash_list, &client_hash[bucket]); |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 76 | } |
| 77 | |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 78 | static void fio_client_remove_hash(struct fio_client *client) |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 79 | { |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 80 | if (!flist_empty(&client->hash_list)) |
| 81 | flist_del_init(&client->hash_list); |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | static void fio_init fio_client_hash_init(void) |
| 85 | { |
| 86 | int i; |
| 87 | |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 88 | for (i = 0; i < FIO_CLIENT_HASH_SZ; i++) |
| 89 | INIT_FLIST_HEAD(&client_hash[i]); |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 90 | } |
| 91 | |
Jens Axboe | 3d0be7c | 2014-11-11 10:24:00 -0700 | [diff] [blame] | 92 | static int read_data(int fd, void *data, size_t size) |
| 93 | { |
| 94 | ssize_t ret; |
| 95 | |
| 96 | while (size) { |
| 97 | ret = read(fd, data, size); |
| 98 | if (ret < 0) { |
| 99 | if (errno == EAGAIN || errno == EINTR) |
| 100 | continue; |
| 101 | break; |
| 102 | } else if (!ret) |
| 103 | break; |
| 104 | else { |
| 105 | data += ret; |
| 106 | size -= ret; |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | if (size) |
| 111 | return EAGAIN; |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 116 | static void fio_client_json_init(void) |
| 117 | { |
| 118 | if (output_format != FIO_OUTPUT_JSON) |
| 119 | return; |
| 120 | root = json_create_object(); |
| 121 | json_object_add_value_string(root, "fio version", fio_version_string); |
| 122 | clients_array = json_create_array(); |
| 123 | json_object_add_value_array(root, "client_stats", clients_array); |
| 124 | du_array = json_create_array(); |
| 125 | json_object_add_value_array(root, "disk_util", du_array); |
| 126 | } |
| 127 | |
| 128 | static void fio_client_json_fini(void) |
| 129 | { |
| 130 | if (output_format != FIO_OUTPUT_JSON) |
| 131 | return; |
| 132 | json_print_object(root); |
| 133 | log_info("\n"); |
| 134 | json_free_object(root); |
| 135 | root = NULL; |
| 136 | clients_array = NULL; |
| 137 | du_array = NULL; |
| 138 | } |
| 139 | |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 140 | static struct fio_client *find_client_by_fd(int fd) |
| 141 | { |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 142 | int bucket = hash_long(fd, FIO_CLIENT_HASH_BITS) & FIO_CLIENT_HASH_MASK; |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 143 | struct fio_client *client; |
| 144 | struct flist_head *entry; |
| 145 | |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 146 | flist_for_each(entry, &client_hash[bucket]) { |
| 147 | client = flist_entry(entry, struct fio_client, hash_list); |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 148 | |
Jens Axboe | e55f8f3 | 2012-03-06 15:42:31 +0100 | [diff] [blame] | 149 | if (client->fd == fd) { |
| 150 | client->refs++; |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 151 | return client; |
Jens Axboe | e55f8f3 | 2012-03-06 15:42:31 +0100 | [diff] [blame] | 152 | } |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 153 | } |
| 154 | |
| 155 | return NULL; |
| 156 | } |
| 157 | |
Jens Axboe | 3af4520 | 2012-03-13 09:59:53 +0100 | [diff] [blame] | 158 | void fio_put_client(struct fio_client *client) |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 159 | { |
Jens Axboe | 5121a9a | 2012-03-05 13:32:47 +0100 | [diff] [blame] | 160 | if (--client->refs) |
| 161 | return; |
| 162 | |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 163 | free(client->hostname); |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 164 | if (client->argv) |
| 165 | free(client->argv); |
Jens Axboe | b5296dd | 2011-10-07 16:35:56 +0200 | [diff] [blame] | 166 | if (client->name) |
| 167 | free(client->name); |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 168 | while (client->nr_files) { |
| 169 | struct client_file *cf = &client->files[--client->nr_files]; |
| 170 | |
| 171 | free(cf->file); |
| 172 | } |
| 173 | if (client->files) |
| 174 | free(client->files); |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 175 | |
Jens Axboe | 108fea7 | 2012-11-14 13:09:45 -0700 | [diff] [blame] | 176 | if (!client->did_stat) |
Jens Axboe | bfa8f5d | 2014-10-13 10:09:28 -0600 | [diff] [blame] | 177 | sum_stat_clients--; |
Jens Axboe | 108fea7 | 2012-11-14 13:09:45 -0700 | [diff] [blame] | 178 | |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 179 | free(client); |
| 180 | } |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 181 | |
Jens Axboe | 3af4520 | 2012-03-13 09:59:53 +0100 | [diff] [blame] | 182 | static void remove_client(struct fio_client *client) |
Jens Axboe | 5121a9a | 2012-03-05 13:32:47 +0100 | [diff] [blame] | 183 | { |
Jens Axboe | 3af4520 | 2012-03-13 09:59:53 +0100 | [diff] [blame] | 184 | assert(client->refs); |
| 185 | |
| 186 | dprint(FD_NET, "client: removed <%s>\n", client->hostname); |
| 187 | |
| 188 | if (!flist_empty(&client->list)) |
| 189 | flist_del_init(&client->list); |
| 190 | |
| 191 | fio_client_remove_hash(client); |
| 192 | |
| 193 | if (!flist_empty(&client->eta_list)) { |
| 194 | flist_del_init(&client->eta_list); |
| 195 | fio_client_dec_jobs_eta(client->eta_in_flight, client->ops->eta); |
| 196 | } |
| 197 | |
Jens Axboe | 1e0c184 | 2012-03-20 15:15:00 +0100 | [diff] [blame] | 198 | close(client->fd); |
| 199 | client->fd = -1; |
| 200 | |
Jens Axboe | 0cf3ece | 2012-03-21 10:15:20 +0100 | [diff] [blame] | 201 | if (client->ops->removed) |
| 202 | client->ops->removed(client); |
| 203 | |
Jens Axboe | 3af4520 | 2012-03-13 09:59:53 +0100 | [diff] [blame] | 204 | nr_clients--; |
Jens Axboe | 3af4520 | 2012-03-13 09:59:53 +0100 | [diff] [blame] | 205 | fio_put_client(client); |
Jens Axboe | 5121a9a | 2012-03-05 13:32:47 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Jens Axboe | 343cb4a | 2012-03-09 17:16:51 +0100 | [diff] [blame] | 208 | struct fio_client *fio_get_client(struct fio_client *client) |
| 209 | { |
| 210 | client->refs++; |
| 211 | return client; |
| 212 | } |
| 213 | |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 214 | static void __fio_client_add_cmd_option(struct fio_client *client, |
| 215 | const char *opt) |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 216 | { |
Jens Axboe | 39e8e01 | 2011-10-04 13:46:08 +0200 | [diff] [blame] | 217 | int index; |
| 218 | |
| 219 | index = client->argc++; |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 220 | client->argv = realloc(client->argv, sizeof(char *) * client->argc); |
Jens Axboe | 39e8e01 | 2011-10-04 13:46:08 +0200 | [diff] [blame] | 221 | client->argv[index] = strdup(opt); |
| 222 | dprint(FD_NET, "client: add cmd %d: %s\n", index, opt); |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 223 | } |
| 224 | |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 225 | void fio_client_add_cmd_option(void *cookie, const char *opt) |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 226 | { |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 227 | struct fio_client *client = cookie; |
Jens Axboe | 3f3a454 | 2011-10-10 21:11:09 +0200 | [diff] [blame] | 228 | struct flist_head *entry; |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 229 | |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 230 | if (!client || !opt) |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 231 | return; |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 232 | |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 233 | __fio_client_add_cmd_option(client, opt); |
Jens Axboe | 3f3a454 | 2011-10-10 21:11:09 +0200 | [diff] [blame] | 234 | |
| 235 | /* |
| 236 | * Duplicate arguments to shared client group |
| 237 | */ |
| 238 | flist_for_each(entry, &arg_list) { |
| 239 | client = flist_entry(entry, struct fio_client, arg_list); |
| 240 | |
| 241 | __fio_client_add_cmd_option(client, opt); |
| 242 | } |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 243 | } |
| 244 | |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 245 | struct fio_client *fio_client_add_explicit(struct client_ops *ops, |
| 246 | const char *hostname, int type, |
Jens Axboe | 3ec62ec | 2012-03-01 12:01:29 +0100 | [diff] [blame] | 247 | int port) |
| 248 | { |
| 249 | struct fio_client *client; |
| 250 | |
| 251 | client = malloc(sizeof(*client)); |
| 252 | memset(client, 0, sizeof(*client)); |
| 253 | |
| 254 | INIT_FLIST_HEAD(&client->list); |
| 255 | INIT_FLIST_HEAD(&client->hash_list); |
| 256 | INIT_FLIST_HEAD(&client->arg_list); |
| 257 | INIT_FLIST_HEAD(&client->eta_list); |
| 258 | INIT_FLIST_HEAD(&client->cmd_list); |
| 259 | |
| 260 | client->hostname = strdup(hostname); |
| 261 | |
| 262 | if (type == Fio_client_socket) |
| 263 | client->is_sock = 1; |
| 264 | else { |
| 265 | int ipv6; |
| 266 | |
| 267 | ipv6 = type == Fio_client_ipv6; |
Jens Axboe | 3aa3cee | 2014-01-24 18:56:56 -0800 | [diff] [blame] | 268 | if (fio_server_parse_host(hostname, ipv6, |
Jens Axboe | 3ec62ec | 2012-03-01 12:01:29 +0100 | [diff] [blame] | 269 | &client->addr.sin_addr, |
| 270 | &client->addr6.sin6_addr)) |
| 271 | goto err; |
| 272 | |
| 273 | client->port = port; |
| 274 | } |
| 275 | |
| 276 | client->fd = -1; |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 277 | client->ops = ops; |
Jens Axboe | 5121a9a | 2012-03-05 13:32:47 +0100 | [diff] [blame] | 278 | client->refs = 1; |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 279 | client->type = ops->client_type; |
Jens Axboe | 3ec62ec | 2012-03-01 12:01:29 +0100 | [diff] [blame] | 280 | |
| 281 | __fio_client_add_cmd_option(client, "fio"); |
| 282 | |
| 283 | flist_add(&client->list, &client_list); |
| 284 | nr_clients++; |
| 285 | dprint(FD_NET, "client: added <%s>\n", client->hostname); |
| 286 | return client; |
| 287 | err: |
| 288 | free(client); |
| 289 | return NULL; |
| 290 | } |
| 291 | |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 292 | int fio_client_add_ini_file(void *cookie, const char *ini_file, int remote) |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 293 | { |
| 294 | struct fio_client *client = cookie; |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 295 | struct client_file *cf; |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 296 | size_t new_size; |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 297 | void *new_files; |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 298 | |
Jens Axboe | 722b5cd | 2014-10-14 19:56:25 -0600 | [diff] [blame] | 299 | if (!client) |
| 300 | return 1; |
| 301 | |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 302 | dprint(FD_NET, "client <%s>: add ini %s\n", client->hostname, ini_file); |
| 303 | |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 304 | new_size = (client->nr_files + 1) * sizeof(struct client_file); |
| 305 | new_files = realloc(client->files, new_size); |
| 306 | if (!new_files) |
| 307 | return 1; |
| 308 | |
| 309 | client->files = new_files; |
| 310 | cf = &client->files[client->nr_files]; |
| 311 | cf->file = strdup(ini_file); |
| 312 | cf->remote = remote; |
| 313 | client->nr_files++; |
| 314 | return 0; |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 317 | int fio_client_add(struct client_ops *ops, const char *hostname, void **cookie) |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 318 | { |
Jens Axboe | 3f3a454 | 2011-10-10 21:11:09 +0200 | [diff] [blame] | 319 | struct fio_client *existing = *cookie; |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 320 | struct fio_client *client; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 321 | |
Jens Axboe | 3f3a454 | 2011-10-10 21:11:09 +0200 | [diff] [blame] | 322 | if (existing) { |
| 323 | /* |
| 324 | * We always add our "exec" name as the option, hence 1 |
| 325 | * means empty. |
| 326 | */ |
| 327 | if (existing->argc == 1) |
| 328 | flist_add_tail(&existing->arg_list, &arg_list); |
| 329 | else { |
| 330 | while (!flist_empty(&arg_list)) |
| 331 | flist_del_init(arg_list.next); |
| 332 | } |
| 333 | } |
| 334 | |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 335 | client = malloc(sizeof(*client)); |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 336 | memset(client, 0, sizeof(*client)); |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 337 | |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 338 | INIT_FLIST_HEAD(&client->list); |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 339 | INIT_FLIST_HEAD(&client->hash_list); |
Jens Axboe | 3f3a454 | 2011-10-10 21:11:09 +0200 | [diff] [blame] | 340 | INIT_FLIST_HEAD(&client->arg_list); |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 341 | INIT_FLIST_HEAD(&client->eta_list); |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 342 | INIT_FLIST_HEAD(&client->cmd_list); |
Jens Axboe | 3c5f57e | 2011-10-06 12:37:50 +0200 | [diff] [blame] | 343 | |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 344 | if (fio_server_parse_string(hostname, &client->hostname, |
| 345 | &client->is_sock, &client->port, |
Jens Axboe | 811826b | 2011-10-24 09:11:50 +0200 | [diff] [blame] | 346 | &client->addr.sin_addr, |
| 347 | &client->addr6.sin6_addr, |
| 348 | &client->ipv6)) |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 349 | return -1; |
| 350 | |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 351 | client->fd = -1; |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 352 | client->ops = ops; |
Jens Axboe | 5121a9a | 2012-03-05 13:32:47 +0100 | [diff] [blame] | 353 | client->refs = 1; |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 354 | client->type = ops->client_type; |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 355 | |
| 356 | __fio_client_add_cmd_option(client, "fio"); |
| 357 | |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 358 | flist_add(&client->list, &client_list); |
| 359 | nr_clients++; |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 360 | dprint(FD_NET, "client: added <%s>\n", client->hostname); |
| 361 | *cookie = client; |
| 362 | return 0; |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 363 | } |
| 364 | |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 365 | static const char *server_name(struct fio_client *client, char *buf, |
| 366 | size_t bufsize) |
| 367 | { |
| 368 | const char *from; |
| 369 | |
| 370 | if (client->ipv6) |
| 371 | from = inet_ntop(AF_INET6, (struct sockaddr *) &client->addr6.sin6_addr, buf, bufsize); |
| 372 | else if (client->is_sock) |
| 373 | from = "sock"; |
| 374 | else |
| 375 | from = inet_ntop(AF_INET, (struct sockaddr *) &client->addr.sin_addr, buf, bufsize); |
| 376 | |
| 377 | return from; |
| 378 | } |
| 379 | |
Jens Axboe | d824c3b | 2012-03-09 17:45:43 +0100 | [diff] [blame] | 380 | static void probe_client(struct fio_client *client) |
| 381 | { |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 382 | struct cmd_client_probe_pdu pdu; |
Jens Axboe | 75289ee | 2015-01-05 08:47:01 -0700 | [diff] [blame] | 383 | const char *sname; |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 384 | uint64_t tag; |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 385 | char buf[64]; |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 386 | |
Jens Axboe | d824c3b | 2012-03-09 17:45:43 +0100 | [diff] [blame] | 387 | dprint(FD_NET, "client: send probe\n"); |
| 388 | |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 389 | #ifdef CONFIG_ZLIB |
| 390 | pdu.flags = __le64_to_cpu(FIO_PROBE_FLAG_ZLIB); |
| 391 | #else |
| 392 | pdu.flags = 0; |
| 393 | #endif |
| 394 | |
Jens Axboe | 75289ee | 2015-01-05 08:47:01 -0700 | [diff] [blame] | 395 | sname = server_name(client, buf, sizeof(buf)); |
| 396 | memset(pdu.server, 0, sizeof(pdu.server)); |
| 397 | strncpy((char *) pdu.server, sname, sizeof(pdu.server) - 1); |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 398 | |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 399 | fio_net_send_cmd(client->fd, FIO_NET_CMD_PROBE, &pdu, sizeof(pdu), &tag, &client->cmd_list); |
Jens Axboe | d824c3b | 2012-03-09 17:45:43 +0100 | [diff] [blame] | 400 | } |
| 401 | |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 402 | static int fio_client_connect_ip(struct fio_client *client) |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 403 | { |
Jens Axboe | 811826b | 2011-10-24 09:11:50 +0200 | [diff] [blame] | 404 | struct sockaddr *addr; |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 405 | socklen_t socklen; |
Jens Axboe | 811826b | 2011-10-24 09:11:50 +0200 | [diff] [blame] | 406 | int fd, domain; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 407 | |
Jens Axboe | 811826b | 2011-10-24 09:11:50 +0200 | [diff] [blame] | 408 | if (client->ipv6) { |
| 409 | client->addr6.sin6_family = AF_INET6; |
| 410 | client->addr6.sin6_port = htons(client->port); |
| 411 | domain = AF_INET6; |
| 412 | addr = (struct sockaddr *) &client->addr6; |
| 413 | socklen = sizeof(client->addr6); |
| 414 | } else { |
| 415 | client->addr.sin_family = AF_INET; |
| 416 | client->addr.sin_port = htons(client->port); |
| 417 | domain = AF_INET; |
| 418 | addr = (struct sockaddr *) &client->addr; |
| 419 | socklen = sizeof(client->addr); |
| 420 | } |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 421 | |
Jens Axboe | 811826b | 2011-10-24 09:11:50 +0200 | [diff] [blame] | 422 | fd = socket(domain, SOCK_STREAM, 0); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 423 | if (fd < 0) { |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 424 | int ret = -errno; |
| 425 | |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 426 | log_err("fio: socket: %s\n", strerror(errno)); |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 427 | return ret; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 428 | } |
| 429 | |
Jens Axboe | 811826b | 2011-10-24 09:11:50 +0200 | [diff] [blame] | 430 | if (connect(fd, addr, socklen) < 0) { |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 431 | int ret = -errno; |
| 432 | |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 433 | log_err("fio: connect: %s\n", strerror(errno)); |
Jens Axboe | a7de0a1 | 2011-10-07 12:55:14 +0200 | [diff] [blame] | 434 | log_err("fio: failed to connect to %s:%u\n", client->hostname, |
| 435 | client->port); |
Jens Axboe | b94cba4 | 2011-10-06 21:27:10 +0200 | [diff] [blame] | 436 | close(fd); |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 437 | return ret; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 438 | } |
| 439 | |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 440 | return fd; |
| 441 | } |
| 442 | |
| 443 | static int fio_client_connect_sock(struct fio_client *client) |
| 444 | { |
| 445 | struct sockaddr_un *addr = &client->addr_un; |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 446 | socklen_t len; |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 447 | int fd; |
| 448 | |
| 449 | memset(addr, 0, sizeof(*addr)); |
| 450 | addr->sun_family = AF_UNIX; |
Jens Axboe | 1cb9641 | 2014-04-14 08:50:33 -0600 | [diff] [blame] | 451 | strncpy(addr->sun_path, client->hostname, sizeof(addr->sun_path) - 1); |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 452 | |
| 453 | fd = socket(AF_UNIX, SOCK_STREAM, 0); |
| 454 | if (fd < 0) { |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 455 | int ret = -errno; |
| 456 | |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 457 | log_err("fio: socket: %s\n", strerror(errno)); |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 458 | return ret; |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1; |
| 462 | if (connect(fd, (struct sockaddr *) addr, len) < 0) { |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 463 | int ret = -errno; |
| 464 | |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 465 | log_err("fio: connect; %s\n", strerror(errno)); |
Jens Axboe | b94cba4 | 2011-10-06 21:27:10 +0200 | [diff] [blame] | 466 | close(fd); |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 467 | return ret; |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | return fd; |
| 471 | } |
| 472 | |
Jens Axboe | 2f99deb | 2012-03-09 14:37:29 +0100 | [diff] [blame] | 473 | int fio_client_connect(struct fio_client *client) |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 474 | { |
| 475 | int fd; |
| 476 | |
| 477 | dprint(FD_NET, "client: connect to host %s\n", client->hostname); |
| 478 | |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 479 | if (client->is_sock) |
| 480 | fd = fio_client_connect_sock(client); |
| 481 | else |
| 482 | fd = fio_client_connect_ip(client); |
| 483 | |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 484 | dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd); |
| 485 | |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 486 | if (fd < 0) |
Jens Axboe | a1a3ed5 | 2012-03-09 17:00:01 +0100 | [diff] [blame] | 487 | return fd; |
Jens Axboe | 87aa8f1 | 2011-10-06 21:24:13 +0200 | [diff] [blame] | 488 | |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 489 | client->fd = fd; |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 490 | fio_client_add_hash(client); |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 491 | client->state = Client_connected; |
Jens Axboe | d824c3b | 2012-03-09 17:45:43 +0100 | [diff] [blame] | 492 | |
| 493 | probe_client(client); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 494 | return 0; |
| 495 | } |
| 496 | |
Jens Axboe | 0cf3ece | 2012-03-21 10:15:20 +0100 | [diff] [blame] | 497 | int fio_client_terminate(struct fio_client *client) |
Jens Axboe | 2f99deb | 2012-03-09 14:37:29 +0100 | [diff] [blame] | 498 | { |
Jens Axboe | 0cf3ece | 2012-03-21 10:15:20 +0100 | [diff] [blame] | 499 | return fio_net_send_quit(client->fd); |
Jens Axboe | 2f99deb | 2012-03-09 14:37:29 +0100 | [diff] [blame] | 500 | } |
| 501 | |
Jens Axboe | cc0df00 | 2011-10-03 20:53:32 +0200 | [diff] [blame] | 502 | void fio_clients_terminate(void) |
| 503 | { |
| 504 | struct flist_head *entry; |
| 505 | struct fio_client *client; |
| 506 | |
Jens Axboe | 60efd14 | 2011-10-04 13:30:11 +0200 | [diff] [blame] | 507 | dprint(FD_NET, "client: terminate clients\n"); |
| 508 | |
Jens Axboe | cc0df00 | 2011-10-03 20:53:32 +0200 | [diff] [blame] | 509 | flist_for_each(entry, &client_list) { |
| 510 | client = flist_entry(entry, struct fio_client, list); |
Jens Axboe | 2f99deb | 2012-03-09 14:37:29 +0100 | [diff] [blame] | 511 | fio_client_terminate(client); |
Jens Axboe | cc0df00 | 2011-10-03 20:53:32 +0200 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | |
| 515 | static void sig_int(int sig) |
| 516 | { |
Jens Axboe | bebe639 | 2011-10-07 10:00:51 +0200 | [diff] [blame] | 517 | dprint(FD_NET, "client: got signal %d\n", sig); |
Jens Axboe | cc0df00 | 2011-10-03 20:53:32 +0200 | [diff] [blame] | 518 | fio_clients_terminate(); |
| 519 | } |
| 520 | |
Jens Axboe | b852e7c | 2012-03-30 10:30:35 +0200 | [diff] [blame] | 521 | static void sig_show_status(int sig) |
| 522 | { |
| 523 | show_running_run_stats(); |
| 524 | } |
| 525 | |
Jens Axboe | cc0df00 | 2011-10-03 20:53:32 +0200 | [diff] [blame] | 526 | static void client_signal_handler(void) |
| 527 | { |
| 528 | struct sigaction act; |
| 529 | |
| 530 | memset(&act, 0, sizeof(act)); |
| 531 | act.sa_handler = sig_int; |
| 532 | act.sa_flags = SA_RESTART; |
| 533 | sigaction(SIGINT, &act, NULL); |
| 534 | |
| 535 | memset(&act, 0, sizeof(act)); |
| 536 | act.sa_handler = sig_int; |
| 537 | act.sa_flags = SA_RESTART; |
| 538 | sigaction(SIGTERM, &act, NULL); |
Jens Axboe | b852e7c | 2012-03-30 10:30:35 +0200 | [diff] [blame] | 539 | |
Bruce Cran | 2f69450 | 2012-10-10 16:34:13 +0100 | [diff] [blame] | 540 | /* Windows uses SIGBREAK as a quit signal from other applications */ |
| 541 | #ifdef WIN32 |
| 542 | memset(&act, 0, sizeof(act)); |
| 543 | act.sa_handler = sig_int; |
| 544 | act.sa_flags = SA_RESTART; |
| 545 | sigaction(SIGBREAK, &act, NULL); |
| 546 | #endif |
| 547 | |
Jens Axboe | b852e7c | 2012-03-30 10:30:35 +0200 | [diff] [blame] | 548 | memset(&act, 0, sizeof(act)); |
| 549 | act.sa_handler = sig_show_status; |
| 550 | act.sa_flags = SA_RESTART; |
| 551 | sigaction(SIGUSR1, &act, NULL); |
Jens Axboe | cc0df00 | 2011-10-03 20:53:32 +0200 | [diff] [blame] | 552 | } |
| 553 | |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 554 | static int send_client_cmd_line(struct fio_client *client) |
| 555 | { |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 556 | struct cmd_single_line_pdu *cslp; |
| 557 | struct cmd_line_pdu *clp; |
| 558 | unsigned long offset; |
Jens Axboe | 7f86831 | 2011-10-10 09:55:21 +0200 | [diff] [blame] | 559 | unsigned int *lens; |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 560 | void *pdu; |
| 561 | size_t mem; |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 562 | int i, ret; |
| 563 | |
Jens Axboe | 39e8e01 | 2011-10-04 13:46:08 +0200 | [diff] [blame] | 564 | dprint(FD_NET, "client: send cmdline %d\n", client->argc); |
Jens Axboe | 60efd14 | 2011-10-04 13:30:11 +0200 | [diff] [blame] | 565 | |
Jens Axboe | 7f86831 | 2011-10-10 09:55:21 +0200 | [diff] [blame] | 566 | lens = malloc(client->argc * sizeof(unsigned int)); |
| 567 | |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 568 | /* |
| 569 | * Find out how much mem we need |
| 570 | */ |
Jens Axboe | 7f86831 | 2011-10-10 09:55:21 +0200 | [diff] [blame] | 571 | for (i = 0, mem = 0; i < client->argc; i++) { |
| 572 | lens[i] = strlen(client->argv[i]) + 1; |
| 573 | mem += lens[i]; |
| 574 | } |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 575 | |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 576 | /* |
| 577 | * We need one cmd_line_pdu, and argc number of cmd_single_line_pdu |
| 578 | */ |
| 579 | mem += sizeof(*clp) + (client->argc * sizeof(*cslp)); |
| 580 | |
| 581 | pdu = malloc(mem); |
| 582 | clp = pdu; |
| 583 | offset = sizeof(*clp); |
| 584 | |
| 585 | for (i = 0; i < client->argc; i++) { |
Jens Axboe | 7f86831 | 2011-10-10 09:55:21 +0200 | [diff] [blame] | 586 | uint16_t arg_len = lens[i]; |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 587 | |
| 588 | cslp = pdu + offset; |
| 589 | strcpy((char *) cslp->text, client->argv[i]); |
| 590 | cslp->len = cpu_to_le16(arg_len); |
| 591 | offset += sizeof(*cslp) + arg_len; |
| 592 | } |
| 593 | |
Jens Axboe | 7f86831 | 2011-10-10 09:55:21 +0200 | [diff] [blame] | 594 | free(lens); |
Jens Axboe | fa2ea80 | 2011-10-08 21:07:29 +0200 | [diff] [blame] | 595 | clp->lines = cpu_to_le16(client->argc); |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 596 | clp->client_type = __cpu_to_le16(client->type); |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 597 | ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, NULL, NULL); |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 598 | free(pdu); |
| 599 | return ret; |
| 600 | } |
| 601 | |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 602 | int fio_clients_connect(void) |
| 603 | { |
| 604 | struct fio_client *client; |
| 605 | struct flist_head *entry, *tmp; |
| 606 | int ret; |
| 607 | |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 608 | #ifdef WIN32 |
| 609 | WSADATA wsd; |
Jens Axboe | 3c3ed07 | 2012-03-27 09:12:39 +0200 | [diff] [blame] | 610 | WSAStartup(MAKEWORD(2, 2), &wsd); |
Bruce Cran | 93bcfd2 | 2012-02-20 20:18:19 +0100 | [diff] [blame] | 611 | #endif |
| 612 | |
Jens Axboe | 60efd14 | 2011-10-04 13:30:11 +0200 | [diff] [blame] | 613 | dprint(FD_NET, "client: connect all\n"); |
| 614 | |
Jens Axboe | cc0df00 | 2011-10-03 20:53:32 +0200 | [diff] [blame] | 615 | client_signal_handler(); |
| 616 | |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 617 | flist_for_each_safe(entry, tmp, &client_list) { |
| 618 | client = flist_entry(entry, struct fio_client, list); |
| 619 | |
| 620 | ret = fio_client_connect(client); |
Jens Axboe | 0b8f30a | 2011-10-04 10:31:53 +0200 | [diff] [blame] | 621 | if (ret) { |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 622 | remove_client(client); |
Jens Axboe | 0b8f30a | 2011-10-04 10:31:53 +0200 | [diff] [blame] | 623 | continue; |
| 624 | } |
| 625 | |
Jens Axboe | 81179ee | 2011-10-04 12:42:06 +0200 | [diff] [blame] | 626 | if (client->argc > 1) |
| 627 | send_client_cmd_line(client); |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | return !nr_clients; |
| 631 | } |
| 632 | |
Jens Axboe | b9d2f30 | 2012-03-08 20:36:28 +0100 | [diff] [blame] | 633 | int fio_start_client(struct fio_client *client) |
| 634 | { |
| 635 | dprint(FD_NET, "client: start %s\n", client->hostname); |
| 636 | return fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_RUN, 0, NULL); |
| 637 | } |
| 638 | |
| 639 | int fio_start_all_clients(void) |
| 640 | { |
| 641 | struct fio_client *client; |
| 642 | struct flist_head *entry, *tmp; |
| 643 | int ret; |
| 644 | |
| 645 | dprint(FD_NET, "client: start all\n"); |
| 646 | |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 647 | fio_client_json_init(); |
| 648 | |
Jens Axboe | b9d2f30 | 2012-03-08 20:36:28 +0100 | [diff] [blame] | 649 | flist_for_each_safe(entry, tmp, &client_list) { |
| 650 | client = flist_entry(entry, struct fio_client, list); |
| 651 | |
| 652 | ret = fio_start_client(client); |
| 653 | if (ret) { |
| 654 | remove_client(client); |
| 655 | continue; |
| 656 | } |
| 657 | } |
| 658 | |
| 659 | return flist_empty(&client_list); |
| 660 | } |
| 661 | |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 662 | static int __fio_client_send_remote_ini(struct fio_client *client, |
| 663 | const char *filename) |
| 664 | { |
| 665 | struct cmd_load_file_pdu *pdu; |
| 666 | size_t p_size; |
| 667 | int ret; |
| 668 | |
| 669 | dprint(FD_NET, "send remote ini %s to %s\n", filename, client->hostname); |
| 670 | |
Jens Axboe | 79ecc30 | 2014-10-07 22:02:21 -0600 | [diff] [blame] | 671 | p_size = sizeof(*pdu) + strlen(filename) + 1; |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 672 | pdu = malloc(p_size); |
Jens Axboe | 79ecc30 | 2014-10-07 22:02:21 -0600 | [diff] [blame] | 673 | memset(pdu, 0, p_size); |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 674 | pdu->name_len = strlen(filename); |
| 675 | strcpy((char *) pdu->file, filename); |
| 676 | pdu->client_type = cpu_to_le16((uint16_t) client->type); |
| 677 | |
| 678 | client->sent_job = 1; |
| 679 | ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_LOAD_FILE, pdu, p_size,NULL, NULL); |
| 680 | free(pdu); |
| 681 | return ret; |
| 682 | } |
| 683 | |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 684 | /* |
| 685 | * Send file contents to server backend. We could use sendfile(), but to remain |
| 686 | * more portable lets just read/write the darn thing. |
| 687 | */ |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 688 | static int __fio_client_send_local_ini(struct fio_client *client, |
| 689 | const char *filename) |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 690 | { |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 691 | struct cmd_job_pdu *pdu; |
| 692 | size_t p_size; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 693 | struct stat sb; |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 694 | char *p; |
| 695 | void *buf; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 696 | off_t len; |
| 697 | int fd, ret; |
| 698 | |
Jens Axboe | 46c48f1 | 2011-10-01 12:50:51 -0600 | [diff] [blame] | 699 | dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname); |
| 700 | |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 701 | fd = open(filename, O_RDONLY); |
| 702 | if (fd < 0) { |
Jens Axboe | 0f7f9a9 | 2014-11-06 09:21:10 -0700 | [diff] [blame] | 703 | ret = -errno; |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 704 | log_err("fio: job file <%s> open: %s\n", filename, strerror(errno)); |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 705 | return ret; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | if (fstat(fd, &sb) < 0) { |
Jens Axboe | 0f7f9a9 | 2014-11-06 09:21:10 -0700 | [diff] [blame] | 709 | ret = -errno; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 710 | log_err("fio: job file stat: %s\n", strerror(errno)); |
Jens Axboe | b94cba4 | 2011-10-06 21:27:10 +0200 | [diff] [blame] | 711 | close(fd); |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 712 | return ret; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 713 | } |
| 714 | |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 715 | p_size = sb.st_size + sizeof(*pdu); |
| 716 | pdu = malloc(p_size); |
| 717 | buf = pdu->buf; |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 718 | |
| 719 | len = sb.st_size; |
| 720 | p = buf; |
Jens Axboe | 3d0be7c | 2014-11-11 10:24:00 -0700 | [diff] [blame] | 721 | if (read_data(fd, p, len)) { |
Jens Axboe | 0b8f30a | 2011-10-04 10:31:53 +0200 | [diff] [blame] | 722 | log_err("fio: failed reading job file %s\n", filename); |
Jens Axboe | b94cba4 | 2011-10-06 21:27:10 +0200 | [diff] [blame] | 723 | close(fd); |
Hong Zhiguo | 03a22d9 | 2013-10-16 08:35:12 -0600 | [diff] [blame] | 724 | free(pdu); |
Jens Axboe | 0b8f30a | 2011-10-04 10:31:53 +0200 | [diff] [blame] | 725 | return 1; |
| 726 | } |
| 727 | |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 728 | pdu->buf_len = __cpu_to_le32(sb.st_size); |
| 729 | pdu->client_type = cpu_to_le32(client->type); |
| 730 | |
Jens Axboe | c2cb686 | 2012-02-23 20:56:12 +0100 | [diff] [blame] | 731 | client->sent_job = 1; |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 732 | ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, pdu, p_size, NULL, NULL); |
Jens Axboe | 46bcd49 | 2012-03-14 11:31:21 +0100 | [diff] [blame] | 733 | free(pdu); |
Jens Axboe | b94cba4 | 2011-10-06 21:27:10 +0200 | [diff] [blame] | 734 | close(fd); |
Jens Axboe | 132159a | 2011-09-30 15:01:32 -0600 | [diff] [blame] | 735 | return ret; |
| 736 | } |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 737 | |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 738 | int fio_client_send_ini(struct fio_client *client, const char *filename, |
| 739 | int remote) |
Jens Axboe | 9988ca7 | 2012-03-09 15:14:06 +0100 | [diff] [blame] | 740 | { |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 741 | int ret; |
| 742 | |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 743 | if (!remote) |
| 744 | ret = __fio_client_send_local_ini(client, filename); |
| 745 | else |
| 746 | ret = __fio_client_send_remote_ini(client, filename); |
| 747 | |
Jens Axboe | 3af4520 | 2012-03-13 09:59:53 +0100 | [diff] [blame] | 748 | if (!ret) |
| 749 | client->sent_job = 1; |
Jens Axboe | 9988ca7 | 2012-03-09 15:14:06 +0100 | [diff] [blame] | 750 | |
Jens Axboe | 25095e1 | 2012-03-09 17:09:55 +0100 | [diff] [blame] | 751 | return ret; |
Jens Axboe | 9988ca7 | 2012-03-09 15:14:06 +0100 | [diff] [blame] | 752 | } |
| 753 | |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 754 | static int fio_client_send_cf(struct fio_client *client, |
| 755 | struct client_file *cf) |
| 756 | { |
| 757 | return fio_client_send_ini(client, cf->file, cf->remote); |
| 758 | } |
| 759 | |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 760 | int fio_clients_send_ini(const char *filename) |
| 761 | { |
| 762 | struct fio_client *client; |
| 763 | struct flist_head *entry, *tmp; |
| 764 | |
| 765 | flist_for_each_safe(entry, tmp, &client_list) { |
| 766 | client = flist_entry(entry, struct fio_client, list); |
| 767 | |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 768 | if (client->nr_files) { |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 769 | int i; |
| 770 | |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 771 | for (i = 0; i < client->nr_files; i++) { |
| 772 | struct client_file *cf; |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 773 | |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 774 | cf = &client->files[i]; |
| 775 | |
| 776 | if (fio_client_send_cf(client, cf)) { |
Jens Axboe | 14ea90e | 2012-08-26 17:33:34 +0200 | [diff] [blame] | 777 | remove_client(client); |
| 778 | break; |
| 779 | } |
| 780 | } |
Jens Axboe | 3589918 | 2014-10-07 20:56:28 -0600 | [diff] [blame] | 781 | } |
| 782 | if (client->sent_job) |
| 783 | continue; |
| 784 | if (!filename || fio_client_send_ini(client, filename, 0)) |
Jens Axboe | 3af4520 | 2012-03-13 09:59:53 +0100 | [diff] [blame] | 785 | remove_client(client); |
Jens Axboe | a37f69b | 2011-10-01 12:24:21 -0600 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | return !nr_clients; |
| 789 | } |
| 790 | |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 791 | int fio_client_update_options(struct fio_client *client, |
| 792 | struct thread_options *o, uint64_t *tag) |
| 793 | { |
| 794 | struct cmd_add_job_pdu pdu; |
| 795 | |
| 796 | pdu.thread_number = cpu_to_le32(client->thread_number); |
| 797 | pdu.groupid = cpu_to_le32(client->groupid); |
| 798 | convert_thread_options_to_net(&pdu.top, o); |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 799 | |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 800 | return fio_net_send_cmd(client->fd, FIO_NET_CMD_UPDATE_JOB, &pdu, sizeof(pdu), tag, &client->cmd_list); |
| 801 | } |
| 802 | |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 803 | static void convert_io_stat(struct io_stat *dst, struct io_stat *src) |
| 804 | { |
| 805 | dst->max_val = le64_to_cpu(src->max_val); |
| 806 | dst->min_val = le64_to_cpu(src->min_val); |
| 807 | dst->samples = le64_to_cpu(src->samples); |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 808 | |
| 809 | /* |
| 810 | * Floats arrive as IEEE 754 encoded uint64_t, convert back to double |
| 811 | */ |
| 812 | dst->mean.u.f = fio_uint64_to_double(le64_to_cpu(dst->mean.u.i)); |
| 813 | dst->S.u.f = fio_uint64_to_double(le64_to_cpu(dst->S.u.i)); |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 814 | } |
| 815 | |
| 816 | static void convert_ts(struct thread_stat *dst, struct thread_stat *src) |
| 817 | { |
| 818 | int i, j; |
| 819 | |
Jens Axboe | 2f122b1 | 2012-03-15 13:10:19 +0100 | [diff] [blame] | 820 | dst->error = le32_to_cpu(src->error); |
| 821 | dst->thread_number = le32_to_cpu(src->thread_number); |
| 822 | dst->groupid = le32_to_cpu(src->groupid); |
| 823 | dst->pid = le32_to_cpu(src->pid); |
| 824 | dst->members = le32_to_cpu(src->members); |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 825 | dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep); |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 826 | |
Jens Axboe | 298921d | 2012-09-24 18:47:01 +0200 | [diff] [blame] | 827 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 828 | convert_io_stat(&dst->clat_stat[i], &src->clat_stat[i]); |
| 829 | convert_io_stat(&dst->slat_stat[i], &src->slat_stat[i]); |
| 830 | convert_io_stat(&dst->lat_stat[i], &src->lat_stat[i]); |
| 831 | convert_io_stat(&dst->bw_stat[i], &src->bw_stat[i]); |
| 832 | } |
| 833 | |
| 834 | dst->usr_time = le64_to_cpu(src->usr_time); |
| 835 | dst->sys_time = le64_to_cpu(src->sys_time); |
| 836 | dst->ctx = le64_to_cpu(src->ctx); |
| 837 | dst->minf = le64_to_cpu(src->minf); |
| 838 | dst->majf = le64_to_cpu(src->majf); |
| 839 | dst->clat_percentiles = le64_to_cpu(src->clat_percentiles); |
Jens Axboe | 623216d | 2014-11-07 18:47:41 -0700 | [diff] [blame] | 840 | dst->percentile_precision = le64_to_cpu(src->percentile_precision); |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 841 | |
| 842 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { |
| 843 | fio_fp64_t *fps = &src->percentile_list[i]; |
| 844 | fio_fp64_t *fpd = &dst->percentile_list[i]; |
| 845 | |
| 846 | fpd->u.f = fio_uint64_to_double(le64_to_cpu(fps->u.i)); |
| 847 | } |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 848 | |
| 849 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { |
| 850 | dst->io_u_map[i] = le32_to_cpu(src->io_u_map[i]); |
| 851 | dst->io_u_submit[i] = le32_to_cpu(src->io_u_submit[i]); |
| 852 | dst->io_u_complete[i] = le32_to_cpu(src->io_u_complete[i]); |
| 853 | } |
| 854 | |
| 855 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) { |
| 856 | dst->io_u_lat_u[i] = le32_to_cpu(src->io_u_lat_u[i]); |
| 857 | dst->io_u_lat_m[i] = le32_to_cpu(src->io_u_lat_m[i]); |
| 858 | } |
| 859 | |
Jens Axboe | 298921d | 2012-09-24 18:47:01 +0200 | [diff] [blame] | 860 | for (i = 0; i < DDIR_RWDIR_CNT; i++) |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 861 | for (j = 0; j < FIO_IO_U_PLAT_NR; j++) |
| 862 | dst->io_u_plat[i][j] = le32_to_cpu(src->io_u_plat[i][j]); |
| 863 | |
Jens Axboe | 78799de | 2013-01-29 20:53:52 +0100 | [diff] [blame] | 864 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 865 | dst->total_io_u[i] = le64_to_cpu(src->total_io_u[i]); |
Jens Axboe | 93eee04 | 2011-10-03 21:08:48 +0200 | [diff] [blame] | 866 | dst->short_io_u[i] = le64_to_cpu(src->short_io_u[i]); |
Jens Axboe | 67e149c | 2014-10-09 13:27:44 -0600 | [diff] [blame] | 867 | dst->drop_io_u[i] = le64_to_cpu(src->drop_io_u[i]); |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 868 | } |
| 869 | |
| 870 | dst->total_submit = le64_to_cpu(src->total_submit); |
| 871 | dst->total_complete = le64_to_cpu(src->total_complete); |
| 872 | |
Jens Axboe | 298921d | 2012-09-24 18:47:01 +0200 | [diff] [blame] | 873 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 874 | dst->io_bytes[i] = le64_to_cpu(src->io_bytes[i]); |
| 875 | dst->runtime[i] = le64_to_cpu(src->runtime[i]); |
| 876 | } |
| 877 | |
| 878 | dst->total_run_time = le64_to_cpu(src->total_run_time); |
| 879 | dst->continue_on_error = le16_to_cpu(src->continue_on_error); |
| 880 | dst->total_err_count = le64_to_cpu(src->total_err_count); |
Jens Axboe | ddcc0b6 | 2011-10-03 14:45:27 +0200 | [diff] [blame] | 881 | dst->first_error = le32_to_cpu(src->first_error); |
| 882 | dst->kb_base = le32_to_cpu(src->kb_base); |
Steven Noonan | ad705bc | 2013-04-08 15:05:25 -0700 | [diff] [blame] | 883 | dst->unit_base = le32_to_cpu(src->unit_base); |
Jens Axboe | 3e260a4 | 2013-12-09 12:38:53 -0700 | [diff] [blame] | 884 | |
| 885 | dst->latency_depth = le32_to_cpu(src->latency_depth); |
| 886 | dst->latency_target = le64_to_cpu(src->latency_target); |
| 887 | dst->latency_window = le64_to_cpu(src->latency_window); |
| 888 | dst->latency_percentile.u.f = fio_uint64_to_double(le64_to_cpu(src->latency_percentile.u.i)); |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 889 | } |
| 890 | |
| 891 | static void convert_gs(struct group_run_stats *dst, struct group_run_stats *src) |
| 892 | { |
| 893 | int i; |
| 894 | |
Jens Axboe | 298921d | 2012-09-24 18:47:01 +0200 | [diff] [blame] | 895 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 896 | dst->max_run[i] = le64_to_cpu(src->max_run[i]); |
| 897 | dst->min_run[i] = le64_to_cpu(src->min_run[i]); |
| 898 | dst->max_bw[i] = le64_to_cpu(src->max_bw[i]); |
| 899 | dst->min_bw[i] = le64_to_cpu(src->min_bw[i]); |
| 900 | dst->io_kb[i] = le64_to_cpu(src->io_kb[i]); |
| 901 | dst->agg[i] = le64_to_cpu(src->agg[i]); |
| 902 | } |
| 903 | |
| 904 | dst->kb_base = le32_to_cpu(src->kb_base); |
Steven Noonan | ad705bc | 2013-04-08 15:05:25 -0700 | [diff] [blame] | 905 | dst->unit_base = le32_to_cpu(src->unit_base); |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 906 | dst->groupid = le32_to_cpu(src->groupid); |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 907 | dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep); |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 908 | } |
| 909 | |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 910 | static void json_object_add_client_info(struct json_object *obj, |
Castor Fu | 54bcda5 | 2014-08-22 17:16:44 -0500 | [diff] [blame] | 911 | struct fio_client *client) |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 912 | { |
Castor Fu | 54bcda5 | 2014-08-22 17:16:44 -0500 | [diff] [blame] | 913 | const char *hostname = client->hostname ? client->hostname : ""; |
| 914 | |
| 915 | json_object_add_value_string(obj, "hostname", hostname); |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 916 | json_object_add_value_int(obj, "port", client->port); |
| 917 | } |
| 918 | |
Jens Axboe | 89e5fad | 2012-03-05 09:21:12 +0100 | [diff] [blame] | 919 | static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd) |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 920 | { |
| 921 | struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload; |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 922 | struct json_object *tsobj; |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 923 | |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 924 | tsobj = show_thread_status(&p->ts, &p->rs); |
Jens Axboe | 108fea7 | 2012-11-14 13:09:45 -0700 | [diff] [blame] | 925 | client->did_stat = 1; |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 926 | if (tsobj) { |
| 927 | json_object_add_client_info(tsobj, client); |
| 928 | json_array_add_value_object(clients_array, tsobj); |
| 929 | } |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 930 | |
Jens Axboe | bfa8f5d | 2014-10-13 10:09:28 -0600 | [diff] [blame] | 931 | if (sum_stat_clients <= 1) |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 932 | return; |
| 933 | |
| 934 | sum_thread_stats(&client_ts, &p->ts, sum_stat_nr); |
| 935 | sum_group_stats(&client_gs, &p->rs); |
| 936 | |
| 937 | client_ts.members++; |
Jens Axboe | 2f122b1 | 2012-03-15 13:10:19 +0100 | [diff] [blame] | 938 | client_ts.thread_number = p->ts.thread_number; |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 939 | client_ts.groupid = p->ts.groupid; |
Jens Axboe | 771e58b | 2013-01-30 12:56:23 +0100 | [diff] [blame] | 940 | client_ts.unified_rw_rep = p->ts.unified_rw_rep; |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 941 | |
| 942 | if (++sum_stat_nr == sum_stat_clients) { |
| 943 | strcpy(client_ts.name, "All clients"); |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 944 | tsobj = show_thread_status(&client_ts, &client_gs); |
| 945 | if (tsobj) { |
| 946 | json_object_add_client_info(tsobj, client); |
| 947 | json_array_add_value_object(clients_array, tsobj); |
| 948 | } |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 949 | } |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 950 | } |
| 951 | |
Jens Axboe | 89e5fad | 2012-03-05 09:21:12 +0100 | [diff] [blame] | 952 | static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd) |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 953 | { |
| 954 | struct group_run_stats *gs = (struct group_run_stats *) cmd->payload; |
| 955 | |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 956 | show_group_stats(gs); |
| 957 | } |
| 958 | |
Jens Axboe | 3bf236c | 2012-03-03 20:35:50 +0100 | [diff] [blame] | 959 | static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd) |
| 960 | { |
| 961 | struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload; |
| 962 | const char *buf = (const char *) pdu->buf; |
| 963 | const char *name; |
| 964 | int fio_unused ret; |
| 965 | |
| 966 | name = client->name ? client->name : client->hostname; |
| 967 | |
| 968 | if (!client->skip_newline) |
| 969 | fprintf(f_out, "<%s> ", name); |
| 970 | ret = fwrite(buf, pdu->buf_len, 1, f_out); |
| 971 | fflush(f_out); |
| 972 | client->skip_newline = strchr(buf, '\n') == NULL; |
| 973 | } |
| 974 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 975 | static void convert_agg(struct disk_util_agg *agg) |
| 976 | { |
| 977 | int i; |
| 978 | |
| 979 | for (i = 0; i < 2; i++) { |
Jens Axboe | 2a3bf76 | 2014-12-01 09:42:48 -0700 | [diff] [blame] | 980 | agg->ios[i] = le64_to_cpu(agg->ios[i]); |
| 981 | agg->merges[i] = le64_to_cpu(agg->merges[i]); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 982 | agg->sectors[i] = le64_to_cpu(agg->sectors[i]); |
Jens Axboe | 2a3bf76 | 2014-12-01 09:42:48 -0700 | [diff] [blame] | 983 | agg->ticks[i] = le64_to_cpu(agg->ticks[i]); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 984 | } |
| 985 | |
Jens Axboe | 2a3bf76 | 2014-12-01 09:42:48 -0700 | [diff] [blame] | 986 | agg->io_ticks = le64_to_cpu(agg->io_ticks); |
| 987 | agg->time_in_queue = le64_to_cpu(agg->time_in_queue); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 988 | agg->slavecount = le32_to_cpu(agg->slavecount); |
Jens Axboe | 2b827fa | 2014-10-13 16:05:10 -0600 | [diff] [blame] | 989 | agg->max_util.u.f = fio_uint64_to_double(le64_to_cpu(agg->max_util.u.i)); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | static void convert_dus(struct disk_util_stat *dus) |
| 993 | { |
| 994 | int i; |
| 995 | |
| 996 | for (i = 0; i < 2; i++) { |
Jens Axboe | 2a3bf76 | 2014-12-01 09:42:48 -0700 | [diff] [blame] | 997 | dus->s.ios[i] = le64_to_cpu(dus->s.ios[i]); |
| 998 | dus->s.merges[i] = le64_to_cpu(dus->s.merges[i]); |
Jens Axboe | a3b4cf7 | 2014-04-11 12:17:53 -0600 | [diff] [blame] | 999 | dus->s.sectors[i] = le64_to_cpu(dus->s.sectors[i]); |
Jens Axboe | 2a3bf76 | 2014-12-01 09:42:48 -0700 | [diff] [blame] | 1000 | dus->s.ticks[i] = le64_to_cpu(dus->s.ticks[i]); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 1001 | } |
| 1002 | |
Jens Axboe | 2a3bf76 | 2014-12-01 09:42:48 -0700 | [diff] [blame] | 1003 | dus->s.io_ticks = le64_to_cpu(dus->s.io_ticks); |
| 1004 | dus->s.time_in_queue = le64_to_cpu(dus->s.time_in_queue); |
Jens Axboe | a3b4cf7 | 2014-04-11 12:17:53 -0600 | [diff] [blame] | 1005 | dus->s.msec = le64_to_cpu(dus->s.msec); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 1006 | } |
| 1007 | |
| 1008 | static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd) |
| 1009 | { |
| 1010 | struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload; |
| 1011 | |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 1012 | if (!client->disk_stats_shown) { |
| 1013 | client->disk_stats_shown = 1; |
| 1014 | log_info("\nDisk stats (read/write):\n"); |
| 1015 | } |
| 1016 | |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 1017 | if (output_format == FIO_OUTPUT_JSON) { |
| 1018 | struct json_object *duobj; |
| 1019 | json_array_add_disk_util(&du->dus, &du->agg, du_array); |
| 1020 | duobj = json_array_last_value_object(du_array); |
| 1021 | json_object_add_client_info(duobj, client); |
| 1022 | } else |
| 1023 | print_disk_util(&du->dus, &du->agg, output_format == FIO_OUTPUT_TERSE); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 1024 | } |
| 1025 | |
Jens Axboe | 3bf236c | 2012-03-03 20:35:50 +0100 | [diff] [blame] | 1026 | static void convert_jobs_eta(struct jobs_eta *je) |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 1027 | { |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 1028 | int i; |
| 1029 | |
| 1030 | je->nr_running = le32_to_cpu(je->nr_running); |
| 1031 | je->nr_ramp = le32_to_cpu(je->nr_ramp); |
| 1032 | je->nr_pending = le32_to_cpu(je->nr_pending); |
Jens Axboe | 714e85f | 2013-04-15 10:21:56 +0200 | [diff] [blame] | 1033 | je->nr_setting_up = le32_to_cpu(je->nr_setting_up); |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 1034 | je->files_open = le32_to_cpu(je->files_open); |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 1035 | |
Jens Axboe | 298921d | 2012-09-24 18:47:01 +0200 | [diff] [blame] | 1036 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
| 1037 | je->m_rate[i] = le32_to_cpu(je->m_rate[i]); |
| 1038 | je->t_rate[i] = le32_to_cpu(je->t_rate[i]); |
| 1039 | je->m_iops[i] = le32_to_cpu(je->m_iops[i]); |
| 1040 | je->t_iops[i] = le32_to_cpu(je->t_iops[i]); |
Jens Axboe | 16725bb | 2013-04-11 12:43:05 +0200 | [diff] [blame] | 1041 | je->rate[i] = le32_to_cpu(je->rate[i]); |
| 1042 | je->iops[i] = le32_to_cpu(je->iops[i]); |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 1043 | } |
| 1044 | |
Jens Axboe | b51eedb | 2011-10-09 12:13:39 +0200 | [diff] [blame] | 1045 | je->elapsed_sec = le64_to_cpu(je->elapsed_sec); |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 1046 | je->eta_sec = le64_to_cpu(je->eta_sec); |
Jens Axboe | 8c621fb | 2012-03-08 12:30:48 +0100 | [diff] [blame] | 1047 | je->nr_threads = le32_to_cpu(je->nr_threads); |
Jens Axboe | b7f05eb | 2012-05-11 20:33:02 +0200 | [diff] [blame] | 1048 | je->is_pow2 = le32_to_cpu(je->is_pow2); |
Jens Axboe | ed2c0a1 | 2013-04-11 12:55:16 +0200 | [diff] [blame] | 1049 | je->unit_base = le32_to_cpu(je->unit_base); |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 1050 | } |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 1051 | |
Jens Axboe | 3e47bd2 | 2012-02-29 13:45:02 +0100 | [diff] [blame] | 1052 | void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je) |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 1053 | { |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 1054 | int i; |
| 1055 | |
| 1056 | dst->nr_running += je->nr_running; |
| 1057 | dst->nr_ramp += je->nr_ramp; |
| 1058 | dst->nr_pending += je->nr_pending; |
Jens Axboe | 714e85f | 2013-04-15 10:21:56 +0200 | [diff] [blame] | 1059 | dst->nr_setting_up += je->nr_setting_up; |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 1060 | dst->files_open += je->files_open; |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 1061 | |
Jens Axboe | 298921d | 2012-09-24 18:47:01 +0200 | [diff] [blame] | 1062 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
Jens Axboe | 3e47bd2 | 2012-02-29 13:45:02 +0100 | [diff] [blame] | 1063 | dst->m_rate[i] += je->m_rate[i]; |
| 1064 | dst->t_rate[i] += je->t_rate[i]; |
| 1065 | dst->m_iops[i] += je->m_iops[i]; |
| 1066 | dst->t_iops[i] += je->t_iops[i]; |
Jens Axboe | 16725bb | 2013-04-11 12:43:05 +0200 | [diff] [blame] | 1067 | dst->rate[i] += je->rate[i]; |
| 1068 | dst->iops[i] += je->iops[i]; |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | dst->elapsed_sec += je->elapsed_sec; |
| 1072 | |
| 1073 | if (je->eta_sec > dst->eta_sec) |
| 1074 | dst->eta_sec = je->eta_sec; |
Jens Axboe | 8c621fb | 2012-03-08 12:30:48 +0100 | [diff] [blame] | 1075 | |
| 1076 | dst->nr_threads += je->nr_threads; |
Jens Axboe | 27b9155 | 2014-06-27 15:30:06 -0600 | [diff] [blame] | 1077 | |
| 1078 | /* |
| 1079 | * This wont be correct for multiple strings, but at least it |
| 1080 | * works for the basic cases. |
| 1081 | */ |
| 1082 | strcpy((char *) dst->run_str, (char *) je->run_str); |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 1083 | } |
| 1084 | |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1085 | void fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op eta_fn) |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1086 | { |
| 1087 | if (!--eta->pending) { |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1088 | eta_fn(&eta->eta); |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1089 | free(eta); |
| 1090 | } |
| 1091 | } |
| 1092 | |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1093 | static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd) |
| 1094 | { |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1095 | struct fio_net_cmd_reply *reply = NULL; |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1096 | struct flist_head *entry; |
| 1097 | |
| 1098 | flist_for_each(entry, &client->cmd_list) { |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1099 | reply = flist_entry(entry, struct fio_net_cmd_reply, list); |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1100 | |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1101 | if (cmd->tag == (uintptr_t) reply) |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1102 | break; |
| 1103 | |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1104 | reply = NULL; |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1105 | } |
| 1106 | |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1107 | if (!reply) { |
Jens Axboe | 4e0a8fa | 2013-04-15 11:40:57 +0200 | [diff] [blame] | 1108 | log_err("fio: client: unable to find matching tag (%llx)\n", (unsigned long long) cmd->tag); |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1109 | return; |
| 1110 | } |
| 1111 | |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1112 | flist_del(&reply->list); |
| 1113 | cmd->tag = reply->saved_tag; |
| 1114 | free(reply); |
| 1115 | } |
| 1116 | |
| 1117 | int fio_client_wait_for_reply(struct fio_client *client, uint64_t tag) |
| 1118 | { |
| 1119 | do { |
| 1120 | struct fio_net_cmd_reply *reply = NULL; |
| 1121 | struct flist_head *entry; |
| 1122 | |
| 1123 | flist_for_each(entry, &client->cmd_list) { |
| 1124 | reply = flist_entry(entry, struct fio_net_cmd_reply, list); |
| 1125 | |
| 1126 | if (tag == (uintptr_t) reply) |
| 1127 | break; |
| 1128 | |
| 1129 | reply = NULL; |
| 1130 | } |
| 1131 | |
| 1132 | if (!reply) |
| 1133 | break; |
| 1134 | |
| 1135 | usleep(1000); |
| 1136 | } while (1); |
| 1137 | |
| 1138 | return 0; |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1139 | } |
| 1140 | |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1141 | static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd) |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 1142 | { |
| 1143 | struct jobs_eta *je = (struct jobs_eta *) cmd->payload; |
Jens Axboe | df38093 | 2011-10-11 14:25:08 +0200 | [diff] [blame] | 1144 | struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag; |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1145 | |
| 1146 | dprint(FD_NET, "client: got eta tag %p, %d\n", eta, eta->pending); |
Jens Axboe | 48fbb46 | 2011-10-09 12:19:08 +0200 | [diff] [blame] | 1147 | |
Jens Axboe | f77d267 | 2011-10-10 14:36:07 +0200 | [diff] [blame] | 1148 | assert(client->eta_in_flight == eta); |
| 1149 | |
| 1150 | client->eta_in_flight = NULL; |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1151 | flist_del_init(&client->eta_list); |
| 1152 | |
Jens Axboe | 2f99deb | 2012-03-09 14:37:29 +0100 | [diff] [blame] | 1153 | if (client->ops->jobs_eta) |
| 1154 | client->ops->jobs_eta(client, je); |
| 1155 | |
Jens Axboe | 3e47bd2 | 2012-02-29 13:45:02 +0100 | [diff] [blame] | 1156 | fio_client_sum_jobs_eta(&eta->eta, je); |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1157 | fio_client_dec_jobs_eta(eta, client->ops->eta); |
Jens Axboe | cf451d1 | 2011-10-03 16:48:30 +0200 | [diff] [blame] | 1158 | } |
| 1159 | |
Jens Axboe | b5296dd | 2011-10-07 16:35:56 +0200 | [diff] [blame] | 1160 | static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd) |
Jens Axboe | 2e03b4b | 2011-10-04 09:00:40 +0200 | [diff] [blame] | 1161 | { |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1162 | struct cmd_probe_reply_pdu *probe = (struct cmd_probe_reply_pdu *) cmd->payload; |
Jens Axboe | d233335 | 2011-10-11 15:07:23 +0200 | [diff] [blame] | 1163 | const char *os, *arch; |
| 1164 | char bit[16]; |
Jens Axboe | 2e03b4b | 2011-10-04 09:00:40 +0200 | [diff] [blame] | 1165 | |
Jens Axboe | cca8464 | 2011-10-07 12:47:57 +0200 | [diff] [blame] | 1166 | os = fio_get_os_string(probe->os); |
| 1167 | if (!os) |
| 1168 | os = "unknown"; |
| 1169 | |
| 1170 | arch = fio_get_arch_string(probe->arch); |
| 1171 | if (!arch) |
| 1172 | os = "unknown"; |
| 1173 | |
Jens Axboe | d233335 | 2011-10-11 15:07:23 +0200 | [diff] [blame] | 1174 | sprintf(bit, "%d-bit", probe->bpp * 8); |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1175 | probe->flags = le64_to_cpu(probe->flags); |
Jens Axboe | 38fdef2 | 2011-10-11 14:30:06 +0200 | [diff] [blame] | 1176 | |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1177 | log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s, flags=%lx\n", |
Jens Axboe | 38fdef2 | 2011-10-11 14:30:06 +0200 | [diff] [blame] | 1178 | probe->hostname, probe->bigendian, bit, os, arch, |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1179 | probe->fio_version, (unsigned long) probe->flags); |
Jens Axboe | b5296dd | 2011-10-07 16:35:56 +0200 | [diff] [blame] | 1180 | |
| 1181 | if (!client->name) |
| 1182 | client->name = strdup((char *) probe->hostname); |
Jens Axboe | 2e03b4b | 2011-10-04 09:00:40 +0200 | [diff] [blame] | 1183 | } |
| 1184 | |
Jens Axboe | 11e950b | 2011-10-16 21:34:14 +0200 | [diff] [blame] | 1185 | static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd) |
| 1186 | { |
| 1187 | struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload; |
| 1188 | |
| 1189 | client->state = Client_started; |
| 1190 | client->jobs = le32_to_cpu(pdu->jobs); |
Jens Axboe | 30f8e31 | 2014-10-13 11:33:27 -0600 | [diff] [blame] | 1191 | client->nr_stat = le32_to_cpu(pdu->stat_outputs); |
Jens Axboe | 108fea7 | 2012-11-14 13:09:45 -0700 | [diff] [blame] | 1192 | |
Jens Axboe | 30f8e31 | 2014-10-13 11:33:27 -0600 | [diff] [blame] | 1193 | sum_stat_clients += client->nr_stat; |
Jens Axboe | 11e950b | 2011-10-16 21:34:14 +0200 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd) |
| 1197 | { |
Jens Axboe | 498c92c | 2011-10-17 09:14:42 +0200 | [diff] [blame] | 1198 | if (client->error) |
| 1199 | log_info("client <%s>: exited with error %d\n", client->hostname, client->error); |
Jens Axboe | 11e950b | 2011-10-16 21:34:14 +0200 | [diff] [blame] | 1200 | } |
| 1201 | |
Jens Axboe | 6b79c80 | 2012-03-08 10:51:36 +0100 | [diff] [blame] | 1202 | static void convert_stop(struct fio_net_cmd *cmd) |
| 1203 | { |
| 1204 | struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload; |
| 1205 | |
| 1206 | pdu->error = le32_to_cpu(pdu->error); |
| 1207 | } |
| 1208 | |
Jens Axboe | 084d1c6 | 2012-03-03 20:28:07 +0100 | [diff] [blame] | 1209 | static void convert_text(struct fio_net_cmd *cmd) |
| 1210 | { |
| 1211 | struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload; |
| 1212 | |
| 1213 | pdu->level = le32_to_cpu(pdu->level); |
| 1214 | pdu->buf_len = le32_to_cpu(pdu->buf_len); |
| 1215 | pdu->log_sec = le64_to_cpu(pdu->log_sec); |
| 1216 | pdu->log_usec = le64_to_cpu(pdu->log_usec); |
| 1217 | } |
| 1218 | |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1219 | static struct cmd_iolog_pdu *convert_iolog_gz(struct fio_net_cmd *cmd, |
| 1220 | struct cmd_iolog_pdu *pdu) |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1221 | { |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1222 | #ifdef CONFIG_ZLIB |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1223 | struct cmd_iolog_pdu *ret; |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1224 | z_stream stream; |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1225 | uint32_t nr_samples; |
| 1226 | size_t total; |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1227 | void *p; |
| 1228 | |
| 1229 | stream.zalloc = Z_NULL; |
| 1230 | stream.zfree = Z_NULL; |
| 1231 | stream.opaque = Z_NULL; |
| 1232 | stream.avail_in = 0; |
| 1233 | stream.next_in = Z_NULL; |
| 1234 | |
| 1235 | if (inflateInit(&stream) != Z_OK) |
| 1236 | return NULL; |
| 1237 | |
| 1238 | /* |
Jens Axboe | f5ed765 | 2012-03-14 16:28:07 +0100 | [diff] [blame] | 1239 | * Get header first, it's not compressed |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1240 | */ |
Jens Axboe | f2b9a67 | 2014-07-01 08:47:11 -0600 | [diff] [blame] | 1241 | nr_samples = le64_to_cpu(pdu->nr_samples); |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1242 | |
Jens Axboe | f2b9a67 | 2014-07-01 08:47:11 -0600 | [diff] [blame] | 1243 | total = nr_samples * __log_entry_sz(le32_to_cpu(pdu->log_offset)); |
Jens Axboe | f5ed765 | 2012-03-14 16:28:07 +0100 | [diff] [blame] | 1244 | ret = malloc(total + sizeof(*pdu)); |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1245 | ret->nr_samples = nr_samples; |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1246 | |
| 1247 | memcpy(ret, pdu, sizeof(*pdu)); |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1248 | |
Jens Axboe | f5ed765 | 2012-03-14 16:28:07 +0100 | [diff] [blame] | 1249 | p = (void *) ret + sizeof(*pdu); |
| 1250 | |
| 1251 | stream.avail_in = cmd->pdu_len - sizeof(*pdu); |
| 1252 | stream.next_in = (void *) pdu + sizeof(*pdu); |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1253 | while (stream.avail_in) { |
| 1254 | unsigned int this_chunk = 65536; |
| 1255 | unsigned int this_len; |
| 1256 | int err; |
| 1257 | |
| 1258 | if (this_chunk > total) |
| 1259 | this_chunk = total; |
| 1260 | |
| 1261 | stream.avail_out = this_chunk; |
| 1262 | stream.next_out = p; |
| 1263 | err = inflate(&stream, Z_NO_FLUSH); |
Jens Axboe | 3c547fe | 2012-03-14 21:53:00 +0100 | [diff] [blame] | 1264 | /* may be Z_OK, or Z_STREAM_END */ |
| 1265 | if (err < 0) { |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1266 | log_err("fio: inflate error %d\n", err); |
Jens Axboe | f5ed765 | 2012-03-14 16:28:07 +0100 | [diff] [blame] | 1267 | free(ret); |
| 1268 | ret = NULL; |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1269 | goto err; |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1270 | } |
| 1271 | |
| 1272 | this_len = this_chunk - stream.avail_out; |
| 1273 | p += this_len; |
| 1274 | total -= this_len; |
| 1275 | } |
| 1276 | |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1277 | err: |
| 1278 | inflateEnd(&stream); |
| 1279 | return ret; |
| 1280 | #else |
| 1281 | return NULL; |
| 1282 | #endif |
| 1283 | } |
| 1284 | |
| 1285 | /* |
| 1286 | * This has been compressed on the server side, since it can be big. |
| 1287 | * Uncompress here. |
| 1288 | */ |
| 1289 | static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd) |
| 1290 | { |
| 1291 | struct cmd_iolog_pdu *pdu = (struct cmd_iolog_pdu *) cmd->payload; |
| 1292 | struct cmd_iolog_pdu *ret; |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 1293 | uint64_t i; |
| 1294 | void *samples; |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1295 | |
| 1296 | /* |
| 1297 | * Convert if compressed and we support it. If it's not |
| 1298 | * compressed, we need not do anything. |
| 1299 | */ |
| 1300 | if (le32_to_cpu(pdu->compressed)) { |
| 1301 | #ifndef CONFIG_ZLIB |
| 1302 | log_err("fio: server sent compressed data by mistake\n"); |
| 1303 | return NULL; |
| 1304 | #endif |
| 1305 | ret = convert_iolog_gz(cmd, pdu); |
| 1306 | if (!ret) { |
| 1307 | log_err("fio: failed decompressing log\n"); |
| 1308 | return NULL; |
| 1309 | } |
| 1310 | } else |
| 1311 | ret = pdu; |
| 1312 | |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 1313 | ret->nr_samples = le64_to_cpu(ret->nr_samples); |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1314 | ret->thread_number = le32_to_cpu(ret->thread_number); |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1315 | ret->log_type = le32_to_cpu(ret->log_type); |
| 1316 | ret->compressed = le32_to_cpu(ret->compressed); |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 1317 | ret->log_offset = le32_to_cpu(ret->log_offset); |
Jens Axboe | 3989b14 | 2013-04-12 13:13:24 +0200 | [diff] [blame] | 1318 | |
Jens Axboe | e8c4fb0 | 2014-07-01 16:07:59 -0600 | [diff] [blame] | 1319 | samples = &ret->samples[0]; |
Jens Axboe | f5ed765 | 2012-03-14 16:28:07 +0100 | [diff] [blame] | 1320 | for (i = 0; i < ret->nr_samples; i++) { |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 1321 | struct io_sample *s; |
Jens Axboe | f5ed765 | 2012-03-14 16:28:07 +0100 | [diff] [blame] | 1322 | |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 1323 | s = __get_sample(samples, ret->log_offset, i); |
Jens Axboe | bac4af1 | 2014-07-03 13:42:28 -0600 | [diff] [blame] | 1324 | s->time = le64_to_cpu(s->time); |
| 1325 | s->val = le64_to_cpu(s->val); |
| 1326 | s->__ddir = le32_to_cpu(s->__ddir); |
| 1327 | s->bs = le32_to_cpu(s->bs); |
Jens Axboe | ccefd5f | 2014-06-30 20:59:03 -0600 | [diff] [blame] | 1328 | |
| 1329 | if (ret->log_offset) { |
| 1330 | struct io_sample_offset *so = (void *) s; |
| 1331 | |
| 1332 | so->offset = le64_to_cpu(so->offset); |
| 1333 | } |
Jens Axboe | f5ed765 | 2012-03-14 16:28:07 +0100 | [diff] [blame] | 1334 | } |
| 1335 | |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1336 | return ret; |
| 1337 | } |
| 1338 | |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 1339 | static void sendfile_reply(int fd, struct cmd_sendfile_reply *rep, |
| 1340 | size_t size, uint64_t tag) |
| 1341 | { |
| 1342 | rep->error = cpu_to_le32(rep->error); |
| 1343 | fio_net_send_cmd(fd, FIO_NET_CMD_SENDFILE, rep, size, &tag, NULL); |
| 1344 | } |
| 1345 | |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 1346 | static int send_file(struct fio_client *client, struct cmd_sendfile *pdu, |
| 1347 | uint64_t tag) |
| 1348 | { |
| 1349 | struct cmd_sendfile_reply *rep; |
| 1350 | struct stat sb; |
| 1351 | size_t size; |
| 1352 | int fd; |
| 1353 | |
| 1354 | size = sizeof(*rep); |
| 1355 | rep = malloc(size); |
| 1356 | |
| 1357 | if (stat((char *)pdu->path, &sb) < 0) { |
| 1358 | fail: |
| 1359 | rep->error = errno; |
| 1360 | sendfile_reply(client->fd, rep, size, tag); |
| 1361 | free(rep); |
| 1362 | return 1; |
| 1363 | } |
| 1364 | |
| 1365 | size += sb.st_size; |
| 1366 | rep = realloc(rep, size); |
| 1367 | rep->size = cpu_to_le32((uint32_t) sb.st_size); |
| 1368 | |
| 1369 | fd = open((char *)pdu->path, O_RDONLY); |
| 1370 | if (fd == -1 ) |
| 1371 | goto fail; |
| 1372 | |
| 1373 | rep->error = read_data(fd, &rep->data, sb.st_size); |
| 1374 | sendfile_reply(client->fd, rep, size, tag); |
| 1375 | free(rep); |
| 1376 | close(fd); |
| 1377 | return 0; |
| 1378 | } |
| 1379 | |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1380 | int fio_handle_client(struct fio_client *client) |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 1381 | { |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1382 | struct client_ops *ops = client->ops; |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 1383 | struct fio_net_cmd *cmd; |
| 1384 | |
Jens Axboe | 60efd14 | 2011-10-04 13:30:11 +0200 | [diff] [blame] | 1385 | dprint(FD_NET, "client: handle %s\n", client->hostname); |
| 1386 | |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1387 | cmd = fio_net_recv_cmd(client->fd); |
| 1388 | if (!cmd) |
| 1389 | return 0; |
Jens Axboe | c2c9458 | 2011-10-05 20:31:30 +0200 | [diff] [blame] | 1390 | |
Jens Axboe | b9d2f30 | 2012-03-08 20:36:28 +0100 | [diff] [blame] | 1391 | dprint(FD_NET, "client: got cmd op %s from %s (pdu=%u)\n", |
| 1392 | fio_server_op(cmd->opcode), client->hostname, cmd->pdu_len); |
Jens Axboe | 46c48f1 | 2011-10-01 12:50:51 -0600 | [diff] [blame] | 1393 | |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1394 | switch (cmd->opcode) { |
| 1395 | case FIO_NET_CMD_QUIT: |
Jens Axboe | 3ec62ec | 2012-03-01 12:01:29 +0100 | [diff] [blame] | 1396 | if (ops->quit) |
Jens Axboe | 35c0ba7 | 2012-03-14 10:56:40 +0100 | [diff] [blame] | 1397 | ops->quit(client, cmd); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1398 | remove_client(client); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1399 | break; |
Jens Axboe | 084d1c6 | 2012-03-03 20:28:07 +0100 | [diff] [blame] | 1400 | case FIO_NET_CMD_TEXT: |
| 1401 | convert_text(cmd); |
Jens Axboe | 35c0ba7 | 2012-03-14 10:56:40 +0100 | [diff] [blame] | 1402 | ops->text(client, cmd); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1403 | break; |
Jens Axboe | 3bf236c | 2012-03-03 20:35:50 +0100 | [diff] [blame] | 1404 | case FIO_NET_CMD_DU: { |
| 1405 | struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload; |
| 1406 | |
| 1407 | convert_dus(&du->dus); |
| 1408 | convert_agg(&du->agg); |
| 1409 | |
Stephen M. Cameron | dd36672 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 1410 | ops->disk_util(client, cmd); |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 1411 | break; |
Jens Axboe | 3bf236c | 2012-03-03 20:35:50 +0100 | [diff] [blame] | 1412 | } |
| 1413 | case FIO_NET_CMD_TS: { |
| 1414 | struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload; |
| 1415 | |
| 1416 | convert_ts(&p->ts, &p->ts); |
| 1417 | convert_gs(&p->rs, &p->rs); |
| 1418 | |
Jens Axboe | 89e5fad | 2012-03-05 09:21:12 +0100 | [diff] [blame] | 1419 | ops->thread_status(client, cmd); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1420 | break; |
Jens Axboe | 3bf236c | 2012-03-03 20:35:50 +0100 | [diff] [blame] | 1421 | } |
| 1422 | case FIO_NET_CMD_GS: { |
| 1423 | struct group_run_stats *gs = (struct group_run_stats *) cmd->payload; |
| 1424 | |
| 1425 | convert_gs(gs, gs); |
| 1426 | |
Jens Axboe | 89e5fad | 2012-03-05 09:21:12 +0100 | [diff] [blame] | 1427 | ops->group_stats(client, cmd); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1428 | break; |
Jens Axboe | 3bf236c | 2012-03-03 20:35:50 +0100 | [diff] [blame] | 1429 | } |
| 1430 | case FIO_NET_CMD_ETA: { |
| 1431 | struct jobs_eta *je = (struct jobs_eta *) cmd->payload; |
| 1432 | |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1433 | remove_reply_cmd(client, cmd); |
Jens Axboe | 3bf236c | 2012-03-03 20:35:50 +0100 | [diff] [blame] | 1434 | convert_jobs_eta(je); |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1435 | handle_eta(client, cmd); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1436 | break; |
Jens Axboe | 3bf236c | 2012-03-03 20:35:50 +0100 | [diff] [blame] | 1437 | } |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1438 | case FIO_NET_CMD_PROBE: |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1439 | remove_reply_cmd(client, cmd); |
Stephen M. Cameron | dd36672 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 1440 | ops->probe(client, cmd); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1441 | break; |
Jens Axboe | 5d7793a | 2012-03-08 19:59:16 +0100 | [diff] [blame] | 1442 | case FIO_NET_CMD_SERVER_START: |
Jens Axboe | 01be038 | 2011-10-15 14:43:41 +0200 | [diff] [blame] | 1443 | client->state = Client_running; |
Jens Axboe | 85dd01e | 2012-03-12 14:33:16 +0100 | [diff] [blame] | 1444 | if (ops->job_start) |
| 1445 | ops->job_start(client, cmd); |
Jens Axboe | 01be038 | 2011-10-15 14:43:41 +0200 | [diff] [blame] | 1446 | break; |
Jens Axboe | 85dd01e | 2012-03-12 14:33:16 +0100 | [diff] [blame] | 1447 | case FIO_NET_CMD_START: { |
| 1448 | struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload; |
| 1449 | |
| 1450 | pdu->jobs = le32_to_cpu(pdu->jobs); |
| 1451 | ops->start(client, cmd); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1452 | break; |
Jens Axboe | 85dd01e | 2012-03-12 14:33:16 +0100 | [diff] [blame] | 1453 | } |
Jens Axboe | 6b79c80 | 2012-03-08 10:51:36 +0100 | [diff] [blame] | 1454 | case FIO_NET_CMD_STOP: { |
| 1455 | struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload; |
| 1456 | |
| 1457 | convert_stop(cmd); |
| 1458 | client->state = Client_stopped; |
Jens Axboe | 122c772 | 2012-03-19 09:13:15 +0100 | [diff] [blame] | 1459 | client->error = le32_to_cpu(pdu->error); |
| 1460 | client->signal = le32_to_cpu(pdu->signal); |
Jens Axboe | 6b79c80 | 2012-03-08 10:51:36 +0100 | [diff] [blame] | 1461 | ops->stop(client, cmd); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1462 | break; |
Jens Axboe | 6b79c80 | 2012-03-08 10:51:36 +0100 | [diff] [blame] | 1463 | } |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1464 | case FIO_NET_CMD_ADD_JOB: { |
| 1465 | struct cmd_add_job_pdu *pdu = (struct cmd_add_job_pdu *) cmd->payload; |
| 1466 | |
| 1467 | client->thread_number = le32_to_cpu(pdu->thread_number); |
| 1468 | client->groupid = le32_to_cpu(pdu->groupid); |
| 1469 | |
Jens Axboe | 807f997 | 2012-03-02 10:25:24 +0100 | [diff] [blame] | 1470 | if (ops->add_job) |
| 1471 | ops->add_job(client, cmd); |
Jens Axboe | 807f997 | 2012-03-02 10:25:24 +0100 | [diff] [blame] | 1472 | break; |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1473 | } |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1474 | case FIO_NET_CMD_IOLOG: |
| 1475 | if (ops->iolog) { |
| 1476 | struct cmd_iolog_pdu *pdu; |
| 1477 | |
| 1478 | pdu = convert_iolog(cmd); |
| 1479 | ops->iolog(client, pdu); |
| 1480 | } |
Jens Axboe | 1b42725 | 2012-03-14 15:03:03 +0100 | [diff] [blame] | 1481 | break; |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1482 | case FIO_NET_CMD_UPDATE_JOB: |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1483 | ops->update_job(client, cmd); |
Jens Axboe | 649cee9 | 2012-03-28 09:15:32 +0200 | [diff] [blame] | 1484 | remove_reply_cmd(client, cmd); |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1485 | break; |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 1486 | case FIO_NET_CMD_VTRIGGER: { |
| 1487 | struct all_io_list *pdu = (struct all_io_list *) cmd->payload; |
| 1488 | char buf[64]; |
| 1489 | |
| 1490 | __verify_save_state(pdu, server_name(client, buf, sizeof(buf))); |
Jens Axboe | 7eebf50 | 2014-11-19 09:09:01 -0700 | [diff] [blame] | 1491 | exec_trigger(trigger_cmd); |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 1492 | break; |
| 1493 | } |
| 1494 | case FIO_NET_CMD_SENDFILE: { |
| 1495 | struct cmd_sendfile *pdu = (struct cmd_sendfile *) cmd->payload; |
| 1496 | send_file(client, pdu, cmd->tag); |
| 1497 | break; |
| 1498 | } |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1499 | default: |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1500 | log_err("fio: unknown client op: %s\n", fio_server_op(cmd->opcode)); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1501 | break; |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 1502 | } |
| 1503 | |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 1504 | free(cmd); |
Jens Axboe | e951bdc | 2011-10-05 21:58:45 +0200 | [diff] [blame] | 1505 | return 1; |
Jens Axboe | 37db14f | 2011-09-30 17:00:42 -0600 | [diff] [blame] | 1506 | } |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1507 | |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 1508 | int fio_clients_send_trigger(const char *cmd) |
| 1509 | { |
| 1510 | struct flist_head *entry; |
| 1511 | struct fio_client *client; |
| 1512 | size_t slen; |
| 1513 | |
| 1514 | dprint(FD_NET, "client: send vtrigger: %s\n", cmd); |
| 1515 | |
| 1516 | if (!cmd) |
| 1517 | slen = 0; |
| 1518 | else |
| 1519 | slen = strlen(cmd); |
| 1520 | |
| 1521 | flist_for_each(entry, &client_list) { |
| 1522 | struct cmd_vtrigger_pdu *pdu; |
| 1523 | |
| 1524 | client = flist_entry(entry, struct fio_client, list); |
| 1525 | |
| 1526 | pdu = malloc(sizeof(*pdu) + slen); |
| 1527 | pdu->len = cpu_to_le16((uint16_t) slen); |
| 1528 | if (slen) |
| 1529 | memcpy(pdu->cmd, cmd, slen); |
| 1530 | fio_net_send_cmd(client->fd, FIO_NET_CMD_VTRIGGER, pdu, |
| 1531 | sizeof(*pdu) + slen, NULL, NULL); |
| 1532 | free(pdu); |
| 1533 | } |
| 1534 | |
| 1535 | return 0; |
| 1536 | } |
| 1537 | |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1538 | static void request_client_etas(struct client_ops *ops) |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1539 | { |
| 1540 | struct fio_client *client; |
| 1541 | struct flist_head *entry; |
| 1542 | struct client_eta *eta; |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1543 | int skipped = 0; |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1544 | |
| 1545 | dprint(FD_NET, "client: request eta (%d)\n", nr_clients); |
| 1546 | |
Jens Axboe | 27b9155 | 2014-06-27 15:30:06 -0600 | [diff] [blame] | 1547 | eta = calloc(1, sizeof(*eta) + __THREAD_RUNSTR_SZ(REAL_MAX_JOBS)); |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1548 | eta->pending = nr_clients; |
| 1549 | |
| 1550 | flist_for_each(entry, &client_list) { |
| 1551 | client = flist_entry(entry, struct fio_client, list); |
| 1552 | |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1553 | if (!flist_empty(&client->eta_list)) { |
| 1554 | skipped++; |
| 1555 | continue; |
| 1556 | } |
Jens Axboe | 01be038 | 2011-10-15 14:43:41 +0200 | [diff] [blame] | 1557 | if (client->state != Client_running) |
| 1558 | continue; |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1559 | |
Jens Axboe | f77d267 | 2011-10-10 14:36:07 +0200 | [diff] [blame] | 1560 | assert(!client->eta_in_flight); |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1561 | flist_add_tail(&client->eta_list, &eta_list); |
Jens Axboe | f77d267 | 2011-10-10 14:36:07 +0200 | [diff] [blame] | 1562 | client->eta_in_flight = eta; |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1563 | fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA, |
Jens Axboe | df38093 | 2011-10-11 14:25:08 +0200 | [diff] [blame] | 1564 | (uintptr_t) eta, &client->cmd_list); |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1565 | } |
| 1566 | |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1567 | while (skipped--) |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1568 | fio_client_dec_jobs_eta(eta, ops->eta); |
Jens Axboe | 82c1ed3 | 2011-10-10 08:56:18 +0200 | [diff] [blame] | 1569 | |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1570 | dprint(FD_NET, "client: requested eta tag %p\n", eta); |
| 1571 | } |
| 1572 | |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1573 | static int client_check_cmd_timeout(struct fio_client *client, |
| 1574 | struct timeval *now) |
| 1575 | { |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1576 | struct fio_net_cmd_reply *reply; |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1577 | struct flist_head *entry, *tmp; |
| 1578 | int ret = 0; |
| 1579 | |
| 1580 | flist_for_each_safe(entry, tmp, &client->cmd_list) { |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1581 | reply = flist_entry(entry, struct fio_net_cmd_reply, list); |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1582 | |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1583 | if (mtime_since(&reply->tv, now) < FIO_NET_CLIENT_TIMEOUT) |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1584 | continue; |
| 1585 | |
| 1586 | log_err("fio: client %s, timeout on cmd %s\n", client->hostname, |
Jens Axboe | 40c6051 | 2012-03-27 16:03:04 +0200 | [diff] [blame] | 1587 | fio_server_op(reply->opcode)); |
| 1588 | flist_del(&reply->list); |
| 1589 | free(reply); |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1590 | ret = 1; |
| 1591 | } |
| 1592 | |
| 1593 | return flist_empty(&client->cmd_list) && ret; |
| 1594 | } |
| 1595 | |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1596 | static int fio_check_clients_timed_out(void) |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1597 | { |
| 1598 | struct fio_client *client; |
| 1599 | struct flist_head *entry, *tmp; |
| 1600 | struct timeval tv; |
| 1601 | int ret = 0; |
| 1602 | |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 1603 | fio_gettime(&tv, NULL); |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1604 | |
| 1605 | flist_for_each_safe(entry, tmp, &client_list) { |
| 1606 | client = flist_entry(entry, struct fio_client, list); |
| 1607 | |
| 1608 | if (flist_empty(&client->cmd_list)) |
| 1609 | continue; |
| 1610 | |
| 1611 | if (!client_check_cmd_timeout(client, &tv)) |
| 1612 | continue; |
| 1613 | |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1614 | if (client->ops->timed_out) |
| 1615 | client->ops->timed_out(client); |
Jens Axboe | ed727a4 | 2012-03-02 12:14:40 +0100 | [diff] [blame] | 1616 | else |
| 1617 | log_err("fio: client %s timed out\n", client->hostname); |
| 1618 | |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1619 | remove_client(client); |
| 1620 | ret = 1; |
| 1621 | } |
| 1622 | |
| 1623 | return ret; |
| 1624 | } |
| 1625 | |
Stephen M. Cameron | dd36672 | 2012-02-24 08:17:30 +0100 | [diff] [blame] | 1626 | int fio_handle_clients(struct client_ops *ops) |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1627 | { |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1628 | struct pollfd *pfds; |
Jens Axboe | 498c92c | 2011-10-17 09:14:42 +0200 | [diff] [blame] | 1629 | int i, ret = 0, retval = 0; |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1630 | |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 1631 | fio_gettime(&eta_tv, NULL); |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1632 | |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1633 | pfds = malloc(nr_clients * sizeof(struct pollfd)); |
| 1634 | |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 1635 | init_thread_stat(&client_ts); |
| 1636 | init_group_run_stat(&client_gs); |
| 1637 | |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1638 | while (!exit_backend && nr_clients) { |
Jens Axboe | c2cb686 | 2012-02-23 20:56:12 +0100 | [diff] [blame] | 1639 | struct flist_head *entry, *tmp; |
| 1640 | struct fio_client *client; |
| 1641 | |
Jens Axboe | 82a4be1 | 2011-10-01 12:40:32 -0600 | [diff] [blame] | 1642 | i = 0; |
Jens Axboe | c2cb686 | 2012-02-23 20:56:12 +0100 | [diff] [blame] | 1643 | flist_for_each_safe(entry, tmp, &client_list) { |
Jens Axboe | 82a4be1 | 2011-10-01 12:40:32 -0600 | [diff] [blame] | 1644 | client = flist_entry(entry, struct fio_client, list); |
| 1645 | |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1646 | if (!client->sent_job && !client->ops->stay_connected && |
Jens Axboe | c2cb686 | 2012-02-23 20:56:12 +0100 | [diff] [blame] | 1647 | flist_empty(&client->cmd_list)) { |
| 1648 | remove_client(client); |
| 1649 | continue; |
| 1650 | } |
| 1651 | |
Jens Axboe | 82a4be1 | 2011-10-01 12:40:32 -0600 | [diff] [blame] | 1652 | pfds[i].fd = client->fd; |
| 1653 | pfds[i].events = POLLIN; |
| 1654 | i++; |
| 1655 | } |
| 1656 | |
Jens Axboe | c2cb686 | 2012-02-23 20:56:12 +0100 | [diff] [blame] | 1657 | if (!nr_clients) |
| 1658 | break; |
| 1659 | |
Jens Axboe | 82a4be1 | 2011-10-01 12:40:32 -0600 | [diff] [blame] | 1660 | assert(i == nr_clients); |
| 1661 | |
Jens Axboe | 5c2857f | 2011-10-04 13:14:32 +0200 | [diff] [blame] | 1662 | do { |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1663 | struct timeval tv; |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 1664 | int timeout; |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1665 | |
Jens Axboe | 67bf982 | 2013-01-10 11:23:19 +0100 | [diff] [blame] | 1666 | fio_gettime(&tv, NULL); |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1667 | if (mtime_since(&eta_tv, &tv) >= 900) { |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1668 | request_client_etas(ops); |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1669 | memcpy(&eta_tv, &tv, sizeof(tv)); |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1670 | |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1671 | if (fio_check_clients_timed_out()) |
Jens Axboe | 89c1707 | 2011-10-11 10:15:51 +0200 | [diff] [blame] | 1672 | break; |
Jens Axboe | af9c9fb | 2011-10-09 21:54:10 +0200 | [diff] [blame] | 1673 | } |
| 1674 | |
Jens Axboe | de54cfd | 2014-11-10 20:34:00 -0700 | [diff] [blame] | 1675 | check_trigger_file(); |
| 1676 | |
| 1677 | timeout = min(100u, ops->eta_msec); |
| 1678 | |
| 1679 | ret = poll(pfds, nr_clients, timeout); |
Jens Axboe | 5c2857f | 2011-10-04 13:14:32 +0200 | [diff] [blame] | 1680 | if (ret < 0) { |
| 1681 | if (errno == EINTR) |
| 1682 | continue; |
| 1683 | log_err("fio: poll clients: %s\n", strerror(errno)); |
| 1684 | break; |
| 1685 | } else if (!ret) |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1686 | continue; |
Jens Axboe | 5c2857f | 2011-10-04 13:14:32 +0200 | [diff] [blame] | 1687 | } while (ret <= 0); |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1688 | |
| 1689 | for (i = 0; i < nr_clients; i++) { |
| 1690 | if (!(pfds[i].revents & POLLIN)) |
| 1691 | continue; |
| 1692 | |
| 1693 | client = find_client_by_fd(pfds[i].fd); |
| 1694 | if (!client) { |
Jens Axboe | 65e1a12 | 2013-08-30 10:13:36 -0600 | [diff] [blame] | 1695 | log_err("fio: unknown client fd %ld\n", (long) pfds[i].fd); |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1696 | continue; |
| 1697 | } |
Jens Axboe | a527661 | 2012-03-04 15:15:08 +0100 | [diff] [blame] | 1698 | if (!fio_handle_client(client)) { |
Jens Axboe | 28d3ab0 | 2011-10-05 20:45:37 +0200 | [diff] [blame] | 1699 | log_info("client: host=%s disconnected\n", |
| 1700 | client->hostname); |
| 1701 | remove_client(client); |
Jens Axboe | 498c92c | 2011-10-17 09:14:42 +0200 | [diff] [blame] | 1702 | retval = 1; |
Jens Axboe | 3899076 | 2011-10-17 13:31:33 +0200 | [diff] [blame] | 1703 | } else if (client->error) |
Jens Axboe | 498c92c | 2011-10-17 09:14:42 +0200 | [diff] [blame] | 1704 | retval = 1; |
Jens Axboe | 343cb4a | 2012-03-09 17:16:51 +0100 | [diff] [blame] | 1705 | fio_put_client(client); |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1706 | } |
| 1707 | } |
| 1708 | |
Castor Fu | 952b05e | 2013-10-31 11:00:34 -0600 | [diff] [blame] | 1709 | fio_client_json_fini(); |
| 1710 | |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1711 | free(pfds); |
Jens Axboe | 498c92c | 2011-10-17 09:14:42 +0200 | [diff] [blame] | 1712 | return retval; |
Jens Axboe | b66570d | 2011-10-01 11:11:35 -0600 | [diff] [blame] | 1713 | } |