xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_dir.h (revision a2eea2e1)
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 /*
22ea8dc4b6Seschrock  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23fa9e4066Sahrens  * Use is subject to license terms.
24fa9e4066Sahrens  */
25fa9e4066Sahrens 
26fa9e4066Sahrens #ifndef	_SYS_DSL_DIR_H
27fa9e4066Sahrens #define	_SYS_DSL_DIR_H
28fa9e4066Sahrens 
29fa9e4066Sahrens #pragma ident	"%Z%%M%	%I%	%E% SMI"
30fa9e4066Sahrens 
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>
36fa9e4066Sahrens 
37fa9e4066Sahrens #ifdef	__cplusplus
38fa9e4066Sahrens extern "C" {
39fa9e4066Sahrens #endif
40fa9e4066Sahrens 
41fa9e4066Sahrens struct dsl_dataset;
42fa9e4066Sahrens 
43fa9e4066Sahrens typedef struct dsl_dir_phys {
44*a2eea2e1Sahrens 	uint64_t dd_creation_time; /* not actually used */
45fa9e4066Sahrens 	uint64_t dd_head_dataset_obj;
46fa9e4066Sahrens 	uint64_t dd_parent_obj;
47fa9e4066Sahrens 	uint64_t dd_clone_parent_obj;
48fa9e4066Sahrens 	uint64_t dd_child_dir_zapobj;
49fa9e4066Sahrens 	/*
50fa9e4066Sahrens 	 * how much space our children are accounting for; for leaf
51fa9e4066Sahrens 	 * datasets, == physical space used by fs + snaps
52fa9e4066Sahrens 	 */
53fa9e4066Sahrens 	uint64_t dd_used_bytes;
54fa9e4066Sahrens 	uint64_t dd_compressed_bytes;
55fa9e4066Sahrens 	uint64_t dd_uncompressed_bytes;
56fa9e4066Sahrens 	/* Administrative quota setting */
57fa9e4066Sahrens 	uint64_t dd_quota;
58fa9e4066Sahrens 	/* Administrative reservation setting */
59fa9e4066Sahrens 	uint64_t dd_reserved;
60fa9e4066Sahrens 	uint64_t dd_props_zapobj;
61fa9e4066Sahrens 	uint64_t dd_pad[21]; /* pad out to 256 bytes for good measure */
62fa9e4066Sahrens } dsl_dir_phys_t;
63fa9e4066Sahrens 
64fa9e4066Sahrens struct dsl_dir {
65fa9e4066Sahrens 	/* These are immutable; no lock needed: */
66fa9e4066Sahrens 	uint64_t dd_object;
67fa9e4066Sahrens 	dsl_dir_phys_t *dd_phys;
68fa9e4066Sahrens 	dmu_buf_t *dd_dbuf;
69fa9e4066Sahrens 	dsl_pool_t *dd_pool;
70fa9e4066Sahrens 
71fa9e4066Sahrens 	/* protected by lock on pool's dp_dirty_dirs list */
72fa9e4066Sahrens 	txg_node_t dd_dirty_link;
73fa9e4066Sahrens 
74fa9e4066Sahrens 	/* protected by dp_config_rwlock */
75fa9e4066Sahrens 	dsl_dir_t *dd_parent;
76fa9e4066Sahrens 
77fa9e4066Sahrens 	/* Protected by dd_lock */
78fa9e4066Sahrens 	kmutex_t dd_lock;
79fa9e4066Sahrens 	list_t dd_prop_cbs; /* list of dsl_prop_cb_record_t's */
80fa9e4066Sahrens 
81fa9e4066Sahrens 	/* Accounting */
82fa9e4066Sahrens 	/* reflects any changes to dd_phys->dd_used_bytes made this syncing */
83fa9e4066Sahrens 	int64_t dd_used_bytes;
84fa9e4066Sahrens 	/* gross estimate of space used by in-flight tx's */
85fa9e4066Sahrens 	uint64_t dd_tempreserved[TXG_SIZE];
86fa9e4066Sahrens 	/* amount of space we expect to write; == amount of dirty data */
87fa9e4066Sahrens 	int64_t dd_space_towrite[TXG_SIZE];
88fa9e4066Sahrens 
89fa9e4066Sahrens 	/* protected by dd_lock; keep at end of struct for better locality */
90fa9e4066Sahrens 	char dd_myname[MAXNAMELEN];
91fa9e4066Sahrens };
92fa9e4066Sahrens 
93fa9e4066Sahrens void dsl_dir_close(dsl_dir_t *dd, void *tag);
94ea8dc4b6Seschrock int dsl_dir_open(const char *name, void *tag, dsl_dir_t **, const char **tail);
95ea8dc4b6Seschrock int dsl_dir_open_spa(spa_t *spa, const char *name, void *tag, dsl_dir_t **,
96fa9e4066Sahrens     const char **tailp);
97ea8dc4b6Seschrock int dsl_dir_open_obj(dsl_pool_t *dp, uint64_t ddobj,
98ea8dc4b6Seschrock     const char *tail, void *tag, dsl_dir_t **);
99fa9e4066Sahrens void dsl_dir_name(dsl_dir_t *dd, char *buf);
100fa9e4066Sahrens int dsl_dir_is_private(dsl_dir_t *dd);
1011d452cf5Sahrens uint64_t dsl_dir_create_sync(dsl_dir_t *pds, const char *name, dmu_tx_t *tx);
102fa9e4066Sahrens void dsl_dir_create_root(objset_t *mos, uint64_t *ddobjp, dmu_tx_t *tx);
1031d452cf5Sahrens dsl_checkfunc_t dsl_dir_destroy_check;
1041d452cf5Sahrens dsl_syncfunc_t dsl_dir_destroy_sync;
105*a2eea2e1Sahrens void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv);
106*a2eea2e1Sahrens uint64_t dsl_dir_space_available(dsl_dir_t *dd,
107*a2eea2e1Sahrens     dsl_dir_t *ancestor, int64_t delta, int ondiskonly);
108fa9e4066Sahrens void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx);
109fa9e4066Sahrens void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx);
110fa9e4066Sahrens int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem,
111fa9e4066Sahrens     uint64_t asize, uint64_t fsize, void **tr_cookiep, dmu_tx_t *tx);
112fa9e4066Sahrens void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx);
113fa9e4066Sahrens void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx);
114fa9e4066Sahrens void dsl_dir_diduse_space(dsl_dir_t *dd,
115fa9e4066Sahrens     int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx);
116fa9e4066Sahrens int dsl_dir_set_quota(const char *ddname, uint64_t quota);
117fa9e4066Sahrens int dsl_dir_set_reservation(const char *ddname, uint64_t reservation);
1181d452cf5Sahrens int dsl_dir_rename(dsl_dir_t *dd, const char *newname);
11999653d4eSeschrock int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, uint64_t space);
120fa9e4066Sahrens 
12115f66a7fSek /* internal reserved dir name */
12215f66a7fSek #define	MOS_DIR_NAME "$MOS"
12315f66a7fSek 
124fa9e4066Sahrens #ifdef ZFS_DEBUG
125fa9e4066Sahrens #define	dprintf_dd(dd, fmt, ...) do { \
126fa9e4066Sahrens 	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
12715f66a7fSek 	char *__ds_name = kmem_alloc(MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, \
12815f66a7fSek 	    KM_SLEEP); \
129fa9e4066Sahrens 	dsl_dir_name(dd, __ds_name); \
130fa9e4066Sahrens 	dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
13115f66a7fSek 	kmem_free(__ds_name, MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); \
132fa9e4066Sahrens 	} \
133fa9e4066Sahrens _NOTE(CONSTCOND) } while (0)
134fa9e4066Sahrens #else
135fa9e4066Sahrens #define	dprintf_dd(dd, fmt, ...)
136fa9e4066Sahrens #endif
137fa9e4066Sahrens 
138fa9e4066Sahrens #ifdef	__cplusplus
139fa9e4066Sahrens }
140fa9e4066Sahrens #endif
141fa9e4066Sahrens 
142fa9e4066Sahrens #endif /* _SYS_DSL_DIR_H */
143