From b126bb5f67a2e400ad0e702754e34b2d20c1d5a0 Mon Sep 17 00:00:00 2001 From: Matthew Ahrens Date: Fri, 2 Dec 2022 09:49:42 -0800 Subject: [PATCH] ztest fails assertion in zio_write_gang_member_ready() Encrypted blocks can have up to 2 DVA's, as the third DVA is reserved for the salt+IV. However, dmu_write_policy() allows non-encrypted blocks (e.g. DMU_OT_OBJSET) inside encrypted datasets to request and allocate 3 DVA's, since they don't need a salt+IV (they are merely authenicated). However, if such a block becomes a gang block, the gang code incorrectly limits the gang block header to 2 DVA's. This leads to a "NDVAs inversion", where a parent block (the gang block header) has less DVA's than its children (the gang members), causing an assertion failure in zio_write_gang_member_ready(). This commit addresses the problem by only restricting the gang block header to 2 DVA's if the block is actually encrypted (and thus its gang block members can have at most 2 DVA's). Signed-off-by: Matthew Ahrens Closes #14250 --- module/zfs/zio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/zfs/zio.c b/module/zfs/zio.c index 9ae2458669f7..5d7ed6d582a2 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -2826,7 +2826,7 @@ zio_write_gang_block(zio_t *pio, metaslab_class_t *mc) * have a third copy. */ gbh_copies = MIN(copies + 1, spa_max_replication(spa)); - if (gio->io_prop.zp_encrypt && gbh_copies >= SPA_DVAS_PER_BP) + if (BP_IS_ENCRYPTED(bp) && gbh_copies >= SPA_DVAS_PER_BP) gbh_copies = SPA_DVAS_PER_BP - 1; int flags = METASLAB_HINTBP_FAVOR | METASLAB_GANG_HEADER;