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