From 3a71c49be9887e9c8f92c40b7d533fb29c8a9e99 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 10:31:35 +0100 Subject: [PATCH 1/5] common: introduce a separate FATAL macro with errno Signed-off-by: Tomasz Gromadzki --- src/common/set.c | 5 ++- src/common/util_pmem.h | 4 +- src/core/alloc.c | 4 +- src/core/out.c | 4 +- src/core/out.h | 5 ++- src/core/sys_util.h | 40 +++++++++---------- src/libpmem/pmem.c | 4 +- src/libpmem2/aarch64/init.c | 4 +- src/libpmem2/map_posix.c | 2 +- src/libpmem2/pmem2_utils.c | 2 +- src/libpmem2/source_posix.c | 4 +- src/libpmem2/x86_64/init.c | 4 +- src/libpmemobj/lane.c | 14 +++---- src/libpmemobj/memblock.c | 9 +++-- src/libpmemobj/obj.c | 8 ++-- src/libpmemobj/palloc.c | 2 +- src/libpmemobj/sync.h | 6 +-- src/libpmemobj/tx.c | 26 +++++++----- src/libpmempool/check_pool_hdr.c | 2 +- src/libpmempool/check_sds.c | 2 +- src/libpmempool/check_util.c | 4 +- .../pmem_is_pmem_posix/pmem_is_pmem_posix.c | 6 +-- 22 files changed, 85 insertions(+), 76 deletions(-) diff --git a/src/common/set.c b/src/common/set.c index 487e755c65d..be2415aaaad 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -217,7 +217,7 @@ util_unmap_hdr(struct pool_set_part *part) VALGRIND_REMOVE_PMEM_MAPPING(part->hdr, part->hdrsize); if (munmap(part->hdr, part->hdrsize) != 0) /* this means there's a bug on the caller side */ - FATAL("!munmap: %s", part->path); + FATAL_W_ERRNO("munmap: %s", part->path); part->hdr = NULL; part->hdrsize = 0; } @@ -2209,7 +2209,8 @@ util_poolset_append_new_part(struct pool_set *set, size_t size) d->path, PMEM_FILE_PADDING, set->next_id, PMEM_EXT); if (util_replica_add_part(&set->replica[r], path, size) != 0) - FATAL("cannot add a new part to the replica info"); + FATAL_WO_ERRNO( + "cannot add a new part to the replica info"); } set->next_directory_id += 1; diff --git a/src/common/util_pmem.h b/src/common/util_pmem.h index a31b6b8f7e9..76dd0d279a3 100644 --- a/src/common/util_pmem.h +++ b/src/common/util_pmem.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2017-2020, Intel Corporation */ +/* Copyright 2017-2024, Intel Corporation */ /* * util_pmem.h -- internal definitions for pmem utils @@ -26,7 +26,7 @@ util_persist(int is_pmem, const void *addr, size_t len) if (is_pmem) pmem_persist(addr, len); else if (pmem_msync(addr, len)) - FATAL("!pmem_msync"); + FATAL_W_ERRNO("pmem_msync"); } /* diff --git a/src/core/alloc.c b/src/core/alloc.c index e267e4e6291..6c3d7e16bdb 100644 --- a/src/core/alloc.c +++ b/src/core/alloc.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2020, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ #include @@ -58,7 +58,7 @@ core_inject_fault_at(enum pmem_allocation_type type, int nth, const char *at) fail_realloc_from = at; break; default: - FATAL("unknown allocation type"); + FATAL_WO_ERRNO("unknown allocation type"); } } diff --git a/src/core/out.c b/src/core/out.c index 4b5ea1ccc94..ad51b320c61 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -48,7 +48,7 @@ _Last_errormsg_key_alloc(void) { int pth_ret = os_tls_key_create(&Last_errormsg_key, free); if (pth_ret) - FATAL("!os_thread_key_create"); + FATAL_W_ERRNO("os_thread_key_create"); VALGRIND_ANNOTATE_HAPPENS_BEFORE(&Last_errormsg_key_once); } @@ -89,7 +89,7 @@ Last_errormsg_get(void) errormsg->msg[0] = '\0'; int ret = os_tls_set(Last_errormsg_key, errormsg); if (ret) - FATAL("!os_tls_set"); + FATAL_W_ERRNO("os_tls_set"); } return errormsg; } diff --git a/src/core/out.h b/src/core/out.h index c0914ac2c1c..f5227991ba9 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -117,9 +117,12 @@ out_fatal_abort(const char *file, int line, const char *func, } while (0) /* produce output and exit */ -#define FATAL(...)\ +#define FATAL_WO_ERRNO(...)\ OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, __VA_ARGS__) +#define FATAL_W_ERRNO(...)\ + OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, "!" __VA_ARGS__) + /* assert a condition is true at runtime */ #define ASSERT_rt(cnd) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ diff --git a/src/core/sys_util.h b/src/core/sys_util.h index 58a4fb0208e..80d880e90a5 100644 --- a/src/core/sys_util.h +++ b/src/core/sys_util.h @@ -28,7 +28,7 @@ util_mutex_init(os_mutex_t *m) int tmp = os_mutex_init(m); if (tmp) { errno = tmp; - FATAL("!os_mutex_init"); + FATAL_W_ERRNO("os_mutex_init"); } } @@ -43,7 +43,7 @@ util_mutex_destroy(os_mutex_t *m) int tmp = os_mutex_destroy(m); if (tmp) { errno = tmp; - FATAL("!os_mutex_destroy"); + FATAL_W_ERRNO("os_mutex_destroy"); } } @@ -58,7 +58,7 @@ util_mutex_lock(os_mutex_t *m) int tmp = os_mutex_lock(m); if (tmp) { errno = tmp; - FATAL("!os_mutex_lock"); + FATAL_W_ERRNO("os_mutex_lock"); } } @@ -74,7 +74,7 @@ util_mutex_trylock(os_mutex_t *m) int tmp = os_mutex_trylock(m); if (tmp && tmp != EBUSY) { errno = tmp; - FATAL("!os_mutex_trylock"); + FATAL_W_ERRNO("os_mutex_trylock"); } return tmp; } @@ -90,7 +90,7 @@ util_mutex_unlock(os_mutex_t *m) int tmp = os_mutex_unlock(m); if (tmp) { errno = tmp; - FATAL("!os_mutex_unlock"); + FATAL_W_ERRNO("os_mutex_unlock"); } } @@ -105,7 +105,7 @@ util_rwlock_init(os_rwlock_t *m) int tmp = os_rwlock_init(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_init"); + FATAL_W_ERRNO("os_rwlock_init"); } } @@ -120,7 +120,7 @@ util_rwlock_rdlock(os_rwlock_t *m) int tmp = os_rwlock_rdlock(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_rdlock"); + FATAL_W_ERRNO("os_rwlock_rdlock"); } } @@ -135,7 +135,7 @@ util_rwlock_wrlock(os_rwlock_t *m) int tmp = os_rwlock_wrlock(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_wrlock"); + FATAL_W_ERRNO("os_rwlock_wrlock"); } } @@ -150,7 +150,7 @@ util_rwlock_unlock(os_rwlock_t *m) int tmp = os_rwlock_unlock(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_unlock"); + FATAL_W_ERRNO("os_rwlock_unlock"); } } @@ -165,7 +165,7 @@ util_rwlock_destroy(os_rwlock_t *m) int tmp = os_rwlock_destroy(m); if (tmp) { errno = tmp; - FATAL("!os_rwlock_destroy"); + FATAL_W_ERRNO("os_rwlock_destroy"); } } @@ -194,7 +194,7 @@ util_spin_destroy(os_spinlock_t *lock) int tmp = os_spin_destroy(lock); if (tmp) { errno = tmp; - FATAL("!os_spin_destroy"); + FATAL_W_ERRNO("os_spin_destroy"); } } @@ -208,7 +208,7 @@ util_spin_lock(os_spinlock_t *lock) int tmp = os_spin_lock(lock); if (tmp) { errno = tmp; - FATAL("!os_spin_lock"); + FATAL_W_ERRNO("os_spin_lock"); } } @@ -223,7 +223,7 @@ util_spin_unlock(os_spinlock_t *lock) int tmp = os_spin_unlock(lock); if (tmp) { errno = tmp; - FATAL("!os_spin_unlock"); + FATAL_W_ERRNO("os_spin_unlock"); } } @@ -236,7 +236,7 @@ static inline void util_semaphore_init(os_semaphore_t *sem, unsigned value) { if (os_semaphore_init(sem, value)) - FATAL("!os_semaphore_init"); + FATAL_W_ERRNO("os_semaphore_init"); } /* @@ -246,7 +246,7 @@ static inline void util_semaphore_destroy(os_semaphore_t *sem) { if (os_semaphore_destroy(sem) != 0) - FATAL("!os_semaphore_destroy"); + FATAL_W_ERRNO("os_semaphore_destroy"); } /* @@ -263,7 +263,7 @@ util_semaphore_wait(os_semaphore_t *sem) } while (errno == EINTR); /* signal interrupt */ if (ret != 0) - FATAL("!os_semaphore_wait"); + FATAL_W_ERRNO("os_semaphore_wait"); } /* @@ -279,7 +279,7 @@ util_semaphore_trywait(os_semaphore_t *sem) } while (errno == EINTR); /* signal interrupt */ if (ret != 0 && errno != EAGAIN) - FATAL("!os_semaphore_trywait"); + FATAL_W_ERRNO("os_semaphore_trywait"); return ret; } @@ -291,21 +291,21 @@ static inline void util_semaphore_post(os_semaphore_t *sem) { if (os_semaphore_post(sem) != 0) - FATAL("!os_semaphore_post"); + FATAL_W_ERRNO("os_semaphore_post"); } static inline void util_cond_init(os_cond_t *__restrict cond) { if (os_cond_init(cond)) - FATAL("!os_cond_init"); + FATAL_W_ERRNO("os_cond_init"); } static inline void util_cond_destroy(os_cond_t *__restrict cond) { if (os_cond_destroy(cond)) - FATAL("!os_cond_destroy"); + FATAL_W_ERRNO("os_cond_destroy"); } #ifdef __cplusplus diff --git a/src/libpmem/pmem.c b/src/libpmem/pmem.c index 5b4241ba2c7..49ae318facb 100644 --- a/src/libpmem/pmem.c +++ b/src/libpmem/pmem.c @@ -359,7 +359,7 @@ pmem_is_pmem_init(void) Is_pmem = is_pmem_never; if (!util_bool_compare_and_swap32(&init, 1, 2)) - FATAL("util_bool_compare_and_swap32"); + FATAL_WO_ERRNO("util_bool_compare_and_swap32"); } } @@ -911,7 +911,7 @@ pmem_init(void) if (Funcs.flush == flush_empty) LOG(3, "not flushing CPU cache"); else if (Funcs.flush != Funcs.deep_flush) - FATAL("invalid flush function address"); + FATAL_WO_ERRNO("invalid flush function address"); pmem_os_init(&Is_pmem); } diff --git a/src/libpmem2/aarch64/init.c b/src/libpmem2/aarch64/init.c index 6540b0bf70e..21cf6c0bfdd 100644 --- a/src/libpmem2/aarch64/init.c +++ b/src/libpmem2/aarch64/init.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2021, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ #include #include @@ -85,5 +85,5 @@ pmem2_arch_init(struct pmem2_arch_info *info) else if (info->flush == flush_pop) LOG(3, "Synchronize VA to pop for ARM"); else - FATAL("invalid deep flush function address"); + FATAL_WO_ERRNO("invalid deep flush function address"); } diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index 9fe3ec616e6..fa886a58e20 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -484,7 +484,7 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, [cfg->requested_max_granularity] [available_min_granularity]; if (strcmp(err, GRAN_IMPOSSIBLE) == 0) - FATAL( + FATAL_WO_ERRNO( "unhandled granularity error: available_min_granularity: %d" \ "requested_max_granularity: %d", available_min_granularity, diff --git a/src/libpmem2/pmem2_utils.c b/src/libpmem2/pmem2_utils.c index 3daf76929a1..b9c0b3bd9c3 100644 --- a/src/libpmem2/pmem2_utils.c +++ b/src/libpmem2/pmem2_utils.c @@ -67,7 +67,7 @@ int pmem2_err_to_errno(int err) { if (err > 0) - FATAL("positive error code is a bug in libpmem2"); + FATAL_WO_ERRNO("positive error code is a bug in libpmem2"); if (err == PMEM2_E_NOSUPP) return ENOTSUP; diff --git a/src/libpmem2/source_posix.c b/src/libpmem2/source_posix.c index 6f811170f59..4f36c1cef18 100644 --- a/src/libpmem2/source_posix.c +++ b/src/libpmem2/source_posix.c @@ -126,7 +126,7 @@ pmem2_source_size(const struct pmem2_source *src, size_t *size) *size = (size_t)st.st_size; break; default: - FATAL( + FATAL_WO_ERRNO( "BUG: unhandled file type in pmem2_source_size"); } @@ -162,7 +162,7 @@ pmem2_source_alignment(const struct pmem2_source *src, size_t *alignment) *alignment = Pagesize; break; default: - FATAL( + FATAL_WO_ERRNO( "BUG: unhandled file type in pmem2_source_alignment"); } diff --git a/src/libpmem2/x86_64/init.c b/src/libpmem2/x86_64/init.c index bc21183301c..95b9e84b705 100644 --- a/src/libpmem2/x86_64/init.c +++ b/src/libpmem2/x86_64/init.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2014-2022, Intel Corporation */ +/* Copyright 2014-2024, Intel Corporation */ #include #include @@ -585,7 +585,7 @@ pmem2_arch_init(struct pmem2_arch_info *info) else if (info->flush == flush_clflush) LOG(3, "using clflush"); else - FATAL("invalid deep flush function address"); + FATAL_WO_ERRNO("invalid deep flush function address"); if (impl == MEMCPY_MOVDIR64B) LOG(3, "using movnt MOVDIR64B"); diff --git a/src/libpmemobj/lane.c b/src/libpmemobj/lane.c index 26350bea714..6210b27ddd1 100644 --- a/src/libpmemobj/lane.c +++ b/src/libpmemobj/lane.c @@ -40,7 +40,7 @@ lane_info_create(void) { Lane_info_ht = critnib_new(); if (Lane_info_ht == NULL) - FATAL("critnib_new"); + FATAL_WO_ERRNO("critnib_new"); } /* @@ -77,7 +77,7 @@ lane_info_ht_boot(void) int result = os_tls_set(Lane_info_key, Lane_info_ht); if (result != 0) { errno = result; - FATAL("!os_tls_set"); + FATAL_W_ERRNO("os_tls_set"); } } @@ -102,7 +102,7 @@ lane_info_boot(void) int result = os_tls_key_create(&Lane_info_key, lane_info_ht_destroy); if (result != 0) { errno = result; - FATAL("!os_tls_key_create"); + FATAL_W_ERRNO("os_tls_key_create"); } } @@ -479,7 +479,7 @@ get_lane_info_record(PMEMobjpool *pop) if (unlikely(info == NULL)) { info = Malloc(sizeof(struct lane_info)); if (unlikely(info == NULL)) { - FATAL("Malloc"); + FATAL_WO_ERRNO("Malloc"); } info->pop_uuid_lo = pop->uuid_lo; info->lane_idx = UINT64_MAX; @@ -495,7 +495,7 @@ get_lane_info_record(PMEMobjpool *pop) if (unlikely(critnib_insert( Lane_info_ht, pop->uuid_lo, info) != 0)) { - FATAL("critnib_insert"); + FATAL_WO_ERRNO("critnib_insert"); } } @@ -551,12 +551,12 @@ lane_release(PMEMobjpool *pop) ASSERTne(lane->lane_idx, UINT64_MAX); if (unlikely(lane->nest_count == 0)) { - FATAL("lane_release"); + FATAL_WO_ERRNO("lane_release"); } else if (--(lane->nest_count) == 0) { if (unlikely(!util_bool_compare_and_swap64( &pop->lanes_desc.lane_locks[lane->lane_idx], 1, 0))) { - FATAL("util_bool_compare_and_swap64"); + FATAL_WO_ERRNO("util_bool_compare_and_swap64"); } } } diff --git a/src/libpmemobj/memblock.c b/src/libpmemobj/memblock.c index 9ad6c2dc063..e3c68bd5650 100644 --- a/src/libpmemobj/memblock.c +++ b/src/libpmemobj/memblock.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2021, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * memblock.c -- implementation of memory block @@ -1103,7 +1103,7 @@ huge_vg_init(const struct memory_block *m, int objects, if (objects && huge_get_state(m) == MEMBLOCK_ALLOCATED) { if (cb(m, arg) != 0) - FATAL("failed to initialize valgrind state"); + FATAL_WO_ERRNO("failed to initialize valgrind state"); } } @@ -1143,7 +1143,7 @@ run_vg_init(const struct memory_block *m, int objects, if (objects) { if (run_iterate_used(m, cb, arg) != 0) - FATAL("failed to initialize valgrind state"); + FATAL_WO_ERRNO("failed to initialize valgrind state"); } } @@ -1463,7 +1463,8 @@ memblock_detect_type(struct palloc_heap *heap, const struct memory_block *m) break; default: /* unreachable */ - FATAL("possible zone chunks metadata corruption"); + FATAL_WO_ERRNO( + "possible zone chunks metadata corruption"); } return ret; } diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index fe9747bc04a..4ebce90182f 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -146,7 +146,7 @@ obj_pool_init(void) if (pools_ht == NULL) { c = critnib_new(); if (c == NULL) - FATAL("!critnib_new for pools_ht"); + FATAL_W_ERRNO("critnib_new for pools_ht"); if (!util_bool_compare_and_swap64(&pools_ht, NULL, c)) critnib_delete(c); } @@ -154,7 +154,7 @@ obj_pool_init(void) if (pools_tree == NULL) { c = critnib_new(); if (c == NULL) - FATAL("!critnib_new for pools_tree"); + FATAL_W_ERRNO("critnib_new for pools_tree"); if (!util_bool_compare_and_swap64(&pools_tree, NULL, c)) critnib_delete(c); } @@ -209,7 +209,7 @@ obj_init(void) pmalloc_global_ctl_register(); if (obj_ctl_init_and_load(NULL)) - FATAL("error: %s", pmemobj_errormsg()); + FATAL_WO_ERRNO("error: %s", pmemobj_errormsg()); lane_info_boot(); } @@ -250,7 +250,7 @@ static void obj_msync_nofail(const void *addr, size_t size) { if (pmem_msync(addr, size)) - FATAL("!pmem_msync"); + FATAL_W_ERRNO("pmem_msync"); } /* diff --git a/src/libpmemobj/palloc.c b/src/libpmemobj/palloc.c index e4aa51cddb9..ee98af180c5 100644 --- a/src/libpmemobj/palloc.c +++ b/src/libpmemobj/palloc.c @@ -301,7 +301,7 @@ palloc_restore_free_chunk_state(struct palloc_heap *heap, HEAP_ARENA_PER_THREAD); if (heap_free_chunk_reuse(heap, b, m) != 0) { if (errno == EEXIST) { - FATAL( + FATAL_WO_ERRNO( "duplicate runtime chunk state, possible double free"); } else { LOG(2, "unable to track runtime chunk state"); diff --git a/src/libpmemobj/sync.h b/src/libpmemobj/sync.h index 46aa1bb221c..3ba37b9f89b 100644 --- a/src/libpmemobj/sync.h +++ b/src/libpmemobj/sync.h @@ -1,5 +1,5 @@ /* SPDX-License-Identifier: BSD-3-Clause */ -/* Copyright 2016-2020, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * sync.h -- internal to obj synchronization API @@ -84,7 +84,7 @@ pmemobj_mutex_lock_nofail(PMEMobjpool *pop, PMEMmutex *mutexp) int ret = pmemobj_mutex_lock(pop, mutexp); if (ret) { errno = ret; - FATAL("!pmemobj_mutex_lock"); + FATAL_W_ERRNO("pmemobj_mutex_lock"); } } @@ -99,7 +99,7 @@ pmemobj_mutex_unlock_nofail(PMEMobjpool *pop, PMEMmutex *mutexp) int ret = pmemobj_mutex_unlock(pop, mutexp); if (ret) { errno = ret; - FATAL("!pmemobj_mutex_unlock"); + FATAL_W_ERRNO("pmemobj_mutex_unlock"); } } diff --git a/src/libpmemobj/tx.c b/src/libpmemobj/tx.c index 6e4f25a230e..f95d7569bd4 100644 --- a/src/libpmemobj/tx.c +++ b/src/libpmemobj/tx.c @@ -158,13 +158,14 @@ obj_tx_fail_null(int errnum, uint64_t flags) /* ASSERT_IN_TX -- checks whether there's open transaction */ #define ASSERT_IN_TX(tx) do {\ if ((tx)->stage == TX_STAGE_NONE)\ - FATAL("%s called outside of transaction", __func__);\ + FATAL_WO_ERRNO("%s called outside of transaction", __func__);\ } while (0) /* ASSERT_TX_STAGE_WORK -- checks whether current transaction stage is WORK */ #define ASSERT_TX_STAGE_WORK(tx) do {\ if ((tx)->stage != TX_STAGE_WORK)\ - FATAL("%s called in invalid stage %d", __func__, (tx)->stage);\ + FATAL_WO_ERRNO("%s called in invalid stage %d",\ + __func__, (tx)->stage);\ } while (0) /* @@ -268,7 +269,7 @@ tx_remove_range(struct txr *tx_ranges, void *begin, void *end) struct tx_range_data *txrn = Malloc(sizeof(*txrn)); if (txrn == NULL) /* we can't do it any other way */ - FATAL("!Malloc"); + FATAL_W_ERRNO("Malloc"); txrn->begin = txr->begin; txrn->end = begin; @@ -280,7 +281,7 @@ tx_remove_range(struct txr *tx_ranges, void *begin, void *end) struct tx_range_data *txrn = Malloc(sizeof(*txrn)); if (txrn == NULL) /* we can't do it any other way */ - FATAL("!Malloc"); + FATAL_W_ERRNO("Malloc"); txrn->begin = end; txrn->end = txr->end; @@ -317,7 +318,7 @@ tx_restore_range(PMEMobjpool *pop, struct tx *tx, struct ulog_entry_buf *range) txr = Malloc(sizeof(*txr)); if (txr == NULL) { /* we can't do it any other way */ - FATAL("!Malloc"); + FATAL_W_ERRNO("Malloc"); } uint64_t range_offset = ulog_entry_offset(&range->base); @@ -570,7 +571,7 @@ tx_lane_ranges_insert_def(PMEMobjpool *pop, struct tx *tx, int ret = ravl_emplace_copy(tx->ranges, rdef); if (ret && errno == EEXIST) - FATAL("invalid state of ranges tree"); + FATAL_WO_ERRNO("invalid state of ranges tree"); return ret; } @@ -765,7 +766,8 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) tx->user_data = NULL; } else { - FATAL("Invalid stage %d to begin new transaction", tx->stage); + FATAL_WO_ERRNO("Invalid stage %d to begin new transaction", + tx->stage); } struct tx_data *txd = Malloc(sizeof(*txd)); @@ -802,8 +804,8 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) if (tx->stage_callback && (tx->stage_callback != cb || tx->stage_callback_arg != arg)) { - FATAL("transaction callback is already set, " - "old %p new %p old_arg %p new_arg %p", + FATAL_WO_ERRNO( + "transaction callback is already set, old %p new %p old_arg %p new_arg %p", tx->stage_callback, cb, tx->stage_callback_arg, arg); } @@ -1044,10 +1046,12 @@ pmemobj_tx_end(void) struct tx *tx = get_tx(); if (tx->stage == TX_STAGE_WORK) - FATAL("pmemobj_tx_end called without pmemobj_tx_commit"); + FATAL_WO_ERRNO( + "pmemobj_tx_end called without pmemobj_tx_commit"); if (tx->pop == NULL) - FATAL("pmemobj_tx_end called without pmemobj_tx_begin"); + FATAL_WO_ERRNO( + "pmemobj_tx_end called without pmemobj_tx_begin"); if (tx->stage_callback && (tx->stage == TX_STAGE_ONCOMMIT || diff --git a/src/libpmempool/check_pool_hdr.c b/src/libpmempool/check_pool_hdr.c index 8475dbf8a94..d6a645cb4be 100644 --- a/src/libpmempool/check_pool_hdr.c +++ b/src/libpmempool/check_pool_hdr.c @@ -852,7 +852,7 @@ init_location_data(PMEMpoolcheck *ppc, location *loc) "replica %u part %u: ", loc->replica, loc->part); if (ret < 0) - FATAL("!snprintf"); + FATAL_W_ERRNO("snprintf"); } else loc->prefix[0] = '\0'; loc->step = 0; diff --git a/src/libpmempool/check_sds.c b/src/libpmempool/check_sds.c index 7844fcf6cb2..a67da1697a1 100644 --- a/src/libpmempool/check_sds.c +++ b/src/libpmempool/check_sds.c @@ -187,7 +187,7 @@ init_prefix(location *loc) "replica %u: ", loc->replica); if (ret < 0) - FATAL("!snprintf"); + FATAL_W_ERRNO("snprintf"); } else loc->prefix[0] = '\0'; loc->step = 0; diff --git a/src/libpmempool/check_util.c b/src/libpmempool/check_util.c index 1d4a8416310..b57962991b8 100644 --- a/src/libpmempool/check_util.c +++ b/src/libpmempool/check_util.c @@ -181,11 +181,11 @@ status_alloc(void) { struct check_status *status = malloc(sizeof(*status)); if (!status) - FATAL("!malloc"); + FATAL_W_ERRNO("malloc"); status->msg = malloc(sizeof(char) * MAX_MSG_STR_SIZE); if (!status->msg) { free(status); - FATAL("!malloc"); + FATAL_W_ERRNO("malloc"); } status->status.str.msg = status->msg; status->answer = PMEMPOOL_CHECK_ANSWER_EMPTY; diff --git a/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c b/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c index ffef2686eb7..22757e1bfcf 100644 --- a/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c +++ b/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2016-2020, Intel Corporation */ +/* Copyright 2016-2024, Intel Corporation */ /* * pmem_is_pmem_posix.c -- Posix specific unit test for pmem_is_pmem() @@ -24,7 +24,7 @@ str2type(char *str) if (strcmp(str, "MAP_SYNC") == 0) return PMEM_MAP_SYNC; - FATAL("unknown type '%s'", str); + FATAL_WO_ERRNO("unknown type '%s'", str); } static int @@ -145,7 +145,7 @@ main(int argc, char *argv[]) i += do_fault_injection_split(addr, len); break; default: - FATAL("invalid op '%c'", argv[i][0]); + FATAL_WO_ERRNO("invalid op '%c'", argv[i][0]); } } From c64c0c96162eafa836834951ed23dd12907a36d5 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 12:53:05 +0100 Subject: [PATCH 2/5] common: replace FATAL* by CORE_LOG_FATAL* Signed-off-by: Tomasz Gromadzki --- src/common/set.c | 4 +- src/common/util_pmem.h | 2 +- src/core/alloc.c | 2 +- src/core/log_default.c | 1 - src/core/log_internal.h | 18 ++++++++- src/core/out.c | 4 +- src/core/out.h | 7 ---- src/core/sys_util.h | 40 +++++++++---------- src/libpmem/pmem.c | 4 +- src/libpmem2/aarch64/init.c | 2 +- src/libpmem2/map_posix.c | 2 +- src/libpmem2/pmem2_utils.c | 2 +- src/libpmem2/source_posix.c | 4 +- src/libpmem2/x86_64/init.c | 2 +- src/libpmemobj/lane.c | 14 +++---- src/libpmemobj/memblock.c | 6 +-- src/libpmemobj/obj.c | 8 ++-- src/libpmemobj/palloc.c | 2 +- src/libpmemobj/sync.h | 4 +- src/libpmemobj/tx.c | 20 +++++----- src/libpmempool/check_pool_hdr.c | 2 +- src/libpmempool/check_sds.c | 2 +- src/libpmempool/check_util.c | 4 +- .../pmem_is_pmem_posix/pmem_is_pmem_posix.c | 4 +- 24 files changed, 84 insertions(+), 76 deletions(-) diff --git a/src/common/set.c b/src/common/set.c index be2415aaaad..621d6e5e2d1 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -217,7 +217,7 @@ util_unmap_hdr(struct pool_set_part *part) VALGRIND_REMOVE_PMEM_MAPPING(part->hdr, part->hdrsize); if (munmap(part->hdr, part->hdrsize) != 0) /* this means there's a bug on the caller side */ - FATAL_W_ERRNO("munmap: %s", part->path); + CORE_LOG_FATAL_W_ERRNO("munmap: %s", part->path); part->hdr = NULL; part->hdrsize = 0; } @@ -2209,7 +2209,7 @@ util_poolset_append_new_part(struct pool_set *set, size_t size) d->path, PMEM_FILE_PADDING, set->next_id, PMEM_EXT); if (util_replica_add_part(&set->replica[r], path, size) != 0) - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "cannot add a new part to the replica info"); } diff --git a/src/common/util_pmem.h b/src/common/util_pmem.h index 76dd0d279a3..743fbc31cc9 100644 --- a/src/common/util_pmem.h +++ b/src/common/util_pmem.h @@ -26,7 +26,7 @@ util_persist(int is_pmem, const void *addr, size_t len) if (is_pmem) pmem_persist(addr, len); else if (pmem_msync(addr, len)) - FATAL_W_ERRNO("pmem_msync"); + CORE_LOG_FATAL_W_ERRNO("pmem_msync"); } /* diff --git a/src/core/alloc.c b/src/core/alloc.c index 6c3d7e16bdb..7d508d8cbf7 100644 --- a/src/core/alloc.c +++ b/src/core/alloc.c @@ -58,7 +58,7 @@ core_inject_fault_at(enum pmem_allocation_type type, int nth, const char *at) fail_realloc_from = at; break; default: - FATAL_WO_ERRNO("unknown allocation type"); + CORE_LOG_FATAL("unknown allocation type"); } } diff --git a/src/core/log_default.c b/src/core/log_default.c index 353fc2dc76e..a0715da3b92 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -6,7 +6,6 @@ * to syslog or to stderr */ -#define _GNU_SOURCE #include #include #include diff --git a/src/core/log_internal.h b/src/core/log_internal.h index b8b01b8f8c0..3117b0d9d7e 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -8,6 +8,10 @@ #ifndef CORE_LOG_INTERNAL_H #define CORE_LOG_INTERNAL_H +#if !defined(_GNU_SOURCE) +#define _GNU_SOURCE +#endif + #include #include #include @@ -137,7 +141,19 @@ void core_log_default_function(void *context, enum core_log_level level, CORE_LOG(CORE_LOG_LEVEL_ERROR, format, ##__VA_ARGS__) #define CORE_LOG_FATAL(format, ...) \ - CORE_LOG(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__) + do { \ + CORE_LOG(CORE_LOG_LEVEL_FATAL, format, ##__VA_ARGS__); \ + abort(); \ + } while (0) + +#define CORE_LOG_MAX_ERR_MSG 128 +#define CORE_LOG_FATAL_W_ERRNO(format, ...) \ + do { \ + char buff[CORE_LOG_MAX_ERR_MSG]; \ + CORE_LOG(CORE_LOG_LEVEL_FATAL, format ": %s", ##__VA_ARGS__, \ + strerror_r(errno, buff, CORE_LOG_MAX_ERR_MSG)); \ + abort(); \ + } while (0) #define CORE_LOG_ALWAYS(format, ...) \ CORE_LOG(CORE_LOG_LEVEL_ALWAYS, format, ##__VA_ARGS__) diff --git a/src/core/out.c b/src/core/out.c index ad51b320c61..dc80e53ccae 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -48,7 +48,7 @@ _Last_errormsg_key_alloc(void) { int pth_ret = os_tls_key_create(&Last_errormsg_key, free); if (pth_ret) - FATAL_W_ERRNO("os_thread_key_create"); + CORE_LOG_FATAL_W_ERRNO("os_thread_key_create"); VALGRIND_ANNOTATE_HAPPENS_BEFORE(&Last_errormsg_key_once); } @@ -89,7 +89,7 @@ Last_errormsg_get(void) errormsg->msg[0] = '\0'; int ret = os_tls_set(Last_errormsg_key, errormsg); if (ret) - FATAL_W_ERRNO("os_tls_set"); + CORE_LOG_FATAL_W_ERRNO("os_tls_set"); } return errormsg; } diff --git a/src/core/out.h b/src/core/out.h index f5227991ba9..33d30315e50 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -116,13 +116,6 @@ out_fatal_abort(const char *file, int line, const char *func, OUT_NONL(level, __VA_ARGS__); \ } while (0) -/* produce output and exit */ -#define FATAL_WO_ERRNO(...)\ - OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, __VA_ARGS__) - -#define FATAL_W_ERRNO(...)\ - OUT_FATAL_ABORT(__FILE__, __LINE__, __func__, "!" __VA_ARGS__) - /* assert a condition is true at runtime */ #define ASSERT_rt(cnd) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ diff --git a/src/core/sys_util.h b/src/core/sys_util.h index 80d880e90a5..931c73e4cdb 100644 --- a/src/core/sys_util.h +++ b/src/core/sys_util.h @@ -28,7 +28,7 @@ util_mutex_init(os_mutex_t *m) int tmp = os_mutex_init(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_mutex_init"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_init"); } } @@ -43,7 +43,7 @@ util_mutex_destroy(os_mutex_t *m) int tmp = os_mutex_destroy(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_mutex_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_destroy"); } } @@ -58,7 +58,7 @@ util_mutex_lock(os_mutex_t *m) int tmp = os_mutex_lock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_mutex_lock"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_lock"); } } @@ -74,7 +74,7 @@ util_mutex_trylock(os_mutex_t *m) int tmp = os_mutex_trylock(m); if (tmp && tmp != EBUSY) { errno = tmp; - FATAL_W_ERRNO("os_mutex_trylock"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_trylock"); } return tmp; } @@ -90,7 +90,7 @@ util_mutex_unlock(os_mutex_t *m) int tmp = os_mutex_unlock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_mutex_unlock"); + CORE_LOG_FATAL_W_ERRNO("os_mutex_unlock"); } } @@ -105,7 +105,7 @@ util_rwlock_init(os_rwlock_t *m) int tmp = os_rwlock_init(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_init"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_init"); } } @@ -120,7 +120,7 @@ util_rwlock_rdlock(os_rwlock_t *m) int tmp = os_rwlock_rdlock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_rdlock"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_rdlock"); } } @@ -135,7 +135,7 @@ util_rwlock_wrlock(os_rwlock_t *m) int tmp = os_rwlock_wrlock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_wrlock"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_wrlock"); } } @@ -150,7 +150,7 @@ util_rwlock_unlock(os_rwlock_t *m) int tmp = os_rwlock_unlock(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_unlock"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_unlock"); } } @@ -165,7 +165,7 @@ util_rwlock_destroy(os_rwlock_t *m) int tmp = os_rwlock_destroy(m); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_rwlock_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_rwlock_destroy"); } } @@ -194,7 +194,7 @@ util_spin_destroy(os_spinlock_t *lock) int tmp = os_spin_destroy(lock); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_spin_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_spin_destroy"); } } @@ -208,7 +208,7 @@ util_spin_lock(os_spinlock_t *lock) int tmp = os_spin_lock(lock); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_spin_lock"); + CORE_LOG_FATAL_W_ERRNO("os_spin_lock"); } } @@ -223,7 +223,7 @@ util_spin_unlock(os_spinlock_t *lock) int tmp = os_spin_unlock(lock); if (tmp) { errno = tmp; - FATAL_W_ERRNO("os_spin_unlock"); + CORE_LOG_FATAL_W_ERRNO("os_spin_unlock"); } } @@ -236,7 +236,7 @@ static inline void util_semaphore_init(os_semaphore_t *sem, unsigned value) { if (os_semaphore_init(sem, value)) - FATAL_W_ERRNO("os_semaphore_init"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_init"); } /* @@ -246,7 +246,7 @@ static inline void util_semaphore_destroy(os_semaphore_t *sem) { if (os_semaphore_destroy(sem) != 0) - FATAL_W_ERRNO("os_semaphore_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_destroy"); } /* @@ -263,7 +263,7 @@ util_semaphore_wait(os_semaphore_t *sem) } while (errno == EINTR); /* signal interrupt */ if (ret != 0) - FATAL_W_ERRNO("os_semaphore_wait"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_wait"); } /* @@ -279,7 +279,7 @@ util_semaphore_trywait(os_semaphore_t *sem) } while (errno == EINTR); /* signal interrupt */ if (ret != 0 && errno != EAGAIN) - FATAL_W_ERRNO("os_semaphore_trywait"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_trywait"); return ret; } @@ -291,21 +291,21 @@ static inline void util_semaphore_post(os_semaphore_t *sem) { if (os_semaphore_post(sem) != 0) - FATAL_W_ERRNO("os_semaphore_post"); + CORE_LOG_FATAL_W_ERRNO("os_semaphore_post"); } static inline void util_cond_init(os_cond_t *__restrict cond) { if (os_cond_init(cond)) - FATAL_W_ERRNO("os_cond_init"); + CORE_LOG_FATAL_W_ERRNO("os_cond_init"); } static inline void util_cond_destroy(os_cond_t *__restrict cond) { if (os_cond_destroy(cond)) - FATAL_W_ERRNO("os_cond_destroy"); + CORE_LOG_FATAL_W_ERRNO("os_cond_destroy"); } #ifdef __cplusplus diff --git a/src/libpmem/pmem.c b/src/libpmem/pmem.c index 49ae318facb..931ae63b550 100644 --- a/src/libpmem/pmem.c +++ b/src/libpmem/pmem.c @@ -359,7 +359,7 @@ pmem_is_pmem_init(void) Is_pmem = is_pmem_never; if (!util_bool_compare_and_swap32(&init, 1, 2)) - FATAL_WO_ERRNO("util_bool_compare_and_swap32"); + CORE_LOG_FATAL("util_bool_compare_and_swap32"); } } @@ -911,7 +911,7 @@ pmem_init(void) if (Funcs.flush == flush_empty) LOG(3, "not flushing CPU cache"); else if (Funcs.flush != Funcs.deep_flush) - FATAL_WO_ERRNO("invalid flush function address"); + CORE_LOG_FATAL("invalid flush function address"); pmem_os_init(&Is_pmem); } diff --git a/src/libpmem2/aarch64/init.c b/src/libpmem2/aarch64/init.c index 21cf6c0bfdd..d4dd8812b21 100644 --- a/src/libpmem2/aarch64/init.c +++ b/src/libpmem2/aarch64/init.c @@ -85,5 +85,5 @@ pmem2_arch_init(struct pmem2_arch_info *info) else if (info->flush == flush_pop) LOG(3, "Synchronize VA to pop for ARM"); else - FATAL_WO_ERRNO("invalid deep flush function address"); + CORE_LOG_FATAL("invalid deep flush function address"); } diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index fa886a58e20..cab0d705e4a 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -484,7 +484,7 @@ pmem2_map_new(struct pmem2_map **map_ptr, const struct pmem2_config *cfg, [cfg->requested_max_granularity] [available_min_granularity]; if (strcmp(err, GRAN_IMPOSSIBLE) == 0) - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "unhandled granularity error: available_min_granularity: %d" \ "requested_max_granularity: %d", available_min_granularity, diff --git a/src/libpmem2/pmem2_utils.c b/src/libpmem2/pmem2_utils.c index b9c0b3bd9c3..19cfc5c9c56 100644 --- a/src/libpmem2/pmem2_utils.c +++ b/src/libpmem2/pmem2_utils.c @@ -67,7 +67,7 @@ int pmem2_err_to_errno(int err) { if (err > 0) - FATAL_WO_ERRNO("positive error code is a bug in libpmem2"); + CORE_LOG_FATAL("positive error code is a bug in libpmem2"); if (err == PMEM2_E_NOSUPP) return ENOTSUP; diff --git a/src/libpmem2/source_posix.c b/src/libpmem2/source_posix.c index 4f36c1cef18..346623d770d 100644 --- a/src/libpmem2/source_posix.c +++ b/src/libpmem2/source_posix.c @@ -126,7 +126,7 @@ pmem2_source_size(const struct pmem2_source *src, size_t *size) *size = (size_t)st.st_size; break; default: - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "BUG: unhandled file type in pmem2_source_size"); } @@ -162,7 +162,7 @@ pmem2_source_alignment(const struct pmem2_source *src, size_t *alignment) *alignment = Pagesize; break; default: - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "BUG: unhandled file type in pmem2_source_alignment"); } diff --git a/src/libpmem2/x86_64/init.c b/src/libpmem2/x86_64/init.c index 95b9e84b705..66867f2e84d 100644 --- a/src/libpmem2/x86_64/init.c +++ b/src/libpmem2/x86_64/init.c @@ -585,7 +585,7 @@ pmem2_arch_init(struct pmem2_arch_info *info) else if (info->flush == flush_clflush) LOG(3, "using clflush"); else - FATAL_WO_ERRNO("invalid deep flush function address"); + CORE_LOG_FATAL("invalid deep flush function address"); if (impl == MEMCPY_MOVDIR64B) LOG(3, "using movnt MOVDIR64B"); diff --git a/src/libpmemobj/lane.c b/src/libpmemobj/lane.c index 6210b27ddd1..0dcdbe59ccd 100644 --- a/src/libpmemobj/lane.c +++ b/src/libpmemobj/lane.c @@ -40,7 +40,7 @@ lane_info_create(void) { Lane_info_ht = critnib_new(); if (Lane_info_ht == NULL) - FATAL_WO_ERRNO("critnib_new"); + CORE_LOG_FATAL("critnib_new"); } /* @@ -77,7 +77,7 @@ lane_info_ht_boot(void) int result = os_tls_set(Lane_info_key, Lane_info_ht); if (result != 0) { errno = result; - FATAL_W_ERRNO("os_tls_set"); + CORE_LOG_FATAL_W_ERRNO("os_tls_set"); } } @@ -102,7 +102,7 @@ lane_info_boot(void) int result = os_tls_key_create(&Lane_info_key, lane_info_ht_destroy); if (result != 0) { errno = result; - FATAL_W_ERRNO("os_tls_key_create"); + CORE_LOG_FATAL_W_ERRNO("os_tls_key_create"); } } @@ -479,7 +479,7 @@ get_lane_info_record(PMEMobjpool *pop) if (unlikely(info == NULL)) { info = Malloc(sizeof(struct lane_info)); if (unlikely(info == NULL)) { - FATAL_WO_ERRNO("Malloc"); + CORE_LOG_FATAL("Malloc"); } info->pop_uuid_lo = pop->uuid_lo; info->lane_idx = UINT64_MAX; @@ -495,7 +495,7 @@ get_lane_info_record(PMEMobjpool *pop) if (unlikely(critnib_insert( Lane_info_ht, pop->uuid_lo, info) != 0)) { - FATAL_WO_ERRNO("critnib_insert"); + CORE_LOG_FATAL("critnib_insert"); } } @@ -551,12 +551,12 @@ lane_release(PMEMobjpool *pop) ASSERTne(lane->lane_idx, UINT64_MAX); if (unlikely(lane->nest_count == 0)) { - FATAL_WO_ERRNO("lane_release"); + CORE_LOG_FATAL("lane_release"); } else if (--(lane->nest_count) == 0) { if (unlikely(!util_bool_compare_and_swap64( &pop->lanes_desc.lane_locks[lane->lane_idx], 1, 0))) { - FATAL_WO_ERRNO("util_bool_compare_and_swap64"); + CORE_LOG_FATAL("util_bool_compare_and_swap64"); } } } diff --git a/src/libpmemobj/memblock.c b/src/libpmemobj/memblock.c index e3c68bd5650..ee5dc7141c5 100644 --- a/src/libpmemobj/memblock.c +++ b/src/libpmemobj/memblock.c @@ -1103,7 +1103,7 @@ huge_vg_init(const struct memory_block *m, int objects, if (objects && huge_get_state(m) == MEMBLOCK_ALLOCATED) { if (cb(m, arg) != 0) - FATAL_WO_ERRNO("failed to initialize valgrind state"); + CORE_LOG_FATAL("failed to initialize valgrind state"); } } @@ -1143,7 +1143,7 @@ run_vg_init(const struct memory_block *m, int objects, if (objects) { if (run_iterate_used(m, cb, arg) != 0) - FATAL_WO_ERRNO("failed to initialize valgrind state"); + CORE_LOG_FATAL("failed to initialize valgrind state"); } } @@ -1463,7 +1463,7 @@ memblock_detect_type(struct palloc_heap *heap, const struct memory_block *m) break; default: /* unreachable */ - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "possible zone chunks metadata corruption"); } return ret; diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index 4ebce90182f..ef8a2c2298d 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -146,7 +146,7 @@ obj_pool_init(void) if (pools_ht == NULL) { c = critnib_new(); if (c == NULL) - FATAL_W_ERRNO("critnib_new for pools_ht"); + CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_ht"); if (!util_bool_compare_and_swap64(&pools_ht, NULL, c)) critnib_delete(c); } @@ -154,7 +154,7 @@ obj_pool_init(void) if (pools_tree == NULL) { c = critnib_new(); if (c == NULL) - FATAL_W_ERRNO("critnib_new for pools_tree"); + CORE_LOG_FATAL_W_ERRNO("critnib_new for pools_tree"); if (!util_bool_compare_and_swap64(&pools_tree, NULL, c)) critnib_delete(c); } @@ -209,7 +209,7 @@ obj_init(void) pmalloc_global_ctl_register(); if (obj_ctl_init_and_load(NULL)) - FATAL_WO_ERRNO("error: %s", pmemobj_errormsg()); + CORE_LOG_FATAL("error: %s", pmemobj_errormsg()); lane_info_boot(); } @@ -250,7 +250,7 @@ static void obj_msync_nofail(const void *addr, size_t size) { if (pmem_msync(addr, size)) - FATAL_W_ERRNO("pmem_msync"); + CORE_LOG_FATAL_W_ERRNO("pmem_msync"); } /* diff --git a/src/libpmemobj/palloc.c b/src/libpmemobj/palloc.c index ee98af180c5..bbce59dff68 100644 --- a/src/libpmemobj/palloc.c +++ b/src/libpmemobj/palloc.c @@ -301,7 +301,7 @@ palloc_restore_free_chunk_state(struct palloc_heap *heap, HEAP_ARENA_PER_THREAD); if (heap_free_chunk_reuse(heap, b, m) != 0) { if (errno == EEXIST) { - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "duplicate runtime chunk state, possible double free"); } else { LOG(2, "unable to track runtime chunk state"); diff --git a/src/libpmemobj/sync.h b/src/libpmemobj/sync.h index 3ba37b9f89b..bc206826c16 100644 --- a/src/libpmemobj/sync.h +++ b/src/libpmemobj/sync.h @@ -84,7 +84,7 @@ pmemobj_mutex_lock_nofail(PMEMobjpool *pop, PMEMmutex *mutexp) int ret = pmemobj_mutex_lock(pop, mutexp); if (ret) { errno = ret; - FATAL_W_ERRNO("pmemobj_mutex_lock"); + CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_lock"); } } @@ -99,7 +99,7 @@ pmemobj_mutex_unlock_nofail(PMEMobjpool *pop, PMEMmutex *mutexp) int ret = pmemobj_mutex_unlock(pop, mutexp); if (ret) { errno = ret; - FATAL_W_ERRNO("pmemobj_mutex_unlock"); + CORE_LOG_FATAL_W_ERRNO("pmemobj_mutex_unlock"); } } diff --git a/src/libpmemobj/tx.c b/src/libpmemobj/tx.c index f95d7569bd4..f9fe29de58d 100644 --- a/src/libpmemobj/tx.c +++ b/src/libpmemobj/tx.c @@ -158,13 +158,13 @@ obj_tx_fail_null(int errnum, uint64_t flags) /* ASSERT_IN_TX -- checks whether there's open transaction */ #define ASSERT_IN_TX(tx) do {\ if ((tx)->stage == TX_STAGE_NONE)\ - FATAL_WO_ERRNO("%s called outside of transaction", __func__);\ + CORE_LOG_FATAL("%s called outside of transaction", __func__);\ } while (0) /* ASSERT_TX_STAGE_WORK -- checks whether current transaction stage is WORK */ #define ASSERT_TX_STAGE_WORK(tx) do {\ if ((tx)->stage != TX_STAGE_WORK)\ - FATAL_WO_ERRNO("%s called in invalid stage %d",\ + CORE_LOG_FATAL("%s called in invalid stage %d",\ __func__, (tx)->stage);\ } while (0) @@ -269,7 +269,7 @@ tx_remove_range(struct txr *tx_ranges, void *begin, void *end) struct tx_range_data *txrn = Malloc(sizeof(*txrn)); if (txrn == NULL) /* we can't do it any other way */ - FATAL_W_ERRNO("Malloc"); + CORE_LOG_FATAL_W_ERRNO("Malloc"); txrn->begin = txr->begin; txrn->end = begin; @@ -281,7 +281,7 @@ tx_remove_range(struct txr *tx_ranges, void *begin, void *end) struct tx_range_data *txrn = Malloc(sizeof(*txrn)); if (txrn == NULL) /* we can't do it any other way */ - FATAL_W_ERRNO("Malloc"); + CORE_LOG_FATAL_W_ERRNO("Malloc"); txrn->begin = end; txrn->end = txr->end; @@ -318,7 +318,7 @@ tx_restore_range(PMEMobjpool *pop, struct tx *tx, struct ulog_entry_buf *range) txr = Malloc(sizeof(*txr)); if (txr == NULL) { /* we can't do it any other way */ - FATAL_W_ERRNO("Malloc"); + CORE_LOG_FATAL_W_ERRNO("Malloc"); } uint64_t range_offset = ulog_entry_offset(&range->base); @@ -571,7 +571,7 @@ tx_lane_ranges_insert_def(PMEMobjpool *pop, struct tx *tx, int ret = ravl_emplace_copy(tx->ranges, rdef); if (ret && errno == EEXIST) - FATAL_WO_ERRNO("invalid state of ranges tree"); + CORE_LOG_FATAL("invalid state of ranges tree"); return ret; } @@ -766,7 +766,7 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) tx->user_data = NULL; } else { - FATAL_WO_ERRNO("Invalid stage %d to begin new transaction", + CORE_LOG_FATAL("Invalid stage %d to begin new transaction", tx->stage); } @@ -804,7 +804,7 @@ pmemobj_tx_begin(PMEMobjpool *pop, jmp_buf env, ...) if (tx->stage_callback && (tx->stage_callback != cb || tx->stage_callback_arg != arg)) { - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "transaction callback is already set, old %p new %p old_arg %p new_arg %p", tx->stage_callback, cb, tx->stage_callback_arg, arg); @@ -1046,11 +1046,11 @@ pmemobj_tx_end(void) struct tx *tx = get_tx(); if (tx->stage == TX_STAGE_WORK) - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "pmemobj_tx_end called without pmemobj_tx_commit"); if (tx->pop == NULL) - FATAL_WO_ERRNO( + CORE_LOG_FATAL( "pmemobj_tx_end called without pmemobj_tx_begin"); if (tx->stage_callback && diff --git a/src/libpmempool/check_pool_hdr.c b/src/libpmempool/check_pool_hdr.c index d6a645cb4be..7a5500570d9 100644 --- a/src/libpmempool/check_pool_hdr.c +++ b/src/libpmempool/check_pool_hdr.c @@ -852,7 +852,7 @@ init_location_data(PMEMpoolcheck *ppc, location *loc) "replica %u part %u: ", loc->replica, loc->part); if (ret < 0) - FATAL_W_ERRNO("snprintf"); + CORE_LOG_FATAL_W_ERRNO("snprintf"); } else loc->prefix[0] = '\0'; loc->step = 0; diff --git a/src/libpmempool/check_sds.c b/src/libpmempool/check_sds.c index a67da1697a1..3ffc87bb985 100644 --- a/src/libpmempool/check_sds.c +++ b/src/libpmempool/check_sds.c @@ -187,7 +187,7 @@ init_prefix(location *loc) "replica %u: ", loc->replica); if (ret < 0) - FATAL_W_ERRNO("snprintf"); + CORE_LOG_FATAL_W_ERRNO("snprintf"); } else loc->prefix[0] = '\0'; loc->step = 0; diff --git a/src/libpmempool/check_util.c b/src/libpmempool/check_util.c index b57962991b8..5611fc51308 100644 --- a/src/libpmempool/check_util.c +++ b/src/libpmempool/check_util.c @@ -181,11 +181,11 @@ status_alloc(void) { struct check_status *status = malloc(sizeof(*status)); if (!status) - FATAL_W_ERRNO("malloc"); + CORE_LOG_FATAL_W_ERRNO("malloc"); status->msg = malloc(sizeof(char) * MAX_MSG_STR_SIZE); if (!status->msg) { free(status); - FATAL_W_ERRNO("malloc"); + CORE_LOG_FATAL_W_ERRNO("malloc"); } status->status.str.msg = status->msg; status->answer = PMEMPOOL_CHECK_ANSWER_EMPTY; diff --git a/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c b/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c index 22757e1bfcf..fae84bbc5cb 100644 --- a/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c +++ b/src/test/pmem_is_pmem_posix/pmem_is_pmem_posix.c @@ -24,7 +24,7 @@ str2type(char *str) if (strcmp(str, "MAP_SYNC") == 0) return PMEM_MAP_SYNC; - FATAL_WO_ERRNO("unknown type '%s'", str); + CORE_LOG_FATAL("unknown type '%s'", str); } static int @@ -145,7 +145,7 @@ main(int argc, char *argv[]) i += do_fault_injection_split(addr, len); break; default: - FATAL_WO_ERRNO("invalid op '%c'", argv[i][0]); + CORE_LOG_FATAL("invalid op '%c'", argv[i][0]); } } From f9df2013e36a386a3edb160fb4bddef98f074297 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 13:02:14 +0100 Subject: [PATCH 3/5] common: remove old FATAL implementation Signed-off-by: Tomasz Gromadzki --- src/core/out.c | 17 ----------------- src/core/out.h | 10 ++++------ utils/call_stacks_analysis/white_list.json | 1 - 3 files changed, 4 insertions(+), 24 deletions(-) diff --git a/src/core/out.c b/src/core/out.c index dc80e53ccae..ff8c9db027b 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -491,23 +491,6 @@ out_log(const char *file, int line, const char *func, int level, va_end(ap); } -/* - * out_fatal -- output a fatal error & die (i.e. assertion failure) - */ -void -out_fatal(const char *file, int line, const char *func, - const char *fmt, ...) -{ - va_list ap; - va_start(ap, fmt); - - out_common(file, line, func, 1, "\n", fmt, ap); - - va_end(ap); - - abort(); -} - /* * out_err -- output an error message */ diff --git a/src/core/out.h b/src/core/out.h index 33d30315e50..99ff4353d61 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -43,8 +43,6 @@ extern "C" { #define OUT_LOG out_log #define OUT_NONL out_nonl -#define OUT_FATAL out_fatal -#define OUT_FATAL_ABORT out_fatal #else @@ -119,20 +117,20 @@ out_fatal_abort(const char *file, int line, const char *func, /* assert a condition is true at runtime */ #define ASSERT_rt(cnd) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ - OUT_FATAL(__FILE__, __LINE__, __func__, "assertion failure: %s", #cnd);\ + CORE_LOG_FATAL("assertion failure: %s", #cnd);\ } while (0) /* assertion with extra info printed if assertion fails at runtime */ #define ASSERTinfo_rt(cnd, info) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ - OUT_FATAL(__FILE__, __LINE__, __func__, \ + CORE_LOG_FATAL( \ "assertion failure: %s (%s = %s)", #cnd, #info, info);\ } while (0) /* assert two integer values are equal at runtime */ #define ASSERTeq_rt(lhs, rhs) do { \ if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) == (rhs))) break; \ - OUT_FATAL(__FILE__, __LINE__, __func__,\ + CORE_LOG_FATAL(\ "assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs,\ (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) @@ -140,7 +138,7 @@ out_fatal_abort(const char *file, int line, const char *func, /* assert two integer values are not equal at runtime */ #define ASSERTne_rt(lhs, rhs) do { \ if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) != (rhs))) break; \ - OUT_FATAL(__FILE__, __LINE__, __func__,\ + CORE_LOG_FATAL(\ "assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) diff --git a/utils/call_stacks_analysis/white_list.json b/utils/call_stacks_analysis/white_list.json index 9031d208c59..89c7cacd11a 100644 --- a/utils/call_stacks_analysis/white_list.json +++ b/utils/call_stacks_analysis/white_list.json @@ -125,7 +125,6 @@ "os_thread_setaffinity_np", "os_unsetenv", "os_writev", - "out_fatal", "out_log", "out_log_va", "out_nonl", From 5eb4adc74d93772f1c01f8d62af539fd01ba1580 Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 13:12:52 +0100 Subject: [PATCH 4/5] common: assert macros redefinition Signed-off-by: Tomasz Gromadzki --- src/core/out.h | 53 ++++++++++++++++---------------------------------- 1 file changed, 17 insertions(+), 36 deletions(-) diff --git a/src/core/out.h b/src/core/out.h index 99ff4353d61..bc48cffe9a8 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -23,12 +23,6 @@ extern "C" { * Suppress errors which are after appropriate ASSERT* macro for nondebug * builds. */ -#if !defined(DEBUG) && (defined(__clang_analyzer__) || defined(__COVERITY__)) -#define OUT_FATAL_DISCARD_NORETURN __attribute__((noreturn)) -#else -#define OUT_FATAL_DISCARD_NORETURN -#endif - #ifndef EVALUATE_DBG_EXPRESSIONS #if defined(DEBUG) || defined(__clang_analyzer__) || defined(__COVERITY__) ||\ defined(__KLOCWORK__) @@ -61,28 +55,8 @@ out_nonl_discard(int level, const char *fmt, ...) SUPPRESS_UNUSED(level, fmt); } -static __attribute__((always_inline)) OUT_FATAL_DISCARD_NORETURN inline void -out_fatal_discard(const char *file, int line, const char *func, - const char *fmt, ...) -{ - /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(file, line, func, fmt); -} - -static __attribute__((always_inline)) NORETURN inline void -out_fatal_abort(const char *file, int line, const char *func, - const char *fmt, ...) -{ - /* suppress unused-parameter errors */ - SUPPRESS_UNUSED(file, line, func, fmt); - - abort(); -} - #define OUT_LOG out_log_discard #define OUT_NONL out_nonl_discard -#define OUT_FATAL out_fatal_discard -#define OUT_FATAL_ABORT out_fatal_abort #endif @@ -115,6 +89,7 @@ out_fatal_abort(const char *file, int line, const char *func, } while (0) /* assert a condition is true at runtime */ +#if defined(DEBUG) #define ASSERT_rt(cnd) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ CORE_LOG_FATAL("assertion failure: %s", #cnd);\ @@ -123,23 +98,20 @@ out_fatal_abort(const char *file, int line, const char *func, /* assertion with extra info printed if assertion fails at runtime */ #define ASSERTinfo_rt(cnd, info) do { \ if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ - CORE_LOG_FATAL( \ - "assertion failure: %s (%s = %s)", #cnd, #info, info);\ + CORE_LOG_FATAL("assertion failure: %s (%s = %s)", #cnd, #info, info);\ } while (0) /* assert two integer values are equal at runtime */ #define ASSERTeq_rt(lhs, rhs) do { \ if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) == (rhs))) break; \ - CORE_LOG_FATAL(\ - "assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs,\ - (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ + CORE_LOG_FATAL("assertion failure: %s (0x%llx) == %s (0x%llx)", \ + #lhs, (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) /* assert two integer values are not equal at runtime */ #define ASSERTne_rt(lhs, rhs) do { \ if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) != (rhs))) break; \ - CORE_LOG_FATAL(\ - "assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ + CORE_LOG_FATAL("assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) @@ -177,9 +149,18 @@ out_fatal_abort(const char *file, int line, const char *func, TEST_ALWAYS_NE_EXPR(lhs, rhs);\ ASSERTne_rt(lhs, rhs);\ } while (0) - -#define ERR(use_errno, ...)\ - out_err(use_errno, __FILE__, __LINE__, __func__, __VA_ARGS__) +#else +#define ASSERT_rt(cnd) +#define ASSERTinfo_rt(cnd, info) +#define ASSERTeq_rt(lhs, rhs) +#define ASSERTne_rt(lhs, rhs) +#define ASSERT(cnd) +#define ASSERTinfo(cnd, info) +#define ASSERTeq(lhs, rhs) +#define ASSERTne(lhs, rhs) +#endif // #if defined(DEBUG) +#define ERR(...)\ + out_err(__FILE__, __LINE__, __func__, __VA_ARGS__) #define ERR_W_ERRNO(f, ...)\ do {\ From b8f11e952f61f61b75941ec488306468344e28ce Mon Sep 17 00:00:00 2001 From: Tomasz Gromadzki Date: Fri, 26 Jan 2024 15:02:17 +0100 Subject: [PATCH 5/5] common: adjust code for null ASSERT definition in debug Signed-off-by: Tomasz Gromadzki --- src/common/set.c | 2 ++ src/core/log_internal.h | 2 +- src/core/out.h | 27 +++++++++++++----------- src/libpmem2/map_posix.c | 5 ++++- src/libpmem2/mcsafe_ops_posix.c | 18 +++++++++------- src/libpmemobj/alloc_class.c | 6 ++++-- src/libpmemobj/heap.c | 4 ++++ src/libpmemobj/list.c | 2 ++ src/libpmemobj/memops.c | 5 ++++- src/libpmemobj/obj.c | 5 ++++- src/libpmemobj/pmalloc.c | 11 +++++++++- src/libpmemobj/stats.c | 3 +++ src/libpmemobj/ulog.c | 2 ++ src/libpmempool/check_util.c | 2 ++ src/libpmempool/sync.c | 2 ++ src/test/obj_ctl_arenas/obj_ctl_arenas.c | 8 +++---- src/test/pmem2_perror/pmem2_perror.c | 10 +++++++-- 17 files changed, 80 insertions(+), 34 deletions(-) diff --git a/src/common/set.c b/src/common/set.c index 621d6e5e2d1..944d6be97f5 100644 --- a/src/common/set.c +++ b/src/common/set.c @@ -3263,8 +3263,10 @@ util_replica_deep_common(const void *addr, size_t len, struct pool_set *set, addr, len, set, replica_id, flush); struct pool_replica *rep = set->replica[replica_id]; +#ifdef DEBUG /* variables required for ASSERTs below */ uintptr_t rep_start = (uintptr_t)rep->part[0].addr; uintptr_t rep_end = rep_start + rep->repsize; +#endif uintptr_t start = (uintptr_t)addr; uintptr_t end = start + len; diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 3117b0d9d7e..bd6bb124feb 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -8,7 +8,7 @@ #ifndef CORE_LOG_INTERNAL_H #define CORE_LOG_INTERNAL_H -#if !defined(_GNU_SOURCE) +#ifndef _GNU_SOURCE #define _GNU_SOURCE #endif diff --git a/src/core/out.h b/src/core/out.h index bc48cffe9a8..42f15032878 100644 --- a/src/core/out.h +++ b/src/core/out.h @@ -20,7 +20,7 @@ extern "C" { #endif /* - * Suppress errors which are after appropriate ASSERT* macro for nondebug + * Suppress errors messages (LOG()) in non-debug version * builds. */ #ifndef EVALUATE_DBG_EXPRESSIONS @@ -89,30 +89,32 @@ out_nonl_discard(int level, const char *fmt, ...) } while (0) /* assert a condition is true at runtime */ -#if defined(DEBUG) +#if defined(DEBUG) || defined(__clang_analyzer__) || defined(__COVERITY__) ||\ + defined(__KLOCWORK__) #define ASSERT_rt(cnd) do { \ - if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ + if ((cnd)) break; \ CORE_LOG_FATAL("assertion failure: %s", #cnd);\ } while (0) /* assertion with extra info printed if assertion fails at runtime */ #define ASSERTinfo_rt(cnd, info) do { \ - if (!EVALUATE_DBG_EXPRESSIONS || (cnd)) break; \ + if ((cnd)) break; \ CORE_LOG_FATAL("assertion failure: %s (%s = %s)", #cnd, #info, info);\ } while (0) /* assert two integer values are equal at runtime */ #define ASSERTeq_rt(lhs, rhs) do { \ - if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) == (rhs))) break; \ - CORE_LOG_FATAL("assertion failure: %s (0x%llx) == %s (0x%llx)", \ - #lhs, (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ + if ((lhs) == (rhs)) break; \ + CORE_LOG_FATAL( \ + "assertion failure: %s (0x%llx) == %s (0x%llx)", #lhs, \ + (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) /* assert two integer values are not equal at runtime */ #define ASSERTne_rt(lhs, rhs) do { \ - if (!EVALUATE_DBG_EXPRESSIONS || ((lhs) != (rhs))) break; \ + if ((lhs) != (rhs)) break; \ CORE_LOG_FATAL("assertion failure: %s (0x%llx) != %s (0x%llx)", #lhs,\ - (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ + (unsigned long long)(lhs), #rhs, (unsigned long long)(rhs)); \ } while (0) /* assert a condition is true */ @@ -158,9 +160,10 @@ out_nonl_discard(int level, const char *fmt, ...) #define ASSERTinfo(cnd, info) #define ASSERTeq(lhs, rhs) #define ASSERTne(lhs, rhs) -#endif // #if defined(DEBUG) -#define ERR(...)\ - out_err(__FILE__, __LINE__, __func__, __VA_ARGS__) +#endif /* DEBUG */ + +#define ERR(use_errno, ...)\ + out_err(use_errno, __FILE__, __LINE__, __func__, __VA_ARGS__) #define ERR_W_ERRNO(f, ...)\ do {\ diff --git a/src/libpmem2/map_posix.c b/src/libpmem2/map_posix.c index cab0d705e4a..44ffbc130fc 100644 --- a/src/libpmem2/map_posix.c +++ b/src/libpmem2/map_posix.c @@ -266,9 +266,12 @@ unmap(void *addr, size_t len) static int vm_reservation_mend(struct pmem2_vm_reservation *rsv, void *addr, size_t size) { +#ifdef DEBUG /* variables required for ASSERTs below */ void *rsv_addr = pmem2_vm_reservation_get_address(rsv); size_t rsv_size = pmem2_vm_reservation_get_size(rsv); - +#else + SUPPRESS_UNUSED(rsv); +#endif ASSERT((char *)addr >= (char *)rsv_addr && (char *)addr + size <= (char *)rsv_addr + rsv_size); diff --git a/src/libpmem2/mcsafe_ops_posix.c b/src/libpmem2/mcsafe_ops_posix.c index 1da8c1c9200..72a913ba3e8 100644 --- a/src/libpmem2/mcsafe_ops_posix.c +++ b/src/libpmem2/mcsafe_ops_posix.c @@ -163,7 +163,6 @@ static int devdax_read(struct pmem2_source *src, void *buf, size_t size, size_t offset) { int ret; - int clnup_ret; struct pmem2_config *cfg; struct pmem2_map *map; @@ -186,11 +185,13 @@ devdax_read(struct pmem2_source *src, void *buf, size_t size, size_t offset) memcpy_fn(buf, ADDR_SUM(addr, offset), size, 0); - clnup_ret = pmem2_map_delete(&map); +#ifdef DEBUG /* variables required for ASSERTs below */ + int clnup_ret = +#endif + pmem2_map_delete(&map); ASSERTeq(clnup_ret, 0); clnup_cfg_delete: - clnup_ret = pmem2_config_delete(&cfg); - ASSERTeq(clnup_ret, 0); + pmem2_config_delete(&cfg); return ret; } @@ -202,7 +203,6 @@ static int devdax_write(struct pmem2_source *src, void *buf, size_t size, size_t offset) { int ret; - int clnup_ret; struct pmem2_config *cfg; struct pmem2_map *map; @@ -225,11 +225,13 @@ devdax_write(struct pmem2_source *src, void *buf, size_t size, size_t offset) memcpy_fn(ADDR_SUM(addr, offset), buf, size, 0); - clnup_ret = pmem2_map_delete(&map); +#ifdef DEBUG /* variables required for ASSERTs below */ + int clnup_ret = +#endif + pmem2_map_delete(&map); ASSERTeq(clnup_ret, 0); clnup_cfg_delete: - clnup_ret = pmem2_config_delete(&cfg); - ASSERTeq(clnup_ret, 0); + pmem2_config_delete(&cfg); return ret; } diff --git a/src/libpmemobj/alloc_class.c b/src/libpmemobj/alloc_class.c index af261412d46..6b807d64f6d 100644 --- a/src/libpmemobj/alloc_class.c +++ b/src/libpmemobj/alloc_class.c @@ -167,8 +167,10 @@ alloc_class_reservation_clear(struct alloc_class_collection *ac, int id) { LOG(10, NULL); - int ret = util_bool_compare_and_swap64(&ac->aclasses[id], - ACLASS_RESERVED, NULL); +#ifdef DEBUG /* variables required for ASSERTs below */ + int ret = +#endif + util_bool_compare_and_swap64(&ac->aclasses[id], ACLASS_RESERVED, NULL); ASSERT(ret); } diff --git a/src/libpmemobj/heap.c b/src/libpmemobj/heap.c index 1090e607ad6..e71c5513735 100644 --- a/src/libpmemobj/heap.c +++ b/src/libpmemobj/heap.c @@ -741,7 +741,9 @@ heap_reclaim_run(struct palloc_heap *heap, struct memory_block *m, int startup) struct recycler_element e = recycler_element_new(heap, m); if (c == NULL) { +#ifdef DEBUG uint32_t size_idx = m->size_idx; +#endif struct run_bitmap b; m->m_ops->get_bitmap(m, &b); @@ -827,7 +829,9 @@ heap_ensure_zone_reclaimed(struct palloc_heap *heap, uint32_t zone_id) DEFAULT_ALLOC_CLASS_ID, HEAP_ARENA_PER_THREAD); +#ifdef DEBUG /* variables required for ASSERTs below */ struct zone *z = ZID_TO_ZONE(heap->layout, zone_id); +#endif ASSERTeq(z->header.magic, ZONE_HEADER_MAGIC); /* check a second time just to make sure no other thread was first */ diff --git a/src/libpmemobj/list.c b/src/libpmemobj/list.c index bb93f004fb1..af2cfbbd2a0 100644 --- a/src/libpmemobj/list.c +++ b/src/libpmemobj/list.c @@ -202,7 +202,9 @@ list_update_head(PMEMobjpool *pop, static void u64_add_offset(uint64_t *value, ssize_t off) { +#ifdef DEBUG /* variables required for ASSERTs below */ uint64_t prev = *value; +#endif if (off >= 0) { *value += (size_t)off; ASSERT(*value >= prev); /* detect overflow */ diff --git a/src/libpmemobj/memops.c b/src/libpmemobj/memops.c index a321e83b611..f9c630b4f19 100644 --- a/src/libpmemobj/memops.c +++ b/src/libpmemobj/memops.c @@ -466,7 +466,10 @@ operation_add_buffer(struct operation_context *ctx, ulog_clobber_entry(next_entry, ctx->p_ops); /* create a persistent log entry */ - struct ulog_entry_buf *e = ulog_entry_buf_create(ctx->ulog_curr, +#ifdef DEBUG /* variables required for ASSERTs below */ + struct ulog_entry_buf *e = +#endif + ulog_entry_buf_create(ctx->ulog_curr, ctx->ulog_curr_offset, ctx->ulog_curr_gen_num, dest, src, data_size, diff --git a/src/libpmemobj/obj.c b/src/libpmemobj/obj.c index ef8a2c2298d..6849ff47102 100644 --- a/src/libpmemobj/obj.c +++ b/src/libpmemobj/obj.c @@ -1001,7 +1001,10 @@ obj_runtime_init(PMEMobjpool *pop, int rdonly, int boot, unsigned nlanes) util_mutex_destroy(&pop->ulog_user_buffers.lock); ctl_delete(pop->ctl); err_ctl:; - void *n = critnib_remove(pools_tree, (uint64_t)pop); +#ifdef DEBUG /* variables required for ASSERTs below */ + void *n = +#endif + critnib_remove(pools_tree, (uint64_t)pop); ASSERTne(n, NULL); err_tree_insert: critnib_remove(pools_ht, pop->uuid_lo); diff --git a/src/libpmemobj/pmalloc.c b/src/libpmemobj/pmalloc.c index 1678710eb5e..9956538b3ce 100644 --- a/src/libpmemobj/pmalloc.c +++ b/src/libpmemobj/pmalloc.c @@ -166,7 +166,10 @@ pfree(PMEMobjpool *pop, uint64_t *off) struct operation_context *ctx = pmalloc_operation_hold_type(pop, OPERATION_INTERNAL, 1); - int ret = palloc_operation(&pop->heap, *off, off, 0, NULL, NULL, +#ifdef DEBUG /* variables required for ASSERTs below */ + int ret = +#endif + palloc_operation(&pop->heap, *off, off, 0, NULL, NULL, 0, 0, 0, 0, ctx); ASSERTeq(ret, 0); @@ -326,6 +329,9 @@ pmalloc_header_type_parser(const void *arg, void *dest, size_t dest_size) { const char *vstr = arg; enum pobj_header_type *htype = dest; +#ifndef DEBUG + SUPPRESS_UNUSED(dest_size); +#endif ASSERTeq(dest_size, sizeof(enum pobj_header_type)); if (strcmp(vstr, "none") == 0) { @@ -900,6 +906,9 @@ arenas_assignment_type_parser(const void *arg, void *dest, size_t dest_size) { const char *vstr = arg; enum pobj_arenas_assignment_type *atype = dest; +#ifndef DEBUG + SUPPRESS_UNUSED(dest_size); +#endif ASSERTeq(dest_size, sizeof(enum pobj_header_type)); if (strcmp(vstr, "global") == 0) { diff --git a/src/libpmemobj/stats.c b/src/libpmemobj/stats.c index d1871268c62..1e17b3e3539 100644 --- a/src/libpmemobj/stats.c +++ b/src/libpmemobj/stats.c @@ -49,6 +49,9 @@ stats_enabled_parser(const void *arg, void *dest, size_t dest_size) { const char *vstr = arg; enum pobj_stats_enabled *enabled = dest; +#ifndef DEBUG + SUPPRESS_UNUSED(dest_size); +#endif ASSERTeq(dest_size, sizeof(enum pobj_stats_enabled)); int bool_out; diff --git a/src/libpmemobj/ulog.c b/src/libpmemobj/ulog.c index 54b7f316f42..6d7ab9153d1 100644 --- a/src/libpmemobj/ulog.c +++ b/src/libpmemobj/ulog.c @@ -26,8 +26,10 @@ #define ULOG_OFFSET_MASK (~(ULOG_OPERATION_MASK)) #define CACHELINE_ALIGN(size) ALIGN_UP(size, CACHELINE_SIZE) +#ifdef DEBUG /* variables required for ASSERTs below */ #define IS_CACHELINE_ALIGNED(ptr)\ (((uintptr_t)(ptr) & (CACHELINE_SIZE - 1)) == 0) +#endif /* * ulog_by_offset -- calculates the ulog pointer diff --git a/src/libpmempool/check_util.c b/src/libpmempool/check_util.c index 5611fc51308..d1afc6c44fd 100644 --- a/src/libpmempool/check_util.c +++ b/src/libpmempool/check_util.c @@ -20,7 +20,9 @@ #define MSG_SEPARATOR '|' /* error part of message must have '.' at the end */ +#ifdef DEBUG /* variables required for ASSERTs below */ #define MSG_PLACE_OF_SEPARATION '.' +#endif #define MAX_MSG_STR_SIZE 8192 #define CHECK_ANSWER_YES "yes" diff --git a/src/libpmempool/sync.c b/src/libpmempool/sync.c index bc22068f244..17199a70423 100644 --- a/src/libpmempool/sync.c +++ b/src/libpmempool/sync.c @@ -532,7 +532,9 @@ sync_badblocks_assign_healthy_replica(struct part_health_status *phs, struct bb_vec bbv_new = VEC_INITIALIZER; +#ifdef DEBUG /* variables required for ASSERTs below */ size_t size_all = VEC_SIZE(pbbv_all); +#endif pbb_all = VEC_GET(pbbv_all, *i_all); for (unsigned i = 0; i < phs->bbs.bb_cnt; i++) { diff --git a/src/test/obj_ctl_arenas/obj_ctl_arenas.c b/src/test/obj_ctl_arenas/obj_ctl_arenas.c index ff11bf975bc..7f5cff2d0b8 100644 --- a/src/test/obj_ctl_arenas/obj_ctl_arenas.c +++ b/src/test/obj_ctl_arenas/obj_ctl_arenas.c @@ -1,5 +1,5 @@ // SPDX-License-Identifier: BSD-3-Clause -/* Copyright 2019-2021, Intel Corporation */ +/* Copyright 2019-2024, Intel Corporation */ /* * obj_ctl_arenas.c -- tests for the ctl entry points @@ -215,7 +215,6 @@ worker_arena_threads(void *arg) UT_ASSERTeq(ret, 0); PMEMoid oid[NOBJECT_THREAD]; - unsigned d; for (int i = 0; i < NOBJECT_THREAD; i++) { ret = pmemobj_xalloc(pop, &oid[i], @@ -224,10 +223,9 @@ worker_arena_threads(void *arg) NULL, NULL); UT_ASSERTeq(ret, 0); - d = labs((long)ref->oid.off - (long)oid[i].off); - /* objects are in the same block as the first one */ - ASSERT(d <= alloc_class[ALLOC_CLASS_ARENA].unit_size * + ASSERT(labs((long)ref->oid.off - (long)oid[i].off) <= + alloc_class[ALLOC_CLASS_ARENA].unit_size * (alloc_class[ALLOC_CLASS_ARENA].units_per_block - 1)); } diff --git a/src/test/pmem2_perror/pmem2_perror.c b/src/test/pmem2_perror/pmem2_perror.c index 65de96605d6..45cb08b3a9d 100644 --- a/src/test/pmem2_perror/pmem2_perror.c +++ b/src/test/pmem2_perror/pmem2_perror.c @@ -98,7 +98,10 @@ test_fail_pmem2_syscall_simple(const struct test_case *tc, src.value.fd = -1; /* "randomly" chosen function to be failed */ - int ret = pmem2_source_size(&src, &size); +#ifdef DEBUG /* variables required for ASSERTs below */ + int ret = +#endif + pmem2_source_size(&src, &size); ASSERTne(ret, 0); pmem2_perror("test"); @@ -121,7 +124,10 @@ test_fail_pmem2_syscall_format(const struct test_case *tc, src.value.fd = -1; /* "randomly" chosen function to be failed */ - int ret = pmem2_source_size(&src, &size); +#ifdef DEBUG /* variables required for ASSERTs below */ + int ret = +#endif + pmem2_source_size(&src, &size); ASSERTne(ret, 0); pmem2_perror("test %d", 123);