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