Merge commit '8671400134a11c848244896ca51a7db4d0f69da4'
[unleashed.git] / kernel / fs / zfs / sys / dsl_dir.h
blob21d953cb6013cd712e4313aeab904f5ac7e89b49
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
24 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
25 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
28 #ifndef _SYS_DSL_DIR_H
29 #define _SYS_DSL_DIR_H
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>
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
41 struct dsl_dataset;
44 * DD_FIELD_* are strings that are used in the "extensified" dsl_dir zap object.
45 * They should be of the format <reverse-dns>:<field>.
48 #define DD_FIELD_FILESYSTEM_COUNT "com.joyent:filesystem_count"
49 #define DD_FIELD_SNAPSHOT_COUNT "com.joyent:snapshot_count"
50 #define DD_FIELD_LAST_REMAP_TXG "com.delphix:last_remap_txg"
52 typedef enum dd_used {
53 DD_USED_HEAD,
54 DD_USED_SNAP,
55 DD_USED_CHILD,
56 DD_USED_CHILD_RSRV,
57 DD_USED_REFRSRV,
58 DD_USED_NUM
59 } dd_used_t;
61 #define DD_FLAG_USED_BREAKDOWN (1<<0)
63 typedef struct dsl_dir_phys {
64 uint64_t dd_creation_time; /* not actually used */
65 uint64_t dd_head_dataset_obj;
66 uint64_t dd_parent_obj;
67 uint64_t dd_origin_obj;
68 uint64_t dd_child_dir_zapobj;
70 * how much space our children are accounting for; for leaf
71 * datasets, == physical space used by fs + snaps
73 uint64_t dd_used_bytes;
74 uint64_t dd_compressed_bytes;
75 uint64_t dd_uncompressed_bytes;
76 /* Administrative quota setting */
77 uint64_t dd_quota;
78 /* Administrative reservation setting */
79 uint64_t dd_reserved;
80 uint64_t dd_props_zapobj;
81 uint64_t dd_deleg_zapobj; /* dataset delegation permissions */
82 uint64_t dd_flags;
83 uint64_t dd_used_breakdown[DD_USED_NUM];
84 uint64_t dd_clones; /* dsl_dir objects */
85 uint64_t dd_pad[13]; /* pad out to 256 bytes for good measure */
86 } dsl_dir_phys_t;
88 struct dsl_dir {
89 dmu_buf_user_t dd_dbu;
91 /* These are immutable; no lock needed: */
92 uint64_t dd_object;
93 dsl_pool_t *dd_pool;
95 /* Stable until user eviction; no lock needed: */
96 dmu_buf_t *dd_dbuf;
98 /* protected by lock on pool's dp_dirty_dirs list */
99 txg_node_t dd_dirty_link;
101 /* protected by dp_config_rwlock */
102 dsl_dir_t *dd_parent;
104 /* Protected by dd_lock */
105 kmutex_t dd_lock;
106 list_t dd_props; /* list of dsl_prop_record_t's */
107 timestruc_t dd_snap_cmtime; /* last time snapshot namespace changed */
108 uint64_t dd_origin_txg;
110 /* gross estimate of space used by in-flight tx's */
111 uint64_t dd_tempreserved[TXG_SIZE];
112 /* amount of space we expect to write; == amount of dirty data */
113 int64_t dd_space_towrite[TXG_SIZE];
115 /* protected by dd_lock; keep at end of struct for better locality */
116 char dd_myname[ZFS_MAX_DATASET_NAME_LEN];
119 inline dsl_dir_phys_t *
120 dsl_dir_phys(dsl_dir_t *dd)
122 return (dd->dd_dbuf->db_data);
125 void dsl_dir_rele(dsl_dir_t *dd, void *tag);
126 void dsl_dir_async_rele(dsl_dir_t *dd, void *tag);
127 int dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag,
128 dsl_dir_t **, const char **tail);
129 int dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj,
130 const char *tail, void *tag, dsl_dir_t **);
131 void dsl_dir_name(dsl_dir_t *dd, char *buf);
132 int dsl_dir_namelen(dsl_dir_t *dd);
133 uint64_t dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds,
134 const char *name, dmu_tx_t *tx);
136 uint64_t dsl_dir_get_used(dsl_dir_t *dd);
137 uint64_t dsl_dir_get_compressed(dsl_dir_t *dd);
138 uint64_t dsl_dir_get_quota(dsl_dir_t *dd);
139 uint64_t dsl_dir_get_reservation(dsl_dir_t *dd);
140 uint64_t dsl_dir_get_compressratio(dsl_dir_t *dd);
141 uint64_t dsl_dir_get_logicalused(dsl_dir_t *dd);
142 uint64_t dsl_dir_get_usedsnap(dsl_dir_t *dd);
143 uint64_t dsl_dir_get_usedds(dsl_dir_t *dd);
144 uint64_t dsl_dir_get_usedrefreserv(dsl_dir_t *dd);
145 uint64_t dsl_dir_get_usedchild(dsl_dir_t *dd);
146 void dsl_dir_get_origin(dsl_dir_t *dd, char *buf);
147 int dsl_dir_get_filesystem_count(dsl_dir_t *dd, uint64_t *count);
148 int dsl_dir_get_snapshot_count(dsl_dir_t *dd, uint64_t *count);
149 int dsl_dir_get_remaptxg(dsl_dir_t *dd, uint64_t *count);
151 void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv);
152 uint64_t dsl_dir_space_available(dsl_dir_t *dd,
153 dsl_dir_t *ancestor, int64_t delta, int ondiskonly);
154 void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx);
155 void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx);
156 int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem,
157 uint64_t asize, boolean_t netfree, void **tr_cookiep, dmu_tx_t *tx);
158 void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx);
159 void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx);
160 void dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type,
161 int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx);
162 void dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta,
163 dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx);
164 int dsl_dir_set_quota(const char *ddname, zprop_source_t source,
165 uint64_t quota);
166 int dsl_dir_set_reservation(const char *ddname, zprop_source_t source,
167 uint64_t reservation);
168 int dsl_dir_activate_fs_ss_limit(const char *);
169 int dsl_fs_ss_limit_check(dsl_dir_t *, uint64_t, zfs_prop_t, dsl_dir_t *,
170 cred_t *);
171 void dsl_fs_ss_count_adjust(dsl_dir_t *, int64_t, const char *, dmu_tx_t *);
172 int dsl_dir_update_last_remap_txg(dsl_dir_t *, uint64_t);
173 int dsl_dir_rename(const char *oldname, const char *newname);
174 int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd,
175 uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space, cred_t *);
176 boolean_t dsl_dir_is_clone(dsl_dir_t *dd);
177 void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds,
178 uint64_t reservation, cred_t *cr, dmu_tx_t *tx);
179 void dsl_dir_snap_cmtime_update(dsl_dir_t *dd);
180 timestruc_t dsl_dir_snap_cmtime(dsl_dir_t *dd);
181 void dsl_dir_set_reservation_sync_impl(dsl_dir_t *dd, uint64_t value,
182 dmu_tx_t *tx);
183 void dsl_dir_zapify(dsl_dir_t *dd, dmu_tx_t *tx);
184 boolean_t dsl_dir_is_zapified(dsl_dir_t *dd);
186 /* internal reserved dir name */
187 #define MOS_DIR_NAME "$MOS"
188 #define ORIGIN_DIR_NAME "$ORIGIN"
189 #define FREE_DIR_NAME "$FREE"
190 #define LEAK_DIR_NAME "$LEAK"
192 #ifdef ZFS_DEBUG
193 #define dprintf_dd(dd, fmt, ...) do { \
194 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
195 char *__ds_name = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP); \
196 dsl_dir_name(dd, __ds_name); \
197 dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
198 kmem_free(__ds_name, ZFS_MAX_DATASET_NAME_LEN); \
200 _NOTE(CONSTCOND) } while (0)
201 #else
202 #define dprintf_dd(dd, fmt, ...)
203 #endif
205 #ifdef __cplusplus
207 #endif
209 #endif /* _SYS_DSL_DIR_H */