zdb: fix checksum calculation for decompressed blocks

Currently, when reading compressed blocks with -R and decompressing
them with :d option and specifying lsize, which is normally bigger
than psize for compressed blocks, the checksum is calculated on
decompressed data. But it makes no sense since zfs always calculates
checksum on physical, i.e. compressed data. So reading the same block
produces different checksum results depending on how we read it,
whether we decompress it or not, which, again, makes no sense.

Fix: use psize instead of lsize when calculating the checksum so that
it is always calculated on the physical block size, no matter was it
compressed or not.

Signed-off-by: Andriy Tkachuk <andriy.tkachuk@seagate.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Closes #17547
This commit is contained in:
Andriy Tkachuk 2025-07-25 02:24:15 +01:00 committed by Alexander Motin
parent 0c928f7a37
commit 6d378564b4

View File

@ -9118,7 +9118,7 @@ zdb_read_block(char *thing, spa_t *spa)
ck_zio->io_offset = ck_zio->io_offset =
DVA_GET_OFFSET(&bp->blk_dva[0]); DVA_GET_OFFSET(&bp->blk_dva[0]);
ck_zio->io_bp = bp; ck_zio->io_bp = bp;
zio_checksum_compute(ck_zio, ck, pabd, lsize); zio_checksum_compute(ck_zio, ck, pabd, psize);
printf( printf(
"%12s\t" "%12s\t"
"cksum=%016llx:%016llx:%016llx:%016llx\n", "cksum=%016llx:%016llx:%016llx:%016llx\n",