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