From 00a27515f01151fcb9c9f48d51ddf2732afca726 Mon Sep 17 00:00:00 2001 From: Ryan Moeller Date: Wed, 21 Oct 2020 17:23:08 +0000 Subject: [PATCH] zvol_os: Tidy up asserts Using more specific assert variants gives better messages on failure. No functional change. Reviewed-by: Alexander Motin Reviewed-by: Matt Macy Signed-off-by: Ryan Moeller Closes #11117 --- module/os/freebsd/zfs/zvol_os.c | 30 +++++++++++++++--------------- 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 218e1101e..0ac201ff1 100644 --- a/module/os/linux/zfs/zvol_os.c +++ b/module/os/linux/zfs/zvol_os.c @@ -107,8 +107,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)) @@ -189,8 +190,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, @@ -256,7 +258,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; @@ -482,9 +485,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; @@ -530,7 +533,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 @@ -553,11 +556,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); @@ -859,8 +863,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);