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

Function zio_decrypt

freebsd/contrib/openzfs/module/zfs/zio.c:455–584  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453}
454
455static void
456zio_decrypt(zio_t *zio, abd_t *data, uint64_t size)
457{
458 int ret;
459 void *tmp;
460 blkptr_t *bp = zio->io_bp;
461 spa_t *spa = zio->io_spa;
462 uint64_t dsobj = zio->io_bookmark.zb_objset;
463 uint64_t lsize = BP_GET_LSIZE(bp);
464 dmu_object_type_t ot = BP_GET_TYPE(bp);
465 uint8_t salt[ZIO_DATA_SALT_LEN];
466 uint8_t iv[ZIO_DATA_IV_LEN];
467 uint8_t mac[ZIO_DATA_MAC_LEN];
468 boolean_t no_crypt = B_FALSE;
469
470 ASSERT(BP_USES_CRYPT(bp));
471 ASSERT3U(size, !=, 0);
472
473 if (zio->io_error != 0)
474 return;
475
476 /*
477 * Verify the cksum of MACs stored in an indirect bp. It will always
478 * be possible to verify this since it does not require an encryption
479 * key.
480 */
481 if (BP_HAS_INDIRECT_MAC_CKSUM(bp)) {
482 zio_crypt_decode_mac_bp(bp, mac);
483
484 if (BP_GET_COMPRESS(bp) != ZIO_COMPRESS_OFF) {
485 /*
486 * We haven't decompressed the data yet, but
487 * zio_crypt_do_indirect_mac_checksum() requires
488 * decompressed data to be able to parse out the MACs
489 * from the indirect block. We decompress it now and
490 * throw away the result after we are finished.
491 */
492 tmp = zio_buf_alloc(lsize);
493 ret = zio_decompress_data(BP_GET_COMPRESS(bp),
494 zio->io_abd, tmp, zio->io_size, lsize,
495 &zio->io_prop.zp_complevel);
496 if (ret != 0) {
497 ret = SET_ERROR(EIO);
498 goto error;
499 }
500 ret = zio_crypt_do_indirect_mac_checksum(B_FALSE,
501 tmp, lsize, BP_SHOULD_BYTESWAP(bp), mac);
502 zio_buf_free(tmp, lsize);
503 } else {
504 ret = zio_crypt_do_indirect_mac_checksum_abd(B_FALSE,
505 zio->io_abd, size, BP_SHOULD_BYTESWAP(bp), mac);
506 }
507 abd_copy(data, zio->io_abd, size);
508
509 if (zio_injection_enabled && ot != DMU_OT_DNODE && ret == 0) {
510 ret = zio_handle_decrypt_injection(spa,
511 &zio->io_bookmark, ot, ECKSUM);
512 }

Callers

nothing calls this directly

Calls 15

zio_buf_allocFunction · 0.85
zio_decompress_dataFunction · 0.85
zio_buf_freeFunction · 0.85
abd_copyFunction · 0.85
spa_do_crypt_mac_abdFunction · 0.85
abd_borrow_buf_copyFunction · 0.85
abd_return_bufFunction · 0.85
spa_do_crypt_abdFunction · 0.85
spa_log_errorFunction · 0.85
zfs_ereport_postFunction · 0.85

Tested by

no test coverage detected