From a490875103659bfb58cae1778c0f326c2111dd66 Mon Sep 17 00:00:00 2001 From: Alexander Motin Date: Wed, 22 Nov 2023 13:15:32 -0500 Subject: [PATCH] ZIL: Refactor TX_WRITE encryption similar to TX_CLONE_RANGE It should be purely textual change to make the code more readable. Should cause no functional difference. Reviewed-by: Richard Yao Reviewed-by: Tom Caputi Reviewed-by: Sean Eric Fagan Reviewed-by: Brian Behlendorf Reviewed-by: Edmund Nadolski Signed-off-by: Alexander Motin Sponsored by: iXsystems, Inc. Closes #15543 Closes #15513 --- module/os/freebsd/zfs/zio_crypt.c | 18 ++++++------------ module/os/linux/zfs/zio_crypt.c | 12 ++++-------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/module/os/freebsd/zfs/zio_crypt.c b/module/os/freebsd/zfs/zio_crypt.c index 024a931d78..74755eb6d9 100644 --- a/module/os/freebsd/zfs/zio_crypt.c +++ b/module/os/freebsd/zfs/zio_crypt.c @@ -1338,19 +1338,14 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf, * authenticate it. */ if (txtype == TX_WRITE) { - crypt_len = sizeof (lr_write_t) - - sizeof (lr_t) - sizeof (blkptr_t); - dst_iovecs[vec].iov_base = (char *)dlrp + - sizeof (lr_t); + const size_t o = offsetof(lr_write_t, lr_blkptr); + crypt_len = o - sizeof (lr_t); + dst_iovecs[vec].iov_base = (char *)dlrp + sizeof (lr_t); dst_iovecs[vec].iov_len = crypt_len; /* copy the bp now since it will not be encrypted */ - memcpy(dlrp + sizeof (lr_write_t) - sizeof (blkptr_t), - slrp + sizeof (lr_write_t) - sizeof (blkptr_t), - sizeof (blkptr_t)); - memcpy(aadp, - slrp + sizeof (lr_write_t) - sizeof (blkptr_t), - sizeof (blkptr_t)); + memcpy(dlrp + o, slrp + o, sizeof (blkptr_t)); + memcpy(aadp, slrp + o, sizeof (blkptr_t)); aadp += sizeof (blkptr_t); aad_len += sizeof (blkptr_t); vec++; @@ -1379,8 +1374,7 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf, total_len += crypt_len; } else { crypt_len = lr_len - sizeof (lr_t); - dst_iovecs[vec].iov_base = (char *)dlrp + - sizeof (lr_t); + dst_iovecs[vec].iov_base = (char *)dlrp + sizeof (lr_t); dst_iovecs[vec].iov_len = crypt_len; vec++; total_len += crypt_len; diff --git a/module/os/linux/zfs/zio_crypt.c b/module/os/linux/zfs/zio_crypt.c index 775ab8efbc..55f807ccfc 100644 --- a/module/os/linux/zfs/zio_crypt.c +++ b/module/os/linux/zfs/zio_crypt.c @@ -1513,20 +1513,16 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf, * authenticate it. */ if (txtype == TX_WRITE) { - crypt_len = sizeof (lr_write_t) - - sizeof (lr_t) - sizeof (blkptr_t); + const size_t o = offsetof(lr_write_t, lr_blkptr); + crypt_len = o - sizeof (lr_t); src_iovecs[nr_iovecs].iov_base = slrp + sizeof (lr_t); src_iovecs[nr_iovecs].iov_len = crypt_len; dst_iovecs[nr_iovecs].iov_base = dlrp + sizeof (lr_t); dst_iovecs[nr_iovecs].iov_len = crypt_len; /* copy the bp now since it will not be encrypted */ - memcpy(dlrp + sizeof (lr_write_t) - sizeof (blkptr_t), - slrp + sizeof (lr_write_t) - sizeof (blkptr_t), - sizeof (blkptr_t)); - memcpy(aadp, - slrp + sizeof (lr_write_t) - sizeof (blkptr_t), - sizeof (blkptr_t)); + memcpy(dlrp + o, slrp + o, sizeof (blkptr_t)); + memcpy(aadp, slrp + o, sizeof (blkptr_t)); aadp += sizeof (blkptr_t); aad_len += sizeof (blkptr_t); nr_iovecs++;