1fa9e406ahrens/*
2fa9e406ahrens * CDDL HEADER START
3fa9e406ahrens *
4fa9e406ahrens * The contents of this file are subject to the terms of the
5ea8dc4beschrock * Common Development and Distribution License (the "License").
6ea8dc4beschrock * You may not use this file except in compliance with the License.
7fa9e406ahrens *
8fa9e406ahrens * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e406ahrens * or http://www.opensolaris.org/os/licensing.
10fa9e406ahrens * See the License for the specific language governing permissions
11fa9e406ahrens * and limitations under the License.
12fa9e406ahrens *
13fa9e406ahrens * When distributing Covered Code, include this CDDL HEADER in each
14fa9e406ahrens * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e406ahrens * If applicable, add the following below this CDDL HEADER, with the
16fa9e406ahrens * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e406ahrens * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e406ahrens *
19fa9e406ahrens * CDDL HEADER END
20fa9e406ahrens */
21fa9e406ahrens/*
223113f7cGeorge Wilson * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2394c2d0eMatthew Ahrens * Copyright (c) 2013, 2017 by Delphix. All rights reserved.
24ff5177eAlek Pinchuk * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
25fa9e406ahrens */
26fa9e406ahrens
27fa9e406ahrens#ifndef	_SYS_DSL_POOL_H
28fa9e406ahrens#define	_SYS_DSL_POOL_H
29fa9e406ahrens
30fa9e406ahrens#include <sys/spa.h>
31fa9e406ahrens#include <sys/txg.h>
32fa9e406ahrens#include <sys/txg_impl.h>
33fa9e406ahrens#include <sys/zfs_context.h>
34088f389ahrens#include <sys/zio.h>
3588b7b0fMatthew Ahrens#include <sys/dnode.h>
36bbfd46cJeff Bonwick#include <sys/ddt.h>
373f9d6adLin Ling#include <sys/arc.h>
38cde58dbMatthew Ahrens#include <sys/bpobj.h>
39ad135b5Christopher Siden#include <sys/bptree.h>
403b2aab1Matthew Ahrens#include <sys/rrwlock.h>
418671400Serapheim Dimitropoulos#include <sys/dsl_synctask.h>
42e0f1c0aOlaf Faaland#include <sys/mmp.h>
43fa9e406ahrens
44fa9e406ahrens#ifdef	__cplusplus
45fa9e406ahrensextern "C" {
46fa9e406ahrens#endif
47fa9e406ahrens
48fa9e406ahrensstruct objset;
49fa9e406ahrensstruct dsl_dir;
50088f389ahrensstruct dsl_dataset;
51088f389ahrensstruct dsl_pool;
52088f389ahrensstruct dmu_tx;
533f9d6adLin Lingstruct dsl_scan;
54eb63303Tom Caputistruct dsl_crypto_params;
55088f389ahrens
5669962b5Matthew Ahrensextern uint64_t zfs_dirty_data_max;
5769962b5Matthew Ahrensextern uint64_t zfs_dirty_data_max_max;
587928f4bMatthew Ahrensextern uint64_t zfs_dirty_data_sync_pct;
5969962b5Matthew Ahrensextern int zfs_dirty_data_max_percent;
6069962b5Matthew Ahrensextern int zfs_delay_min_dirty_percent;
6169962b5Matthew Ahrensextern uint64_t zfs_delay_scale;
6269962b5Matthew Ahrens
6388b7b0fMatthew Ahrens/* These macros are for indexing into the zfs_all_blkstats_t. */
6488b7b0fMatthew Ahrens#define	DMU_OT_DEFERRED	DMU_OT_NONE
65ad135b5Christopher Siden#define	DMU_OT_OTHER	DMU_OT_NUMTYPES /* place holder for DMU_OT() types */
66ad135b5Christopher Siden#define	DMU_OT_TOTAL	(DMU_OT_NUMTYPES + 1)
6788b7b0fMatthew Ahrens
6888b7b0fMatthew Ahrenstypedef struct zfs_blkstat {
6988b7b0fMatthew Ahrens	uint64_t	zb_count;
7088b7b0fMatthew Ahrens	uint64_t	zb_asize;
7188b7b0fMatthew Ahrens	uint64_t	zb_lsize;
7288b7b0fMatthew Ahrens	uint64_t	zb_psize;
7388b7b0fMatthew Ahrens	uint64_t	zb_gangs;
7488b7b0fMatthew Ahrens	uint64_t	zb_ditto_2_of_2_samevdev;
7588b7b0fMatthew Ahrens	uint64_t	zb_ditto_2_of_3_samevdev;
7688b7b0fMatthew Ahrens	uint64_t	zb_ditto_3_of_3_samevdev;
7788b7b0fMatthew Ahrens} zfs_blkstat_t;
7888b7b0fMatthew Ahrens
7988b7b0fMatthew Ahrenstypedef struct zfs_all_blkstats {
8088b7b0fMatthew Ahrens	zfs_blkstat_t	zab_type[DN_MAX_LEVELS + 1][DMU_OT_TOTAL + 1];
81a3874b8Toomas Soome	kmutex_t	zab_lock;
8288b7b0fMatthew Ahrens} zfs_all_blkstats_t;
8388b7b0fMatthew Ahrens
84fa9e406ahrens
85fa9e406ahrenstypedef struct dsl_pool {
86fa9e406ahrens	/* Immutable */
87fa9e406ahrens	spa_t *dp_spa;
88fa9e406ahrens	struct objset *dp_meta_objset;
89fa9e406ahrens	struct dsl_dir *dp_root_dir;
90fa9e406ahrens	struct dsl_dir *dp_mos_dir;
91cde58dbMatthew Ahrens	struct dsl_dir *dp_free_dir;
927fd05acMatthew Ahrens	struct dsl_dir *dp_leak_dir;
93088f389ahrens	struct dsl_dataset *dp_origin_snap;
94fa9e406ahrens	uint64_t dp_root_dir_obj;
95591e0e1Sebastien Roy	taskq_t *dp_vnrele_taskq;
96c5832a5Alek Pinchuk	struct taskq *dp_unlinked_drain_taskq;
97fa9e406ahrens
98fa9e406ahrens	/* No lock needed - sync context only */
99fa9e406ahrens	blkptr_t dp_meta_rootbp;
100ca45db4Chris Kirby	uint64_t dp_tmp_userrefs_obj;
101cde58dbMatthew Ahrens	bpobj_t dp_free_bpobj;
102ad135b5Christopher Siden	uint64_t dp_bptree_obj;
103f174573Matthew Ahrens	uint64_t dp_empty_bpobj;
1045cabbc6Prashanth Sreenivasa	bpobj_t dp_obsolete_bpobj;
1051ab7f2dmaybee
1063f9d6adLin Ling	struct dsl_scan *dp_scan;
1073f9d6adLin Ling
1081ab7f2dmaybee	/* Uses dp_lock */
1091ab7f2dmaybee	kmutex_t dp_lock;
11069962b5Matthew Ahrens	kcondvar_t dp_spaceavail_cv;
11169962b5Matthew Ahrens	uint64_t dp_dirty_pertxg[TXG_SIZE];
11269962b5Matthew Ahrens	uint64_t dp_dirty_total;
113ff5177eAlek Pinchuk	uint64_t dp_long_free_dirty_pertxg[TXG_SIZE];
114ce636f8Matthew Ahrens	uint64_t dp_mos_used_delta;
115ce636f8Matthew Ahrens	uint64_t dp_mos_compressed_delta;
116ce636f8Matthew Ahrens	uint64_t dp_mos_uncompressed_delta;
117fa9e406ahrens
11869962b5Matthew Ahrens	/*
11969962b5Matthew Ahrens	 * Time of most recently scheduled (furthest in the future)
12069962b5Matthew Ahrens	 * wakeup for delayed transactions.
12169962b5Matthew Ahrens	 */
12269962b5Matthew Ahrens	hrtime_t dp_last_wakeup;
12369962b5Matthew Ahrens
124fa9e406ahrens	/* Has its own locking */
125fa9e406ahrens	tx_state_t dp_tx;
126fa9e406ahrens	txg_list_t dp_dirty_datasets;
127ce636f8Matthew Ahrens	txg_list_t dp_dirty_zilogs;
128fa9e406ahrens	txg_list_t dp_dirty_dirs;
1291d452cfahrens	txg_list_t dp_sync_tasks;
1308671400Serapheim Dimitropoulos	txg_list_t dp_early_sync_tasks;
13194c2d0eMatthew Ahrens	taskq_t *dp_sync_taskq;
132216d772Prakash Surya	taskq_t *dp_zil_clean_taskq;
133fa9e406ahrens
134fa9e406ahrens	/*
135fa9e406ahrens	 * Protects administrative changes (properties, namespace)
136f717074Will Andrews	 *
137fa9e406ahrens	 * It is only held for write in syncing context.  Therefore
138fa9e406ahrens	 * syncing context does not need to ever have it for read, since
139fa9e406ahrens	 * nobody else could possibly have it for write.
140fa9e406ahrens	 */
1413b2aab1Matthew Ahrens	rrwlock_t dp_config_rwlock;
14288b7b0fMatthew Ahrens
14388b7b0fMatthew Ahrens	zfs_all_blkstats_t *dp_blkstats;
144fa9e406ahrens} dsl_pool_t;
145fa9e406ahrens
146ad135b5Christopher Sidenint dsl_pool_init(spa_t *spa, uint64_t txg, dsl_pool_t **dpp);
147ad135b5Christopher Sidenint dsl_pool_open(dsl_pool_t *dp);
148fa9e406ahrensvoid dsl_pool_close(dsl_pool_t *dp);
149eb63303Tom Caputidsl_pool_t *dsl_pool_create(spa_t *spa, nvlist_t *zplprops,
150eb63303Tom Caputi    struct dsl_crypto_params *dcp, uint64_t txg);
151fa9e406ahrensvoid dsl_pool_sync(dsl_pool_t *dp, uint64_t txg);
152b24ab67Jeff Bonwickvoid dsl_pool_sync_done(dsl_pool_t *dp, uint64_t txg);
153fa9e406ahrensint dsl_pool_sync_context(dsl_pool_t *dp);
1548671400Serapheim Dimitropoulosuint64_t dsl_pool_adjustedsize(dsl_pool_t *dp, zfs_space_check_t slop_policy);
1558671400Serapheim Dimitropoulosuint64_t dsl_pool_unreserved_space(dsl_pool_t *dp,
1568671400Serapheim Dimitropoulos    zfs_space_check_t slop_policy);
15769962b5Matthew Ahrensvoid dsl_pool_dirty_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx);
15869962b5Matthew Ahrensvoid dsl_pool_undirty_space(dsl_pool_t *dp, int64_t space, uint64_t txg);
159b24ab67Jeff Bonwickvoid dsl_free(dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp);
1603113f7cGeorge Wilsonvoid dsl_free_sync(zio_t *pio, dsl_pool_t *dp, uint64_t txg,
1613113f7cGeorge Wilson    const blkptr_t *bpp);
162088f389ahrensvoid dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx);
163088f389ahrensvoid dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx);
164cde58dbMatthew Ahrensvoid dsl_pool_upgrade_dir_clones(dsl_pool_t *dp, dmu_tx_t *tx);
165ce636f8Matthew Ahrensvoid dsl_pool_mos_diduse_space(dsl_pool_t *dp,
166ce636f8Matthew Ahrens    int64_t used, int64_t comp, int64_t uncomp);
1678671400Serapheim Dimitropoulosvoid dsl_pool_ckpoint_diduse_space(dsl_pool_t *dp,
1688671400Serapheim Dimitropoulos    int64_t used, int64_t comp, int64_t uncomp);
1693b2aab1Matthew Ahrensvoid dsl_pool_config_enter(dsl_pool_t *dp, void *tag);
1701d3f896Arne Jansenvoid dsl_pool_config_enter_prio(dsl_pool_t *dp, void *tag);
1713b2aab1Matthew Ahrensvoid dsl_pool_config_exit(dsl_pool_t *dp, void *tag);
1723b2aab1Matthew Ahrensboolean_t dsl_pool_config_held(dsl_pool_t *dp);
17312380e1Arne Jansenboolean_t dsl_pool_config_held_writer(dsl_pool_t *dp);
17469962b5Matthew Ahrensboolean_t dsl_pool_need_dirty_delay(dsl_pool_t *dp);
175088f389ahrens
1769d3574bNeil Perrintaskq_t *dsl_pool_vnrele_taskq(dsl_pool_t *dp);
177c5832a5Alek Pinchuktaskq_t *dsl_pool_unlinked_drain_taskq(dsl_pool_t *dp);
1789d3574bNeil Perrin
1793b2aab1Matthew Ahrensint dsl_pool_user_hold(dsl_pool_t *dp, uint64_t dsobj,
1803b2aab1Matthew Ahrens    const char *tag, uint64_t now, dmu_tx_t *tx);
1813b2aab1Matthew Ahrensint dsl_pool_user_release(dsl_pool_t *dp, uint64_t dsobj,
182ca45db4Chris Kirby    const char *tag, dmu_tx_t *tx);
1833b2aab1Matthew Ahrensvoid dsl_pool_clean_tmp_userrefs(dsl_pool_t *dp);
1843f9d6adLin Lingint dsl_pool_open_special_dir(dsl_pool_t *dp, const char *name, dsl_dir_t **);
1853b2aab1Matthew Ahrensint dsl_pool_hold(const char *name, void *tag, dsl_pool_t **dp);
1863b2aab1Matthew Ahrensvoid dsl_pool_rele(dsl_pool_t *dp, void *tag);
187ca45db4Chris Kirby
1885cabbc6Prashanth Sreenivasavoid dsl_pool_create_obsolete_bpobj(dsl_pool_t *dp, dmu_tx_t *tx);
1895cabbc6Prashanth Sreenivasavoid dsl_pool_destroy_obsolete_bpobj(dsl_pool_t *dp, dmu_tx_t *tx);
1905cabbc6Prashanth Sreenivasa
191fa9e406ahrens#ifdef	__cplusplus
192fa9e406ahrens}
193fa9e406ahrens#endif
194fa9e406ahrens
195fa9e406ahrens#endif /* _SYS_DSL_POOL_H */
196