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/*
3113f7cee6785cfe8d9e78c535cf9e2a79283275George Wilson * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * Copyright (c) 2013 by Delphix. All rights reserved.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifndef _SYS_DSL_POOL_H
fa9e4066f08beec538e775443c5be79dd423fcabahrens#define _SYS_DSL_POOL_H
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/spa.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/txg.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/txg_impl.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens#include <sys/zfs_context.h>
088f389458728c464569a5506b58070254fa4f7dahrens#include <sys/zio.h>
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens#include <sys/dnode.h>
bbfd46c40e81c7d954cec28db66453ec5ab44613Jeff Bonwick#include <sys/ddt.h>
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling#include <sys/arc.h>
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens#include <sys/bpobj.h>
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden#include <sys/bptree.h>
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens#include <sys/rrwlock.h>
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifdef __cplusplus
fa9e4066f08beec538e775443c5be79dd423fcabahrensextern "C" {
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrensstruct objset;
fa9e4066f08beec538e775443c5be79dd423fcabahrensstruct dsl_dir;
088f389458728c464569a5506b58070254fa4f7dahrensstruct dsl_dataset;
088f389458728c464569a5506b58070254fa4f7dahrensstruct dsl_pool;
088f389458728c464569a5506b58070254fa4f7dahrensstruct dmu_tx;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingstruct dsl_scan;
088f389458728c464569a5506b58070254fa4f7dahrens
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensextern uint64_t zfs_dirty_data_max;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensextern uint64_t zfs_dirty_data_max_max;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensextern uint64_t zfs_dirty_data_sync;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensextern int zfs_dirty_data_max_percent;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensextern int zfs_delay_min_dirty_percent;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensextern uint64_t zfs_delay_scale;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens/* These macros are for indexing into the zfs_all_blkstats_t. */
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens#define DMU_OT_DEFERRED DMU_OT_NONE
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden#define DMU_OT_OTHER DMU_OT_NUMTYPES /* place holder for DMU_OT() types */
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden#define DMU_OT_TOTAL (DMU_OT_NUMTYPES + 1)
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrenstypedef struct zfs_blkstat {
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t zb_count;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t zb_asize;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t zb_lsize;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t zb_psize;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t zb_gangs;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t zb_ditto_2_of_2_samevdev;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t zb_ditto_2_of_3_samevdev;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens uint64_t zb_ditto_3_of_3_samevdev;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens} zfs_blkstat_t;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrenstypedef struct zfs_all_blkstats {
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens zfs_blkstat_t zab_type[DN_MAX_LEVELS + 1][DMU_OT_TOTAL + 1];
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens} zfs_all_blkstats_t;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrenstypedef struct dsl_pool {
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Immutable */
fa9e4066f08beec538e775443c5be79dd423fcabahrens spa_t *dp_spa;
fa9e4066f08beec538e775443c5be79dd423fcabahrens struct objset *dp_meta_objset;
fa9e4066f08beec538e775443c5be79dd423fcabahrens struct dsl_dir *dp_root_dir;
fa9e4066f08beec538e775443c5be79dd423fcabahrens struct dsl_dir *dp_mos_dir;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens struct dsl_dir *dp_free_dir;
7fd05ac4dec0c343d2f68f310d3718b715ecfbafMatthew Ahrens struct dsl_dir *dp_leak_dir;
088f389458728c464569a5506b58070254fa4f7dahrens struct dsl_dataset *dp_origin_snap;
fa9e4066f08beec538e775443c5be79dd423fcabahrens uint64_t dp_root_dir_obj;
9d3574bff0b382b89dd380c1e23d742ebc156772Neil Perrin struct taskq *dp_vnrele_taskq;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* No lock needed - sync context only */
fa9e4066f08beec538e775443c5be79dd423fcabahrens blkptr_t dp_meta_rootbp;
ca45db4129beff691dc46576c328149443788af2Chris Kirby uint64_t dp_tmp_userrefs_obj;
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrens bpobj_t dp_free_bpobj;
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Siden uint64_t dp_bptree_obj;
f17457368189aa911f774c38c1f21875a568bdcaMatthew Ahrens uint64_t dp_empty_bpobj;
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling struct dsl_scan *dp_scan;
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Ling
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee /* Uses dp_lock */
1ab7f2ded02e7a1bc3c73516eb27efa79bf2a2ffmaybee kmutex_t dp_lock;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens kcondvar_t dp_spaceavail_cv;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens uint64_t dp_dirty_pertxg[TXG_SIZE];
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens uint64_t dp_dirty_total;
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens uint64_t dp_mos_used_delta;
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens uint64_t dp_mos_compressed_delta;
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens uint64_t dp_mos_uncompressed_delta;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens /*
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * Time of most recently scheduled (furthest in the future)
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens * wakeup for delayed transactions.
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens */
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens hrtime_t dp_last_wakeup;
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /* Has its own locking */
fa9e4066f08beec538e775443c5be79dd423fcabahrens tx_state_t dp_tx;
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_t dp_dirty_datasets;
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens txg_list_t dp_dirty_zilogs;
fa9e4066f08beec538e775443c5be79dd423fcabahrens txg_list_t dp_dirty_dirs;
1d452cf5123cb6ac0a013a4dbd4dcceeb0da314dahrens txg_list_t dp_sync_tasks;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens /*
fa9e4066f08beec538e775443c5be79dd423fcabahrens * Protects administrative changes (properties, namespace)
f7170741490edba9d1d9c697c177c887172bc741Will Andrews *
fa9e4066f08beec538e775443c5be79dd423fcabahrens * It is only held for write in syncing context. Therefore
fa9e4066f08beec538e775443c5be79dd423fcabahrens * syncing context does not need to ever have it for read, since
fa9e4066f08beec538e775443c5be79dd423fcabahrens * nobody else could possibly have it for write.
fa9e4066f08beec538e775443c5be79dd423fcabahrens */
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens rrwlock_t dp_config_rwlock;
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens
88b7b0f29b20b808b9e06071885b1d6a3ddb6328Matthew Ahrens zfs_all_blkstats_t *dp_blkstats;
fa9e4066f08beec538e775443c5be79dd423fcabahrens} dsl_pool_t;
fa9e4066f08beec538e775443c5be79dd423fcabahrens
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Sidenint dsl_pool_init(spa_t *spa, uint64_t txg, dsl_pool_t **dpp);
ad135b5d644628e791c3188a6ecbd9c257961ef8Christopher Sidenint dsl_pool_open(dsl_pool_t *dp);
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid dsl_pool_close(dsl_pool_t *dp);
0a48a24e663a04e34e2ed4e55390ad96f178dbeatimhdsl_pool_t *dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrensvoid dsl_pool_sync(dsl_pool_t *dp, uint64_t txg);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickvoid dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg);
fa9e4066f08beec538e775443c5be79dd423fcabahrensint dsl_pool_sync_context(dsl_pool_t *dp);
fa9e4066f08beec538e775443c5be79dd423fcabahrensuint64_t dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree);
468c413a79615e77179e8d98f22a7e513a8135bdTim Haleyuint64_t dsl_pool_adjustedfree(dsl_pool_t *dp, boolean_t netfree);
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensvoid dsl_pool_dirty_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx);
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensvoid dsl_pool_undirty_space(dsl_pool_t *dp, int64_t space, uint64_t txg);
b24ab6762772a3f6a89393947930c7fa61306783Jeff Bonwickvoid dsl_free(dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp);
3113f7cee6785cfe8d9e78c535cf9e2a79283275George Wilsonvoid dsl_free_sync(zio_t *pio, dsl_pool_t *dp, uint64_t txg,
3113f7cee6785cfe8d9e78c535cf9e2a79283275George Wilson const blkptr_t *bpp);
088f389458728c464569a5506b58070254fa4f7dahrensvoid dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx);
088f389458728c464569a5506b58070254fa4f7dahrensvoid dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx);
cde58dbc6a23d4d38db7c8866312be83221c765fMatthew Ahrensvoid dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx);
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrensvoid dsl_pool_mos_diduse_space(dsl_pool_t *dp,
ce636f8b38e8c9ff484e880d9abb27251a882860Matthew Ahrens int64_t used, int64_t comp, int64_t uncomp);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensvoid dsl_pool_config_enter(dsl_pool_t *dp, void *tag);
1d3f896f5469c69c1339890ec3d68e9feddb0343Arne Jansenvoid dsl_pool_config_enter_prio(dsl_pool_t *dp, void *tag);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensvoid dsl_pool_config_exit(dsl_pool_t *dp, void *tag);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensboolean_t dsl_pool_config_held(dsl_pool_t *dp);
12380e1e701fda28c9e9f32d01cafb54af279eb5Arne Jansenboolean_t dsl_pool_config_held_writer(dsl_pool_t *dp);
69962b5647e4a8b9b14998733b765925381b727eMatthew Ahrensboolean_t dsl_pool_need_dirty_delay(dsl_pool_t *dp);
088f389458728c464569a5506b58070254fa4f7dahrens
9d3574bff0b382b89dd380c1e23d742ebc156772Neil Perrintaskq_t *dsl_pool_vnrele_taskq(dsl_pool_t *dp);
9d3574bff0b382b89dd380c1e23d742ebc156772Neil Perrin
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensint dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj,
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrens const char *tag, uint64_t now, dmu_tx_t *tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensint dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj,
ca45db4129beff691dc46576c328149443788af2Chris Kirby const char *tag, dmu_tx_t *tx);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensvoid dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp);
3f9d6ad73e45c6823b409f93b0c8d4f62861d2d5Lin Lingint dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensint dsl_pool_hold(const char *name, void *tag, dsl_pool_t **dp);
3b2aab18808792cbd248a12f1edf139b89833c13Matthew Ahrensvoid dsl_pool_rele(dsl_pool_t *dp, void *tag);
ca45db4129beff691dc46576c328149443788af2Chris Kirby
fa9e4066f08beec538e775443c5be79dd423fcabahrens#ifdef __cplusplus
fa9e4066f08beec538e775443c5be79dd423fcabahrens}
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif
fa9e4066f08beec538e775443c5be79dd423fcabahrens
fa9e4066f08beec538e775443c5be79dd423fcabahrens#endif /* _SYS_DSL_POOL_H */