| 442 | } |
| 443 | |
| 444 | static dnode_t * |
| 445 | dnode_create(objset_t *os, dnode_phys_t *dnp, dmu_buf_impl_t *db, |
| 446 | uint64_t object, dnode_handle_t *dnh) |
| 447 | { |
| 448 | dnode_t *dn; |
| 449 | |
| 450 | dn = kmem_cache_alloc(dnode_cache, KM_SLEEP); |
| 451 | dn->dn_moved = 0; |
| 452 | |
| 453 | /* |
| 454 | * Defer setting dn_objset until the dnode is ready to be a candidate |
| 455 | * for the dnode_move() callback. |
| 456 | */ |
| 457 | dn->dn_object = object; |
| 458 | dn->dn_dbuf = db; |
| 459 | dn->dn_handle = dnh; |
| 460 | dn->dn_phys = dnp; |
| 461 | |
| 462 | if (dnp->dn_datablkszsec) { |
| 463 | dnode_setdblksz(dn, dnp->dn_datablkszsec << SPA_MINBLOCKSHIFT); |
| 464 | } else { |
| 465 | dn->dn_datablksz = 0; |
| 466 | dn->dn_datablkszsec = 0; |
| 467 | dn->dn_datablkshift = 0; |
| 468 | } |
| 469 | dn->dn_indblkshift = dnp->dn_indblkshift; |
| 470 | dn->dn_nlevels = dnp->dn_nlevels; |
| 471 | dn->dn_type = dnp->dn_type; |
| 472 | dn->dn_nblkptr = dnp->dn_nblkptr; |
| 473 | dn->dn_checksum = dnp->dn_checksum; |
| 474 | dn->dn_compress = dnp->dn_compress; |
| 475 | dn->dn_bonustype = dnp->dn_bonustype; |
| 476 | dn->dn_bonuslen = dnp->dn_bonuslen; |
| 477 | dn->dn_num_slots = dnp->dn_extra_slots + 1; |
| 478 | dn->dn_maxblkid = dnp->dn_maxblkid; |
| 479 | dn->dn_have_spill = ((dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR) != 0); |
| 480 | dn->dn_id_flags = 0; |
| 481 | |
| 482 | dmu_zfetch_init(&dn->dn_zfetch, dn); |
| 483 | |
| 484 | ASSERT(DMU_OT_IS_VALID(dn->dn_phys->dn_type)); |
| 485 | ASSERT(zrl_is_locked(&dnh->dnh_zrlock)); |
| 486 | ASSERT(!DN_SLOT_IS_PTR(dnh->dnh_dnode)); |
| 487 | |
| 488 | mutex_enter(&os->os_lock); |
| 489 | |
| 490 | /* |
| 491 | * Exclude special dnodes from os_dnodes so an empty os_dnodes |
| 492 | * signifies that the special dnodes have no references from |
| 493 | * their children (the entries in os_dnodes). This allows |
| 494 | * dnode_destroy() to easily determine if the last child has |
| 495 | * been removed and then complete eviction of the objset. |
| 496 | */ |
| 497 | if (!DMU_OBJECT_IS_SPECIAL(object)) |
| 498 | list_insert_head(&os->os_dnodes, dn); |
| 499 | membar_producer(); |
| 500 | |
| 501 | /* |
no test coverage detected