bptree.c revision fb09f5aad449c97fe309678f3f604982b563a96f
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * CDDL HEADER START
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * The contents of this file are subject to the terms of the
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * Common Development and Distribution License (the "License").
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * You may not use this file except in compliance with the License.
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * See the License for the specific language governing permissions
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * and limitations under the License.
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * When distributing Covered Code, include this CDDL HEADER in each
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * If applicable, add the following below this CDDL HEADER, with the
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * fields enclosed by brackets "[]" replaced with your own identifying
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * information: Portions Copyright [yyyy] [name of copyright owner]
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * CDDL HEADER END
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * Copyright (c) 2012 by Delphix. All rights reserved.
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * A bptree is a queue of root block pointers from destroyed datasets. When a
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * dataset is destroyed its root block pointer is put on the end of the pool's
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * bptree queue so the dataset's blocks can be freed asynchronously by
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * dsl_scan_sync. This allows the delete operation to finish without traversing
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * all the dataset's blocks.
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * Note that while bt_begin and bt_end are only ever incremented in this code
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * they are effectively reset to 0 every time the entire bptree is freed because
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * the bptree's object is destroyed and re-created.
53089ab7c84db6fb76c16ca50076c147cda11757eschrock bptree_phys_t *ba_phys; /* data in bonus buffer, dirtied if freeing */
53089ab7c84db6fb76c16ca50076c147cda11757eschrock boolean_t ba_free; /* true if freeing during traversal */
53089ab7c84db6fb76c16ca50076c147cda11757eschrock bptree_itor_t *ba_func; /* function to call for each blockpointer */
53089ab7c84db6fb76c16ca50076c147cda11757eschrock void *ba_arg; /* caller supplied argument to ba_func */
53089ab7c84db6fb76c16ca50076c147cda11757eschrock dmu_tx_t *ba_tx; /* caller supplied tx, NULL if not freeing */
53089ab7c84db6fb76c16ca50076c147cda11757eschrock obj = dmu_object_alloc(os, DMU_OTN_UINT64_METADATA,
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * Bonus buffer contents are already initialized to 0, but for
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * readability we make it explicit.
b420f3adeb349714478d1a7813d2c0e069d41555Richard Lowe VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
53089ab7c84db6fb76c16ca50076c147cda11757eschrockbptree_free(objset_t *os, uint64_t obj, dmu_tx_t *tx)
b420f3adeb349714478d1a7813d2c0e069d41555Richard Lowe VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
53089ab7c84db6fb76c16ca50076c147cda11757eschrockbptree_add(objset_t *os, uint64_t obj, blkptr_t *bp, uint64_t birth_txg,
53089ab7c84db6fb76c16ca50076c147cda11757eschrock uint64_t bytes, uint64_t comp, uint64_t uncomp, dmu_tx_t *tx)
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * bptree objects are in the pool mos, therefore they can only be
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * modified in syncing context. Furthermore, this is only modified
53089ab7c84db6fb76c16ca50076c147cda11757eschrock * by the sync thread, so no locking is necessary.
b420f3adeb349714478d1a7813d2c0e069d41555Richard Lowe VERIFY3U(0, ==, dmu_bonus_hold(os, obj, FTAG, &db));
53089ab7c84db6fb76c16ca50076c147cda11757eschrock dmu_write(os, obj, bt->bt_end * sizeof (bte), sizeof (bte), &bte, tx);
53089ab7c84db6fb76c16ca50076c147cda11757eschrock/* ARGSUSED */
53089ab7c84db6fb76c16ca50076c147cda11757eschrockbptree_visit_cb(spa_t *spa, zilog_t *zilog, const blkptr_t *bp, arc_buf_t *pbuf,
53089ab7c84db6fb76c16ca50076c147cda11757eschrock const zbookmark_t *zb, const dnode_phys_t *dnp, void *arg)
53089ab7c84db6fb76c16ca50076c147cda11757eschrock return (0);
53089ab7c84db6fb76c16ca50076c147cda11757eschrock ba->ba_phys->bt_bytes -= bp_get_dsize_sync(spa, bp);
53089ab7c84db6fb76c16ca50076c147cda11757eschrockbptree_iterate(objset_t *os, uint64_t obj, boolean_t free, bptree_itor_t func,
53089ab7c84db6fb76c16ca50076c147cda11757eschrock for (i = ba.ba_phys->bt_begin; i < ba.ba_phys->bt_end; i++) {
53089ab7c84db6fb76c16ca50076c147cda11757eschrock err = dmu_read(os, obj, i * sizeof (bte), sizeof (bte),
53089ab7c84db6fb76c16ca50076c147cda11757eschrock err = traverse_dataset_destroyed(os->os_spa, &bte.be_bp,
53089ab7c84db6fb76c16ca50076c147cda11757eschrock if (err != 0) {
53089ab7c84db6fb76c16ca50076c147cda11757eschrock /* save bookmark for future resume */
53089ab7c84db6fb76c16ca50076c147cda11757eschrock ASSERT(!free || err != 0 || ba.ba_phys->bt_begin == ba.ba_phys->bt_end);
53089ab7c84db6fb76c16ca50076c147cda11757eschrock /* if all blocks are free there should be no used space */