From 418f382163a0ebc72334fdc9932e4bf8aa4dc74b Mon Sep 17 00:00:00 2001 From: Paul Dagnelie Date: Fri, 27 Aug 2021 11:49:18 -0700 Subject: [PATCH] Compressed receive with different ashift can result in incorrect PSIZE on disk (#8462) Signed-off-by: Paul Dagnelie --- module/zfs/zio.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/module/zfs/zio.c b/module/zfs/zio.c index 76ed4fad4304..b61e6a258cc6 100644 --- a/module/zfs/zio.c +++ b/module/zfs/zio.c @@ -1771,6 +1771,19 @@ zio_write_compress(zio_t *zio) zio->io_abd, NULL, lsize, zp->zp_complevel); if (psize == 0 || psize >= lsize) compress = ZIO_COMPRESS_OFF; + } else if (zio->io_flags & ZIO_FLAG_RAW_COMPRESS) { + size_t rounded = MIN((size_t)roundup(psize, + spa->spa_min_alloc), lsize); + + if (rounded != psize) { + abd_t *cdata = abd_get_from_buf(zio_buf_alloc(rounded), rounded); + abd_take_ownership_of_buf(cdata, B_TRUE); + abd_zero_off(cdata, psize, rounded - psize); + abd_copy_off(cdata, zio->io_abd, 0, 0, psize); + psize = rounded; + zio_push_transform(zio, cdata, + psize, rounded, NULL); + } } else { ASSERT3U(psize, !=, 0); }