Server logging cleanup/functionality
authorJens Axboe <axboe@kernel.dk>
Fri, 30 Sep 2011 23:35:45 +0000 (17:35 -0600)
committerJens Axboe <axboe@kernel.dk>
Fri, 30 Sep 2011 23:35:45 +0000 (17:35 -0600)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Makefile
client.c
infolog.c [new file with mode: 0644]
init.c
log.h
server.c
server.h

index 7c5819271969fce8c33e5288a94c9a0c1f3e15bc..ea3306b32dc5f80b9d267877d725c90d4d5387f4 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -14,7 +14,7 @@ SOURCE = gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
                rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
                lib/num2str.c $(wildcard crc/*.c) engines/cpu.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
                rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
                lib/num2str.c $(wildcard crc/*.c) engines/cpu.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
-               memalign.c server.c client.c
+               memalign.c server.c client.c infolog.c
 
 ifeq ($(UNAME), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c helpers.c cgroup.c trim.c \
 
 ifeq ($(UNAME), Linux)
   SOURCE += diskutil.c fifo.c blktrace.c helpers.c cgroup.c trim.c \
index 6aaad0193d2b6d272bcfb31afb20bf421a278ad0..d9e3857ee05e264d8ee8beb0ca2e0a4bc14a4083 100644 (file)
--- a/client.c
+++ b/client.c
@@ -126,6 +126,8 @@ int fio_handle_clients(void)
 
        while (!exit_backend) {
                cmd = fio_net_cmd_read(fio_client_fd);
 
        while (!exit_backend) {
                cmd = fio_net_cmd_read(fio_client_fd);
+               if (!cmd)
+                       continue;
 
                if (cmd->opcode == FIO_NET_CMD_ACK) {
                        free(cmd);
 
                if (cmd->opcode == FIO_NET_CMD_ACK) {
                        free(cmd);
diff --git a/infolog.c b/infolog.c
new file mode 100644 (file)
index 0000000..8396522
--- /dev/null
+++ b/infolog.c
@@ -0,0 +1,38 @@
+#include <unistd.h>
+#include <fcntl.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include "fio.h"
+
+int log_info(const char *format, ...)
+{
+       char buffer[1024];
+       va_list args;
+       size_t len;
+
+       va_start(args, format);
+       len = vsprintf(buffer, format, args);
+       va_end(args);
+
+       if (is_backend)
+               return fio_server_text_output(buffer, len);
+       else
+               return fwrite(buffer, len, 1, f_out);
+}
+
+int log_err(const char *format, ...)
+{
+       char buffer[1024];
+       va_list args;
+       size_t len;
+
+       va_start(args, format);
+       len = vsprintf(buffer, format, args);
+       va_end(args);
+
+       if (is_backend)
+               return fio_server_text_output(buffer, len);
+       else
+               return fwrite(buffer, len, 1, f_err);
+}
diff --git a/init.c b/init.c
index 28852fb7005d0bdce3e2e14e6dd62d94e40721e8..87052b9e5476aae581ffc6475293aa5529bf7590 100644 (file)
--- a/init.c
+++ b/init.c
@@ -177,16 +177,6 @@ static struct option l_opts[FIO_NR_OPTIONS] = {
        },
 };
 
        },
 };
 
-FILE *get_f_out()
-{
-       return f_out;
-}
-
-FILE *get_f_err()
-{
-       return f_err;
-}
-
 /*
  * Return a free job structure.
  */
 /*
  * Return a free job structure.
  */
diff --git a/log.h b/log.h
index eea1129ba4ff3756fcd969545b6340e6fcc34032..916f464dab8f19ea73931fa1880785e9eca8669b 100644 (file)
--- a/log.h
+++ b/log.h
@@ -6,19 +6,9 @@
 extern FILE *f_out;
 extern FILE *f_err;
 
 extern FILE *f_out;
 extern FILE *f_err;
 
-/*
- * If logging output to a file, stderr should go to both stderr and f_err
- */
-#define log_err(args, ...)     do {                            \
-       fprintf(f_err, args,  ##__VA_ARGS__);           \
-       if (f_err != stderr)                                            \
-               fprintf(stderr, args,  ##__VA_ARGS__);  \
-       } while (0)
+extern int log_err(const char *format, ...);
+extern int log_info(const char *format, ...);
 
 
-#define log_info(args, ...)    fprintf(f_out, args, ##__VA_ARGS__)
 #define log_valist(str, args)  vfprintf(f_out, (str), (args))
 
 #define log_valist(str, args)  vfprintf(f_out, (str), (args))
 
-FILE *get_f_out(void);
-FILE *get_f_err(void);
-
 #endif
 #endif
index 1749e7365bb446076366ad50f6a0db4c8a7be81d..4a78f38396c2a2eb0fc99808d565288c7e695705 100644 (file)
--- a/server.c
+++ b/server.c
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <stdarg.h>
 #include <unistd.h>
 #include <limits.h>
 #include <errno.h>
 #include <unistd.h>
 #include <limits.h>
 #include <errno.h>
@@ -367,11 +368,12 @@ int fio_server(void)
        return ret;
 }
 
        return ret;
 }
 
-void fio_server_text_output(const char *buf, unsigned int len)
+int fio_server_text_output(const char *buf, unsigned int len)
 {
        struct fio_net_cmd *cmd;
 {
        struct fio_net_cmd *cmd;
+       int size = sizeof(*cmd) + len;
 
 
-       cmd = malloc(sizeof(*cmd) + len);
+       cmd = malloc(size);
        fio_init_net_cmd(cmd);
        cmd->opcode     = cpu_to_le16(FIO_NET_CMD_TEXT);
        cmd->pdu_len    = cpu_to_le32(len);
        fio_init_net_cmd(cmd);
        cmd->opcode     = cpu_to_le16(FIO_NET_CMD_TEXT);
        cmd->pdu_len    = cpu_to_le32(len);
@@ -379,6 +381,19 @@ void fio_server_text_output(const char *buf, unsigned int len)
 
        fio_net_cmd_crc(cmd);
 
 
        fio_net_cmd_crc(cmd);
 
-       fio_send_data(server_fd, cmd, sizeof(*cmd) + len);
+       fio_send_data(server_fd, cmd, size);
        free(cmd);
        free(cmd);
+       return size;
+}
+
+int fio_server_log(const char *format, ...)
+{
+       char buffer[1024];
+       va_list args;
+
+       va_start(args, format);
+       sprintf(buffer, format, args);
+       va_end(args);
+
+       return fio_server_text_output(buffer, strlen(buffer));
 }
 }
index c2cb9942774b8a3c11b4e930d560300b3df2ffa7..969659ddb94b24f97f42ae92f588def5538a7e17 100644 (file)
--- a/server.h
+++ b/server.h
@@ -2,6 +2,7 @@
 #define FIO_SERVER_H
 
 #include <inttypes.h>
 #define FIO_SERVER_H
 
 #include <inttypes.h>
+#include <string.h>
 #include <endian.h>
 
 /*
 #include <endian.h>
 
 /*
@@ -34,7 +35,8 @@ enum {
 };
 
 extern int fio_server(void);
 };
 
 extern int fio_server(void);
-extern void fio_server_text_output(const char *, unsigned int len);
+extern int fio_server_text_output(const char *, unsigned int len);
+extern int fio_server_log(const char *format, ...);
 
 extern int fio_client_connect(const char *);
 extern int fio_client_send_ini(const char *);
 
 extern int fio_client_connect(const char *);
 extern int fio_client_send_ini(const char *);