]>
Commit | Line | Data |
---|---|---|
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 | |
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 | /* | |
428870ff | 22 | * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. |
3ec3bc21 | 23 | * Copyright (c) 2012, 2016 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 BB |
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> | |
b5256303 | 36 | #include <sys/dsl_crypt.h> |
34dc7c2f BB |
37 | |
38 | #ifdef __cplusplus | |
39 | extern "C" { | |
40 | #endif | |
41 | ||
42 | struct dsl_dataset; | |
43 | ||
788eb90c JJ |
44 | /* |
45 | * DD_FIELD_* are strings that are used in the "extensified" dsl_dir zap object. | |
46 | * They should be of the format <reverse-dns>:<field>. | |
47 | */ | |
48 | ||
49 | #define DD_FIELD_FILESYSTEM_COUNT "com.joyent:filesystem_count" | |
50 | #define DD_FIELD_SNAPSHOT_COUNT "com.joyent:snapshot_count" | |
b5256303 | 51 | #define DD_FIELD_CRYPTO_KEY_OBJ "com.datto:crypto_key_obj" |
788eb90c | 52 | |
b128c09f BB |
53 | typedef enum dd_used { |
54 | DD_USED_HEAD, | |
55 | DD_USED_SNAP, | |
56 | DD_USED_CHILD, | |
57 | DD_USED_CHILD_RSRV, | |
58 | DD_USED_REFRSRV, | |
59 | DD_USED_NUM | |
60 | } dd_used_t; | |
61 | ||
62 | #define DD_FLAG_USED_BREAKDOWN (1<<0) | |
63 | ||
34dc7c2f BB |
64 | typedef struct dsl_dir_phys { |
65 | uint64_t dd_creation_time; /* not actually used */ | |
66 | uint64_t dd_head_dataset_obj; | |
67 | uint64_t dd_parent_obj; | |
68 | uint64_t dd_origin_obj; | |
69 | uint64_t dd_child_dir_zapobj; | |
70 | /* | |
71 | * how much space our children are accounting for; for leaf | |
72 | * datasets, == physical space used by fs + snaps | |
73 | */ | |
74 | uint64_t dd_used_bytes; | |
75 | uint64_t dd_compressed_bytes; | |
76 | uint64_t dd_uncompressed_bytes; | |
77 | /* Administrative quota setting */ | |
78 | uint64_t dd_quota; | |
79 | /* Administrative reservation setting */ | |
80 | uint64_t dd_reserved; | |
81 | uint64_t dd_props_zapobj; | |
82 | uint64_t dd_deleg_zapobj; /* dataset delegation permissions */ | |
b128c09f BB |
83 | uint64_t dd_flags; |
84 | uint64_t dd_used_breakdown[DD_USED_NUM]; | |
428870ff BB |
85 | uint64_t dd_clones; /* dsl_dir objects */ |
86 | uint64_t dd_pad[13]; /* pad out to 256 bytes for good measure */ | |
34dc7c2f BB |
87 | } dsl_dir_phys_t; |
88 | ||
89 | struct dsl_dir { | |
0c66c32d JG |
90 | dmu_buf_user_t dd_dbu; |
91 | ||
34dc7c2f BB |
92 | /* These are immutable; no lock needed: */ |
93 | uint64_t dd_object; | |
b5256303 | 94 | uint64_t dd_crypto_obj; |
34dc7c2f BB |
95 | dsl_pool_t *dd_pool; |
96 | ||
d683ddbb JG |
97 | /* Stable until user eviction; no lock needed: */ |
98 | dmu_buf_t *dd_dbuf; | |
99 | ||
34dc7c2f BB |
100 | /* protected by lock on pool's dp_dirty_dirs list */ |
101 | txg_node_t dd_dirty_link; | |
102 | ||
103 | /* protected by dp_config_rwlock */ | |
104 | dsl_dir_t *dd_parent; | |
105 | ||
106 | /* Protected by dd_lock */ | |
107 | kmutex_t dd_lock; | |
0eb21616 | 108 | list_t dd_props; /* list of dsl_prop_record_t's */ |
428870ff BB |
109 | timestruc_t dd_snap_cmtime; /* last time snapshot namespace changed */ |
110 | uint64_t dd_origin_txg; | |
34dc7c2f | 111 | |
34dc7c2f BB |
112 | /* gross estimate of space used by in-flight tx's */ |
113 | uint64_t dd_tempreserved[TXG_SIZE]; | |
114 | /* amount of space we expect to write; == amount of dirty data */ | |
115 | int64_t dd_space_towrite[TXG_SIZE]; | |
116 | ||
117 | /* protected by dd_lock; keep at end of struct for better locality */ | |
eca7b760 | 118 | char dd_myname[ZFS_MAX_DATASET_NAME_LEN]; |
34dc7c2f BB |
119 | }; |
120 | ||
d683ddbb JG |
121 | static inline dsl_dir_phys_t * |
122 | dsl_dir_phys(dsl_dir_t *dd) | |
123 | { | |
124 | return (dd->dd_dbuf->db_data); | |
125 | } | |
126 | ||
13fe0198 | 127 | void dsl_dir_rele(dsl_dir_t *dd, void *tag); |
0c66c32d | 128 | void dsl_dir_async_rele(dsl_dir_t *dd, void *tag); |
13fe0198 MA |
129 | int dsl_dir_hold(dsl_pool_t *dp, const char *name, void *tag, |
130 | dsl_dir_t **, const char **tail); | |
131 | int dsl_dir_hold_obj(dsl_pool_t *dp, uint64_t ddobj, | |
34dc7c2f BB |
132 | const char *tail, void *tag, dsl_dir_t **); |
133 | void dsl_dir_name(dsl_dir_t *dd, char *buf); | |
134 | int dsl_dir_namelen(dsl_dir_t *dd); | |
b128c09f BB |
135 | uint64_t dsl_dir_create_sync(dsl_pool_t *dp, dsl_dir_t *pds, |
136 | const char *name, dmu_tx_t *tx); | |
34dc7c2f BB |
137 | void dsl_dir_stats(dsl_dir_t *dd, nvlist_t *nv); |
138 | uint64_t dsl_dir_space_available(dsl_dir_t *dd, | |
139 | dsl_dir_t *ancestor, int64_t delta, int ondiskonly); | |
140 | void dsl_dir_dirty(dsl_dir_t *dd, dmu_tx_t *tx); | |
141 | void dsl_dir_sync(dsl_dir_t *dd, dmu_tx_t *tx); | |
142 | int dsl_dir_tempreserve_space(dsl_dir_t *dd, uint64_t mem, | |
3ec3bc21 | 143 | uint64_t asize, boolean_t netfree, void **tr_cookiep, dmu_tx_t *tx); |
34dc7c2f BB |
144 | void dsl_dir_tempreserve_clear(void *tr_cookie, dmu_tx_t *tx); |
145 | void dsl_dir_willuse_space(dsl_dir_t *dd, int64_t space, dmu_tx_t *tx); | |
b128c09f | 146 | void dsl_dir_diduse_space(dsl_dir_t *dd, dd_used_t type, |
34dc7c2f | 147 | int64_t used, int64_t compressed, int64_t uncompressed, dmu_tx_t *tx); |
b128c09f BB |
148 | void dsl_dir_transfer_space(dsl_dir_t *dd, int64_t delta, |
149 | dd_used_t oldtype, dd_used_t newtype, dmu_tx_t *tx); | |
428870ff BB |
150 | int dsl_dir_set_quota(const char *ddname, zprop_source_t source, |
151 | uint64_t quota); | |
152 | int dsl_dir_set_reservation(const char *ddname, zprop_source_t source, | |
153 | uint64_t reservation); | |
788eb90c JJ |
154 | int dsl_dir_activate_fs_ss_limit(const char *); |
155 | int dsl_fs_ss_limit_check(dsl_dir_t *, uint64_t, zfs_prop_t, dsl_dir_t *, | |
156 | cred_t *); | |
157 | void dsl_fs_ss_count_adjust(dsl_dir_t *, int64_t, const char *, dmu_tx_t *); | |
13fe0198 | 158 | int dsl_dir_rename(const char *oldname, const char *newname); |
788eb90c JJ |
159 | int dsl_dir_transfer_possible(dsl_dir_t *sdd, dsl_dir_t *tdd, |
160 | uint64_t fs_cnt, uint64_t ss_cnt, uint64_t space, cred_t *); | |
b128c09f BB |
161 | boolean_t dsl_dir_is_clone(dsl_dir_t *dd); |
162 | void dsl_dir_new_refreservation(dsl_dir_t *dd, struct dsl_dataset *ds, | |
163 | uint64_t reservation, cred_t *cr, dmu_tx_t *tx); | |
428870ff BB |
164 | void dsl_dir_snap_cmtime_update(dsl_dir_t *dd); |
165 | timestruc_t dsl_dir_snap_cmtime(dsl_dir_t *dd); | |
13fe0198 MA |
166 | void dsl_dir_set_reservation_sync_impl(dsl_dir_t *dd, uint64_t value, |
167 | dmu_tx_t *tx); | |
788eb90c JJ |
168 | void dsl_dir_zapify(dsl_dir_t *dd, dmu_tx_t *tx); |
169 | boolean_t dsl_dir_is_zapified(dsl_dir_t *dd); | |
34dc7c2f BB |
170 | |
171 | /* internal reserved dir name */ | |
172 | #define MOS_DIR_NAME "$MOS" | |
b128c09f | 173 | #define ORIGIN_DIR_NAME "$ORIGIN" |
428870ff BB |
174 | #define XLATION_DIR_NAME "$XLATION" |
175 | #define FREE_DIR_NAME "$FREE" | |
fbeddd60 | 176 | #define LEAK_DIR_NAME "$LEAK" |
34dc7c2f BB |
177 | |
178 | #ifdef ZFS_DEBUG | |
179 | #define dprintf_dd(dd, fmt, ...) do { \ | |
180 | if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ | |
eca7b760 | 181 | char *__ds_name = kmem_alloc(ZFS_MAX_DATASET_NAME_LEN, KM_SLEEP); \ |
34dc7c2f BB |
182 | dsl_dir_name(dd, __ds_name); \ |
183 | dprintf("dd=%s " fmt, __ds_name, __VA_ARGS__); \ | |
eca7b760 | 184 | kmem_free(__ds_name, ZFS_MAX_DATASET_NAME_LEN); \ |
34dc7c2f BB |
185 | } \ |
186 | _NOTE(CONSTCOND) } while (0) | |
187 | #else | |
188 | #define dprintf_dd(dd, fmt, ...) | |
189 | #endif | |
190 | ||
191 | #ifdef __cplusplus | |
192 | } | |
193 | #endif | |
194 | ||
195 | #endif /* _SYS_DSL_DIR_H */ |