Skip to content

Commit

Permalink
Replace ASSERTV macro with compiler annotation
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Macy <[email protected]>
  • Loading branch information
mattmacy committed Dec 4, 2019
1 parent 5a08977 commit e2e9a52
Show file tree
Hide file tree
Showing 28 changed files with 64 additions and 61 deletions.
2 changes: 1 addition & 1 deletion cmd/zdb/zdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -4664,7 +4664,7 @@ zdb_leak_fini(spa_t *spa, zdb_cb_t *zcb)
vdev_t *rvd = spa->spa_root_vdev;
for (unsigned c = 0; c < rvd->vdev_children; c++) {
vdev_t *vd = rvd->vdev_child[c];
ASSERTV(metaslab_group_t *mg = vd->vdev_mg);
metaslab_group_t *mg __maybe_unused = vd->vdev_mg;

if (zcb->zcb_vd_obsolete_counts[c] != NULL) {
leaks |= zdb_check_for_obsolete_leaks(vd, zcb);
Expand Down
2 changes: 1 addition & 1 deletion cmd/ztest/ztest.c
Original file line number Diff line number Diff line change
Expand Up @@ -3607,7 +3607,7 @@ ztest_device_removal(ztest_ds_t *zd, uint64_t id)
vdev_t *
grow_vdev(vdev_t *vd, void *arg)
{
ASSERTV(spa_t *spa = vd->vdev_spa);
spa_t *spa __maybe_unused = vd->vdev_spa;
size_t *newsize = arg;
size_t fsize;
int fd;
Expand Down
6 changes: 4 additions & 2 deletions include/os/linux/spl/sys/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
*/
#define __printflike(a, b) __printf(a, b)

#ifndef __maybe_unused
#define __maybe_unused __attribute__((unused))
#endif

int spl_panic(const char *file, const char *func, int line,
const char *fmt, ...);
void spl_dumpstack(void);
Expand Down Expand Up @@ -132,7 +136,6 @@ void spl_dumpstack(void);
#ifdef NDEBUG

#define ASSERT(x) ((void)0)
#define ASSERTV(x)
#define ASSERT3B(x,y,z) ((void)0)
#define ASSERT3S(x,y,z) ((void)0)
#define ASSERT3U(x,y,z) ((void)0)
Expand All @@ -152,7 +155,6 @@ void spl_dumpstack(void);
#define ASSERT3P VERIFY3P
#define ASSERT0 VERIFY0
#define ASSERT VERIFY
#define ASSERTV(x) x
#define IMPLY(A, B) \
((void)(((!(A)) || (B)) || \
spl_panic(__FILE__, __FUNCTION__, __LINE__, \
Expand Down
2 changes: 0 additions & 2 deletions lib/libspl/include/assert.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ do { \
#define ASSERT0(x) ((void)0)
#define ASSERT(x) ((void)0)
#define assert(x) ((void)0)
#define ASSERTV(x)
#define IMPLY(A, B) ((void)0)
#define EQUIV(A, B) ((void)0)
#else
Expand All @@ -156,7 +155,6 @@ do { \
#define ASSERT0 VERIFY0
#define ASSERT VERIFY
#define assert VERIFY
#define ASSERTV(x) x
#define IMPLY(A, B) \
((void)(((!(A)) || (B)) || \
libspl_assert("(" #A ") implies (" #B ")", \
Expand Down
2 changes: 2 additions & 0 deletions lib/libspl/include/sys/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@
#define __printflike(x, y) __attribute__((__format__(__printf__, x, y)))
#endif

#define __maybe_unused __attribute__((unused))

#endif
6 changes: 3 additions & 3 deletions module/os/linux/zfs/zfs_vnops.c
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,9 @@ zfs_write(struct inode *ip, uio_t *uio, int ioflag, cred_t *cr)
uint64_t end_size = MAX(zp->z_size, woff + n);
zilog_t *zilog = zfsvfs->z_log;
#ifdef HAVE_UIO_ZEROCOPY
int i_iov = 0;
const iovec_t *iovp = uio->uio_iov;
ASSERTV(int iovcnt = uio->uio_iovcnt);
int i_iov = 0;
const iovec_t *iovp = uio->uio_iov;
int iovcnt __maybe_unused = uio->uio_iovcnt;
#endif


Expand Down
2 changes: 1 addition & 1 deletion module/zfs/arc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ hdr_full_crypt_dest(void *vbuf, void *unused)
static void
hdr_l2only_dest(void *vbuf, void *unused)
{
ASSERTV(arc_buf_hdr_t *hdr = vbuf);
arc_buf_hdr_t *hdr __maybe_unused = vbuf;

ASSERT(HDR_EMPTY(hdr));
arc_space_return(HDR_L2ONLY_SIZE, ARC_SPACE_L2HDRS);
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/btree.c
Original file line number Diff line number Diff line change
Expand Up @@ -684,8 +684,8 @@ zfs_btree_insert_leaf_impl(zfs_btree_t *tree, zfs_btree_leaf_t *leaf,
uint64_t size = tree->bt_elem_size;
uint8_t *start = leaf->btl_elems + (idx * size);
zfs_btree_hdr_t *hdr = &leaf->btl_hdr;
ASSERTV(uint64_t capacity = P2ALIGN((BTREE_LEAF_SIZE -
sizeof (zfs_btree_hdr_t)) / size, 2));
uint64_t capacity __maybe_unused = P2ALIGN((BTREE_LEAF_SIZE -
sizeof (zfs_btree_hdr_t)) / size, 2);
uint64_t count = leaf->btl_hdr.bth_count - idx;
ASSERT3U(leaf->btl_hdr.bth_count, <, capacity);

Expand Down
10 changes: 5 additions & 5 deletions module/zfs/dbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -986,8 +986,8 @@ dbuf_verify(dmu_buf_impl_t *db)
&dn->dn_phys->dn_blkptr[db->db_blkid]);
} else {
/* db is pointed to by an indirect block */
ASSERTV(int epb = db->db_parent->db.db_size >>
SPA_BLKPTRSHIFT);
int epb __maybe_unused = db->db_parent->db.db_size >>
SPA_BLKPTRSHIFT;
ASSERT3U(db->db_parent->db_level, ==, db->db_level+1);
ASSERT3U(db->db_parent->db.db_object, ==,
db->db.db_object);
Expand Down Expand Up @@ -1881,7 +1881,7 @@ dbuf_new_size(dmu_buf_impl_t *db, int size, dmu_tx_t *tx)
void
dbuf_release_bp(dmu_buf_impl_t *db)
{
ASSERTV(objset_t *os = db->db_objset);
objset_t *os __maybe_unused = db->db_objset;

ASSERT(dsl_pool_sync_context(dmu_objset_pool(os)));
ASSERT(arc_released(os->os_phys_buf) ||
Expand Down Expand Up @@ -4345,8 +4345,8 @@ dbuf_write_done(zio_t *zio, arc_buf_t *buf, void *vdb)
ASSERT(list_head(&dr->dt.di.dr_children) == NULL);
ASSERT3U(db->db.db_size, ==, 1 << dn->dn_phys->dn_indblkshift);
if (!BP_IS_HOLE(db->db_blkptr)) {
ASSERTV(int epbs = dn->dn_phys->dn_indblkshift -
SPA_BLKPTRSHIFT);
int epbs __maybe_unused = dn->dn_phys->dn_indblkshift -
SPA_BLKPTRSHIFT;
ASSERT3U(db->db_blkid, <=,
dn->dn_phys->dn_maxblkid >> (db->db_level * epbs));
ASSERT3U(BP_GET_LSIZE(db->db_blkptr), ==,
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -1768,7 +1768,7 @@ dmu_sync_late_arrival_done(zio_t *zio)
zil_lwb_add_block(zgd->zgd_lwb, zgd->zgd_bp);

if (!BP_IS_HOLE(bp)) {
ASSERTV(blkptr_t *bp_orig = &zio->io_bp_orig);
blkptr_t *bp_orig __maybe_unused = &zio->io_bp_orig;
ASSERT(!(zio->io_flags & ZIO_FLAG_NOPWRITE));
ASSERT(BP_IS_HOLE(bp_orig) || !BP_EQUAL(bp, bp_orig));
ASSERT(zio->io_bp->blk_birth == zio->io_txg);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dnode.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ dnode_stats_t dnode_stats = {
static kstat_t *dnode_ksp;
static kmem_cache_t *dnode_cache;

ASSERTV(static dnode_phys_t dnode_phys_zero);
static dnode_phys_t dnode_phys_zero __maybe_unused;

int zfs_default_bs = SPA_MINBLOCKSHIFT;
int zfs_default_ibs = DN_MAX_INDBLKSHIFT;
Expand Down
8 changes: 4 additions & 4 deletions module/zfs/dnode_sync.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,11 @@ dnode_sync_free_range_impl(dnode_t *dn, uint64_t blkid, uint64_t nblks,
* match.
*/
if (trunc && !dn->dn_objset->os_raw_receive) {
ASSERTV(uint64_t off);
uint64_t off __maybe_unused;
dn->dn_phys->dn_maxblkid = blkid == 0 ? 0 : blkid - 1;

ASSERTV(off = (dn->dn_phys->dn_maxblkid + 1) *
(dn->dn_phys->dn_datablkszsec << SPA_MINBLOCKSHIFT));
off = (dn->dn_phys->dn_maxblkid + 1) *
(dn->dn_phys->dn_datablkszsec << SPA_MINBLOCKSHIFT);
ASSERT(off < dn->dn_phys->dn_maxblkid ||
dn->dn_phys->dn_maxblkid == 0 ||
dnode_next_offset(dn, 0, &off, 1, 1, 0) != 0);
Expand Down Expand Up @@ -628,7 +628,7 @@ dnode_sync(dnode_t *dn, dmu_tx_t *tx)
dnode_phys_t *dnp = dn->dn_phys;
int txgoff = tx->tx_txg & TXG_MASK;
list_t *list = &dn->dn_dirty_records[txgoff];
ASSERTV(static const dnode_phys_t zerodn = { 0 });
static const dnode_phys_t zerodn __maybe_unused = { 0 };
boolean_t kill_spill = B_FALSE;

ASSERT(dmu_tx_is_syncing(tx));
Expand Down
10 changes: 5 additions & 5 deletions module/zfs/dsl_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -1366,7 +1366,7 @@ dsl_dataset_remove_from_next_clones(dsl_dataset_t *ds, uint64_t obj,
dmu_tx_t *tx)
{
objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
ASSERTV(uint64_t count);
uint64_t count __maybe_unused;
int err;

ASSERT(dsl_dataset_phys(ds)->ds_num_children >= 2);
Expand Down Expand Up @@ -1674,8 +1674,8 @@ dsl_dataset_snapshot_sync_impl(dsl_dataset_t *ds, const char *snapname,
dsl_dataset_phys_t *dsphys;
uint64_t dsobj, crtxg;
objset_t *mos = dp->dp_meta_objset;
ASSERTV(static zil_header_t zero_zil);
ASSERTV(objset_t *os);
static zil_header_t zero_zil __maybe_unused;
objset_t *os __maybe_unused;

ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));

Expand Down Expand Up @@ -2843,7 +2843,7 @@ dsl_dataset_stats(dsl_dataset_t *ds, nvlist_t *nv)
void
dsl_dataset_fast_stat(dsl_dataset_t *ds, dmu_objset_stats_t *stat)
{
ASSERTV(dsl_pool_t *dp = ds->ds_dir->dd_pool);
dsl_pool_t *dp __maybe_unused = ds->ds_dir->dd_pool;
ASSERT(dsl_pool_config_held(dp));

stat->dds_creation_txg = dsl_get_creationtxg(ds);
Expand Down Expand Up @@ -2899,7 +2899,7 @@ dsl_dataset_space(dsl_dataset_t *ds,
boolean_t
dsl_dataset_modified_since_snap(dsl_dataset_t *ds, dsl_dataset_t *snap)
{
ASSERTV(dsl_pool_t *dp = ds->ds_dir->dd_pool);
dsl_pool_t *dp __maybe_unused = ds->ds_dir->dd_pool;
uint64_t birth;

ASSERT(dsl_pool_config_held(dp));
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dsl_destroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ dsl_destroy_snapshot_sync_impl(dsl_dataset_t *ds, boolean_t defer, dmu_tx_t *tx)
spa_prop_clear_bootfs(dp->dp_spa, ds->ds_object, tx);

if (dsl_dataset_phys(ds)->ds_next_clones_obj != 0) {
ASSERTV(uint64_t count);
uint64_t count __maybe_unused;
ASSERT0(zap_count(mos,
dsl_dataset_phys(ds)->ds_next_clones_obj, &count) &&
count == 0);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dsl_dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ dsl_dir_evict_async(void *dbu)
{
dsl_dir_t *dd = dbu;
int t;
ASSERTV(dsl_pool_t *dp = dd->dd_pool);
dsl_pool_t *dp __maybe_unused = dd->dd_pool;

dd->dd_dbuf = NULL;

Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dsl_prop.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ dsl_prop_register(dsl_dataset_t *ds, const char *propname,
dsl_prop_record_t *pr;
dsl_prop_cb_record_t *cbr;
int err;
ASSERTV(dsl_pool_t *dp = dd->dd_pool);
dsl_pool_t *dp __maybe_unused = dd->dd_pool;

ASSERT(dsl_pool_config_held(dp));

Expand Down
4 changes: 2 additions & 2 deletions module/zfs/metaslab.c
Original file line number Diff line number Diff line change
Expand Up @@ -3354,7 +3354,7 @@ metaslab_passivate_allocator(metaslab_group_t *mg, metaslab_t *msp,
static void
metaslab_passivate(metaslab_t *msp, uint64_t weight)
{
ASSERTV(uint64_t size = weight & ~METASLAB_WEIGHT_TYPE);
uint64_t size __maybe_unused = weight & ~METASLAB_WEIGHT_TYPE;

/*
* If size < SPA_MINBLOCKSIZE, then we will not allocate from
Expand Down Expand Up @@ -5959,7 +5959,7 @@ static void
metaslab_check_free_impl(vdev_t *vd, uint64_t offset, uint64_t size)
{
metaslab_t *msp;
ASSERTV(spa_t *spa = vd->vdev_spa);
spa_t *spa __maybe_unused = vd->vdev_spa;

if ((zfs_flags & ZFS_DEBUG_ZIO_FREE) == 0)
return;
Expand Down
4 changes: 2 additions & 2 deletions module/zfs/sa.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,7 +1237,7 @@ sa_byteswap(sa_handle_t *hdl, sa_buf_type_t buftype)
dmu_buf_impl_t *db;
int num_lengths = 1;
int i;
ASSERTV(sa_os_t *sa = hdl->sa_os->os_sa);
sa_os_t *sa __maybe_unused = hdl->sa_os->os_sa;

ASSERT(MUTEX_HELD(&sa->sa_lock));
if (sa_hdr_phys->sa_magic == SA_MAGIC)
Expand Down Expand Up @@ -1344,7 +1344,7 @@ sa_idx_tab_rele(objset_t *os, void *arg)
static void
sa_idx_tab_hold(objset_t *os, sa_idx_tab_t *idx_tab)
{
ASSERTV(sa_os_t *sa = os->os_sa);
sa_os_t *sa __maybe_unused = os->os_sa;

ASSERT(MUTEX_HELD(&sa->sa_lock));
(void) zfs_refcount_add(&idx_tab->sa_refcount, NULL);
Expand Down
10 changes: 5 additions & 5 deletions module/zfs/spa.c
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ spa_prop_clear_bootfs(spa_t *spa, uint64_t dsobj, dmu_tx_t *tx)
static int
spa_change_guid_check(void *arg, dmu_tx_t *tx)
{
ASSERTV(uint64_t *newguid = arg);
uint64_t *newguid __maybe_unused = arg;
spa_t *spa = dmu_tx_pool(tx)->dp_spa;
vdev_t *rvd = spa->spa_root_vdev;
uint64_t vdev_state;
Expand Down Expand Up @@ -6530,7 +6530,7 @@ int
spa_vdev_attach(spa_t *spa, uint64_t guid, nvlist_t *nvroot, int replacing)
{
uint64_t txg, dtl_max_txg;
ASSERTV(vdev_t *rvd = spa->spa_root_vdev);
vdev_t *rvd __maybe_unused = spa->spa_root_vdev;
vdev_t *oldvd, *newvd, *newrootvd, *pvd, *tvd;
vdev_ops_t *pvops;
char *oldvdpath, *newvdpath;
Expand Down Expand Up @@ -6755,7 +6755,7 @@ spa_vdev_detach(spa_t *spa, uint64_t guid, uint64_t pguid, int replace_done)
{
uint64_t txg;
int error;
ASSERTV(vdev_t *rvd = spa->spa_root_vdev);
vdev_t *rvd __maybe_unused = spa->spa_root_vdev;
vdev_t *vd, *pvd, *cvd, *tvd;
boolean_t unspare = B_FALSE;
uint64_t unspare_guid = 0;
Expand Down Expand Up @@ -8640,8 +8640,8 @@ spa_sync_upgrades(spa_t *spa, dmu_tx_t *tx)
static void
vdev_indirect_state_sync_verify(vdev_t *vd)
{
ASSERTV(vdev_indirect_mapping_t *vim = vd->vdev_indirect_mapping);
ASSERTV(vdev_indirect_births_t *vib = vd->vdev_indirect_births);
vdev_indirect_mapping_t *vim __maybe_unused = vd->vdev_indirect_mapping;
vdev_indirect_births_t *vib __maybe_unused = vd->vdev_indirect_births;

if (vd->vdev_ops == &vdev_indirect_ops) {
ASSERT(vim != NULL);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/txg.c
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ txg_sync_waiting(dsl_pool_t *dp)
void
txg_verify(spa_t *spa, uint64_t txg)
{
ASSERTV(dsl_pool_t *dp = spa_get_dsl(spa));
dsl_pool_t *dp __maybe_unused = spa_get_dsl(spa);
if (txg <= TXG_INITIAL || txg == ZILTEST_TXG)
return;
ASSERT3U(txg, <=, dp->dp_tx.tx_open_txg);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/vdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2197,7 +2197,7 @@ void
vdev_close(vdev_t *vd)
{
vdev_t *pvd = vd->vdev_parent;
ASSERTV(spa_t *spa = vd->vdev_spa);
spa_t *spa __maybe_unused = vd->vdev_spa;

ASSERT(spa_config_held(spa, SCL_STATE_ALL, RW_WRITER) == SCL_STATE_ALL);

Expand Down
2 changes: 1 addition & 1 deletion module/zfs/vdev_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ vdev_cache_read(zio_t *zio)
vdev_cache_entry_t *ve, *ve_search;
uint64_t cache_offset = P2ALIGN(zio->io_offset, VCBS);
zio_t *fio;
ASSERTV(uint64_t cache_phase = P2PHASE(zio->io_offset, VCBS));
uint64_t cache_phase __maybe_unused = P2PHASE(zio->io_offset, VCBS);

ASSERT3U(zio->io_type, ==, ZIO_TYPE_READ);

Expand Down
8 changes: 4 additions & 4 deletions module/zfs/vdev_indirect.c
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ vdev_indirect_should_condense(vdev_t *vd)
* If nothing new has been marked obsolete, there is no
* point in condensing.
*/
ASSERTV(uint64_t obsolete_sm_obj);
uint64_t obsolete_sm_obj __maybe_unused;
ASSERT0(vdev_obsolete_sm_object(vd, &obsolete_sm_obj));
if (vd->vdev_obsolete_sm == NULL) {
ASSERT0(obsolete_sm_obj);
Expand Down Expand Up @@ -544,7 +544,7 @@ spa_condense_indirect_commit_sync(void *arg, dmu_tx_t *tx)
{
spa_condensing_indirect_t *sci = arg;
uint64_t txg = dmu_tx_get_txg(tx);
ASSERTV(spa_t *spa = dmu_tx_pool(tx)->dp_spa);
spa_t *spa __maybe_unused = dmu_tx_pool(tx)->dp_spa;

ASSERT(dmu_tx_is_syncing(tx));
ASSERT3P(sci, ==, spa->spa_condensing_indirect);
Expand Down Expand Up @@ -815,7 +815,7 @@ void
vdev_indirect_sync_obsolete(vdev_t *vd, dmu_tx_t *tx)
{
spa_t *spa = vd->vdev_spa;
ASSERTV(vdev_indirect_config_t *vic = &vd->vdev_indirect_config);
vdev_indirect_config_t *vic __maybe_unused = &vd->vdev_indirect_config;

ASSERT3U(vic->vic_mapping_object, !=, 0);
ASSERT(range_tree_space(vd->vdev_obsolete_segments) > 0);
Expand Down Expand Up @@ -1298,7 +1298,7 @@ vdev_indirect_read_all(zio_t *zio)
static void
vdev_indirect_io_start(zio_t *zio)
{
ASSERTV(spa_t *spa = zio->io_spa);
spa_t *spa __maybe_unused = zio->io_spa;
indirect_vsd_t *iv = kmem_zalloc(sizeof (*iv), KM_SLEEP);
list_create(&iv->iv_splits,
sizeof (indirect_split_t), offsetof(indirect_split_t, is_node));
Expand Down
11 changes: 6 additions & 5 deletions module/zfs/vdev_indirect_mapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@ vdev_indirect_mapping_verify(vdev_indirect_mapping_t *vim)
EQUIV(vim->vim_phys->vimp_num_entries > 0,
vim->vim_entries != NULL);
if (vim->vim_phys->vimp_num_entries > 0) {
ASSERTV(vdev_indirect_mapping_entry_phys_t *last_entry =
&vim->vim_entries[vim->vim_phys->vimp_num_entries - 1]);
ASSERTV(uint64_t offset =
DVA_MAPPING_GET_SRC_OFFSET(last_entry));
ASSERTV(uint64_t size = DVA_GET_ASIZE(&last_entry->vimep_dst));
vdev_indirect_mapping_entry_phys_t *last_entry __maybe_unused =
&vim->vim_entries[vim->vim_phys->vimp_num_entries - 1];
uint64_t offset __maybe_unused =
DVA_MAPPING_GET_SRC_OFFSET(last_entry);
uint64_t size __maybe_unused =
DVA_GET_ASIZE(&last_entry->vimep_dst);

ASSERT3U(vim->vim_phys->vimp_max_offset, >=, offset + size);
}
Expand Down
Loading

0 comments on commit e2e9a52

Please sign in to comment.