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

Function zio_encrypt

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

* This function is used for ZIO_STAGE_ENCRYPT. It is responsible for * managing the storage of encryption parameters and passing them to the * lower-level encryption functions. */

Source from the content-addressed store, hash-verified

4056 * lower-level encryption functions.
4057 */
4058static zio_t *
4059zio_encrypt(zio_t *zio)
4060{
4061 zio_prop_t *zp = &zio->io_prop;
4062 spa_t *spa = zio->io_spa;
4063 blkptr_t *bp = zio->io_bp;
4064 uint64_t psize = BP_GET_PSIZE(bp);
4065 uint64_t dsobj = zio->io_bookmark.zb_objset;
4066 dmu_object_type_t ot = BP_GET_TYPE(bp);
4067 void *enc_buf = NULL;
4068 abd_t *eabd = NULL;
4069 uint8_t salt[ZIO_DATA_SALT_LEN];
4070 uint8_t iv[ZIO_DATA_IV_LEN];
4071 uint8_t mac[ZIO_DATA_MAC_LEN];
4072 boolean_t no_crypt = B_FALSE;
4073
4074 /* the root zio already encrypted the data */
4075 if (zio->io_child_type == ZIO_CHILD_GANG)
4076 return (zio);
4077
4078 /* only ZIL blocks are re-encrypted on rewrite */
4079 if (!IO_IS_ALLOCATING(zio) && ot != DMU_OT_INTENT_LOG)
4080 return (zio);
4081
4082 if (!(zp->zp_encrypt || BP_IS_ENCRYPTED(bp))) {
4083 BP_SET_CRYPT(bp, B_FALSE);
4084 return (zio);
4085 }
4086
4087 /* if we are doing raw encryption set the provided encryption params */
4088 if (zio->io_flags & ZIO_FLAG_RAW_ENCRYPT) {
4089 ASSERT0(BP_GET_LEVEL(bp));
4090 BP_SET_CRYPT(bp, B_TRUE);
4091 BP_SET_BYTEORDER(bp, zp->zp_byteorder);
4092 if (ot != DMU_OT_OBJSET)
4093 zio_crypt_encode_mac_bp(bp, zp->zp_mac);
4094
4095 /* dnode blocks must be written out in the provided byteorder */
4096 if (zp->zp_byteorder != ZFS_HOST_BYTEORDER &&
4097 ot == DMU_OT_DNODE) {
4098 void *bswap_buf = zio_buf_alloc(psize);
4099 abd_t *babd = abd_get_from_buf(bswap_buf, psize);
4100
4101 ASSERT3U(BP_GET_COMPRESS(bp), ==, ZIO_COMPRESS_OFF);
4102 abd_copy_to_buf(bswap_buf, zio->io_abd, psize);
4103 dmu_ot_byteswap[DMU_OT_BYTESWAP(ot)].ob_func(bswap_buf,
4104 psize);
4105
4106 abd_take_ownership_of_buf(babd, B_TRUE);
4107 zio_push_transform(zio, babd, psize, psize, NULL);
4108 }
4109
4110 if (DMU_OT_IS_ENCRYPTED(ot))
4111 zio_crypt_encode_params_bp(bp, zp->zp_salt, zp->zp_iv);
4112 return (zio);
4113 }
4114
4115 /* indirect blocks only maintain a cksum of the lower level MACs */

Callers

nothing calls this directly

Calls 15

zio_buf_allocFunction · 0.85
abd_get_from_bufFunction · 0.85
abd_copy_to_bufFunction · 0.85
zio_push_transformFunction · 0.85
spa_do_crypt_mac_abdFunction · 0.85
spa_feature_is_activeFunction · 0.85
spa_do_crypt_abdFunction · 0.85
abd_freeFunction · 0.85
zio_crypt_encode_mac_bpFunction · 0.50

Tested by

no test coverage detected