]> git.proxmox.com Git - mirror_zfs.git/blame - include/sys/dsl_dir.h
Add DD_FIELD string for snapshots_changed property
[mirror_zfs.git] / include / sys / dsl_dir.h
CommitLineData
34dc7c2f
BB
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
1d3ba0bf 9 * or https://opensource.org/licenses/CDDL-1.0.
34dc7c2f
BB
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/*
428870ff 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
37f03da8 23 * Copyright (c) 2012, 2018 by Delphix. All rights reserved.
788eb90c 24 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
0c66c32d 25 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
34dc7c2f
BB
26 */
27
28#ifndef _SYS_DSL_DIR_H
29#define _SYS_DSL_DIR_H
30
34dc7c2f 31#include <sys/dmu.h>
37f03da8 32#include <sys/dsl_deadlist.h>
34dc7c2f
BB
33#include <sys/dsl_pool.h>
34#include <sys/dsl_synctask.h>
27d96d22 35#include <sys/zfs_refcount.h>
34dc7c2f 36#include <sys/zfs_context.h>
b5256303 37#include <sys/dsl_crypt.h>
37f03da8 38#include <sys/bplist.h>
34dc7c2f
BB
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
44struct dsl_dataset;
37f03da8 45struct zthr;
788eb90c
JJ
46/*
47 * DD_FIELD_* are strings that are used in the "extensified" dsl_dir zap object.
48 * They should be of the format <reverse-dns>:<field>.
49 */
50
51#define DD_FIELD_FILESYSTEM_COUNT "com.joyent:filesystem_count"
52#define DD_FIELD_SNAPSHOT_COUNT "com.joyent:snapshot_count"
b5256303 53#define DD_FIELD_CRYPTO_KEY_OBJ "com.datto:crypto_key_obj"
37f03da8 54#define DD_FIELD_LIVELIST "com.delphix:livelist"
59767479 55#define DD_FIELD_SNAPSHOTS_CHANGED "com.ixsystems:snapshots_changed"
788eb90c 56
b128c09f
BB
57typedef enum dd_used {
58 DD_USED_HEAD,
59 DD_USED_SNAP,
60 DD_USED_CHILD,
61 DD_USED_CHILD_RSRV,
62 DD_USED_REFRSRV,
63 DD_USED_NUM
64} dd_used_t;
65
66#define DD_FLAG_USED_BREAKDOWN (1<<0)
67
34dc7c2f
BB
68typedef struct dsl_dir_phys {
69 uint64_t dd_creation_time; /* not actually used */
70 uint64_t dd_head_dataset_obj;
71 uint64_t dd_parent_obj;
72 uint64_t dd_origin_obj;
73 uint64_t dd_child_dir_zapobj;
74 /*
75 * how much space our children are accounting for; for leaf
76 * datasets, == physical space used by fs + snaps
77 */
78 uint64_t dd_used_bytes;
79 uint64_t dd_compressed_bytes;
80 uint64_t dd_uncompressed_bytes;
81 /* Administrative quota setting */
82 uint64_t dd_quota;
83 /* Administrative reservation setting */
84 uint64_t dd_reserved;
85 uint64_t dd_props_zapobj;
86 uint64_t dd_deleg_zapobj; /* dataset delegation permissions */
b128c09f
BB
87 uint64_t dd_flags;
88 uint64_t dd_used_breakdown[DD_USED_NUM];
428870ff
BB
89 uint64_t dd_clones; /* dsl_dir objects */
90 uint64_t dd_pad[13]; /* pad out to 256 bytes for good measure */
34dc7c2f
BB
91} dsl_dir_phys_t;
92
93struct dsl_dir {
0c66c32d
JG
94 dmu_buf_user_t dd_dbu;
95
34dc7c2f
BB
96 /* These are immutable; no lock needed: */
97 uint64_t dd_object;
b5256303 98 uint64_t dd_crypto_obj;
34dc7c2f
BB
99 dsl_pool_t *dd_pool;
100
d683ddbb
JG
101 /* Stable until user eviction; no lock needed: */
102 dmu_buf_t *dd_dbuf;
103
34dc7c2f
BB
104 /* protected by lock on pool's dp_dirty_dirs list */
105 txg_node_t dd_dirty_link;
106
107 /* protected by dp_config_rwlock */
108 dsl_dir_t *dd_parent;
109
110 /* Protected by dd_lock */
111 kmutex_t dd_lock;
0eb21616 112 list_t dd_props; /* list of dsl_prop_record_t's */
6413c95f 113 inode_timespec_t dd_snap_cmtime; /* last snapshot namespace change */
428870ff 114 uint64_t dd_origin_txg;
34dc7c2f 115
34dc7c2f
BB
116 /* gross estimate of space used by in-flight tx's */
117 uint64_t dd_tempreserved[TXG_SIZE];
118 /* amount of space we expect to write; == amount of dirty data */
119 int64_t dd_space_towrite[TXG_SIZE];
120
37f03da8
SH
121 dsl_deadlist_t dd_livelist;
122 bplist_t dd_pending_frees;
123 bplist_t dd_pending_allocs;
124
5a42ef04
PD
125 kmutex_t dd_activity_lock;
126 kcondvar_t dd_activity_cv;
127 boolean_t dd_activity_cancelled;
128 uint64_t dd_activity_waiters;
129
34dc7c2f 130 /* protected by dd_lock; keep at end of struct for better locality */
eca7b760 131 char dd_myname[ZFS_MAX_DATASET_NAME_LEN];
34dc7c2f
BB
132};
133
d683ddbb
JG
134static inline dsl_dir_phys_t *
135dsl_dir_phys(dsl_dir_t *dd)
136{
137 return (dd->dd_dbuf->db_data);
138}
139
dd66857d
AZ
140void dsl_dir_rele(dsl_dir_t *dd, const void *tag);
141void dsl_dir_async_rele(dsl_dir_t *dd, const void *tag);
142int dsl_dir_hold(dsl_pool_t *dp, const char *name, const void *tag,
13fe0198
MA
143 dsl_dir_t **, const char **tail);
144int dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj,
dd66857d 145 const char *tail, const void *tag, dsl_dir_t **);
34dc7c2f
BB
146void dsl_dir_name(dsl_dir_t *dd, char *buf);
147int dsl_dir_namelen(dsl_dir_t *dd);
b128c09f
BB
148uint64_t dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds,
149 const char *name, dmu_tx_t *tx);
d99a0153
CW
150
151uint64_t dsl_dir_get_used(dsl_dir_t *dd);
d2734cce 152uint64_t dsl_dir_get_compressed(dsl_dir_t *dd);
d99a0153
CW
153uint64_t dsl_dir_get_quota(dsl_dir_t *dd);
154uint64_t dsl_dir_get_reservation(dsl_dir_t *dd);
155uint64_t dsl_dir_get_compressratio(dsl_dir_t *dd);
156uint64_t dsl_dir_get_logicalused(dsl_dir_t *dd);
157uint64_t dsl_dir_get_usedsnap(dsl_dir_t *dd);
158uint64_t dsl_dir_get_usedds(dsl_dir_t *dd);
159uint64_t dsl_dir_get_usedrefreserv(dsl_dir_t *dd);
160uint64_t dsl_dir_get_usedchild(dsl_dir_t *dd);
161void dsl_dir_get_origin(dsl_dir_t *dd, char *buf);
162int dsl_dir_get_filesystem_count(dsl_dir_t *dd, uint64_t *count);
163int dsl_dir_get_snapshot_count(dsl_dir_t *dd, uint64_t *count);
164
34dc7c2f
BB
165void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv);
166uint64_t dsl_dir_space_available(dsl_dir_t *dd,
167 dsl_dir_t *ancestor, int64_t delta, int ondiskonly);
168void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx);
169void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx);
170int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem,
3ec3bc21 171 uint64_t asize, boolean_t netfree, void **tr_cookiep, dmu_tx_t *tx);
34dc7c2f
BB
172void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx);
173void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx);
b128c09f 174void dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type,
34dc7c2f 175 int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx);
b128c09f
BB
176void dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta,
177 dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx);
c1b5869b
AM
178void dsl_dir_diduse_transfer_space(dsl_dir_t *dd, int64_t used,
179 int64_t compressed, int64_t uncompressed, int64_t tonew,
180 dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx);
428870ff
BB
181int dsl_dir_set_quota(const char *ddname, zprop_source_t source,
182 uint64_t quota);
183int dsl_dir_set_reservation(const char *ddname, zprop_source_t source,
184 uint64_t reservation);
788eb90c
JJ
185int dsl_dir_activate_fs_ss_limit(const char *);
186int dsl_fs_ss_limit_check(dsl_dir_t *, uint64_t, zfs_prop_t, dsl_dir_t *,
e59a377a 187 cred_t *, proc_t *);
788eb90c 188void dsl_fs_ss_count_adjust(dsl_dir_t *, int64_t, const char *, dmu_tx_t *);
13fe0198 189int dsl_dir_rename(const char *oldname, const char *newname);
788eb90c 190int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd,
e59a377a 191 uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space, cred_t *, proc_t *);
b128c09f
BB
192boolean_t dsl_dir_is_clone(dsl_dir_t *dd);
193void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds,
194 uint64_t reservation, cred_t *cr, dmu_tx_t *tx);
9681de46 195void dsl_dir_snap_cmtime_update(dsl_dir_t *dd, dmu_tx_t *tx);
6413c95f 196inode_timespec_t dsl_dir_snap_cmtime(dsl_dir_t *dd);
13fe0198
MA
197void dsl_dir_set_reservation_sync_impl(dsl_dir_t *dd, uint64_t value,
198 dmu_tx_t *tx);
788eb90c
JJ
199void dsl_dir_zapify(dsl_dir_t *dd, dmu_tx_t *tx);
200boolean_t dsl_dir_is_zapified(dsl_dir_t *dd);
37f03da8
SH
201void dsl_dir_livelist_open(dsl_dir_t *dd, uint64_t obj);
202void dsl_dir_livelist_close(dsl_dir_t *dd);
203void dsl_dir_remove_livelist(dsl_dir_t *dd, dmu_tx_t *tx, boolean_t total);
5a42ef04
PD
204int dsl_dir_wait(dsl_dir_t *dd, dsl_dataset_t *ds, zfs_wait_activity_t activity,
205 boolean_t *waited);
206void dsl_dir_cancel_waiters(dsl_dir_t *dd);
34dc7c2f
BB
207
208/* internal reserved dir name */
209#define MOS_DIR_NAME "$MOS"
b128c09f 210#define ORIGIN_DIR_NAME "$ORIGIN"
428870ff 211#define FREE_DIR_NAME "$FREE"
fbeddd60 212#define LEAK_DIR_NAME "$LEAK"
34dc7c2f
BB
213
214#ifdef ZFS_DEBUG
215#define dprintf_dd(dd, fmt, ...) do { \
216 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
eca7b760 217 char *__ds_name = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP); \
34dc7c2f
BB
218 dsl_dir_name(dd, __ds_name); \
219 dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \
eca7b760 220 kmem_free(__ds_name, ZFS_MAX_DATASET_NAME_LEN); \
34dc7c2f 221 } \
037af3e0 222} while (0)
34dc7c2f
BB
223#else
224#define dprintf_dd(dd, fmt, ...)
225#endif
226
227#ifdef __cplusplus
228}
229#endif
230
231#endif /* _SYS_DSL_DIR_H */