xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_dir.h (revision 68ac2337c38c8af06edcf32a72e42de36ec72a9d)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DSL_DIR_H
27 #define	_SYS_DSL_DIR_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/dmu.h>
32 #include <sys/dsl_pool.h>
33 #include <sys/dsl_synctask.h>
34 #include <sys/refcount.h>
35 #include <sys/zfs_context.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 struct dsl_dataset;
42 
43 typedef struct dsl_dir_phys {
44 	uint64_t dd_creation_time; /* not actually used */
45 	uint64_t dd_head_dataset_obj;
46 	uint64_t dd_parent_obj;
47 	uint64_t dd_clone_parent_obj;
48 	uint64_t dd_child_dir_zapobj;
49 	/*
50 	 * how much space our children are accounting for; for leaf
51 	 * datasets, == physical space used by fs + snaps
52 	 */
53 	uint64_t dd_used_bytes;
54 	uint64_t dd_compressed_bytes;
55 	uint64_t dd_uncompressed_bytes;
56 	/* Administrative quota setting */
57 	uint64_t dd_quota;
58 	/* Administrative reservation setting */
59 	uint64_t dd_reserved;
60 	uint64_t dd_props_zapobj;
61 	uint64_t dd_pad[21]; /* pad out to 256 bytes for good measure */
62 } dsl_dir_phys_t;
63 
64 struct dsl_dir {
65 	/* These are immutable; no lock needed: */
66 	uint64_t dd_object;
67 	dsl_dir_phys_t *dd_phys;
68 	dmu_buf_t *dd_dbuf;
69 	dsl_pool_t *dd_pool;
70 
71 	/* protected by lock on pool's dp_dirty_dirs list */
72 	txg_node_t dd_dirty_link;
73 
74 	/* protected by dp_config_rwlock */
75 	dsl_dir_t *dd_parent;
76 
77 	/* Protected by dd_lock */
78 	kmutex_t dd_lock;
79 	list_t dd_prop_cbs; /* list of dsl_prop_cb_record_t's */
80 
81 	/* Accounting */
82 	/* reflects any changes to dd_phys->dd_used_bytes made this syncing */
83 	int64_t dd_used_bytes;
84 	/* gross estimate of space used by in-flight tx's */
85 	uint64_t dd_tempreserved[TXG_SIZE];
86 	/* amount of space we expect to write; == amount of dirty data */
87 	int64_t dd_space_towrite[TXG_SIZE];
88 
89 	/* protected by dd_lock; keep at end of struct for better locality */
90 	char dd_myname[MAXNAMELEN];
91 };
92 
93 void dsl_dir_close(dsl_dir_t *dd, void *tag);
94 int dsl_dir_open(const char *name, void *tag, dsl_dir_t **, const char **tail);
95 int dsl_dir_open_spa(spa_t *spa, const char *name, void *tag, dsl_dir_t **,
96     const char **tailp);
97 int dsl_dir_open_obj(dsl_pool_t *dp, uint64_t ddobj,
98     const char *tail, void *tag, dsl_dir_t **);
99 void dsl_dir_name(dsl_dir_t *dd, char *buf);
100 int dsl_dir_is_private(dsl_dir_t *dd);
101 uint64_t dsl_dir_create_sync(dsl_dir_t *pds, const char *name, dmu_tx_t *tx);
102 void dsl_dir_create_root(objset_t *mos, uint64_t *ddobjp, dmu_tx_t *tx);
103 dsl_checkfunc_t dsl_dir_destroy_check;
104 dsl_syncfunc_t dsl_dir_destroy_sync;
105 void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv);
106 uint64_t dsl_dir_space_available(dsl_dir_t *dd,
107     dsl_dir_t *ancestor, int64_t delta, int ondiskonly);
108 void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx);
109 void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx);
110 int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem,
111     uint64_t asize, uint64_t fsize, void **tr_cookiep, dmu_tx_t *tx);
112 void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx);
113 void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx);
114 void dsl_dir_diduse_space(dsl_dir_t *dd,
115     int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx);
116 int dsl_dir_set_quota(const char *ddname, uint64_t quota);
117 int dsl_dir_set_reservation(const char *ddname, uint64_t reservation);
118 int dsl_dir_rename(dsl_dir_t *dd, const char *newname);
119 int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, uint64_t space);
120 
121 /* internal reserved dir name */
122 #define	MOS_DIR_NAME "$MOS"
123 
124 #ifdef ZFS_DEBUG
125 #define	dprintf_dd(dd, fmt, ...) do { \
126 	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
127 	char *__ds_name = kmem_alloc(MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, \
128 	    KM_SLEEP); \
129 	dsl_dir_name(dd, __ds_name); \
130 	dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
131 	kmem_free(__ds_name, MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); \
132 	} \
133 _NOTE(CONSTCOND) } while (0)
134 #else
135 #define	dprintf_dd(dd, fmt, ...)
136 #endif
137 
138 #ifdef	__cplusplus
139 }
140 #endif
141 
142 #endif /* _SYS_DSL_DIR_H */
143