Skip to content

Commit

Permalink
FreeBSD: Clean up ASSERT/VERIFY use in module
Browse files Browse the repository at this point in the history
Convert use of ASSERT() to ASSERT0(), ASSERT3U(), ASSERT3S(), 
ASSERT3P(), and likewise for VERIFY().  In some cases it ended up 
making more sense to change the code, such as VERIFY on nvlist 
operations that I have converted to use fnvlist instead.  In one 
place I changed an internal struct member from int to boolean_t to 
match its use.  Some asserts that combined multiple checks with && 
in a single assert have been split to separate asserts, to make it 
apparent which check fails.

Reviewed-by: Brian Behlendorf <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes openzfs#11971
  • Loading branch information
Ryan Moeller authored Apr 30, 2021
1 parent ec4f330 commit e4efb70
Show file tree
Hide file tree
Showing 23 changed files with 233 additions and 238 deletions.
6 changes: 3 additions & 3 deletions module/os/freebsd/spl/acl_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
#include <grp.h>
#include <pwd.h>
#include <acl_common.h>
#define ASSERT assert
#endif

#define ACE_POSIX_SUPPORTED_BITS (ACE_READ_DATA | \
Expand Down Expand Up @@ -170,8 +169,9 @@ ksort(caddr_t v, int n, int s, int (*f)(void *, void *))
return;

/* Sanity check on arguments */
ASSERT(((uintptr_t)v & 0x3) == 0 && (s & 0x3) == 0);
ASSERT(s > 0);
ASSERT3U(((uintptr_t)v & 0x3), ==, 0);
ASSERT3S((s & 0x3), ==, 0);
ASSERT3S(s, >, 0);
for (g = n / 2; g > 0; g /= 2) {
for (i = g; i < n; i++) {
for (j = i - g; j >= 0 &&
Expand Down
16 changes: 8 additions & 8 deletions module/os/freebsd/spl/callb.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ typedef struct callb {
typedef struct callb_table {
kmutex_t ct_lock; /* protect all callb states */
callb_t *ct_freelist; /* free callb structures */
int ct_busy; /* != 0 prevents additions */
boolean_t ct_busy; /* B_TRUE prevents additions */
kcondvar_t ct_busy_cv; /* to wait for not busy */
int ct_ncallb; /* num of callbs allocated */
callb_t *ct_first_cb[NCBCLASS]; /* ptr to 1st callb in a class */
Expand All @@ -98,7 +98,7 @@ callb_cpr_t callb_cprinfo_safe = {
static void
callb_init(void *dummy __unused)
{
callb_table.ct_busy = 0; /* mark table open for additions */
callb_table.ct_busy = B_FALSE; /* mark table open for additions */
mutex_init(&callb_safe_mutex, NULL, MUTEX_DEFAULT, NULL);
mutex_init(&callb_table.ct_lock, NULL, MUTEX_DEFAULT, NULL);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ callb_add_common(boolean_t (*func)(void *arg, int code),
{
callb_t *cp;

ASSERT(class < NCBCLASS);
ASSERT3S(class, <, NCBCLASS);

mutex_enter(&ct->ct_lock);
while (ct->ct_busy)
Expand Down Expand Up @@ -259,7 +259,7 @@ callb_execute_class(int class, int code)
callb_t *cp;
void *ret = NULL;

ASSERT(class < NCBCLASS);
ASSERT3S(class, <, NCBCLASS);

mutex_enter(&ct->ct_lock);

Expand Down Expand Up @@ -351,8 +351,8 @@ void
callb_lock_table(void)
{
mutex_enter(&ct->ct_lock);
ASSERT(ct->ct_busy == 0);
ct->ct_busy = 1;
ASSERT(!ct->ct_busy);
ct->ct_busy = B_TRUE;
mutex_exit(&ct->ct_lock);
}

Expand All @@ -363,8 +363,8 @@ void
callb_unlock_table(void)
{
mutex_enter(&ct->ct_lock);
ASSERT(ct->ct_busy != 0);
ct->ct_busy = 0;
ASSERT(ct->ct_busy);
ct->ct_busy = B_FALSE;
cv_broadcast(&ct->ct_busy_cv);
mutex_exit(&ct->ct_lock);
}
Expand Down
17 changes: 8 additions & 9 deletions module/os/freebsd/spl/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@
void
list_create(list_t *list, size_t size, size_t offset)
{
ASSERT(list);
ASSERT(size > 0);
ASSERT(size >= offset + sizeof (list_node_t));
ASSERT3P(list, !=, NULL);
ASSERT3U(size, >=, offset + sizeof (list_node_t));

list->list_size = size;
list->list_offset = offset;
Expand All @@ -76,9 +75,9 @@ list_destroy(list_t *list)
{
list_node_t *node = &list->list_head;

ASSERT(list);
ASSERT(list->list_head.list_next == node);
ASSERT(list->list_head.list_prev == node);
ASSERT3P(list, !=, NULL);
ASSERT3P(list->list_head.list_next, ==, node);
ASSERT3P(list->list_head.list_prev, ==, node);

node->list_next = node->list_prev = NULL;
}
Expand Down Expand Up @@ -124,7 +123,7 @@ list_remove(list_t *list, void *object)
{
list_node_t *lold = list_d2l(list, object);
ASSERT(!list_empty(list));
ASSERT(lold->list_next != NULL);
ASSERT3P(lold->list_next, !=, NULL);
list_remove_node(lold);
}

Expand Down Expand Up @@ -195,8 +194,8 @@ list_move_tail(list_t *dst, list_t *src)
list_node_t *dstnode = &dst->list_head;
list_node_t *srcnode = &src->list_head;

ASSERT(dst->list_size == src->list_size);
ASSERT(dst->list_offset == src->list_offset);
ASSERT3U(dst->list_size, ==, src->list_size);
ASSERT3U(dst->list_offset, ==, src->list_offset);

if (list_empty(src))
return;
Expand Down
6 changes: 3 additions & 3 deletions module/os/freebsd/spl/spl_kmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ zfs_kmem_free(void *buf, size_t size __unused)
if (i == buf)
break;
}
ASSERT(i != NULL);
ASSERT3P(i, !=, NULL);
LIST_REMOVE(i, next);
mtx_unlock(&kmem_items_mtx);
memset(buf, 0xDC, MAX(size, 16));
Expand Down Expand Up @@ -162,7 +162,7 @@ kmem_cache_create(char *name, size_t bufsize, size_t align,
{
kmem_cache_t *cache;

ASSERT(vmp == NULL);
ASSERT3P(vmp, ==, NULL);

cache = kmem_alloc(sizeof (*cache), KM_SLEEP);
strlcpy(cache->kc_name, name, sizeof (cache->kc_name));
Expand Down Expand Up @@ -324,7 +324,7 @@ void
spl_kmem_cache_set_move(kmem_cache_t *skc,
kmem_cbrc_t (move)(void *, void *, size_t, void *))
{
ASSERT(move != NULL);
ASSERT3P(move, !=, NULL);
}

#ifdef KMEM_DEBUG
Expand Down
14 changes: 7 additions & 7 deletions module/os/freebsd/spl/spl_kstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ __kstat_set_seq_raw_ops(kstat_t *ksp,
static int
kstat_default_update(kstat_t *ksp, int rw)
{
ASSERT(ksp != NULL);
ASSERT3P(ksp, !=, NULL);

if (rw == KSTAT_WRITE)
return (EACCES);
Expand Down Expand Up @@ -223,7 +223,7 @@ kstat_sysctl_raw(SYSCTL_HANDLER_ARGS)
sbuf_printf(sb, "%s", ksp->ks_raw_buf);

} else {
ASSERT(ksp->ks_ndata == 1);
ASSERT3U(ksp->ks_ndata, ==, 1);
sbuf_hexdump(sb, ksp->ks_data,
ksp->ks_data_size, NULL, 0);
}
Expand All @@ -250,7 +250,7 @@ __kstat_create(const char *module, int instance, const char *name,

KASSERT(instance == 0, ("instance=%d", instance));
if ((ks_type == KSTAT_TYPE_INTR) || (ks_type == KSTAT_TYPE_IO))
ASSERT(ks_ndata == 1);
ASSERT3U(ks_ndata, ==, 1);

if (class == NULL)
class = "misc";
Expand Down Expand Up @@ -461,7 +461,7 @@ kstat_install(kstat_t *ksp)
struct sysctl_oid *root;

if (ksp->ks_ndata == UINT32_MAX)
VERIFY(ksp->ks_type == KSTAT_TYPE_RAW);
VERIFY3U(ksp->ks_type, ==, KSTAT_TYPE_RAW);

switch (ksp->ks_type) {
case KSTAT_TYPE_NAMED:
Expand Down Expand Up @@ -493,7 +493,7 @@ kstat_install(kstat_t *ksp)
default:
panic("unsupported kstat type %d\n", ksp->ks_type);
}
VERIFY(root != NULL);
VERIFY3P(root, !=, NULL);
ksp->ks_sysctl_root = root;
}

Expand Down Expand Up @@ -535,7 +535,7 @@ kstat_waitq_exit(kstat_io_t *kiop)
delta = new - kiop->wlastupdate;
kiop->wlastupdate = new;
wcnt = kiop->wcnt--;
ASSERT((int)wcnt > 0);
ASSERT3S(wcnt, >, 0);
kiop->wlentime += delta * wcnt;
kiop->wtime += delta;
}
Expand Down Expand Up @@ -566,7 +566,7 @@ kstat_runq_exit(kstat_io_t *kiop)
delta = new - kiop->rlastupdate;
kiop->rlastupdate = new;
rcnt = kiop->rcnt--;
ASSERT((int)rcnt > 0);
ASSERT3S(rcnt, >, 0);
kiop->rlentime += delta * rcnt;
kiop->rtime += delta;
}
2 changes: 1 addition & 1 deletion module/os/freebsd/spl/spl_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ kmem_asprintf(const char *fmt, ...)
void
kmem_strfree(char *str)
{
ASSERT(str != NULL);
ASSERT3P(str, !=, NULL);
kmem_free(str, strlen(str) + 1);
}
2 changes: 1 addition & 1 deletion module/os/freebsd/spl/spl_sysevent.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ sysevent_worker(void *arg __unused)
if (error == ESHUTDOWN)
break;
} else {
VERIFY(event != NULL);
VERIFY3P(event, !=, NULL);
log_sysevent(event);
nvlist_free(event);
}
Expand Down
4 changes: 2 additions & 2 deletions module/os/freebsd/spl/spl_uio.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
int
zfs_uiomove(void *cp, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio)
{
ASSERT(zfs_uio_rw(uio) == dir);
ASSERT3U(zfs_uio_rw(uio), ==, dir);
return (uiomove(cp, (int)n, GET_UIO_STRUCT(uio)));
}

Expand Down Expand Up @@ -102,6 +102,6 @@ zfs_uioskip(zfs_uio_t *uio, size_t n)
int
zfs_uio_fault_move(void *p, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio)
{
ASSERT(zfs_uio_rw(uio) == dir);
ASSERT3U(zfs_uio_rw(uio), ==, dir);
return (vn_io_fault_uiomove(p, n, GET_UIO_STRUCT(uio)));
}
6 changes: 3 additions & 3 deletions module/os/freebsd/spl/spl_vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -275,13 +275,13 @@ mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath,
void
vn_rele_async(vnode_t *vp, taskq_t *taskq)
{
VERIFY(vp->v_usecount > 0);
VERIFY3U(vp->v_usecount, >, 0);
if (refcount_release_if_not_last(&vp->v_usecount)) {
#if __FreeBSD_version < 1300045
vdrop(vp);
#endif
return;
}
VERIFY(taskq_dispatch((taskq_t *)taskq,
(task_func_t *)vrele, vp, TQ_SLEEP) != 0);
VERIFY3U(taskq_dispatch((taskq_t *)taskq,
(task_func_t *)vrele, vp, TQ_SLEEP), !=, 0);
}
3 changes: 1 addition & 2 deletions module/os/freebsd/zfs/abd_os.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ abd_verify_scatter(abd_t *abd)
* if an error if the ABD has been marked as a linear page.
*/
ASSERT(!abd_is_linear_page(abd));
ASSERT3U(ABD_SCATTER(abd).abd_offset, <,
zfs_abd_chunk_size);
ASSERT3U(ABD_SCATTER(abd).abd_offset, <, zfs_abd_chunk_size);
n = abd_scatter_chunkcnt(abd);
for (i = 0; i < n; i++) {
ASSERT3P(ABD_SCATTER(abd).abd_chunks[i], !=, NULL);
Expand Down
Loading

0 comments on commit e4efb70

Please sign in to comment.