xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dsl_dir.h (revision a9799022)
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 2007 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_origin_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_deleg_zapobj; /* dataset delegation permissions */
62 	uint64_t dd_pad[20]; /* pad out to 256 bytes for good measure */
63 } dsl_dir_phys_t;
64 
65 struct dsl_dir {
66 	/* These are immutable; no lock needed: */
67 	uint64_t dd_object;
68 	dsl_dir_phys_t *dd_phys;
69 	dmu_buf_t *dd_dbuf;
70 	dsl_pool_t *dd_pool;
71 
72 	/* protected by lock on pool's dp_dirty_dirs list */
73 	txg_node_t dd_dirty_link;
74 
75 	/* protected by dp_config_rwlock */
76 	dsl_dir_t *dd_parent;
77 
78 	/* Protected by dd_lock */
79 	kmutex_t dd_lock;
80 	list_t dd_prop_cbs; /* list of dsl_prop_cb_record_t's */
81 
82 	/* Accounting */
83 	/* reflects any changes to dd_phys->dd_used_bytes made this syncing */
84 	int64_t dd_used_bytes;
85 	/* gross estimate of space used by in-flight tx's */
86 	uint64_t dd_tempreserved[TXG_SIZE];
87 	/* amount of space we expect to write; == amount of dirty data */
88 	int64_t dd_space_towrite[TXG_SIZE];
89 
90 	/* protected by dd_lock; keep at end of struct for better locality */
91 	char dd_myname[MAXNAMELEN];
92 };
93 
94 void dsl_dir_close(dsl_dir_t *dd, void *tag);
95 int dsl_dir_open(const char *name, void *tag, dsl_dir_t **, const char **tail);
96 int dsl_dir_open_spa(spa_t *spa, const char *name, void *tag, dsl_dir_t **,
97     const char **tailp);
98 int dsl_dir_open_obj(dsl_pool_t *dp, uint64_t ddobj,
99     const char *tail, void *tag, dsl_dir_t **);
100 void dsl_dir_name(dsl_dir_t *dd, char *buf);
101 int dsl_dir_namelen(dsl_dir_t *dd);
102 int dsl_dir_is_private(dsl_dir_t *dd);
103 uint64_t dsl_dir_create_sync(dsl_dir_t *pds, const char *name, dmu_tx_t *tx);
104 void dsl_dir_create_root(objset_t *mos, uint64_t *ddobjp, dmu_tx_t *tx);
105 dsl_checkfunc_t dsl_dir_destroy_check;
106 dsl_syncfunc_t dsl_dir_destroy_sync;
107 void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv);
108 uint64_t dsl_dir_space_available(dsl_dir_t *dd,
109     dsl_dir_t *ancestor, int64_t delta, int ondiskonly);
110 void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx);
111 void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx);
112 int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem,
113     uint64_t asize, uint64_t fsize, uint64_t usize, void **tr_cookiep,
114     dmu_tx_t *tx);
115 void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx);
116 void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx);
117 void dsl_dir_diduse_space(dsl_dir_t *dd,
118     int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx);
119 int dsl_dir_set_quota(const char *ddname, uint64_t quota);
120 int dsl_dir_set_reservation(const char *ddname, uint64_t reservation);
121 int dsl_dir_rename(dsl_dir_t *dd, const char *newname);
122 int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, uint64_t space);
123 int dsl_dir_set_reservation_check(void *arg1, void *arg2, dmu_tx_t *tx);
124 
125 /* internal reserved dir name */
126 #define	MOS_DIR_NAME "$MOS"
127 
128 #ifdef ZFS_DEBUG
129 #define	dprintf_dd(dd, fmt, ...) do { \
130 	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
131 	char *__ds_name = kmem_alloc(MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, \
132 	    KM_SLEEP); \
133 	dsl_dir_name(dd, __ds_name); \
134 	dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
135 	kmem_free(__ds_name, MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); \
136 	} \
137 _NOTE(CONSTCOND) } while (0)
138 #else
139 #define	dprintf_dd(dd, fmt, ...)
140 #endif
141 
142 #ifdef	__cplusplus
143 }
144 #endif
145 
146 #endif /* _SYS_DSL_DIR_H */
147