xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_pool.h (revision 9d3574bff0b382b89dd380c1e23d742ebc156772)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
22*9d3574bfSNeil Perrin  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #ifndef	_SYS_DSL_POOL_H
27fa9e4066Sahrens #define	_SYS_DSL_POOL_H
28fa9e4066Sahrens 
29fa9e4066Sahrens #include <sys/spa.h>
30fa9e4066Sahrens #include <sys/txg.h>
31fa9e4066Sahrens #include <sys/txg_impl.h>
32fa9e4066Sahrens #include <sys/zfs_context.h>
33088f3894Sahrens #include <sys/zio.h>
3488b7b0f2SMatthew Ahrens #include <sys/dnode.h>
35fa9e4066Sahrens 
36fa9e4066Sahrens #ifdef	__cplusplus
37fa9e4066Sahrens extern "C" {
38fa9e4066Sahrens #endif
39fa9e4066Sahrens 
40fa9e4066Sahrens struct objset;
41fa9e4066Sahrens struct dsl_dir;
42088f3894Sahrens struct dsl_dataset;
43088f3894Sahrens struct dsl_pool;
44088f3894Sahrens struct dmu_tx;
45088f3894Sahrens 
46088f3894Sahrens enum scrub_func {
47088f3894Sahrens 	SCRUB_FUNC_NONE,
48088f3894Sahrens 	SCRUB_FUNC_CLEAN,
49088f3894Sahrens 	SCRUB_FUNC_NUMFUNCS
50088f3894Sahrens };
51088f3894Sahrens 
5288b7b0f2SMatthew Ahrens /* These macros are for indexing into the zfs_all_blkstats_t. */
5388b7b0f2SMatthew Ahrens #define	DMU_OT_DEFERRED	DMU_OT_NONE
5488b7b0f2SMatthew Ahrens #define	DMU_OT_TOTAL	DMU_OT_NUMTYPES
5588b7b0f2SMatthew Ahrens 
5688b7b0f2SMatthew Ahrens typedef struct zfs_blkstat {
5788b7b0f2SMatthew Ahrens 	uint64_t	zb_count;
5888b7b0f2SMatthew Ahrens 	uint64_t	zb_asize;
5988b7b0f2SMatthew Ahrens 	uint64_t	zb_lsize;
6088b7b0f2SMatthew Ahrens 	uint64_t	zb_psize;
6188b7b0f2SMatthew Ahrens 	uint64_t	zb_gangs;
6288b7b0f2SMatthew Ahrens 	uint64_t	zb_ditto_2_of_2_samevdev;
6388b7b0f2SMatthew Ahrens 	uint64_t	zb_ditto_2_of_3_samevdev;
6488b7b0f2SMatthew Ahrens 	uint64_t	zb_ditto_3_of_3_samevdev;
6588b7b0f2SMatthew Ahrens } zfs_blkstat_t;
6688b7b0f2SMatthew Ahrens 
6788b7b0f2SMatthew Ahrens typedef struct zfs_all_blkstats {
6888b7b0f2SMatthew Ahrens 	zfs_blkstat_t	zab_type[DN_MAX_LEVELS + 1][DMU_OT_TOTAL + 1];
6988b7b0f2SMatthew Ahrens } zfs_all_blkstats_t;
7088b7b0f2SMatthew Ahrens 
71fa9e4066Sahrens 
72fa9e4066Sahrens typedef struct dsl_pool {
73fa9e4066Sahrens 	/* Immutable */
74fa9e4066Sahrens 	spa_t *dp_spa;
75fa9e4066Sahrens 	struct objset *dp_meta_objset;
76fa9e4066Sahrens 	struct dsl_dir *dp_root_dir;
77fa9e4066Sahrens 	struct dsl_dir *dp_mos_dir;
78088f3894Sahrens 	struct dsl_dataset *dp_origin_snap;
79fa9e4066Sahrens 	uint64_t dp_root_dir_obj;
80*9d3574bfSNeil Perrin 	struct taskq *dp_vnrele_taskq;
81fa9e4066Sahrens 
82fa9e4066Sahrens 	/* No lock needed - sync context only */
83fa9e4066Sahrens 	blkptr_t dp_meta_rootbp;
843cb34c60Sahrens 	list_t dp_synced_datasets;
8505715f94SMark Maybee 	hrtime_t dp_read_overhead;
8605715f94SMark Maybee 	uint64_t dp_throughput;
871ab7f2deSmaybee 	uint64_t dp_write_limit;
881ab7f2deSmaybee 
891ab7f2deSmaybee 	/* Uses dp_lock */
901ab7f2deSmaybee 	kmutex_t dp_lock;
911ab7f2deSmaybee 	uint64_t dp_space_towrite[TXG_SIZE];
921ab7f2deSmaybee 	uint64_t dp_tempreserved[TXG_SIZE];
93fa9e4066Sahrens 
94088f3894Sahrens 	enum scrub_func dp_scrub_func;
95088f3894Sahrens 	uint64_t dp_scrub_queue_obj;
96088f3894Sahrens 	uint64_t dp_scrub_min_txg;
97088f3894Sahrens 	uint64_t dp_scrub_max_txg;
98088f3894Sahrens 	zbookmark_t dp_scrub_bookmark;
99088f3894Sahrens 	boolean_t dp_scrub_pausing;
100088f3894Sahrens 	boolean_t dp_scrub_isresilver;
101088f3894Sahrens 	uint64_t dp_scrub_start_time;
102088f3894Sahrens 	kmutex_t dp_scrub_cancel_lock; /* protects dp_scrub_restart */
103088f3894Sahrens 	boolean_t dp_scrub_restart;
104088f3894Sahrens 
105fa9e4066Sahrens 	/* Has its own locking */
106fa9e4066Sahrens 	tx_state_t dp_tx;
107fa9e4066Sahrens 	txg_list_t dp_dirty_datasets;
108fa9e4066Sahrens 	txg_list_t dp_dirty_dirs;
1091d452cf5Sahrens 	txg_list_t dp_sync_tasks;
110fa9e4066Sahrens 
111fa9e4066Sahrens 	/*
112fa9e4066Sahrens 	 * Protects administrative changes (properties, namespace)
113fa9e4066Sahrens 	 * It is only held for write in syncing context.  Therefore
114fa9e4066Sahrens 	 * syncing context does not need to ever have it for read, since
115fa9e4066Sahrens 	 * nobody else could possibly have it for write.
116fa9e4066Sahrens 	 */
117fa9e4066Sahrens 	krwlock_t dp_config_rwlock;
11888b7b0f2SMatthew Ahrens 
11988b7b0f2SMatthew Ahrens 	zfs_all_blkstats_t *dp_blkstats;
120fa9e4066Sahrens } dsl_pool_t;
121fa9e4066Sahrens 
122ea8dc4b6Seschrock int dsl_pool_open(spa_t *spa, uint64_t txg, dsl_pool_t **dpp);
123fa9e4066Sahrens void dsl_pool_close(dsl_pool_t *dp);
1240a48a24eStimh dsl_pool_t *dsl_pool_create(spa_t *spa, nvlist_t *zplprops, uint64_t txg);
125fa9e4066Sahrens void dsl_pool_sync(dsl_pool_t *dp, uint64_t txg);
126fa9e4066Sahrens void dsl_pool_zil_clean(dsl_pool_t *dp);
127fa9e4066Sahrens int dsl_pool_sync_context(dsl_pool_t *dp);
128fa9e4066Sahrens uint64_t dsl_pool_adjustedsize(dsl_pool_t *dp, boolean_t netfree);
1291ab7f2deSmaybee int dsl_pool_tempreserve_space(dsl_pool_t *dp, uint64_t space, dmu_tx_t *tx);
1301ab7f2deSmaybee void dsl_pool_tempreserve_clear(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx);
1311ab7f2deSmaybee void dsl_pool_memory_pressure(dsl_pool_t *dp);
1321ab7f2deSmaybee void dsl_pool_willuse_space(dsl_pool_t *dp, int64_t space, dmu_tx_t *tx);
133088f3894Sahrens int dsl_free(zio_t *pio, dsl_pool_t *dp, uint64_t txg, const blkptr_t *bpp,
134088f3894Sahrens     zio_done_func_t *done, void *private, uint32_t arc_flags);
135088f3894Sahrens void dsl_pool_ds_destroyed(struct dsl_dataset *ds, struct dmu_tx *tx);
136088f3894Sahrens void dsl_pool_ds_snapshotted(struct dsl_dataset *ds, struct dmu_tx *tx);
13788b7b0f2SMatthew Ahrens void dsl_pool_ds_clone_swapped(struct dsl_dataset *ds1, struct dsl_dataset *ds2,
13888b7b0f2SMatthew Ahrens     struct dmu_tx *tx);
139088f3894Sahrens void dsl_pool_create_origin(dsl_pool_t *dp, dmu_tx_t *tx);
140088f3894Sahrens void dsl_pool_upgrade_clones(dsl_pool_t *dp, dmu_tx_t *tx);
141088f3894Sahrens 
142088f3894Sahrens int dsl_pool_scrub_cancel(dsl_pool_t *dp);
143088f3894Sahrens int dsl_pool_scrub_clean(dsl_pool_t *dp);
144088f3894Sahrens void dsl_pool_scrub_sync(dsl_pool_t *dp, dmu_tx_t *tx);
145088f3894Sahrens void dsl_pool_scrub_restart(dsl_pool_t *dp);
146fa9e4066Sahrens 
147*9d3574bfSNeil Perrin taskq_t *dsl_pool_vnrele_taskq(dsl_pool_t *dp);
148*9d3574bfSNeil Perrin 
149fa9e4066Sahrens #ifdef	__cplusplus
150fa9e4066Sahrens }
151fa9e4066Sahrens #endif
152fa9e4066Sahrens 
153fa9e4066Sahrens #endif /* _SYS_DSL_POOL_H */
154