Lines Matching refs:client

28 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd);
29 static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd);
30 static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd);
31 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd);
32 static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd);
33 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd);
34 static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd);
72 static void fio_client_add_hash(struct fio_client *client) in fio_client_add_hash() argument
74 int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS); in fio_client_add_hash()
77 flist_add(&client->hash_list, &client_hash[bucket]); in fio_client_add_hash()
80 static void fio_client_remove_hash(struct fio_client *client) in fio_client_remove_hash() argument
82 if (!flist_empty(&client->hash_list)) in fio_client_remove_hash()
83 flist_del_init(&client->hash_list); in fio_client_remove_hash()
145 struct fio_client *client; in find_client_by_fd() local
149 client = flist_entry(entry, struct fio_client, hash_list); in find_client_by_fd()
151 if (client->fd == fd) { in find_client_by_fd()
152 client->refs++; in find_client_by_fd()
153 return client; in find_client_by_fd()
160 void fio_put_client(struct fio_client *client) in fio_put_client() argument
162 if (--client->refs) in fio_put_client()
165 free(client->hostname); in fio_put_client()
166 if (client->argv) in fio_put_client()
167 free(client->argv); in fio_put_client()
168 if (client->name) in fio_put_client()
169 free(client->name); in fio_put_client()
170 while (client->nr_files) { in fio_put_client()
171 struct client_file *cf = &client->files[--client->nr_files]; in fio_put_client()
175 if (client->files) in fio_put_client()
176 free(client->files); in fio_put_client()
178 if (!client->did_stat) in fio_put_client()
181 if (client->error) in fio_put_client()
184 free(client); in fio_put_client()
187 static void remove_client(struct fio_client *client) in remove_client() argument
189 assert(client->refs); in remove_client()
191 dprint(FD_NET, "client: removed <%s>\n", client->hostname); in remove_client()
193 if (!flist_empty(&client->list)) in remove_client()
194 flist_del_init(&client->list); in remove_client()
196 fio_client_remove_hash(client); in remove_client()
198 if (!flist_empty(&client->eta_list)) { in remove_client()
199 flist_del_init(&client->eta_list); in remove_client()
200 fio_client_dec_jobs_eta(client->eta_in_flight, client->ops->eta); in remove_client()
203 close(client->fd); in remove_client()
204 client->fd = -1; in remove_client()
206 if (client->ops->removed) in remove_client()
207 client->ops->removed(client); in remove_client()
210 fio_put_client(client); in remove_client()
213 struct fio_client *fio_get_client(struct fio_client *client) in fio_get_client() argument
215 client->refs++; in fio_get_client()
216 return client; in fio_get_client()
219 static void __fio_client_add_cmd_option(struct fio_client *client, in __fio_client_add_cmd_option() argument
224 index = client->argc++; in __fio_client_add_cmd_option()
225 client->argv = realloc(client->argv, sizeof(char *) * client->argc); in __fio_client_add_cmd_option()
226 client->argv[index] = strdup(opt); in __fio_client_add_cmd_option()
232 struct fio_client *client = cookie; in fio_client_add_cmd_option() local
235 if (!client || !opt) in fio_client_add_cmd_option()
238 __fio_client_add_cmd_option(client, opt); in fio_client_add_cmd_option()
244 client = flist_entry(entry, struct fio_client, arg_list); in fio_client_add_cmd_option()
246 __fio_client_add_cmd_option(client, opt); in fio_client_add_cmd_option()
254 struct fio_client *client; in fio_client_add_explicit() local
256 client = malloc(sizeof(*client)); in fio_client_add_explicit()
257 memset(client, 0, sizeof(*client)); in fio_client_add_explicit()
259 INIT_FLIST_HEAD(&client->list); in fio_client_add_explicit()
260 INIT_FLIST_HEAD(&client->hash_list); in fio_client_add_explicit()
261 INIT_FLIST_HEAD(&client->arg_list); in fio_client_add_explicit()
262 INIT_FLIST_HEAD(&client->eta_list); in fio_client_add_explicit()
263 INIT_FLIST_HEAD(&client->cmd_list); in fio_client_add_explicit()
265 client->hostname = strdup(hostname); in fio_client_add_explicit()
268 client->is_sock = 1; in fio_client_add_explicit()
274 &client->addr.sin_addr, in fio_client_add_explicit()
275 &client->addr6.sin6_addr)) in fio_client_add_explicit()
278 client->port = port; in fio_client_add_explicit()
281 client->fd = -1; in fio_client_add_explicit()
282 client->ops = ops; in fio_client_add_explicit()
283 client->refs = 1; in fio_client_add_explicit()
284 client->type = ops->client_type; in fio_client_add_explicit()
286 __fio_client_add_cmd_option(client, "fio"); in fio_client_add_explicit()
288 flist_add(&client->list, &client_list); in fio_client_add_explicit()
290 dprint(FD_NET, "client: added <%s>\n", client->hostname); in fio_client_add_explicit()
291 return client; in fio_client_add_explicit()
293 free(client); in fio_client_add_explicit()
299 struct fio_client *client = cookie; in fio_client_add_ini_file() local
304 if (!client) in fio_client_add_ini_file()
307 dprint(FD_NET, "client <%s>: add ini %s\n", client->hostname, ini_file); in fio_client_add_ini_file()
309 new_size = (client->nr_files + 1) * sizeof(struct client_file); in fio_client_add_ini_file()
310 new_files = realloc(client->files, new_size); in fio_client_add_ini_file()
314 client->files = new_files; in fio_client_add_ini_file()
315 cf = &client->files[client->nr_files]; in fio_client_add_ini_file()
318 client->nr_files++; in fio_client_add_ini_file()
325 struct fio_client *client; in fio_client_add() local
340 client = malloc(sizeof(*client)); in fio_client_add()
341 memset(client, 0, sizeof(*client)); in fio_client_add()
343 INIT_FLIST_HEAD(&client->list); in fio_client_add()
344 INIT_FLIST_HEAD(&client->hash_list); in fio_client_add()
345 INIT_FLIST_HEAD(&client->arg_list); in fio_client_add()
346 INIT_FLIST_HEAD(&client->eta_list); in fio_client_add()
347 INIT_FLIST_HEAD(&client->cmd_list); in fio_client_add()
349 if (fio_server_parse_string(hostname, &client->hostname, in fio_client_add()
350 &client->is_sock, &client->port, in fio_client_add()
351 &client->addr.sin_addr, in fio_client_add()
352 &client->addr6.sin6_addr, in fio_client_add()
353 &client->ipv6)) in fio_client_add()
356 client->fd = -1; in fio_client_add()
357 client->ops = ops; in fio_client_add()
358 client->refs = 1; in fio_client_add()
359 client->type = ops->client_type; in fio_client_add()
361 __fio_client_add_cmd_option(client, "fio"); in fio_client_add()
363 flist_add(&client->list, &client_list); in fio_client_add()
365 dprint(FD_NET, "client: added <%s>\n", client->hostname); in fio_client_add()
366 *cookie = client; in fio_client_add()
370 static const char *server_name(struct fio_client *client, char *buf, in server_name() argument
375 if (client->ipv6) in server_name()
376 from = inet_ntop(AF_INET6, (struct sockaddr *) &client->addr6.sin6_addr, buf, bufsize); in server_name()
377 else if (client->is_sock) in server_name()
380 from = inet_ntop(AF_INET, (struct sockaddr *) &client->addr.sin_addr, buf, bufsize); in server_name()
385 static void probe_client(struct fio_client *client) in probe_client() argument
400 sname = server_name(client, buf, sizeof(buf)); in probe_client()
404 fio_net_send_cmd(client->fd, FIO_NET_CMD_PROBE, &pdu, sizeof(pdu), &tag, &client->cmd_list); in probe_client()
407 static int fio_client_connect_ip(struct fio_client *client) in fio_client_connect_ip() argument
413 if (client->ipv6) { in fio_client_connect_ip()
414 client->addr6.sin6_family = AF_INET6; in fio_client_connect_ip()
415 client->addr6.sin6_port = htons(client->port); in fio_client_connect_ip()
417 addr = (struct sockaddr *) &client->addr6; in fio_client_connect_ip()
418 socklen = sizeof(client->addr6); in fio_client_connect_ip()
420 client->addr.sin_family = AF_INET; in fio_client_connect_ip()
421 client->addr.sin_port = htons(client->port); in fio_client_connect_ip()
423 addr = (struct sockaddr *) &client->addr; in fio_client_connect_ip()
424 socklen = sizeof(client->addr); in fio_client_connect_ip()
439 log_err("fio: failed to connect to %s:%u\n", client->hostname, in fio_client_connect_ip()
440 client->port); in fio_client_connect_ip()
448 static int fio_client_connect_sock(struct fio_client *client) in fio_client_connect_sock() argument
450 struct sockaddr_un *addr = &client->addr_un; in fio_client_connect_sock()
456 strncpy(addr->sun_path, client->hostname, sizeof(addr->sun_path) - 1); in fio_client_connect_sock()
478 int fio_client_connect(struct fio_client *client) in fio_client_connect() argument
482 dprint(FD_NET, "client: connect to host %s\n", client->hostname); in fio_client_connect()
484 if (client->is_sock) in fio_client_connect()
485 fd = fio_client_connect_sock(client); in fio_client_connect()
487 fd = fio_client_connect_ip(client); in fio_client_connect()
489 dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd); in fio_client_connect()
494 client->fd = fd; in fio_client_connect()
495 fio_client_add_hash(client); in fio_client_connect()
496 client->state = Client_connected; in fio_client_connect()
498 probe_client(client); in fio_client_connect()
502 int fio_client_terminate(struct fio_client *client) in fio_client_terminate() argument
504 return fio_net_send_quit(client->fd); in fio_client_terminate()
510 struct fio_client *client; in fio_clients_terminate() local
515 client = flist_entry(entry, struct fio_client, list); in fio_clients_terminate()
516 fio_client_terminate(client); in fio_clients_terminate()
559 static int send_client_cmd_line(struct fio_client *client) in send_client_cmd_line() argument
569 dprint(FD_NET, "client: send cmdline %d\n", client->argc); in send_client_cmd_line()
571 lens = malloc(client->argc * sizeof(unsigned int)); in send_client_cmd_line()
576 for (i = 0, mem = 0; i < client->argc; i++) { in send_client_cmd_line()
577 lens[i] = strlen(client->argv[i]) + 1; in send_client_cmd_line()
584 mem += sizeof(*clp) + (client->argc * sizeof(*cslp)); in send_client_cmd_line()
590 for (i = 0; i < client->argc; i++) { in send_client_cmd_line()
594 strcpy((char *) cslp->text, client->argv[i]); in send_client_cmd_line()
600 clp->lines = cpu_to_le16(client->argc); in send_client_cmd_line()
601 clp->client_type = __cpu_to_le16(client->type); in send_client_cmd_line()
602 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, NULL, NULL); in send_client_cmd_line()
609 struct fio_client *client; in fio_clients_connect() local
623 client = flist_entry(entry, struct fio_client, list); in fio_clients_connect()
625 ret = fio_client_connect(client); in fio_clients_connect()
627 remove_client(client); in fio_clients_connect()
631 if (client->argc > 1) in fio_clients_connect()
632 send_client_cmd_line(client); in fio_clients_connect()
638 int fio_start_client(struct fio_client *client) in fio_start_client() argument
640 dprint(FD_NET, "client: start %s\n", client->hostname); in fio_start_client()
641 return fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_RUN, 0, NULL); in fio_start_client()
646 struct fio_client *client; in fio_start_all_clients() local
655 client = flist_entry(entry, struct fio_client, list); in fio_start_all_clients()
657 ret = fio_start_client(client); in fio_start_all_clients()
659 remove_client(client); in fio_start_all_clients()
667 static int __fio_client_send_remote_ini(struct fio_client *client, in __fio_client_send_remote_ini() argument
674 dprint(FD_NET, "send remote ini %s to %s\n", filename, client->hostname); in __fio_client_send_remote_ini()
681 pdu->client_type = cpu_to_le16((uint16_t) client->type); in __fio_client_send_remote_ini()
683 client->sent_job = 1; in __fio_client_send_remote_ini()
684 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_LOAD_FILE, pdu, p_size,NULL, NULL); in __fio_client_send_remote_ini()
693 static int __fio_client_send_local_ini(struct fio_client *client, in __fio_client_send_local_ini() argument
704 dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname); in __fio_client_send_local_ini()
734 pdu->client_type = cpu_to_le32(client->type); in __fio_client_send_local_ini()
736 client->sent_job = 1; in __fio_client_send_local_ini()
737 ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, pdu, p_size, NULL, NULL); in __fio_client_send_local_ini()
743 int fio_client_send_ini(struct fio_client *client, const char *filename, in fio_client_send_ini() argument
749 ret = __fio_client_send_local_ini(client, filename); in fio_client_send_ini()
751 ret = __fio_client_send_remote_ini(client, filename); in fio_client_send_ini()
754 client->sent_job = 1; in fio_client_send_ini()
759 static int fio_client_send_cf(struct fio_client *client, in fio_client_send_cf() argument
762 return fio_client_send_ini(client, cf->file, cf->remote); in fio_client_send_cf()
767 struct fio_client *client; in fio_clients_send_ini() local
771 client = flist_entry(entry, struct fio_client, list); in fio_clients_send_ini()
773 if (client->nr_files) { in fio_clients_send_ini()
776 for (i = 0; i < client->nr_files; i++) { in fio_clients_send_ini()
779 cf = &client->files[i]; in fio_clients_send_ini()
781 if (fio_client_send_cf(client, cf)) { in fio_clients_send_ini()
782 remove_client(client); in fio_clients_send_ini()
787 if (client->sent_job) in fio_clients_send_ini()
789 if (!filename || fio_client_send_ini(client, filename, 0)) in fio_clients_send_ini()
790 remove_client(client); in fio_clients_send_ini()
796 int fio_client_update_options(struct fio_client *client, in fio_client_update_options() argument
801 pdu.thread_number = cpu_to_le32(client->thread_number); in fio_client_update_options()
802 pdu.groupid = cpu_to_le32(client->groupid); in fio_client_update_options()
805 …return fio_net_send_cmd(client->fd, FIO_NET_CMD_UPDATE_JOB, &pdu, sizeof(pdu), tag, &client->cmd_l… in fio_client_update_options()
916 struct fio_client *client) in json_object_add_client_info() argument
918 const char *hostname = client->hostname ? client->hostname : ""; in json_object_add_client_info()
921 json_object_add_value_int(obj, "port", client->port); in json_object_add_client_info()
924 static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd) in handle_ts() argument
930 client->did_stat = 1; in handle_ts()
932 json_object_add_client_info(tsobj, client); in handle_ts()
951 json_object_add_client_info(tsobj, client); in handle_ts()
957 static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd) in handle_gs() argument
964 static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd) in handle_text() argument
971 name = client->name ? client->name : client->hostname; in handle_text()
973 if (!client->skip_newline) in handle_text()
977 client->skip_newline = strchr(buf, '\n') == NULL; in handle_text()
1013 static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd) in handle_du() argument
1017 if (!client->disk_stats_shown) { in handle_du()
1018 client->disk_stats_shown = 1; in handle_du()
1026 json_object_add_client_info(duobj, client); in handle_du()
1098 static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd) in remove_reply_cmd() argument
1103 flist_for_each(entry, &client->cmd_list) { in remove_reply_cmd()
1122 int fio_client_wait_for_reply(struct fio_client *client, uint64_t tag) in fio_client_wait_for_reply() argument
1128 flist_for_each(entry, &client->cmd_list) { in fio_client_wait_for_reply()
1146 static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd) in handle_eta() argument
1153 assert(client->eta_in_flight == eta); in handle_eta()
1155 client->eta_in_flight = NULL; in handle_eta()
1156 flist_del_init(&client->eta_list); in handle_eta()
1158 if (client->ops->jobs_eta) in handle_eta()
1159 client->ops->jobs_eta(client, je); in handle_eta()
1162 fio_client_dec_jobs_eta(eta, client->ops->eta); in handle_eta()
1165 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd) in handle_probe() argument
1186 if (!client->name) in handle_probe()
1187 client->name = strdup((char *) probe->hostname); in handle_probe()
1190 static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd) in handle_start() argument
1194 client->state = Client_started; in handle_start()
1195 client->jobs = le32_to_cpu(pdu->jobs); in handle_start()
1196 client->nr_stat = le32_to_cpu(pdu->stat_outputs); in handle_start()
1198 sum_stat_clients += client->nr_stat; in handle_start()
1201 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd) in handle_stop() argument
1203 if (client->error) in handle_stop()
1204 log_info("client <%s>: exited with error %d\n", client->hostname, client->error); in handle_stop()
1351 static int send_file(struct fio_client *client, struct cmd_sendfile *pdu, in send_file() argument
1365 sendfile_reply(client->fd, rep, size, tag); in send_file()
1379 sendfile_reply(client->fd, rep, size, tag); in send_file()
1385 int fio_handle_client(struct fio_client *client) in fio_handle_client() argument
1387 struct client_ops *ops = client->ops; in fio_handle_client()
1390 dprint(FD_NET, "client: handle %s\n", client->hostname); in fio_handle_client()
1392 cmd = fio_net_recv_cmd(client->fd); in fio_handle_client()
1397 fio_server_op(cmd->opcode), client->hostname, cmd->pdu_len); in fio_handle_client()
1402 ops->quit(client, cmd); in fio_handle_client()
1403 remove_client(client); in fio_handle_client()
1407 ops->text(client, cmd); in fio_handle_client()
1415 ops->disk_util(client, cmd); in fio_handle_client()
1424 ops->thread_status(client, cmd); in fio_handle_client()
1432 ops->group_stats(client, cmd); in fio_handle_client()
1438 remove_reply_cmd(client, cmd); in fio_handle_client()
1440 handle_eta(client, cmd); in fio_handle_client()
1444 remove_reply_cmd(client, cmd); in fio_handle_client()
1445 ops->probe(client, cmd); in fio_handle_client()
1448 client->state = Client_running; in fio_handle_client()
1450 ops->job_start(client, cmd); in fio_handle_client()
1456 ops->start(client, cmd); in fio_handle_client()
1463 client->state = Client_stopped; in fio_handle_client()
1464 client->error = le32_to_cpu(pdu->error); in fio_handle_client()
1465 client->signal = le32_to_cpu(pdu->signal); in fio_handle_client()
1466 ops->stop(client, cmd); in fio_handle_client()
1472 client->thread_number = le32_to_cpu(pdu->thread_number); in fio_handle_client()
1473 client->groupid = le32_to_cpu(pdu->groupid); in fio_handle_client()
1476 ops->add_job(client, cmd); in fio_handle_client()
1484 ops->iolog(client, pdu); in fio_handle_client()
1488 ops->update_job(client, cmd); in fio_handle_client()
1489 remove_reply_cmd(client, cmd); in fio_handle_client()
1495 __verify_save_state(pdu, server_name(client, buf, sizeof(buf))); in fio_handle_client()
1501 send_file(client, pdu, cmd->tag); in fio_handle_client()
1516 struct fio_client *client; in fio_clients_send_trigger() local
1529 client = flist_entry(entry, struct fio_client, list); in fio_clients_send_trigger()
1535 fio_net_send_cmd(client->fd, FIO_NET_CMD_VTRIGGER, pdu, in fio_clients_send_trigger()
1545 struct fio_client *client; in request_client_etas() local
1556 client = flist_entry(entry, struct fio_client, list); in request_client_etas()
1558 if (!flist_empty(&client->eta_list)) { in request_client_etas()
1562 if (client->state != Client_running) in request_client_etas()
1565 assert(!client->eta_in_flight); in request_client_etas()
1566 flist_add_tail(&client->eta_list, &eta_list); in request_client_etas()
1567 client->eta_in_flight = eta; in request_client_etas()
1568 fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_SEND_ETA, in request_client_etas()
1569 (uintptr_t) eta, &client->cmd_list); in request_client_etas()
1578 static int client_check_cmd_timeout(struct fio_client *client, in client_check_cmd_timeout() argument
1585 flist_for_each_safe(entry, tmp, &client->cmd_list) { in client_check_cmd_timeout()
1591 log_err("fio: client %s, timeout on cmd %s\n", client->hostname, in client_check_cmd_timeout()
1598 return flist_empty(&client->cmd_list) && ret; in client_check_cmd_timeout()
1603 struct fio_client *client; in fio_check_clients_timed_out() local
1611 client = flist_entry(entry, struct fio_client, list); in fio_check_clients_timed_out()
1613 if (flist_empty(&client->cmd_list)) in fio_check_clients_timed_out()
1616 if (!client_check_cmd_timeout(client, &tv)) in fio_check_clients_timed_out()
1619 if (client->ops->timed_out) in fio_check_clients_timed_out()
1620 client->ops->timed_out(client); in fio_check_clients_timed_out()
1622 log_err("fio: client %s timed out\n", client->hostname); in fio_check_clients_timed_out()
1624 client->error = ETIMEDOUT; in fio_check_clients_timed_out()
1625 remove_client(client); in fio_check_clients_timed_out()
1646 struct fio_client *client; in fio_handle_clients() local
1650 client = flist_entry(entry, struct fio_client, list); in fio_handle_clients()
1652 if (!client->sent_job && !client->ops->stay_connected && in fio_handle_clients()
1653 flist_empty(&client->cmd_list)) { in fio_handle_clients()
1654 remove_client(client); in fio_handle_clients()
1658 pfds[i].fd = client->fd; in fio_handle_clients()
1699 client = find_client_by_fd(pfds[i].fd); in fio_handle_clients()
1700 if (!client) { in fio_handle_clients()
1704 if (!fio_handle_client(client)) { in fio_handle_clients()
1706 client->hostname); in fio_handle_clients()
1707 remove_client(client); in fio_handle_clients()
1709 } else if (client->error) in fio_handle_clients()
1711 fio_put_client(client); in fio_handle_clients()