Print this page
3742 zfs comments need cleaner, more consistent style
Submitted by: Will Andrews <willa@spectralogic.com>
Submitted by: Alan Somers <alans@spectralogic.com>
Reviewed by: Matthew Ahrens <mahrens@delphix.com>
Reviewed by: George Wilson <george.wilson@delphix.com>
Reviewed by: Eric Schrock <eric.schrock@delphix.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/sys/dnode.h
+++ new/usr/src/uts/common/fs/zfs/sys/dnode.h
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 23 * Copyright (c) 2012 by Delphix. All rights reserved.
24 24 */
25 25
26 26 #ifndef _SYS_DNODE_H
27 27 #define _SYS_DNODE_H
28 28
29 29 #include <sys/zfs_context.h>
30 30 #include <sys/avl.h>
31 31 #include <sys/spa.h>
32 32 #include <sys/txg.h>
33 33 #include <sys/zio.h>
34 34 #include <sys/refcount.h>
35 35 #include <sys/dmu_zfetch.h>
36 36 #include <sys/zrlock.h>
37 37
38 38 #ifdef __cplusplus
39 39 extern "C" {
40 40 #endif
41 41
42 42 /*
43 43 * dnode_hold() flags.
44 44 */
45 45 #define DNODE_MUST_BE_ALLOCATED 1
46 46 #define DNODE_MUST_BE_FREE 2
47 47
48 48 /*
49 49 * dnode_next_offset() flags.
50 50 */
51 51 #define DNODE_FIND_HOLE 1
52 52 #define DNODE_FIND_BACKWARDS 2
53 53 #define DNODE_FIND_HAVELOCK 4
54 54
55 55 /*
56 56 * Fixed constants.
57 57 */
58 58 #define DNODE_SHIFT 9 /* 512 bytes */
59 59 #define DN_MIN_INDBLKSHIFT 10 /* 1k */
60 60 #define DN_MAX_INDBLKSHIFT 14 /* 16k */
61 61 #define DNODE_BLOCK_SHIFT 14 /* 16k */
62 62 #define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */
63 63 #define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */
64 64 #define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */
65 65
66 66 /*
67 67 * dnode id flags
68 68 *
69 69 * Note: a file will never ever have its
70 70 * ids moved from bonus->spill
71 71 * and only in a crypto environment would it be on spill
72 72 */
73 73 #define DN_ID_CHKED_BONUS 0x1
74 74 #define DN_ID_CHKED_SPILL 0x2
75 75 #define DN_ID_OLD_EXIST 0x4
76 76 #define DN_ID_NEW_EXIST 0x8
77 77
78 78 /*
79 79 * Derived constants.
80 80 */
81 81 #define DNODE_SIZE (1 << DNODE_SHIFT)
82 82 #define DN_MAX_NBLKPTR ((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
83 83 #define DN_MAX_BONUSLEN (DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT))
84 84 #define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT)
85 85 #define DN_ZERO_BONUSLEN (DN_MAX_BONUSLEN + 1)
86 86 #define DN_KILL_SPILLBLK (1)
87 87
88 88 #define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT)
89 89 #define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT)
90 90 #define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT)
91 91 #define DNODES_PER_LEVEL (1ULL << DNODES_PER_LEVEL_SHIFT)
92 92
93 93 /* The +2 here is a cheesy way to round up */
94 94 #define DN_MAX_LEVELS (2 + ((DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT) / \
95 95 (DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT)))
96 96
97 97 #define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \
98 98 (((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t))))
99 99
100 100 #define DN_USED_BYTES(dnp) (((dnp)->dn_flags & DNODE_FLAG_USED_BYTES) ? \
101 101 (dnp)->dn_used : (dnp)->dn_used << SPA_MINBLOCKSHIFT)
102 102
103 103 #define EPB(blkshift, typeshift) (1 << (blkshift - typeshift))
104 104
105 105 struct dmu_buf_impl;
106 106 struct objset;
107 107 struct zio;
108 108
109 109 enum dnode_dirtycontext {
110 110 DN_UNDIRTIED,
111 111 DN_DIRTY_OPEN,
112 112 DN_DIRTY_SYNC
113 113 };
114 114
115 115 /* Is dn_used in bytes? if not, it's in multiples of SPA_MINBLOCKSIZE */
116 116 #define DNODE_FLAG_USED_BYTES (1<<0)
117 117 #define DNODE_FLAG_USERUSED_ACCOUNTED (1<<1)
118 118
119 119 /* Does dnode have a SA spill blkptr in bonus? */
120 120 #define DNODE_FLAG_SPILL_BLKPTR (1<<2)
121 121
122 122 typedef struct dnode_phys {
123 123 uint8_t dn_type; /* dmu_object_type_t */
124 124 uint8_t dn_indblkshift; /* ln2(indirect block size) */
125 125 uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */
126 126 uint8_t dn_nblkptr; /* length of dn_blkptr */
127 127 uint8_t dn_bonustype; /* type of data in bonus buffer */
128 128 uint8_t dn_checksum; /* ZIO_CHECKSUM type */
129 129 uint8_t dn_compress; /* ZIO_COMPRESS type */
130 130 uint8_t dn_flags; /* DNODE_FLAG_* */
131 131 uint16_t dn_datablkszsec; /* data block size in 512b sectors */
132 132 uint16_t dn_bonuslen; /* length of dn_bonus */
133 133 uint8_t dn_pad2[4];
134 134
135 135 /* accounting is protected by dn_dirty_mtx */
136 136 uint64_t dn_maxblkid; /* largest allocated block ID */
137 137 uint64_t dn_used; /* bytes (or sectors) of disk space */
↓ open down ↓ |
137 lines elided |
↑ open up ↑ |
138 138
139 139 uint64_t dn_pad3[4];
140 140
141 141 blkptr_t dn_blkptr[1];
142 142 uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof (blkptr_t)];
143 143 blkptr_t dn_spill;
144 144 } dnode_phys_t;
145 145
146 146 typedef struct dnode {
147 147 /*
148 - * dn_struct_rwlock protects the structure of the dnode,
149 - * including the number of levels of indirection (dn_nlevels),
150 - * dn_maxblkid, and dn_next_*
148 + * Protects the structure of the dnode, including the number of levels
149 + * of indirection (dn_nlevels), dn_maxblkid, and dn_next_*
151 150 */
152 151 krwlock_t dn_struct_rwlock;
153 152
154 153 /* Our link on dn_objset->os_dnodes list; protected by os_lock. */
155 154 list_node_t dn_link;
156 155
157 156 /* immutable: */
158 157 struct objset *dn_objset;
159 158 uint64_t dn_object;
160 159 struct dmu_buf_impl *dn_dbuf;
161 160 struct dnode_handle *dn_handle;
162 161 dnode_phys_t *dn_phys; /* pointer into dn->dn_dbuf->db.db_data */
163 162
164 163 /*
165 164 * Copies of stuff in dn_phys. They're valid in the open
166 165 * context (eg. even before the dnode is first synced).
167 166 * Where necessary, these are protected by dn_struct_rwlock.
168 167 */
169 168 dmu_object_type_t dn_type; /* object type */
170 169 uint16_t dn_bonuslen; /* bonus length */
171 170 uint8_t dn_bonustype; /* bonus type */
172 171 uint8_t dn_nblkptr; /* number of blkptrs (immutable) */
173 172 uint8_t dn_checksum; /* ZIO_CHECKSUM type */
174 173 uint8_t dn_compress; /* ZIO_COMPRESS type */
175 174 uint8_t dn_nlevels;
176 175 uint8_t dn_indblkshift;
177 176 uint8_t dn_datablkshift; /* zero if blksz not power of 2! */
178 177 uint8_t dn_moved; /* Has this dnode been moved? */
179 178 uint16_t dn_datablkszsec; /* in 512b sectors */
180 179 uint32_t dn_datablksz; /* in bytes */
181 180 uint64_t dn_maxblkid;
182 181 uint8_t dn_next_nblkptr[TXG_SIZE];
183 182 uint8_t dn_next_nlevels[TXG_SIZE];
184 183 uint8_t dn_next_indblkshift[TXG_SIZE];
185 184 uint8_t dn_next_bonustype[TXG_SIZE];
186 185 uint8_t dn_rm_spillblk[TXG_SIZE]; /* for removing spill blk */
187 186 uint16_t dn_next_bonuslen[TXG_SIZE];
188 187 uint32_t dn_next_blksz[TXG_SIZE]; /* next block size in bytes */
189 188
190 189 /* protected by dn_dbufs_mtx; declared here to fill 32-bit hole */
191 190 uint32_t dn_dbufs_count; /* count of dn_dbufs */
192 191
193 192 /* protected by os_lock: */
194 193 list_node_t dn_dirty_link[TXG_SIZE]; /* next on dataset's dirty */
195 194
196 195 /* protected by dn_mtx: */
197 196 kmutex_t dn_mtx;
198 197 list_t dn_dirty_records[TXG_SIZE];
199 198 avl_tree_t dn_ranges[TXG_SIZE];
200 199 uint64_t dn_allocated_txg;
201 200 uint64_t dn_free_txg;
202 201 uint64_t dn_assigned_txg;
203 202 kcondvar_t dn_notxholds;
204 203 enum dnode_dirtycontext dn_dirtyctx;
205 204 uint8_t *dn_dirtyctx_firstset; /* dbg: contents meaningless */
206 205
207 206 /* protected by own devices */
208 207 refcount_t dn_tx_holds;
209 208 refcount_t dn_holds;
210 209
211 210 kmutex_t dn_dbufs_mtx;
212 211 list_t dn_dbufs; /* descendent dbufs */
213 212
214 213 /* protected by dn_struct_rwlock */
215 214 struct dmu_buf_impl *dn_bonus; /* bonus buffer dbuf */
216 215
217 216 boolean_t dn_have_spill; /* have spill or are spilling */
218 217
219 218 /* parent IO for current sync write */
220 219 zio_t *dn_zio;
221 220
222 221 /* used in syncing context */
223 222 uint64_t dn_oldused; /* old phys used bytes */
224 223 uint64_t dn_oldflags; /* old phys dn_flags */
225 224 uint64_t dn_olduid, dn_oldgid;
226 225 uint64_t dn_newuid, dn_newgid;
227 226 int dn_id_flags;
228 227
229 228 /* holds prefetch structure */
230 229 struct zfetch dn_zfetch;
231 230 } dnode_t;
232 231
233 232 /*
234 233 * Adds a level of indirection between the dbuf and the dnode to avoid
235 234 * iterating descendent dbufs in dnode_move(). Handles are not allocated
236 235 * individually, but as an array of child dnodes in dnode_hold_impl().
237 236 */
238 237 typedef struct dnode_handle {
239 238 /* Protects dnh_dnode from modification by dnode_move(). */
240 239 zrlock_t dnh_zrlock;
241 240 dnode_t *dnh_dnode;
242 241 } dnode_handle_t;
243 242
244 243 typedef struct dnode_children {
245 244 size_t dnc_count; /* number of children */
246 245 dnode_handle_t dnc_children[1]; /* sized dynamically */
247 246 } dnode_children_t;
248 247
249 248 typedef struct free_range {
250 249 avl_node_t fr_node;
251 250 uint64_t fr_blkid;
252 251 uint64_t fr_nblks;
253 252 } free_range_t;
254 253
255 254 dnode_t *dnode_special_open(struct objset *dd, dnode_phys_t *dnp,
256 255 uint64_t object, dnode_handle_t *dnh);
257 256 void dnode_special_close(dnode_handle_t *dnh);
258 257
259 258 void dnode_setbonuslen(dnode_t *dn, int newsize, dmu_tx_t *tx);
260 259 void dnode_setbonus_type(dnode_t *dn, dmu_object_type_t, dmu_tx_t *tx);
261 260 void dnode_rm_spill(dnode_t *dn, dmu_tx_t *tx);
262 261
263 262 int dnode_hold(struct objset *dd, uint64_t object,
264 263 void *ref, dnode_t **dnp);
265 264 int dnode_hold_impl(struct objset *dd, uint64_t object, int flag,
266 265 void *ref, dnode_t **dnp);
267 266 boolean_t dnode_add_ref(dnode_t *dn, void *ref);
268 267 void dnode_rele(dnode_t *dn, void *ref);
269 268 void dnode_setdirty(dnode_t *dn, dmu_tx_t *tx);
270 269 void dnode_sync(dnode_t *dn, dmu_tx_t *tx);
271 270 void dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs,
272 271 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
273 272 void dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
274 273 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
275 274 void dnode_free(dnode_t *dn, dmu_tx_t *tx);
276 275 void dnode_byteswap(dnode_phys_t *dnp);
277 276 void dnode_buf_byteswap(void *buf, size_t size);
278 277 void dnode_verify(dnode_t *dn);
279 278 int dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx);
280 279 void dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx);
281 280 void dnode_clear_range(dnode_t *dn, uint64_t blkid,
282 281 uint64_t nblks, dmu_tx_t *tx);
283 282 void dnode_diduse_space(dnode_t *dn, int64_t space);
284 283 void dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx);
285 284 void dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t);
286 285 uint64_t dnode_block_freed(dnode_t *dn, uint64_t blkid);
287 286 void dnode_init(void);
288 287 void dnode_fini(void);
289 288 int dnode_next_offset(dnode_t *dn, int flags, uint64_t *off,
290 289 int minlvl, uint64_t blkfill, uint64_t txg);
291 290 void dnode_evict_dbufs(dnode_t *dn);
292 291
293 292 #ifdef ZFS_DEBUG
294 293
295 294 /*
296 295 * There should be a ## between the string literal and fmt, to make it
297 296 * clear that we're joining two strings together, but that piece of shit
298 297 * gcc doesn't support that preprocessor token.
299 298 */
300 299 #define dprintf_dnode(dn, fmt, ...) do { \
301 300 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
302 301 char __db_buf[32]; \
303 302 uint64_t __db_obj = (dn)->dn_object; \
304 303 if (__db_obj == DMU_META_DNODE_OBJECT) \
305 304 (void) strcpy(__db_buf, "mdn"); \
306 305 else \
307 306 (void) snprintf(__db_buf, sizeof (__db_buf), "%lld", \
308 307 (u_longlong_t)__db_obj);\
309 308 dprintf_ds((dn)->dn_objset->os_dsl_dataset, "obj=%s " fmt, \
310 309 __db_buf, __VA_ARGS__); \
311 310 } \
312 311 _NOTE(CONSTCOND) } while (0)
313 312
314 313 #define DNODE_VERIFY(dn) dnode_verify(dn)
315 314 #define FREE_VERIFY(db, start, end, tx) free_verify(db, start, end, tx)
316 315
317 316 #else
318 317
319 318 #define dprintf_dnode(db, fmt, ...)
320 319 #define DNODE_VERIFY(dn)
321 320 #define FREE_VERIFY(db, start, end, tx)
322 321
323 322 #endif
324 323
325 324 #ifdef __cplusplus
326 325 }
327 326 #endif
328 327
329 328 #endif /* _SYS_DNODE_H */
↓ open down ↓ |
169 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX