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