3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * CDDL HEADER START
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The contents of this file are subject to the terms of the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Common Development and Distribution License (the "License").
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * You may not use this file except in compliance with the License.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * or http://www.opensolaris.org/os/licensing.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * See the License for the specific language governing permissions
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * and limitations under the License.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * When distributing Covered Code, include this CDDL HEADER in each
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * If applicable, add the following below this CDDL HEADER, with the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * fields enclosed by brackets "[]" replaced with your own identifying
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * CDDL HEADER END
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
ca0cc3918a1789fa839194af2a9245f801a06b1aMatthew Ahrens * Copyright (c) 2012, 2015 by Delphix. All rights reserved.
a7a845e4bf22fd1b2a284729ccd95c7370a0438cSteven Hartland * Copyright (c) 2013 Steven Hartland. All rights reserved.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Copyright (c) 2013 by Joyent, Inc. All rights reserved.
c3d26abc9ee97b4f60233556aadeb57e0bd30bb9Matthew Ahrens * Copyright (c) 2014 Integros [integros.com]
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_snapshot_check_impl(dsl_dataset_t *ds, boolean_t defer)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Only allow deferred destroy on pools that support it.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * NOTE: deferred destroy is only supported on snapshots.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (spa_version(ds->ds_dir->dd_pool->dp_spa) <
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * If this snapshot has an elevated user reference count,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * we can't destroy it yet.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Can't delete a branch point.
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds)->ds_num_children > 1)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_snapshot_check(void *arg, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (pair = nvlist_next_nvpair(dsda->dsda_snaps, NULL);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens pair != NULL; pair = nvlist_next_nvpair(dsda->dsda_snaps, pair)) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, nvpair_name(pair),
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * If the snapshot does not exist, silently ignore it
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * (it's "already destroyed").
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens fnvlist_add_boolean(dsda->dsda_successful_snaps,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens pair = nvlist_next_nvpair(dsda->dsda_errlist, NULL);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensprocess_old_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (bp->blk_birth <= dsl_dataset_phys(poa->ds)->ds_prev_snap_txg) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_deadlist_insert(&poa->ds->ds_deadlist, bp, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (poa->ds_prev && !poa->after_branch_point &&
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(poa->ds_prev)->ds_prev_snap_txg) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(poa->ds_prev)->ds_unique_bytes +=
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens poa->used += bp_get_dsize_sync(dp->dp_spa, bp);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensprocess_old_deadlist(dsl_dataset_t *ds, dsl_dataset_t *ds_prev,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_t *ds_next, boolean_t after_branch_point, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens poa.pio = zio_root(dp->dp_spa, NULL, NULL, ZIO_FLAG_MUSTSUCCEED);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(bpobj_iterate(&ds_next->ds_deadlist.dl_bpobj,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT3U(poa.used, ==, dsl_dataset_phys(ds)->ds_unique_bytes);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* change snapused */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dir_diduse_space(ds->ds_dir, DD_USED_SNAP,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* swap next's deadlist to our deadlist */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs deadlist_obj = dsl_dataset_phys(ds)->ds_deadlist_obj;
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_next)->ds_deadlist_obj = deadlist_obj;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_deadlist_open(&ds_next->ds_deadlist, mos,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_next)->ds_deadlist_obj);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_dataset_remove_clones_key(dsl_dataset_t *ds, uint64_t mintxg, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens objset_t *mos = ds->ds_dir->dd_pool->dp_meta_objset;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * If it is the old version, dd_clones doesn't exist so we can't
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * find the clones, but dsl_deadlist_remove_key() is a no-op so it
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * doesn't matter.
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dir_phys(ds->ds_dir)->dd_clones == 0)
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs for (zap_cursor_init(&zc, mos, dsl_dir_phys(ds->ds_dir)->dd_clones);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold_obj(ds->ds_dir->dd_pool,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_remove_clones_key(clone, mintxg, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_snapshot_sync_impl(dsl_dataset_t *ds, boolean_t defer, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT3U(dsl_dataset_phys(ds)->ds_bp.blk_birth, <=, tx->tx_txg);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_num_children > 1)) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT(spa_version(dp->dp_spa) >= SPA_VERSION_USERREFS);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_flags |= DS_FLAG_DEFER_DESTROY;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens spa_history_log_internal_ds(ds, "defer_destroy", tx, "");
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT3U(dsl_dataset_phys(ds)->ds_num_children, <=, 1);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* We need to log before removing it from the namespace. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens spa_history_log_internal_ds(ds, "destroy", tx, "");
ca0cc3918a1789fa839194af2a9245f801a06b1aMatthew Ahrens for (spa_feature_t f = 0; f < SPA_FEATURES; f++) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds)->ds_prev_snap_obj != 0) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_prev_snap_obj, FTAG, &ds_prev));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs (dsl_dataset_phys(ds_prev)->ds_next_snap_obj != obj);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_prev)->ds_next_clones_obj != 0) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_remove_from_next_clones(ds_prev, obj, tx);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds)->ds_next_snap_obj != 0) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_prev)->ds_next_snap_obj =
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_next_snap_obj, FTAG, &ds_next));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT3U(dsl_dataset_phys(ds_next)->ds_prev_snap_obj, ==, obj);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs old_unique = dsl_dataset_phys(ds_next)->ds_unique_bytes;
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_next)->ds_prev_snap_obj =
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_next)->ds_prev_snap_txg =
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT3U(dsl_dataset_phys(ds)->ds_prev_snap_txg, ==,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ds_prev ? dsl_dataset_phys(ds_prev)->ds_creation_txg : 0);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Adjust prev's unique space. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_deadlist_space_range(&ds_next->ds_deadlist,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_prev)->ds_prev_snap_txg,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_prev)->ds_unique_bytes += used;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Adjust snapused. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_deadlist_space_range(&ds_next->ds_deadlist,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_prev_snap_txg, UINT64_MAX,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dir_diduse_space(ds->ds_dir, DD_USED_SNAP,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Move blocks to be freed to pool's free list. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_deadlist_move_bpobj(&ds_next->ds_deadlist,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs &dp->dp_free_bpobj, dsl_dataset_phys(ds)->ds_prev_snap_txg,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dir_diduse_space(tx->tx_pool->dp_free_dir,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Merge our deadlist into next's and free it. */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_deadlist_free(mos, dsl_dataset_phys(ds)->ds_deadlist_obj, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Collapse range in clone heads */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Update next's unique to include blocks which
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * were previously shared by only this snapshot
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * and it. Those blocks will be born after the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * prev snap and before this snap, and will have
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * died after the next snap and before the one
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * after that (ie. be on the snap after next's
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_next)->ds_next_snap_obj,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_deadlist_space_range(&ds_nextnext->ds_deadlist,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds_next)->ds_unique_bytes += used;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Collapse range in this head. */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(ds->ds_dir)->dd_head_dataset_obj, FTAG, &hds));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Reduce the amount of our unconsumed refreservation
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * being charged to our parent by the amount of
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * new unique data we have gained.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * This must be done after the dsl_traverse(), because it will
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * re-open the objset.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* remove from snapshot namespace */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT(dsl_dataset_phys(ds)->ds_snapnames_zapobj == 0);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(ds->ds_dir)->dd_head_dataset_obj, FTAG, &ds_head));
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek VERIFY0(dsl_dataset_snap_remove(ds_head, ds->ds_snapname, tx, B_TRUE));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens spa_prop_clear_bootfs(dp->dp_spa, ds->ds_object, tx);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds)->ds_next_clones_obj != 0) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_next_clones_obj, &count) &&
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_next_clones_obj, tx));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds)->ds_props_obj != 0)
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs VERIFY0(zap_destroy(mos, dsl_dataset_phys(ds)->ds_props_obj,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds)->ds_userrefs_obj != 0)
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs VERIFY0(zap_destroy(mos, dsl_dataset_phys(ds)->ds_userrefs_obj,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_snapshot_sync(void *arg, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (pair = nvlist_next_nvpair(dsda->dsda_successful_snaps, NULL);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens pair = nvlist_next_nvpair(dsda->dsda_successful_snaps, pair)) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold(dp, nvpair_name(pair), FTAG, &ds));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_destroy_snapshot_sync_impl(ds, dsda->dsda_defer, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The semantics of this function are described in the comment above
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * lzc_destroy_snaps(). To summarize:
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * The snapshots must all be in the same pool.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Snapshots that don't exist will be silently ignored (considered to be
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * "already deleted").
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * On success, all snaps will be destroyed and this will return 0.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * On failure, no snaps will be destroyed, the errlist will be filled in,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * and this will return an errno.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_snapshots_nvl(nvlist_t *snaps, boolean_t defer,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsda.dsda_successful_snaps = fnvlist_alloc();
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_destroy_snapshot_check, dsl_destroy_snapshot_sync,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_snapshot(const char *name, boolean_t defer)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_destroy_snapshots_nvl(nvl, defer, errlist);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens/* ARGSUSED */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrenskill_blkptr(spa_t *spa, zilog_t *zilog, const blkptr_t *bp,
7802d7bf98dec568dadf72286893b1fe5abd8602Matthew Ahrens const zbookmark_phys_t *zb, const dnode_phys_t *dnp, void *arg)
a2cdcdd260232b58202b11a9bfc0103c9449ed52Paul Dagnelie if (bp == NULL || BP_IS_HOLE(bp) || BP_IS_EMBEDDED(bp))
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * It's a block in the intent log. It has no
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * accounting, so just free it.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_free(ka->tx->tx_pool, ka->tx->tx_txg, bp);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ka->ds)->ds_prev_snap_txg);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (void) dsl_dataset_block_kill(ka->ds, bp, tx, B_FALSE);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensold_synchronous_dataset_destroy(dsl_dataset_t *ds, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Free everything that we point to (that's born after
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * the previous snapshot, if we are a clone)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * NB: this should be very quick, because we already
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * freed all the objects in open context.
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_prev_snap_txg, TRAVERSE_POST,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_unique_bytes == 0);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_head_check_impl(dsl_dataset_t *ds, int expected_holds)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (refcount_count(&ds->ds_longholds) != expected_holds)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Can't delete a head dataset if there are snapshots of it.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * (Except if the only snapshots are from the branch we cloned
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds->ds_prev)->ds_next_snap_obj == ds->ds_object)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Can't delete if there are children of this fs.
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(ds->ds_dir)->dd_child_dir_zapobj, &count);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (dsl_dir_is_clone(ds->ds_dir) && DS_IS_DEFER_DESTROY(ds->ds_prev) &&
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds->ds_prev)->ds_num_children == 2 &&
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* We need to remove the origin snapshot as well. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (!refcount_is_zero(&ds->ds_prev->ds_longholds))
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_head_check(void *arg, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_dataset_hold(dp, ddha->ddha_name, FTAG, &ds);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_dir_destroy_sync(uint64_t ddobj, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT(RRW_WRITE_HELD(&dmu_tx_pool(tx)->dp_config_rwlock));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dir_hold_obj(dp, ddobj, NULL, FTAG, &dd));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT0(dsl_dir_phys(dd)->dd_head_dataset_obj);
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * Decrement the filesystem count for all parent filesystems.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * When we receive an incremental stream into a filesystem that already
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * exists, a temporary clone is created. We never count this temporary
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek * clone, whose name begins with a '%'.
a2afb611b30628fb74ad9eade4ae465f9031e262Jerry Jelinek if (dd->dd_myname[0] != '%' && dd->dd_parent != NULL)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Remove our reservation. The impl() routine avoids setting the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * actual property, which would require the (already destroyed) ds.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dir_set_reservation_sync_impl(dd, 0, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens for (t = 0; t < DD_USED_NUM; t++)
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT0(dsl_dir_phys(dd)->dd_used_breakdown[t]);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs VERIFY0(zap_destroy(mos, dsl_dir_phys(dd)->dd_child_dir_zapobj, tx));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs VERIFY0(zap_destroy(mos, dsl_dir_phys(dd)->dd_props_zapobj, tx));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs VERIFY0(dsl_deleg_destroy(mos, dsl_dir_phys(dd)->dd_deleg_zapobj, tx));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(dd->dd_parent)->dd_child_dir_zapobj,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_head_sync_impl(dsl_dataset_t *ds, dmu_tx_t *tx)
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT3U(dsl_dataset_phys(ds)->ds_num_children, <=, 1);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds->ds_prev)->ds_next_snap_obj != ds->ds_object);
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT3U(dsl_dataset_phys(ds)->ds_bp.blk_birth, <=, tx->tx_txg);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens ASSERT(RRW_WRITE_HELD(&dp->dp_config_rwlock));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* We need to log before removing it from the namespace. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens spa_history_log_internal_ds(ds, "destroy", tx, "");
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds->ds_prev)->ds_num_children == 2 &&
5d7b4d438c4a51eccc95e77a83a437b4d48380ebMatthew Ahrens /* Remove our reservation. */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens (ZPROP_SRC_NONE | ZPROP_SRC_LOCAL | ZPROP_SRC_RECEIVED),
ca0cc3918a1789fa839194af2a9245f801a06b1aMatthew Ahrens for (spa_feature_t f = 0; f < SPA_FEATURES; f++) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds)->ds_prev_snap_obj != 0) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* This is a clone */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT3U(dsl_dataset_phys(ds->ds_prev)->ds_next_snap_obj, !=,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT0(dsl_dataset_phys(ds)->ds_next_snap_obj);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dmu_buf_will_dirty(ds->ds_prev->ds_dbuf, tx);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs if (dsl_dataset_phys(ds->ds_prev)->ds_next_clones_obj != 0) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dataset_remove_from_next_clones(ds->ds_prev,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT3U(dsl_dataset_phys(ds->ds_prev)->ds_num_children, >, 1);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds->ds_prev)->ds_num_children--;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Destroy the deadlist. Unless it's a clone, the
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * deadlist should be empty. (If it's a clone, it's
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * safe to ignore the deadlist contents.)
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_deadlist_free(mos, dsl_dataset_phys(ds)->ds_deadlist_obj, tx);
2acef22db7808606888f8f92715629ff3ba555b9Matthew Ahrens if (!spa_feature_is_enabled(dp->dp_spa, SPA_FEATURE_ASYNC_DESTROY)) {
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Move the bptree into the pool's list of trees to
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * clean up and update space accounting information.
2acef22db7808606888f8f92715629ff3ba555b9Matthew Ahrens spa_feature_incr(dp->dp_spa, SPA_FEATURE_ASYNC_DESTROY,
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs used = dsl_dir_phys(ds->ds_dir)->dd_used_bytes;
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs comp = dsl_dir_phys(ds->ds_dir)->dd_compressed_bytes;
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs uncomp = dsl_dir_phys(ds->ds_dir)->dd_uncompressed_bytes;
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_unique_bytes == used);
c166b69d29138aed7a415fe7cef698e54c6ae945Paul Dagnelie rrw_enter(&ds->ds_bp_rwlock, RW_READER, FTAG);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dir_diduse_space(ds->ds_dir, DD_USED_HEAD,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_dir_diduse_space(dp->dp_free_dir, DD_USED_HEAD,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (spa_version(dp->dp_spa) >= SPA_VERSION_DIR_CLONES) {
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(ds->ds_prev->ds_dir)->dd_clones,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * This must be done after the dsl_traverse(), because it will
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * re-open the objset.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Erase the link in the dir */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dir_phys(ds->ds_dir)->dd_head_dataset_obj = 0;
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT(dsl_dataset_phys(ds)->ds_snapnames_zapobj != 0);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_snapnames_zapobj, tx));
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs VERIFY0(zap_destroy(mos, ds->ds_bookmarks, tx));
78f171005391b928aaf1642b3206c534ed644332Matthew Ahrens spa_feature_decr(dp->dp_spa, SPA_FEATURE_BOOKMARKS, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens spa_prop_clear_bootfs(dp->dp_spa, ds->ds_object, tx);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT0(dsl_dataset_phys(ds)->ds_next_clones_obj);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT0(dsl_dataset_phys(ds)->ds_props_obj);
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs ASSERT0(dsl_dataset_phys(ds)->ds_userrefs_obj);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold_obj(dp, prevobj, FTAG, &prev));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens dsl_destroy_snapshot_sync_impl(prev, B_FALSE, tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_head_sync(void *arg, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold(dp, ddha->ddha_name, FTAG, &ds));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_head_begin_sync(void *arg, dmu_tx_t *tx)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens VERIFY0(dsl_dataset_hold(dp, ddha->ddha_name, FTAG, &ds));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* Mark it as inconsistent on-disk, in case we crash */
c1379625401dfbe1c39b79136dd384a571d47fdeJustin T. Gibbs dsl_dataset_phys(ds)->ds_flags |= DS_FLAG_INCONSISTENT;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens spa_history_log_internal_ds(ds, "destroy begin", tx, "");
2acef22db7808606888f8f92715629ff3ba555b9Matthew Ahrens isenabled = spa_feature_is_enabled(spa, SPA_FEATURE_ASYNC_DESTROY);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dsl_sync_task(name, dsl_destroy_head_check,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Head deletion is processed in one txg on old pools;
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * remove the objects from open context so that the txg sync
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * is not too long.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens error = dmu_objset_own(name, DMU_OST_ANY, B_FALSE, FTAG, &os);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens /* sync out all frees */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens return (dsl_sync_task(name, dsl_destroy_head_check,
7d46dc6ca63a6f3f0d51aa655bfcf10cf2405a9eMatthew Ahrens dsl_destroy_head_sync, &ddha, 0, ZFS_SPACE_CHECK_NONE));
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * Note, this function is used as the callback for dmu_objset_find(). We
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * always return 0 so that we will continue to find and process
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * inconsistent datasets, even if we encounter an error trying to
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens * process one of them.
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens/* ARGSUSED */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensdsl_destroy_inconsistent(const char *dsname, void *arg)
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens if (dmu_objset_hold(dsname, FTAG, &os) == 0) {
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens boolean_t need_destroy = DS_IS_INCONSISTENT(dmu_objset_ds(os));
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * If the dataset is inconsistent because a resumable receive
9c3fd1216fa7fb02cfbc78a2518a686d54b48ab8Matthew Ahrens * has failed, then do not destroy it.