Print this page
8115 parallel zfs mount
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/fs/zfs/dnode.c
+++ new/usr/src/uts/common/fs/zfs/dnode.c
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
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
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, 2017 by Delphix. All rights reserved.
24 24 * Copyright (c) 2014 Spectra Logic Corporation, All rights reserved.
25 25 * Copyright (c) 2014 Integros [integros.com]
26 + * Copyright 2017 RackTop Systems.
26 27 */
27 28
28 29 #include <sys/zfs_context.h>
29 30 #include <sys/dbuf.h>
30 31 #include <sys/dnode.h>
31 32 #include <sys/dmu.h>
32 33 #include <sys/dmu_impl.h>
33 34 #include <sys/dmu_tx.h>
34 35 #include <sys/dmu_objset.h>
35 36 #include <sys/dsl_dir.h>
36 37 #include <sys/dsl_dataset.h>
37 38 #include <sys/spa.h>
38 39 #include <sys/zio.h>
39 40 #include <sys/dmu_zfetch.h>
40 41 #include <sys/range_tree.h>
41 42
42 43 static kmem_cache_t *dnode_cache;
43 44 /*
44 45 * Define DNODE_STATS to turn on statistic gathering. By default, it is only
45 46 * turned on when DEBUG is also defined.
46 47 */
47 48 #ifdef DEBUG
48 49 #define DNODE_STATS
49 50 #endif /* DEBUG */
50 51
51 52 #ifdef DNODE_STATS
↓ open down ↓ |
16 lines elided |
↑ open up ↑ |
52 53 #define DNODE_STAT_ADD(stat) ((stat)++)
53 54 #else
54 55 #define DNODE_STAT_ADD(stat) /* nothing */
55 56 #endif /* DNODE_STATS */
56 57
57 58 static dnode_phys_t dnode_phys_zero;
58 59
59 60 int zfs_default_bs = SPA_MINBLOCKSHIFT;
60 61 int zfs_default_ibs = DN_MAX_INDBLKSHIFT;
61 62
63 +#ifdef _KERNEL
62 64 static kmem_cbrc_t dnode_move(void *, void *, size_t, void *);
65 +#endif /* _KERNEL */
63 66
64 67 static int
65 68 dbuf_compare(const void *x1, const void *x2)
66 69 {
67 70 const dmu_buf_impl_t *d1 = x1;
68 71 const dmu_buf_impl_t *d2 = x2;
69 72
70 73 if (d1->db_level < d2->db_level) {
71 74 return (-1);
72 75 }
73 76 if (d1->db_level > d2->db_level) {
74 77 return (1);
75 78 }
76 79
77 80 if (d1->db_blkid < d2->db_blkid) {
78 81 return (-1);
79 82 }
80 83 if (d1->db_blkid > d2->db_blkid) {
81 84 return (1);
82 85 }
83 86
84 87 if (d1->db_state == DB_SEARCH) {
85 88 ASSERT3S(d2->db_state, !=, DB_SEARCH);
86 89 return (-1);
87 90 } else if (d2->db_state == DB_SEARCH) {
88 91 ASSERT3S(d1->db_state, !=, DB_SEARCH);
89 92 return (1);
90 93 }
91 94
92 95 if ((uintptr_t)d1 < (uintptr_t)d2) {
93 96 return (-1);
94 97 }
95 98 if ((uintptr_t)d1 > (uintptr_t)d2) {
96 99 return (1);
97 100 }
98 101 return (0);
99 102 }
100 103
101 104 /* ARGSUSED */
102 105 static int
103 106 dnode_cons(void *arg, void *unused, int kmflag)
104 107 {
105 108 dnode_t *dn = arg;
106 109 int i;
107 110
108 111 rw_init(&dn->dn_struct_rwlock, NULL, RW_DEFAULT, NULL);
109 112 mutex_init(&dn->dn_mtx, NULL, MUTEX_DEFAULT, NULL);
110 113 mutex_init(&dn->dn_dbufs_mtx, NULL, MUTEX_DEFAULT, NULL);
111 114 cv_init(&dn->dn_notxholds, NULL, CV_DEFAULT, NULL);
112 115
113 116 /*
114 117 * Every dbuf has a reference, and dropping a tracked reference is
115 118 * O(number of references), so don't track dn_holds.
116 119 */
117 120 refcount_create_untracked(&dn->dn_holds);
118 121 refcount_create(&dn->dn_tx_holds);
119 122 list_link_init(&dn->dn_link);
120 123
121 124 bzero(&dn->dn_next_nblkptr[0], sizeof (dn->dn_next_nblkptr));
122 125 bzero(&dn->dn_next_nlevels[0], sizeof (dn->dn_next_nlevels));
123 126 bzero(&dn->dn_next_indblkshift[0], sizeof (dn->dn_next_indblkshift));
124 127 bzero(&dn->dn_next_bonustype[0], sizeof (dn->dn_next_bonustype));
125 128 bzero(&dn->dn_rm_spillblk[0], sizeof (dn->dn_rm_spillblk));
126 129 bzero(&dn->dn_next_bonuslen[0], sizeof (dn->dn_next_bonuslen));
127 130 bzero(&dn->dn_next_blksz[0], sizeof (dn->dn_next_blksz));
128 131
129 132 for (i = 0; i < TXG_SIZE; i++) {
130 133 list_link_init(&dn->dn_dirty_link[i]);
131 134 dn->dn_free_ranges[i] = NULL;
132 135 list_create(&dn->dn_dirty_records[i],
133 136 sizeof (dbuf_dirty_record_t),
134 137 offsetof(dbuf_dirty_record_t, dr_dirty_node));
135 138 }
136 139
137 140 dn->dn_allocated_txg = 0;
138 141 dn->dn_free_txg = 0;
139 142 dn->dn_assigned_txg = 0;
140 143 dn->dn_dirtyctx = 0;
141 144 dn->dn_dirtyctx_firstset = NULL;
142 145 dn->dn_bonus = NULL;
143 146 dn->dn_have_spill = B_FALSE;
144 147 dn->dn_zio = NULL;
145 148 dn->dn_oldused = 0;
146 149 dn->dn_oldflags = 0;
147 150 dn->dn_olduid = 0;
148 151 dn->dn_oldgid = 0;
149 152 dn->dn_newuid = 0;
150 153 dn->dn_newgid = 0;
151 154 dn->dn_id_flags = 0;
152 155
153 156 dn->dn_dbufs_count = 0;
154 157 avl_create(&dn->dn_dbufs, dbuf_compare, sizeof (dmu_buf_impl_t),
155 158 offsetof(dmu_buf_impl_t, db_link));
156 159
157 160 dn->dn_moved = 0;
158 161 return (0);
159 162 }
160 163
161 164 /* ARGSUSED */
162 165 static void
163 166 dnode_dest(void *arg, void *unused)
164 167 {
165 168 int i;
166 169 dnode_t *dn = arg;
167 170
168 171 rw_destroy(&dn->dn_struct_rwlock);
169 172 mutex_destroy(&dn->dn_mtx);
170 173 mutex_destroy(&dn->dn_dbufs_mtx);
171 174 cv_destroy(&dn->dn_notxholds);
172 175 refcount_destroy(&dn->dn_holds);
173 176 refcount_destroy(&dn->dn_tx_holds);
174 177 ASSERT(!list_link_active(&dn->dn_link));
175 178
176 179 for (i = 0; i < TXG_SIZE; i++) {
177 180 ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
178 181 ASSERT3P(dn->dn_free_ranges[i], ==, NULL);
179 182 list_destroy(&dn->dn_dirty_records[i]);
180 183 ASSERT0(dn->dn_next_nblkptr[i]);
181 184 ASSERT0(dn->dn_next_nlevels[i]);
182 185 ASSERT0(dn->dn_next_indblkshift[i]);
183 186 ASSERT0(dn->dn_next_bonustype[i]);
184 187 ASSERT0(dn->dn_rm_spillblk[i]);
185 188 ASSERT0(dn->dn_next_bonuslen[i]);
186 189 ASSERT0(dn->dn_next_blksz[i]);
187 190 }
188 191
189 192 ASSERT0(dn->dn_allocated_txg);
190 193 ASSERT0(dn->dn_free_txg);
191 194 ASSERT0(dn->dn_assigned_txg);
192 195 ASSERT0(dn->dn_dirtyctx);
193 196 ASSERT3P(dn->dn_dirtyctx_firstset, ==, NULL);
194 197 ASSERT3P(dn->dn_bonus, ==, NULL);
195 198 ASSERT(!dn->dn_have_spill);
196 199 ASSERT3P(dn->dn_zio, ==, NULL);
197 200 ASSERT0(dn->dn_oldused);
198 201 ASSERT0(dn->dn_oldflags);
199 202 ASSERT0(dn->dn_olduid);
200 203 ASSERT0(dn->dn_oldgid);
201 204 ASSERT0(dn->dn_newuid);
202 205 ASSERT0(dn->dn_newgid);
203 206 ASSERT0(dn->dn_id_flags);
204 207
205 208 ASSERT0(dn->dn_dbufs_count);
↓ open down ↓ |
133 lines elided |
↑ open up ↑ |
206 209 avl_destroy(&dn->dn_dbufs);
207 210 }
208 211
209 212 void
210 213 dnode_init(void)
211 214 {
212 215 ASSERT(dnode_cache == NULL);
213 216 dnode_cache = kmem_cache_create("dnode_t",
214 217 sizeof (dnode_t),
215 218 0, dnode_cons, dnode_dest, NULL, NULL, NULL, 0);
219 +#ifdef _KERNEL
216 220 kmem_cache_set_move(dnode_cache, dnode_move);
221 +#endif /* _KERNEL */
217 222 }
218 223
219 224 void
220 225 dnode_fini(void)
221 226 {
222 227 kmem_cache_destroy(dnode_cache);
223 228 dnode_cache = NULL;
224 229 }
225 230
226 231
227 232 #ifdef ZFS_DEBUG
228 233 void
229 234 dnode_verify(dnode_t *dn)
230 235 {
231 236 int drop_struct_lock = FALSE;
232 237
233 238 ASSERT(dn->dn_phys);
234 239 ASSERT(dn->dn_objset);
235 240 ASSERT(dn->dn_handle->dnh_dnode == dn);
236 241
237 242 ASSERT(DMU_OT_IS_VALID(dn->dn_phys->dn_type));
238 243
239 244 if (!(zfs_flags & ZFS_DEBUG_DNODE_VERIFY))
240 245 return;
241 246
242 247 if (!RW_WRITE_HELD(&dn->dn_struct_rwlock)) {
243 248 rw_enter(&dn->dn_struct_rwlock, RW_READER);
244 249 drop_struct_lock = TRUE;
245 250 }
246 251 if (dn->dn_phys->dn_type != DMU_OT_NONE || dn->dn_allocated_txg != 0) {
247 252 int i;
248 253 ASSERT3U(dn->dn_indblkshift, >=, 0);
249 254 ASSERT3U(dn->dn_indblkshift, <=, SPA_MAXBLOCKSHIFT);
250 255 if (dn->dn_datablkshift) {
251 256 ASSERT3U(dn->dn_datablkshift, >=, SPA_MINBLOCKSHIFT);
252 257 ASSERT3U(dn->dn_datablkshift, <=, SPA_MAXBLOCKSHIFT);
253 258 ASSERT3U(1<<dn->dn_datablkshift, ==, dn->dn_datablksz);
254 259 }
255 260 ASSERT3U(dn->dn_nlevels, <=, 30);
256 261 ASSERT(DMU_OT_IS_VALID(dn->dn_type));
257 262 ASSERT3U(dn->dn_nblkptr, >=, 1);
258 263 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR);
259 264 ASSERT3U(dn->dn_bonuslen, <=, DN_MAX_BONUSLEN);
260 265 ASSERT3U(dn->dn_datablksz, ==,
261 266 dn->dn_datablkszsec << SPA_MINBLOCKSHIFT);
262 267 ASSERT3U(ISP2(dn->dn_datablksz), ==, dn->dn_datablkshift != 0);
263 268 ASSERT3U((dn->dn_nblkptr - 1) * sizeof (blkptr_t) +
264 269 dn->dn_bonuslen, <=, DN_MAX_BONUSLEN);
265 270 for (i = 0; i < TXG_SIZE; i++) {
266 271 ASSERT3U(dn->dn_next_nlevels[i], <=, dn->dn_nlevels);
267 272 }
268 273 }
269 274 if (dn->dn_phys->dn_type != DMU_OT_NONE)
270 275 ASSERT3U(dn->dn_phys->dn_nlevels, <=, dn->dn_nlevels);
271 276 ASSERT(DMU_OBJECT_IS_SPECIAL(dn->dn_object) || dn->dn_dbuf != NULL);
272 277 if (dn->dn_dbuf != NULL) {
273 278 ASSERT3P(dn->dn_phys, ==,
274 279 (dnode_phys_t *)dn->dn_dbuf->db.db_data +
275 280 (dn->dn_object % (dn->dn_dbuf->db.db_size >> DNODE_SHIFT)));
276 281 }
277 282 if (drop_struct_lock)
278 283 rw_exit(&dn->dn_struct_rwlock);
279 284 }
280 285 #endif
281 286
282 287 void
283 288 dnode_byteswap(dnode_phys_t *dnp)
284 289 {
285 290 uint64_t *buf64 = (void*)&dnp->dn_blkptr;
286 291 int i;
287 292
288 293 if (dnp->dn_type == DMU_OT_NONE) {
289 294 bzero(dnp, sizeof (dnode_phys_t));
290 295 return;
291 296 }
292 297
293 298 dnp->dn_datablkszsec = BSWAP_16(dnp->dn_datablkszsec);
294 299 dnp->dn_bonuslen = BSWAP_16(dnp->dn_bonuslen);
295 300 dnp->dn_maxblkid = BSWAP_64(dnp->dn_maxblkid);
296 301 dnp->dn_used = BSWAP_64(dnp->dn_used);
297 302
298 303 /*
299 304 * dn_nblkptr is only one byte, so it's OK to read it in either
300 305 * byte order. We can't read dn_bouslen.
301 306 */
302 307 ASSERT(dnp->dn_indblkshift <= SPA_MAXBLOCKSHIFT);
303 308 ASSERT(dnp->dn_nblkptr <= DN_MAX_NBLKPTR);
304 309 for (i = 0; i < dnp->dn_nblkptr * sizeof (blkptr_t)/8; i++)
305 310 buf64[i] = BSWAP_64(buf64[i]);
306 311
307 312 /*
308 313 * OK to check dn_bonuslen for zero, because it won't matter if
309 314 * we have the wrong byte order. This is necessary because the
310 315 * dnode dnode is smaller than a regular dnode.
311 316 */
312 317 if (dnp->dn_bonuslen != 0) {
313 318 /*
314 319 * Note that the bonus length calculated here may be
315 320 * longer than the actual bonus buffer. This is because
316 321 * we always put the bonus buffer after the last block
317 322 * pointer (instead of packing it against the end of the
318 323 * dnode buffer).
319 324 */
320 325 int off = (dnp->dn_nblkptr-1) * sizeof (blkptr_t);
321 326 size_t len = DN_MAX_BONUSLEN - off;
322 327 ASSERT(DMU_OT_IS_VALID(dnp->dn_bonustype));
323 328 dmu_object_byteswap_t byteswap =
324 329 DMU_OT_BYTESWAP(dnp->dn_bonustype);
325 330 dmu_ot_byteswap[byteswap].ob_func(dnp->dn_bonus + off, len);
326 331 }
327 332
328 333 /* Swap SPILL block if we have one */
329 334 if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR)
330 335 byteswap_uint64_array(&dnp->dn_spill, sizeof (blkptr_t));
331 336
332 337 }
333 338
334 339 void
335 340 dnode_buf_byteswap(void *vbuf, size_t size)
336 341 {
337 342 dnode_phys_t *buf = vbuf;
338 343 int i;
339 344
340 345 ASSERT3U(sizeof (dnode_phys_t), ==, (1<<DNODE_SHIFT));
341 346 ASSERT((size & (sizeof (dnode_phys_t)-1)) == 0);
342 347
343 348 size >>= DNODE_SHIFT;
344 349 for (i = 0; i < size; i++) {
345 350 dnode_byteswap(buf);
346 351 buf++;
347 352 }
348 353 }
349 354
350 355 void
351 356 dnode_setbonuslen(dnode_t *dn, int newsize, dmu_tx_t *tx)
352 357 {
353 358 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1);
354 359
355 360 dnode_setdirty(dn, tx);
356 361 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
357 362 ASSERT3U(newsize, <=, DN_MAX_BONUSLEN -
358 363 (dn->dn_nblkptr-1) * sizeof (blkptr_t));
359 364 dn->dn_bonuslen = newsize;
360 365 if (newsize == 0)
361 366 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = DN_ZERO_BONUSLEN;
362 367 else
363 368 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen;
364 369 rw_exit(&dn->dn_struct_rwlock);
365 370 }
366 371
367 372 void
368 373 dnode_setbonus_type(dnode_t *dn, dmu_object_type_t newtype, dmu_tx_t *tx)
369 374 {
370 375 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1);
371 376 dnode_setdirty(dn, tx);
372 377 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
373 378 dn->dn_bonustype = newtype;
374 379 dn->dn_next_bonustype[tx->tx_txg & TXG_MASK] = dn->dn_bonustype;
375 380 rw_exit(&dn->dn_struct_rwlock);
376 381 }
377 382
378 383 void
379 384 dnode_rm_spill(dnode_t *dn, dmu_tx_t *tx)
380 385 {
381 386 ASSERT3U(refcount_count(&dn->dn_holds), >=, 1);
382 387 ASSERT(RW_WRITE_HELD(&dn->dn_struct_rwlock));
383 388 dnode_setdirty(dn, tx);
384 389 dn->dn_rm_spillblk[tx->tx_txg&TXG_MASK] = DN_KILL_SPILLBLK;
385 390 dn->dn_have_spill = B_FALSE;
386 391 }
387 392
388 393 static void
389 394 dnode_setdblksz(dnode_t *dn, int size)
390 395 {
391 396 ASSERT0(P2PHASE(size, SPA_MINBLOCKSIZE));
392 397 ASSERT3U(size, <=, SPA_MAXBLOCKSIZE);
393 398 ASSERT3U(size, >=, SPA_MINBLOCKSIZE);
394 399 ASSERT3U(size >> SPA_MINBLOCKSHIFT, <,
395 400 1<<(sizeof (dn->dn_phys->dn_datablkszsec) * 8));
396 401 dn->dn_datablksz = size;
397 402 dn->dn_datablkszsec = size >> SPA_MINBLOCKSHIFT;
398 403 dn->dn_datablkshift = ISP2(size) ? highbit64(size - 1) : 0;
399 404 }
400 405
401 406 static dnode_t *
402 407 dnode_create(objset_t *os, dnode_phys_t *dnp, dmu_buf_impl_t *db,
403 408 uint64_t object, dnode_handle_t *dnh)
404 409 {
405 410 dnode_t *dn;
406 411
407 412 dn = kmem_cache_alloc(dnode_cache, KM_SLEEP);
408 413 ASSERT(!POINTER_IS_VALID(dn->dn_objset));
409 414 dn->dn_moved = 0;
410 415
411 416 /*
412 417 * Defer setting dn_objset until the dnode is ready to be a candidate
413 418 * for the dnode_move() callback.
414 419 */
415 420 dn->dn_object = object;
416 421 dn->dn_dbuf = db;
417 422 dn->dn_handle = dnh;
418 423 dn->dn_phys = dnp;
419 424
420 425 if (dnp->dn_datablkszsec) {
421 426 dnode_setdblksz(dn, dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT);
422 427 } else {
423 428 dn->dn_datablksz = 0;
424 429 dn->dn_datablkszsec = 0;
425 430 dn->dn_datablkshift = 0;
426 431 }
427 432 dn->dn_indblkshift = dnp->dn_indblkshift;
428 433 dn->dn_nlevels = dnp->dn_nlevels;
429 434 dn->dn_type = dnp->dn_type;
430 435 dn->dn_nblkptr = dnp->dn_nblkptr;
431 436 dn->dn_checksum = dnp->dn_checksum;
432 437 dn->dn_compress = dnp->dn_compress;
433 438 dn->dn_bonustype = dnp->dn_bonustype;
434 439 dn->dn_bonuslen = dnp->dn_bonuslen;
435 440 dn->dn_maxblkid = dnp->dn_maxblkid;
436 441 dn->dn_have_spill = ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) != 0);
437 442 dn->dn_id_flags = 0;
438 443
439 444 dmu_zfetch_init(&dn->dn_zfetch, dn);
440 445
441 446 ASSERT(DMU_OT_IS_VALID(dn->dn_phys->dn_type));
442 447
443 448 mutex_enter(&os->os_lock);
444 449 if (dnh->dnh_dnode != NULL) {
445 450 /* Lost the allocation race. */
446 451 mutex_exit(&os->os_lock);
447 452 kmem_cache_free(dnode_cache, dn);
448 453 return (dnh->dnh_dnode);
449 454 }
450 455
451 456 /*
452 457 * Exclude special dnodes from os_dnodes so an empty os_dnodes
453 458 * signifies that the special dnodes have no references from
454 459 * their children (the entries in os_dnodes). This allows
455 460 * dnode_destroy() to easily determine if the last child has
456 461 * been removed and then complete eviction of the objset.
457 462 */
458 463 if (!DMU_OBJECT_IS_SPECIAL(object))
459 464 list_insert_head(&os->os_dnodes, dn);
460 465 membar_producer();
461 466
462 467 /*
463 468 * Everything else must be valid before assigning dn_objset
464 469 * makes the dnode eligible for dnode_move().
465 470 */
466 471 dn->dn_objset = os;
467 472
468 473 dnh->dnh_dnode = dn;
469 474 mutex_exit(&os->os_lock);
470 475
471 476 arc_space_consume(sizeof (dnode_t), ARC_SPACE_OTHER);
472 477 return (dn);
473 478 }
474 479
475 480 /*
476 481 * Caller must be holding the dnode handle, which is released upon return.
477 482 */
478 483 static void
479 484 dnode_destroy(dnode_t *dn)
480 485 {
481 486 objset_t *os = dn->dn_objset;
482 487 boolean_t complete_os_eviction = B_FALSE;
483 488
484 489 ASSERT((dn->dn_id_flags & DN_ID_NEW_EXIST) == 0);
485 490
486 491 mutex_enter(&os->os_lock);
487 492 POINTER_INVALIDATE(&dn->dn_objset);
488 493 if (!DMU_OBJECT_IS_SPECIAL(dn->dn_object)) {
489 494 list_remove(&os->os_dnodes, dn);
490 495 complete_os_eviction =
491 496 list_is_empty(&os->os_dnodes) &&
492 497 list_link_active(&os->os_evicting_node);
493 498 }
494 499 mutex_exit(&os->os_lock);
495 500
496 501 /* the dnode can no longer move, so we can release the handle */
497 502 zrl_remove(&dn->dn_handle->dnh_zrlock);
498 503
499 504 dn->dn_allocated_txg = 0;
500 505 dn->dn_free_txg = 0;
501 506 dn->dn_assigned_txg = 0;
502 507
503 508 dn->dn_dirtyctx = 0;
504 509 if (dn->dn_dirtyctx_firstset != NULL) {
505 510 kmem_free(dn->dn_dirtyctx_firstset, 1);
506 511 dn->dn_dirtyctx_firstset = NULL;
507 512 }
508 513 if (dn->dn_bonus != NULL) {
509 514 mutex_enter(&dn->dn_bonus->db_mtx);
510 515 dbuf_destroy(dn->dn_bonus);
511 516 dn->dn_bonus = NULL;
512 517 }
513 518 dn->dn_zio = NULL;
514 519
515 520 dn->dn_have_spill = B_FALSE;
516 521 dn->dn_oldused = 0;
517 522 dn->dn_oldflags = 0;
518 523 dn->dn_olduid = 0;
519 524 dn->dn_oldgid = 0;
520 525 dn->dn_newuid = 0;
521 526 dn->dn_newgid = 0;
522 527 dn->dn_id_flags = 0;
523 528
524 529 dmu_zfetch_fini(&dn->dn_zfetch);
525 530 kmem_cache_free(dnode_cache, dn);
526 531 arc_space_return(sizeof (dnode_t), ARC_SPACE_OTHER);
527 532
528 533 if (complete_os_eviction)
529 534 dmu_objset_evict_done(os);
530 535 }
531 536
532 537 void
533 538 dnode_allocate(dnode_t *dn, dmu_object_type_t ot, int blocksize, int ibs,
534 539 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
535 540 {
536 541 int i;
537 542
538 543 ASSERT3U(blocksize, <=,
539 544 spa_maxblocksize(dmu_objset_spa(dn->dn_objset)));
540 545 if (blocksize == 0)
541 546 blocksize = 1 << zfs_default_bs;
542 547 else
543 548 blocksize = P2ROUNDUP(blocksize, SPA_MINBLOCKSIZE);
544 549
545 550 if (ibs == 0)
546 551 ibs = zfs_default_ibs;
547 552
548 553 ibs = MIN(MAX(ibs, DN_MIN_INDBLKSHIFT), DN_MAX_INDBLKSHIFT);
549 554
550 555 dprintf("os=%p obj=%llu txg=%llu blocksize=%d ibs=%d\n", dn->dn_objset,
551 556 dn->dn_object, tx->tx_txg, blocksize, ibs);
552 557
553 558 ASSERT(dn->dn_type == DMU_OT_NONE);
554 559 ASSERT(bcmp(dn->dn_phys, &dnode_phys_zero, sizeof (dnode_phys_t)) == 0);
555 560 ASSERT(dn->dn_phys->dn_type == DMU_OT_NONE);
556 561 ASSERT(ot != DMU_OT_NONE);
557 562 ASSERT(DMU_OT_IS_VALID(ot));
558 563 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
559 564 (bonustype == DMU_OT_SA && bonuslen == 0) ||
560 565 (bonustype != DMU_OT_NONE && bonuslen != 0));
561 566 ASSERT(DMU_OT_IS_VALID(bonustype));
562 567 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
563 568 ASSERT(dn->dn_type == DMU_OT_NONE);
564 569 ASSERT0(dn->dn_maxblkid);
565 570 ASSERT0(dn->dn_allocated_txg);
566 571 ASSERT0(dn->dn_assigned_txg);
567 572 ASSERT(refcount_is_zero(&dn->dn_tx_holds));
568 573 ASSERT3U(refcount_count(&dn->dn_holds), <=, 1);
569 574 ASSERT(avl_is_empty(&dn->dn_dbufs));
570 575
571 576 for (i = 0; i < TXG_SIZE; i++) {
572 577 ASSERT0(dn->dn_next_nblkptr[i]);
573 578 ASSERT0(dn->dn_next_nlevels[i]);
574 579 ASSERT0(dn->dn_next_indblkshift[i]);
575 580 ASSERT0(dn->dn_next_bonuslen[i]);
576 581 ASSERT0(dn->dn_next_bonustype[i]);
577 582 ASSERT0(dn->dn_rm_spillblk[i]);
578 583 ASSERT0(dn->dn_next_blksz[i]);
579 584 ASSERT(!list_link_active(&dn->dn_dirty_link[i]));
580 585 ASSERT3P(list_head(&dn->dn_dirty_records[i]), ==, NULL);
581 586 ASSERT3P(dn->dn_free_ranges[i], ==, NULL);
582 587 }
583 588
584 589 dn->dn_type = ot;
585 590 dnode_setdblksz(dn, blocksize);
586 591 dn->dn_indblkshift = ibs;
587 592 dn->dn_nlevels = 1;
588 593 if (bonustype == DMU_OT_SA) /* Maximize bonus space for SA */
589 594 dn->dn_nblkptr = 1;
590 595 else
591 596 dn->dn_nblkptr = 1 +
592 597 ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
593 598 dn->dn_bonustype = bonustype;
594 599 dn->dn_bonuslen = bonuslen;
595 600 dn->dn_checksum = ZIO_CHECKSUM_INHERIT;
596 601 dn->dn_compress = ZIO_COMPRESS_INHERIT;
597 602 dn->dn_dirtyctx = 0;
598 603
599 604 dn->dn_free_txg = 0;
600 605 if (dn->dn_dirtyctx_firstset) {
601 606 kmem_free(dn->dn_dirtyctx_firstset, 1);
602 607 dn->dn_dirtyctx_firstset = NULL;
603 608 }
604 609
605 610 dn->dn_allocated_txg = tx->tx_txg;
606 611 dn->dn_id_flags = 0;
607 612
608 613 dnode_setdirty(dn, tx);
609 614 dn->dn_next_indblkshift[tx->tx_txg & TXG_MASK] = ibs;
610 615 dn->dn_next_bonuslen[tx->tx_txg & TXG_MASK] = dn->dn_bonuslen;
611 616 dn->dn_next_bonustype[tx->tx_txg & TXG_MASK] = dn->dn_bonustype;
612 617 dn->dn_next_blksz[tx->tx_txg & TXG_MASK] = dn->dn_datablksz;
613 618 }
614 619
615 620 void
616 621 dnode_reallocate(dnode_t *dn, dmu_object_type_t ot, int blocksize,
617 622 dmu_object_type_t bonustype, int bonuslen, dmu_tx_t *tx)
618 623 {
619 624 int nblkptr;
620 625
621 626 ASSERT3U(blocksize, >=, SPA_MINBLOCKSIZE);
622 627 ASSERT3U(blocksize, <=,
623 628 spa_maxblocksize(dmu_objset_spa(dn->dn_objset)));
624 629 ASSERT0(blocksize % SPA_MINBLOCKSIZE);
625 630 ASSERT(dn->dn_object != DMU_META_DNODE_OBJECT || dmu_tx_private_ok(tx));
626 631 ASSERT(tx->tx_txg != 0);
627 632 ASSERT((bonustype == DMU_OT_NONE && bonuslen == 0) ||
628 633 (bonustype != DMU_OT_NONE && bonuslen != 0) ||
629 634 (bonustype == DMU_OT_SA && bonuslen == 0));
630 635 ASSERT(DMU_OT_IS_VALID(bonustype));
631 636 ASSERT3U(bonuslen, <=, DN_MAX_BONUSLEN);
632 637
633 638 /* clean up any unreferenced dbufs */
634 639 dnode_evict_dbufs(dn);
635 640
636 641 dn->dn_id_flags = 0;
637 642
638 643 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
639 644 dnode_setdirty(dn, tx);
640 645 if (dn->dn_datablksz != blocksize) {
641 646 /* change blocksize */
642 647 ASSERT(dn->dn_maxblkid == 0 &&
643 648 (BP_IS_HOLE(&dn->dn_phys->dn_blkptr[0]) ||
644 649 dnode_block_freed(dn, 0)));
645 650 dnode_setdblksz(dn, blocksize);
646 651 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = blocksize;
647 652 }
648 653 if (dn->dn_bonuslen != bonuslen)
649 654 dn->dn_next_bonuslen[tx->tx_txg&TXG_MASK] = bonuslen;
650 655
651 656 if (bonustype == DMU_OT_SA) /* Maximize bonus space for SA */
652 657 nblkptr = 1;
653 658 else
654 659 nblkptr = 1 + ((DN_MAX_BONUSLEN - bonuslen) >> SPA_BLKPTRSHIFT);
655 660 if (dn->dn_bonustype != bonustype)
656 661 dn->dn_next_bonustype[tx->tx_txg&TXG_MASK] = bonustype;
657 662 if (dn->dn_nblkptr != nblkptr)
658 663 dn->dn_next_nblkptr[tx->tx_txg&TXG_MASK] = nblkptr;
659 664 if (dn->dn_phys->dn_flags & DNODE_FLAG_SPILL_BLKPTR) {
660 665 dbuf_rm_spill(dn, tx);
661 666 dnode_rm_spill(dn, tx);
662 667 }
663 668 rw_exit(&dn->dn_struct_rwlock);
664 669
665 670 /* change type */
666 671 dn->dn_type = ot;
667 672
668 673 /* change bonus size and type */
669 674 mutex_enter(&dn->dn_mtx);
670 675 dn->dn_bonustype = bonustype;
671 676 dn->dn_bonuslen = bonuslen;
672 677 dn->dn_nblkptr = nblkptr;
673 678 dn->dn_checksum = ZIO_CHECKSUM_INHERIT;
674 679 dn->dn_compress = ZIO_COMPRESS_INHERIT;
675 680 ASSERT3U(dn->dn_nblkptr, <=, DN_MAX_NBLKPTR);
676 681
677 682 /* fix up the bonus db_size */
678 683 if (dn->dn_bonus) {
679 684 dn->dn_bonus->db.db_size =
680 685 DN_MAX_BONUSLEN - (dn->dn_nblkptr-1) * sizeof (blkptr_t);
681 686 ASSERT(dn->dn_bonuslen <= dn->dn_bonus->db.db_size);
682 687 }
683 688
684 689 dn->dn_allocated_txg = tx->tx_txg;
685 690 mutex_exit(&dn->dn_mtx);
686 691 }
687 692
688 693 #ifdef DNODE_STATS
689 694 static struct {
↓ open down ↓ |
463 lines elided |
↑ open up ↑ |
690 695 uint64_t dms_dnode_invalid;
691 696 uint64_t dms_dnode_recheck1;
692 697 uint64_t dms_dnode_recheck2;
693 698 uint64_t dms_dnode_special;
694 699 uint64_t dms_dnode_handle;
695 700 uint64_t dms_dnode_rwlock;
696 701 uint64_t dms_dnode_active;
697 702 } dnode_move_stats;
698 703 #endif /* DNODE_STATS */
699 704
705 +#ifdef _KERNEL
700 706 static void
701 707 dnode_move_impl(dnode_t *odn, dnode_t *ndn)
702 708 {
703 709 int i;
704 710
705 711 ASSERT(!RW_LOCK_HELD(&odn->dn_struct_rwlock));
706 712 ASSERT(MUTEX_NOT_HELD(&odn->dn_mtx));
707 713 ASSERT(MUTEX_NOT_HELD(&odn->dn_dbufs_mtx));
708 714 ASSERT(!RW_LOCK_HELD(&odn->dn_zfetch.zf_rwlock));
709 715
710 716 /* Copy fields. */
711 717 ndn->dn_objset = odn->dn_objset;
712 718 ndn->dn_object = odn->dn_object;
713 719 ndn->dn_dbuf = odn->dn_dbuf;
714 720 ndn->dn_handle = odn->dn_handle;
715 721 ndn->dn_phys = odn->dn_phys;
716 722 ndn->dn_type = odn->dn_type;
717 723 ndn->dn_bonuslen = odn->dn_bonuslen;
718 724 ndn->dn_bonustype = odn->dn_bonustype;
719 725 ndn->dn_nblkptr = odn->dn_nblkptr;
720 726 ndn->dn_checksum = odn->dn_checksum;
721 727 ndn->dn_compress = odn->dn_compress;
722 728 ndn->dn_nlevels = odn->dn_nlevels;
723 729 ndn->dn_indblkshift = odn->dn_indblkshift;
724 730 ndn->dn_datablkshift = odn->dn_datablkshift;
725 731 ndn->dn_datablkszsec = odn->dn_datablkszsec;
726 732 ndn->dn_datablksz = odn->dn_datablksz;
727 733 ndn->dn_maxblkid = odn->dn_maxblkid;
728 734 bcopy(&odn->dn_next_nblkptr[0], &ndn->dn_next_nblkptr[0],
729 735 sizeof (odn->dn_next_nblkptr));
730 736 bcopy(&odn->dn_next_nlevels[0], &ndn->dn_next_nlevels[0],
731 737 sizeof (odn->dn_next_nlevels));
732 738 bcopy(&odn->dn_next_indblkshift[0], &ndn->dn_next_indblkshift[0],
733 739 sizeof (odn->dn_next_indblkshift));
734 740 bcopy(&odn->dn_next_bonustype[0], &ndn->dn_next_bonustype[0],
735 741 sizeof (odn->dn_next_bonustype));
736 742 bcopy(&odn->dn_rm_spillblk[0], &ndn->dn_rm_spillblk[0],
737 743 sizeof (odn->dn_rm_spillblk));
738 744 bcopy(&odn->dn_next_bonuslen[0], &ndn->dn_next_bonuslen[0],
739 745 sizeof (odn->dn_next_bonuslen));
740 746 bcopy(&odn->dn_next_blksz[0], &ndn->dn_next_blksz[0],
741 747 sizeof (odn->dn_next_blksz));
742 748 for (i = 0; i < TXG_SIZE; i++) {
743 749 list_move_tail(&ndn->dn_dirty_records[i],
744 750 &odn->dn_dirty_records[i]);
745 751 }
746 752 bcopy(&odn->dn_free_ranges[0], &ndn->dn_free_ranges[0],
747 753 sizeof (odn->dn_free_ranges));
748 754 ndn->dn_allocated_txg = odn->dn_allocated_txg;
749 755 ndn->dn_free_txg = odn->dn_free_txg;
750 756 ndn->dn_assigned_txg = odn->dn_assigned_txg;
751 757 ndn->dn_dirtyctx = odn->dn_dirtyctx;
752 758 ndn->dn_dirtyctx_firstset = odn->dn_dirtyctx_firstset;
753 759 ASSERT(refcount_count(&odn->dn_tx_holds) == 0);
754 760 refcount_transfer(&ndn->dn_holds, &odn->dn_holds);
755 761 ASSERT(avl_is_empty(&ndn->dn_dbufs));
756 762 avl_swap(&ndn->dn_dbufs, &odn->dn_dbufs);
757 763 ndn->dn_dbufs_count = odn->dn_dbufs_count;
758 764 ndn->dn_bonus = odn->dn_bonus;
759 765 ndn->dn_have_spill = odn->dn_have_spill;
760 766 ndn->dn_zio = odn->dn_zio;
761 767 ndn->dn_oldused = odn->dn_oldused;
762 768 ndn->dn_oldflags = odn->dn_oldflags;
763 769 ndn->dn_olduid = odn->dn_olduid;
764 770 ndn->dn_oldgid = odn->dn_oldgid;
765 771 ndn->dn_newuid = odn->dn_newuid;
766 772 ndn->dn_newgid = odn->dn_newgid;
767 773 ndn->dn_id_flags = odn->dn_id_flags;
768 774 dmu_zfetch_init(&ndn->dn_zfetch, NULL);
769 775 list_move_tail(&ndn->dn_zfetch.zf_stream, &odn->dn_zfetch.zf_stream);
770 776 ndn->dn_zfetch.zf_dnode = odn->dn_zfetch.zf_dnode;
771 777
772 778 /*
773 779 * Update back pointers. Updating the handle fixes the back pointer of
774 780 * every descendant dbuf as well as the bonus dbuf.
775 781 */
776 782 ASSERT(ndn->dn_handle->dnh_dnode == odn);
777 783 ndn->dn_handle->dnh_dnode = ndn;
778 784 if (ndn->dn_zfetch.zf_dnode == odn) {
779 785 ndn->dn_zfetch.zf_dnode = ndn;
780 786 }
781 787
782 788 /*
783 789 * Invalidate the original dnode by clearing all of its back pointers.
784 790 */
785 791 odn->dn_dbuf = NULL;
786 792 odn->dn_handle = NULL;
787 793 avl_create(&odn->dn_dbufs, dbuf_compare, sizeof (dmu_buf_impl_t),
788 794 offsetof(dmu_buf_impl_t, db_link));
789 795 odn->dn_dbufs_count = 0;
790 796 odn->dn_bonus = NULL;
791 797 odn->dn_zfetch.zf_dnode = NULL;
792 798
793 799 /*
794 800 * Set the low bit of the objset pointer to ensure that dnode_move()
795 801 * recognizes the dnode as invalid in any subsequent callback.
796 802 */
797 803 POINTER_INVALIDATE(&odn->dn_objset);
798 804
799 805 /*
800 806 * Satisfy the destructor.
801 807 */
802 808 for (i = 0; i < TXG_SIZE; i++) {
803 809 list_create(&odn->dn_dirty_records[i],
804 810 sizeof (dbuf_dirty_record_t),
805 811 offsetof(dbuf_dirty_record_t, dr_dirty_node));
806 812 odn->dn_free_ranges[i] = NULL;
807 813 odn->dn_next_nlevels[i] = 0;
808 814 odn->dn_next_indblkshift[i] = 0;
809 815 odn->dn_next_bonustype[i] = 0;
810 816 odn->dn_rm_spillblk[i] = 0;
811 817 odn->dn_next_bonuslen[i] = 0;
812 818 odn->dn_next_blksz[i] = 0;
813 819 }
814 820 odn->dn_allocated_txg = 0;
815 821 odn->dn_free_txg = 0;
816 822 odn->dn_assigned_txg = 0;
817 823 odn->dn_dirtyctx = 0;
818 824 odn->dn_dirtyctx_firstset = NULL;
819 825 odn->dn_have_spill = B_FALSE;
820 826 odn->dn_zio = NULL;
821 827 odn->dn_oldused = 0;
822 828 odn->dn_oldflags = 0;
823 829 odn->dn_olduid = 0;
824 830 odn->dn_oldgid = 0;
825 831 odn->dn_newuid = 0;
↓ open down ↓ |
116 lines elided |
↑ open up ↑ |
826 832 odn->dn_newgid = 0;
827 833 odn->dn_id_flags = 0;
828 834
829 835 /*
830 836 * Mark the dnode.
831 837 */
832 838 ndn->dn_moved = 1;
833 839 odn->dn_moved = (uint8_t)-1;
834 840 }
835 841
836 -#ifdef _KERNEL
837 842 /*ARGSUSED*/
838 843 static kmem_cbrc_t
839 844 dnode_move(void *buf, void *newbuf, size_t size, void *arg)
840 845 {
841 846 dnode_t *odn = buf, *ndn = newbuf;
842 847 objset_t *os;
843 848 int64_t refcount;
844 849 uint32_t dbufs;
845 850
846 851 /*
847 852 * The dnode is on the objset's list of known dnodes if the objset
848 853 * pointer is valid. We set the low bit of the objset pointer when
849 854 * freeing the dnode to invalidate it, and the memory patterns written
850 855 * by kmem (baddcafe and deadbeef) set at least one of the two low bits.
851 856 * A newly created dnode sets the objset pointer last of all to indicate
852 857 * that the dnode is known and in a valid state to be moved by this
853 858 * function.
854 859 */
855 860 os = odn->dn_objset;
856 861 if (!POINTER_IS_VALID(os)) {
857 862 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_invalid);
858 863 return (KMEM_CBRC_DONT_KNOW);
859 864 }
860 865
861 866 /*
862 867 * Ensure that the objset does not go away during the move.
863 868 */
864 869 rw_enter(&os_lock, RW_WRITER);
865 870 if (os != odn->dn_objset) {
866 871 rw_exit(&os_lock);
867 872 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_recheck1);
868 873 return (KMEM_CBRC_DONT_KNOW);
869 874 }
870 875
871 876 /*
872 877 * If the dnode is still valid, then so is the objset. We know that no
873 878 * valid objset can be freed while we hold os_lock, so we can safely
874 879 * ensure that the objset remains in use.
875 880 */
876 881 mutex_enter(&os->os_lock);
877 882
878 883 /*
879 884 * Recheck the objset pointer in case the dnode was removed just before
880 885 * acquiring the lock.
881 886 */
882 887 if (os != odn->dn_objset) {
883 888 mutex_exit(&os->os_lock);
884 889 rw_exit(&os_lock);
885 890 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_recheck2);
886 891 return (KMEM_CBRC_DONT_KNOW);
887 892 }
888 893
889 894 /*
890 895 * At this point we know that as long as we hold os->os_lock, the dnode
891 896 * cannot be freed and fields within the dnode can be safely accessed.
892 897 * The objset listing this dnode cannot go away as long as this dnode is
893 898 * on its list.
894 899 */
895 900 rw_exit(&os_lock);
896 901 if (DMU_OBJECT_IS_SPECIAL(odn->dn_object)) {
897 902 mutex_exit(&os->os_lock);
898 903 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_special);
899 904 return (KMEM_CBRC_NO);
900 905 }
901 906 ASSERT(odn->dn_dbuf != NULL); /* only "special" dnodes have no parent */
902 907
903 908 /*
904 909 * Lock the dnode handle to prevent the dnode from obtaining any new
905 910 * holds. This also prevents the descendant dbufs and the bonus dbuf
906 911 * from accessing the dnode, so that we can discount their holds. The
907 912 * handle is safe to access because we know that while the dnode cannot
908 913 * go away, neither can its handle. Once we hold dnh_zrlock, we can
909 914 * safely move any dnode referenced only by dbufs.
910 915 */
911 916 if (!zrl_tryenter(&odn->dn_handle->dnh_zrlock)) {
912 917 mutex_exit(&os->os_lock);
913 918 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_handle);
914 919 return (KMEM_CBRC_LATER);
915 920 }
916 921
917 922 /*
918 923 * Ensure a consistent view of the dnode's holds and the dnode's dbufs.
919 924 * We need to guarantee that there is a hold for every dbuf in order to
920 925 * determine whether the dnode is actively referenced. Falsely matching
921 926 * a dbuf to an active hold would lead to an unsafe move. It's possible
922 927 * that a thread already having an active dnode hold is about to add a
923 928 * dbuf, and we can't compare hold and dbuf counts while the add is in
924 929 * progress.
925 930 */
926 931 if (!rw_tryenter(&odn->dn_struct_rwlock, RW_WRITER)) {
927 932 zrl_exit(&odn->dn_handle->dnh_zrlock);
928 933 mutex_exit(&os->os_lock);
929 934 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_rwlock);
930 935 return (KMEM_CBRC_LATER);
931 936 }
932 937
933 938 /*
934 939 * A dbuf may be removed (evicted) without an active dnode hold. In that
935 940 * case, the dbuf count is decremented under the handle lock before the
936 941 * dbuf's hold is released. This order ensures that if we count the hold
937 942 * after the dbuf is removed but before its hold is released, we will
938 943 * treat the unmatched hold as active and exit safely. If we count the
939 944 * hold before the dbuf is removed, the hold is discounted, and the
940 945 * removal is blocked until the move completes.
941 946 */
942 947 refcount = refcount_count(&odn->dn_holds);
943 948 ASSERT(refcount >= 0);
944 949 dbufs = odn->dn_dbufs_count;
945 950
946 951 /* We can't have more dbufs than dnode holds. */
947 952 ASSERT3U(dbufs, <=, refcount);
948 953 DTRACE_PROBE3(dnode__move, dnode_t *, odn, int64_t, refcount,
949 954 uint32_t, dbufs);
950 955
951 956 if (refcount > dbufs) {
952 957 rw_exit(&odn->dn_struct_rwlock);
953 958 zrl_exit(&odn->dn_handle->dnh_zrlock);
954 959 mutex_exit(&os->os_lock);
955 960 DNODE_STAT_ADD(dnode_move_stats.dms_dnode_active);
956 961 return (KMEM_CBRC_LATER);
957 962 }
958 963
959 964 rw_exit(&odn->dn_struct_rwlock);
960 965
961 966 /*
962 967 * At this point we know that anyone with a hold on the dnode is not
963 968 * actively referencing it. The dnode is known and in a valid state to
964 969 * move. We're holding the locks needed to execute the critical section.
965 970 */
966 971 dnode_move_impl(odn, ndn);
967 972
968 973 list_link_replace(&odn->dn_link, &ndn->dn_link);
969 974 /* If the dnode was safe to move, the refcount cannot have changed. */
970 975 ASSERT(refcount == refcount_count(&ndn->dn_holds));
971 976 ASSERT(dbufs == ndn->dn_dbufs_count);
972 977 zrl_exit(&ndn->dn_handle->dnh_zrlock); /* handle has moved */
973 978 mutex_exit(&os->os_lock);
974 979
975 980 return (KMEM_CBRC_YES);
976 981 }
977 982 #endif /* _KERNEL */
978 983
979 984 void
980 985 dnode_special_close(dnode_handle_t *dnh)
981 986 {
982 987 dnode_t *dn = dnh->dnh_dnode;
983 988
984 989 /*
985 990 * Wait for final references to the dnode to clear. This can
986 991 * only happen if the arc is asyncronously evicting state that
987 992 * has a hold on this dnode while we are trying to evict this
988 993 * dnode.
989 994 */
990 995 while (refcount_count(&dn->dn_holds) > 0)
991 996 delay(1);
992 997 ASSERT(dn->dn_dbuf == NULL ||
993 998 dmu_buf_get_user(&dn->dn_dbuf->db) == NULL);
994 999 zrl_add(&dnh->dnh_zrlock);
995 1000 dnode_destroy(dn); /* implicit zrl_remove() */
996 1001 zrl_destroy(&dnh->dnh_zrlock);
997 1002 dnh->dnh_dnode = NULL;
998 1003 }
999 1004
1000 1005 void
1001 1006 dnode_special_open(objset_t *os, dnode_phys_t *dnp, uint64_t object,
1002 1007 dnode_handle_t *dnh)
1003 1008 {
1004 1009 dnode_t *dn;
1005 1010
1006 1011 dn = dnode_create(os, dnp, NULL, object, dnh);
1007 1012 zrl_init(&dnh->dnh_zrlock);
1008 1013 DNODE_VERIFY(dn);
1009 1014 }
1010 1015
1011 1016 static void
1012 1017 dnode_buf_evict_async(void *dbu)
1013 1018 {
1014 1019 dnode_children_t *children_dnodes = dbu;
1015 1020 int i;
1016 1021
1017 1022 for (i = 0; i < children_dnodes->dnc_count; i++) {
1018 1023 dnode_handle_t *dnh = &children_dnodes->dnc_children[i];
1019 1024 dnode_t *dn;
1020 1025
1021 1026 /*
1022 1027 * The dnode handle lock guards against the dnode moving to
1023 1028 * another valid address, so there is no need here to guard
1024 1029 * against changes to or from NULL.
1025 1030 */
1026 1031 if (dnh->dnh_dnode == NULL) {
1027 1032 zrl_destroy(&dnh->dnh_zrlock);
1028 1033 continue;
1029 1034 }
1030 1035
1031 1036 zrl_add(&dnh->dnh_zrlock);
1032 1037 dn = dnh->dnh_dnode;
1033 1038 /*
1034 1039 * If there are holds on this dnode, then there should
1035 1040 * be holds on the dnode's containing dbuf as well; thus
1036 1041 * it wouldn't be eligible for eviction and this function
1037 1042 * would not have been called.
1038 1043 */
1039 1044 ASSERT(refcount_is_zero(&dn->dn_holds));
1040 1045 ASSERT(refcount_is_zero(&dn->dn_tx_holds));
1041 1046
1042 1047 dnode_destroy(dn); /* implicit zrl_remove() */
1043 1048 zrl_destroy(&dnh->dnh_zrlock);
1044 1049 dnh->dnh_dnode = NULL;
1045 1050 }
1046 1051 kmem_free(children_dnodes, sizeof (dnode_children_t) +
1047 1052 children_dnodes->dnc_count * sizeof (dnode_handle_t));
1048 1053 }
1049 1054
1050 1055 /*
1051 1056 * errors:
1052 1057 * EINVAL - invalid object number.
1053 1058 * EIO - i/o error.
1054 1059 * succeeds even for free dnodes.
1055 1060 */
1056 1061 int
1057 1062 dnode_hold_impl(objset_t *os, uint64_t object, int flag,
1058 1063 void *tag, dnode_t **dnp)
1059 1064 {
1060 1065 int epb, idx, err;
1061 1066 int drop_struct_lock = FALSE;
1062 1067 int type;
1063 1068 uint64_t blk;
1064 1069 dnode_t *mdn, *dn;
1065 1070 dmu_buf_impl_t *db;
1066 1071 dnode_children_t *children_dnodes;
1067 1072 dnode_handle_t *dnh;
1068 1073
1069 1074 /*
1070 1075 * If you are holding the spa config lock as writer, you shouldn't
1071 1076 * be asking the DMU to do *anything* unless it's the root pool
1072 1077 * which may require us to read from the root filesystem while
1073 1078 * holding some (not all) of the locks as writer.
1074 1079 */
1075 1080 ASSERT(spa_config_held(os->os_spa, SCL_ALL, RW_WRITER) == 0 ||
1076 1081 (spa_is_root(os->os_spa) &&
1077 1082 spa_config_held(os->os_spa, SCL_STATE, RW_WRITER)));
1078 1083
1079 1084 if (object == DMU_USERUSED_OBJECT || object == DMU_GROUPUSED_OBJECT) {
1080 1085 dn = (object == DMU_USERUSED_OBJECT) ?
1081 1086 DMU_USERUSED_DNODE(os) : DMU_GROUPUSED_DNODE(os);
1082 1087 if (dn == NULL)
1083 1088 return (SET_ERROR(ENOENT));
1084 1089 type = dn->dn_type;
1085 1090 if ((flag & DNODE_MUST_BE_ALLOCATED) && type == DMU_OT_NONE)
1086 1091 return (SET_ERROR(ENOENT));
1087 1092 if ((flag & DNODE_MUST_BE_FREE) && type != DMU_OT_NONE)
1088 1093 return (SET_ERROR(EEXIST));
1089 1094 DNODE_VERIFY(dn);
1090 1095 (void) refcount_add(&dn->dn_holds, tag);
1091 1096 *dnp = dn;
1092 1097 return (0);
1093 1098 }
1094 1099
1095 1100 if (object == 0 || object >= DN_MAX_OBJECT)
1096 1101 return (SET_ERROR(EINVAL));
1097 1102
1098 1103 mdn = DMU_META_DNODE(os);
1099 1104 ASSERT(mdn->dn_object == DMU_META_DNODE_OBJECT);
1100 1105
1101 1106 DNODE_VERIFY(mdn);
1102 1107
1103 1108 if (!RW_WRITE_HELD(&mdn->dn_struct_rwlock)) {
1104 1109 rw_enter(&mdn->dn_struct_rwlock, RW_READER);
1105 1110 drop_struct_lock = TRUE;
1106 1111 }
1107 1112
1108 1113 blk = dbuf_whichblock(mdn, 0, object * sizeof (dnode_phys_t));
1109 1114
1110 1115 db = dbuf_hold(mdn, blk, FTAG);
1111 1116 if (drop_struct_lock)
1112 1117 rw_exit(&mdn->dn_struct_rwlock);
1113 1118 if (db == NULL)
1114 1119 return (SET_ERROR(EIO));
1115 1120 err = dbuf_read(db, NULL, DB_RF_CANFAIL);
1116 1121 if (err) {
1117 1122 dbuf_rele(db, FTAG);
1118 1123 return (err);
1119 1124 }
1120 1125
1121 1126 ASSERT3U(db->db.db_size, >=, 1<<DNODE_SHIFT);
1122 1127 epb = db->db.db_size >> DNODE_SHIFT;
1123 1128
1124 1129 idx = object & (epb-1);
1125 1130
1126 1131 ASSERT(DB_DNODE(db)->dn_type == DMU_OT_DNODE);
1127 1132 children_dnodes = dmu_buf_get_user(&db->db);
1128 1133 if (children_dnodes == NULL) {
1129 1134 int i;
1130 1135 dnode_children_t *winner;
1131 1136 children_dnodes = kmem_zalloc(sizeof (dnode_children_t) +
1132 1137 epb * sizeof (dnode_handle_t), KM_SLEEP);
1133 1138 children_dnodes->dnc_count = epb;
1134 1139 dnh = &children_dnodes->dnc_children[0];
1135 1140 for (i = 0; i < epb; i++) {
1136 1141 zrl_init(&dnh[i].dnh_zrlock);
1137 1142 }
1138 1143 dmu_buf_init_user(&children_dnodes->dnc_dbu, NULL,
1139 1144 dnode_buf_evict_async, NULL);
1140 1145 winner = dmu_buf_set_user(&db->db, &children_dnodes->dnc_dbu);
1141 1146 if (winner != NULL) {
1142 1147
1143 1148 for (i = 0; i < epb; i++) {
1144 1149 zrl_destroy(&dnh[i].dnh_zrlock);
1145 1150 }
1146 1151
1147 1152 kmem_free(children_dnodes, sizeof (dnode_children_t) +
1148 1153 epb * sizeof (dnode_handle_t));
1149 1154 children_dnodes = winner;
1150 1155 }
1151 1156 }
1152 1157 ASSERT(children_dnodes->dnc_count == epb);
1153 1158
1154 1159 dnh = &children_dnodes->dnc_children[idx];
1155 1160 zrl_add(&dnh->dnh_zrlock);
1156 1161 dn = dnh->dnh_dnode;
1157 1162 if (dn == NULL) {
1158 1163 dnode_phys_t *phys = (dnode_phys_t *)db->db.db_data+idx;
1159 1164
1160 1165 dn = dnode_create(os, phys, db, object, dnh);
1161 1166 }
1162 1167
1163 1168 mutex_enter(&dn->dn_mtx);
1164 1169 type = dn->dn_type;
1165 1170 if (dn->dn_free_txg ||
1166 1171 ((flag & DNODE_MUST_BE_ALLOCATED) && type == DMU_OT_NONE) ||
1167 1172 ((flag & DNODE_MUST_BE_FREE) &&
1168 1173 (type != DMU_OT_NONE || !refcount_is_zero(&dn->dn_holds)))) {
1169 1174 mutex_exit(&dn->dn_mtx);
1170 1175 zrl_remove(&dnh->dnh_zrlock);
1171 1176 dbuf_rele(db, FTAG);
1172 1177 return (type == DMU_OT_NONE ? ENOENT : EEXIST);
1173 1178 }
1174 1179 if (refcount_add(&dn->dn_holds, tag) == 1)
1175 1180 dbuf_add_ref(db, dnh);
1176 1181 mutex_exit(&dn->dn_mtx);
1177 1182
1178 1183 /* Now we can rely on the hold to prevent the dnode from moving. */
1179 1184 zrl_remove(&dnh->dnh_zrlock);
1180 1185
1181 1186 DNODE_VERIFY(dn);
1182 1187 ASSERT3P(dn->dn_dbuf, ==, db);
1183 1188 ASSERT3U(dn->dn_object, ==, object);
1184 1189 dbuf_rele(db, FTAG);
1185 1190
1186 1191 *dnp = dn;
1187 1192 return (0);
1188 1193 }
1189 1194
1190 1195 /*
1191 1196 * Return held dnode if the object is allocated, NULL if not.
1192 1197 */
1193 1198 int
1194 1199 dnode_hold(objset_t *os, uint64_t object, void *tag, dnode_t **dnp)
1195 1200 {
1196 1201 return (dnode_hold_impl(os, object, DNODE_MUST_BE_ALLOCATED, tag, dnp));
1197 1202 }
1198 1203
1199 1204 /*
1200 1205 * Can only add a reference if there is already at least one
1201 1206 * reference on the dnode. Returns FALSE if unable to add a
1202 1207 * new reference.
1203 1208 */
1204 1209 boolean_t
1205 1210 dnode_add_ref(dnode_t *dn, void *tag)
1206 1211 {
1207 1212 mutex_enter(&dn->dn_mtx);
1208 1213 if (refcount_is_zero(&dn->dn_holds)) {
1209 1214 mutex_exit(&dn->dn_mtx);
1210 1215 return (FALSE);
1211 1216 }
1212 1217 VERIFY(1 < refcount_add(&dn->dn_holds, tag));
1213 1218 mutex_exit(&dn->dn_mtx);
1214 1219 return (TRUE);
1215 1220 }
1216 1221
1217 1222 void
1218 1223 dnode_rele(dnode_t *dn, void *tag)
1219 1224 {
1220 1225 mutex_enter(&dn->dn_mtx);
1221 1226 dnode_rele_and_unlock(dn, tag);
1222 1227 }
1223 1228
1224 1229 void
1225 1230 dnode_rele_and_unlock(dnode_t *dn, void *tag)
1226 1231 {
1227 1232 uint64_t refs;
1228 1233 /* Get while the hold prevents the dnode from moving. */
1229 1234 dmu_buf_impl_t *db = dn->dn_dbuf;
1230 1235 dnode_handle_t *dnh = dn->dn_handle;
1231 1236
1232 1237 refs = refcount_remove(&dn->dn_holds, tag);
1233 1238 mutex_exit(&dn->dn_mtx);
1234 1239
1235 1240 /*
1236 1241 * It's unsafe to release the last hold on a dnode by dnode_rele() or
1237 1242 * indirectly by dbuf_rele() while relying on the dnode handle to
1238 1243 * prevent the dnode from moving, since releasing the last hold could
1239 1244 * result in the dnode's parent dbuf evicting its dnode handles. For
1240 1245 * that reason anyone calling dnode_rele() or dbuf_rele() without some
1241 1246 * other direct or indirect hold on the dnode must first drop the dnode
1242 1247 * handle.
1243 1248 */
1244 1249 ASSERT(refs > 0 || dnh->dnh_zrlock.zr_owner != curthread);
1245 1250
1246 1251 /* NOTE: the DNODE_DNODE does not have a dn_dbuf */
1247 1252 if (refs == 0 && db != NULL) {
1248 1253 /*
1249 1254 * Another thread could add a hold to the dnode handle in
1250 1255 * dnode_hold_impl() while holding the parent dbuf. Since the
1251 1256 * hold on the parent dbuf prevents the handle from being
1252 1257 * destroyed, the hold on the handle is OK. We can't yet assert
1253 1258 * that the handle has zero references, but that will be
1254 1259 * asserted anyway when the handle gets destroyed.
1255 1260 */
1256 1261 dbuf_rele(db, dnh);
1257 1262 }
1258 1263 }
1259 1264
1260 1265 void
1261 1266 dnode_setdirty(dnode_t *dn, dmu_tx_t *tx)
1262 1267 {
1263 1268 objset_t *os = dn->dn_objset;
1264 1269 uint64_t txg = tx->tx_txg;
1265 1270
1266 1271 if (DMU_OBJECT_IS_SPECIAL(dn->dn_object)) {
1267 1272 dsl_dataset_dirty(os->os_dsl_dataset, tx);
1268 1273 return;
1269 1274 }
1270 1275
1271 1276 DNODE_VERIFY(dn);
1272 1277
1273 1278 #ifdef ZFS_DEBUG
1274 1279 mutex_enter(&dn->dn_mtx);
1275 1280 ASSERT(dn->dn_phys->dn_type || dn->dn_allocated_txg);
1276 1281 ASSERT(dn->dn_free_txg == 0 || dn->dn_free_txg >= txg);
1277 1282 mutex_exit(&dn->dn_mtx);
1278 1283 #endif
1279 1284
1280 1285 /*
1281 1286 * Determine old uid/gid when necessary
1282 1287 */
1283 1288 dmu_objset_userquota_get_ids(dn, B_TRUE, tx);
1284 1289
1285 1290 multilist_t *dirtylist = os->os_dirty_dnodes[txg & TXG_MASK];
1286 1291 multilist_sublist_t *mls = multilist_sublist_lock_obj(dirtylist, dn);
1287 1292
1288 1293 /*
1289 1294 * If we are already marked dirty, we're done.
1290 1295 */
1291 1296 if (list_link_active(&dn->dn_dirty_link[txg & TXG_MASK])) {
1292 1297 multilist_sublist_unlock(mls);
1293 1298 return;
1294 1299 }
1295 1300
1296 1301 ASSERT(!refcount_is_zero(&dn->dn_holds) ||
1297 1302 !avl_is_empty(&dn->dn_dbufs));
1298 1303 ASSERT(dn->dn_datablksz != 0);
1299 1304 ASSERT0(dn->dn_next_bonuslen[txg&TXG_MASK]);
1300 1305 ASSERT0(dn->dn_next_blksz[txg&TXG_MASK]);
1301 1306 ASSERT0(dn->dn_next_bonustype[txg&TXG_MASK]);
1302 1307
1303 1308 dprintf_ds(os->os_dsl_dataset, "obj=%llu txg=%llu\n",
1304 1309 dn->dn_object, txg);
1305 1310
1306 1311 multilist_sublist_insert_head(mls, dn);
1307 1312
1308 1313 multilist_sublist_unlock(mls);
1309 1314
1310 1315 /*
1311 1316 * The dnode maintains a hold on its containing dbuf as
1312 1317 * long as there are holds on it. Each instantiated child
1313 1318 * dbuf maintains a hold on the dnode. When the last child
1314 1319 * drops its hold, the dnode will drop its hold on the
1315 1320 * containing dbuf. We add a "dirty hold" here so that the
1316 1321 * dnode will hang around after we finish processing its
1317 1322 * children.
1318 1323 */
1319 1324 VERIFY(dnode_add_ref(dn, (void *)(uintptr_t)tx->tx_txg));
1320 1325
1321 1326 (void) dbuf_dirty(dn->dn_dbuf, tx);
1322 1327
1323 1328 dsl_dataset_dirty(os->os_dsl_dataset, tx);
1324 1329 }
1325 1330
1326 1331 void
1327 1332 dnode_free(dnode_t *dn, dmu_tx_t *tx)
1328 1333 {
1329 1334 mutex_enter(&dn->dn_mtx);
1330 1335 if (dn->dn_type == DMU_OT_NONE || dn->dn_free_txg) {
1331 1336 mutex_exit(&dn->dn_mtx);
1332 1337 return;
1333 1338 }
1334 1339 dn->dn_free_txg = tx->tx_txg;
1335 1340 mutex_exit(&dn->dn_mtx);
1336 1341
1337 1342 dnode_setdirty(dn, tx);
1338 1343 }
1339 1344
1340 1345 /*
1341 1346 * Try to change the block size for the indicated dnode. This can only
1342 1347 * succeed if there are no blocks allocated or dirty beyond first block
1343 1348 */
1344 1349 int
1345 1350 dnode_set_blksz(dnode_t *dn, uint64_t size, int ibs, dmu_tx_t *tx)
1346 1351 {
1347 1352 dmu_buf_impl_t *db;
1348 1353 int err;
1349 1354
1350 1355 ASSERT3U(size, <=, spa_maxblocksize(dmu_objset_spa(dn->dn_objset)));
1351 1356 if (size == 0)
1352 1357 size = SPA_MINBLOCKSIZE;
1353 1358 else
1354 1359 size = P2ROUNDUP(size, SPA_MINBLOCKSIZE);
1355 1360
1356 1361 if (ibs == dn->dn_indblkshift)
1357 1362 ibs = 0;
1358 1363
1359 1364 if (size >> SPA_MINBLOCKSHIFT == dn->dn_datablkszsec && ibs == 0)
1360 1365 return (0);
1361 1366
1362 1367 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
1363 1368
1364 1369 /* Check for any allocated blocks beyond the first */
1365 1370 if (dn->dn_maxblkid != 0)
1366 1371 goto fail;
1367 1372
1368 1373 mutex_enter(&dn->dn_dbufs_mtx);
1369 1374 for (db = avl_first(&dn->dn_dbufs); db != NULL;
1370 1375 db = AVL_NEXT(&dn->dn_dbufs, db)) {
1371 1376 if (db->db_blkid != 0 && db->db_blkid != DMU_BONUS_BLKID &&
1372 1377 db->db_blkid != DMU_SPILL_BLKID) {
1373 1378 mutex_exit(&dn->dn_dbufs_mtx);
1374 1379 goto fail;
1375 1380 }
1376 1381 }
1377 1382 mutex_exit(&dn->dn_dbufs_mtx);
1378 1383
1379 1384 if (ibs && dn->dn_nlevels != 1)
1380 1385 goto fail;
1381 1386
1382 1387 /* resize the old block */
1383 1388 err = dbuf_hold_impl(dn, 0, 0, TRUE, FALSE, FTAG, &db);
1384 1389 if (err == 0)
1385 1390 dbuf_new_size(db, size, tx);
1386 1391 else if (err != ENOENT)
1387 1392 goto fail;
1388 1393
1389 1394 dnode_setdblksz(dn, size);
1390 1395 dnode_setdirty(dn, tx);
1391 1396 dn->dn_next_blksz[tx->tx_txg&TXG_MASK] = size;
1392 1397 if (ibs) {
1393 1398 dn->dn_indblkshift = ibs;
1394 1399 dn->dn_next_indblkshift[tx->tx_txg&TXG_MASK] = ibs;
1395 1400 }
1396 1401 /* rele after we have fixed the blocksize in the dnode */
1397 1402 if (db)
1398 1403 dbuf_rele(db, FTAG);
1399 1404
1400 1405 rw_exit(&dn->dn_struct_rwlock);
1401 1406 return (0);
1402 1407
1403 1408 fail:
1404 1409 rw_exit(&dn->dn_struct_rwlock);
1405 1410 return (SET_ERROR(ENOTSUP));
1406 1411 }
1407 1412
1408 1413 /* read-holding callers must not rely on the lock being continuously held */
1409 1414 void
1410 1415 dnode_new_blkid(dnode_t *dn, uint64_t blkid, dmu_tx_t *tx, boolean_t have_read)
1411 1416 {
1412 1417 uint64_t txgoff = tx->tx_txg & TXG_MASK;
1413 1418 int epbs, new_nlevels;
1414 1419 uint64_t sz;
1415 1420
1416 1421 ASSERT(blkid != DMU_BONUS_BLKID);
1417 1422
1418 1423 ASSERT(have_read ?
1419 1424 RW_READ_HELD(&dn->dn_struct_rwlock) :
1420 1425 RW_WRITE_HELD(&dn->dn_struct_rwlock));
1421 1426
1422 1427 /*
1423 1428 * if we have a read-lock, check to see if we need to do any work
1424 1429 * before upgrading to a write-lock.
1425 1430 */
1426 1431 if (have_read) {
1427 1432 if (blkid <= dn->dn_maxblkid)
1428 1433 return;
1429 1434
1430 1435 if (!rw_tryupgrade(&dn->dn_struct_rwlock)) {
1431 1436 rw_exit(&dn->dn_struct_rwlock);
1432 1437 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
1433 1438 }
1434 1439 }
1435 1440
1436 1441 if (blkid <= dn->dn_maxblkid)
1437 1442 goto out;
1438 1443
1439 1444 dn->dn_maxblkid = blkid;
1440 1445
1441 1446 /*
1442 1447 * Compute the number of levels necessary to support the new maxblkid.
1443 1448 */
1444 1449 new_nlevels = 1;
1445 1450 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;
1446 1451 for (sz = dn->dn_nblkptr;
1447 1452 sz <= blkid && sz >= dn->dn_nblkptr; sz <<= epbs)
1448 1453 new_nlevels++;
1449 1454
1450 1455 if (new_nlevels > dn->dn_nlevels) {
1451 1456 int old_nlevels = dn->dn_nlevels;
1452 1457 dmu_buf_impl_t *db;
1453 1458 list_t *list;
1454 1459 dbuf_dirty_record_t *new, *dr, *dr_next;
1455 1460
1456 1461 dn->dn_nlevels = new_nlevels;
1457 1462
1458 1463 ASSERT3U(new_nlevels, >, dn->dn_next_nlevels[txgoff]);
1459 1464 dn->dn_next_nlevels[txgoff] = new_nlevels;
1460 1465
1461 1466 /* dirty the left indirects */
1462 1467 db = dbuf_hold_level(dn, old_nlevels, 0, FTAG);
1463 1468 ASSERT(db != NULL);
1464 1469 new = dbuf_dirty(db, tx);
1465 1470 dbuf_rele(db, FTAG);
1466 1471
1467 1472 /* transfer the dirty records to the new indirect */
1468 1473 mutex_enter(&dn->dn_mtx);
1469 1474 mutex_enter(&new->dt.di.dr_mtx);
1470 1475 list = &dn->dn_dirty_records[txgoff];
1471 1476 for (dr = list_head(list); dr; dr = dr_next) {
1472 1477 dr_next = list_next(&dn->dn_dirty_records[txgoff], dr);
1473 1478 if (dr->dr_dbuf->db_level != new_nlevels-1 &&
1474 1479 dr->dr_dbuf->db_blkid != DMU_BONUS_BLKID &&
1475 1480 dr->dr_dbuf->db_blkid != DMU_SPILL_BLKID) {
1476 1481 ASSERT(dr->dr_dbuf->db_level == old_nlevels-1);
1477 1482 list_remove(&dn->dn_dirty_records[txgoff], dr);
1478 1483 list_insert_tail(&new->dt.di.dr_children, dr);
1479 1484 dr->dr_parent = new;
1480 1485 }
1481 1486 }
1482 1487 mutex_exit(&new->dt.di.dr_mtx);
1483 1488 mutex_exit(&dn->dn_mtx);
1484 1489 }
1485 1490
1486 1491 out:
1487 1492 if (have_read)
1488 1493 rw_downgrade(&dn->dn_struct_rwlock);
1489 1494 }
1490 1495
1491 1496 static void
1492 1497 dnode_dirty_l1(dnode_t *dn, uint64_t l1blkid, dmu_tx_t *tx)
1493 1498 {
1494 1499 dmu_buf_impl_t *db = dbuf_hold_level(dn, 1, l1blkid, FTAG);
1495 1500 if (db != NULL) {
1496 1501 dmu_buf_will_dirty(&db->db, tx);
1497 1502 dbuf_rele(db, FTAG);
1498 1503 }
1499 1504 }
1500 1505
1501 1506 void
1502 1507 dnode_free_range(dnode_t *dn, uint64_t off, uint64_t len, dmu_tx_t *tx)
1503 1508 {
1504 1509 dmu_buf_impl_t *db;
1505 1510 uint64_t blkoff, blkid, nblks;
1506 1511 int blksz, blkshift, head, tail;
1507 1512 int trunc = FALSE;
1508 1513 int epbs;
1509 1514
1510 1515 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
1511 1516 blksz = dn->dn_datablksz;
1512 1517 blkshift = dn->dn_datablkshift;
1513 1518 epbs = dn->dn_indblkshift - SPA_BLKPTRSHIFT;
1514 1519
1515 1520 if (len == DMU_OBJECT_END) {
1516 1521 len = UINT64_MAX - off;
1517 1522 trunc = TRUE;
1518 1523 }
1519 1524
1520 1525 /*
1521 1526 * First, block align the region to free:
1522 1527 */
1523 1528 if (ISP2(blksz)) {
1524 1529 head = P2NPHASE(off, blksz);
1525 1530 blkoff = P2PHASE(off, blksz);
1526 1531 if ((off >> blkshift) > dn->dn_maxblkid)
1527 1532 goto out;
1528 1533 } else {
1529 1534 ASSERT(dn->dn_maxblkid == 0);
1530 1535 if (off == 0 && len >= blksz) {
1531 1536 /*
1532 1537 * Freeing the whole block; fast-track this request.
1533 1538 * Note that we won't dirty any indirect blocks,
1534 1539 * which is fine because we will be freeing the entire
1535 1540 * file and thus all indirect blocks will be freed
1536 1541 * by free_children().
1537 1542 */
1538 1543 blkid = 0;
1539 1544 nblks = 1;
1540 1545 goto done;
1541 1546 } else if (off >= blksz) {
1542 1547 /* Freeing past end-of-data */
1543 1548 goto out;
1544 1549 } else {
1545 1550 /* Freeing part of the block. */
1546 1551 head = blksz - off;
1547 1552 ASSERT3U(head, >, 0);
1548 1553 }
1549 1554 blkoff = off;
1550 1555 }
1551 1556 /* zero out any partial block data at the start of the range */
1552 1557 if (head) {
1553 1558 ASSERT3U(blkoff + head, ==, blksz);
1554 1559 if (len < head)
1555 1560 head = len;
1556 1561 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, 0, off),
1557 1562 TRUE, FALSE, FTAG, &db) == 0) {
1558 1563 caddr_t data;
1559 1564
1560 1565 /* don't dirty if it isn't on disk and isn't dirty */
1561 1566 if (db->db_last_dirty ||
1562 1567 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) {
1563 1568 rw_exit(&dn->dn_struct_rwlock);
1564 1569 dmu_buf_will_dirty(&db->db, tx);
1565 1570 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
1566 1571 data = db->db.db_data;
1567 1572 bzero(data + blkoff, head);
1568 1573 }
1569 1574 dbuf_rele(db, FTAG);
1570 1575 }
1571 1576 off += head;
1572 1577 len -= head;
1573 1578 }
1574 1579
1575 1580 /* If the range was less than one block, we're done */
1576 1581 if (len == 0)
1577 1582 goto out;
1578 1583
1579 1584 /* If the remaining range is past end of file, we're done */
1580 1585 if ((off >> blkshift) > dn->dn_maxblkid)
1581 1586 goto out;
1582 1587
1583 1588 ASSERT(ISP2(blksz));
1584 1589 if (trunc)
1585 1590 tail = 0;
1586 1591 else
1587 1592 tail = P2PHASE(len, blksz);
1588 1593
1589 1594 ASSERT0(P2PHASE(off, blksz));
1590 1595 /* zero out any partial block data at the end of the range */
1591 1596 if (tail) {
1592 1597 if (len < tail)
1593 1598 tail = len;
1594 1599 if (dbuf_hold_impl(dn, 0, dbuf_whichblock(dn, 0, off+len),
1595 1600 TRUE, FALSE, FTAG, &db) == 0) {
1596 1601 /* don't dirty if not on disk and not dirty */
1597 1602 if (db->db_last_dirty ||
1598 1603 (db->db_blkptr && !BP_IS_HOLE(db->db_blkptr))) {
1599 1604 rw_exit(&dn->dn_struct_rwlock);
1600 1605 dmu_buf_will_dirty(&db->db, tx);
1601 1606 rw_enter(&dn->dn_struct_rwlock, RW_WRITER);
1602 1607 bzero(db->db.db_data, tail);
1603 1608 }
1604 1609 dbuf_rele(db, FTAG);
1605 1610 }
1606 1611 len -= tail;
1607 1612 }
1608 1613
1609 1614 /* If the range did not include a full block, we are done */
1610 1615 if (len == 0)
1611 1616 goto out;
1612 1617
1613 1618 ASSERT(IS_P2ALIGNED(off, blksz));
1614 1619 ASSERT(trunc || IS_P2ALIGNED(len, blksz));
1615 1620 blkid = off >> blkshift;
1616 1621 nblks = len >> blkshift;
1617 1622 if (trunc)
1618 1623 nblks += 1;
1619 1624
1620 1625 /*
1621 1626 * Dirty all the indirect blocks in this range. Note that only
1622 1627 * the first and last indirect blocks can actually be written
1623 1628 * (if they were partially freed) -- they must be dirtied, even if
1624 1629 * they do not exist on disk yet. The interior blocks will
1625 1630 * be freed by free_children(), so they will not actually be written.
1626 1631 * Even though these interior blocks will not be written, we
1627 1632 * dirty them for two reasons:
1628 1633 *
1629 1634 * - It ensures that the indirect blocks remain in memory until
1630 1635 * syncing context. (They have already been prefetched by
1631 1636 * dmu_tx_hold_free(), so we don't have to worry about reading
1632 1637 * them serially here.)
1633 1638 *
1634 1639 * - The dirty space accounting will put pressure on the txg sync
1635 1640 * mechanism to begin syncing, and to delay transactions if there
1636 1641 * is a large amount of freeing. Even though these indirect
1637 1642 * blocks will not be written, we could need to write the same
1638 1643 * amount of space if we copy the freed BPs into deadlists.
1639 1644 */
1640 1645 if (dn->dn_nlevels > 1) {
1641 1646 uint64_t first, last;
1642 1647
1643 1648 first = blkid >> epbs;
1644 1649 dnode_dirty_l1(dn, first, tx);
1645 1650 if (trunc)
1646 1651 last = dn->dn_maxblkid >> epbs;
1647 1652 else
1648 1653 last = (blkid + nblks - 1) >> epbs;
1649 1654 if (last != first)
1650 1655 dnode_dirty_l1(dn, last, tx);
1651 1656
1652 1657 int shift = dn->dn_datablkshift + dn->dn_indblkshift -
1653 1658 SPA_BLKPTRSHIFT;
1654 1659 for (uint64_t i = first + 1; i < last; i++) {
1655 1660 /*
1656 1661 * Set i to the blockid of the next non-hole
1657 1662 * level-1 indirect block at or after i. Note
1658 1663 * that dnode_next_offset() operates in terms of
1659 1664 * level-0-equivalent bytes.
1660 1665 */
1661 1666 uint64_t ibyte = i << shift;
1662 1667 int err = dnode_next_offset(dn, DNODE_FIND_HAVELOCK,
1663 1668 &ibyte, 2, 1, 0);
1664 1669 i = ibyte >> shift;
1665 1670 if (i >= last)
1666 1671 break;
1667 1672
1668 1673 /*
1669 1674 * Normally we should not see an error, either
1670 1675 * from dnode_next_offset() or dbuf_hold_level()
1671 1676 * (except for ESRCH from dnode_next_offset).
1672 1677 * If there is an i/o error, then when we read
1673 1678 * this block in syncing context, it will use
1674 1679 * ZIO_FLAG_MUSTSUCCEED, and thus hang/panic according
1675 1680 * to the "failmode" property. dnode_next_offset()
1676 1681 * doesn't have a flag to indicate MUSTSUCCEED.
1677 1682 */
1678 1683 if (err != 0)
1679 1684 break;
1680 1685
1681 1686 dnode_dirty_l1(dn, i, tx);
1682 1687 }
1683 1688 }
1684 1689
1685 1690 done:
1686 1691 /*
1687 1692 * Add this range to the dnode range list.
1688 1693 * We will finish up this free operation in the syncing phase.
1689 1694 */
1690 1695 mutex_enter(&dn->dn_mtx);
1691 1696 int txgoff = tx->tx_txg & TXG_MASK;
1692 1697 if (dn->dn_free_ranges[txgoff] == NULL) {
1693 1698 dn->dn_free_ranges[txgoff] =
1694 1699 range_tree_create(NULL, NULL, &dn->dn_mtx);
1695 1700 }
1696 1701 range_tree_clear(dn->dn_free_ranges[txgoff], blkid, nblks);
1697 1702 range_tree_add(dn->dn_free_ranges[txgoff], blkid, nblks);
1698 1703 dprintf_dnode(dn, "blkid=%llu nblks=%llu txg=%llu\n",
1699 1704 blkid, nblks, tx->tx_txg);
1700 1705 mutex_exit(&dn->dn_mtx);
1701 1706
1702 1707 dbuf_free_range(dn, blkid, blkid + nblks - 1, tx);
1703 1708 dnode_setdirty(dn, tx);
1704 1709 out:
1705 1710
1706 1711 rw_exit(&dn->dn_struct_rwlock);
1707 1712 }
1708 1713
1709 1714 static boolean_t
1710 1715 dnode_spill_freed(dnode_t *dn)
1711 1716 {
1712 1717 int i;
1713 1718
1714 1719 mutex_enter(&dn->dn_mtx);
1715 1720 for (i = 0; i < TXG_SIZE; i++) {
1716 1721 if (dn->dn_rm_spillblk[i] == DN_KILL_SPILLBLK)
1717 1722 break;
1718 1723 }
1719 1724 mutex_exit(&dn->dn_mtx);
1720 1725 return (i < TXG_SIZE);
1721 1726 }
1722 1727
1723 1728 /* return TRUE if this blkid was freed in a recent txg, or FALSE if it wasn't */
1724 1729 uint64_t
1725 1730 dnode_block_freed(dnode_t *dn, uint64_t blkid)
1726 1731 {
1727 1732 void *dp = spa_get_dsl(dn->dn_objset->os_spa);
1728 1733 int i;
1729 1734
1730 1735 if (blkid == DMU_BONUS_BLKID)
1731 1736 return (FALSE);
1732 1737
1733 1738 /*
1734 1739 * If we're in the process of opening the pool, dp will not be
1735 1740 * set yet, but there shouldn't be anything dirty.
1736 1741 */
1737 1742 if (dp == NULL)
1738 1743 return (FALSE);
1739 1744
1740 1745 if (dn->dn_free_txg)
1741 1746 return (TRUE);
1742 1747
1743 1748 if (blkid == DMU_SPILL_BLKID)
1744 1749 return (dnode_spill_freed(dn));
1745 1750
1746 1751 mutex_enter(&dn->dn_mtx);
1747 1752 for (i = 0; i < TXG_SIZE; i++) {
1748 1753 if (dn->dn_free_ranges[i] != NULL &&
1749 1754 range_tree_contains(dn->dn_free_ranges[i], blkid, 1))
1750 1755 break;
1751 1756 }
1752 1757 mutex_exit(&dn->dn_mtx);
1753 1758 return (i < TXG_SIZE);
1754 1759 }
1755 1760
1756 1761 /* call from syncing context when we actually write/free space for this dnode */
1757 1762 void
1758 1763 dnode_diduse_space(dnode_t *dn, int64_t delta)
1759 1764 {
1760 1765 uint64_t space;
1761 1766 dprintf_dnode(dn, "dn=%p dnp=%p used=%llu delta=%lld\n",
1762 1767 dn, dn->dn_phys,
1763 1768 (u_longlong_t)dn->dn_phys->dn_used,
1764 1769 (longlong_t)delta);
1765 1770
1766 1771 mutex_enter(&dn->dn_mtx);
1767 1772 space = DN_USED_BYTES(dn->dn_phys);
1768 1773 if (delta > 0) {
1769 1774 ASSERT3U(space + delta, >=, space); /* no overflow */
1770 1775 } else {
1771 1776 ASSERT3U(space, >=, -delta); /* no underflow */
1772 1777 }
1773 1778 space += delta;
1774 1779 if (spa_version(dn->dn_objset->os_spa) < SPA_VERSION_DNODE_BYTES) {
1775 1780 ASSERT((dn->dn_phys->dn_flags & DNODE_FLAG_USED_BYTES) == 0);
1776 1781 ASSERT0(P2PHASE(space, 1<<DEV_BSHIFT));
1777 1782 dn->dn_phys->dn_used = space >> DEV_BSHIFT;
1778 1783 } else {
1779 1784 dn->dn_phys->dn_used = space;
1780 1785 dn->dn_phys->dn_flags |= DNODE_FLAG_USED_BYTES;
1781 1786 }
1782 1787 mutex_exit(&dn->dn_mtx);
1783 1788 }
1784 1789
1785 1790 /*
1786 1791 * Scans a block at the indicated "level" looking for a hole or data,
1787 1792 * depending on 'flags'.
1788 1793 *
1789 1794 * If level > 0, then we are scanning an indirect block looking at its
1790 1795 * pointers. If level == 0, then we are looking at a block of dnodes.
1791 1796 *
1792 1797 * If we don't find what we are looking for in the block, we return ESRCH.
1793 1798 * Otherwise, return with *offset pointing to the beginning (if searching
1794 1799 * forwards) or end (if searching backwards) of the range covered by the
1795 1800 * block pointer we matched on (or dnode).
1796 1801 *
1797 1802 * The basic search algorithm used below by dnode_next_offset() is to
1798 1803 * use this function to search up the block tree (widen the search) until
1799 1804 * we find something (i.e., we don't return ESRCH) and then search back
1800 1805 * down the tree (narrow the search) until we reach our original search
1801 1806 * level.
1802 1807 */
1803 1808 static int
1804 1809 dnode_next_offset_level(dnode_t *dn, int flags, uint64_t *offset,
1805 1810 int lvl, uint64_t blkfill, uint64_t txg)
1806 1811 {
1807 1812 dmu_buf_impl_t *db = NULL;
1808 1813 void *data = NULL;
1809 1814 uint64_t epbs = dn->dn_phys->dn_indblkshift - SPA_BLKPTRSHIFT;
1810 1815 uint64_t epb = 1ULL << epbs;
1811 1816 uint64_t minfill, maxfill;
1812 1817 boolean_t hole;
1813 1818 int i, inc, error, span;
1814 1819
1815 1820 dprintf("probing object %llu offset %llx level %d of %u\n",
1816 1821 dn->dn_object, *offset, lvl, dn->dn_phys->dn_nlevels);
1817 1822
1818 1823 hole = ((flags & DNODE_FIND_HOLE) != 0);
1819 1824 inc = (flags & DNODE_FIND_BACKWARDS) ? -1 : 1;
1820 1825 ASSERT(txg == 0 || !hole);
1821 1826
1822 1827 if (lvl == dn->dn_phys->dn_nlevels) {
1823 1828 error = 0;
1824 1829 epb = dn->dn_phys->dn_nblkptr;
1825 1830 data = dn->dn_phys->dn_blkptr;
1826 1831 } else {
1827 1832 uint64_t blkid = dbuf_whichblock(dn, lvl, *offset);
1828 1833 error = dbuf_hold_impl(dn, lvl, blkid, TRUE, FALSE, FTAG, &db);
1829 1834 if (error) {
1830 1835 if (error != ENOENT)
1831 1836 return (error);
1832 1837 if (hole)
1833 1838 return (0);
1834 1839 /*
1835 1840 * This can only happen when we are searching up
1836 1841 * the block tree for data. We don't really need to
1837 1842 * adjust the offset, as we will just end up looking
1838 1843 * at the pointer to this block in its parent, and its
1839 1844 * going to be unallocated, so we will skip over it.
1840 1845 */
1841 1846 return (SET_ERROR(ESRCH));
1842 1847 }
1843 1848 error = dbuf_read(db, NULL, DB_RF_CANFAIL | DB_RF_HAVESTRUCT);
1844 1849 if (error) {
1845 1850 dbuf_rele(db, FTAG);
1846 1851 return (error);
1847 1852 }
1848 1853 data = db->db.db_data;
1849 1854 }
1850 1855
1851 1856
1852 1857 if (db != NULL && txg != 0 && (db->db_blkptr == NULL ||
1853 1858 db->db_blkptr->blk_birth <= txg ||
1854 1859 BP_IS_HOLE(db->db_blkptr))) {
1855 1860 /*
1856 1861 * This can only happen when we are searching up the tree
1857 1862 * and these conditions mean that we need to keep climbing.
1858 1863 */
1859 1864 error = SET_ERROR(ESRCH);
1860 1865 } else if (lvl == 0) {
1861 1866 dnode_phys_t *dnp = data;
1862 1867 span = DNODE_SHIFT;
1863 1868 ASSERT(dn->dn_type == DMU_OT_DNODE);
1864 1869
1865 1870 for (i = (*offset >> span) & (blkfill - 1);
1866 1871 i >= 0 && i < blkfill; i += inc) {
1867 1872 if ((dnp[i].dn_type == DMU_OT_NONE) == hole)
1868 1873 break;
1869 1874 *offset += (1ULL << span) * inc;
1870 1875 }
1871 1876 if (i < 0 || i == blkfill)
1872 1877 error = SET_ERROR(ESRCH);
1873 1878 } else {
1874 1879 blkptr_t *bp = data;
1875 1880 uint64_t start = *offset;
1876 1881 span = (lvl - 1) * epbs + dn->dn_datablkshift;
1877 1882 minfill = 0;
1878 1883 maxfill = blkfill << ((lvl - 1) * epbs);
1879 1884
1880 1885 if (hole)
1881 1886 maxfill--;
1882 1887 else
1883 1888 minfill++;
1884 1889
1885 1890 *offset = *offset >> span;
1886 1891 for (i = BF64_GET(*offset, 0, epbs);
1887 1892 i >= 0 && i < epb; i += inc) {
1888 1893 if (BP_GET_FILL(&bp[i]) >= minfill &&
1889 1894 BP_GET_FILL(&bp[i]) <= maxfill &&
1890 1895 (hole || bp[i].blk_birth > txg))
1891 1896 break;
1892 1897 if (inc > 0 || *offset > 0)
1893 1898 *offset += inc;
1894 1899 }
1895 1900 *offset = *offset << span;
1896 1901 if (inc < 0) {
1897 1902 /* traversing backwards; position offset at the end */
1898 1903 ASSERT3U(*offset, <=, start);
1899 1904 *offset = MIN(*offset + (1ULL << span) - 1, start);
1900 1905 } else if (*offset < start) {
1901 1906 *offset = start;
1902 1907 }
1903 1908 if (i < 0 || i >= epb)
1904 1909 error = SET_ERROR(ESRCH);
1905 1910 }
1906 1911
1907 1912 if (db)
1908 1913 dbuf_rele(db, FTAG);
1909 1914
1910 1915 return (error);
1911 1916 }
1912 1917
1913 1918 /*
1914 1919 * Find the next hole, data, or sparse region at or after *offset.
1915 1920 * The value 'blkfill' tells us how many items we expect to find
1916 1921 * in an L0 data block; this value is 1 for normal objects,
1917 1922 * DNODES_PER_BLOCK for the meta dnode, and some fraction of
1918 1923 * DNODES_PER_BLOCK when searching for sparse regions thereof.
1919 1924 *
1920 1925 * Examples:
1921 1926 *
1922 1927 * dnode_next_offset(dn, flags, offset, 1, 1, 0);
1923 1928 * Finds the next/previous hole/data in a file.
1924 1929 * Used in dmu_offset_next().
1925 1930 *
1926 1931 * dnode_next_offset(mdn, flags, offset, 0, DNODES_PER_BLOCK, txg);
1927 1932 * Finds the next free/allocated dnode an objset's meta-dnode.
1928 1933 * Only finds objects that have new contents since txg (ie.
1929 1934 * bonus buffer changes and content removal are ignored).
1930 1935 * Used in dmu_object_next().
1931 1936 *
1932 1937 * dnode_next_offset(mdn, DNODE_FIND_HOLE, offset, 2, DNODES_PER_BLOCK >> 2, 0);
1933 1938 * Finds the next L2 meta-dnode bp that's at most 1/4 full.
1934 1939 * Used in dmu_object_alloc().
1935 1940 */
1936 1941 int
1937 1942 dnode_next_offset(dnode_t *dn, int flags, uint64_t *offset,
1938 1943 int minlvl, uint64_t blkfill, uint64_t txg)
1939 1944 {
1940 1945 uint64_t initial_offset = *offset;
1941 1946 int lvl, maxlvl;
1942 1947 int error = 0;
1943 1948
1944 1949 if (!(flags & DNODE_FIND_HAVELOCK))
1945 1950 rw_enter(&dn->dn_struct_rwlock, RW_READER);
1946 1951
1947 1952 if (dn->dn_phys->dn_nlevels == 0) {
1948 1953 error = SET_ERROR(ESRCH);
1949 1954 goto out;
1950 1955 }
1951 1956
1952 1957 if (dn->dn_datablkshift == 0) {
1953 1958 if (*offset < dn->dn_datablksz) {
1954 1959 if (flags & DNODE_FIND_HOLE)
1955 1960 *offset = dn->dn_datablksz;
1956 1961 } else {
1957 1962 error = SET_ERROR(ESRCH);
1958 1963 }
1959 1964 goto out;
1960 1965 }
1961 1966
1962 1967 maxlvl = dn->dn_phys->dn_nlevels;
1963 1968
1964 1969 for (lvl = minlvl; lvl <= maxlvl; lvl++) {
1965 1970 error = dnode_next_offset_level(dn,
1966 1971 flags, offset, lvl, blkfill, txg);
1967 1972 if (error != ESRCH)
1968 1973 break;
1969 1974 }
1970 1975
1971 1976 while (error == 0 && --lvl >= minlvl) {
1972 1977 error = dnode_next_offset_level(dn,
1973 1978 flags, offset, lvl, blkfill, txg);
1974 1979 }
1975 1980
1976 1981 /*
1977 1982 * There's always a "virtual hole" at the end of the object, even
1978 1983 * if all BP's which physically exist are non-holes.
1979 1984 */
1980 1985 if ((flags & DNODE_FIND_HOLE) && error == ESRCH && txg == 0 &&
1981 1986 minlvl == 1 && blkfill == 1 && !(flags & DNODE_FIND_BACKWARDS)) {
1982 1987 error = 0;
1983 1988 }
1984 1989
1985 1990 if (error == 0 && (flags & DNODE_FIND_BACKWARDS ?
1986 1991 initial_offset < *offset : initial_offset > *offset))
1987 1992 error = SET_ERROR(ESRCH);
1988 1993 out:
1989 1994 if (!(flags & DNODE_FIND_HAVELOCK))
1990 1995 rw_exit(&dn->dn_struct_rwlock);
1991 1996
1992 1997 return (error);
1993 1998 }
↓ open down ↓ |
1147 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX