server/client: add FD_NET debug clues
authorJens Axboe <axboe@kernel.dk>
Sat, 1 Oct 2011 18:50:51 +0000 (12:50 -0600)
committerJens Axboe <axboe@kernel.dk>
Sat, 1 Oct 2011 18:50:51 +0000 (12:50 -0600)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
client.c
debug.c
infolog.c
log.h
server.c

index c080c17d03fadaf36466398bb7c062c0bb15b5d0..63ecee6d11c93c315a35d1153c6933e326d63ad9 100644 (file)
--- 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 013cd53c214debe2cbb7be1ca8842c436390ff96..5e9806335fc630e01da4f8a55c5ed042dd939488 100644 (file)
--- 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);
index b09e65d61aeef5711d690e663ff5b1c18ad9e254..5d1d0b52d5f48ec09f705f3bea04dddb53d7160d 100644 (file)
--- 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 916f464dab8f19ea73931fa1880785e9eca8669b..f201191b11eb552a302f3876e64750dfd4969856 100644 (file)
--- 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))
 
index ca37e3f6b9dd89894dd5babea42c4670fa8aaf7a..8f93d2f8a2c6531de13cb8755272911b4813ff34 100644 (file)
--- 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));