xref: /illumos-gate/usr/src/uts/common/fs/zfs/sys/dnode.h (revision 5cabbc6b49070407fb9610cfe73d4c0e0dea3e77)
1fa9e4066Sahrens /*
2fa9e4066Sahrens  * CDDL HEADER START
3fa9e4066Sahrens  *
4fa9e4066Sahrens  * The contents of this file are subject to the terms of the
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
7fa9e4066Sahrens  *
8fa9e4066Sahrens  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9fa9e4066Sahrens  * or http://www.opensolaris.org/os/licensing.
10fa9e4066Sahrens  * See the License for the specific language governing permissions
11fa9e4066Sahrens  * and limitations under the License.
12fa9e4066Sahrens  *
13fa9e4066Sahrens  * When distributing Covered Code, include this CDDL HEADER in each
14fa9e4066Sahrens  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fa9e4066Sahrens  * If applicable, add the following below this CDDL HEADER, with the
16fa9e4066Sahrens  * fields enclosed by brackets "[]" replaced with your own identifying
17fa9e4066Sahrens  * information: Portions Copyright [yyyy] [name of copyright owner]
18fa9e4066Sahrens  *
19fa9e4066Sahrens  * CDDL HEADER END
20fa9e4066Sahrens  */
21fa9e4066Sahrens /*
2228d97a71SMark Shellenbaum  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
2394c2d0ebSMatthew Ahrens  * Copyright (c) 2012, 2017 by Delphix. All rights reserved.
24bc9014e6SJustin Gibbs  * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
25fa9e4066Sahrens  */
26fa9e4066Sahrens 
27fa9e4066Sahrens #ifndef	_SYS_DNODE_H
28fa9e4066Sahrens #define	_SYS_DNODE_H
29fa9e4066Sahrens 
30fa9e4066Sahrens #include <sys/zfs_context.h>
31fa9e4066Sahrens #include <sys/avl.h>
32fa9e4066Sahrens #include <sys/spa.h>
33fa9e4066Sahrens #include <sys/txg.h>
34c717a561Smaybee #include <sys/zio.h>
35fa9e4066Sahrens #include <sys/refcount.h>
36fa9e4066Sahrens #include <sys/dmu_zfetch.h>
37744947dcSTom Erickson #include <sys/zrlock.h>
3894c2d0ebSMatthew Ahrens #include <sys/multilist.h>
39fa9e4066Sahrens 
40fa9e4066Sahrens #ifdef	__cplusplus
41fa9e4066Sahrens extern "C" {
42fa9e4066Sahrens #endif
43fa9e4066Sahrens 
44fa9e4066Sahrens /*
45cdb0ab79Smaybee  * dnode_hold() flags.
46fa9e4066Sahrens  */
47fa9e4066Sahrens #define	DNODE_MUST_BE_ALLOCATED	1
48fa9e4066Sahrens #define	DNODE_MUST_BE_FREE	2
49fa9e4066Sahrens 
50cdb0ab79Smaybee /*
51cdb0ab79Smaybee  * dnode_next_offset() flags.
52cdb0ab79Smaybee  */
53cdb0ab79Smaybee #define	DNODE_FIND_HOLE		1
54cdb0ab79Smaybee #define	DNODE_FIND_BACKWARDS	2
55cdb0ab79Smaybee #define	DNODE_FIND_HAVELOCK	4
56cdb0ab79Smaybee 
57fa9e4066Sahrens /*
58fa9e4066Sahrens  * Fixed constants.
59fa9e4066Sahrens  */
60fa9e4066Sahrens #define	DNODE_SHIFT		9	/* 512 bytes */
61e94f268aSMatthew Ahrens #define	DN_MIN_INDBLKSHIFT	12	/* 4k */
627de35a3eSPaul Dagnelie /*
637de35a3eSPaul Dagnelie  * If we ever increase this value beyond 20, we need to revisit all logic that
647de35a3eSPaul Dagnelie  * does x << level * ebps to handle overflow.  With a 1M indirect block size,
657de35a3eSPaul Dagnelie  * 4 levels of indirect blocks would not be able to guarantee addressing an
667de35a3eSPaul Dagnelie  * entire object, so 5 levels will be used, but 5 * (20 - 7) = 65.
677de35a3eSPaul Dagnelie  */
684b5c8e93SMatthew Ahrens #define	DN_MAX_INDBLKSHIFT	17	/* 128k */
69fa9e4066Sahrens #define	DNODE_BLOCK_SHIFT	14	/* 16k */
70fa9e4066Sahrens #define	DNODE_CORE_SIZE		64	/* 64 bytes for dnode sans blkptrs */
71fa9e4066Sahrens #define	DN_MAX_OBJECT_SHIFT	48	/* 256 trillion (zfs_fid_t limit) */
72fa9e4066Sahrens #define	DN_MAX_OFFSET_SHIFT	64	/* 2^64 bytes in a dnode */
73fa9e4066Sahrens 
740a586ceaSMark Shellenbaum /*
750a586ceaSMark Shellenbaum  * dnode id flags
760a586ceaSMark Shellenbaum  *
770a586ceaSMark Shellenbaum  * Note: a file will never ever have its
780a586ceaSMark Shellenbaum  * ids moved from bonus->spill
790a586ceaSMark Shellenbaum  * and only in a crypto environment would it be on spill
800a586ceaSMark Shellenbaum  */
810a586ceaSMark Shellenbaum #define	DN_ID_CHKED_BONUS	0x1
820a586ceaSMark Shellenbaum #define	DN_ID_CHKED_SPILL	0x2
830a586ceaSMark Shellenbaum #define	DN_ID_OLD_EXIST		0x4
840a586ceaSMark Shellenbaum #define	DN_ID_NEW_EXIST		0x8
850a586ceaSMark Shellenbaum 
86fa9e4066Sahrens /*
87fa9e4066Sahrens  * Derived constants.
88fa9e4066Sahrens  */
89fa9e4066Sahrens #define	DNODE_SIZE	(1 << DNODE_SHIFT)
90fa9e4066Sahrens #define	DN_MAX_NBLKPTR	((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
91fa9e4066Sahrens #define	DN_MAX_BONUSLEN	(DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT))
92ea8dc4b6Seschrock #define	DN_MAX_OBJECT	(1ULL << DN_MAX_OBJECT_SHIFT)
931934e92fSmaybee #define	DN_ZERO_BONUSLEN	(DN_MAX_BONUSLEN + 1)
940a586ceaSMark Shellenbaum #define	DN_KILL_SPILLBLK (1)
95fa9e4066Sahrens 
96fa9e4066Sahrens #define	DNODES_PER_BLOCK_SHIFT	(DNODE_BLOCK_SHIFT - DNODE_SHIFT)
97fa9e4066Sahrens #define	DNODES_PER_BLOCK	(1ULL << DNODES_PER_BLOCK_SHIFT)
984b5c8e93SMatthew Ahrens 
994b5c8e93SMatthew Ahrens /*
1004b5c8e93SMatthew Ahrens  * This is inaccurate if the indblkshift of the particular object is not the
1014b5c8e93SMatthew Ahrens  * max.  But it's only used by userland to calculate the zvol reservation.
1024b5c8e93SMatthew Ahrens  */
103fa9e4066Sahrens #define	DNODES_PER_LEVEL_SHIFT	(DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT)
104c1449561SEric Taylor #define	DNODES_PER_LEVEL	(1ULL << DNODES_PER_LEVEL_SHIFT)
105fa9e4066Sahrens 
106fa9e4066Sahrens /* The +2 here is a cheesy way to round up */
107fa9e4066Sahrens #define	DN_MAX_LEVELS	(2 + ((DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT) / \
108fa9e4066Sahrens 	(DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT)))
109fa9e4066Sahrens 
110fa9e4066Sahrens #define	DN_BONUS(dnp)	((void*)((dnp)->dn_bonus + \
111fa9e4066Sahrens 	(((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t))))
112fa9e4066Sahrens 
11399653d4eSeschrock #define	DN_USED_BYTES(dnp) (((dnp)->dn_flags & DNODE_FLAG_USED_BYTES) ? \
11499653d4eSeschrock 	(dnp)->dn_used : (dnp)->dn_used << SPA_MINBLOCKSHIFT)
11599653d4eSeschrock 
116fa9e4066Sahrens #define	EPB(blkshift, typeshift)	(1 << (blkshift - typeshift))
117fa9e4066Sahrens 
118fa9e4066Sahrens struct dmu_buf_impl;
119503ad85cSMatthew Ahrens struct objset;
120fa9e4066Sahrens struct zio;
121fa9e4066Sahrens 
122fa9e4066Sahrens enum dnode_dirtycontext {
123fa9e4066Sahrens 	DN_UNDIRTIED,
124fa9e4066Sahrens 	DN_DIRTY_OPEN,
125fa9e4066Sahrens 	DN_DIRTY_SYNC
126fa9e4066Sahrens };
127fa9e4066Sahrens 
12899653d4eSeschrock /* Is dn_used in bytes?  if not, it's in multiples of SPA_MINBLOCKSIZE */
12914843421SMatthew Ahrens #define	DNODE_FLAG_USED_BYTES		(1<<0)
13014843421SMatthew Ahrens #define	DNODE_FLAG_USERUSED_ACCOUNTED	(1<<1)
13199653d4eSeschrock 
1320a586ceaSMark Shellenbaum /* Does dnode have a SA spill blkptr in bonus? */
1330a586ceaSMark Shellenbaum #define	DNODE_FLAG_SPILL_BLKPTR	(1<<2)
1340a586ceaSMark Shellenbaum 
135fa9e4066Sahrens typedef struct dnode_phys {
136fa9e4066Sahrens 	uint8_t dn_type;		/* dmu_object_type_t */
137fa9e4066Sahrens 	uint8_t dn_indblkshift;		/* ln2(indirect block size) */
138fa9e4066Sahrens 	uint8_t dn_nlevels;		/* 1=dn_blkptr->data blocks */
139fa9e4066Sahrens 	uint8_t dn_nblkptr;		/* length of dn_blkptr */
140fa9e4066Sahrens 	uint8_t dn_bonustype;		/* type of data in bonus buffer */
141fa9e4066Sahrens 	uint8_t	dn_checksum;		/* ZIO_CHECKSUM type */
142fa9e4066Sahrens 	uint8_t	dn_compress;		/* ZIO_COMPRESS type */
14399653d4eSeschrock 	uint8_t dn_flags;		/* DNODE_FLAG_* */
144fa9e4066Sahrens 	uint16_t dn_datablkszsec;	/* data block size in 512b sectors */
145fa9e4066Sahrens 	uint16_t dn_bonuslen;		/* length of dn_bonus */
146fa9e4066Sahrens 	uint8_t dn_pad2[4];
147fa9e4066Sahrens 
148fa9e4066Sahrens 	/* accounting is protected by dn_dirty_mtx */
149fa9e4066Sahrens 	uint64_t dn_maxblkid;		/* largest allocated block ID */
15099653d4eSeschrock 	uint64_t dn_used;		/* bytes (or sectors) of disk space */
151fa9e4066Sahrens 
152fa9e4066Sahrens 	uint64_t dn_pad3[4];
153fa9e4066Sahrens 
154fa9e4066Sahrens 	blkptr_t dn_blkptr[1];
1550a586ceaSMark Shellenbaum 	uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof (blkptr_t)];
1560a586ceaSMark Shellenbaum 	blkptr_t dn_spill;
157fa9e4066Sahrens } dnode_phys_t;
158fa9e4066Sahrens 
15979d72832SMatthew Ahrens struct dnode {
160fa9e4066Sahrens 	/*
161f7170741SWill Andrews 	 * Protects the structure of the dnode, including the number of levels
162f7170741SWill Andrews 	 * of indirection (dn_nlevels), dn_maxblkid, and dn_next_*
163fa9e4066Sahrens 	 */
164fa9e4066Sahrens 	krwlock_t dn_struct_rwlock;
165fa9e4066Sahrens 
16614843421SMatthew Ahrens 	/* Our link on dn_objset->os_dnodes list; protected by os_lock.  */
167fa9e4066Sahrens 	list_node_t dn_link;
168fa9e4066Sahrens 
169fa9e4066Sahrens 	/* immutable: */
170503ad85cSMatthew Ahrens 	struct objset *dn_objset;
171fa9e4066Sahrens 	uint64_t dn_object;
172fa9e4066Sahrens 	struct dmu_buf_impl *dn_dbuf;
173744947dcSTom Erickson 	struct dnode_handle *dn_handle;
174fa9e4066Sahrens 	dnode_phys_t *dn_phys; /* pointer into dn->dn_dbuf->db.db_data */
175fa9e4066Sahrens 
176fa9e4066Sahrens 	/*
177c543ec06Sahrens 	 * Copies of stuff in dn_phys.  They're valid in the open
178c543ec06Sahrens 	 * context (eg. even before the dnode is first synced).
179c543ec06Sahrens 	 * Where necessary, these are protected by dn_struct_rwlock.
180fa9e4066Sahrens 	 */
181c543ec06Sahrens 	dmu_object_type_t dn_type;	/* object type */
182c543ec06Sahrens 	uint16_t dn_bonuslen;		/* bonus length */
183c543ec06Sahrens 	uint8_t dn_bonustype;		/* bonus type */
184fa9e4066Sahrens 	uint8_t dn_nblkptr;		/* number of blkptrs (immutable) */
185fa9e4066Sahrens 	uint8_t dn_checksum;		/* ZIO_CHECKSUM type */
186fa9e4066Sahrens 	uint8_t dn_compress;		/* ZIO_COMPRESS type */
187fa9e4066Sahrens 	uint8_t dn_nlevels;
188fa9e4066Sahrens 	uint8_t dn_indblkshift;
189c543ec06Sahrens 	uint8_t dn_datablkshift;	/* zero if blksz not power of 2! */
190744947dcSTom Erickson 	uint8_t dn_moved;		/* Has this dnode been moved? */
191c543ec06Sahrens 	uint16_t dn_datablkszsec;	/* in 512b sectors */
192c543ec06Sahrens 	uint32_t dn_datablksz;		/* in bytes */
193c543ec06Sahrens 	uint64_t dn_maxblkid;
1942acef22dSMatthew Ahrens 	uint8_t dn_next_type[TXG_SIZE];
195da03de99SMark Maybee 	uint8_t dn_next_nblkptr[TXG_SIZE];
196fa9e4066Sahrens 	uint8_t dn_next_nlevels[TXG_SIZE];
197fa9e4066Sahrens 	uint8_t dn_next_indblkshift[TXG_SIZE];
1980a586ceaSMark Shellenbaum 	uint8_t dn_next_bonustype[TXG_SIZE];
1990a586ceaSMark Shellenbaum 	uint8_t dn_rm_spillblk[TXG_SIZE];	/* for removing spill blk */
2001934e92fSmaybee 	uint16_t dn_next_bonuslen[TXG_SIZE];
201c543ec06Sahrens 	uint32_t dn_next_blksz[TXG_SIZE];	/* next block size in bytes */
202fa9e4066Sahrens 
203744947dcSTom Erickson 	/* protected by dn_dbufs_mtx; declared here to fill 32-bit hole */
204744947dcSTom Erickson 	uint32_t dn_dbufs_count;	/* count of dn_dbufs */
205744947dcSTom Erickson 
206fa9e4066Sahrens 	/* protected by os_lock: */
20794c2d0ebSMatthew Ahrens 	multilist_node_t dn_dirty_link[TXG_SIZE]; /* next on dataset's dirty */
208fa9e4066Sahrens 
209fa9e4066Sahrens 	/* protected by dn_mtx: */
210fa9e4066Sahrens 	kmutex_t dn_mtx;
211c717a561Smaybee 	list_t dn_dirty_records[TXG_SIZE];
212bf16b11eSMatthew Ahrens 	struct range_tree *dn_free_ranges[TXG_SIZE];
213fa9e4066Sahrens 	uint64_t dn_allocated_txg;
214fa9e4066Sahrens 	uint64_t dn_free_txg;
215fa9e4066Sahrens 	uint64_t dn_assigned_txg;
216fa9e4066Sahrens 	kcondvar_t dn_notxholds;
217fa9e4066Sahrens 	enum dnode_dirtycontext dn_dirtyctx;
218fa9e4066Sahrens 	uint8_t *dn_dirtyctx_firstset;		/* dbg: contents meaningless */
219fa9e4066Sahrens 
220fa9e4066Sahrens 	/* protected by own devices */
221fa9e4066Sahrens 	refcount_t dn_tx_holds;
222fa9e4066Sahrens 	refcount_t dn_holds;
223fa9e4066Sahrens 
224fa9e4066Sahrens 	kmutex_t dn_dbufs_mtx;
22586bb58aeSAlex Reece 	/*
22686bb58aeSAlex Reece 	 * Descendent dbufs, ordered by dbuf_compare. Note that dn_dbufs
22786bb58aeSAlex Reece 	 * can contain multiple dbufs of the same (level, blkid) when a
22886bb58aeSAlex Reece 	 * dbuf is marked DB_EVICTING without being removed from
22986bb58aeSAlex Reece 	 * dn_dbufs. To maintain the avl invariant that there cannot be
23086bb58aeSAlex Reece 	 * duplicate entries, we order the dbufs by an arbitrary value -
23186bb58aeSAlex Reece 	 * their address in memory. This means that dn_dbufs cannot be used to
23286bb58aeSAlex Reece 	 * directly look up a dbuf. Instead, callers must use avl_walk, have
23386bb58aeSAlex Reece 	 * a reference to the dbuf, or look up a non-existant node with
23486bb58aeSAlex Reece 	 * db_state = DB_SEARCH (see dbuf_free_range for an example).
23586bb58aeSAlex Reece 	 */
23686bb58aeSAlex Reece 	avl_tree_t dn_dbufs;
237744947dcSTom Erickson 
238744947dcSTom Erickson 	/* protected by dn_struct_rwlock */
239ea8dc4b6Seschrock 	struct dmu_buf_impl *dn_bonus;	/* bonus buffer dbuf */
240744947dcSTom Erickson 
2410a586ceaSMark Shellenbaum 	boolean_t dn_have_spill;	/* have spill or are spilling */
242fa9e4066Sahrens 
243c717a561Smaybee 	/* parent IO for current sync write */
244c717a561Smaybee 	zio_t *dn_zio;
245c717a561Smaybee 
24614843421SMatthew Ahrens 	/* used in syncing context */
2470a586ceaSMark Shellenbaum 	uint64_t dn_oldused;	/* old phys used bytes */
2480a586ceaSMark Shellenbaum 	uint64_t dn_oldflags;	/* old phys dn_flags */
2490a586ceaSMark Shellenbaum 	uint64_t dn_olduid, dn_oldgid;
2500a586ceaSMark Shellenbaum 	uint64_t dn_newuid, dn_newgid;
2510a586ceaSMark Shellenbaum 	int dn_id_flags;
25214843421SMatthew Ahrens 
253fa9e4066Sahrens 	/* holds prefetch structure */
254fa9e4066Sahrens 	struct zfetch	dn_zfetch;
25579d72832SMatthew Ahrens };
256fa9e4066Sahrens 
257744947dcSTom Erickson /*
258744947dcSTom Erickson  * Adds a level of indirection between the dbuf and the dnode to avoid
259744947dcSTom Erickson  * iterating descendent dbufs in dnode_move(). Handles are not allocated
260744947dcSTom Erickson  * individually, but as an array of child dnodes in dnode_hold_impl().
261744947dcSTom Erickson  */
262744947dcSTom Erickson typedef struct dnode_handle {
263744947dcSTom Erickson 	/* Protects dnh_dnode from modification by dnode_move(). */
264744947dcSTom Erickson 	zrlock_t dnh_zrlock;
265744947dcSTom Erickson 	dnode_t *dnh_dnode;
266744947dcSTom Erickson } dnode_handle_t;
267744947dcSTom Erickson 
268744947dcSTom Erickson typedef struct dnode_children {
269bc9014e6SJustin Gibbs 	dmu_buf_user_t dnc_dbu;		/* User evict data */
270744947dcSTom Erickson 	size_t dnc_count;		/* number of children */
2717f18da4cSJustin T. Gibbs 	dnode_handle_t dnc_children[];	/* sized dynamically */
272744947dcSTom Erickson } dnode_children_t;
273744947dcSTom Erickson 
274fa9e4066Sahrens typedef struct free_range {
275fa9e4066Sahrens 	avl_node_t fr_node;
276fa9e4066Sahrens 	uint64_t fr_blkid;
277fa9e4066Sahrens 	uint64_t fr_nblks;
278fa9e4066Sahrens } free_range_t;
279fa9e4066Sahrens 
280bc9014e6SJustin Gibbs void dnode_special_open(struct objset *dd, dnode_phys_t *dnp,
281744947dcSTom Erickson     uint64_t object, dnode_handle_t *dnh);
282744947dcSTom Erickson void dnode_special_close(dnode_handle_t *dnh);
283fa9e4066Sahrens 
2841934e92fSmaybee void dnode_setbonuslen(dnode_t *dn, int newsize, dmu_tx_t *tx);
2850a586ceaSMark Shellenbaum void dnode_setbonus_type(dnode_t *dn, dmu_object_type_t, dmu_tx_t *tx);
2860a586ceaSMark Shellenbaum void dnode_rm_spill(dnode_t *dn, dmu_tx_t *tx);
2870a586ceaSMark Shellenbaum 
288503ad85cSMatthew Ahrens int dnode_hold(struct objset *dd, uint64_t object,
289ea8dc4b6Seschrock     void *ref, dnode_t **dnp);
290503ad85cSMatthew Ahrens int dnode_hold_impl(struct objset *dd, uint64_t object, int flag,
291ea8dc4b6Seschrock     void *ref, dnode_t **dnp);
2921934e92fSmaybee boolean_t dnode_add_ref(dnode_t *dn, void *ref);
293fa9e4066Sahrens void dnode_rele(dnode_t *dn, void *ref);
294cd485b49SJustin T. Gibbs void dnode_rele_and_unlock(dnode_t *dn, void *tag);
295fa9e4066Sahrens void dnode_setdirty(dnode_t *dn, dmu_tx_t *tx);
296c717a561Smaybee void dnode_sync(dnode_t *dn, dmu_tx_t *tx);
297fa9e4066Sahrens void dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs,
298fa9e4066Sahrens     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
299fa9e4066Sahrens void dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
300fa9e4066Sahrens     dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
301fa9e4066Sahrens void dnode_free(dnode_t *dn, dmu_tx_t *tx);
302fa9e4066Sahrens void dnode_byteswap(dnode_phys_t *dnp);
303fa9e4066Sahrens void dnode_buf_byteswap(void *buf, size_t size);
304fa9e4066Sahrens void dnode_verify(dnode_t *dn);
305fa9e4066Sahrens int dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx);
306fa9e4066Sahrens void dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx);
307fa9e4066Sahrens void dnode_diduse_space(dnode_t *dn, int64_t space);
3088346f03fSJonathan W Adams void dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t);
309fa9e4066Sahrens uint64_t dnode_block_freed(dnode_t *dn, uint64_t blkid);
310fa9e4066Sahrens void dnode_init(void);
311fa9e4066Sahrens void dnode_fini(void);
312cdb0ab79Smaybee int dnode_next_offset(dnode_t *dn, int flags, uint64_t *off,
313cdb0ab79Smaybee     int minlvl, uint64_t blkfill, uint64_t txg);
3141934e92fSmaybee void dnode_evict_dbufs(dnode_t *dn);
315cd485b49SJustin T. Gibbs void dnode_evict_bonus(dnode_t *dn);
316*5cabbc6bSPrashanth Sreenivasa boolean_t dnode_needs_remap(const dnode_t *dn);
317fa9e4066Sahrens 
318cb92f413SAlexander Motin #define	DNODE_IS_CACHEABLE(_dn)						\
319cb92f413SAlexander Motin 	((_dn)->dn_objset->os_primary_cache == ZFS_CACHE_ALL ||		\
320cb92f413SAlexander Motin 	(DMU_OT_IS_METADATA((_dn)->dn_type) &&				\
321cb92f413SAlexander Motin 	(_dn)->dn_objset->os_primary_cache == ZFS_CACHE_METADATA))
322cb92f413SAlexander Motin 
323cb92f413SAlexander Motin #define	DNODE_META_IS_CACHEABLE(_dn)					\
324cb92f413SAlexander Motin 	((_dn)->dn_objset->os_primary_cache == ZFS_CACHE_ALL ||		\
325cb92f413SAlexander Motin 	(_dn)->dn_objset->os_primary_cache == ZFS_CACHE_METADATA)
326cb92f413SAlexander Motin 
327fa9e4066Sahrens #ifdef ZFS_DEBUG
328fa9e4066Sahrens 
329fa9e4066Sahrens /*
330fa9e4066Sahrens  * There should be a ## between the string literal and fmt, to make it
331fa9e4066Sahrens  * clear that we're joining two strings together, but that piece of shit
332fa9e4066Sahrens  * gcc doesn't support that preprocessor token.
333fa9e4066Sahrens  */
334fa9e4066Sahrens #define	dprintf_dnode(dn, fmt, ...) do { \
335fa9e4066Sahrens 	if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
336fa9e4066Sahrens 	char __db_buf[32]; \
337fa9e4066Sahrens 	uint64_t __db_obj = (dn)->dn_object; \
338fa9e4066Sahrens 	if (__db_obj == DMU_META_DNODE_OBJECT) \
339fa9e4066Sahrens 		(void) strcpy(__db_buf, "mdn"); \
340fa9e4066Sahrens 	else \
341fa9e4066Sahrens 		(void) snprintf(__db_buf, sizeof (__db_buf), "%lld", \
342fa9e4066Sahrens 		    (u_longlong_t)__db_obj);\
343fa9e4066Sahrens 	dprintf_ds((dn)->dn_objset->os_dsl_dataset, "obj=%s " fmt, \
344fa9e4066Sahrens 	    __db_buf, __VA_ARGS__); \
345fa9e4066Sahrens 	} \
346fa9e4066Sahrens _NOTE(CONSTCOND) } while (0)
347fa9e4066Sahrens 
3489c9dc39aSek #define	DNODE_VERIFY(dn)		dnode_verify(dn)
3499c9dc39aSek #define	FREE_VERIFY(db, start, end, tx)	free_verify(db, start, end, tx)
3509c9dc39aSek 
351fa9e4066Sahrens #else
352fa9e4066Sahrens 
353fa9e4066Sahrens #define	dprintf_dnode(db, fmt, ...)
3549c9dc39aSek #define	DNODE_VERIFY(dn)
3559c9dc39aSek #define	FREE_VERIFY(db, start, end, tx)
356fa9e4066Sahrens 
357fa9e4066Sahrens #endif
358fa9e4066Sahrens 
359fa9e4066Sahrens #ifdef	__cplusplus
360fa9e4066Sahrens }
361fa9e4066Sahrens #endif
362fa9e4066Sahrens 
363fa9e4066Sahrens #endif	/* _SYS_DNODE_H */
364