Skip to content

Commit 8a6cd21

Browse files
committed
Fix bug caused by rounding in vdev_raidz_asize_to_psize
When an allocation is happening on a raidz vdev, the number of sectors allocated is rounded up to a multiple of nparity + 1. If this results in the allocation spilling into an extra row, then the corresponding call to vdev_raidz_asize_to_psize will incorrectly assume that parity sectors were allocated for that spilled row, even though no data is stored there. If we determine that happened, we need to subtract out those extra sectors before performing the rest of the capacity calculation. Signed-off-by: Paul Dagnelie <[email protected]> Sponsored-by: Klara, Inc. Sponsored-by: Wasabi Technology, Inc.
1 parent ea076d6 commit 8a6cd21

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

module/zfs/vdev_raidz.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2257,6 +2257,14 @@ vdev_raidz_asize_to_psize(vdev_t *vd, uint64_t asize, uint64_t txg)
22572257
ASSERT0(asize % (1 << ashift));
22582258

22592259
psize = (asize >> ashift);
2260+
/*
2261+
* If the roundup to nparity + 1 caused us to spill into a new row, we
2262+
* need to ignore that row entirely (since it can't store data or
2263+
* parity).
2264+
*/
2265+
uint64_t rows = psize / cols;
2266+
psize = psize - (rows * cols) <= nparity ? rows * cols : psize;
2267+
/* Subtract out parity sectors for each row storing data. */
22602268
psize -= nparity * DIV_ROUND_UP(psize, cols);
22612269
psize <<= ashift;
22622270

module/zfs/zio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,6 +3239,7 @@ zio_write_gang_block(zio_t *pio, metaslab_class_t *mc)
32393239

32403240
uint64_t psize = allocated ? MIN(resid, allocated_size) :
32413241
min_size;
3242+
ASSERT3U(psize, >=, min_size);
32423243

32433244
zio_t *cio = zio_write(zio, spa, txg, bp, has_data ?
32443245
abd_get_offset(pio->io_abd, pio->io_size - resid) : NULL,

0 commit comments

Comments
 (0)