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