summaryrefslogtreecommitdiffstats
path: root/module/zfs
diff options
context:
space:
mode:
authorWill Andrews <[email protected]>2021-01-25 17:04:11 -0600
committerGitHub <[email protected]>2021-01-25 15:04:11 -0800
commitf4f50a70488ebad3fa96c2fe4142924215733113 (patch)
tree94fe5f57f7fa5b0b07ed53ab3c3d802533618e33 /module/zfs
parent35ac0ed1fd78a820474658f34dd7661af1bf635f (diff)
spa_export_common: refactor common exit points
Create a common exit point for spa_export_common (a very long function), which avoids missing steps on failure. This work is helpful for the planned forced pool export changes. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Will Andrews <[email protected]> Closes #11514
Diffstat (limited to 'module/zfs')
-rw-r--r--module/zfs/spa.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/module/zfs/spa.c b/module/zfs/spa.c
index 57a492993..56354a107 100644
--- a/module/zfs/spa.c
+++ b/module/zfs/spa.c
@@ -6250,6 +6250,7 @@ static int
spa_export_common(const char *pool, int new_state, nvlist_t **oldconfig,
boolean_t force, boolean_t hardforce)
{
+ int error;
spa_t *spa;
if (oldconfig)
@@ -6302,13 +6303,9 @@ spa_export_common(const char *pool, int new_state, nvlist_t **oldconfig,
* references. If we are resetting a pool, allow references by
* fault injection handlers.
*/
- if (!spa_refcount_zero(spa) ||
- (spa->spa_inject_ref != 0 &&
- new_state != POOL_STATE_UNINITIALIZED)) {
- spa_async_resume(spa);
- spa->spa_is_exporting = B_FALSE;
- mutex_exit(&spa_namespace_lock);
- return (SET_ERROR(EBUSY));
+ if (!spa_refcount_zero(spa) || (spa->spa_inject_ref != 0)) {
+ error = SET_ERROR(EBUSY);
+ goto fail;
}
if (spa->spa_sync_on) {
@@ -6320,10 +6317,8 @@ spa_export_common(const char *pool, int new_state, nvlist_t **oldconfig,
*/
if (!force && new_state == POOL_STATE_EXPORTED &&
spa_has_active_shared_spare(spa)) {
- spa_async_resume(spa);
- spa->spa_is_exporting = B_FALSE;
- mutex_exit(&spa_namespace_lock);
- return (SET_ERROR(EXDEV));
+ error = SET_ERROR(EXDEV);
+ goto fail;
}
/*
@@ -6385,6 +6380,12 @@ export_spa:
mutex_exit(&spa_namespace_lock);
return (0);
+
+fail:
+ spa->spa_is_exporting = B_FALSE;
+ spa_async_resume(spa);
+ mutex_exit(&spa_namespace_lock);
+ return (error);
}
/*