A few min/max cleanups
authorJens Axboe <axboe@fb.com>
Mon, 23 Nov 2015 22:04:56 +0000 (15:04 -0700)
committerJens Axboe <axboe@fb.com>
Mon, 23 Nov 2015 22:04:56 +0000 (15:04 -0700)
Signed-off-by: Jens Axboe <axboe@fb.com>
backend.c
io_u.c
log.c
minmax.h

index aa94acf2499808e4543922f26ea83d21ebff06d4..1560749618a5a91ed6152849cba8f9124b73dc16 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -448,7 +448,7 @@ static int wait_for_completions(struct thread_data *td, struct timeval *time)
         * if the queue is full, we MUST reap at least 1 event
         */
        min_evts = min(td->o.iodepth_batch_complete_min, td->cur_depth);
-    if ((full && !min_evts) || !td->o.iodepth_batch_complete_min)
+       if ((full && !min_evts) || !td->o.iodepth_batch_complete_min)
                min_evts = 1;
 
        if (time && (__should_check_rate(td, DDIR_READ) ||
diff --git a/io_u.c b/io_u.c
index b1aa4141cdbc8557411e1d9c0626fd9c90db2766..dd4502f1cfccb7c532480bd45fc13785578f9912 100644 (file)
--- a/io_u.c
+++ b/io_u.c
@@ -13,6 +13,7 @@
 #include "lib/axmap.h"
 #include "err.h"
 #include "lib/pow2.h"
+#include "minmax.h"
 
 struct io_completion_data {
        int nr;                         /* input */
@@ -1927,9 +1928,8 @@ void fill_io_buffer(struct thread_data *td, void *buf, unsigned int min_write,
                        min_write = min(min_write, left);
 
                        if (perc) {
-                               this_write = min(min_write, td->o.compress_chunk);
-                               if (!this_write)
-                                       this_write = min_write;
+                               this_write = min_not_zero(min_write,
+                                                       td->o.compress_chunk);
 
                                fill_random_buf_percentage(rs, buf, perc,
                                        this_write, this_write,
diff --git a/log.c b/log.c
index 8d511b549b9e2ff3caf88500a6b118bc65a8938b..d508267676b7f9d71f609d6ee5bf058c69897ef5 100644 (file)
--- a/log.c
+++ b/log.c
@@ -59,9 +59,8 @@ size_t __log_buf(struct buf_output *buf, const char *format, ...)
        va_start(args, format);
        len = vsnprintf(buffer, sizeof(buffer), format, args);
        va_end(args);
-       len = min(len, sizeof(buffer) - 1);
 
-       return buf_output_add(buf, buffer, len);
+       return buf_output_add(buf, buffer, min(len, sizeof(buffer) - 1));
 }
 
 int log_info_flush(void)
index 97957c8874e2e68b6e84a318d70c7c62670501bf..afc78f02e4b3f4cfe2de624d780301a54f8bc926 100644 (file)
--- a/minmax.h
+++ b/minmax.h
@@ -17,4 +17,9 @@
        _x > _y ? _x : _y; })
 #endif
 
+#define min_not_zero(x, y) ({          \
+       typeof(x) __x = (x);            \
+       typeof(y) __y = (y);            \
+       __x == 0 ? __y : ((__y == 0) ? __x : min(__x, __y)); })
+
 #endif