FreeBSD: Clean up ASSERT/VERIFY use in module

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 <behlendorf1@llnl.gov>
Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
Closes #11971
This commit is contained in:
Ryan Moeller
2021-04-30 19:36:10 -04:00
committed by Tony Hutter
parent 4f92fe0f5c
commit 1826068523
23 changed files with 231 additions and 236 deletions
+3 -3
View File
@@ -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 | \
@@ -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 &&
+8 -8
View File
@@ -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 */
@@ -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);
}
@@ -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)
@@ -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);
@@ -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);
}
@@ -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);
}
+8 -9
View File
@@ -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;
@@ -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;
}
@@ -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);
}
@@ -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;
+3 -3
View File
@@ -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));
@@ -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));
@@ -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
+5 -5
View File
@@ -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);
@@ -223,7 +223,7 @@ restart:
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);
}
@@ -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";
@@ -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:
@@ -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;
}
+1 -1
View File
@@ -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);
}
+1 -1
View File
@@ -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);
}
+2 -2
View File
@@ -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)));
}
@@ -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)));
}
+3 -3
View File
@@ -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);
}