* Transition between the two allocation states for the arc_buf_hdr struct. * The arc_buf_hdr struct can be allocated with (hdr_full_cache) or without * (hdr_l2only_cache) the fields necessary for the L1 cache - the smaller * version is used when a cache buffer is only in the L2ARC in order to reduce * memory usage. */
| 3353 | * memory usage. |
| 3354 | */ |
| 3355 | static arc_buf_hdr_t * |
| 3356 | arc_hdr_realloc(arc_buf_hdr_t *hdr, kmem_cache_t *old, kmem_cache_t *new) |
| 3357 | { |
| 3358 | ASSERT(HDR_HAS_L2HDR(hdr)); |
| 3359 | |
| 3360 | arc_buf_hdr_t *nhdr; |
| 3361 | l2arc_dev_t *dev = hdr->b_l2hdr.b_dev; |
| 3362 | |
| 3363 | ASSERT((old == hdr_full_cache && new == hdr_l2only_cache) || |
| 3364 | (old == hdr_l2only_cache && new == hdr_full_cache)); |
| 3365 | |
| 3366 | /* |
| 3367 | * if the caller wanted a new full header and the header is to be |
| 3368 | * encrypted we will actually allocate the header from the full crypt |
| 3369 | * cache instead. The same applies to freeing from the old cache. |
| 3370 | */ |
| 3371 | if (HDR_PROTECTED(hdr) && new == hdr_full_cache) |
| 3372 | new = hdr_full_crypt_cache; |
| 3373 | if (HDR_PROTECTED(hdr) && old == hdr_full_cache) |
| 3374 | old = hdr_full_crypt_cache; |
| 3375 | |
| 3376 | nhdr = kmem_cache_alloc(new, KM_PUSHPAGE); |
| 3377 | |
| 3378 | ASSERT(MUTEX_HELD(HDR_LOCK(hdr))); |
| 3379 | buf_hash_remove(hdr); |
| 3380 | |
| 3381 | bcopy(hdr, nhdr, HDR_L2ONLY_SIZE); |
| 3382 | |
| 3383 | if (new == hdr_full_cache || new == hdr_full_crypt_cache) { |
| 3384 | arc_hdr_set_flags(nhdr, ARC_FLAG_HAS_L1HDR); |
| 3385 | /* |
| 3386 | * arc_access and arc_change_state need to be aware that a |
| 3387 | * header has just come out of L2ARC, so we set its state to |
| 3388 | * l2c_only even though it's about to change. |
| 3389 | */ |
| 3390 | nhdr->b_l1hdr.b_state = arc_l2c_only; |
| 3391 | |
| 3392 | /* Verify previous threads set to NULL before freeing */ |
| 3393 | ASSERT3P(nhdr->b_l1hdr.b_pabd, ==, NULL); |
| 3394 | ASSERT(!HDR_HAS_RABD(hdr)); |
| 3395 | } else { |
| 3396 | ASSERT3P(hdr->b_l1hdr.b_buf, ==, NULL); |
| 3397 | ASSERT0(hdr->b_l1hdr.b_bufcnt); |
| 3398 | ASSERT3P(hdr->b_l1hdr.b_freeze_cksum, ==, NULL); |
| 3399 | |
| 3400 | /* |
| 3401 | * If we've reached here, We must have been called from |
| 3402 | * arc_evict_hdr(), as such we should have already been |
| 3403 | * removed from any ghost list we were previously on |
| 3404 | * (which protects us from racing with arc_evict_state), |
| 3405 | * thus no locking is needed during this check. |
| 3406 | */ |
| 3407 | ASSERT(!multilist_link_active(&hdr->b_l1hdr.b_arc_node)); |
| 3408 | |
| 3409 | /* |
| 3410 | * A buffer must not be moved into the arc_l2c_only |
| 3411 | * state if it's not finished being written out to the |
| 3412 | * l2arc device. Otherwise, the b_l1hdr.b_pabd field |
no test coverage detected