From 83276370ce4d6ce7fc43fb9faf06454403877da1 Mon Sep 17 00:00:00 2001 From: Denis Pronin Date: Fri, 11 Mar 2022 13:59:07 +0300 Subject: [PATCH] fixed compiler warnings if NDEBUG enabled in core code if NDEBUG is defined we check several return codes fairly rather than ignore them in turning into nothing assert call in RELEASE mode Signed-off-by: Denis Pronin --- backend.c | 18 ++++++++++++++---- helper_thread.c | 8 +++++++- io_u.c | 7 ++++--- ioengines.c | 10 ++++++++-- rate-submit.c | 18 +++++++++++++++--- server.c | 8 ++++++-- zbd.c | 18 ++++++++---------- 7 files changed, 62 insertions(+), 25 deletions(-) diff --git a/backend.c b/backend.c index 317e4f6c..c196672e 100644 --- a/backend.c +++ b/backend.c @@ -1600,7 +1600,7 @@ static void *thread_main(void *data) uint64_t bytes_done[DDIR_RWDIR_CNT]; int deadlock_loop_cnt; bool clear_state; - int res, ret; + int ret; sk_out_assign(sk_out); free(fd); @@ -1931,13 +1931,23 @@ static void *thread_main(void *data) * another thread is checking its io_u's for overlap */ if (td_offload_overlap(td)) { - int res = pthread_mutex_lock(&overlap_check); - assert(res == 0); + int res; + + res = pthread_mutex_lock(&overlap_check); + if (res) { + td->error = errno; + goto err; + } } td_set_runstate(td, TD_FINISHING); if (td_offload_overlap(td)) { + int res; + res = pthread_mutex_unlock(&overlap_check); - assert(res == 0); + if (res) { + td->error = errno; + goto err; + } } update_rusage_stat(td); diff --git a/helper_thread.c b/helper_thread.c index b9b83db3..26857773 100644 --- a/helper_thread.c +++ b/helper_thread.c @@ -1,4 +1,7 @@ +#include #include +#include +#include #include #ifdef CONFIG_HAVE_TIMERFD_CREATE #include @@ -122,7 +125,10 @@ static void submit_action(enum action a) return; ret = write_to_pipe(helper_data->pipe[1], &data, sizeof(data)); - assert(ret == 1); + if (ret != 1) { + log_err("failed to write action into pipe, err %i:%s", errno, strerror(errno)); + assert(0); + } } void helper_reset(void) diff --git a/io_u.c b/io_u.c index eec378dd..8da79002 100644 --- a/io_u.c +++ b/io_u.c @@ -1570,7 +1570,6 @@ struct io_u *__get_io_u(struct thread_data *td) { const bool needs_lock = td_async_processing(td); struct io_u *io_u = NULL; - int ret; if (td->stop_io) return NULL; @@ -1604,14 +1603,16 @@ again: io_u_set(td, io_u, IO_U_F_IN_CUR_DEPTH); io_u->ipo = NULL; } else if (td_async_processing(td)) { + int ret; /* * We ran out, wait for async verify threads to finish and * return one */ assert(!(td->flags & TD_F_CHILD)); ret = pthread_cond_wait(&td->free_cond, &td->io_u_lock); - assert(ret == 0); - if (!td->error) + if (fio_unlikely(ret != 0)) { + td->error = errno; + } else if (!td->error) goto again; } diff --git a/ioengines.c b/ioengines.c index 68f307e5..63234e8a 100644 --- a/ioengines.c +++ b/ioengines.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "fio.h" #include "diskutil.h" @@ -335,8 +336,13 @@ enum fio_q_status td_io_queue(struct thread_data *td, struct io_u *io_u) * flag is now set */ if (td_offload_overlap(td)) { - int res = pthread_mutex_unlock(&overlap_check); - assert(res == 0); + int res; + + res = pthread_mutex_unlock(&overlap_check); + if (fio_unlikely(res != 0)) { + log_err("failed to unlock overlap check mutex, err: %i:%s", errno, strerror(errno)); + abort(); + } } assert(fio_file_open(io_u->file)); diff --git a/rate-submit.c b/rate-submit.c index 268356d1..bc076e86 100644 --- a/rate-submit.c +++ b/rate-submit.c @@ -5,6 +5,9 @@ * */ #include +#include +#include + #include "fio.h" #include "ioengines.h" #include "lib/getrusage.h" @@ -28,7 +31,10 @@ static void check_overlap(struct io_u *io_u) * threads as they assess overlap. */ res = pthread_mutex_lock(&overlap_check); - assert(res == 0); + if (fio_unlikely(res != 0)) { + log_err("failed to lock overlap check mutex, err: %i:%s", errno, strerror(errno)); + abort(); + } retry: for_each_td(td, i) { @@ -42,9 +48,15 @@ retry: continue; res = pthread_mutex_unlock(&overlap_check); - assert(res == 0); + if (fio_unlikely(res != 0)) { + log_err("failed to unlock overlap check mutex, err: %i:%s", errno, strerror(errno)); + abort(); + } res = pthread_mutex_lock(&overlap_check); - assert(res == 0); + if (fio_unlikely(res != 0)) { + log_err("failed to lock overlap check mutex, err: %i:%s", errno, strerror(errno)); + abort(); + } goto retry; } } diff --git a/server.c b/server.c index 4c71bd44..0bb82281 100644 --- a/server.c +++ b/server.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include @@ -2336,8 +2337,11 @@ void fio_server_send_add_job(struct thread_data *td) void fio_server_send_start(struct thread_data *td) { struct sk_out *sk_out = pthread_getspecific(sk_out_key); - - assert(sk_out->sk != -1); + if (!sk_out || sk_out->sk == -1) { + log_err("pthread getting specific for key failed, sk_out %p, sk %i, err: %i:%s", + sk_out, sk_out->sk, errno, strerror(errno)); + abort(); + } fio_net_queue_cmd(FIO_NET_CMD_SERVER_START, NULL, 0, NULL, SK_F_SIMPLE); } diff --git a/zbd.c b/zbd.c index b1fd6b4b..2f2d054e 100644 --- a/zbd.c +++ b/zbd.c @@ -11,6 +11,7 @@ #include #include +#include "compiler/compiler.h" #include "os/os.h" #include "file.h" #include "fio.h" @@ -90,13 +91,13 @@ static bool zbd_zone_full(const struct fio_file *f, struct fio_zone_info *z, static void zone_lock(struct thread_data *td, const struct fio_file *f, struct fio_zone_info *z) { +#ifndef NDEBUG struct zoned_block_device_info *zbd = f->zbd_info; - uint32_t nz = z - zbd->zone_info; - + uint32_t const nz = z - zbd->zone_info; /* A thread should never lock zones outside its working area. */ assert(f->min_zone <= nz && nz < f->max_zone); - assert(z->has_wp); +#endif /* * Lock the io_u target zone. The zone will be unlocked if io_u offset @@ -116,11 +117,8 @@ static void zone_lock(struct thread_data *td, const struct fio_file *f, static inline void zone_unlock(struct fio_zone_info *z) { - int ret; - assert(z->has_wp); - ret = pthread_mutex_unlock(&z->mutex); - assert(!ret); + pthread_mutex_unlock(&z->mutex); } static inline struct fio_zone_info *zbd_get_zone(const struct fio_file *f, @@ -339,7 +337,8 @@ static int zbd_reset_zones(struct thread_data *td, struct fio_file *f, const uint64_t min_bs = td->o.min_bs[DDIR_WRITE]; int res = 0; - assert(min_bs); + if (fio_unlikely(0 == min_bs)) + return 1; dprint(FD_ZBD, "%s: examining zones %u .. %u\n", f->file_name, zbd_zone_idx(f, zb), zbd_zone_idx(f, ze)); @@ -1651,10 +1650,9 @@ unlock: static void zbd_put_io(struct thread_data *td, const struct io_u *io_u) { const struct fio_file *f = io_u->file; - struct zoned_block_device_info *zbd_info = f->zbd_info; struct fio_zone_info *z; - assert(zbd_info); + assert(f->zbd_info); z = zbd_offset_to_zone(f, io_u->offset); assert(z->has_wp); -- 2.25.1