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 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2013 by Delphix. All rights reserved.
24 */
25
26 #ifndef _SYS_DNODE_H
27 #define _SYS_DNODE_H
28
29 #include <sys/zfs_context.h>
30 #include <sys/avl.h>
31 #include <sys/spa.h>
32 #include <sys/txg.h>
33 #include <sys/zio.h>
34 #include <sys/refcount.h>
35 #include <sys/dmu_zfetch.h>
36 #include <sys/zrlock.h>
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /*
43 * dnode_hold() flags.
181 uint8_t dn_next_type[TXG_SIZE];
182 uint8_t dn_next_nblkptr[TXG_SIZE];
183 uint8_t dn_next_nlevels[TXG_SIZE];
184 uint8_t dn_next_indblkshift[TXG_SIZE];
185 uint8_t dn_next_bonustype[TXG_SIZE];
186 uint8_t dn_rm_spillblk[TXG_SIZE]; /* for removing spill blk */
187 uint16_t dn_next_bonuslen[TXG_SIZE];
188 uint32_t dn_next_blksz[TXG_SIZE]; /* next block size in bytes */
189
190 /* protected by dn_dbufs_mtx; declared here to fill 32-bit hole */
191 uint32_t dn_dbufs_count; /* count of dn_dbufs */
192 /* There are no level-0 blocks of this blkid or higher in dn_dbufs */
193 uint64_t dn_unlisted_l0_blkid;
194
195 /* protected by os_lock: */
196 list_node_t dn_dirty_link[TXG_SIZE]; /* next on dataset's dirty */
197
198 /* protected by dn_mtx: */
199 kmutex_t dn_mtx;
200 list_t dn_dirty_records[TXG_SIZE];
201 avl_tree_t dn_ranges[TXG_SIZE];
202 uint64_t dn_allocated_txg;
203 uint64_t dn_free_txg;
204 uint64_t dn_assigned_txg;
205 kcondvar_t dn_notxholds;
206 enum dnode_dirtycontext dn_dirtyctx;
207 uint8_t *dn_dirtyctx_firstset; /* dbg: contents meaningless */
208
209 /* protected by own devices */
210 refcount_t dn_tx_holds;
211 refcount_t dn_holds;
212
213 kmutex_t dn_dbufs_mtx;
214 list_t dn_dbufs; /* descendent dbufs */
215
216 /* protected by dn_struct_rwlock */
217 struct dmu_buf_impl *dn_bonus; /* bonus buffer dbuf */
218
219 boolean_t dn_have_spill; /* have spill or are spilling */
220
221 /* parent IO for current sync write */
263 void dnode_rm_spill(dnode_t *dn, dmu_tx_t *tx);
264
265 int dnode_hold(struct objset *dd, uint64_t object,
266 void *ref, dnode_t **dnp);
267 int dnode_hold_impl(struct objset *dd, uint64_t object, int flag,
268 void *ref, dnode_t **dnp);
269 boolean_t dnode_add_ref(dnode_t *dn, void *ref);
270 void dnode_rele(dnode_t *dn, void *ref);
271 void dnode_setdirty(dnode_t *dn, dmu_tx_t *tx);
272 void dnode_sync(dnode_t *dn, dmu_tx_t *tx);
273 void dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs,
274 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
275 void dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
276 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
277 void dnode_free(dnode_t *dn, dmu_tx_t *tx);
278 void dnode_byteswap(dnode_phys_t *dnp);
279 void dnode_buf_byteswap(void *buf, size_t size);
280 void dnode_verify(dnode_t *dn);
281 int dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx);
282 void dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx);
283 void dnode_clear_range(dnode_t *dn, uint64_t blkid,
284 uint64_t nblks, dmu_tx_t *tx);
285 void dnode_diduse_space(dnode_t *dn, int64_t space);
286 void dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx);
287 void dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t);
288 uint64_t dnode_block_freed(dnode_t *dn, uint64_t blkid);
289 void dnode_init(void);
290 void dnode_fini(void);
291 int dnode_next_offset(dnode_t *dn, int flags, uint64_t *off,
292 int minlvl, uint64_t blkfill, uint64_t txg);
293 void dnode_evict_dbufs(dnode_t *dn);
294
295 #ifdef ZFS_DEBUG
296
297 /*
298 * There should be a ## between the string literal and fmt, to make it
299 * clear that we're joining two strings together, but that piece of shit
300 * gcc doesn't support that preprocessor token.
301 */
302 #define dprintf_dnode(dn, fmt, ...) do { \
303 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
304 char __db_buf[32]; \
|
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 /*
22 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23 * Copyright (c) 2012, 2014 by Delphix. All rights reserved.
24 */
25
26 #ifndef _SYS_DNODE_H
27 #define _SYS_DNODE_H
28
29 #include <sys/zfs_context.h>
30 #include <sys/avl.h>
31 #include <sys/spa.h>
32 #include <sys/txg.h>
33 #include <sys/zio.h>
34 #include <sys/refcount.h>
35 #include <sys/dmu_zfetch.h>
36 #include <sys/zrlock.h>
37
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41
42 /*
43 * dnode_hold() flags.
181 uint8_t dn_next_type[TXG_SIZE];
182 uint8_t dn_next_nblkptr[TXG_SIZE];
183 uint8_t dn_next_nlevels[TXG_SIZE];
184 uint8_t dn_next_indblkshift[TXG_SIZE];
185 uint8_t dn_next_bonustype[TXG_SIZE];
186 uint8_t dn_rm_spillblk[TXG_SIZE]; /* for removing spill blk */
187 uint16_t dn_next_bonuslen[TXG_SIZE];
188 uint32_t dn_next_blksz[TXG_SIZE]; /* next block size in bytes */
189
190 /* protected by dn_dbufs_mtx; declared here to fill 32-bit hole */
191 uint32_t dn_dbufs_count; /* count of dn_dbufs */
192 /* There are no level-0 blocks of this blkid or higher in dn_dbufs */
193 uint64_t dn_unlisted_l0_blkid;
194
195 /* protected by os_lock: */
196 list_node_t dn_dirty_link[TXG_SIZE]; /* next on dataset's dirty */
197
198 /* protected by dn_mtx: */
199 kmutex_t dn_mtx;
200 list_t dn_dirty_records[TXG_SIZE];
201 struct range_tree *dn_free_ranges[TXG_SIZE];
202 uint64_t dn_allocated_txg;
203 uint64_t dn_free_txg;
204 uint64_t dn_assigned_txg;
205 kcondvar_t dn_notxholds;
206 enum dnode_dirtycontext dn_dirtyctx;
207 uint8_t *dn_dirtyctx_firstset; /* dbg: contents meaningless */
208
209 /* protected by own devices */
210 refcount_t dn_tx_holds;
211 refcount_t dn_holds;
212
213 kmutex_t dn_dbufs_mtx;
214 list_t dn_dbufs; /* descendent dbufs */
215
216 /* protected by dn_struct_rwlock */
217 struct dmu_buf_impl *dn_bonus; /* bonus buffer dbuf */
218
219 boolean_t dn_have_spill; /* have spill or are spilling */
220
221 /* parent IO for current sync write */
263 void dnode_rm_spill(dnode_t *dn, dmu_tx_t *tx);
264
265 int dnode_hold(struct objset *dd, uint64_t object,
266 void *ref, dnode_t **dnp);
267 int dnode_hold_impl(struct objset *dd, uint64_t object, int flag,
268 void *ref, dnode_t **dnp);
269 boolean_t dnode_add_ref(dnode_t *dn, void *ref);
270 void dnode_rele(dnode_t *dn, void *ref);
271 void dnode_setdirty(dnode_t *dn, dmu_tx_t *tx);
272 void dnode_sync(dnode_t *dn, dmu_tx_t *tx);
273 void dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs,
274 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
275 void dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
276 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx);
277 void dnode_free(dnode_t *dn, dmu_tx_t *tx);
278 void dnode_byteswap(dnode_phys_t *dnp);
279 void dnode_buf_byteswap(void *buf, size_t size);
280 void dnode_verify(dnode_t *dn);
281 int dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx);
282 void dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx);
283 void dnode_diduse_space(dnode_t *dn, int64_t space);
284 void dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx);
285 void dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t);
286 uint64_t dnode_block_freed(dnode_t *dn, uint64_t blkid);
287 void dnode_init(void);
288 void dnode_fini(void);
289 int dnode_next_offset(dnode_t *dn, int flags, uint64_t *off,
290 int minlvl, uint64_t blkfill, uint64_t txg);
291 void dnode_evict_dbufs(dnode_t *dn);
292
293 #ifdef ZFS_DEBUG
294
295 /*
296 * There should be a ## between the string literal and fmt, to make it
297 * clear that we're joining two strings together, but that piece of shit
298 * gcc doesn't support that preprocessor token.
299 */
300 #define dprintf_dnode(dn, fmt, ...) do { \
301 if (zfs_flags & ZFS_DEBUG_DPRINTF) { \
302 char __db_buf[32]; \
|