Drop circular dependency in log.c and lib/output_buffer.c
authorTomohiro Kusumi <tkusumi@tuxera.com>
Tue, 23 May 2017 18:44:47 +0000 (21:44 +0300)
committerJens Axboe <axboe@fb.com>
Wed, 24 May 2017 02:02:42 +0000 (20:02 -0600)
Two files log.c and lib/output_buffer.c have dependency on each other,
i.e. log.c is using buf_output_add() in lib/output_buffer.c, while
lib/output_buffer.c is using log_info_buf() in log.c.

This commit removes this dependency from lib/output_buffer.c by
dropping log_info_buf() call from a library function buf_output_flush(),
and then as a result rename buf_output_flush() to buf_output_clear()
since it's no longer flusing anything. log_info_buf() is now called
independently by __show_run_stats() which was the only caller of
buf_output_flush().

log_info_buf() returning 0 on !len is necessary to keep this commit
without making functional difference. dprint()/log_info() basically
never pass NULL or "" to log_info_buf(), but __show_run_stats() would
pass NULL with length 0 for unused output modes which then needs to
be avoided as a special case.

Signed-off-by: Tomohiro Kusumi <tkusumi@tuxera.com>
Signed-off-by: Jens Axboe <axboe@fb.com>
lib/output_buffer.c
lib/output_buffer.h
log.c
stat.c

index c1fdfc95f610aca10ece35ebdc2dac437c01af66..313536dea97aa4f5277fb7634c0116bb5fcae1d7 100644 (file)
@@ -3,7 +3,6 @@
 #include <stdlib.h>
 
 #include "output_buffer.h"
 #include <stdlib.h>
 
 #include "output_buffer.h"
-#include "../log.h"
 #include "../minmax.h"
 
 #define BUF_INC        1024
 #include "../minmax.h"
 
 #define BUF_INC        1024
@@ -41,15 +40,10 @@ size_t buf_output_add(struct buf_output *out, const char *buf, size_t len)
        return len;
 }
 
        return len;
 }
 
-size_t buf_output_flush(struct buf_output *out)
+void buf_output_clear(struct buf_output *out)
 {
 {
-       size_t ret = 0;
-
        if (out->buflen) {
        if (out->buflen) {
-               ret = log_info_buf(out->buf, out->buflen);
                memset(out->buf, 0, out->max_buflen);
                out->buflen = 0;
        }
                memset(out->buf, 0, out->max_buflen);
                out->buflen = 0;
        }
-
-       return ret;
 }
 }
index 396002fbfa91474fd02bfb291acdd72fa712918f..15ee00566e7f6784c347b0c997f91a71134f5963 100644 (file)
@@ -12,6 +12,6 @@ struct buf_output {
 void buf_output_init(struct buf_output *out);
 void buf_output_free(struct buf_output *out);
 size_t buf_output_add(struct buf_output *out, const char *buf, size_t len);
 void buf_output_init(struct buf_output *out);
 void buf_output_free(struct buf_output *out);
 size_t buf_output_add(struct buf_output *out, const char *buf, size_t len);
-size_t buf_output_flush(struct buf_output *out);
+void buf_output_clear(struct buf_output *out);
 
 #endif
 
 #endif
diff --git a/log.c b/log.c
index 4eb4af5905c40a45c8df1bd12f4bf02a99ea70a0..172f1538c6e7366f784c374db0dcc1b3ea7b4cd6 100644 (file)
--- a/log.c
+++ b/log.c
@@ -8,6 +8,12 @@
 
 size_t log_info_buf(const char *buf, size_t len)
 {
 
 size_t log_info_buf(const char *buf, size_t len)
 {
+       /*
+        * buf could be NULL (not just "").
+        */
+       if (!buf)
+               return 0;
+
        if (is_backend) {
                size_t ret = fio_server_text_output(FIO_LOG_INFO, buf, len);
                if (ret != -1)
        if (is_backend) {
                size_t ret = fio_server_text_output(FIO_LOG_INFO, buf, len);
                if (ret != -1)
diff --git a/stat.c b/stat.c
index 5b4841322285b1b28cce80bd190049f3c5f14030..1f124a8c0b65d40d080638e3aa2a7a4089f061df 100644 (file)
--- a/stat.c
+++ b/stat.c
@@ -1825,8 +1825,10 @@ void __show_run_stats(void)
        }
 
        for (i = 0; i < FIO_OUTPUT_NR; i++) {
        }
 
        for (i = 0; i < FIO_OUTPUT_NR; i++) {
-               buf_output_flush(&output[i]);
-               buf_output_free(&output[i]);
+               struct buf_output *out = &output[i];
+               log_info_buf(out->buf, out->buflen);
+               buf_output_clear(out);
+               buf_output_free(out);
        }
 
        log_info_flush();
        }
 
        log_info_flush();