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