| 3301 | } |
| 3302 | |
| 3303 | static arc_buf_hdr_t * |
| 3304 | arc_hdr_alloc(uint64_t spa, int32_t psize, int32_t lsize, |
| 3305 | boolean_t protected, enum zio_compress compression_type, uint8_t complevel, |
| 3306 | arc_buf_contents_t type, boolean_t alloc_rdata) |
| 3307 | { |
| 3308 | arc_buf_hdr_t *hdr; |
| 3309 | int flags = ARC_HDR_DO_ADAPT; |
| 3310 | |
| 3311 | VERIFY(type == ARC_BUFC_DATA || type == ARC_BUFC_METADATA); |
| 3312 | if (protected) { |
| 3313 | hdr = kmem_cache_alloc(hdr_full_crypt_cache, KM_PUSHPAGE); |
| 3314 | } else { |
| 3315 | hdr = kmem_cache_alloc(hdr_full_cache, KM_PUSHPAGE); |
| 3316 | } |
| 3317 | flags |= alloc_rdata ? ARC_HDR_ALLOC_RDATA : 0; |
| 3318 | |
| 3319 | ASSERT(HDR_EMPTY(hdr)); |
| 3320 | ASSERT3P(hdr->b_l1hdr.b_freeze_cksum, ==, NULL); |
| 3321 | HDR_SET_PSIZE(hdr, psize); |
| 3322 | HDR_SET_LSIZE(hdr, lsize); |
| 3323 | hdr->b_spa = spa; |
| 3324 | hdr->b_type = type; |
| 3325 | hdr->b_flags = 0; |
| 3326 | arc_hdr_set_flags(hdr, arc_bufc_to_flags(type) | ARC_FLAG_HAS_L1HDR); |
| 3327 | arc_hdr_set_compress(hdr, compression_type); |
| 3328 | hdr->b_complevel = complevel; |
| 3329 | if (protected) |
| 3330 | arc_hdr_set_flags(hdr, ARC_FLAG_PROTECTED); |
| 3331 | |
| 3332 | hdr->b_l1hdr.b_state = arc_anon; |
| 3333 | hdr->b_l1hdr.b_arc_access = 0; |
| 3334 | hdr->b_l1hdr.b_bufcnt = 0; |
| 3335 | hdr->b_l1hdr.b_buf = NULL; |
| 3336 | |
| 3337 | /* |
| 3338 | * Allocate the hdr's buffer. This will contain either |
| 3339 | * the compressed or uncompressed data depending on the block |
| 3340 | * it references and compressed arc enablement. |
| 3341 | */ |
| 3342 | arc_hdr_alloc_abd(hdr, flags); |
| 3343 | ASSERT(zfs_refcount_is_zero(&hdr->b_l1hdr.b_refcnt)); |
| 3344 | |
| 3345 | return (hdr); |
| 3346 | } |
| 3347 | |
| 3348 | /* |
| 3349 | * Transition between the two allocation states for the arc_buf_hdr struct. |
no test coverage detected