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