Skip to content

Commit

Permalink
Merge branch 'improvement/fix-warnings-if-NDEBUG-enabled' of https://…
Browse files Browse the repository at this point in the history
…github.com/dpronin/fio

* 'improvement/fix-warnings-if-NDEBUG-enabled' of https://github.com/dpronin/fio:
  fixed compiler warnings if NDEBUG enabled in test code
  fixed compiler warnings if NDEBUG enabled in core code
  • Loading branch information
axboe committed Jul 3, 2023
2 parents 38708e2 + 1f081ec commit 2091760
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 32 deletions.
18 changes: 14 additions & 4 deletions backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,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);
Expand Down Expand Up @@ -1974,13 +1974,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);
Expand Down
8 changes: 7 additions & 1 deletion helper_thread.c
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions io_u.c
Original file line number Diff line number Diff line change
Expand Up @@ -1613,7 +1613,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;
Expand Down Expand Up @@ -1647,14 +1646,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;
}

Expand Down
10 changes: 8 additions & 2 deletions ioengines.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <assert.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>

#include "fio.h"
#include "diskutil.h"
Expand Down Expand Up @@ -342,8 +343,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));
Expand Down
18 changes: 15 additions & 3 deletions rate-submit.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
*
*/
#include <assert.h>
#include <errno.h>
#include <pthread.h>

#include "fio.h"
#include "ioengines.h"
#include "lib/getrusage.h"
Expand All @@ -27,7 +30,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) {
Expand All @@ -41,9 +47,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;
} end_for_each();
}
Expand Down
8 changes: 6 additions & 2 deletions server.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <poll.h>
Expand Down Expand Up @@ -2342,8 +2343,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);
}
Expand Down
30 changes: 23 additions & 7 deletions t/read-to-pipe-async.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@

#include "../flist.h"

#include "compiler/compiler.h"

static int bs = 4096;
static int max_us = 10000;
static char *file;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand All @@ -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)
Expand Down Expand Up @@ -467,10 +483,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);
Expand Down Expand Up @@ -624,10 +640,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);
Expand Down
18 changes: 8 additions & 10 deletions zbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -102,13 +103,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
Expand All @@ -128,11 +129,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,
Expand Down Expand Up @@ -420,7 +418,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));
Expand Down Expand Up @@ -1714,10 +1713,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);
Expand Down

0 comments on commit 2091760

Please sign in to comment.