From 46bcd498f7b3fb55f7f048bf299f36bd8c8f7db1 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Wed, 14 Mar 2012 11:31:21 +0100 Subject: [PATCH] client/server: pass type of client to the backend Signed-off-by: Jens Axboe --- client.c | 20 ++++++++++++++++---- client.h | 7 +++++++ fio.h | 8 +++++--- gfio.c | 1 + init.c | 27 +++++++++++++++------------ profile.c | 2 +- server.c | 17 ++++++++++++----- server.h | 9 ++++++++- 8 files changed, 65 insertions(+), 26 deletions(-) diff --git a/client.c b/client.c index 84f13aa1..6371c2be 100644 --- a/client.c +++ b/client.c @@ -39,6 +39,7 @@ struct client_ops fio_client_ops = { .eta = display_thread_status, .probe = handle_probe, .eta_msec = FIO_CLIENT_DEF_ETA_MSEC, + .client_type = FIO_CLIENT_TYPE_CLI, }; static struct timeval eta_tv; @@ -206,6 +207,7 @@ struct fio_client *fio_client_add_explicit(struct client_ops *ops, client->fd = -1; client->ops = ops; client->refs = 1; + client->type = ops->client_type; __fio_client_add_cmd_option(client, "fio"); @@ -255,6 +257,7 @@ int fio_client_add(struct client_ops *ops, const char *hostname, void **cookie) client->fd = -1; client->ops = ops; client->refs = 1; + client->type = ops->client_type; __fio_client_add_cmd_option(client, "fio"); @@ -448,6 +451,7 @@ static int send_client_cmd_line(struct fio_client *client) free(lens); clp->lines = cpu_to_le16(client->argc); + clp->client_type = __cpu_to_le16(client->type); ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, 0); free(pdu); return ret; @@ -517,8 +521,11 @@ int fio_start_all_clients(void) */ static int __fio_client_send_ini(struct fio_client *client, const char *filename) { + struct cmd_job_pdu *pdu; + size_t p_size; struct stat sb; - char *p, *buf; + char *p; + void *buf; off_t len; int fd, ret; @@ -540,7 +547,9 @@ static int __fio_client_send_ini(struct fio_client *client, const char *filename return ret; } - buf = malloc(sb.st_size); + p_size = sb.st_size + sizeof(*pdu); + pdu = malloc(p_size); + buf = pdu->buf; len = sb.st_size; p = buf; @@ -565,9 +574,12 @@ static int __fio_client_send_ini(struct fio_client *client, const char *filename return 1; } + pdu->buf_len = __cpu_to_le32(sb.st_size); + pdu->client_type = cpu_to_le32(client->type); + client->sent_job = 1; - ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size, 0); - free(buf); + ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, pdu, p_size, 0); + free(pdu); close(fd); return ret; } diff --git a/client.h b/client.h index 41a2a2dd..5b9c2770 100644 --- a/client.h +++ b/client.h @@ -45,6 +45,7 @@ struct fio_client { int error; int ipv6; int sent_job; + uint32_t type; struct flist_head eta_list; struct client_eta *eta_in_flight; @@ -80,6 +81,7 @@ struct client_ops { unsigned int eta_msec; int stay_connected; + uint32_t client_type; }; extern struct client_ops fio_client_ops; @@ -116,5 +118,10 @@ extern void fio_put_client(struct fio_client *); #define FIO_CLIENT_DEF_ETA_MSEC 900 +enum { + FIO_CLIENT_TYPE_CLI = 1, + FIO_CLIENT_TYPE_GUI = 2, +}; + #endif diff --git a/fio.h b/fio.h index cafc93ae..db0e8756 100644 --- a/fio.h +++ b/fio.h @@ -70,6 +70,8 @@ struct thread_data { int groupid; struct thread_stat ts; + int client_type; + struct io_log *slat_log; struct io_log *clat_log; struct io_log *lat_log; @@ -379,8 +381,8 @@ static inline int should_fsync(struct thread_data *td) */ extern int __must_check fio_init_options(void); extern int __must_check parse_options(int, char **); -extern int parse_jobs_ini(char *, int, int); -extern int parse_cmd_line(int, char **); +extern int parse_jobs_ini(char *, int, int, int); +extern int parse_cmd_line(int, char **, int); extern int fio_backend(void); extern void reset_fio_state(void); extern void clear_io_state(struct thread_data *); @@ -395,7 +397,7 @@ extern void fio_options_dup_and_init(struct option *); extern void fio_options_mem_dupe(struct thread_data *); extern void options_mem_dupe(void *data, struct fio_option *options); extern void td_fill_rand_seeds(struct thread_data *); -extern void add_job_opts(const char **); +extern void add_job_opts(const char **, int); extern char *num2str(unsigned long, int, int, int); extern int ioengine_load(struct thread_data *); diff --git a/gfio.c b/gfio.c index 1a96a1ae..73aeb276 100644 --- a/gfio.c +++ b/gfio.c @@ -1652,6 +1652,7 @@ struct client_ops gfio_client_ops = { .job_start = gfio_client_job_start, .eta_msec = FIO_CLIENT_DEF_ETA_MSEC, .stay_connected = 1, + .client_type = FIO_CLIENT_TYPE_GUI, }; /* diff --git a/init.c b/init.c index 3041ac45..61b3d4b1 100644 --- a/init.c +++ b/init.c @@ -745,7 +745,7 @@ int ioengine_load(struct thread_data *td) * members of td. */ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, - int recursed) + int recursed, int client_type) { unsigned int i; char fname[PATH_MAX]; @@ -765,6 +765,8 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, return 0; } + td->client_type = client_type; + if (profile_td_init(td)) goto err; @@ -915,7 +917,7 @@ static int add_job(struct thread_data *td, const char *jobname, int job_add_num, job_add_num = numjobs - 1; - if (add_job(td_new, jobname, job_add_num, 1)) + if (add_job(td_new, jobname, job_add_num, 1, client_type)) goto err; } @@ -928,7 +930,7 @@ err: /* * Parse as if 'o' was a command line */ -void add_job_opts(const char **o) +void add_job_opts(const char **o, int client_type) { struct thread_data *td, *td_parent; int i, in_global = 1; @@ -940,7 +942,7 @@ void add_job_opts(const char **o) if (!strncmp(o[i], "name", 4)) { in_global = 0; if (td) - add_job(td, jobname, 0, 0); + add_job(td, jobname, 0, 0, client_type); td = NULL; sprintf(jobname, "%s", o[i] + 5); } @@ -959,7 +961,7 @@ void add_job_opts(const char **o) } if (td) - add_job(td, jobname, 0, 0); + add_job(td, jobname, 0, 0, client_type); } static int skip_this_section(const char *name) @@ -997,7 +999,7 @@ static int is_empty_or_comment(char *line) /* * This is our [ini] type file parser. */ -int parse_jobs_ini(char *file, int is_buf, int stonewall_flag) +int parse_jobs_ini(char *file, int is_buf, int stonewall_flag, int type) { unsigned int global; struct thread_data *td; @@ -1141,7 +1143,7 @@ int parse_jobs_ini(char *file, int is_buf, int stonewall_flag) for (i = 0; i < num_opts; i++) log_info("--%s ", opts[i]); - ret = add_job(td, name, 0, 0); + ret = add_job(td, name, 0, 0, type); } else { log_err("fio: job %s dropped\n", name); put_job(td); @@ -1388,7 +1390,7 @@ void parse_cmd_client(void *client, char *opt) fio_client_add_cmd_option(client, opt); } -int parse_cmd_line(int argc, char *argv[]) +int parse_cmd_line(int argc, char *argv[], int client_type) { struct thread_data *td = NULL; int c, ini_idx = 0, lidx, ret = 0, do_exit = 0, exit_val = 0; @@ -1507,7 +1509,7 @@ int parse_cmd_line(int argc, char *argv[]) char *val = optarg; if (!strncmp(opt, "name", 4) && td) { - ret = add_job(td, td->o.name ?: "fio", 0, 0); + ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type); if (ret) return 0; td = NULL; @@ -1611,7 +1613,7 @@ int parse_cmd_line(int argc, char *argv[]) if (td) { if (!ret) - ret = add_job(td, td->o.name ?: "fio", 0, 0); + ret = add_job(td, td->o.name ?: "fio", 0, 0, client_type); } while (!ret && optind < argc) { @@ -1644,6 +1646,7 @@ extern int fio_check_options(struct thread_options *); int parse_options(int argc, char *argv[]) { + const int type = FIO_CLIENT_TYPE_CLI; int job_files, i; if (fio_init_options()) @@ -1651,7 +1654,7 @@ int parse_options(int argc, char *argv[]) if (fio_test_cconv(&def_thread.o)) log_err("fio: failed internal cconv test\n"); - job_files = parse_cmd_line(argc, argv); + job_files = parse_cmd_line(argc, argv, type); if (job_files > 0) { for (i = 0; i < job_files; i++) { @@ -1662,7 +1665,7 @@ int parse_options(int argc, char *argv[]) return 1; free(ini_file[i]); } else if (!is_backend) { - if (parse_jobs_ini(ini_file[i], 0, i)) + if (parse_jobs_ini(ini_file[i], 0, i, type)) return 1; free(ini_file[i]); } diff --git a/profile.c b/profile.c index 855dde3e..c9758437 100644 --- a/profile.c +++ b/profile.c @@ -31,7 +31,7 @@ int load_profile(const char *profile) ops = find_profile(profile); if (ops) { ops->prep_cmd(); - add_job_opts(ops->cmdline); + add_job_opts(ops->cmdline, FIO_CLIENT_TYPE_CLI); return 0; } diff --git a/server.c b/server.c index 25b15a5d..89422e96 100644 --- a/server.c +++ b/server.c @@ -233,9 +233,11 @@ struct fio_net_cmd *fio_net_recv_cmd(int sk) buf[pdu->buf_len ] = '\0'; } else if (cmdret->opcode == FIO_NET_CMD_JOB) { - char *buf = (char *) cmdret->payload; + struct cmd_job_pdu *pdu = (struct cmd_job_pdu *) cmdret->payload; + char *buf = (char *) pdu->buf; + int len = le32_to_cpu(pdu->buf_len); - buf[cmdret->pdu_len ] = '\0'; + buf[len] = '\0'; } } @@ -361,10 +363,14 @@ static int handle_run_cmd(struct fio_net_cmd *cmd) static int handle_job_cmd(struct fio_net_cmd *cmd) { - char *buf = (char *) cmd->payload; + struct cmd_job_pdu *pdu = (struct cmd_job_pdu *) cmd->payload; + void *buf = pdu->buf; struct cmd_start_pdu spdu; - if (parse_jobs_ini(buf, 1, 0)) { + pdu->buf_len = le32_to_cpu(pdu->buf_len); + pdu->client_type = le32_to_cpu(pdu->client_type); + + if (parse_jobs_ini(buf, 1, 0, pdu->client_type)) { fio_server_send_quit_cmd(); return -1; } @@ -386,6 +392,7 @@ static int handle_jobline_cmd(struct fio_net_cmd *cmd) clp = pdu; clp->lines = le16_to_cpu(clp->lines); + clp->client_type = le16_to_cpu(clp->client_type); argv = malloc(clp->lines * sizeof(char *)); offset = sizeof(*clp); @@ -399,7 +406,7 @@ static int handle_jobline_cmd(struct fio_net_cmd *cmd) dprint(FD_NET, "server: %d: %s\n", i, argv[i]); } - if (parse_cmd_line(clp->lines, argv)) { + if (parse_cmd_line(clp->lines, argv, clp->client_type)) { fio_server_send_quit_cmd(); free(argv); return -1; diff --git a/server.h b/server.h index 7a801bf0..2235f3a5 100644 --- a/server.h +++ b/server.h @@ -38,7 +38,7 @@ struct fio_net_int_cmd { }; enum { - FIO_SERVER_VER = 10, + FIO_SERVER_VER = 11, FIO_SERVER_MAX_FRAGMENT_PDU = 1024, @@ -97,9 +97,16 @@ struct cmd_single_line_pdu { struct cmd_line_pdu { uint16_t lines; + uint16_t client_type; struct cmd_single_line_pdu options[0]; }; +struct cmd_job_pdu { + uint32_t buf_len; + uint32_t client_type; + uint8_t buf[0]; +}; + struct cmd_start_pdu { uint32_t jobs; }; -- 2.25.1