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.
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.
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]
22 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_DSL_DIR_H
27 #define _SYS_DSL_DIR_H
29 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <sys/dsl_pool.h>
33 #include <sys/dsl_synctask.h>
34 #include <sys/refcount.h>
35 #include <sys/zfs_context.h>
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;
50 * how much space our children are accounting for; for leaf
51 * datasets, == physical space used by fs + snaps
53 uint64_t dd_used_bytes;
54 uint64_t dd_compressed_bytes;
55 uint64_t dd_uncompressed_bytes;
56 /* Administrative quota setting */
58 /* Administrative reservation setting */
60 uint64_t dd_props_zapobj;
61 uint64_t dd_pad[21]; /* pad out to 256 bytes for good measure */
65 /* These are immutable; no lock needed: */
67 dsl_dir_phys_t *dd_phys;
71 /* protected by lock on pool's dp_dirty_dirs list */
72 txg_node_t dd_dirty_link;
74 /* protected by dp_config_rwlock */
77 /* Protected by dd_lock */
79 list_t dd_prop_cbs; /* list of dsl_prop_cb_record_t's */
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];
89 /* protected by dd_lock; keep at end of struct for better locality */
90 char dd_myname[MAXNAMELEN];
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 **,
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_namelen(dsl_dir_t *dd);
101 int dsl_dir_is_private(dsl_dir_t *dd);
102 uint64_t dsl_dir_create_sync(dsl_dir_t *pds, const char *name, dmu_tx_t *tx);
103 void dsl_dir_create_root(objset_t *mos, uint64_t *ddobjp, dmu_tx_t *tx);
104 dsl_checkfunc_t dsl_dir_destroy_check;
105 dsl_syncfunc_t dsl_dir_destroy_sync;
106 void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv);
107 uint64_t dsl_dir_space_available(dsl_dir_t *dd,
108 dsl_dir_t *ancestor, int64_t delta, int ondiskonly);
109 void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx);
110 void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx);
111 int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem,
112 uint64_t asize, uint64_t fsize, void **tr_cookiep, dmu_tx_t *tx);
113 void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx);
114 void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx);
115 void dsl_dir_diduse_space(dsl_dir_t *dd,
116 int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx);
117 int dsl_dir_set_quota(const char *ddname, uint64_t quota);
118 int dsl_dir_set_reservation(const char *ddname, uint64_t reservation);
119 int dsl_dir_rename(dsl_dir_t *dd, const char *newname);
120 int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, uint64_t space);
122 /* internal reserved dir name */
123 #define MOS_DIR_NAME "$MOS"
126 #define dprintf_dd(dd, fmt, ...) do { \
127 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
128 char *__ds_name = kmem_alloc(MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, \
130 dsl_dir_name(dd, __ds_name); \
131 dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
132 kmem_free(__ds_name, MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); \
134 _NOTE(CONSTCOND) } while (0)
136 #define dprintf_dd(dd, fmt, ...)
143 #endif /* _SYS_DSL_DIR_H */