author | Matthew Ahrens <Matthew.Ahrens@Sun.COM> |
Sat, 18 Apr 2009 13:41:47 -0700 | |
changeset 9396 | f41cf682d0d3 |
parent 8644 | 10534c530688 |
child 10298 | a0d52501437c |
permissions | -rw-r--r-- |
789 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
1544 | 5 |
* Common Development and Distribution License (the "License"). |
6 |
* You may not use this file except in compliance with the License. |
|
789 | 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 |
/* |
|
8644
10534c530688
6793373 assertion failed in dnode_reallocate: dn_nblkptr >= old_nblkptr
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
22 |
* Copyright 2009 Sun Microsystems, Inc. All rights reserved. |
789 | 23 |
* Use is subject to license terms. |
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> |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3025
diff
changeset
|
33 |
#include <sys/zio.h> |
789 | 34 |
#include <sys/refcount.h> |
35 |
#include <sys/dmu_zfetch.h> |
|
36 |
||
37 |
#ifdef __cplusplus |
|
38 |
extern "C" { |
|
39 |
#endif |
|
40 |
||
41 |
/* |
|
6992 | 42 |
* dnode_hold() flags. |
789 | 43 |
*/ |
44 |
#define DNODE_MUST_BE_ALLOCATED 1 |
|
45 |
#define DNODE_MUST_BE_FREE 2 |
|
46 |
||
47 |
/* |
|
6992 | 48 |
* dnode_next_offset() flags. |
49 |
*/ |
|
50 |
#define DNODE_FIND_HOLE 1 |
|
51 |
#define DNODE_FIND_BACKWARDS 2 |
|
52 |
#define DNODE_FIND_HAVELOCK 4 |
|
53 |
||
54 |
/* |
|
789 | 55 |
* Fixed constants. |
56 |
*/ |
|
57 |
#define DNODE_SHIFT 9 /* 512 bytes */ |
|
58 |
#define DN_MIN_INDBLKSHIFT 10 /* 1k */ |
|
59 |
#define DN_MAX_INDBLKSHIFT 14 /* 16k */ |
|
60 |
#define DNODE_BLOCK_SHIFT 14 /* 16k */ |
|
61 |
#define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */ |
|
62 |
#define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */ |
|
63 |
#define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */ |
|
64 |
||
65 |
/* |
|
66 |
* Derived constants. |
|
67 |
*/ |
|
68 |
#define DNODE_SIZE (1 << DNODE_SHIFT) |
|
69 |
#define DN_MAX_NBLKPTR ((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT) |
|
70 |
#define DN_MAX_BONUSLEN (DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT)) |
|
1544 | 71 |
#define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT) |
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4787
diff
changeset
|
72 |
#define DN_ZERO_BONUSLEN (DN_MAX_BONUSLEN + 1) |
789 | 73 |
|
74 |
#define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT) |
|
75 |
#define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT) |
|
76 |
#define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT) |
|
77 |
||
78 |
/* The +2 here is a cheesy way to round up */ |
|
79 |
#define DN_MAX_LEVELS (2 + ((DN_MAX_OFFSET_SHIFT - SPA_MINBLOCKSHIFT) / \ |
|
80 |
(DN_MIN_INDBLKSHIFT - SPA_BLKPTRSHIFT))) |
|
81 |
||
82 |
#define DN_BONUS(dnp) ((void*)((dnp)->dn_bonus + \ |
|
83 |
(((dnp)->dn_nblkptr - 1) * sizeof (blkptr_t)))) |
|
84 |
||
2082 | 85 |
#define DN_USED_BYTES(dnp) (((dnp)->dn_flags & DNODE_FLAG_USED_BYTES) ? \ |
86 |
(dnp)->dn_used : (dnp)->dn_used << SPA_MINBLOCKSHIFT) |
|
87 |
||
789 | 88 |
#define EPB(blkshift, typeshift) (1 << (blkshift - typeshift)) |
89 |
||
90 |
struct dmu_buf_impl; |
|
91 |
struct objset_impl; |
|
92 |
struct zio; |
|
93 |
||
94 |
enum dnode_dirtycontext { |
|
95 |
DN_UNDIRTIED, |
|
96 |
DN_DIRTY_OPEN, |
|
97 |
DN_DIRTY_SYNC |
|
98 |
}; |
|
99 |
||
2082 | 100 |
/* Is dn_used in bytes? if not, it's in multiples of SPA_MINBLOCKSIZE */ |
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8644
diff
changeset
|
101 |
#define DNODE_FLAG_USED_BYTES (1<<0) |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8644
diff
changeset
|
102 |
#define DNODE_FLAG_USERUSED_ACCOUNTED (1<<1) |
2082 | 103 |
|
789 | 104 |
typedef struct dnode_phys { |
105 |
uint8_t dn_type; /* dmu_object_type_t */ |
|
106 |
uint8_t dn_indblkshift; /* ln2(indirect block size) */ |
|
107 |
uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */ |
|
108 |
uint8_t dn_nblkptr; /* length of dn_blkptr */ |
|
109 |
uint8_t dn_bonustype; /* type of data in bonus buffer */ |
|
110 |
uint8_t dn_checksum; /* ZIO_CHECKSUM type */ |
|
111 |
uint8_t dn_compress; /* ZIO_COMPRESS type */ |
|
2082 | 112 |
uint8_t dn_flags; /* DNODE_FLAG_* */ |
789 | 113 |
uint16_t dn_datablkszsec; /* data block size in 512b sectors */ |
114 |
uint16_t dn_bonuslen; /* length of dn_bonus */ |
|
115 |
uint8_t dn_pad2[4]; |
|
116 |
||
117 |
/* accounting is protected by dn_dirty_mtx */ |
|
118 |
uint64_t dn_maxblkid; /* largest allocated block ID */ |
|
2082 | 119 |
uint64_t dn_used; /* bytes (or sectors) of disk space */ |
789 | 120 |
|
121 |
uint64_t dn_pad3[4]; |
|
122 |
||
123 |
blkptr_t dn_blkptr[1]; |
|
124 |
uint8_t dn_bonus[DN_MAX_BONUSLEN]; |
|
125 |
} dnode_phys_t; |
|
126 |
||
127 |
typedef struct dnode { |
|
128 |
/* |
|
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
129 |
* dn_struct_rwlock protects the structure of the dnode, |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
130 |
* including the number of levels of indirection (dn_nlevels), |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
131 |
* dn_maxblkid, and dn_next_* |
789 | 132 |
*/ |
133 |
krwlock_t dn_struct_rwlock; |
|
134 |
||
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8644
diff
changeset
|
135 |
/* Our link on dn_objset->os_dnodes list; protected by os_lock. */ |
789 | 136 |
list_node_t dn_link; |
137 |
||
138 |
/* immutable: */ |
|
139 |
struct objset_impl *dn_objset; |
|
140 |
uint64_t dn_object; |
|
141 |
struct dmu_buf_impl *dn_dbuf; |
|
142 |
dnode_phys_t *dn_phys; /* pointer into dn->dn_dbuf->db.db_data */ |
|
143 |
||
144 |
/* |
|
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
145 |
* Copies of stuff in dn_phys. They're valid in the open |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
146 |
* context (eg. even before the dnode is first synced). |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
147 |
* Where necessary, these are protected by dn_struct_rwlock. |
789 | 148 |
*/ |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
149 |
dmu_object_type_t dn_type; /* object type */ |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
150 |
uint16_t dn_bonuslen; /* bonus length */ |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
151 |
uint8_t dn_bonustype; /* bonus type */ |
789 | 152 |
uint8_t dn_nblkptr; /* number of blkptrs (immutable) */ |
153 |
uint8_t dn_checksum; /* ZIO_CHECKSUM type */ |
|
154 |
uint8_t dn_compress; /* ZIO_COMPRESS type */ |
|
155 |
uint8_t dn_nlevels; |
|
156 |
uint8_t dn_indblkshift; |
|
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
157 |
uint8_t dn_datablkshift; /* zero if blksz not power of 2! */ |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
158 |
uint16_t dn_datablkszsec; /* in 512b sectors */ |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
159 |
uint32_t dn_datablksz; /* in bytes */ |
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
160 |
uint64_t dn_maxblkid; |
8644
10534c530688
6793373 assertion failed in dnode_reallocate: dn_nblkptr >= old_nblkptr
Mark Maybee <Mark.Maybee@Sun.COM>
parents:
7332
diff
changeset
|
161 |
uint8_t dn_next_nblkptr[TXG_SIZE]; |
789 | 162 |
uint8_t dn_next_nlevels[TXG_SIZE]; |
163 |
uint8_t dn_next_indblkshift[TXG_SIZE]; |
|
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4787
diff
changeset
|
164 |
uint16_t dn_next_bonuslen[TXG_SIZE]; |
1596
2e2377ccbf85
6395371 ASSERT in dmu_tx_count_free: blkid + i < dn->dn_phys->dn_nblkptr
ahrens
parents:
1544
diff
changeset
|
165 |
uint32_t dn_next_blksz[TXG_SIZE]; /* next block size in bytes */ |
789 | 166 |
|
167 |
/* protected by os_lock: */ |
|
168 |
list_node_t dn_dirty_link[TXG_SIZE]; /* next on dataset's dirty */ |
|
169 |
||
170 |
/* protected by dn_mtx: */ |
|
171 |
kmutex_t dn_mtx; |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3025
diff
changeset
|
172 |
list_t dn_dirty_records[TXG_SIZE]; |
789 | 173 |
avl_tree_t dn_ranges[TXG_SIZE]; |
174 |
uint64_t dn_allocated_txg; |
|
175 |
uint64_t dn_free_txg; |
|
176 |
uint64_t dn_assigned_txg; |
|
177 |
kcondvar_t dn_notxholds; |
|
178 |
enum dnode_dirtycontext dn_dirtyctx; |
|
179 |
uint8_t *dn_dirtyctx_firstset; /* dbg: contents meaningless */ |
|
180 |
||
181 |
/* protected by own devices */ |
|
182 |
refcount_t dn_tx_holds; |
|
183 |
refcount_t dn_holds; |
|
184 |
||
185 |
kmutex_t dn_dbufs_mtx; |
|
186 |
list_t dn_dbufs; /* linked list of descendent dbuf_t's */ |
|
1544 | 187 |
struct dmu_buf_impl *dn_bonus; /* bonus buffer dbuf */ |
789 | 188 |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3025
diff
changeset
|
189 |
/* parent IO for current sync write */ |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3025
diff
changeset
|
190 |
zio_t *dn_zio; |
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3025
diff
changeset
|
191 |
|
9396
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8644
diff
changeset
|
192 |
/* used in syncing context */ |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8644
diff
changeset
|
193 |
dnode_phys_t *dn_oldphys; |
f41cf682d0d3
PSARC/2009/204 ZFS user/group quotas & space accounting
Matthew Ahrens <Matthew.Ahrens@Sun.COM>
parents:
8644
diff
changeset
|
194 |
|
789 | 195 |
/* holds prefetch structure */ |
196 |
struct zfetch dn_zfetch; |
|
197 |
} dnode_t; |
|
198 |
||
199 |
typedef struct free_range { |
|
200 |
avl_node_t fr_node; |
|
201 |
uint64_t fr_blkid; |
|
202 |
uint64_t fr_nblks; |
|
203 |
} free_range_t; |
|
204 |
||
205 |
dnode_t *dnode_special_open(struct objset_impl *dd, dnode_phys_t *dnp, |
|
206 |
uint64_t object); |
|
207 |
void dnode_special_close(dnode_t *dn); |
|
208 |
||
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4787
diff
changeset
|
209 |
void dnode_setbonuslen(dnode_t *dn, int newsize, dmu_tx_t *tx); |
1544 | 210 |
int dnode_hold(struct objset_impl *dd, uint64_t object, |
211 |
void *ref, dnode_t **dnp); |
|
212 |
int dnode_hold_impl(struct objset_impl *dd, uint64_t object, int flag, |
|
213 |
void *ref, dnode_t **dnp); |
|
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4787
diff
changeset
|
214 |
boolean_t dnode_add_ref(dnode_t *dn, void *ref); |
789 | 215 |
void dnode_rele(dnode_t *dn, void *ref); |
216 |
void dnode_setdirty(dnode_t *dn, dmu_tx_t *tx); |
|
3547
e396e0a440b1
6512391 DMU should leverage ZIO dependencies to achieve greater parallelism
maybee
parents:
3025
diff
changeset
|
217 |
void dnode_sync(dnode_t *dn, dmu_tx_t *tx); |
789 | 218 |
void dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs, |
219 |
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); |
|
220 |
void dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, |
|
221 |
dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx); |
|
222 |
void dnode_free(dnode_t *dn, dmu_tx_t *tx); |
|
223 |
void dnode_byteswap(dnode_phys_t *dnp); |
|
224 |
void dnode_buf_byteswap(void *buf, size_t size); |
|
225 |
void dnode_verify(dnode_t *dn); |
|
226 |
int dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx); |
|
227 |
uint64_t dnode_current_max_length(dnode_t *dn); |
|
228 |
void dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx); |
|
229 |
void dnode_clear_range(dnode_t *dn, uint64_t blkid, |
|
230 |
uint64_t nblks, dmu_tx_t *tx); |
|
231 |
void dnode_diduse_space(dnode_t *dn, int64_t space); |
|
232 |
void dnode_willuse_space(dnode_t *dn, int64_t space, dmu_tx_t *tx); |
|
7332
396f25bd1f34
6579975 dnode_new_blkid should look before it locks
Jonathan W Adams <Jonathan.Adams@Sun.COM>
parents:
6992
diff
changeset
|
233 |
void dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t); |
789 | 234 |
uint64_t dnode_block_freed(dnode_t *dn, uint64_t blkid); |
235 |
void dnode_init(void); |
|
236 |
void dnode_fini(void); |
|
6992 | 237 |
int dnode_next_offset(dnode_t *dn, int flags, uint64_t *off, |
238 |
int minlvl, uint64_t blkfill, uint64_t txg); |
|
4944
96d96f8de974
6569719 panic dangling dbufs (dn=ffffffff28814d30, dbuf=ffffffff20756008)
maybee
parents:
4787
diff
changeset
|
239 |
void dnode_evict_dbufs(dnode_t *dn); |
789 | 240 |
|
241 |
#ifdef ZFS_DEBUG |
|
242 |
||
243 |
/* |
|
244 |
* There should be a ## between the string literal and fmt, to make it |
|
245 |
* clear that we're joining two strings together, but that piece of shit |
|
246 |
* gcc doesn't support that preprocessor token. |
|
247 |
*/ |
|
248 |
#define dprintf_dnode(dn, fmt, ...) do { \ |
|
249 |
if (zfs_flags & ZFS_DEBUG_DPRINTF) { \ |
|
250 |
char __db_buf[32]; \ |
|
251 |
uint64_t __db_obj = (dn)->dn_object; \ |
|
252 |
if (__db_obj == DMU_META_DNODE_OBJECT) \ |
|
253 |
(void) strcpy(__db_buf, "mdn"); \ |
|
254 |
else \ |
|
255 |
(void) snprintf(__db_buf, sizeof (__db_buf), "%lld", \ |
|
256 |
(u_longlong_t)__db_obj);\ |
|
257 |
dprintf_ds((dn)->dn_objset->os_dsl_dataset, "obj=%s " fmt, \ |
|
258 |
__db_buf, __VA_ARGS__); \ |
|
259 |
} \ |
|
260 |
_NOTE(CONSTCOND) } while (0) |
|
261 |
||
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
262 |
#define DNODE_VERIFY(dn) dnode_verify(dn) |
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
263 |
#define FREE_VERIFY(db, start, end, tx) free_verify(db, start, end, tx) |
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
264 |
|
789 | 265 |
#else |
266 |
||
267 |
#define dprintf_dnode(db, fmt, ...) |
|
873
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
268 |
#define DNODE_VERIFY(dn) |
adefbfa5f42d
6347448 non ZFS_DEBUG kernels shouldn't call empty verify functions
ek110237
parents:
789
diff
changeset
|
269 |
#define FREE_VERIFY(db, start, end, tx) |
789 | 270 |
|
271 |
#endif |
|
272 |
||
273 |
#ifdef __cplusplus |
|
274 |
} |
|
275 |
#endif |
|
276 |
||
277 |
#endif /* _SYS_DNODE_H */ |