* Sync the specified transaction group. New blocks may be dirtied as * part of the process, so we iterate until it converges. */
| 9063 | * part of the process, so we iterate until it converges. |
| 9064 | */ |
| 9065 | void |
| 9066 | spa_sync(spa_t *spa, uint64_t txg) |
| 9067 | { |
| 9068 | vdev_t *vd = NULL; |
| 9069 | |
| 9070 | VERIFY(spa_writeable(spa)); |
| 9071 | |
| 9072 | /* |
| 9073 | * Wait for i/os issued in open context that need to complete |
| 9074 | * before this txg syncs. |
| 9075 | */ |
| 9076 | (void) zio_wait(spa->spa_txg_zio[txg & TXG_MASK]); |
| 9077 | spa->spa_txg_zio[txg & TXG_MASK] = zio_root(spa, NULL, NULL, |
| 9078 | ZIO_FLAG_CANFAIL); |
| 9079 | |
| 9080 | /* |
| 9081 | * Lock out configuration changes. |
| 9082 | */ |
| 9083 | spa_config_enter(spa, SCL_CONFIG, FTAG, RW_READER); |
| 9084 | |
| 9085 | spa->spa_syncing_txg = txg; |
| 9086 | spa->spa_sync_pass = 0; |
| 9087 | |
| 9088 | for (int i = 0; i < spa->spa_alloc_count; i++) { |
| 9089 | mutex_enter(&spa->spa_alloc_locks[i]); |
| 9090 | VERIFY0(avl_numnodes(&spa->spa_alloc_trees[i])); |
| 9091 | mutex_exit(&spa->spa_alloc_locks[i]); |
| 9092 | } |
| 9093 | |
| 9094 | /* |
| 9095 | * If there are any pending vdev state changes, convert them |
| 9096 | * into config changes that go out with this transaction group. |
| 9097 | */ |
| 9098 | spa_config_enter(spa, SCL_STATE, FTAG, RW_READER); |
| 9099 | while (list_head(&spa->spa_state_dirty_list) != NULL) { |
| 9100 | /* |
| 9101 | * We need the write lock here because, for aux vdevs, |
| 9102 | * calling vdev_config_dirty() modifies sav_config. |
| 9103 | * This is ugly and will become unnecessary when we |
| 9104 | * eliminate the aux vdev wart by integrating all vdevs |
| 9105 | * into the root vdev tree. |
| 9106 | */ |
| 9107 | spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG); |
| 9108 | spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_WRITER); |
| 9109 | while ((vd = list_head(&spa->spa_state_dirty_list)) != NULL) { |
| 9110 | vdev_state_clean(vd); |
| 9111 | vdev_config_dirty(vd); |
| 9112 | } |
| 9113 | spa_config_exit(spa, SCL_CONFIG | SCL_STATE, FTAG); |
| 9114 | spa_config_enter(spa, SCL_CONFIG | SCL_STATE, FTAG, RW_READER); |
| 9115 | } |
| 9116 | spa_config_exit(spa, SCL_STATE, FTAG); |
| 9117 | |
| 9118 | dsl_pool_t *dp = spa->spa_dsl_pool; |
| 9119 | dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg); |
| 9120 | |
| 9121 | spa->spa_sync_starttime = gethrtime(); |
| 9122 | taskq_cancel_id(system_delay_taskq, spa->spa_deadman_tqid); |
no test coverage detected