mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 10:37:35 +03:00
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 <matt@delphix.com> Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov> Signed-off-by: Serapheim Dimitropoulos <serapheim@delphix.com> Closes #9015 Closes #9044
This commit is contained in:
committed by
Brian Behlendorf
parent
1c44a5c97f
commit
43a8536260
+17
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user