From: Jens Axboe Date: Sat, 1 Oct 2011 18:50:51 +0000 (-0600) Subject: server/client: add FD_NET debug clues X-Git-Tag: fio-1.99~68 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=46c48f1f9b8ce94132c13638e4c83c13e1d392da server/client: add FD_NET debug clues Signed-off-by: Jens Axboe --- diff --git a/client.c b/client.c index c080c17d..63ecee6d 100644 --- a/client.c +++ b/client.c @@ -61,6 +61,7 @@ static struct fio_client *find_client_by_name(const char *name) static void remove_client(struct fio_client *client) { + dprint(FD_NET, "removed client <%s>\n", client->hostname); flist_del(&client->list); nr_clients--; free(client->hostname); @@ -71,6 +72,7 @@ void fio_client_add(const char *hostname) { struct fio_client *client; + dprint(FD_NET, "added client <%s>\n", hostname); client = malloc(sizeof(*client)); memset(client, 0, sizeof(*client)); client->hostname = strdup(hostname); @@ -83,6 +85,8 @@ static int fio_client_connect(struct fio_client *client) { int fd; + dprint(FD_NET, "connect to host %s\n", client->hostname); + memset(&client->addr, 0, sizeof(client->addr)); client->addr.sin_family = AF_INET; client->addr.sin_port = htons(fio_net_port); @@ -149,6 +153,8 @@ static int fio_client_send_ini(struct fio_client *client, const char *filename) off_t len; int fd, ret; + dprint(FD_NET, "send ini %s to %s\n", filename, client->hostname); + fd = open(filename, O_RDONLY); if (fd < 0) { log_err("fio: job file open: %s\n", strerror(errno)); @@ -203,6 +209,9 @@ static int handle_client(struct fio_client *client) struct fio_net_cmd *cmd; while ((cmd = fio_net_cmd_read(client->fd)) != NULL) { + dprint(FD_NET, "%s: got cmd op %d\n", client->hostname, + cmd->opcode); + if (cmd->opcode == FIO_NET_CMD_ACK) { free(cmd); continue; diff --git a/debug.c b/debug.c index 013cd53c..5e980633 100644 --- a/debug.c +++ b/debug.c @@ -16,8 +16,8 @@ void __dprint(int type, const char *str, ...) && pid != *fio_debug_jobp) return; - log_info("%-8s ", debug_levels[type].name); - log_info("%-5u ", (int) pid); + log_local("%-8s ", debug_levels[type].name); + log_local("%-5u ", (int) pid); va_start(args, str); log_valist(str, args); diff --git a/infolog.c b/infolog.c index b09e65d6..5d1d0b52 100644 --- a/infolog.c +++ b/infolog.c @@ -5,6 +5,19 @@ #include "fio.h" +int log_local(const char *format, ...) +{ + char buffer[1024]; + va_list args; + size_t len; + + va_start(args, format); + len = vsnprintf(buffer, sizeof(buffer), format, args); + va_end(args); + + return fwrite(buffer, len, 1, f_out); +} + int log_info(const char *format, ...) { char buffer[1024]; diff --git a/log.h b/log.h index 916f464d..f201191b 100644 --- a/log.h +++ b/log.h @@ -8,6 +8,7 @@ extern FILE *f_err; extern int log_err(const char *format, ...); extern int log_info(const char *format, ...); +extern int log_local(const char *format, ...); #define log_valist(str, args) vfprintf(f_out, (str), (args)) diff --git a/server.c b/server.c index ca37e3f6..8f93d2f8 100644 --- a/server.c +++ b/server.c @@ -25,7 +25,7 @@ static char *job_buf; static unsigned int job_cur_len; static unsigned int job_max_len; -static int server_fd; +static int server_fd = -1; int fio_send_data(int sk, const void *p, unsigned int len) { @@ -222,6 +222,7 @@ static int nak_command(int sk, struct fio_net_cmd *cmd) static int send_quit_command(void) { + dprint(FD_NET, "server: sending quit\n"); return send_simple_command(server_fd, FIO_NET_CMD_QUIT, 0); } @@ -258,6 +259,8 @@ static int handle_command(struct fio_net_cmd *cmd) { int ret; + dprint(FD_NET, "server: got opcode %d\n", cmd->opcode); + switch (cmd->opcode) { case FIO_NET_CMD_QUIT: exit_backend = 1; @@ -343,6 +346,8 @@ again: return -1; } + dprint(FD_NET, "server got a connection\n"); + server_fd = sk; exitval = handle_connection(sk); @@ -364,6 +369,8 @@ int fio_server(void) unsigned int len; int sk, opt, ret; + dprint(FD_NET, "starting server\n"); + sk = socket(AF_INET, SOCK_STREAM, 0); if (sk < 0) { log_err("fio: socket: %s\n", strerror(errno));