Skip to content

Commit

Permalink
iolog/blktrace: boolean conversion
Browse files Browse the repository at this point in the history
They don't return error numbers, so switch to true/false for good/bad
return.

Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
axboe committed Apr 27, 2018
1 parent 811f542 commit b153f94
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
2 changes: 1 addition & 1 deletion backend.c
Expand Up @@ -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))
Expand Down
28 changes: 14 additions & 14 deletions blktrace.c
Expand Up @@ -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;
}

/*
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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] = { };
Expand All @@ -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);
Expand Down Expand Up @@ -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;
}

/*
Expand All @@ -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];
Expand Down Expand Up @@ -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;
}
14 changes: 7 additions & 7 deletions blktrace.h
Expand Up @@ -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
Expand Down
32 changes: 17 additions & 15 deletions iolog.c
Expand Up @@ -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;
Expand Down Expand Up @@ -474,38 +474,38 @@ 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)
td->o.td_ddir = TD_DDIR_WRITE;
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);
if (!p) {
td_verror(td, errno, "iolog read");
log_err("fio: unable to read iolog\n");
fclose(f);
return 1;
return false;
}

/*
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}

/*
Expand All @@ -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;
}

/*
Expand All @@ -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;
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion iolog.h
Expand Up @@ -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 *);
Expand Down

0 comments on commit b153f94

Please sign in to comment.