aboutsummaryrefslogtreecommitdiffstats
path: root/module/zfs/spa.c
diff options
context:
space:
mode:
authorSerapheim Dimitropoulos <[email protected]>2019-07-18 13:02:33 -0700
committerBrian Behlendorf <[email protected]>2019-07-18 13:02:33 -0700
commit43a8536260e76dab4a615164f9e6d6397c6b7778 (patch)
treeb5a8ab080464448090b92fc3b1eb1b86ce092366 /module/zfs/spa.c
parent1c44a5c97fabc669885df84c3e9b6b5e16f0cd35 (diff)
Race condition between spa async threads and export
In the past we've seen multiple race conditions that have to do with open-context threads async threads and concurrent calls to spa_export()/spa_destroy() (including the one referenced in issue #9015). This patch ensures that only one thread can execute the main body of spa_export_common() at a time, with subsequent threads returning with a new error code created just for this situation, eliminating this way any race condition bugs introduced by concurrent calls to this function. Reviewed by: Matt Ahrens <[email protected]> Reviewed by: Brian Behlendorf <[email protected]> Signed-off-by: Serapheim Dimitropoulos <[email protected]> Closes #9015 Closes #9044
Diffstat (limited to 'module/zfs/spa.c')
-rw-r--r--module/zfs/spa.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/module/zfs/spa.c b/module/zfs/spa.c
index 3ad8fc6e4..6af162edb 100644
--- a/module/zfs/spa.c
+++ b/module/zfs/spa.c
@@ -5790,6 +5790,13 @@ spa_export_common(char *pool, int new_state, nvlist_t **oldconfig,
return (SET_ERROR(ENOENT));
}
+ if (spa->spa_is_exporting) {
+ /* the pool is being exported by another thread */
+ mutex_exit(&spa_namespace_lock);
+ return (SET_ERROR(ZFS_ERR_EXPORT_IN_PROGRESS));
+ }
+ spa->spa_is_exporting = B_TRUE;
+
/*
* Put a hold on the pool, drop the namespace lock, stop async tasks,
* reacquire the namespace lock, and see if we can export.
@@ -5825,6 +5832,7 @@ spa_export_common(char *pool, int new_state, nvlist_t **oldconfig,
(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));
}
@@ -5839,6 +5847,7 @@ spa_export_common(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));
}
@@ -5890,9 +5899,16 @@ export_spa:
if (!hardforce)
spa_write_cachefile(spa, B_TRUE, B_TRUE);
spa_remove(spa);
+ } else {
+ /*
+ * If spa_remove() is not called for this spa_t and
+ * there is any possibility that it can be reused,
+ * we make sure to reset the exporting flag.
+ */
+ spa->spa_is_exporting = B_FALSE;
}
- mutex_exit(&spa_namespace_lock);
+ mutex_exit(&spa_namespace_lock);
return (0);
}