From b405837a6cf74165316bf996b4b79d171b19c211 Mon Sep 17 00:00:00 2001 From: Tom Caputi Date: Wed, 6 Jun 2018 13:17:50 -0400 Subject: [PATCH] Update the correct abd in l2arc_read_done() This patch fixes an issue where l2arc_read_done() would always write data to b_pabd, even if raw encrypted data was requested. This only occured in cases where the L2ARC device had a different ashift than the main pool. Reviewed-by: Brian Behlendorf Reviewed by: Matthew Ahrens Signed-off-by: Tom Caputi Closes #7586 Closes #7593 --- module/zfs/arc.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/module/zfs/arc.c b/module/zfs/arc.c index 8f90afaa1760..bf514f00f074 100644 --- a/module/zfs/arc.c +++ b/module/zfs/arc.c @@ -8248,17 +8248,18 @@ static void l2arc_read_done(zio_t *zio) { int tfm_error = 0; - l2arc_read_callback_t *cb; + l2arc_read_callback_t *cb = zio->io_private; arc_buf_hdr_t *hdr; kmutex_t *hash_lock; - boolean_t valid_cksum, using_rdata; + boolean_t valid_cksum; + boolean_t using_rdata = (BP_IS_ENCRYPTED(&cb->l2rcb_bp) && + (cb->l2rcb_flags & ZIO_FLAG_RAW_ENCRYPT)); ASSERT3P(zio->io_vd, !=, NULL); ASSERT(zio->io_flags & ZIO_FLAG_DONT_PROPAGATE); spa_config_exit(zio->io_spa, SCL_L2ARC, zio->io_vd); - cb = zio->io_private; ASSERT3P(cb, !=, NULL); hdr = cb->l2rcb_hdr; ASSERT3P(hdr, !=, NULL); @@ -8274,8 +8275,13 @@ l2arc_read_done(zio_t *zio) if (cb->l2rcb_abd != NULL) { ASSERT3U(arc_hdr_size(hdr), <, zio->io_size); if (zio->io_error == 0) { - abd_copy(hdr->b_l1hdr.b_pabd, cb->l2rcb_abd, - arc_hdr_size(hdr)); + if (using_rdata) { + abd_copy(hdr->b_crypt_hdr.b_rabd, + cb->l2rcb_abd, arc_hdr_size(hdr)); + } else { + abd_copy(hdr->b_l1hdr.b_pabd, + cb->l2rcb_abd, arc_hdr_size(hdr)); + } } /* @@ -8292,8 +8298,7 @@ l2arc_read_done(zio_t *zio) abd_free(cb->l2rcb_abd); zio->io_size = zio->io_orig_size = arc_hdr_size(hdr); - if (BP_IS_ENCRYPTED(&cb->l2rcb_bp) && - (cb->l2rcb_flags & ZIO_FLAG_RAW_ENCRYPT)) { + if (using_rdata) { ASSERT(HDR_HAS_RABD(hdr)); zio->io_abd = zio->io_orig_abd = hdr->b_crypt_hdr.b_rabd; @@ -8314,8 +8319,6 @@ l2arc_read_done(zio_t *zio) zio->io_bp = &zio->io_bp_copy; /* XXX fix in L2ARC 2.0 */ valid_cksum = arc_cksum_is_equal(hdr, zio); - using_rdata = (HDR_HAS_RABD(hdr) && - zio->io_abd == hdr->b_crypt_hdr.b_rabd); /* * b_rabd will always match the data as it exists on disk if it is