server: error handling and probe command
Signed-off-by: Jens Axboe <axboe@kernel.dk>
diff --git a/server.c b/server.c
index 74f5e6a..938f58b 100644
--- a/server.c
+++ b/server.c
@@ -271,6 +271,19 @@
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 @@
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 @@
while (!exit_backend) {
cmd = fio_net_recv_cmd(sk);
if (!cmd) {
- ret = 1;
+ ret = -1;
break;
}
@@ -407,7 +419,7 @@
#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 @@
pid = fork();
if (pid < 0) {
syslog(LOG_ERR, "failed server fork");
- return 1;
+ return -1;
} else if (pid)
exit(0);