fixed compiler warnings if NDEBUG enabled in core code
authorDenis Pronin <dannftk@yandex.ru>
Fri, 11 Mar 2022 10:59:07 +0000 (13:59 +0300)
committerDenis Pronin <dannftk@yandex.ru>
Fri, 22 Apr 2022 19:25:10 +0000 (22:25 +0300)
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 <dannftk@yandex.ru>
backend.c
helper_thread.c
io_u.c
ioengines.c
rate-submit.c
server.c
zbd.c

index 317e4f6c0d642d26c7f70ac2ab93aa33851082c2..c196672ea35c3f0d542c925680d4f78b4969c328 100644 (file)
--- 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);
index b9b83db3057435f6fd2918d84cc3e96bdb7c4252..26857773bc0dbafe9e593d64bcaf36dae15a0696 100644 (file)
@@ -1,4 +1,7 @@
+#include <errno.h>
 #include <signal.h>
+#include <stdio.h>
+#include <string.h>
 #include <unistd.h>
 #ifdef CONFIG_HAVE_TIMERFD_CREATE
 #include <sys/timerfd.h>
@@ -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 eec378ddc0258169e3edbeb84046f7f27cef6282..8da790027f8e3c51aadfa870495350d737adbb58 100644 (file)
--- 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;
        }
 
index 68f307e541a9f5b0cd469c5f7fc695506b8e5144..63234e8afc71df55622bcf69de31af294c769449 100644 (file)
@@ -17,6 +17,7 @@
 #include <assert.h>
 #include <sys/types.h>
 #include <dirent.h>
+#include <errno.h>
 
 #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));
index 268356d17a1f1b35a6eaa0ad82219db86177a4de..bc076e869f56ad11cd7f346195ba64c902ed6ad9 100644 (file)
@@ -5,6 +5,9 @@
  *
  */
 #include <assert.h>
+#include <errno.h>
+#include <pthread.h>
+
 #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;
        }
 }
index 4c71bd449458aa44ecb65d43ea787962eba34058..0bb82281c8402c0d1798a30643922e4a0ab2e126 100644 (file)
--- a/server.c
+++ b/server.c
@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <unistd.h>
 #include <errno.h>
 #include <poll.h>
@@ -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 b1fd6b4bb0ae23cda7dba13a3c0bf3577139600f..2f2d054e947cd3c051206e873b149f3873f272e9 100644 (file)
--- a/zbd.c
+++ b/zbd.c
@@ -11,6 +11,7 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
+#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);