dsl_pool.c revision 5ad820458efd0fdb914baff9c1447c22b819fa23
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER START
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * The contents of this file are subject to the terms of the
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Common Development and Distribution License (the "License").
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * You may not use this file except in compliance with the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fa9e4066f08beec538e775443c5be79dd423fcabahrens * or http://www.opensolaris.org/os/licensing.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * See the License for the specific language governing permissions
fa9e4066f08beec538e775443c5be79dd423fcabahrens * and limitations under the License.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * When distributing Covered Code, include this CDDL HEADER in each
fa9e4066f08beec538e775443c5be79dd423fcabahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If applicable, add the following below this CDDL HEADER, with the
fa9e4066f08beec538e775443c5be79dd423fcabahrens * fields enclosed by brackets "[]" replaced with your own identifying
fa9e4066f08beec538e775443c5be79dd423fcabahrens * information: Portions Copyright [yyyy] [name of copyright owner]
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * CDDL HEADER END
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens/*
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Use is subject to license terms.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#pragma ident "%Z%%M% %I% %E% SMI"
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dsl_pool.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dsl_dataset.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dsl_dir.h>
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens#include <sys/dsl_synctask.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dmu_tx.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/dmu_objset.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/arc.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/zap.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/zfs_context.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/fs/zfs.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockstatic int
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockdsl_pool_open_mos_dir(dsl_pool_t *dp, dsl_dir_t **ddp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t obj;
fa9e4066f08beec538e775443c5be79dd423fcabahrens int err;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = zap_lookup(dp->dp_meta_objset,
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp->dp_root_dir->dd_phys->dd_child_dir_zapobj,
fa9e4066f08beec538e775443c5be79dd423fcabahrens MOS_DIR_NAME, sizeof (obj), 1, &obj);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (err);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (dsl_dir_open_obj(dp, obj, MOS_DIR_NAME, dp, ddp));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstatic dsl_pool_t *
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_open_impl(spa_t *spa, uint64_t txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_pool_t *dp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens blkptr_t *bp = spa_get_rootblkptr(spa);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp = kmem_zalloc(sizeof (dsl_pool_t), KM_SLEEP);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp->dp_spa = spa;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp->dp_meta_rootbp = *bp;
5ad820458efd0fdb914baff9c1447c22b819fa23nd rw_init(&dp->dp_config_rwlock, NULL, RW_DEFAULT, NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_init(dp, txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_create(&dp->dp_dirty_datasets,
fa9e4066f08beec538e775443c5be79dd423fcabahrens offsetof(dsl_dataset_t, ds_dirty_link));
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_create(&dp->dp_dirty_dirs,
fa9e4066f08beec538e775443c5be79dd423fcabahrens offsetof(dsl_dir_t, dd_dirty_link));
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens txg_list_create(&dp->dp_sync_tasks,
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens offsetof(dsl_sync_task_group_t, dstg_node));
fa9e4066f08beec538e775443c5be79dd423fcabahrens list_create(&dp->dp_synced_objsets, sizeof (dsl_dataset_t),
fa9e4066f08beec538e775443c5be79dd423fcabahrens offsetof(dsl_dataset_t, ds_synced_link));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (dp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockint
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockdsl_pool_open(spa_t *spa, uint64_t txg, dsl_pool_t **dpp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int err;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock objset_impl_t *osi;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens rw_enter(&dp->dp_config_rwlock, RW_READER);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock err = dmu_objset_open_impl(spa, NULL, &dp->dp_meta_rootbp, &osi);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock goto out;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dp->dp_meta_objset = &osi->os;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = zap_lookup(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
fa9e4066f08beec538e775443c5be79dd423fcabahrens DMU_POOL_ROOT_DATASET, sizeof (uint64_t), 1,
fa9e4066f08beec538e775443c5be79dd423fcabahrens &dp->dp_root_dir_obj);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock goto out;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock err = dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock NULL, dp, &dp->dp_root_dir);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock goto out;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock err = dsl_pool_open_mos_dir(dp, &dp->dp_mos_dir);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock goto out;
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrockout:
fa9e4066f08beec538e775443c5be79dd423fcabahrens rw_exit(&dp->dp_config_rwlock);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (err)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dsl_pool_close(dp);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock else
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock *dpp = dp;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock return (err);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_close(dsl_pool_t *dp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* drop our reference from dsl_pool_open() */
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (dp->dp_mos_dir)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dsl_dir_close(dp->dp_mos_dir, dp);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (dp->dp_root_dir)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dsl_dir_close(dp->dp_root_dir, dp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* undo the dmu_objset_open_impl(mos) from dsl_pool_open() */
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock if (dp->dp_meta_objset)
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock dmu_objset_evict(NULL, dp->dp_meta_objset->os);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_destroy(&dp->dp_dirty_datasets);
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_destroy(&dp->dp_dirty_dirs);
fa9e4066f08beec538e775443c5be79dd423fcabahrens list_destroy(&dp->dp_synced_objsets);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens arc_flush();
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_fini(dp);
5ad820458efd0fdb914baff9c1447c22b819fa23nd rw_destroy(&dp->dp_config_rwlock);
fa9e4066f08beec538e775443c5be79dd423fcabahrens kmem_free(dp, sizeof (dsl_pool_t));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_t *
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_create(spa_t *spa, uint64_t txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens int err;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_pool_t *dp = dsl_pool_open_impl(spa, txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_t *tx = dmu_tx_create_assigned(dp, txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dp->dp_meta_objset = &dmu_objset_create_impl(spa,
fa9e4066f08beec538e775443c5be79dd423fcabahrens NULL, DMU_OST_META, tx)->os;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create the pool directory */
fa9e4066f08beec538e775443c5be79dd423fcabahrens err = zap_create_claim(dp->dp_meta_objset, DMU_POOL_DIRECTORY_OBJECT,
fa9e4066f08beec538e775443c5be79dd423fcabahrens DMU_OT_OBJECT_DIRECTORY, DMU_OT_NONE, 0, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT3U(err, ==, 0);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create and open the root dir */
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_dataset_create_root(dp, &dp->dp_root_dir_obj, tx);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock VERIFY(0 == dsl_dir_open_obj(dp, dp->dp_root_dir_obj,
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock NULL, dp, &dp->dp_root_dir));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* create and open the meta-objset dir */
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens (void) dsl_dir_create_sync(dp->dp_root_dir, MOS_DIR_NAME, tx);
ea8dc4b6d2251b437950c0056bc626b311c73c27eschrock VERIFY(0 == dsl_pool_open_mos_dir(dp, &dp->dp_mos_dir));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_commit(tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (dp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_sync(dsl_pool_t *dp, uint64_t txg)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_t *tx;
fa9e4066f08beec538e775443c5be79dd423fcabahrens objset_impl_t *mosi = dp->dp_meta_objset->os;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens tx = dmu_tx_create_assigned(dp, txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens do {
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_dir_t *dd;
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_dataset_t *ds;
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens dsl_sync_task_group_t *dstg;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens while (ds = txg_list_remove(&dp->dp_dirty_datasets, txg)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (!list_link_active(&ds->ds_synced_link))
fa9e4066f08beec538e775443c5be79dd423fcabahrens list_insert_tail(&dp->dp_synced_objsets, ds);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_dataset_sync(ds, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens while (dstg = txg_list_remove(&dp->dp_sync_tasks, txg))
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens dsl_sync_task_group_sync(dstg, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens while (dd = txg_list_remove(&dp->dp_dirty_dirs, txg))
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_dir_sync(dd, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * We need to loop since dsl_sync_task_group_sync()
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens * could create a new (dirty) objset.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * XXX - isn't this taken care of by the spa's sync to
fa9e4066f08beec538e775443c5be79dd423fcabahrens * convergence loop?
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens } while (!txg_list_empty(&dp->dp_dirty_datasets, txg));
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (list_head(&mosi->os_dirty_dnodes[txg & TXG_MASK]) != NULL ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens list_head(&mosi->os_free_dnodes[txg & TXG_MASK]) != NULL) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_objset_sync(mosi, tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens dprintf_bp(&dp->dp_meta_rootbp, "meta objset rootbp is %s", "");
fa9e4066f08beec538e775443c5be79dd423fcabahrens spa_set_rootblkptr(dp->dp_spa, &dp->dp_meta_rootbp);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens dmu_tx_commit(tx);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_zil_clean(dsl_pool_t *dp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens dsl_dataset_t *ds;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens while (ds = list_head(&dp->dp_synced_objsets)) {
fa9e4066f08beec538e775443c5be79dd423fcabahrens list_remove(&dp->dp_synced_objsets, ds);
fa9e4066f08beec538e775443c5be79dd423fcabahrens ASSERT(ds->ds_user_ptr != NULL);
fa9e4066f08beec538e775443c5be79dd423fcabahrens zil_clean(((objset_impl_t *)ds->ds_user_ptr)->os_zil);
fa9e4066f08beec538e775443c5be79dd423fcabahrens }
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensint
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_sync_context(dsl_pool_t *dp)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Yeah, this is cheesy. But the SPA needs some way to let
fa9e4066f08beec538e775443c5be79dd423fcabahrens * the sync threads invoke spa_open() and spa_close() while
fa9e4066f08beec538e775443c5be79dd423fcabahrens * it holds the namespace lock. I'm certainly open to better
fa9e4066f08beec538e775443c5be79dd423fcabahrens * ideas for how to determine whether the current thread is
fa9e4066f08beec538e775443c5be79dd423fcabahrens * operating on behalf of spa_sync(). This works for now.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (curthread == dp->dp_tx.tx_sync_thread ||
fa9e4066f08beec538e775443c5be79dd423fcabahrens BP_IS_HOLE(&dp->dp_meta_rootbp));
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensuint64_t
fa9e4066f08beec538e775443c5be79dd423fcabahrensdsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree)
fa9e4066f08beec538e775443c5be79dd423fcabahrens{
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t space, resv;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm * Reserve about 1.6% (1/64), or at least 32MB, for allocation
fa9e4066f08beec538e775443c5be79dd423fcabahrens * efficiency.
fa9e4066f08beec538e775443c5be79dd423fcabahrens * XXX The intent log is not accounted for, so it must fit
fa9e4066f08beec538e775443c5be79dd423fcabahrens * within this slop.
fa9e4066f08beec538e775443c5be79dd423fcabahrens *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * If we're trying to assess whether it's OK to do a free,
fa9e4066f08beec538e775443c5be79dd423fcabahrens * cut the reservation in half to allow forward progress
fa9e4066f08beec538e775443c5be79dd423fcabahrens * (e.g. make it possible to rm(1) files from a full pool).
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
99653d4ee642c6528e88224f12409a5f23060994eschrock space = spa_get_dspace(dp->dp_spa);
44cd46cadd9aab751dae6a4023c1cb5bf316d274billm resv = MAX(space >> 6, SPA_MINDEVSIZE >> 1);
fa9e4066f08beec538e775443c5be79dd423fcabahrens if (netfree)
fa9e4066f08beec538e775443c5be79dd423fcabahrens resv >>= 1;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens return (space - resv);
fa9e4066f08beec538e775443c5be79dd423fcabahrens}