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 <richard.yao@alumni.stonybrook.edu>
Reviewed-by: Tom Caputi <caputit1@tcnj.edu>
Reviewed-by: Sean Eric Fagan <sef@FreeBSD.org>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Edmund Nadolski <edmund.nadolski@ixsystems.com>
Signed-off-by: Alexander Motin <mav@FreeBSD.org>
Sponsored by: iXsystems, Inc.
Closes #15543
Closes #15513
This commit is contained in:
Alexander Motin 2023-11-22 13:15:32 -05:00 committed by Brian Behlendorf
parent 27d8c23c58
commit a490875103
2 changed files with 10 additions and 20 deletions

View File

@ -1338,19 +1338,14 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf,
* authenticate it. * authenticate it.
*/ */
if (txtype == TX_WRITE) { if (txtype == TX_WRITE) {
crypt_len = sizeof (lr_write_t) - const size_t o = offsetof(lr_write_t, lr_blkptr);
sizeof (lr_t) - sizeof (blkptr_t); crypt_len = o - sizeof (lr_t);
dst_iovecs[vec].iov_base = (char *)dlrp + dst_iovecs[vec].iov_base = (char *)dlrp + sizeof (lr_t);
sizeof (lr_t);
dst_iovecs[vec].iov_len = crypt_len; dst_iovecs[vec].iov_len = crypt_len;
/* copy the bp now since it will not be encrypted */ /* copy the bp now since it will not be encrypted */
memcpy(dlrp + sizeof (lr_write_t) - sizeof (blkptr_t), memcpy(dlrp + o, slrp + o, sizeof (blkptr_t));
slrp + sizeof (lr_write_t) - sizeof (blkptr_t), memcpy(aadp, slrp + o, sizeof (blkptr_t));
sizeof (blkptr_t));
memcpy(aadp,
slrp + sizeof (lr_write_t) - sizeof (blkptr_t),
sizeof (blkptr_t));
aadp += sizeof (blkptr_t); aadp += sizeof (blkptr_t);
aad_len += sizeof (blkptr_t); aad_len += sizeof (blkptr_t);
vec++; vec++;
@ -1379,8 +1374,7 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf,
total_len += crypt_len; total_len += crypt_len;
} else { } else {
crypt_len = lr_len - sizeof (lr_t); crypt_len = lr_len - sizeof (lr_t);
dst_iovecs[vec].iov_base = (char *)dlrp + dst_iovecs[vec].iov_base = (char *)dlrp + sizeof (lr_t);
sizeof (lr_t);
dst_iovecs[vec].iov_len = crypt_len; dst_iovecs[vec].iov_len = crypt_len;
vec++; vec++;
total_len += crypt_len; total_len += crypt_len;

View File

@ -1513,20 +1513,16 @@ zio_crypt_init_uios_zil(boolean_t encrypt, uint8_t *plainbuf,
* authenticate it. * authenticate it.
*/ */
if (txtype == TX_WRITE) { if (txtype == TX_WRITE) {
crypt_len = sizeof (lr_write_t) - const size_t o = offsetof(lr_write_t, lr_blkptr);
sizeof (lr_t) - sizeof (blkptr_t); crypt_len = o - sizeof (lr_t);
src_iovecs[nr_iovecs].iov_base = slrp + sizeof (lr_t); src_iovecs[nr_iovecs].iov_base = slrp + sizeof (lr_t);
src_iovecs[nr_iovecs].iov_len = crypt_len; src_iovecs[nr_iovecs].iov_len = crypt_len;
dst_iovecs[nr_iovecs].iov_base = dlrp + sizeof (lr_t); dst_iovecs[nr_iovecs].iov_base = dlrp + sizeof (lr_t);
dst_iovecs[nr_iovecs].iov_len = crypt_len; dst_iovecs[nr_iovecs].iov_len = crypt_len;
/* copy the bp now since it will not be encrypted */ /* copy the bp now since it will not be encrypted */
memcpy(dlrp + sizeof (lr_write_t) - sizeof (blkptr_t), memcpy(dlrp + o, slrp + o, sizeof (blkptr_t));
slrp + sizeof (lr_write_t) - sizeof (blkptr_t), memcpy(aadp, slrp + o, sizeof (blkptr_t));
sizeof (blkptr_t));
memcpy(aadp,
slrp + sizeof (lr_write_t) - sizeof (blkptr_t),
sizeof (blkptr_t));
aadp += sizeof (blkptr_t); aadp += sizeof (blkptr_t);
aad_len += sizeof (blkptr_t); aad_len += sizeof (blkptr_t);
nr_iovecs++; nr_iovecs++;