xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_dir.h (revision eb633035)
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 /*
223f9d6ad7SLin Ling  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2386714001SSerapheim Dimitropoulos  * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
24a2afb611SJerry Jelinek  * Copyright (c) 2014, Joyent, Inc. All rights reserved.
25bc9014e6SJustin Gibbs  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
26fa9e4066Sahrens  */
28fa9e4066Sahrens #ifndef	_SYS_DSL_DIR_H
29fa9e4066Sahrens #define	_SYS_DSL_DIR_H
31fa9e4066Sahrens #include <sys/dmu.h>
32fa9e4066Sahrens #include <sys/dsl_pool.h>
331d452cf5Sahrens #include <sys/dsl_synctask.h>
34fa9e4066Sahrens #include <sys/refcount.h>
35fa9e4066Sahrens #include <sys/zfs_context.h>
36*eb633035STom Caputi #include <sys/dsl_crypt.h>
38fa9e4066Sahrens #ifdef	__cplusplus
39fa9e4066Sahrens extern "C" {
40fa9e4066Sahrens #endif
42fa9e4066Sahrens struct dsl_dataset;
44a2afb611SJerry Jelinek /*
45a2afb611SJerry Jelinek  * DD_FIELD_* are strings that are used in the "extensified" dsl_dir zap object.
46a2afb611SJerry Jelinek  * They should be of the format <reverse-dns>:<field>.
47a2afb611SJerry Jelinek  */
48a2afb611SJerry Jelinek 
49a2afb611SJerry Jelinek #define	DD_FIELD_FILESYSTEM_COUNT	"com.joyent:filesystem_count"
50a2afb611SJerry Jelinek #define	DD_FIELD_SNAPSHOT_COUNT		"com.joyent:snapshot_count"
515cabbc6bSPrashanth Sreenivasa #define	DD_FIELD_LAST_REMAP_TXG		"com.delphix:last_remap_txg"
52*eb633035STom Caputi #define	DD_FIELD_CRYPTO_KEY_OBJ		"com.datto:crypto_key_obj"
53a2afb611SJerry Jelinek 
5474e7dc98SMatthew Ahrens typedef enum dd_used {
5574e7dc98SMatthew Ahrens 	DD_USED_HEAD,
5674e7dc98SMatthew Ahrens 	DD_USED_SNAP,
5774e7dc98SMatthew Ahrens 	DD_USED_CHILD,
5874e7dc98SMatthew Ahrens 	DD_USED_CHILD_RSRV,
5974e7dc98SMatthew Ahrens 	DD_USED_REFRSRV,
6074e7dc98SMatthew Ahrens 	DD_USED_NUM
6174e7dc98SMatthew Ahrens } dd_used_t;
6274e7dc98SMatthew Ahrens 
6374e7dc98SMatthew Ahrens #define	DD_FLAG_USED_BREAKDOWN (1<<0)
6474e7dc98SMatthew Ahrens 
65fa9e4066Sahrens typedef struct dsl_dir_phys {
66a2eea2e1Sahrens 	uint64_t dd_creation_time; /* not actually used */
67fa9e4066Sahrens 	uint64_t dd_head_dataset_obj;
68fa9e4066Sahrens 	uint64_t dd_parent_obj;
693cb34c60Sahrens 	uint64_t dd_origin_obj;
70fa9e4066Sahrens 	uint64_t dd_child_dir_zapobj;
71fa9e4066Sahrens 	/*
72fa9e4066Sahrens 	 * how much space our children are accounting for; for leaf
73fa9e4066Sahrens 	 * datasets, == physical space used by fs + snaps
74fa9e4066Sahrens 	 */
75fa9e4066Sahrens 	uint64_t dd_used_bytes;
76fa9e4066Sahrens 	uint64_t dd_compressed_bytes;
77fa9e4066Sahrens 	uint64_t dd_uncompressed_bytes;
78fa9e4066Sahrens 	/* Administrative quota setting */
79fa9e4066Sahrens 	uint64_t dd_quota;
80fa9e4066Sahrens 	/* Administrative reservation setting */
81fa9e4066Sahrens 	uint64_t dd_reserved;
82fa9e4066Sahrens 	uint64_t dd_props_zapobj;
83ecd6cf80Smarks 	uint64_t dd_deleg_zapobj; /* dataset delegation permissions */
8474e7dc98SMatthew Ahrens 	uint64_t dd_flags;
8574e7dc98SMatthew Ahrens 	uint64_t dd_used_breakdown[DD_USED_NUM];
86cde58dbcSMatthew Ahrens 	uint64_t dd_clones; /* dsl_dir objects */
87cde58dbcSMatthew Ahrens 	uint64_t dd_pad[13]; /* pad out to 256 bytes for good measure */
88fa9e4066Sahrens } dsl_dir_phys_t;
90fa9e4066Sahrens struct dsl_dir {
91bc9014e6SJustin Gibbs 	dmu_buf_user_t dd_dbu;
92bc9014e6SJustin Gibbs 
93fa9e4066Sahrens 	/* These are immutable; no lock needed: */
94fa9e4066Sahrens 	uint64_t dd_object;
95*eb633035STom Caputi 	uint64_t dd_crypto_obj;
96fa9e4066Sahrens 	dsl_pool_t *dd_pool;
98c1379625SJustin T. Gibbs 	/* Stable until user eviction; no lock needed: */
99c1379625SJustin T. Gibbs 	dmu_buf_t *dd_dbuf;
100c1379625SJustin T. Gibbs 
101fa9e4066Sahrens 	/* protected by lock on pool's dp_dirty_dirs list */
102fa9e4066Sahrens 	txg_node_t dd_dirty_link;
104fa9e4066Sahrens 	/* protected by dp_config_rwlock */
105fa9e4066Sahrens 	dsl_dir_t *dd_parent;
107fa9e4066Sahrens 	/* Protected by dd_lock */
108fa9e4066Sahrens 	kmutex_t dd_lock;
10903bad06fSJustin Gibbs 	list_t dd_props; /* list of dsl_prop_record_t's */
11071eb0538SChris Kirby 	timestruc_t dd_snap_cmtime; /* last time snapshot namespace changed */
1113f9d6ad7SLin Ling 	uint64_t dd_origin_txg;
113fa9e4066Sahrens 	/* gross estimate of space used by in-flight tx's */
114fa9e4066Sahrens 	uint64_t dd_tempreserved[TXG_SIZE];
115fa9e4066Sahrens 	/* amount of space we expect to write; == amount of dirty data */
116fa9e4066Sahrens 	int64_t dd_space_towrite[TXG_SIZE];
118fa9e4066Sahrens 	/* protected by dd_lock; keep at end of struct for better locality */
1199adfa60dSMatthew Ahrens 	char dd_myname[ZFS_MAX_DATASET_NAME_LEN];
120fa9e4066Sahrens };
122c1379625SJustin T. Gibbs inline dsl_dir_phys_t *
dsl_dir_phys(dsl_dir_t * dd)123c1379625SJustin T. Gibbs dsl_dir_phys(dsl_dir_t *dd)
124c1379625SJustin T. Gibbs {
125c1379625SJustin T. Gibbs 	return (dd->dd_dbuf->db_data);
126c1379625SJustin T. Gibbs }
127c1379625SJustin T. Gibbs 
1283b2aab18SMatthew Ahrens void dsl_dir_rele(dsl_dir_t *dd, void *tag);
129bc9014e6SJustin Gibbs void dsl_dir_async_rele(dsl_dir_t *dd, void *tag);
1303b2aab18SMatthew Ahrens int dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag,
1313b2aab18SMatthew Ahrens     dsl_dir_t **, const char **tail);
1323b2aab18SMatthew Ahrens int dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj,
133ea8dc4b6Seschrock     const char *tail, void *tag, dsl_dir_t **);
134fa9e4066Sahrens void dsl_dir_name(dsl_dir_t *dd, char *buf);
135b7661cccSmmusante int dsl_dir_namelen(dsl_dir_t *dd);
136088f3894Sahrens uint64_t dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds,
137088f3894Sahrens     const char *name, dmu_tx_t *tx);
138dfc11533SChris Williamson 
139dfc11533SChris Williamson uint64_t dsl_dir_get_used(dsl_dir_t *dd);
14086714001SSerapheim Dimitropoulos uint64_t dsl_dir_get_compressed(dsl_dir_t *dd);
141dfc11533SChris Williamson uint64_t dsl_dir_get_quota(dsl_dir_t *dd);
142dfc11533SChris Williamson uint64_t dsl_dir_get_reservation(dsl_dir_t *dd);
143dfc11533SChris Williamson uint64_t dsl_dir_get_compressratio(dsl_dir_t *dd);
144dfc11533SChris Williamson uint64_t dsl_dir_get_logicalused(dsl_dir_t *dd);
145dfc11533SChris Williamson uint64_t dsl_dir_get_usedsnap(dsl_dir_t *dd);
146dfc11533SChris Williamson uint64_t dsl_dir_get_usedds(dsl_dir_t *dd);
147dfc11533SChris Williamson uint64_t dsl_dir_get_usedrefreserv(dsl_dir_t *dd);
148dfc11533SChris Williamson uint64_t dsl_dir_get_usedchild(dsl_dir_t *dd);
149dfc11533SChris Williamson void dsl_dir_get_origin(dsl_dir_t *dd, char *buf);
150dfc11533SChris Williamson int dsl_dir_get_filesystem_count(dsl_dir_t *dd, uint64_t *count);
151dfc11533SChris Williamson int dsl_dir_get_snapshot_count(dsl_dir_t *dd, uint64_t *count);
1525cabbc6bSPrashanth Sreenivasa int dsl_dir_get_remaptxg(dsl_dir_t *dd, uint64_t *count);
153dfc11533SChris Williamson 
154a2eea2e1Sahrens void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv);
155a2eea2e1Sahrens uint64_t dsl_dir_space_available(dsl_dir_t *dd,
156a2eea2e1Sahrens     dsl_dir_t *ancestor, int64_t delta, int ondiskonly);
157fa9e4066Sahrens void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx);
158fa9e4066Sahrens void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx);
159fa9e4066Sahrens int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem,
16061e255ceSMatthew Ahrens     uint64_t asize, boolean_t netfree, void **tr_cookiep, dmu_tx_t *tx);
161fa9e4066Sahrens void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx);
162fa9e4066Sahrens void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx);
16374e7dc98SMatthew Ahrens void dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type,
164fa9e4066Sahrens     int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx);
16574e7dc98SMatthew Ahrens void dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta,
16674e7dc98SMatthew Ahrens     dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx);
16792241e0bSTom Erickson int dsl_dir_set_quota(const char *ddname, zprop_source_t source,
16892241e0bSTom Erickson     uint64_t quota);
16992241e0bSTom Erickson int dsl_dir_set_reservation(const char *ddname, zprop_source_t source,
17092241e0bSTom Erickson     uint64_t reservation);
171a2afb611SJerry Jelinek int dsl_dir_activate_fs_ss_limit(const char *);
172a2afb611SJerry Jelinek int dsl_fs_ss_limit_check(dsl_dir_t *, uint64_t, zfs_prop_t, dsl_dir_t *,
173a2afb611SJerry Jelinek     cred_t *);
174a2afb611SJerry Jelinek void dsl_fs_ss_count_adjust(dsl_dir_t *, int64_t, const char *, dmu_tx_t *);
1755cabbc6bSPrashanth Sreenivasa int dsl_dir_update_last_remap_txg(dsl_dir_t *, uint64_t);
1763b2aab18SMatthew Ahrens int dsl_dir_rename(const char *oldname, const char *newname);
177a2afb611SJerry Jelinek int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd,
178a2afb611SJerry Jelinek     uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space, cred_t *);
179088f3894Sahrens boolean_t dsl_dir_is_clone(dsl_dir_t *dd);
1800b383af7SChris Kirby void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds,
1810b383af7SChris Kirby     uint64_t reservation, cred_t *cr, dmu_tx_t *tx);
18271eb0538SChris Kirby void dsl_dir_snap_cmtime_update(dsl_dir_t *dd);
18371eb0538SChris Kirby timestruc_t dsl_dir_snap_cmtime(dsl_dir_t *dd);
1843b2aab18SMatthew Ahrens void dsl_dir_set_reservation_sync_impl(dsl_dir_t *dd, uint64_t value,
1853b2aab18SMatthew Ahrens     dmu_tx_t *tx);
186a2afb611SJerry Jelinek void dsl_dir_zapify(dsl_dir_t *dd, dmu_tx_t *tx);
187a2afb611SJerry Jelinek boolean_t dsl_dir_is_zapified(dsl_dir_t *dd);
18915f66a7fSek /* internal reserved dir name */
19015f66a7fSek #define	MOS_DIR_NAME "$MOS"
191088f3894Sahrens #define	ORIGIN_DIR_NAME "$ORIGIN"
192cde58dbcSMatthew Ahrens #define	FREE_DIR_NAME "$FREE"
1937fd05ac4SMatthew Ahrens #define	LEAK_DIR_NAME "$LEAK"
195fa9e4066Sahrens #ifdef ZFS_DEBUG
196fa9e4066Sahrens #define	dprintf_dd(dd, fmt, ...) do { \
197fa9e4066Sahrens 	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
1989adfa60dSMatthew Ahrens 	char *__ds_name = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP); \
199fa9e4066Sahrens 	dsl_dir_name(dd, __ds_name); \
200fa9e4066Sahrens 	dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
2019adfa60dSMatthew Ahrens 	kmem_free(__ds_name, ZFS_MAX_DATASET_NAME_LEN); \
202fa9e4066Sahrens 	} \
203fa9e4066Sahrens _NOTE(CONSTCOND) } while (0)
204fa9e4066Sahrens #else
205fa9e4066Sahrens #define	dprintf_dd(dd, fmt, ...)
206fa9e4066Sahrens #endif
208fa9e4066Sahrens #ifdef	__cplusplus
209fa9e4066Sahrens }
210fa9e4066Sahrens #endif
212fa9e4066Sahrens #endif /* _SYS_DSL_DIR_H */