diff options
author | Ryan Moeller <[email protected]> | 2020-10-21 17:23:08 +0000 |
---|---|---|
committer | Brian Behlendorf <[email protected]> | 2020-10-30 15:34:15 -0700 |
commit | 0b32d81783bad54540792fc3701817a7b49025ca (patch) | |
tree | e2cc22b4a022e9a3173ef0f0de86bffde80da7ef /module | |
parent | c4ede65bdfca11b532403620bbf0d6e33f0c1c1d (diff) |
zvol_os: Tidy up asserts
Using more specific assert variants gives better messages on failure.
No functional change.
Reviewed-by: Alexander Motin <[email protected]>
Reviewed-by: Matt Macy <[email protected]>
Signed-off-by: Ryan Moeller <[email protected]>
Closes #11117
Diffstat (limited to 'module')
-rw-r--r-- | module/os/freebsd/zfs/zvol_os.c | 30 | ||||
-rw-r--r-- | module/os/linux/zfs/zvol_os.c | 26 |
2 files changed, 30 insertions, 26 deletions
diff --git a/module/os/freebsd/zfs/zvol_os.c b/module/os/freebsd/zfs/zvol_os.c index ecef075f9..48432c3eb 100644 --- a/module/os/freebsd/zfs/zvol_os.c +++ b/module/os/freebsd/zfs/zvol_os.c @@ -248,7 +248,7 @@ retry: } mutex_enter(&zv->zv_state_lock); - ASSERT(zv->zv_zso->zso_volmode == ZFS_VOLMODE_GEOM); + ASSERT3S(zv->zv_zso->zso_volmode, ==, ZFS_VOLMODE_GEOM); /* * make sure zvol is not suspended during first open @@ -342,17 +342,17 @@ zvol_geom_close(struct g_provider *pp, int flag, int count) mutex_enter(&zv->zv_state_lock); if (zv->zv_flags & ZVOL_EXCL) { - ASSERT(zv->zv_open_count == 1); + ASSERT3U(zv->zv_open_count, ==, 1); zv->zv_flags &= ~ZVOL_EXCL; } - ASSERT(zv->zv_zso->zso_volmode == ZFS_VOLMODE_GEOM); + ASSERT3S(zv->zv_zso->zso_volmode, ==, ZFS_VOLMODE_GEOM); /* * If the open count is zero, this is a spurious close. * That indicates a bug in the kernel / DDI framework. */ - ASSERT(zv->zv_open_count > 0); + ASSERT3U(zv->zv_open_count, >, 0); /* * make sure zvol is not suspended during last close @@ -400,7 +400,7 @@ zvol_geom_run(zvol_state_t *zv) struct zvol_state_geom *zsg = &zv->zv_zso->zso_geom; struct g_provider *pp = zsg->zsg_provider; - ASSERT(zv->zv_zso->zso_volmode == ZFS_VOLMODE_GEOM); + ASSERT3S(zv->zv_zso->zso_volmode, ==, ZFS_VOLMODE_GEOM); g_error_provider(pp, 0); @@ -414,7 +414,7 @@ zvol_geom_destroy(zvol_state_t *zv) struct zvol_state_geom *zsg = &zv->zv_zso->zso_geom; struct g_provider *pp = zsg->zsg_provider; - ASSERT(zv->zv_zso->zso_volmode == ZFS_VOLMODE_GEOM); + ASSERT3S(zv->zv_zso->zso_volmode, ==, ZFS_VOLMODE_GEOM); g_topology_assert(); @@ -483,7 +483,7 @@ zvol_geom_worker(void *arg) struct zvol_state_geom *zsg = &zv->zv_zso->zso_geom; struct bio *bp; - ASSERT(zv->zv_zso->zso_volmode == ZFS_VOLMODE_GEOM); + ASSERT3S(zv->zv_zso->zso_volmode, ==, ZFS_VOLMODE_GEOM); thread_lock(curthread); sched_prio(curthread, PRIBIO); @@ -540,7 +540,7 @@ zvol_geom_bio_getattr(struct bio *bp) zvol_state_t *zv; zv = bp->bio_to->private; - ASSERT(zv != NULL); + ASSERT3P(zv, !=, NULL); spa_t *spa = dmu_objset_spa(zv->zv_objset); uint64_t refd, avail, usedobjs, availobjs; @@ -621,7 +621,7 @@ zvol_geom_bio_strategy(struct bio *bp) volsize = zv->zv_volsize; os = zv->zv_objset; - ASSERT(os != NULL); + ASSERT3P(os, !=, NULL); addr = bp->bio_data; resid = bp->bio_length; @@ -836,7 +836,7 @@ zvol_cdev_open(struct cdev *dev, int flags, int fmt, struct thread *td) mutex_enter(&zv->zv_state_lock); - ASSERT(zv->zv_zso->zso_volmode == ZFS_VOLMODE_DEV); + ASSERT3S(zv->zv_zso->zso_volmode, ==, ZFS_VOLMODE_DEV); /* * make sure zvol is not suspended during first open @@ -925,17 +925,17 @@ zvol_cdev_close(struct cdev *dev, int flags, int fmt, struct thread *td) mutex_enter(&zv->zv_state_lock); if (zv->zv_flags & ZVOL_EXCL) { - ASSERT(zv->zv_open_count == 1); + ASSERT3U(zv->zv_open_count, ==, 1); zv->zv_flags &= ~ZVOL_EXCL; } - ASSERT(zv->zv_zso->zso_volmode == ZFS_VOLMODE_DEV); + ASSERT3S(zv->zv_zso->zso_volmode, ==, ZFS_VOLMODE_DEV); /* * If the open count is zero, this is a spurious close. * That indicates a bug in the kernel / DDI framework. */ - ASSERT(zv->zv_open_count > 0); + ASSERT3U(zv->zv_open_count, >, 0); /* * make sure zvol is not suspended during last close * (hold zv_suspend_lock) and respect proper lock acquisition @@ -1150,7 +1150,7 @@ zvol_rename_minor(zvol_state_t *zv, const char *newname) g_topology_lock(); gp = pp->geom; - ASSERT(gp != NULL); + ASSERT3P(gp, !=, NULL); zsg->zsg_provider = NULL; g_wither_provider(pp, ENXIO); @@ -1205,7 +1205,7 @@ zvol_free(zvol_state_t *zv) { ASSERT(!RW_LOCK_HELD(&zv->zv_suspend_lock)); ASSERT(!MUTEX_HELD(&zv->zv_state_lock)); - ASSERT(zv->zv_open_count == 0); + ASSERT0(zv->zv_open_count); ZFS_LOG(1, "ZVOL %s destroyed.", zv->zv_name); diff --git a/module/os/linux/zfs/zvol_os.c b/module/os/linux/zfs/zvol_os.c index 081c6d4ff..2422b331b 100644 --- a/module/os/linux/zfs/zvol_os.c +++ b/module/os/linux/zfs/zvol_os.c @@ -106,8 +106,9 @@ zvol_write(void *arg) uio_from_bio(&uio, bio); zvol_state_t *zv = zvr->zv; - ASSERT(zv && zv->zv_open_count > 0); - ASSERT(zv->zv_zilog != NULL); + ASSERT3P(zv, !=, NULL); + ASSERT3U(zv->zv_open_count, >, 0); + ASSERT3P(zv->zv_zilog, !=, NULL); /* bio marked as FLUSH need to flush before write */ if (bio_is_flush(bio)) @@ -188,8 +189,9 @@ zvol_discard(void *arg) dmu_tx_t *tx; unsigned long start_jif; - ASSERT(zv && zv->zv_open_count > 0); - ASSERT(zv->zv_zilog != NULL); + ASSERT3P(zv, !=, NULL); + ASSERT3U(zv->zv_open_count, >, 0); + ASSERT3P(zv->zv_zilog, !=, NULL); start_jif = jiffies; blk_generic_start_io_acct(zv->zv_zso->zvo_queue, WRITE, @@ -255,7 +257,8 @@ zvol_read(void *arg) uio_from_bio(&uio, bio); zvol_state_t *zv = zvr->zv; - ASSERT(zv && zv->zv_open_count > 0); + ASSERT3P(zv, !=, NULL); + ASSERT3U(zv->zv_open_count, >, 0); ssize_t start_resid = uio.uio_resid; unsigned long start_jif = jiffies; @@ -481,9 +484,9 @@ zvol_open(struct block_device *bdev, fmode_t flag) rw_exit(&zvol_state_lock); ASSERT(MUTEX_HELD(&zv->zv_state_lock)); - ASSERT(zv->zv_open_count != 0 || RW_READ_HELD(&zv->zv_suspend_lock)); if (zv->zv_open_count == 0) { + ASSERT(RW_READ_HELD(&zv->zv_suspend_lock)); error = -zvol_first_open(zv, !(flag & FMODE_WRITE)); if (error) goto out_mutex; @@ -529,7 +532,7 @@ zvol_release(struct gendisk *disk, fmode_t mode) zv = disk->private_data; mutex_enter(&zv->zv_state_lock); - ASSERT(zv->zv_open_count > 0); + ASSERT3U(zv->zv_open_count, >, 0); /* * make sure zvol is not suspended during last close * (hold zv_suspend_lock) and respect proper lock acquisition @@ -552,11 +555,12 @@ zvol_release(struct gendisk *disk, fmode_t mode) rw_exit(&zvol_state_lock); ASSERT(MUTEX_HELD(&zv->zv_state_lock)); - ASSERT(zv->zv_open_count != 1 || RW_READ_HELD(&zv->zv_suspend_lock)); zv->zv_open_count--; - if (zv->zv_open_count == 0) + if (zv->zv_open_count == 0) { + ASSERT(RW_READ_HELD(&zv->zv_suspend_lock)); zvol_last_close(zv); + } mutex_exit(&zv->zv_state_lock); @@ -858,8 +862,8 @@ zvol_free(zvol_state_t *zv) ASSERT(!RW_LOCK_HELD(&zv->zv_suspend_lock)); ASSERT(!MUTEX_HELD(&zv->zv_state_lock)); - ASSERT(zv->zv_open_count == 0); - ASSERT(zv->zv_zso->zvo_disk->private_data == NULL); + ASSERT0(zv->zv_open_count); + ASSERT3P(zv->zv_zso->zvo_disk->private_data, ==, NULL); rw_destroy(&zv->zv_suspend_lock); zfs_rangelock_fini(&zv->zv_rangelock); |