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