* Pool export/destroy * * The act of destroying or exporting a pool is very simple. We make sure there * is no more pending I/O and any references to the pool are gone. Then, we * update the pool state and sync all the labels to disk, removing the * configuration from the cache afterwards. If the 'hardforce' flag is set, then * we don't sync the labels or remove the configuration cache. *
| 6233 | * we don't sync the labels or remove the configuration cache. |
| 6234 | */ |
| 6235 | static int |
| 6236 | spa_export_common(const char *pool, int new_state, nvlist_t **oldconfig, |
| 6237 | boolean_t force, boolean_t hardforce) |
| 6238 | { |
| 6239 | spa_t *spa; |
| 6240 | |
| 6241 | if (oldconfig) |
| 6242 | *oldconfig = NULL; |
| 6243 | |
| 6244 | if (!(spa_mode_global & SPA_MODE_WRITE)) |
| 6245 | return (SET_ERROR(EROFS)); |
| 6246 | |
| 6247 | mutex_enter(&spa_namespace_lock); |
| 6248 | if ((spa = spa_lookup(pool)) == NULL) { |
| 6249 | mutex_exit(&spa_namespace_lock); |
| 6250 | return (SET_ERROR(ENOENT)); |
| 6251 | } |
| 6252 | |
| 6253 | if (spa->spa_is_exporting) { |
| 6254 | /* the pool is being exported by another thread */ |
| 6255 | mutex_exit(&spa_namespace_lock); |
| 6256 | return (SET_ERROR(ZFS_ERR_EXPORT_IN_PROGRESS)); |
| 6257 | } |
| 6258 | spa->spa_is_exporting = B_TRUE; |
| 6259 | |
| 6260 | /* |
| 6261 | * Put a hold on the pool, drop the namespace lock, stop async tasks, |
| 6262 | * reacquire the namespace lock, and see if we can export. |
| 6263 | */ |
| 6264 | spa_open_ref(spa, FTAG); |
| 6265 | mutex_exit(&spa_namespace_lock); |
| 6266 | spa_async_suspend(spa); |
| 6267 | if (spa->spa_zvol_taskq) { |
| 6268 | zvol_remove_minors(spa, spa_name(spa), B_TRUE); |
| 6269 | taskq_wait(spa->spa_zvol_taskq); |
| 6270 | } |
| 6271 | mutex_enter(&spa_namespace_lock); |
| 6272 | spa_close(spa, FTAG); |
| 6273 | |
| 6274 | if (spa->spa_state == POOL_STATE_UNINITIALIZED) |
| 6275 | goto export_spa; |
| 6276 | /* |
| 6277 | * The pool will be in core if it's openable, in which case we can |
| 6278 | * modify its state. Objsets may be open only because they're dirty, |
| 6279 | * so we have to force it to sync before checking spa_refcnt. |
| 6280 | */ |
| 6281 | if (spa->spa_sync_on) { |
| 6282 | txg_wait_synced(spa->spa_dsl_pool, 0); |
| 6283 | spa_evicting_os_wait(spa); |
| 6284 | } |
| 6285 | |
| 6286 | /* |
| 6287 | * A pool cannot be exported or destroyed if there are active |
| 6288 | * references. If we are resetting a pool, allow references by |
| 6289 | * fault injection handlers. |
| 6290 | */ |
| 6291 | if (!spa_refcount_zero(spa) || |
| 6292 | (spa->spa_inject_ref != 0 && |
no test coverage detected