From c28e8e8c68f7e908085f4585299e6e4d74d01837 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Tue, 4 Oct 2011 08:57:39 +0200 Subject: [PATCH] server: error handling and probe command Signed-off-by: Jens Axboe --- client.c | 3 --- server.c | 30 +++++++++++++++++++++--------- server.h | 18 ++++++++++++------ 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/client.c b/client.c index 89c2b442..0a93be0c 100644 --- a/client.c +++ b/client.c @@ -376,9 +376,6 @@ static int handle_client(struct fio_client *client) cmd->opcode); switch (cmd->opcode) { - case FIO_NET_CMD_ACK: - free(cmd); - break; case FIO_NET_CMD_QUIT: remove_client(client); free(cmd); diff --git a/server.c b/server.c index 74f5e6ad..938f58bb 100644 --- a/server.c +++ b/server.c @@ -271,6 +271,19 @@ static int handle_cur_job(struct fio_net_cmd *cmd) return ret; } +static int handle_probe_cmd(struct fio_net_cmd *cmd) +{ + struct cmd_probe_pdu probe; + + memset(&probe, 0, sizeof(probe)); + gethostname((char *) probe.hostname, sizeof(probe.hostname)); + probe.fio_major = 1; + probe.fio_minor = 58; + probe.fio_patch = 0; + + return fio_net_send_cmd(server_fd, FIO_NET_CMD_PROBE, &probe, sizeof(probe)); +} + static int handle_command(struct fio_net_cmd *cmd) { int ret; @@ -280,17 +293,16 @@ static int handle_command(struct fio_net_cmd *cmd) switch (cmd->opcode) { case FIO_NET_CMD_QUIT: fio_terminate_threads(TERMINATE_ALL); - return 1; + return -1; case FIO_NET_CMD_EXIT: exit_backend = 1; - return 1; - case FIO_NET_CMD_ACK: - return 0; - case FIO_NET_CMD_NAK: - return 1; + return -1; case FIO_NET_CMD_JOB: ret = handle_cur_job(cmd); break; + case FIO_NET_CMD_PROBE: + ret = handle_probe_cmd(cmd); + break; default: log_err("fio: unknown opcode: %d\n", cmd->opcode); ret = 1; @@ -308,7 +320,7 @@ static int handle_connection(int sk) while (!exit_backend) { cmd = fio_net_recv_cmd(sk); if (!cmd) { - ret = 1; + ret = -1; break; } @@ -407,7 +419,7 @@ static int fio_server(void) #ifdef SO_REUSEPORT if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &opt, sizeof(opt)) < 0) { log_err("fio: setsockopt: %s\n", strerror(errno)); - return 1; + return -1; } #endif @@ -615,7 +627,7 @@ int fio_start_server(int daemonize) pid = fork(); if (pid < 0) { syslog(LOG_ERR, "failed server fork"); - return 1; + return -1; } else if (pid) exit(0); diff --git a/server.h b/server.h index 61b61f35..4783238b 100644 --- a/server.h +++ b/server.h @@ -34,12 +34,11 @@ enum { FIO_NET_CMD_QUIT = 1, FIO_NET_CMD_EXIT = 2, FIO_NET_CMD_JOB = 3, - FIO_NET_CMD_ACK = 4, - FIO_NET_CMD_NAK = 5, - FIO_NET_CMD_TEXT = 6, - FIO_NET_CMD_TS = 7, - FIO_NET_CMD_GS = 8, - FIO_NET_CMD_ETA = 9, + FIO_NET_CMD_TEXT = 4, + FIO_NET_CMD_TS = 5, + FIO_NET_CMD_GS = 6, + FIO_NET_CMD_ETA = 7, + FIO_NET_CMD_PROBE = 8, FIO_NET_CMD_F_MORE = 1UL << 0, @@ -53,6 +52,13 @@ struct cmd_ts_pdu { struct group_run_stats rs; }; +struct cmd_probe_pdu { + uint8_t hostname[64]; + uint8_t fio_major; + uint8_t fio_minor; + uint8_t fio_patch; +}; + extern int fio_start_server(int); extern int fio_server_text_output(const char *, unsigned int len); extern int fio_server_log(const char *format, ...); -- 2.25.1