* Called in syncing context to free committed log blocks and update log header. */
| 3010 | * Called in syncing context to free committed log blocks and update log header. |
| 3011 | */ |
| 3012 | void |
| 3013 | zil_sync(zilog_t *zilog, dmu_tx_t *tx) |
| 3014 | { |
| 3015 | zil_header_t *zh = zil_header_in_syncing_context(zilog); |
| 3016 | uint64_t txg = dmu_tx_get_txg(tx); |
| 3017 | spa_t *spa = zilog->zl_spa; |
| 3018 | uint64_t *replayed_seq = &zilog->zl_replayed_seq[txg & TXG_MASK]; |
| 3019 | lwb_t *lwb; |
| 3020 | |
| 3021 | /* |
| 3022 | * We don't zero out zl_destroy_txg, so make sure we don't try |
| 3023 | * to destroy it twice. |
| 3024 | */ |
| 3025 | if (spa_sync_pass(spa) != 1) |
| 3026 | return; |
| 3027 | |
| 3028 | mutex_enter(&zilog->zl_lock); |
| 3029 | |
| 3030 | ASSERT(zilog->zl_stop_sync == 0); |
| 3031 | |
| 3032 | if (*replayed_seq != 0) { |
| 3033 | ASSERT(zh->zh_replay_seq < *replayed_seq); |
| 3034 | zh->zh_replay_seq = *replayed_seq; |
| 3035 | *replayed_seq = 0; |
| 3036 | } |
| 3037 | |
| 3038 | if (zilog->zl_destroy_txg == txg) { |
| 3039 | blkptr_t blk = zh->zh_log; |
| 3040 | |
| 3041 | ASSERT(list_head(&zilog->zl_lwb_list) == NULL); |
| 3042 | |
| 3043 | bzero(zh, sizeof (zil_header_t)); |
| 3044 | bzero(zilog->zl_replayed_seq, sizeof (zilog->zl_replayed_seq)); |
| 3045 | |
| 3046 | if (zilog->zl_keep_first) { |
| 3047 | /* |
| 3048 | * If this block was part of log chain that couldn't |
| 3049 | * be claimed because a device was missing during |
| 3050 | * zil_claim(), but that device later returns, |
| 3051 | * then this block could erroneously appear valid. |
| 3052 | * To guard against this, assign a new GUID to the new |
| 3053 | * log chain so it doesn't matter what blk points to. |
| 3054 | */ |
| 3055 | zil_init_log_chain(zilog, &blk); |
| 3056 | zh->zh_log = blk; |
| 3057 | } |
| 3058 | } |
| 3059 | |
| 3060 | while ((lwb = list_head(&zilog->zl_lwb_list)) != NULL) { |
| 3061 | zh->zh_log = lwb->lwb_blk; |
| 3062 | if (lwb->lwb_buf != NULL || lwb->lwb_max_txg > txg) |
| 3063 | break; |
| 3064 | list_remove(&zilog->zl_lwb_list, lwb); |
| 3065 | zio_free(spa, txg, &lwb->lwb_blk); |
| 3066 | zil_free_lwb(zilog, lwb); |
| 3067 | |
| 3068 | /* |
| 3069 | * If we don't have anything left in the lwb list then |
no test coverage detected