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