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 <behlendorf1@llnl.gov>
Signed-off-by:	Will Andrews <will@firepipe.net>
Closes #11514
This commit is contained in:
Will Andrews 2021-01-25 17:04:11 -06:00 committed by GitHub
parent 35ac0ed1fd
commit f4f50a7048
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 11 deletions

View File

@ -6250,6 +6250,7 @@ static int
spa_export_common(const char *pool, int new_state, nvlist_t **oldconfig, spa_export_common(const char *pool, int new_state, nvlist_t **oldconfig,
boolean_t force, boolean_t hardforce) boolean_t force, boolean_t hardforce)
{ {
int error;
spa_t *spa; spa_t *spa;
if (oldconfig) 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 * references. If we are resetting a pool, allow references by
* fault injection handlers. * fault injection handlers.
*/ */
if (!spa_refcount_zero(spa) || if (!spa_refcount_zero(spa) || (spa->spa_inject_ref != 0)) {
(spa->spa_inject_ref != 0 && error = SET_ERROR(EBUSY);
new_state != POOL_STATE_UNINITIALIZED)) { goto fail;
spa_async_resume(spa);
spa->spa_is_exporting = B_FALSE;
mutex_exit(&spa_namespace_lock);
return (SET_ERROR(EBUSY));
} }
if (spa->spa_sync_on) { 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 && if (!force && new_state == POOL_STATE_EXPORTED &&
spa_has_active_shared_spare(spa)) { spa_has_active_shared_spare(spa)) {
spa_async_resume(spa); error = SET_ERROR(EXDEV);
spa->spa_is_exporting = B_FALSE; goto fail;
mutex_exit(&spa_namespace_lock);
return (SET_ERROR(EXDEV));
} }
/* /*
@ -6385,6 +6380,12 @@ export_spa:
mutex_exit(&spa_namespace_lock); mutex_exit(&spa_namespace_lock);
return (0); return (0);
fail:
spa->spa_is_exporting = B_FALSE;
spa_async_resume(spa);
mutex_exit(&spa_namespace_lock);
return (error);
} }
/* /*