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