* [PATCH] ext4: fix an off-by-one issue during moving extents
@ 2025-09-12 10:58 Zhang Yi
2025-09-12 14:17 ` Jan Kara
2025-09-26 21:47 ` Theodore Ts'o
0 siblings, 2 replies; 3+ messages in thread
From: Zhang Yi @ 2025-09-12 10:58 UTC (permalink / raw)
To: linux-ext4
Cc: linux-fsdevel, linux-kernel, tytso, adilger.kernel, jack,
yi.zhang, yi.zhang, libaokun1, yukuai3, yangerkun
From: Zhang Yi <yi.zhang@huawei.com>
During the movement of a written extent, mext_page_mkuptodate() is
called to read data in the range [from, to) into the page cache and to
update the corresponding buffers. Therefore, we should not wait on any
buffer whose start offset is >= 'to'. Otherwise, it will return -EIO and
fail the extents movement.
$ for i in `seq 3 -1 0`; \
do xfs_io -fs -c "pwrite -b 1024 $((i * 1024)) 1024" /mnt/foo; \
done
$ umount /mnt && mount /dev/pmem1s /mnt # drop cache
$ e4defrag /mnt/foo
e4defrag 1.47.0 (5-Feb-2023)
ext4 defragmentation for /mnt/foo
[1/1]/mnt/foo: 0% [ NG ]
Success: [0/1]
Fixes: a40759fb16ae ("ext4: remove array of buffer_heads from mext_page_mkuptodate()")
Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
---
fs/ext4/move_extent.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
index adae3caf175a..4b091c21908f 100644
--- a/fs/ext4/move_extent.c
+++ b/fs/ext4/move_extent.c
@@ -225,7 +225,7 @@ static int mext_page_mkuptodate(struct folio *folio, size_t from, size_t to)
do {
if (bh_offset(bh) + blocksize <= from)
continue;
- if (bh_offset(bh) > to)
+ if (bh_offset(bh) >= to)
break;
wait_on_buffer(bh);
if (buffer_uptodate(bh))
--
2.46.1
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] ext4: fix an off-by-one issue during moving extents
2025-09-12 10:58 [PATCH] ext4: fix an off-by-one issue during moving extents Zhang Yi
@ 2025-09-12 14:17 ` Jan Kara
2025-09-26 21:47 ` Theodore Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Jan Kara @ 2025-09-12 14:17 UTC (permalink / raw)
To: Zhang Yi
Cc: linux-ext4, linux-fsdevel, linux-kernel, tytso, adilger.kernel,
jack, yi.zhang, libaokun1, yukuai3, yangerkun
On Fri 12-09-25 18:58:41, Zhang Yi wrote:
> From: Zhang Yi <yi.zhang@huawei.com>
>
> During the movement of a written extent, mext_page_mkuptodate() is
> called to read data in the range [from, to) into the page cache and to
> update the corresponding buffers. Therefore, we should not wait on any
> buffer whose start offset is >= 'to'. Otherwise, it will return -EIO and
> fail the extents movement.
>
> $ for i in `seq 3 -1 0`; \
> do xfs_io -fs -c "pwrite -b 1024 $((i * 1024)) 1024" /mnt/foo; \
> done
> $ umount /mnt && mount /dev/pmem1s /mnt # drop cache
> $ e4defrag /mnt/foo
> e4defrag 1.47.0 (5-Feb-2023)
> ext4 defragmentation for /mnt/foo
> [1/1]/mnt/foo: 0% [ NG ]
> Success: [0/1]
>
> Fixes: a40759fb16ae ("ext4: remove array of buffer_heads from mext_page_mkuptodate()")
> Signed-off-by: Zhang Yi <yi.zhang@huawei.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/ext4/move_extent.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/ext4/move_extent.c b/fs/ext4/move_extent.c
> index adae3caf175a..4b091c21908f 100644
> --- a/fs/ext4/move_extent.c
> +++ b/fs/ext4/move_extent.c
> @@ -225,7 +225,7 @@ static int mext_page_mkuptodate(struct folio *folio, size_t from, size_t to)
> do {
> if (bh_offset(bh) + blocksize <= from)
> continue;
> - if (bh_offset(bh) > to)
> + if (bh_offset(bh) >= to)
> break;
> wait_on_buffer(bh);
> if (buffer_uptodate(bh))
> --
> 2.46.1
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] ext4: fix an off-by-one issue during moving extents
2025-09-12 10:58 [PATCH] ext4: fix an off-by-one issue during moving extents Zhang Yi
2025-09-12 14:17 ` Jan Kara
@ 2025-09-26 21:47 ` Theodore Ts'o
1 sibling, 0 replies; 3+ messages in thread
From: Theodore Ts'o @ 2025-09-26 21:47 UTC (permalink / raw)
To: linux-ext4, Zhang Yi
Cc: Theodore Ts'o, linux-fsdevel, linux-kernel, adilger.kernel,
jack, yi.zhang, libaokun1, yukuai3, yangerkun
On Fri, 12 Sep 2025 18:58:41 +0800, Zhang Yi wrote:
> During the movement of a written extent, mext_page_mkuptodate() is
> called to read data in the range [from, to) into the page cache and to
> update the corresponding buffers. Therefore, we should not wait on any
> buffer whose start offset is >= 'to'. Otherwise, it will return -EIO and
> fail the extents movement.
>
> $ for i in `seq 3 -1 0`; \
> do xfs_io -fs -c "pwrite -b 1024 $((i * 1024)) 1024" /mnt/foo; \
> done
> $ umount /mnt && mount /dev/pmem1s /mnt # drop cache
> $ e4defrag /mnt/foo
> e4defrag 1.47.0 (5-Feb-2023)
> ext4 defragmentation for /mnt/foo
> [1/1]/mnt/foo: 0% [ NG ]
> Success: [0/1]
>
> [...]
Applied, thanks!
[1/1] ext4: fix an off-by-one issue during moving extents
commit: 12e803c8827d049ae8f2c743ef66ab87ae898375
Best regards,
--
Theodore Ts'o <tytso@mit.edu>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-26 21:48 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-12 10:58 [PATCH] ext4: fix an off-by-one issue during moving extents Zhang Yi
2025-09-12 14:17 ` Jan Kara
2025-09-26 21:47 ` Theodore Ts'o
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).