diff mbox series

btrfs: fix clear_dirty and writeback ordering

Message ID e329dec3e85540e13dac7aefab1d554134214ebe.1728017511.git.naohiro.aota@wdc.com (mailing list archive)
State New, archived
Headers show
Series btrfs: fix clear_dirty and writeback ordering | expand

Commit Message

Naohiro Aota Oct. 4, 2024, 4:53 a.m. UTC
This commit is a replay of commit 6252690f7e1b ("btrfs: fix invalid mapping
of extent xarray state"). We need to call btrfs_folio_clear_dirty() before
btrfs_set_range_writeback(), so that xarray DIRTY tag is cleared. With a
refactoring commit 8189197425e7 ("btrfs: refactor __extent_writepage_io()
to do sector-by-sector submission"), it screwed up and the order is
reversed and causing the same hang. Fix the ordering now in
submit_one_sector().

Fixes: 8189197425e7 ("btrfs: refactor __extent_writepage_io() to do sector-by-sector submission")
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
---
 fs/btrfs/extent_io.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

Comments

Qu Wenruo Oct. 4, 2024, 5:52 a.m. UTC | #1
在 2024/10/4 14:23, Naohiro Aota 写道:
> This commit is a replay of commit 6252690f7e1b ("btrfs: fix invalid mapping
> of extent xarray state"). We need to call btrfs_folio_clear_dirty() before
> btrfs_set_range_writeback(), so that xarray DIRTY tag is cleared. With a
> refactoring commit 8189197425e7 ("btrfs: refactor __extent_writepage_io()
> to do sector-by-sector submission"), it screwed up and the order is
> reversed and causing the same hang. Fix the ordering now in
> submit_one_sector().
>
> Fixes: 8189197425e7 ("btrfs: refactor __extent_writepage_io() to do sector-by-sector submission")
> Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>

Reviewed-by: Qu Wenruo <wqu@suse.com>

Thanks,
Qu

> ---
>   fs/btrfs/extent_io.c | 14 +++++++-------
>   1 file changed, 7 insertions(+), 7 deletions(-)
>
> diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
> index cb0a39370d30..9fbc83c76b94 100644
> --- a/fs/btrfs/extent_io.c
> +++ b/fs/btrfs/extent_io.c
> @@ -1352,6 +1352,13 @@ static int submit_one_sector(struct btrfs_inode *inode,
>   	free_extent_map(em);
>   	em = NULL;
>
> +	/*
> +	 * Although the PageDirty bit is cleared before entering this
> +	 * function, subpage dirty bit is not cleared.
> +	 * So clear subpage dirty bit here so next time we won't submit
> +	 * a folio for a range already written to disk.
> +	 */
> +	btrfs_folio_clear_dirty(fs_info, folio, filepos, sectorsize);
>   	btrfs_set_range_writeback(inode, filepos, filepos + sectorsize - 1);
>   	/*
>   	 * Above call should set the whole folio with writeback flag, even
> @@ -1361,13 +1368,6 @@ static int submit_one_sector(struct btrfs_inode *inode,
>   	 */
>   	ASSERT(folio_test_writeback(folio));
>
> -	/*
> -	 * Although the PageDirty bit is cleared before entering this
> -	 * function, subpage dirty bit is not cleared.
> -	 * So clear subpage dirty bit here so next time we won't submit
> -	 * folio for range already written to disk.
> -	 */
> -	btrfs_folio_clear_dirty(fs_info, folio, filepos, sectorsize);
>   	submit_extent_folio(bio_ctrl, disk_bytenr, folio,
>   			    sectorsize, filepos - folio_pos(folio));
>   	return 0;
Johannes Thumshirn Oct. 4, 2024, 9:10 a.m. UTC | #2
Looks good,
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
David Sterba Oct. 7, 2024, 11:05 p.m. UTC | #3
On Fri, Oct 04, 2024 at 01:53:35PM +0900, Naohiro Aota wrote:
> This commit is a replay of commit 6252690f7e1b ("btrfs: fix invalid mapping
> of extent xarray state"). We need to call btrfs_folio_clear_dirty() before
> btrfs_set_range_writeback(), so that xarray DIRTY tag is cleared. With a
> refactoring commit 8189197425e7 ("btrfs: refactor __extent_writepage_io()
> to do sector-by-sector submission"), it screwed up and the order is
> reversed and causing the same hang.

Thanks for noticing it, this kind of things are hard to spot and keep in
mind between the refactoring patches and fixes.

Reviewed-by: David Sterba <dsterba@suse.com>
diff mbox series

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index cb0a39370d30..9fbc83c76b94 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -1352,6 +1352,13 @@  static int submit_one_sector(struct btrfs_inode *inode,
 	free_extent_map(em);
 	em = NULL;
 
+	/*
+	 * Although the PageDirty bit is cleared before entering this
+	 * function, subpage dirty bit is not cleared.
+	 * So clear subpage dirty bit here so next time we won't submit
+	 * a folio for a range already written to disk.
+	 */
+	btrfs_folio_clear_dirty(fs_info, folio, filepos, sectorsize);
 	btrfs_set_range_writeback(inode, filepos, filepos + sectorsize - 1);
 	/*
 	 * Above call should set the whole folio with writeback flag, even
@@ -1361,13 +1368,6 @@  static int submit_one_sector(struct btrfs_inode *inode,
 	 */
 	ASSERT(folio_test_writeback(folio));
 
-	/*
-	 * Although the PageDirty bit is cleared before entering this
-	 * function, subpage dirty bit is not cleared.
-	 * So clear subpage dirty bit here so next time we won't submit
-	 * folio for range already written to disk.
-	 */
-	btrfs_folio_clear_dirty(fs_info, folio, filepos, sectorsize);
 	submit_extent_folio(bio_ctrl, disk_bytenr, folio,
 			    sectorsize, filepos - folio_pos(folio));
 	return 0;