| From 50bc2f07546738dc233c8674d5ba5f3560a2d601 Mon Sep 17 00:00:00 2001 |
| From: Sasha Levin <sashal@kernel.org> |
| Date: Tue, 1 Jul 2025 15:21:48 +0300 |
| Subject: pNFS: Fix stripe mapping in block/scsi layout |
| |
| From: Sergey Bashirov <sergeybashirov@gmail.com> |
| |
| [ Upstream commit 81438498a285759f31e843ac4800f82a5ce6521f ] |
| |
| Because of integer division, we need to carefully calculate the |
| disk offset. Consider the example below for a stripe of 6 volumes, |
| a chunk size of 4096, and an offset of 70000. |
| |
| chunk = div_u64(offset, dev->chunk_size) = 70000 / 4096 = 17 |
| offset = chunk * dev->chunk_size = 17 * 4096 = 69632 |
| disk_offset_wrong = div_u64(offset, dev->nr_children) = 69632 / 6 = 11605 |
| disk_chunk = div_u64(chunk, dev->nr_children) = 17 / 6 = 2 |
| disk_offset = disk_chunk * dev->chunk_size = 2 * 4096 = 8192 |
| |
| Signed-off-by: Sergey Bashirov <sergeybashirov@gmail.com> |
| Reviewed-by: Christoph Hellwig <hch@lst.de> |
| Link: https://lore.kernel.org/r/20250701122341.199112-1-sergeybashirov@gmail.com |
| Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> |
| Signed-off-by: Sasha Levin <sashal@kernel.org> |
| --- |
| fs/nfs/blocklayout/dev.c | 5 +++-- |
| 1 file changed, 3 insertions(+), 2 deletions(-) |
| |
| diff --git a/fs/nfs/blocklayout/dev.c b/fs/nfs/blocklayout/dev.c |
| index 65cbb5607a5f..61ee0b6c0fba 100644 |
| --- a/fs/nfs/blocklayout/dev.c |
| +++ b/fs/nfs/blocklayout/dev.c |
| @@ -199,10 +199,11 @@ static bool bl_map_stripe(struct pnfs_block_dev *dev, u64 offset, |
| struct pnfs_block_dev *child; |
| u64 chunk; |
| u32 chunk_idx; |
| + u64 disk_chunk; |
| u64 disk_offset; |
| |
| chunk = div_u64(offset, dev->chunk_size); |
| - div_u64_rem(chunk, dev->nr_children, &chunk_idx); |
| + disk_chunk = div_u64_rem(chunk, dev->nr_children, &chunk_idx); |
| |
| if (chunk_idx >= dev->nr_children) { |
| dprintk("%s: invalid chunk idx %d (%lld/%lld)\n", |
| @@ -215,7 +216,7 @@ static bool bl_map_stripe(struct pnfs_block_dev *dev, u64 offset, |
| offset = chunk * dev->chunk_size; |
| |
| /* disk offset of the stripe */ |
| - disk_offset = div_u64(offset, dev->nr_children); |
| + disk_offset = disk_chunk * dev->chunk_size; |
| |
| child = &dev->children[chunk_idx]; |
| child->map(child, disk_offset, map); |
| -- |
| 2.39.5 |
| |