Skip to content

Commit

Permalink
Cleanup: Use ASSERT3S()/VERIFY3S() where applicable
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Yao <richard.yao@alumni.stonybrook.edu>
  • Loading branch information
ryao committed Jan 24, 2023
1 parent 3d96ad6 commit dc59eb5
Show file tree
Hide file tree
Showing 34 changed files with 78 additions and 75 deletions.
2 changes: 1 addition & 1 deletion cmd/raidz_test/raidz_test.c
Expand Up @@ -950,7 +950,7 @@ run_sweep(void)
exit:
LOG(D_ALL, "\nWaiting for test threads to finish...\n");
mutex_enter(&sem_mtx);
VERIFY(free_slots <= max_free_slots);
VERIFY3S(free_slots, <=, max_free_slots);
while (free_slots < max_free_slots) {
(void) cv_wait(&sem_cv, &sem_mtx);
}
Expand Down
10 changes: 5 additions & 5 deletions cmd/zdb/zdb.c
Expand Up @@ -1364,7 +1364,7 @@ dump_sa_layouts(objset_t *os, uint64_t object, void *data, size_t size)
continue;
}

VERIFY(attr.za_integer_length == 2);
VERIFY3S(attr.za_integer_length, ==, 2);
layout_attrs = umem_zalloc(attr.za_num_integers *
attr.za_integer_length, UMEM_NOFAIL);

Expand Down Expand Up @@ -2248,13 +2248,13 @@ blkid2offset(const dnode_phys_t *dnp, const blkptr_t *bp,
const zbookmark_phys_t *zb)
{
if (dnp == NULL) {
ASSERT(zb->zb_level < 0);
ASSERT3S(zb->zb_level, <, 0);
if (zb->zb_object == 0)
return (zb->zb_blkid);
return (zb->zb_blkid * BP_GET_LSIZE(bp));
}

ASSERT(zb->zb_level >= 0);
ASSERT3S(zb->zb_level, >=, 0);

return ((zb->zb_blkid <<
(zb->zb_level * (dnp->dn_indblkshift - SPA_BLKPTRSHIFT))) *
Expand Down Expand Up @@ -2399,7 +2399,7 @@ print_indirect(spa_t *spa, blkptr_t *bp, const zbookmark_phys_t *zb,

(void) printf("%16llx ", (u_longlong_t)blkid2offset(dnp, bp, zb));

ASSERT(zb->zb_level >= 0);
ASSERT3S(zb->zb_level, >=, 0);

for (l = dnp->dn_nlevels - 1; l >= -1; l--) {
if (l == zb->zb_level) {
Expand Down Expand Up @@ -5798,7 +5798,7 @@ zdb_ddt_leak_init(spa_t *spa, zdb_cb_t *zcb)
ddt_exit(ddt);
}

ASSERT(error == ENOENT);
ASSERT3S(error, ==, ENOENT);
}

typedef struct checkpoint_sm_exclude_entry_arg {
Expand Down
2 changes: 1 addition & 1 deletion cmd/zhack.c
Expand Up @@ -206,7 +206,7 @@ dump_obj(objset_t *os, uint64_t obj, const char *name)
(void) printf("\t%s = %llu\n",
za.za_name, (u_longlong_t)za.za_first_integer);
} else {
ASSERT(za.za_integer_length == 1);
ASSERT3S(za.za_integer_length, ==, 1);
char val[1024];
VERIFY0(zap_lookup(os, obj, za.za_name, 1,
sizeof (val), val));
Expand Down
2 changes: 1 addition & 1 deletion cmd/zpool/zpool_main.c
Expand Up @@ -9780,7 +9780,7 @@ zpool_do_events_next(ev_opts_t *opts)
char *pool;

zevent_fd = open(ZFS_DEV, O_RDWR);
VERIFY(zevent_fd >= 0);
VERIFY3S(zevent_fd, >=, 0);

if (!opts->scripted)
(void) printf(gettext("%-30s %s\n"), "TIME", "CLASS");
Expand Down
2 changes: 1 addition & 1 deletion include/os/freebsd/spl/sys/proc.h
Expand Up @@ -76,7 +76,7 @@ do_thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg,
*/
ASSERT(stk == NULL);
ASSERT(len == 0);
ASSERT(state == TS_RUN);
ASSERT3S(state, ==, TS_RUN);

if (pp == &p0)
ppp = &system_proc;
Expand Down
4 changes: 2 additions & 2 deletions lib/libzfs/libzfs_diff.c
Expand Up @@ -490,7 +490,7 @@ differ(void *arg)
if (err)
return ((void *)-1);
if (di->zerr) {
ASSERT(di->zerr == EPIPE);
ASSERT3S(di->zerr, ==, EPIPE);
(void) snprintf(di->errbuf, sizeof (di->errbuf),
dgettext(TEXT_DOMAIN,
"Internal error: bad data from diff IOCTL"));
Expand Down Expand Up @@ -728,7 +728,7 @@ setup_differ_info(zfs_handle_t *zhp, const char *fromsnap,
di->zhp = zhp;

di->cleanupfd = open(ZFS_DEV, O_RDWR | O_CLOEXEC);
VERIFY(di->cleanupfd >= 0);
VERIFY3S(di->cleanupfd, >=, 0);

if (get_snapshot_names(di, fromsnap, tosnap) != 0)
return (-1);
Expand Down
2 changes: 1 addition & 1 deletion lib/libzfs/libzfs_sendrecv.c
Expand Up @@ -3942,7 +3942,7 @@ zfs_receive_package(libzfs_handle_t *hdl, int fd, const char *destname,
static void
trunc_prop_errs(int truncated)
{
ASSERT(truncated != 0);
ASSERT3S(truncated, !=, 0);

if (truncated == 1)
(void) fprintf(stderr, dgettext(TEXT_DOMAIN,
Expand Down
10 changes: 6 additions & 4 deletions lib/libzpool/kernel.c
Expand Up @@ -723,8 +723,10 @@ static int random_fd = -1, urandom_fd = -1;
void
random_init(void)
{
VERIFY((random_fd = open(random_path, O_RDONLY | O_CLOEXEC)) != -1);
VERIFY((urandom_fd = open(urandom_path, O_RDONLY | O_CLOEXEC)) != -1);
VERIFY3S((random_fd = open(random_path, O_RDONLY | O_CLOEXEC)), !=,
-1);
VERIFY3S((urandom_fd = open(urandom_path, O_RDONLY | O_CLOEXEC)), !=,
-1);
}

void
Expand All @@ -743,7 +745,7 @@ random_get_bytes_common(uint8_t *ptr, size_t len, int fd)
size_t resid = len;
ssize_t bytes;

ASSERT(fd != -1);
ASSERT3S(fd, !=, -1);

while (resid != 0) {
bytes = read(fd, ptr, resid);
Expand Down Expand Up @@ -1276,7 +1278,7 @@ zfs_file_pread(zfs_file_t *fp, void *buf, size_t count, loff_t off,
int status;

status = pwrite64(fp->f_dump_fd, buf, rc, off);
ASSERT(status != -1);
ASSERT3S(status, !=, -1);
}

if (resid) {
Expand Down
6 changes: 3 additions & 3 deletions module/avl/avl.c
Expand Up @@ -578,7 +578,7 @@ avl_insert_here(
#ifdef ZFS_DEBUG
diff = tree->avl_compar(new_data, here);
ASSERT(-1 <= diff && diff <= 1);
ASSERT(diff != 0);
ASSERT3S(diff, !=, 0);
ASSERT(diff > 0 ? child == 1 : child == 0);
#endif

Expand All @@ -590,7 +590,7 @@ avl_insert_here(
diff = tree->avl_compar(new_data,
AVL_NODE2DATA(node, tree->avl_offset));
ASSERT(-1 <= diff && diff <= 1);
ASSERT(diff != 0);
ASSERT3S(diff, !=, 0);
ASSERT(diff > 0 ? child == 1 : child == 0);
#endif
node = node->avl_child[child];
Expand All @@ -599,7 +599,7 @@ avl_insert_here(
diff = tree->avl_compar(new_data,
AVL_NODE2DATA(node, tree->avl_offset));
ASSERT(-1 <= diff && diff <= 1);
ASSERT(diff != 0);
ASSERT3S(diff, !=, 0);
ASSERT(diff > 0 ? child == 1 : child == 0);
#endif
}
Expand Down
2 changes: 1 addition & 1 deletion module/icp/core/kcf_mech_tabs.c
Expand Up @@ -246,7 +246,7 @@ kcf_add_mech_provider(short mech_indx,
}

error = kcf_get_mech_entry(kcf_mech_type, &mech_entry);
ASSERT(error == KCF_SUCCESS);
ASSERT3S(error, ==, KCF_SUCCESS);

/* allocate and initialize new kcf_prov_mech_desc */
prov_mech = kmem_zalloc(sizeof (kcf_prov_mech_desc_t), KM_SLEEP);
Expand Down
12 changes: 6 additions & 6 deletions module/icp/include/sys/crypto/impl.h
Expand Up @@ -133,18 +133,18 @@ typedef struct kcf_provider_desc {
*/
#define KCF_PROV_REFHOLD(desc) { \
int newval = atomic_add_32_nv(&(desc)->pd_refcnt, 1); \
ASSERT(newval != 0); \
ASSERT3S(newval, !=, 0); \
}

#define KCF_PROV_IREFHOLD(desc) { \
int newval = atomic_add_32_nv(&(desc)->pd_irefcnt, 1); \
ASSERT(newval != 0); \
ASSERT3S(newval, !=, 0); \
}

#define KCF_PROV_IREFRELE(desc) { \
membar_producer(); \
int newval = atomic_add_32_nv(&(desc)->pd_irefcnt, -1); \
ASSERT(newval != -1); \
ASSERT3S(newval, !=, -1); \
if (newval == 0) { \
cv_broadcast(&(desc)->pd_remove_cv); \
} \
Expand All @@ -155,7 +155,7 @@ typedef struct kcf_provider_desc {
#define KCF_PROV_REFRELE(desc) { \
membar_producer(); \
int newval = atomic_add_32_nv(&(desc)->pd_refcnt, -1); \
ASSERT(newval != -1); \
ASSERT3S(newval, !=, -1); \
if (newval == 0) { \
kcf_provider_zero_refcnt((desc)); \
} \
Expand Down Expand Up @@ -194,7 +194,7 @@ typedef struct kcf_mech_entry {
*/
#define KCF_POLICY_REFHOLD(desc) { \
int newval = atomic_add_32_nv(&(desc)->pd_refcnt, 1); \
ASSERT(newval != 0); \
ASSERT3S(newval, !=, 0); \
}

/*
Expand All @@ -204,7 +204,7 @@ typedef struct kcf_mech_entry {
#define KCF_POLICY_REFRELE(desc) { \
membar_producer(); \
int newval = atomic_add_32_nv(&(desc)->pd_refcnt, -1); \
ASSERT(newval != -1); \
ASSERT3S(newval, !=, -1); \
if (newval == 0) \
kcf_policy_free_desc(desc); \
}
Expand Down
2 changes: 1 addition & 1 deletion module/icp/include/sys/crypto/sched_impl.h
Expand Up @@ -75,7 +75,7 @@ typedef struct kcf_context {
#define KCF_CONTEXT_REFRELE(ictx) { \
membar_producer(); \
int newval = atomic_add_32_nv(&(ictx)->kc_refcnt, -1); \
ASSERT(newval != -1); \
ASSERT3S(newval, !=, -1); \
if (newval == 0) \
kcf_free_context(ictx); \
}
Expand Down
6 changes: 3 additions & 3 deletions module/os/linux/spl/spl-taskq.c
Expand Up @@ -1047,13 +1047,13 @@ taskq_create(const char *name, int threads_arg, pri_t pri,
int nthreads = threads_arg;

ASSERT3P(name, !=, NULL);
ASSERT(minalloc >= 0);
ASSERT3S(minalloc, >=, 0);
ASSERT0((flags & (TASKQ_CPR_SAFE))); /* Unsupported */

/* Scale the number of threads using nthreads as a percentage */
if (flags & TASKQ_THREADS_CPU_PCT) {
ASSERT(nthreads <= 100);
ASSERT(nthreads >= 0);
ASSERT3S(nthreads, <=, 100);
ASSERT3S(nthreads, >=, 0);
nthreads = MIN(threads_arg, 100);
nthreads = MAX(nthreads, 0);
nthreads = MAX((num_online_cpus() * nthreads) /100, 1);
Expand Down
10 changes: 5 additions & 5 deletions module/zcommon/zprop_common.c
Expand Up @@ -316,7 +316,7 @@ zprop_string_to_index(int prop, const char *string, uint64_t *index,
if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
return (-1);

ASSERT(prop < zprop_get_numprops(type));
ASSERT3S(prop, <, zprop_get_numprops(type));
prop_tbl = zprop_get_proptable(type);
if ((idx_tbl = prop_tbl[prop].pd_table) == NULL)
return (-1);
Expand All @@ -342,7 +342,7 @@ zprop_index_to_string(int prop, uint64_t index, const char **string,
if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
return (-1);

ASSERT(prop < zprop_get_numprops(type));
ASSERT3S(prop, <, zprop_get_numprops(type));
prop_tbl = zprop_get_proptable(type);
if ((idx_tbl = prop_tbl[prop].pd_table) == NULL)
return (-1);
Expand Down Expand Up @@ -382,7 +382,7 @@ zprop_values(int prop, zfs_type_t type)
zprop_desc_t *prop_tbl;

ASSERT(prop != ZPROP_INVAL && prop != ZPROP_CONT);
ASSERT(prop < zprop_get_numprops(type));
ASSERT3S(prop, <, zprop_get_numprops(type));

prop_tbl = zprop_get_proptable(type);

Expand All @@ -404,7 +404,7 @@ zprop_valid_for_type(int prop, zfs_type_t type, boolean_t headcheck)
if (prop == ZPROP_INVAL || prop == ZPROP_CONT)
return (B_FALSE);

ASSERT(prop < zprop_get_numprops(type));
ASSERT3S(prop, <, zprop_get_numprops(type));
prop_tbl = zprop_get_proptable(type);
if (headcheck && prop_tbl[prop].pd_types == ZFS_TYPE_SNAPSHOT)
return (B_TRUE);
Expand Down Expand Up @@ -438,7 +438,7 @@ zprop_width(int prop, boolean_t *fixed, zfs_type_t type)
int i;

ASSERT(prop != ZPROP_INVAL && prop != ZPROP_CONT);
ASSERT(prop < zprop_get_numprops(type));
ASSERT3S(prop, <, zprop_get_numprops(type));

prop_tbl = zprop_get_proptable(type);
pd = &prop_tbl[prop];
Expand Down
8 changes: 4 additions & 4 deletions module/zfs/arc.c
Expand Up @@ -2701,14 +2701,14 @@ arc_space_return(uint64_t space, arc_space_type_t type)
}

if (type != ARC_SPACE_DATA && type != ARC_SPACE_ABD_CHUNK_WASTE) {
ASSERT(aggsum_compare(&arc_sums.arcstat_meta_used,
space) >= 0);
ASSERT3S(aggsum_compare(&arc_sums.arcstat_meta_used, space),
>=, 0);
ARCSTAT_MAX(arcstat_meta_max,
aggsum_upper_bound(&arc_sums.arcstat_meta_used));
aggsum_add(&arc_sums.arcstat_meta_used, -space);
}

ASSERT(aggsum_compare(&arc_sums.arcstat_size, space) >= 0);
ASSERT3S(aggsum_compare(&arc_sums.arcstat_size, space), >=, 0);
aggsum_add(&arc_sums.arcstat_size, -space);
}

Expand Down Expand Up @@ -5149,7 +5149,7 @@ arc_adapt(int bytes, arc_state_t *state)
int64_t mrug_size = zfs_refcount_count(&arc_mru_ghost->arcs_size);
int64_t mfug_size = zfs_refcount_count(&arc_mfu_ghost->arcs_size);

ASSERT(bytes > 0);
ASSERT3S(bytes, >, 0);
/*
* Adapt the target size of the MRU list:
* - if we just hit in the MRU ghost list, then increase
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/blake3_zfs.c
Expand Up @@ -94,7 +94,7 @@ abd_checksum_blake3_tmpl_init(const zio_cksum_salt_t *salt)
{
BLAKE3_CTX *ctx;

ASSERT(sizeof (salt->zcs_bytes) == 32);
ASSERT3S(sizeof (salt->zcs_bytes), ==, 32);

/* init reference object */
ctx = kmem_zalloc(sizeof (*ctx), KM_SLEEP);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/bpobj.c
Expand Up @@ -491,7 +491,7 @@ bpobj_iterate_impl(bpobj_t *initial_bpo, bpobj_itor_t func, void *arg,
*/
while ((bpi = list_remove_head(&stack)) != NULL) {
bpobj_t *bpo = bpi->bpi_bpo;
ASSERT(err != 0);
ASSERT3S(err, !=, 0);
ASSERT3P(bpo, !=, NULL);

mutex_exit(&bpo->bpo_lock);
Expand Down
5 changes: 3 additions & 2 deletions module/zfs/ddt.c
Expand Up @@ -437,7 +437,7 @@ ddt_stat_update(ddt_t *ddt, ddt_entry_t *dde, uint64_t neg)
ddt_stat_generate(ddt, dde, &dds);

bucket = highbit64(dds.dds_ref_blocks) - 1;
ASSERT(bucket >= 0);
ASSERT3S(bucket, >=, 0);

ddh = &ddt->ddt_histogram[dde->dde_type][dde->dde_class];

Expand Down Expand Up @@ -1044,7 +1044,8 @@ ddt_sync_entry(ddt_t *ddt, ddt_entry_t *dde, dmu_tx_t *tx, uint64_t txg)
if (otype != DDT_TYPES &&
(otype != ntype || oclass != nclass || total_refcnt == 0)) {
VERIFY0(ddt_object_remove(ddt, otype, oclass, dde, tx));
ASSERT(ddt_object_lookup(ddt, otype, oclass, dde) == ENOENT);
ASSERT3S(ddt_object_lookup(ddt, otype, oclass, dde), ==,
ENOENT);
}

if (total_refcnt != 0) {
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/ddt_zap.c
Expand Up @@ -133,7 +133,7 @@ ddt_zap_walk(objset_t *os, uint64_t object, ddt_entry_t *dde, uint64_t *walk)
if ((error = zap_cursor_retrieve(&zc, &za)) == 0) {
uchar_t cbuf[sizeof (dde->dde_phys) + 1];
uint64_t csize = za.za_num_integers;
ASSERT(za.za_integer_length == 1);
ASSERT3S(za.za_integer_length, ==, 1);
error = zap_lookup_uint64(os, object, (uint64_t *)za.za_name,
DDT_KEY_WORDS, 1, csize, cbuf);
ASSERT0(error);
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dmu_recv.c
Expand Up @@ -3098,7 +3098,7 @@ receive_process_record(struct receive_writer_arg *rwa,
* EAGAIN to indicate that we do not want to free
* the rrd or arc_buf.
*/
ASSERT(err != 0);
ASSERT3S(err, !=, 0);
abd_free(rrd->abd);
rrd->abd = NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dsl_dataset.c
Expand Up @@ -3766,7 +3766,7 @@ snaplist_make(dsl_pool_t *dp,
int err;

err = dsl_dataset_hold_obj(dp, obj, tag, &ds);
ASSERT(err != ENOENT);
ASSERT3S(err, !=, ENOENT);
if (err != 0)
return (err);

Expand Down
2 changes: 1 addition & 1 deletion module/zfs/dsl_deleg.c
Expand Up @@ -347,7 +347,7 @@ dsl_deleg_get(const char *ddname, nvlist_t **nvp)
zap_cursor_advance(basezc)) {
nvlist_t *perms_nvp;

ASSERT(baseza->za_integer_length == 8);
ASSERT3S(baseza->za_integer_length, ==, 8);
ASSERT(baseza->za_num_integers == 1);

perms_nvp = fnvlist_alloc();
Expand Down

0 comments on commit dc59eb5

Please sign in to comment.