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 (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
27 #ifndef _SYS_DSL_DIR_H
28 #define _SYS_DSL_DIR_H
31 #include <sys/dsl_pool.h>
32 #include <sys/dsl_synctask.h>
33 #include <sys/refcount.h>
34 #include <sys/zfs_context.h>
43 * DD_FIELD_* are strings that are used in the "extensified" dsl_dir zap object.
44 * They should be of the format <reverse-dns>:<field>.
47 #define DD_FIELD_FILESYSTEM_COUNT "com.joyent:filesystem_count"
48 #define DD_FIELD_SNAPSHOT_COUNT "com.joyent:snapshot_count"
50 typedef enum dd_used {
59 #define DD_FLAG_USED_BREAKDOWN (1<<0)
61 typedef struct dsl_dir_phys {
62 uint64_t dd_creation_time; /* not actually used */
63 uint64_t dd_head_dataset_obj;
64 uint64_t dd_parent_obj;
65 uint64_t dd_origin_obj;
66 uint64_t dd_child_dir_zapobj;
68 * how much space our children are accounting for; for leaf
69 * datasets, == physical space used by fs + snaps
71 uint64_t dd_used_bytes;
72 uint64_t dd_compressed_bytes;
73 uint64_t dd_uncompressed_bytes;
74 /* Administrative quota setting */
76 /* Administrative reservation setting */
78 uint64_t dd_props_zapobj;
79 uint64_t dd_deleg_zapobj; /* dataset delegation permissions */
81 uint64_t dd_used_breakdown[DD_USED_NUM];
82 uint64_t dd_clones; /* dsl_dir objects */
83 uint64_t dd_pad[13]; /* pad out to 256 bytes for good measure */
87 /* These are immutable; no lock needed: */
89 dsl_dir_phys_t *dd_phys;
93 /* protected by lock on pool's dp_dirty_dirs list */
94 txg_node_t dd_dirty_link;
96 /* protected by dp_config_rwlock */
99 /* Protected by dd_lock */
101 list_t dd_prop_cbs; /* list of dsl_prop_cb_record_t's */
102 timestruc_t dd_snap_cmtime; /* last time snapshot namespace changed */
103 uint64_t dd_origin_txg;
105 /* gross estimate of space used by in-flight tx's */
106 uint64_t dd_tempreserved[TXG_SIZE];
107 /* amount of space we expect to write; == amount of dirty data */
108 int64_t dd_space_towrite[TXG_SIZE];
110 /* protected by dd_lock; keep at end of struct for better locality */
111 char dd_myname[MAXNAMELEN];
114 void dsl_dir_rele(dsl_dir_t *dd, void *tag);
115 int dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag,
116 dsl_dir_t **, const char **tail);
117 int dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj,
118 const char *tail, void *tag, dsl_dir_t **);
119 void dsl_dir_name(dsl_dir_t *dd, char *buf);
120 int dsl_dir_namelen(dsl_dir_t *dd);
121 uint64_t dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds,
122 const char *name, dmu_tx_t *tx);
123 void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv);
124 uint64_t dsl_dir_space_available(dsl_dir_t *dd,
125 dsl_dir_t *ancestor, int64_t delta, int ondiskonly);
126 void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx);
127 void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx);
128 int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem,
129 uint64_t asize, uint64_t fsize, uint64_t usize, void **tr_cookiep,
131 void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx);
132 void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx);
133 void dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type,
134 int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx);
135 void dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta,
136 dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx);
137 int dsl_dir_set_quota(const char *ddname, zprop_source_t source,
139 int dsl_dir_set_reservation(const char *ddname, zprop_source_t source,
140 uint64_t reservation);
141 int dsl_dir_activate_fs_ss_limit(const char *);
142 int dsl_fs_ss_limit_check(dsl_dir_t *, uint64_t, zfs_prop_t, dsl_dir_t *,
144 void dsl_fs_ss_count_adjust(dsl_dir_t *, int64_t, const char *, dmu_tx_t *);
145 int dsl_dir_rename(const char *oldname, const char *newname);
146 int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd,
147 uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space, cred_t *);
148 boolean_t dsl_dir_is_clone(dsl_dir_t *dd);
149 void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds,
150 uint64_t reservation, cred_t *cr, dmu_tx_t *tx);
151 void dsl_dir_snap_cmtime_update(dsl_dir_t *dd);
152 timestruc_t dsl_dir_snap_cmtime(dsl_dir_t *dd);
153 void dsl_dir_set_reservation_sync_impl(dsl_dir_t *dd, uint64_t value,
155 void dsl_dir_zapify(dsl_dir_t *dd, dmu_tx_t *tx);
156 boolean_t dsl_dir_is_zapified(dsl_dir_t *dd);
158 /* internal reserved dir name */
159 #define MOS_DIR_NAME "$MOS"
160 #define ORIGIN_DIR_NAME "$ORIGIN"
161 #define XLATION_DIR_NAME "$XLATION"
162 #define FREE_DIR_NAME "$FREE"
165 #define dprintf_dd(dd, fmt, ...) do { \
166 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
167 char *__ds_name = kmem_alloc(MAXNAMELEN + strlen(MOS_DIR_NAME) + 1, \
169 dsl_dir_name(dd, __ds_name); \
170 dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
171 kmem_free(__ds_name, MAXNAMELEN + strlen(MOS_DIR_NAME) + 1); \
173 _NOTE(CONSTCOND) } while (0)
175 #define dprintf_dd(dd, fmt, ...)
182 #endif /* _SYS_DSL_DIR_H */