-dsl_dataset_rollback_check(void *arg1, void *arg2, dmu_tx_t *tx)
-{
- dsl_dataset_t *ds = arg1;
- dmu_objset_type_t *ost = arg2;
-
- /*
- * We can only roll back to emptyness if it is a ZPL objset.
- */
- if (*ost != DMU_OST_ZFS &&
- ds->ds_phys->ds_prev_snap_txg < TXG_INITIAL)
- return (EINVAL);
-
- /*
- * This must not be a snapshot.
- */
- if (ds->ds_phys->ds_next_snap_obj != 0)
- return (EINVAL);
-
- /*
- * If we made changes this txg, traverse_dataset won't find
- * them. Try again.
- */
- if (ds->ds_phys->ds_bp.blk_birth >= tx->tx_txg)
- return (EAGAIN);
-
- return (0);
-}
-
-/* ARGSUSED */
-static void
-dsl_dataset_rollback_sync(void *arg1, void *arg2, cred_t *cr, dmu_tx_t *tx)
-{
- dsl_dataset_t *ds = arg1;
- dmu_objset_type_t *ost = arg2;
- objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
-
- dmu_buf_will_dirty(ds->ds_dbuf, tx);
-
- if (ds->ds_user_ptr != NULL) {
- /*
- * We need to make sure that the objset_impl_t is reopened after
- * we do the rollback, otherwise it will have the wrong
- * objset_phys_t. Normally this would happen when this
- * dataset-open is closed, thus causing the
- * dataset to be immediately evicted. But when doing "zfs recv
- * -F", we reopen the objset before that, so that there is no
- * window where the dataset is closed and inconsistent.
- */
- ds->ds_user_evict_func(ds, ds->ds_user_ptr);
- ds->ds_user_ptr = NULL;
- }
-
- /* Transfer space that was freed since last snap back to the head. */
- {
- uint64_t used;
-
- VERIFY(0 == bplist_space_birthrange(&ds->ds_deadlist,
- ds->ds_origin_txg, UINT64_MAX, &used));
- dsl_dir_transfer_space(ds->ds_dir, used,
- DD_USED_SNAP, DD_USED_HEAD, tx);
- }
-
- /* Zero out the deadlist. */
- bplist_close(&ds->ds_deadlist);
- bplist_destroy(mos, ds->ds_phys->ds_deadlist_obj, tx);
- ds->ds_phys->ds_deadlist_obj =
- bplist_create(mos, DSL_DEADLIST_BLOCKSIZE, tx);
- VERIFY(0 == bplist_open(&ds->ds_deadlist, mos,
- ds->ds_phys->ds_deadlist_obj));
-
- {
- /*
- * Free blkptrs that we gave birth to - this covers
- * claimed but not played log blocks too.
- */
- zio_t *zio;
- struct killarg ka;
-
- zio = zio_root(tx->tx_pool->dp_spa, NULL, NULL,
- ZIO_FLAG_MUSTSUCCEED);
- ka.ds = ds;
- ka.zio = zio;
- ka.tx = tx;
- (void) traverse_dataset(ds, ds->ds_phys->ds_prev_snap_txg,
- TRAVERSE_POST, kill_blkptr, &ka);
- (void) zio_wait(zio);
- }
-
- ASSERT(!DS_UNIQUE_IS_ACCURATE(ds) || ds->ds_phys->ds_unique_bytes == 0);
-
- if (ds->ds_prev && ds->ds_prev != ds->ds_dir->dd_pool->dp_origin_snap) {
- /* Change our contents to that of the prev snapshot */
-
- ASSERT3U(ds->ds_prev->ds_object, ==,
- ds->ds_phys->ds_prev_snap_obj);
- ASSERT3U(ds->ds_phys->ds_used_bytes, <=,
- ds->ds_prev->ds_phys->ds_used_bytes);
-
- ds->ds_phys->ds_bp = ds->ds_prev->ds_phys->ds_bp;
- ds->ds_phys->ds_used_bytes =
- ds->ds_prev->ds_phys->ds_used_bytes;
- ds->ds_phys->ds_compressed_bytes =
- ds->ds_prev->ds_phys->ds_compressed_bytes;
- ds->ds_phys->ds_uncompressed_bytes =
- ds->ds_prev->ds_phys->ds_uncompressed_bytes;
- ds->ds_phys->ds_flags = ds->ds_prev->ds_phys->ds_flags;
-
- if (ds->ds_prev->ds_phys->ds_next_snap_obj == ds->ds_object) {
- dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx);
- ds->ds_prev->ds_phys->ds_unique_bytes = 0;
- }
- } else {
- objset_impl_t *osi;
-
- ASSERT(*ost != DMU_OST_ZVOL);
- ASSERT3U(ds->ds_phys->ds_used_bytes, ==, 0);
- ASSERT3U(ds->ds_phys->ds_compressed_bytes, ==, 0);
- ASSERT3U(ds->ds_phys->ds_uncompressed_bytes, ==, 0);
-
- bzero(&ds->ds_phys->ds_bp, sizeof (blkptr_t));
- ds->ds_phys->ds_flags = 0;
- ds->ds_phys->ds_unique_bytes = 0;
- if (spa_version(ds->ds_dir->dd_pool->dp_spa) >=
- SPA_VERSION_UNIQUE_ACCURATE)
- ds->ds_phys->ds_flags |= DS_FLAG_UNIQUE_ACCURATE;
-
- osi = dmu_objset_create_impl(ds->ds_dir->dd_pool->dp_spa, ds,
- &ds->ds_phys->ds_bp, *ost, tx);
-#ifdef _KERNEL
- zfs_create_fs(&osi->os, kcred, NULL, tx);
-#endif
- }
-
- spa_history_internal_log(LOG_DS_ROLLBACK, ds->ds_dir->dd_pool->dp_spa,
- tx, cr, "dataset = %llu", ds->ds_object);
-}
-
-/* ARGSUSED */
-static int