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