From b153f94a22d86ab342b7cc7a0f1fa5051311f2b4 Mon Sep 17 00:00:00 2001 From: Jens Axboe Date: Thu, 26 Apr 2018 22:41:03 -0600 Subject: [PATCH] iolog/blktrace: boolean conversion They don't return error numbers, so switch to true/false for good/bad return. Signed-off-by: Jens Axboe --- backend.c | 2 +- blktrace.c | 28 ++++++++++++++-------------- blktrace.h | 14 +++++++------- iolog.c | 32 +++++++++++++++++--------------- iolog.h | 2 +- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/backend.c b/backend.c index d5cb6ef5..033d5a70 100644 --- a/backend.c +++ b/backend.c @@ -1670,7 +1670,7 @@ static void *thread_main(void *data) * May alter parameters that init_io_u() will use, so we need to * do this first. */ - if (init_iolog(td)) + if (!init_iolog(td)) goto err; if (init_io_u(td)) diff --git a/blktrace.c b/blktrace.c index 70f38d45..cda111a3 100644 --- a/blktrace.c +++ b/blktrace.c @@ -73,29 +73,29 @@ static int discard_pdu(struct thread_data *td, struct fifo *fifo, int fd, * Check if this is a blktrace binary data file. We read a single trace * into memory and check for the magic signature. */ -int is_blktrace(const char *filename, int *need_swap) +bool is_blktrace(const char *filename, int *need_swap) { struct blk_io_trace t; int fd, ret; fd = open(filename, O_RDONLY); if (fd < 0) - return 0; + return false; ret = read(fd, &t, sizeof(t)); close(fd); if (ret < 0) { perror("read blktrace"); - return 0; + return false; } else if (ret != sizeof(t)) { log_err("fio: short read on blktrace file\n"); - return 0; + return false; } if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) { *need_swap = 0; - return 1; + return true; } /* @@ -104,10 +104,10 @@ int is_blktrace(const char *filename, int *need_swap) t.magic = fio_swap32(t.magic); if ((t.magic & 0xffffff00) == BLK_IO_TRACE_MAGIC) { *need_swap = 1; - return 1; + return true; } - return 0; + return false; } #define FMINORBITS 20 @@ -412,7 +412,7 @@ static void byteswap_trace(struct blk_io_trace *t) t->pdu_len = fio_swap16(t->pdu_len); } -static int t_is_write(struct blk_io_trace *t) +static bool t_is_write(struct blk_io_trace *t) { return (t->action & BLK_TC_ACT(BLK_TC_WRITE | BLK_TC_DISCARD)) != 0; } @@ -462,7 +462,7 @@ static void depth_end(struct blk_io_trace *t, int *this_depth, int *depth) * Load a blktrace file by reading all the blk_io_trace entries, and storing * them as io_pieces like the fio text version would do. */ -int load_blktrace(struct thread_data *td, const char *filename, int need_swap) +bool load_blktrace(struct thread_data *td, const char *filename, int need_swap) { struct blk_io_trace t; unsigned long ios[DDIR_RWDIR_SYNC_CNT] = { }; @@ -477,7 +477,7 @@ int load_blktrace(struct thread_data *td, const char *filename, int need_swap) fd = open(filename, O_RDONLY); if (fd < 0) { td_verror(td, errno, "open blktrace file"); - return 1; + return false; } fifo = fifo_alloc(TRACE_FIFO_SIZE); @@ -547,7 +547,7 @@ int load_blktrace(struct thread_data *td, const char *filename, int need_swap) if (!td->files_index) { log_err("fio: did not find replay device(s)\n"); - return 1; + return false; } /* @@ -570,7 +570,7 @@ int load_blktrace(struct thread_data *td, const char *filename, int need_swap) if (!ios[DDIR_READ] && !ios[DDIR_WRITE] && !ios[DDIR_TRIM] && !ios[DDIR_SYNC]) { log_err("fio: found no ios in blktrace data\n"); - return 1; + return false; } else if (ios[DDIR_READ] && !ios[DDIR_WRITE]) { td->o.td_ddir = TD_DDIR_READ; td->o.max_bs[DDIR_READ] = rw_bs[DDIR_READ]; @@ -598,9 +598,9 @@ int load_blktrace(struct thread_data *td, const char *filename, int need_swap) if (!fio_option_is_set(&td->o, iodepth)) td->o.iodepth = td->o.iodepth_low = max_depth; - return 0; + return true; err: close(fd); fifo_free(fifo); - return 1; + return false; } diff --git a/blktrace.h b/blktrace.h index 8656a957..096993ed 100644 --- a/blktrace.h +++ b/blktrace.h @@ -3,20 +3,20 @@ #ifdef FIO_HAVE_BLKTRACE -int is_blktrace(const char *, int *); -int load_blktrace(struct thread_data *, const char *, int); +bool is_blktrace(const char *, int *); +bool load_blktrace(struct thread_data *, const char *, int); #else -static inline int is_blktrace(const char *fname, int *need_swap) +static inline bool is_blktrace(const char *fname, int *need_swap) { - return 0; + return false; } -static inline int load_blktrace(struct thread_data *td, const char *fname, - int need_swap) +static inline bool load_blktrace(struct thread_data *td, const char *fname, + int need_swap) { - return 1; + return false; } #endif diff --git a/iolog.c b/iolog.c index f1e52311..13040b68 100644 --- a/iolog.c +++ b/iolog.c @@ -338,7 +338,7 @@ void write_iolog_close(struct thread_data *td) * Read version 2 iolog data. It is enhanced to include per-file logging, * syncs, etc. */ -static int read_iolog2(struct thread_data *td, FILE *f) +static bool read_iolog2(struct thread_data *td, FILE *f) { unsigned long long offset; unsigned int bytes; @@ -474,7 +474,7 @@ static int read_iolog2(struct thread_data *td, FILE *f) } if (!reads && !writes && !waits) - return 1; + return false; else if (reads && !writes) td->o.td_ddir = TD_DDIR_READ; else if (!reads && writes) @@ -482,22 +482,22 @@ static int read_iolog2(struct thread_data *td, FILE *f) else td->o.td_ddir = TD_DDIR_RW; - return 0; + return true; } /* * open iolog, check version, and call appropriate parser */ -static int init_iolog_read(struct thread_data *td) +static bool init_iolog_read(struct thread_data *td) { char buffer[256], *p; FILE *f; - int ret; + bool ret; f = fopen(td->o.read_iolog_file, "r"); if (!f) { perror("fopen read iolog"); - return 1; + return false; } p = fgets(buffer, sizeof(buffer), f); @@ -505,7 +505,7 @@ static int init_iolog_read(struct thread_data *td) td_verror(td, errno, "iolog read"); log_err("fio: unable to read iolog\n"); fclose(f); - return 1; + return false; } /* @@ -516,7 +516,7 @@ static int init_iolog_read(struct thread_data *td) ret = read_iolog2(td, f); else { log_err("fio: iolog version 1 is no longer supported\n"); - ret = 1; + ret = false; } fclose(f); @@ -526,7 +526,7 @@ static int init_iolog_read(struct thread_data *td) /* * Set up a log for storing io patterns. */ -static int init_iolog_write(struct thread_data *td) +static bool init_iolog_write(struct thread_data *td) { struct fio_file *ff; FILE *f; @@ -535,7 +535,7 @@ static int init_iolog_write(struct thread_data *td) f = fopen(td->o.write_iolog_file, "a"); if (!f) { perror("fopen write iolog"); - return 1; + return false; } /* @@ -550,7 +550,7 @@ static int init_iolog_write(struct thread_data *td) */ if (fprintf(f, "%s\n", iolog_ver2) < 0) { perror("iolog init\n"); - return 1; + return false; } /* @@ -559,12 +559,12 @@ static int init_iolog_write(struct thread_data *td) for_each_file(td, ff, i) log_file(td, ff, FIO_LOG_ADD_FILE); - return 0; + return true; } -int init_iolog(struct thread_data *td) +bool init_iolog(struct thread_data *td) { - int ret = 0; + bool ret; if (td->o.read_iolog_file) { int need_swap; @@ -579,8 +579,10 @@ int init_iolog(struct thread_data *td) ret = init_iolog_read(td); } else if (td->o.write_iolog_file) ret = init_iolog_write(td); + else + ret = false; - if (ret) + if (!ret) td_verror(td, EINVAL, "failed initializing iolog"); return ret; diff --git a/iolog.h b/iolog.h index d689140f..60b4f011 100644 --- a/iolog.h +++ b/iolog.h @@ -234,7 +234,7 @@ struct io_u; extern int __must_check read_iolog_get(struct thread_data *, struct io_u *); extern void log_io_u(const struct thread_data *, const struct io_u *); extern void log_file(struct thread_data *, struct fio_file *, enum file_log_act); -extern int __must_check init_iolog(struct thread_data *td); +extern bool __must_check init_iolog(struct thread_data *td); extern void log_io_piece(struct thread_data *, struct io_u *); extern void unlog_io_piece(struct thread_data *, struct io_u *); extern void trim_io_piece(struct thread_data *, const struct io_u *); -- 2.25.1