dsl_deadlist.c revision cde58dbc6a23d4d38db7c8866312be83221c765f
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * CDDL HEADER START
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * The contents of this file are subject to the terms of the
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Common Development and Distribution License (the "License").
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * You may not use this file except in compliance with the License.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * or http://www.opensolaris.org/os/licensing.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * See the License for the specific language governing permissions
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * and limitations under the License.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * When distributing Covered Code, include this CDDL HEADER in each
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * If applicable, add the following below this CDDL HEADER, with the
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * fields enclosed by brackets "[]" replaced with your own identifying
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * CDDL HEADER END
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_compare(const void *arg1, const void *arg2)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens else if (dle1->dle_mintxg > dle2->dle_mintxg)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens avl_create(&dl->dl_tree, dsl_deadlist_compare,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens for (zap_cursor_init(&zc, dl->dl_os, dl->dl_object);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dsl_deadlist_entry_t *dle = kmem_alloc(sizeof (*dle), KM_SLEEP);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dle->dle_mintxg = strtonum(za.za_name, NULL);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, bpobj_open(&dle->dle_bpobj, dl->dl_os,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_open(dsl_deadlist_t *dl, objset_t *os, uint64_t object)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens mutex_init(&dl->dl_lock, NULL, MUTEX_DEFAULT, NULL);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, dmu_bonus_hold(os, object, dl, &dl->dl_dbuf));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, bpobj_open(&dl->dl_bpobj, os, object));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens while ((dle = avl_destroy_nodes(&dl->dl_tree, &cookie))
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_alloc(objset_t *os, dmu_tx_t *tx)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens if (spa_version(dmu_objset_spa(os)) < SPA_VERSION_DEADLISTS)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens return (bpobj_alloc(os, SPA_MAXBLOCKSIZE, tx));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens return (zap_create(os, DMU_OT_DEADLIST, DMU_OT_DEADLIST_HDR,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_free(objset_t *os, uint64_t dlobj, dmu_tx_t *tx)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, dmu_object_info(os, dlobj, &doi));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, dmu_object_free(os, dlobj, tx));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_insert(dsl_deadlist_t *dl, const blkptr_t *bp, dmu_tx_t *tx)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens bp_get_dsize_sync(dmu_objset_spa(dl->dl_os), bp);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dle = avl_find(&dl->dl_tree, &dle_tofind, &where);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dle = avl_nearest(&dl->dl_tree, where, AVL_BEFORE);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Insert new key in deadlist, which must be > all current entries.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * mintxg is not inclusive.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_add_key(dsl_deadlist_t *dl, uint64_t mintxg, dmu_tx_t *tx)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens obj = bpobj_alloc(dl->dl_os, SPA_MAXBLOCKSIZE, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, bpobj_open(&dle->dle_bpobj, dl->dl_os, obj));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, zap_add_int_key(dl->dl_os, dl->dl_object,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Remove this key, merging its entries into the previous key.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_remove_key(dsl_deadlist_t *dl, uint64_t mintxg, dmu_tx_t *tx)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dle = avl_find(&dl->dl_tree, &dle_tofind, NULL);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, zap_remove_int(dl->dl_os, dl->dl_object, mintxg, tx));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Walk ds's snapshots to regenerate generate ZAP & AVL.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_regenerate(objset_t *os, uint64_t dlobj,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens while (mrs_obj != 0) {
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, dsl_dataset_hold_obj(dp, mrs_obj, FTAG, &ds));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dsl_deadlist_add_key(&dl, ds->ds_phys->ds_prev_snap_txg, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_clone(dsl_deadlist_t *dl, uint64_t maxtxg,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dsl_deadlist_regenerate(dl->dl_os, newobj, mrs_obj, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens obj = bpobj_alloc(dl->dl_os, SPA_MAXBLOCKSIZE, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, zap_add_int_key(dl->dl_os, newobj,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t *usedp, uint64_t *compp, uint64_t *uncompp)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * return space used in the range (mintxg, maxtxg].
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Includes maxtxg, does not include mintxg.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * mintxg and maxtxg must both be keys in the deadlist (unless maxtxg is
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * UINT64_MAX).
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_space_range(dsl_deadlist_t *dl, uint64_t mintxg, uint64_t maxtxg,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t *usedp, uint64_t *compp, uint64_t *uncompp)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, bpobj_space_range(&dl->dl_bpobj,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dle = avl_find(&dl->dl_tree, &dle_tofind, &where);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * If we don't find this mintxg, there shouldn't be anything
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * after it either.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens avl_nearest(&dl->dl_tree, where, AVL_AFTER) == NULL);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_insert_bpobj(dsl_deadlist_t *dl, uint64_t obj, uint64_t birth,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, bpobj_open(&bpo, dl->dl_os, obj));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, bpobj_space(&bpo, &used, &comp, &uncomp));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dle = avl_find(&dl->dl_tree, &dle_tofind, &where);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dle = avl_nearest(&dl->dl_tree, where, AVL_BEFORE);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens bpobj_enqueue_subobj(&dle->dle_bpobj, obj, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_insert_cb(void *arg, const blkptr_t *bp, dmu_tx_t *tx)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Merge the deadlist pointed to by 'obj' into dl. obj will be left as
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * an empty deadlist.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_merge(dsl_deadlist_t *dl, uint64_t obj, dmu_tx_t *tx)
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, dmu_object_info(dl->dl_os, obj, &doi));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, bpobj_open(&bpo, dl->dl_os, obj));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens uint64_t mintxg = strtonum(za.za_name, NULL);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dsl_deadlist_insert_bpobj(dl, za.za_first_integer, mintxg, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, zap_remove_int(dl->dl_os, obj, mintxg, tx));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens VERIFY3U(0, ==, dmu_bonus_hold(dl->dl_os, obj, FTAG, &bonus));
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens * Remove entries on dl that are >= mintxg, and put them on the bpobj.
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensdsl_deadlist_move_bpobj(dsl_deadlist_t *dl, bpobj_t *bpo, uint64_t mintxg,
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dle = avl_find(&dl->dl_tree, &dle_tofind, &where);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens dle = avl_nearest(&dl->dl_tree, where, AVL_AFTER);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens bpobj_enqueue_subobj(bpo, dle->dle_bpobj.bpo_object, tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens ASSERT3U(dl->dl_phys->dl_uncomp, >=, uncomp);