From 83276370ce4d6ce7fc43fb9faf06454403877da1 Mon Sep 17 00:00:00 2001 From: Denis Pronin Date: Fri, 11 Mar 2022 13:59:07 +0300 Subject: [PATCH 1/2] 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 317e4f6c0d..c196672ea3 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 b9b83db305..26857773bc 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 eec378ddc0..8da790027f 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 @@ struct io_u *__get_io_u(struct thread_data *td) 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 68f307e541..63234e8afc 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 268356d17a..bc076e869f 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 @@ static void check_overlap(struct io_u *io_u) 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 4c71bd4494..0bb82281c8 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 b1fd6b4bb0..2f2d054e94 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 @@ static void zbd_queue_io(struct thread_data *td, struct io_u *io_u, int q, 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); From 1f081ec0411a67cef0e4d80a0d51a052a5937056 Mon Sep 17 00:00:00 2001 From: Denis Pronin Date: Fri, 22 Apr 2022 22:24:35 +0300 Subject: [PATCH 2/2] fixed compiler warnings if NDEBUG enabled in test 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 --- t/read-to-pipe-async.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/t/read-to-pipe-async.c b/t/read-to-pipe-async.c index 586e3c95bf..76c64ab9c4 100644 --- a/t/read-to-pipe-async.c +++ b/t/read-to-pipe-async.c @@ -36,6 +36,8 @@ #include "../flist.h" +#include "compiler/compiler.h" + static int bs = 4096; static int max_us = 10000; static char *file; @@ -47,6 +49,18 @@ static int separate_writer = 1; #define PLAT_NR (PLAT_GROUP_NR * PLAT_VAL) #define PLAT_LIST_MAX 20 +#ifndef NDEBUG +#define CHECK_ZERO_OR_ABORT(code) assert(code) +#else +#define CHECK_ZERO_OR_ABORT(code) \ + do { \ + if (fio_unlikely((code) != 0)) { \ + log_err("failed checking code %i != 0", (code)); \ + abort(); \ + } \ + } while (0) +#endif + struct stats { unsigned int plat[PLAT_NR]; unsigned int nr_samples; @@ -121,7 +135,7 @@ uint64_t utime_since(const struct timespec *s, const struct timespec *e) return ret; } -static struct work_item *find_seq(struct writer_thread *w, unsigned int seq) +static struct work_item *find_seq(struct writer_thread *w, int seq) { struct work_item *work; struct flist_head *entry; @@ -224,6 +238,8 @@ static int write_work(struct work_item *work) clock_gettime(CLOCK_MONOTONIC, &s); ret = write(STDOUT_FILENO, work->buf, work->buf_size); + if (ret < 0) + return (int)ret; clock_gettime(CLOCK_MONOTONIC, &e); assert(ret == work->buf_size); @@ -241,10 +257,10 @@ static void *writer_fn(void *data) { struct writer_thread *wt = data; struct work_item *work; - unsigned int seq = 1; + int seq = 1; work = NULL; - while (!wt->thread.exit || !flist_empty(&wt->list)) { + while (!(seq < 0) && (!wt->thread.exit || !flist_empty(&wt->list))) { pthread_mutex_lock(&wt->thread.lock); if (work) { @@ -469,10 +485,10 @@ static void init_thread(struct thread_data *thread) int ret; ret = pthread_condattr_init(&cattr); - assert(ret == 0); + CHECK_ZERO_OR_ABORT(ret); #ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK ret = pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC); - assert(ret == 0); + CHECK_ZERO_OR_ABORT(ret); #endif pthread_cond_init(&thread->cond, &cattr); pthread_cond_init(&thread->done_cond, &cattr); @@ -626,10 +642,10 @@ int main(int argc, char *argv[]) bytes = 0; ret = pthread_condattr_init(&cattr); - assert(ret == 0); + CHECK_ZERO_OR_ABORT(ret); #ifdef CONFIG_PTHREAD_CONDATTR_SETCLOCK ret = pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC); - assert(ret == 0); + CHECK_ZERO_OR_ABORT(ret); #endif clock_gettime(CLOCK_MONOTONIC, &s);