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