MCPcopy Create free account
hub / github.com/F-Stack/f-stack / arc_buf_fill

Function arc_buf_fill

freebsd/contrib/openzfs/module/zfs/arc.c:2017–2191  ·  view source on GitHub ↗

* Given a buf that has a data buffer attached to it, this function will * efficiently fill the buf with data of the specified compression setting from * the hdr and update the hdr's b_freeze_cksum if necessary. If the buf and hdr * are already sharing a data buf, no copy is performed. * * If the buf is marked as compressed but uncompressed data was requested, this * will allocate a new data

Source from the content-addressed store, hash-verified

2015 * the correct-sized data buffer.
2016 */
2017static int
2018arc_buf_fill(arc_buf_t *buf, spa_t *spa, const zbookmark_phys_t *zb,
2019 arc_fill_flags_t flags)
2020{
2021 int error = 0;
2022 arc_buf_hdr_t *hdr = buf->b_hdr;
2023 boolean_t hdr_compressed =
2024 (arc_hdr_get_compress(hdr) != ZIO_COMPRESS_OFF);
2025 boolean_t compressed = (flags & ARC_FILL_COMPRESSED) != 0;
2026 boolean_t encrypted = (flags & ARC_FILL_ENCRYPTED) != 0;
2027 dmu_object_byteswap_t bswap = hdr->b_l1hdr.b_byteswap;
2028 kmutex_t *hash_lock = (flags & ARC_FILL_LOCKED) ? NULL : HDR_LOCK(hdr);
2029
2030 ASSERT3P(buf->b_data, !=, NULL);
2031 IMPLY(compressed, hdr_compressed || ARC_BUF_ENCRYPTED(buf));
2032 IMPLY(compressed, ARC_BUF_COMPRESSED(buf));
2033 IMPLY(encrypted, HDR_ENCRYPTED(hdr));
2034 IMPLY(encrypted, ARC_BUF_ENCRYPTED(buf));
2035 IMPLY(encrypted, ARC_BUF_COMPRESSED(buf));
2036 IMPLY(encrypted, !ARC_BUF_SHARED(buf));
2037
2038 /*
2039 * If the caller wanted encrypted data we just need to copy it from
2040 * b_rabd and potentially byteswap it. We won't be able to do any
2041 * further transforms on it.
2042 */
2043 if (encrypted) {
2044 ASSERT(HDR_HAS_RABD(hdr));
2045 abd_copy_to_buf(buf->b_data, hdr->b_crypt_hdr.b_rabd,
2046 HDR_GET_PSIZE(hdr));
2047 goto byteswap;
2048 }
2049
2050 /*
2051 * Adjust encrypted and authenticated headers to accommodate
2052 * the request if needed. Dnode blocks (ARC_FILL_IN_PLACE) are
2053 * allowed to fail decryption due to keys not being loaded
2054 * without being marked as an IO error.
2055 */
2056 if (HDR_PROTECTED(hdr)) {
2057 error = arc_fill_hdr_crypt(hdr, hash_lock, spa,
2058 zb, !!(flags & ARC_FILL_NOAUTH));
2059 if (error == EACCES && (flags & ARC_FILL_IN_PLACE) != 0) {
2060 return (error);
2061 } else if (error != 0) {
2062 if (hash_lock != NULL)
2063 mutex_enter(hash_lock);
2064 arc_hdr_set_flags(hdr, ARC_FLAG_IO_ERROR);
2065 if (hash_lock != NULL)
2066 mutex_exit(hash_lock);
2067 return (error);
2068 }
2069 }
2070
2071 /*
2072 * There is a special case here for dnode blocks which are
2073 * decrypting their bonus buffers. These blocks may request to
2074 * be decrypted in-place. This is necessary because there may

Callers 2

arc_untransformFunction · 0.85
arc_buf_alloc_implFunction · 0.85

Calls 15

arc_hdr_get_compressFunction · 0.85
abd_copy_to_bufFunction · 0.85
arc_fill_hdr_cryptFunction · 0.85
mutex_enterFunction · 0.85
arc_hdr_set_flagsFunction · 0.85
mutex_exitFunction · 0.85
arc_cksum_computeFunction · 0.85
arc_buf_is_sharedFunction · 0.85
arc_buf_sizeFunction · 0.85
arc_get_data_bufFunction · 0.85
arc_hdr_clear_flagsFunction · 0.85

Tested by

no test coverage detected