Skip to content

Commit 1826068

Browse files
Ryan Moellertonyhutter
authored andcommitted
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 <[email protected]> Signed-off-by: Ryan Moeller <[email protected]> Closes openzfs#11971
1 parent 4f92fe0 commit 1826068

23 files changed

+231
-236
lines changed

module/os/freebsd/spl/acl_common.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include <grp.h>
4444
#include <pwd.h>
4545
#include <acl_common.h>
46-
#define ASSERT assert
4746
#endif
4847

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

172171
/* Sanity check on arguments */
173-
ASSERT(((uintptr_t)v & 0x3) == 0 && (s & 0x3) == 0);
174-
ASSERT(s > 0);
172+
ASSERT3U(((uintptr_t)v & 0x3), ==, 0);
173+
ASSERT3S((s & 0x3), ==, 0);
174+
ASSERT3S(s, >, 0);
175175
for (g = n / 2; g > 0; g /= 2) {
176176
for (i = g; i < n; i++) {
177177
for (j = i - g; j >= 0 &&

module/os/freebsd/spl/callb.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ typedef struct callb {
7575
typedef struct callb_table {
7676
kmutex_t ct_lock; /* protect all callb states */
7777
callb_t *ct_freelist; /* free callb structures */
78-
int ct_busy; /* != 0 prevents additions */
78+
boolean_t ct_busy; /* B_TRUE prevents additions */
7979
kcondvar_t ct_busy_cv; /* to wait for not busy */
8080
int ct_ncallb; /* num of callbs allocated */
8181
callb_t *ct_first_cb[NCBCLASS]; /* ptr to 1st callb in a class */
@@ -98,7 +98,7 @@ callb_cpr_t callb_cprinfo_safe = {
9898
static void
9999
callb_init(void *dummy __unused)
100100
{
101-
callb_table.ct_busy = 0; /* mark table open for additions */
101+
callb_table.ct_busy = B_FALSE; /* mark table open for additions */
102102
mutex_init(&callb_safe_mutex, NULL, MUTEX_DEFAULT, NULL);
103103
mutex_init(&callb_table.ct_lock, NULL, MUTEX_DEFAULT, NULL);
104104
}
@@ -139,7 +139,7 @@ callb_add_common(boolean_t (*func)(void *arg, int code),
139139
{
140140
callb_t *cp;
141141

142-
ASSERT(class < NCBCLASS);
142+
ASSERT3S(class, <, NCBCLASS);
143143

144144
mutex_enter(&ct->ct_lock);
145145
while (ct->ct_busy)
@@ -259,7 +259,7 @@ callb_execute_class(int class, int code)
259259
callb_t *cp;
260260
void *ret = NULL;
261261

262-
ASSERT(class < NCBCLASS);
262+
ASSERT3S(class, <, NCBCLASS);
263263

264264
mutex_enter(&ct->ct_lock);
265265

@@ -351,8 +351,8 @@ void
351351
callb_lock_table(void)
352352
{
353353
mutex_enter(&ct->ct_lock);
354-
ASSERT(ct->ct_busy == 0);
355-
ct->ct_busy = 1;
354+
ASSERT(!ct->ct_busy);
355+
ct->ct_busy = B_TRUE;
356356
mutex_exit(&ct->ct_lock);
357357
}
358358

@@ -363,8 +363,8 @@ void
363363
callb_unlock_table(void)
364364
{
365365
mutex_enter(&ct->ct_lock);
366-
ASSERT(ct->ct_busy != 0);
367-
ct->ct_busy = 0;
366+
ASSERT(ct->ct_busy);
367+
ct->ct_busy = B_FALSE;
368368
cv_broadcast(&ct->ct_busy_cv);
369369
mutex_exit(&ct->ct_lock);
370370
}

module/os/freebsd/spl/list.c

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@
6161
void
6262
list_create(list_t *list, size_t size, size_t offset)
6363
{
64-
ASSERT(list);
65-
ASSERT(size > 0);
66-
ASSERT(size >= offset + sizeof (list_node_t));
64+
ASSERT3P(list, !=, NULL);
65+
ASSERT3U(size, >=, offset + sizeof (list_node_t));
6766

6867
list->list_size = size;
6968
list->list_offset = offset;
@@ -76,9 +75,9 @@ list_destroy(list_t *list)
7675
{
7776
list_node_t *node = &list->list_head;
7877

79-
ASSERT(list);
80-
ASSERT(list->list_head.list_next == node);
81-
ASSERT(list->list_head.list_prev == node);
78+
ASSERT3P(list, !=, NULL);
79+
ASSERT3P(list->list_head.list_next, ==, node);
80+
ASSERT3P(list->list_head.list_prev, ==, node);
8281

8382
node->list_next = node->list_prev = NULL;
8483
}
@@ -124,7 +123,7 @@ list_remove(list_t *list, void *object)
124123
{
125124
list_node_t *lold = list_d2l(list, object);
126125
ASSERT(!list_empty(list));
127-
ASSERT(lold->list_next != NULL);
126+
ASSERT3P(lold->list_next, !=, NULL);
128127
list_remove_node(lold);
129128
}
130129

@@ -195,8 +194,8 @@ list_move_tail(list_t *dst, list_t *src)
195194
list_node_t *dstnode = &dst->list_head;
196195
list_node_t *srcnode = &src->list_head;
197196

198-
ASSERT(dst->list_size == src->list_size);
199-
ASSERT(dst->list_offset == src->list_offset);
197+
ASSERT3U(dst->list_size, ==, src->list_size);
198+
ASSERT3U(dst->list_offset, ==, src->list_offset);
200199

201200
if (list_empty(src))
202201
return;

module/os/freebsd/spl/spl_kmem.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ zfs_kmem_free(void *buf, size_t size __unused)
112112
if (i == buf)
113113
break;
114114
}
115-
ASSERT(i != NULL);
115+
ASSERT3P(i, !=, NULL);
116116
LIST_REMOVE(i, next);
117117
mtx_unlock(&kmem_items_mtx);
118118
memset(buf, 0xDC, MAX(size, 16));
@@ -162,7 +162,7 @@ kmem_cache_create(char *name, size_t bufsize, size_t align,
162162
{
163163
kmem_cache_t *cache;
164164

165-
ASSERT(vmp == NULL);
165+
ASSERT3P(vmp, ==, NULL);
166166

167167
cache = kmem_alloc(sizeof (*cache), KM_SLEEP);
168168
strlcpy(cache->kc_name, name, sizeof (cache->kc_name));
@@ -324,7 +324,7 @@ void
324324
spl_kmem_cache_set_move(kmem_cache_t *skc,
325325
kmem_cbrc_t (move)(void *, void *, size_t, void *))
326326
{
327-
ASSERT(move != NULL);
327+
ASSERT3P(move, !=, NULL);
328328
}
329329

330330
#ifdef KMEM_DEBUG

module/os/freebsd/spl/spl_kstat.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ __kstat_set_seq_raw_ops(kstat_t *ksp,
6969
static int
7070
kstat_default_update(kstat_t *ksp, int rw)
7171
{
72-
ASSERT(ksp != NULL);
72+
ASSERT3P(ksp, !=, NULL);
7373

7474
if (rw == KSTAT_WRITE)
7575
return (EACCES);
@@ -223,7 +223,7 @@ kstat_sysctl_raw(SYSCTL_HANDLER_ARGS)
223223
sbuf_printf(sb, "%s", ksp->ks_raw_buf);
224224

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

251251
KASSERT(instance == 0, ("instance=%d", instance));
252252
if ((ks_type == KSTAT_TYPE_INTR) || (ks_type == KSTAT_TYPE_IO))
253-
ASSERT(ks_ndata == 1);
253+
ASSERT3U(ks_ndata, ==, 1);
254254

255255
if (class == NULL)
256256
class = "misc";
@@ -461,7 +461,7 @@ kstat_install(kstat_t *ksp)
461461
struct sysctl_oid *root;
462462

463463
if (ksp->ks_ndata == UINT32_MAX)
464-
VERIFY(ksp->ks_type == KSTAT_TYPE_RAW);
464+
VERIFY3U(ksp->ks_type, ==, KSTAT_TYPE_RAW);
465465

466466
switch (ksp->ks_type) {
467467
case KSTAT_TYPE_NAMED:
@@ -493,7 +493,7 @@ kstat_install(kstat_t *ksp)
493493
default:
494494
panic("unsupported kstat type %d\n", ksp->ks_type);
495495
}
496-
VERIFY(root != NULL);
496+
VERIFY3P(root, !=, NULL);
497497
ksp->ks_sysctl_root = root;
498498
}
499499

module/os/freebsd/spl/spl_string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,6 @@ kmem_asprintf(const char *fmt, ...)
102102
void
103103
kmem_strfree(char *str)
104104
{
105-
ASSERT(str != NULL);
105+
ASSERT3P(str, !=, NULL);
106106
kmem_free(str, strlen(str) + 1);
107107
}

module/os/freebsd/spl/spl_sysevent.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ sysevent_worker(void *arg __unused)
245245
if (error == ESHUTDOWN)
246246
break;
247247
} else {
248-
VERIFY(event != NULL);
248+
VERIFY3P(event, !=, NULL);
249249
log_sysevent(event);
250250
nvlist_free(event);
251251
}

module/os/freebsd/spl/spl_uio.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
int
4949
zfs_uiomove(void *cp, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio)
5050
{
51-
ASSERT(zfs_uio_rw(uio) == dir);
51+
ASSERT3U(zfs_uio_rw(uio), ==, dir);
5252
return (uiomove(cp, (int)n, GET_UIO_STRUCT(uio)));
5353
}
5454

@@ -102,6 +102,6 @@ zfs_uioskip(zfs_uio_t *uio, size_t n)
102102
int
103103
zfs_uio_fault_move(void *p, size_t n, zfs_uio_rw_t dir, zfs_uio_t *uio)
104104
{
105-
ASSERT(zfs_uio_rw(uio) == dir);
105+
ASSERT3U(zfs_uio_rw(uio), ==, dir);
106106
return (vn_io_fault_uiomove(p, n, GET_UIO_STRUCT(uio)));
107107
}

module/os/freebsd/spl/spl_vfs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,13 @@ mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath,
275275
void
276276
vn_rele_async(vnode_t *vp, taskq_t *taskq)
277277
{
278-
VERIFY(vp->v_usecount > 0);
278+
VERIFY3U(vp->v_usecount, >, 0);
279279
if (refcount_release_if_not_last(&vp->v_usecount)) {
280280
#if __FreeBSD_version < 1300045
281281
vdrop(vp);
282282
#endif
283283
return;
284284
}
285-
VERIFY(taskq_dispatch((taskq_t *)taskq,
286-
(task_func_t *)vrele, vp, TQ_SLEEP) != 0);
285+
VERIFY3U(taskq_dispatch((taskq_t *)taskq,
286+
(task_func_t *)vrele, vp, TQ_SLEEP), !=, 0);
287287
}

module/os/freebsd/zfs/abd_os.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,7 @@ abd_verify_scatter(abd_t *abd)
177177
* if an error if the ABD has been marked as a linear page.
178178
*/
179179
ASSERT(!abd_is_linear_page(abd));
180-
ASSERT3U(ABD_SCATTER(abd).abd_offset, <,
181-
zfs_abd_chunk_size);
180+
ASSERT3U(ABD_SCATTER(abd).abd_offset, <, zfs_abd_chunk_size);
182181
n = abd_scatter_chunkcnt(abd);
183182
for (i = 0; i < n; i++) {
184183
ASSERT3P(ABD_SCATTER(abd).abd_chunks[i], !=, NULL);

module/os/freebsd/zfs/dmu_os.c

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ dmu_write_pages(objset_t *os, uint64_t object, uint64_t offset, uint64_t size,
120120
dmu_buf_t *db = dbp[i];
121121
caddr_t va;
122122

123-
ASSERT(size > 0);
123+
ASSERT3U(size, >, 0);
124124
ASSERT3U(db->db_size, >=, PAGESIZE);
125125

126126
bufoff = offset - db->db_offset;
@@ -170,7 +170,7 @@ dmu_read_pages(objset_t *os, uint64_t object, vm_page_t *ma, int count,
170170
int err;
171171

172172
ASSERT3U(ma[0]->pindex + count - 1, ==, ma[count - 1]->pindex);
173-
ASSERT(last_size <= PAGE_SIZE);
173+
ASSERT3S(last_size, <=, PAGE_SIZE);
174174

175175
err = dmu_buf_hold_array(os, object, IDX_TO_OFF(ma[0]->pindex),
176176
IDX_TO_OFF(count - 1) + last_size, TRUE, FTAG, &numbufs, &dbp);
@@ -182,7 +182,7 @@ dmu_read_pages(objset_t *os, uint64_t object, vm_page_t *ma, int count,
182182
if (dbp[0]->db_offset != 0 || numbufs > 1) {
183183
for (i = 0; i < numbufs; i++) {
184184
ASSERT(ISP2(dbp[i]->db_size));
185-
ASSERT((dbp[i]->db_offset % dbp[i]->db_size) == 0);
185+
ASSERT3U((dbp[i]->db_offset % dbp[i]->db_size), ==, 0);
186186
ASSERT3U(dbp[i]->db_size, ==, dbp[0]->db_size);
187187
}
188188
}
@@ -202,10 +202,10 @@ dmu_read_pages(objset_t *os, uint64_t object, vm_page_t *ma, int count,
202202
vm_page_do_sunbusy(m);
203203
break;
204204
}
205-
ASSERT(m->dirty == 0);
205+
ASSERT3U(m->dirty, ==, 0);
206206
ASSERT(!pmap_page_is_write_mapped(m));
207207

208-
ASSERT(db->db_size > PAGE_SIZE);
208+
ASSERT3U(db->db_size, >, PAGE_SIZE);
209209
bufoff = IDX_TO_OFF(m->pindex) % db->db_size;
210210
va = zfs_map_page(m, &sf);
211211
bcopy((char *)db->db_data + bufoff, va, PAGESIZE);
@@ -229,7 +229,7 @@ dmu_read_pages(objset_t *os, uint64_t object, vm_page_t *ma, int count,
229229
if (m != bogus_page) {
230230
vm_page_assert_xbusied(m);
231231
ASSERT(vm_page_none_valid(m));
232-
ASSERT(m->dirty == 0);
232+
ASSERT3U(m->dirty, ==, 0);
233233
ASSERT(!pmap_page_is_write_mapped(m));
234234
va = zfs_map_page(m, &sf);
235235
}
@@ -248,25 +248,28 @@ dmu_read_pages(objset_t *os, uint64_t object, vm_page_t *ma, int count,
248248
* end of file anyway.
249249
*/
250250
tocpy = MIN(db->db_size - bufoff, PAGESIZE - pgoff);
251+
ASSERT3S(tocpy, >=, 0);
251252
if (m != bogus_page)
252253
bcopy((char *)db->db_data + bufoff, va + pgoff, tocpy);
253254

254255
pgoff += tocpy;
255-
ASSERT(pgoff <= PAGESIZE);
256+
ASSERT3S(pgoff, >=, 0);
257+
ASSERT3S(pgoff, <=, PAGESIZE);
256258
if (pgoff == PAGESIZE) {
257259
if (m != bogus_page) {
258260
zfs_unmap_page(sf);
259261
vm_page_valid(m);
260262
}
261-
ASSERT(mi < count);
263+
ASSERT3S(mi, <, count);
262264
mi++;
263265
pgoff = 0;
264266
}
265267

266268
bufoff += tocpy;
267-
ASSERT(bufoff <= db->db_size);
269+
ASSERT3S(bufoff, >=, 0);
270+
ASSERT3S(bufoff, <=, db->db_size);
268271
if (bufoff == db->db_size) {
269-
ASSERT(di < numbufs);
272+
ASSERT3S(di, <, numbufs);
270273
di++;
271274
bufoff = 0;
272275
}
@@ -286,23 +289,23 @@ dmu_read_pages(objset_t *os, uint64_t object, vm_page_t *ma, int count,
286289
* with a size that is not a multiple of the page size.
287290
*/
288291
if (mi == count) {
289-
ASSERT(di >= numbufs - 1);
292+
ASSERT3S(di, >=, numbufs - 1);
290293
IMPLY(*rahead != 0, di == numbufs - 1);
291294
IMPLY(*rahead != 0, bufoff != 0);
292-
ASSERT(pgoff == 0);
295+
ASSERT0(pgoff);
293296
}
294297
if (di == numbufs) {
295-
ASSERT(mi >= count - 1);
296-
ASSERT(*rahead == 0);
298+
ASSERT3S(mi, >=, count - 1);
299+
ASSERT0(*rahead);
297300
IMPLY(pgoff == 0, mi == count);
298301
if (pgoff != 0) {
299-
ASSERT(mi == count - 1);
300-
ASSERT((dbp[0]->db_size & PAGE_MASK) != 0);
302+
ASSERT3S(mi, ==, count - 1);
303+
ASSERT3U((dbp[0]->db_size & PAGE_MASK), !=, 0);
301304
}
302305
}
303306
#endif
304307
if (pgoff != 0) {
305-
ASSERT(m != bogus_page);
308+
ASSERT3P(m, !=, bogus_page);
306309
bzero(va + pgoff, PAGESIZE - pgoff);
307310
zfs_unmap_page(sf);
308311
vm_page_valid(m);
@@ -318,17 +321,17 @@ dmu_read_pages(objset_t *os, uint64_t object, vm_page_t *ma, int count,
318321
vm_page_do_sunbusy(m);
319322
break;
320323
}
321-
ASSERT(m->dirty == 0);
324+
ASSERT3U(m->dirty, ==, 0);
322325
ASSERT(!pmap_page_is_write_mapped(m));
323326

324-
ASSERT(db->db_size > PAGE_SIZE);
327+
ASSERT3U(db->db_size, >, PAGE_SIZE);
325328
bufoff = IDX_TO_OFF(m->pindex) % db->db_size;
326329
tocpy = MIN(db->db_size - bufoff, PAGESIZE);
327330
va = zfs_map_page(m, &sf);
328331
bcopy((char *)db->db_data + bufoff, va, tocpy);
329332
if (tocpy < PAGESIZE) {
330-
ASSERT(i == *rahead - 1);
331-
ASSERT((db->db_size & PAGE_MASK) != 0);
333+
ASSERT3S(i, ==, *rahead - 1);
334+
ASSERT3U((db->db_size & PAGE_MASK), !=, 0);
332335
bzero(va + tocpy, PAGESIZE - tocpy);
333336
}
334337
zfs_unmap_page(sf);

0 commit comments

Comments
 (0)