git: 0abaf7f63023 - releng/13.0 - FreeBSD: Clean up zfsdev_close to match Linux

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 15 Mar 2022 18:14:10 UTC
The branch releng/13.0 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=0abaf7f630235933aca9dd5819d4c0aea9985f3a

commit 0abaf7f630235933aca9dd5819d4c0aea9985f3a
Author:     Ryan Moeller <ryan@iXsystems.com>
AuthorDate: 2021-03-13 00:09:15 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-03-15 18:09:52 +0000

    FreeBSD: Clean up zfsdev_close to match Linux
    
    Resolve some oddities in zfsdev_close() which could result in a
    panic and were not present in the equivalent function for Linux.
    
    - Remove unused definition ZFS_MIN_MINOR
    - FreeBSD: Simplify zfsdev state destruction
    - Assert zs_minor is valid in zfsdev_close
    - Make locking around zfsdev state match Linux
    
    Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
    Reviewed-by: Alexander Motin <mav@FreeBSD.org>
    Signed-off-by: Ryan Moeller <ryan@iXsystems.com>
    Closes #11720
    
    Approved by:    so
    Security:       FreeBSD-EN-22:12.zfs
---
 sys/contrib/openzfs/include/sys/zfs_ioctl.h           |  1 -
 sys/contrib/openzfs/module/os/freebsd/zfs/kmod_core.c | 18 ++++++++----------
 2 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/sys/contrib/openzfs/include/sys/zfs_ioctl.h b/sys/contrib/openzfs/include/sys/zfs_ioctl.h
index afae576ea21a..8834c52990d0 100644
--- a/sys/contrib/openzfs/include/sys/zfs_ioctl.h
+++ b/sys/contrib/openzfs/include/sys/zfs_ioctl.h
@@ -525,7 +525,6 @@ typedef struct zfs_useracct {
 } zfs_useracct_t;
 
 #define	ZFSDEV_MAX_MINOR	(1 << 16)
-#define	ZFS_MIN_MINOR	(ZFSDEV_MAX_MINOR + 1)
 
 #define	ZPOOL_EXPORT_AFTER_SPLIT 0x1
 
diff --git a/sys/contrib/openzfs/module/os/freebsd/zfs/kmod_core.c b/sys/contrib/openzfs/module/os/freebsd/zfs/kmod_core.c
index c11d4dbcf660..d5ba0d93a569 100644
--- a/sys/contrib/openzfs/module/os/freebsd/zfs/kmod_core.c
+++ b/sys/contrib/openzfs/module/os/freebsd/zfs/kmod_core.c
@@ -182,23 +182,21 @@ out:
 static void
 zfsdev_close(void *data)
 {
-	zfsdev_state_t *zs, *zsp = data;
+	zfsdev_state_t *zs = data;
+
+	ASSERT(zs != NULL);
 
 	mutex_enter(&zfsdev_state_lock);
-	for (zs = zfsdev_state_list; zs != NULL; zs = zs->zs_next) {
-		if (zs == zsp)
-			break;
-	}
-	if (zs == NULL || zs->zs_minor <= 0) {
-		mutex_exit(&zfsdev_state_lock);
-		return;
-	}
+
+	ASSERT(zs->zs_minor != 0);
+
 	zs->zs_minor = -1;
 	zfs_onexit_destroy(zs->zs_onexit);
 	zfs_zevent_destroy(zs->zs_zevent);
-	mutex_exit(&zfsdev_state_lock);
 	zs->zs_onexit = NULL;
 	zs->zs_zevent = NULL;
+
+	mutex_exit(&zfsdev_state_lock);
 }
 
 static int