]>
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. |
1fac63e5 | 23 | * Copyright (c) 2012, 2018 by Delphix. All rights reserved. |
0c66c32d | 24 | * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved. |
34dc7c2f BB |
25 | */ |
26 | ||
27 | #ifndef _SYS_DNODE_H | |
28 | #define _SYS_DNODE_H | |
29 | ||
34dc7c2f BB |
30 | #include <sys/zfs_context.h> |
31 | #include <sys/avl.h> | |
32 | #include <sys/spa.h> | |
33 | #include <sys/txg.h> | |
34 | #include <sys/zio.h> | |
35 | #include <sys/refcount.h> | |
36 | #include <sys/dmu_zfetch.h> | |
572e2857 | 37 | #include <sys/zrlock.h> |
64fc7762 | 38 | #include <sys/multilist.h> |
34dc7c2f BB |
39 | |
40 | #ifdef __cplusplus | |
41 | extern "C" { | |
42 | #endif | |
43 | ||
44 | /* | |
b128c09f | 45 | * dnode_hold() flags. |
34dc7c2f BB |
46 | */ |
47 | #define DNODE_MUST_BE_ALLOCATED 1 | |
48 | #define DNODE_MUST_BE_FREE 2 | |
49 | ||
b128c09f BB |
50 | /* |
51 | * dnode_next_offset() flags. | |
52 | */ | |
53 | #define DNODE_FIND_HOLE 1 | |
54 | #define DNODE_FIND_BACKWARDS 2 | |
55 | #define DNODE_FIND_HAVELOCK 4 | |
56 | ||
34dc7c2f BB |
57 | /* |
58 | * Fixed constants. | |
59 | */ | |
60 | #define DNODE_SHIFT 9 /* 512 bytes */ | |
d25b4497 | 61 | #define DN_MIN_INDBLKSHIFT 12 /* 4k */ |
32d41fb7 PD |
62 | /* |
63 | * If we ever increase this value beyond 20, we need to revisit all logic that | |
64 | * does x << level * ebps to handle overflow. With a 1M indirect block size, | |
65 | * 4 levels of indirect blocks would not be able to guarantee addressing an | |
66 | * entire object, so 5 levels will be used, but 5 * (20 - 7) = 65. | |
67 | */ | |
d7958b4c | 68 | #define DN_MAX_INDBLKSHIFT 17 /* 128k */ |
34dc7c2f BB |
69 | #define DNODE_BLOCK_SHIFT 14 /* 16k */ |
70 | #define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */ | |
71 | #define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */ | |
72 | #define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */ | |
73 | ||
428870ff BB |
74 | /* |
75 | * dnode id flags | |
76 | * | |
b5256303 | 77 | * Note: a file will never ever have its ids moved from bonus->spill |
428870ff BB |
78 | */ |
79 | #define DN_ID_CHKED_BONUS 0x1 | |
80 | #define DN_ID_CHKED_SPILL 0x2 | |
81 | #define DN_ID_OLD_EXIST 0x4 | |
82 | #define DN_ID_NEW_EXIST 0x8 | |
83 | ||
34dc7c2f BB |
84 | /* |
85 | * Derived constants. | |
86 | */ | |
50c957f7 NB |
87 | #define DNODE_MIN_SIZE (1 << DNODE_SHIFT) |
88 | #define DNODE_MAX_SIZE (1 << DNODE_BLOCK_SHIFT) | |
89 | #define DNODE_BLOCK_SIZE (1 << DNODE_BLOCK_SHIFT) | |
90 | #define DNODE_MIN_SLOTS (DNODE_MIN_SIZE >> DNODE_SHIFT) | |
91 | #define DNODE_MAX_SLOTS (DNODE_MAX_SIZE >> DNODE_SHIFT) | |
92 | #define DN_BONUS_SIZE(dnsize) ((dnsize) - DNODE_CORE_SIZE - \ | |
93 | (1 << SPA_BLKPTRSHIFT)) | |
94 | #define DN_SLOTS_TO_BONUSLEN(slots) DN_BONUS_SIZE((slots) << DNODE_SHIFT) | |
95 | #define DN_OLD_MAX_BONUSLEN (DN_BONUS_SIZE(DNODE_MIN_SIZE)) | |
96 | #define DN_MAX_NBLKPTR ((DNODE_MIN_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT) | |
34dc7c2f | 97 | #define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT) |
50c957f7 | 98 | #define DN_ZERO_BONUSLEN (DN_BONUS_SIZE(DNODE_MAX_SIZE) + 1) |
428870ff | 99 | #define DN_KILL_SPILLBLK (1) |
34dc7c2f | 100 | |
4c5b89f5 OF |
101 | #define DN_SLOT_UNINIT ((void *)NULL) /* Uninitialized */ |
102 | #define DN_SLOT_FREE ((void *)1UL) /* Free slot */ | |
103 | #define DN_SLOT_ALLOCATED ((void *)2UL) /* Allocated slot */ | |
104 | #define DN_SLOT_INTERIOR ((void *)3UL) /* Interior allocated slot */ | |
105 | #define DN_SLOT_IS_PTR(dn) ((void *)dn > DN_SLOT_INTERIOR) | |
106 | #define DN_SLOT_IS_VALID(dn) ((void *)dn != NULL) | |
107 | ||
34dc7c2f BB |
108 | #define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT) |
109 | #define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT) | |
d7958b4c MA |
110 | |
111 | /* | |
112 | * This is inaccurate if the indblkshift of the particular object is not the | |
113 | * max. But it's only used by userland to calculate the zvol reservation. | |
114 | */ | |
34dc7c2f | 115 | #define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT) |
428870ff | 116 | #define DNODES_PER_LEVEL (1ULL << DNODES_PER_LEVEL_SHIFT) |
34dc7c2f | 117 | |
031d7c2f GN |
118 | #define DN_MAX_LEVELS (DIV_ROUND_UP(DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT, \ |
119 | DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT) + 1) | |
34dc7c2f BB |
120 | |
121 | #define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \ | |
122 | (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t)))) | |
b5256303 TC |
123 | #define DN_MAX_BONUS_LEN(dnp) \ |
124 | ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) ? \ | |
125 | (uint8_t *)DN_SPILL_BLKPTR(dnp) - (uint8_t *)DN_BONUS(dnp) : \ | |
126 | (uint8_t *)(dnp + (dnp->dn_extra_slots + 1)) - (uint8_t *)DN_BONUS(dnp)) | |
34dc7c2f BB |
127 | |
128 | #define DN_USED_BYTES(dnp) (((dnp)->dn_flags & DNODE_FLAG_USED_BYTES) ? \ | |
129 | (dnp)->dn_used : (dnp)->dn_used << SPA_MINBLOCKSHIFT) | |
130 | ||
131 | #define EPB(blkshift, typeshift) (1 << (blkshift - typeshift)) | |
132 | ||
133 | struct dmu_buf_impl; | |
428870ff | 134 | struct objset; |
34dc7c2f BB |
135 | struct zio; |
136 | ||
137 | enum dnode_dirtycontext { | |
138 | DN_UNDIRTIED, | |
139 | DN_DIRTY_OPEN, | |
140 | DN_DIRTY_SYNC | |
141 | }; | |
142 | ||
143 | /* Is dn_used in bytes? if not, it's in multiples of SPA_MINBLOCKSIZE */ | |
1de321e6 JX |
144 | #define DNODE_FLAG_USED_BYTES (1 << 0) |
145 | #define DNODE_FLAG_USERUSED_ACCOUNTED (1 << 1) | |
34dc7c2f | 146 | |
428870ff | 147 | /* Does dnode have a SA spill blkptr in bonus? */ |
1de321e6 JX |
148 | #define DNODE_FLAG_SPILL_BLKPTR (1 << 2) |
149 | ||
9c5167d1 | 150 | /* User/Group/Project dnode accounting */ |
1de321e6 | 151 | #define DNODE_FLAG_USEROBJUSED_ACCOUNTED (1 << 3) |
428870ff | 152 | |
089fbf31 TC |
153 | /* |
154 | * This mask defines the set of flags which are "portable", meaning | |
155 | * that they can be preserved when doing a raw encrypted zfs send. | |
156 | * Flags included in this mask will be protected by AAD when the block | |
157 | * of dnodes is encrypted. | |
158 | */ | |
b5256303 TC |
159 | #define DNODE_CRYPT_PORTABLE_FLAGS_MASK (DNODE_FLAG_SPILL_BLKPTR) |
160 | ||
1e0457e7 MA |
161 | /* |
162 | * VARIABLE-LENGTH (LARGE) DNODES | |
163 | * | |
164 | * The motivation for variable-length dnodes is to eliminate the overhead | |
165 | * associated with using spill blocks. Spill blocks are used to store | |
166 | * system attribute data (i.e. file metadata) that does not fit in the | |
167 | * dnode's bonus buffer. By allowing a larger bonus buffer area the use of | |
168 | * a spill block can be avoided. Spill blocks potentially incur an | |
169 | * additional read I/O for every dnode in a dnode block. As a worst case | |
170 | * example, reading 32 dnodes from a 16k dnode block and all of the spill | |
171 | * blocks could issue 33 separate reads. Now suppose those dnodes have size | |
172 | * 1024 and therefore don't need spill blocks. Then the worst case number | |
173 | * of blocks read is reduced to from 33 to two--one per dnode block. | |
174 | * | |
175 | * ZFS-on-Linux systems that make heavy use of extended attributes benefit | |
176 | * from this feature. In particular, ZFS-on-Linux supports the xattr=sa | |
177 | * dataset property which allows file extended attribute data to be stored | |
178 | * in the dnode bonus buffer as an alternative to the traditional | |
179 | * directory-based format. Workloads such as SELinux and the Lustre | |
180 | * distributed filesystem often store enough xattr data to force spill | |
181 | * blocks when xattr=sa is in effect. Large dnodes may therefore provide a | |
182 | * performance benefit to such systems. Other use cases that benefit from | |
183 | * this feature include files with large ACLs and symbolic links with long | |
184 | * target names. | |
185 | * | |
186 | * The size of a dnode may be a multiple of 512 bytes up to the size of a | |
187 | * dnode block (currently 16384 bytes). The dn_extra_slots field of the | |
188 | * on-disk dnode_phys_t structure describes the size of the physical dnode | |
189 | * on disk. The field represents how many "extra" dnode_phys_t slots a | |
190 | * dnode consumes in its dnode block. This convention results in a value of | |
191 | * 0 for 512 byte dnodes which preserves on-disk format compatibility with | |
192 | * older software which doesn't support large dnodes. | |
193 | * | |
194 | * Similarly, the in-memory dnode_t structure has a dn_num_slots field | |
195 | * to represent the total number of dnode_phys_t slots consumed on disk. | |
196 | * Thus dn->dn_num_slots is 1 greater than the corresponding | |
197 | * dnp->dn_extra_slots. This difference in convention was adopted | |
198 | * because, unlike on-disk structures, backward compatibility is not a | |
199 | * concern for in-memory objects, so we used a more natural way to | |
200 | * represent size for a dnode_t. | |
201 | * | |
202 | * The default size for newly created dnodes is determined by the value of | |
203 | * the "dnodesize" dataset property. By default the property is set to | |
204 | * "legacy" which is compatible with older software. Setting the property | |
205 | * to "auto" will allow the filesystem to choose the most suitable dnode | |
206 | * size. Currently this just sets the default dnode size to 1k, but future | |
207 | * code improvements could dynamically choose a size based on observed | |
208 | * workload patterns. Dnodes of varying sizes can coexist within the same | |
209 | * dataset and even within the same dnode block. | |
210 | */ | |
211 | ||
34dc7c2f BB |
212 | typedef struct dnode_phys { |
213 | uint8_t dn_type; /* dmu_object_type_t */ | |
214 | uint8_t dn_indblkshift; /* ln2(indirect block size) */ | |
215 | uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */ | |
216 | uint8_t dn_nblkptr; /* length of dn_blkptr */ | |
217 | uint8_t dn_bonustype; /* type of data in bonus buffer */ | |
218 | uint8_t dn_checksum; /* ZIO_CHECKSUM type */ | |
219 | uint8_t dn_compress; /* ZIO_COMPRESS type */ | |
220 | uint8_t dn_flags; /* DNODE_FLAG_* */ | |
221 | uint16_t dn_datablkszsec; /* data block size in 512b sectors */ | |
222 | uint16_t dn_bonuslen; /* length of dn_bonus */ | |
50c957f7 NB |
223 | uint8_t dn_extra_slots; /* # of subsequent slots consumed */ |
224 | uint8_t dn_pad2[3]; | |
34dc7c2f BB |
225 | |
226 | /* accounting is protected by dn_dirty_mtx */ | |
227 | uint64_t dn_maxblkid; /* largest allocated block ID */ | |
228 | uint64_t dn_used; /* bytes (or sectors) of disk space */ | |
229 | ||
ae76f45c TC |
230 | /* |
231 | * Both dn_pad2 and dn_pad3 are protected by the block's MAC. This | |
232 | * allows us to protect any fields that might be added here in the | |
233 | * future. In either case, developers will want to check | |
234 | * zio_crypt_init_uios_dnode() to ensure the new field is being | |
235 | * protected properly. | |
236 | */ | |
34dc7c2f BB |
237 | uint64_t dn_pad3[4]; |
238 | ||
aca19e06 | 239 | /* |
50c957f7 NB |
240 | * The tail region is 448 bytes for a 512 byte dnode, and |
241 | * correspondingly larger for larger dnode sizes. The spill | |
242 | * block pointer, when present, is always at the end of the tail | |
243 | * region. There are three ways this space may be used, using | |
244 | * a 512 byte dnode for this diagram: | |
aca19e06 JE |
245 | * |
246 | * 0 64 128 192 256 320 384 448 (offset) | |
247 | * +---------------+---------------+---------------+-------+ | |
248 | * | dn_blkptr[0] | dn_blkptr[1] | dn_blkptr[2] | / | | |
249 | * +---------------+---------------+---------------+-------+ | |
250 | * | dn_blkptr[0] | dn_bonus[0..319] | | |
251 | * +---------------+-----------------------+---------------+ | |
50c957f7 | 252 | * | dn_blkptr[0] | dn_bonus[0..191] | dn_spill | |
aca19e06 JE |
253 | * +---------------+-----------------------+---------------+ |
254 | */ | |
255 | union { | |
50c957f7 | 256 | blkptr_t dn_blkptr[1+DN_OLD_MAX_BONUSLEN/sizeof (blkptr_t)]; |
aca19e06 JE |
257 | struct { |
258 | blkptr_t __dn_ignore1; | |
50c957f7 | 259 | uint8_t dn_bonus[DN_OLD_MAX_BONUSLEN]; |
aca19e06 JE |
260 | }; |
261 | struct { | |
262 | blkptr_t __dn_ignore2; | |
50c957f7 NB |
263 | uint8_t __dn_ignore3[DN_OLD_MAX_BONUSLEN - |
264 | sizeof (blkptr_t)]; | |
aca19e06 JE |
265 | blkptr_t dn_spill; |
266 | }; | |
267 | }; | |
34dc7c2f BB |
268 | } dnode_phys_t; |
269 | ||
50c957f7 NB |
270 | #define DN_SPILL_BLKPTR(dnp) (blkptr_t *)((char *)(dnp) + \ |
271 | (((dnp)->dn_extra_slots + 1) << DNODE_SHIFT) - (1 << SPA_BLKPTRSHIFT)) | |
272 | ||
2bce8049 | 273 | struct dnode { |
34dc7c2f | 274 | /* |
d3cc8b15 WA |
275 | * Protects the structure of the dnode, including the number of levels |
276 | * of indirection (dn_nlevels), dn_maxblkid, and dn_next_* | |
34dc7c2f BB |
277 | */ |
278 | krwlock_t dn_struct_rwlock; | |
279 | ||
9babb374 | 280 | /* Our link on dn_objset->os_dnodes list; protected by os_lock. */ |
34dc7c2f BB |
281 | list_node_t dn_link; |
282 | ||
283 | /* immutable: */ | |
428870ff | 284 | struct objset *dn_objset; |
34dc7c2f BB |
285 | uint64_t dn_object; |
286 | struct dmu_buf_impl *dn_dbuf; | |
572e2857 | 287 | struct dnode_handle *dn_handle; |
34dc7c2f BB |
288 | dnode_phys_t *dn_phys; /* pointer into dn->dn_dbuf->db.db_data */ |
289 | ||
290 | /* | |
291 | * Copies of stuff in dn_phys. They're valid in the open | |
292 | * context (eg. even before the dnode is first synced). | |
293 | * Where necessary, these are protected by dn_struct_rwlock. | |
294 | */ | |
295 | dmu_object_type_t dn_type; /* object type */ | |
296 | uint16_t dn_bonuslen; /* bonus length */ | |
297 | uint8_t dn_bonustype; /* bonus type */ | |
298 | uint8_t dn_nblkptr; /* number of blkptrs (immutable) */ | |
299 | uint8_t dn_checksum; /* ZIO_CHECKSUM type */ | |
300 | uint8_t dn_compress; /* ZIO_COMPRESS type */ | |
301 | uint8_t dn_nlevels; | |
302 | uint8_t dn_indblkshift; | |
303 | uint8_t dn_datablkshift; /* zero if blksz not power of 2! */ | |
572e2857 | 304 | uint8_t dn_moved; /* Has this dnode been moved? */ |
34dc7c2f BB |
305 | uint16_t dn_datablkszsec; /* in 512b sectors */ |
306 | uint32_t dn_datablksz; /* in bytes */ | |
307 | uint64_t dn_maxblkid; | |
fa86b5db | 308 | uint8_t dn_next_type[TXG_SIZE]; |
50c957f7 | 309 | uint8_t dn_num_slots; /* metadnode slots consumed on disk */ |
d164b209 | 310 | uint8_t dn_next_nblkptr[TXG_SIZE]; |
34dc7c2f BB |
311 | uint8_t dn_next_nlevels[TXG_SIZE]; |
312 | uint8_t dn_next_indblkshift[TXG_SIZE]; | |
428870ff BB |
313 | uint8_t dn_next_bonustype[TXG_SIZE]; |
314 | uint8_t dn_rm_spillblk[TXG_SIZE]; /* for removing spill blk */ | |
34dc7c2f BB |
315 | uint16_t dn_next_bonuslen[TXG_SIZE]; |
316 | uint32_t dn_next_blksz[TXG_SIZE]; /* next block size in bytes */ | |
ae76f45c | 317 | uint64_t dn_next_maxblkid[TXG_SIZE]; /* next maxblkid in bytes */ |
34dc7c2f | 318 | |
572e2857 BB |
319 | /* protected by dn_dbufs_mtx; declared here to fill 32-bit hole */ |
320 | uint32_t dn_dbufs_count; /* count of dn_dbufs */ | |
321 | ||
34dc7c2f | 322 | /* protected by os_lock: */ |
64fc7762 | 323 | multilist_node_t dn_dirty_link[TXG_SIZE]; /* next on dataset's dirty */ |
34dc7c2f BB |
324 | |
325 | /* protected by dn_mtx: */ | |
326 | kmutex_t dn_mtx; | |
327 | list_t dn_dirty_records[TXG_SIZE]; | |
9bd274dd | 328 | struct range_tree *dn_free_ranges[TXG_SIZE]; |
34dc7c2f BB |
329 | uint64_t dn_allocated_txg; |
330 | uint64_t dn_free_txg; | |
331 | uint64_t dn_assigned_txg; | |
edc1e713 | 332 | uint64_t dn_dirty_txg; /* txg dnode was last dirtied */ |
34dc7c2f BB |
333 | kcondvar_t dn_notxholds; |
334 | enum dnode_dirtycontext dn_dirtyctx; | |
335 | uint8_t *dn_dirtyctx_firstset; /* dbg: contents meaningless */ | |
336 | ||
337 | /* protected by own devices */ | |
c13060e4 TS |
338 | zfs_refcount_t dn_tx_holds; |
339 | zfs_refcount_t dn_holds; | |
34dc7c2f BB |
340 | |
341 | kmutex_t dn_dbufs_mtx; | |
9925c28c AR |
342 | /* |
343 | * Descendent dbufs, ordered by dbuf_compare. Note that dn_dbufs | |
344 | * can contain multiple dbufs of the same (level, blkid) when a | |
345 | * dbuf is marked DB_EVICTING without being removed from | |
346 | * dn_dbufs. To maintain the avl invariant that there cannot be | |
347 | * duplicate entries, we order the dbufs by an arbitrary value - | |
348 | * their address in memory. This means that dn_dbufs cannot be used to | |
349 | * directly look up a dbuf. Instead, callers must use avl_walk, have | |
4e33ba4c | 350 | * a reference to the dbuf, or look up a non-existent node with |
9925c28c AR |
351 | * db_state = DB_SEARCH (see dbuf_free_range for an example). |
352 | */ | |
353 | avl_tree_t dn_dbufs; | |
572e2857 BB |
354 | |
355 | /* protected by dn_struct_rwlock */ | |
34dc7c2f | 356 | struct dmu_buf_impl *dn_bonus; /* bonus buffer dbuf */ |
572e2857 | 357 | |
428870ff | 358 | boolean_t dn_have_spill; /* have spill or are spilling */ |
34dc7c2f BB |
359 | |
360 | /* parent IO for current sync write */ | |
361 | zio_t *dn_zio; | |
362 | ||
9babb374 | 363 | /* used in syncing context */ |
428870ff BB |
364 | uint64_t dn_oldused; /* old phys used bytes */ |
365 | uint64_t dn_oldflags; /* old phys dn_flags */ | |
9c5167d1 NF |
366 | uint64_t dn_olduid, dn_oldgid, dn_oldprojid; |
367 | uint64_t dn_newuid, dn_newgid, dn_newprojid; | |
428870ff | 368 | int dn_id_flags; |
9babb374 | 369 | |
34dc7c2f BB |
370 | /* holds prefetch structure */ |
371 | struct zfetch dn_zfetch; | |
2bce8049 | 372 | }; |
34dc7c2f | 373 | |
572e2857 BB |
374 | /* |
375 | * Adds a level of indirection between the dbuf and the dnode to avoid | |
376 | * iterating descendent dbufs in dnode_move(). Handles are not allocated | |
377 | * individually, but as an array of child dnodes in dnode_hold_impl(). | |
378 | */ | |
379 | typedef struct dnode_handle { | |
380 | /* Protects dnh_dnode from modification by dnode_move(). */ | |
381 | zrlock_t dnh_zrlock; | |
382 | dnode_t *dnh_dnode; | |
383 | } dnode_handle_t; | |
384 | ||
385 | typedef struct dnode_children { | |
0c66c32d | 386 | dmu_buf_user_t dnc_dbu; /* User evict data */ |
572e2857 | 387 | size_t dnc_count; /* number of children */ |
5aea3644 | 388 | dnode_handle_t dnc_children[]; /* sized dynamically */ |
572e2857 BB |
389 | } dnode_children_t; |
390 | ||
34dc7c2f BB |
391 | typedef struct free_range { |
392 | avl_node_t fr_node; | |
393 | uint64_t fr_blkid; | |
394 | uint64_t fr_nblks; | |
395 | } free_range_t; | |
396 | ||
0c66c32d | 397 | void dnode_special_open(struct objset *dd, dnode_phys_t *dnp, |
572e2857 BB |
398 | uint64_t object, dnode_handle_t *dnh); |
399 | void dnode_special_close(dnode_handle_t *dnh); | |
34dc7c2f BB |
400 | |
401 | void dnode_setbonuslen(dnode_t *dn, int newsize, dmu_tx_t *tx); | |
428870ff BB |
402 | void dnode_setbonus_type(dnode_t *dn, dmu_object_type_t, dmu_tx_t *tx); |
403 | void dnode_rm_spill(dnode_t *dn, dmu_tx_t *tx); | |
404 | ||
405 | int dnode_hold(struct objset *dd, uint64_t object, | |
34dc7c2f | 406 | void *ref, dnode_t **dnp); |
50c957f7 | 407 | int dnode_hold_impl(struct objset *dd, uint64_t object, int flag, int dn_slots, |
34dc7c2f BB |
408 | void *ref, dnode_t **dnp); |
409 | boolean_t dnode_add_ref(dnode_t *dn, void *ref); | |
410 | void dnode_rele(dnode_t *dn, void *ref); | |
3d503a76 | 411 | void dnode_rele_and_unlock(dnode_t *dn, void *tag, boolean_t evicting); |
34dc7c2f BB |
412 | void dnode_setdirty(dnode_t *dn, dmu_tx_t *tx); |
413 | void dnode_sync(dnode_t *dn, dmu_tx_t *tx); | |
414 | void dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs, | |
50c957f7 | 415 | dmu_object_type_t bonustype, int bonuslen, int dn_slots, dmu_tx_t *tx); |
34dc7c2f | 416 | void dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, |
50c957f7 | 417 | dmu_object_type_t bonustype, int bonuslen, int dn_slots, dmu_tx_t *tx); |
34dc7c2f BB |
418 | void dnode_free(dnode_t *dn, dmu_tx_t *tx); |
419 | void dnode_byteswap(dnode_phys_t *dnp); | |
420 | void dnode_buf_byteswap(void *buf, size_t size); | |
421 | void dnode_verify(dnode_t *dn); | |
b5256303 | 422 | int dnode_set_nlevels(dnode_t *dn, int nlevels, dmu_tx_t *tx); |
34dc7c2f | 423 | int dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx); |
34dc7c2f | 424 | void dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx); |
34dc7c2f | 425 | void dnode_diduse_space(dnode_t *dn, int64_t space); |
b128c09f | 426 | void dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t); |
34dc7c2f BB |
427 | uint64_t dnode_block_freed(dnode_t *dn, uint64_t blkid); |
428 | void dnode_init(void); | |
429 | void dnode_fini(void); | |
b128c09f BB |
430 | int dnode_next_offset(dnode_t *dn, int flags, uint64_t *off, |
431 | int minlvl, uint64_t blkfill, uint64_t txg); | |
34dc7c2f | 432 | void dnode_evict_dbufs(dnode_t *dn); |
4c7b7eed | 433 | void dnode_evict_bonus(dnode_t *dn); |
047116ac | 434 | void dnode_free_interior_slots(dnode_t *dn); |
a1d477c2 | 435 | boolean_t dnode_needs_remap(const dnode_t *dn); |
34dc7c2f | 436 | |
edc1e713 TC |
437 | #define DNODE_IS_DIRTY(_dn) \ |
438 | ((_dn)->dn_dirty_txg >= spa_syncing_txg((_dn)->dn_objset->os_spa)) | |
439 | ||
755065f3 AM |
440 | #define DNODE_IS_CACHEABLE(_dn) \ |
441 | ((_dn)->dn_objset->os_primary_cache == ZFS_CACHE_ALL || \ | |
442 | (DMU_OT_IS_METADATA((_dn)->dn_type) && \ | |
443 | (_dn)->dn_objset->os_primary_cache == ZFS_CACHE_METADATA)) | |
444 | ||
445 | #define DNODE_META_IS_CACHEABLE(_dn) \ | |
446 | ((_dn)->dn_objset->os_primary_cache == ZFS_CACHE_ALL || \ | |
447 | (_dn)->dn_objset->os_primary_cache == ZFS_CACHE_METADATA) | |
448 | ||
4c5b89f5 OF |
449 | /* |
450 | * Used for dnodestats kstat. | |
451 | */ | |
452 | typedef struct dnode_stats { | |
453 | /* | |
454 | * Number of failed attempts to hold a meta dnode dbuf. | |
455 | */ | |
456 | kstat_named_t dnode_hold_dbuf_hold; | |
457 | /* | |
458 | * Number of failed attempts to read a meta dnode dbuf. | |
459 | */ | |
460 | kstat_named_t dnode_hold_dbuf_read; | |
461 | /* | |
462 | * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) was able | |
463 | * to hold the requested object number which was allocated. This is | |
464 | * the common case when looking up any allocated object number. | |
465 | */ | |
466 | kstat_named_t dnode_hold_alloc_hits; | |
467 | /* | |
468 | * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) was not | |
469 | * able to hold the request object number because it was not allocated. | |
470 | */ | |
471 | kstat_named_t dnode_hold_alloc_misses; | |
472 | /* | |
473 | * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) was not | |
474 | * able to hold the request object number because the object number | |
475 | * refers to an interior large dnode slot. | |
476 | */ | |
477 | kstat_named_t dnode_hold_alloc_interior; | |
478 | /* | |
479 | * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) needed | |
480 | * to retry acquiring slot zrl locks due to contention. | |
481 | */ | |
482 | kstat_named_t dnode_hold_alloc_lock_retry; | |
483 | /* | |
484 | * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) did not | |
485 | * need to create the dnode because another thread did so after | |
486 | * dropping the read lock but before acquiring the write lock. | |
487 | */ | |
488 | kstat_named_t dnode_hold_alloc_lock_misses; | |
489 | /* | |
490 | * Number of times dnode_hold(..., DNODE_MUST_BE_ALLOCATED) found | |
491 | * a free dnode instantiated by dnode_create() but not yet allocated | |
492 | * by dnode_allocate(). | |
493 | */ | |
494 | kstat_named_t dnode_hold_alloc_type_none; | |
495 | /* | |
496 | * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) was able | |
497 | * to hold the requested range of free dnode slots. | |
498 | */ | |
499 | kstat_named_t dnode_hold_free_hits; | |
500 | /* | |
501 | * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) was not | |
502 | * able to hold the requested range of free dnode slots because | |
503 | * at least one slot was allocated. | |
504 | */ | |
505 | kstat_named_t dnode_hold_free_misses; | |
506 | /* | |
507 | * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) was not | |
508 | * able to hold the requested range of free dnode slots because | |
509 | * after acquiring the zrl lock at least one slot was allocated. | |
510 | */ | |
511 | kstat_named_t dnode_hold_free_lock_misses; | |
512 | /* | |
513 | * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) needed | |
514 | * to retry acquiring slot zrl locks due to contention. | |
515 | */ | |
516 | kstat_named_t dnode_hold_free_lock_retry; | |
517 | /* | |
518 | * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) requested | |
519 | * a range of dnode slots which were held by another thread. | |
520 | */ | |
521 | kstat_named_t dnode_hold_free_refcount; | |
522 | /* | |
523 | * Number of times dnode_hold(..., DNODE_MUST_BE_FREE) requested | |
524 | * a range of dnode slots which would overflow the dnode_phys_t. | |
525 | */ | |
526 | kstat_named_t dnode_hold_free_overflow; | |
527 | /* | |
528 | * Number of times a dnode_hold(...) was attempted on a dnode | |
529 | * which had already been unlinked in an earlier txg. | |
530 | */ | |
531 | kstat_named_t dnode_hold_free_txg; | |
047116ac TC |
532 | /* |
533 | * Number of times dnode_free_interior_slots() needed to retry | |
534 | * acquiring a slot zrl lock due to contention. | |
535 | */ | |
536 | kstat_named_t dnode_free_interior_lock_retry; | |
4c5b89f5 OF |
537 | /* |
538 | * Number of new dnodes allocated by dnode_allocate(). | |
539 | */ | |
540 | kstat_named_t dnode_allocate; | |
541 | /* | |
542 | * Number of dnodes re-allocated by dnode_reallocate(). | |
543 | */ | |
544 | kstat_named_t dnode_reallocate; | |
545 | /* | |
546 | * Number of meta dnode dbufs evicted. | |
547 | */ | |
548 | kstat_named_t dnode_buf_evict; | |
549 | /* | |
550 | * Number of times dmu_object_alloc*() reached the end of the existing | |
551 | * object ID chunk and advanced to a new one. | |
552 | */ | |
553 | kstat_named_t dnode_alloc_next_chunk; | |
554 | /* | |
555 | * Number of times multiple threads attempted to allocate a dnode | |
556 | * from the same block of free dnodes. | |
557 | */ | |
558 | kstat_named_t dnode_alloc_race; | |
559 | /* | |
560 | * Number of times dmu_object_alloc*() was forced to advance to the | |
561 | * next meta dnode dbuf due to an error from dmu_object_next(). | |
562 | */ | |
563 | kstat_named_t dnode_alloc_next_block; | |
564 | /* | |
565 | * Statistics for tracking dnodes which have been moved. | |
566 | */ | |
567 | kstat_named_t dnode_move_invalid; | |
568 | kstat_named_t dnode_move_recheck1; | |
569 | kstat_named_t dnode_move_recheck2; | |
570 | kstat_named_t dnode_move_special; | |
571 | kstat_named_t dnode_move_handle; | |
572 | kstat_named_t dnode_move_rwlock; | |
573 | kstat_named_t dnode_move_active; | |
574 | } dnode_stats_t; | |
575 | ||
576 | extern dnode_stats_t dnode_stats; | |
577 | ||
578 | #define DNODE_STAT_INCR(stat, val) \ | |
579 | atomic_add_64(&dnode_stats.stat.value.ui64, (val)); | |
580 | #define DNODE_STAT_BUMP(stat) \ | |
581 | DNODE_STAT_INCR(stat, 1); | |
582 | ||
34dc7c2f BB |
583 | #ifdef ZFS_DEBUG |
584 | ||
585 | /* | |
586 | * There should be a ## between the string literal and fmt, to make it | |
587 | * clear that we're joining two strings together, but that piece of shit | |
588 | * gcc doesn't support that preprocessor token. | |
589 | */ | |
590 | #define dprintf_dnode(dn, fmt, ...) do { \ | |
591 | if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ | |
592 | char __db_buf[32]; \ | |
593 | uint64_t __db_obj = (dn)->dn_object; \ | |
594 | if (__db_obj == DMU_META_DNODE_OBJECT) \ | |
595 | (void) strcpy(__db_buf, "mdn"); \ | |
596 | else \ | |
597 | (void) snprintf(__db_buf, sizeof (__db_buf), "%lld", \ | |
598 | (u_longlong_t)__db_obj);\ | |
599 | dprintf_ds((dn)->dn_objset->os_dsl_dataset, "obj=%s " fmt, \ | |
600 | __db_buf, __VA_ARGS__); \ | |
601 | } \ | |
602 | _NOTE(CONSTCOND) } while (0) | |
603 | ||
604 | #define DNODE_VERIFY(dn) dnode_verify(dn) | |
605 | #define FREE_VERIFY(db, start, end, tx) free_verify(db, start, end, tx) | |
606 | ||
607 | #else | |
608 | ||
609 | #define dprintf_dnode(db, fmt, ...) | |
610 | #define DNODE_VERIFY(dn) | |
611 | #define FREE_VERIFY(db, start, end, tx) | |
612 | ||
613 | #endif | |
614 | ||
615 | #ifdef __cplusplus | |
616 | } | |
617 | #endif | |
618 | ||
619 | #endif /* _SYS_DNODE_H */ |