From 52224c0284d158b4f5c8f4f20df0af42c686d4a4 Mon Sep 17 00:00:00 2001 From: Jorgen Lundman Date: Fri, 26 Nov 2021 10:58:41 +0900 Subject: [PATCH] Add spa _os() hooks Add hooks for when spa is created, exported, activated and deactivated. Used by macOS to attach iokit, and lock kext as busy (to stop unloads). Userland, Linux, and, FreeBSD have empty stubs. Signed-off-by: Jorgen Lundman --- include/sys/spa_impl.h | 5 +++++ lib/libzpool/kernel.c | 24 ++++++++++++++++++++++++ module/os/freebsd/zfs/spa_os.c | 24 ++++++++++++++++++++++++ module/os/linux/zfs/spa_misc_os.c | 24 ++++++++++++++++++++++++ module/zfs/spa.c | 11 +++++++++++ 5 files changed, 88 insertions(+) diff --git a/include/sys/spa_impl.h b/include/sys/spa_impl.h index 9946c4e3c316..03ee5e510c23 100644 --- a/include/sys/spa_impl.h +++ b/include/sys/spa_impl.h @@ -460,6 +460,11 @@ extern void spa_set_deadman_synctime(hrtime_t ns); extern void spa_set_deadman_ziotime(hrtime_t ns); extern const char *spa_history_zone(void); +extern void spa_create_os(spa_t *spa); +extern void spa_export_os(spa_t *spa); +extern void spa_activate_os(spa_t *spa); +extern void spa_deactivate_os(spa_t *spa); + #ifdef __cplusplus } #endif diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index 41e0e7815c43..1149838fb08f 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -1405,3 +1405,27 @@ zfsvfs_update_fromname(const char *oldname, const char *newname) { (void) oldname, (void) newname; } + +void +spa_create_os(spa_t *spa) +{ + (void) spa; +} + +void +spa_export_os(spa_t *spa) +{ + (void) spa; +} + +void +spa_activate_os(spa_t *spa) +{ + (void) spa; +} + +void +spa_deactivate_os(spa_t *spa) +{ + (void) spa; +} diff --git a/module/os/freebsd/zfs/spa_os.c b/module/os/freebsd/zfs/spa_os.c index c8c833426131..81fb9e646921 100644 --- a/module/os/freebsd/zfs/spa_os.c +++ b/module/os/freebsd/zfs/spa_os.c @@ -268,3 +268,27 @@ spa_history_zone(void) { return ("freebsd"); } + +void +spa_create_os(spa_t *spa) +{ + (void) spa; +} + +void +spa_export_os(spa_t *spa) +{ + (void) spa; +} + +void +spa_activate_os(spa_t *spa) +{ + (void) spa; +} + +void +spa_deactivate_os(spa_t *spa) +{ + (void) spa; +} diff --git a/module/os/linux/zfs/spa_misc_os.c b/module/os/linux/zfs/spa_misc_os.c index 5672cd6d5c5e..d85a5cdac2e8 100644 --- a/module/os/linux/zfs/spa_misc_os.c +++ b/module/os/linux/zfs/spa_misc_os.c @@ -108,3 +108,27 @@ spa_history_zone(void) { return ("linux"); } + +void +spa_create_os(spa_t *spa) +{ + (void) spa; +} + +void +spa_export_os(spa_t *spa) +{ + (void) spa; +} + +void +spa_activate_os(spa_t *spa) +{ + (void) spa; +} + +void +spa_deactivate_os(spa_t *spa) +{ + (void) spa; +} diff --git a/module/zfs/spa.c b/module/zfs/spa.c index 7e18048af5e6..e9b9cf9c3ce1 100644 --- a/module/zfs/spa.c +++ b/module/zfs/spa.c @@ -1315,6 +1315,8 @@ spa_activate(spa_t *spa, spa_mode_t mode) spa_error_entry_compare, sizeof (spa_error_entry_t), offsetof(spa_error_entry_t, se_avl)); + spa_activate_os(spa); + spa_keystore_init(&spa->spa_keystore); /* @@ -1451,6 +1453,9 @@ spa_deactivate(spa_t *spa) thread_join(spa->spa_did); spa->spa_did = 0; } + + spa_deactivate_os(spa); + } /* @@ -6023,6 +6028,8 @@ spa_create(const char *pool, nvlist_t *nvroot, nvlist_t *props, spa->spa_minref = zfs_refcount_count(&spa->spa_refcount); spa->spa_load_state = SPA_LOAD_NONE; + spa_create_os(spa); + mutex_exit(&spa_namespace_lock); return (0); @@ -6206,6 +6213,8 @@ spa_import(char *pool, nvlist_t *config, nvlist_t *props, uint64_t flags) zvol_create_minors_recursive(pool); + spa_create_os(spa); + return (0); } @@ -6435,6 +6444,8 @@ spa_export_common(const char *pool, int new_state, nvlist_t **oldconfig, } export_spa: + spa_export_os(spa); + if (new_state == POOL_STATE_DESTROYED) spa_event_notify(spa, NULL, NULL, ESC_ZFS_POOL_DESTROY); else if (new_state == POOL_STATE_EXPORTED)