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