diff mbox series

Btrfs: fix cur_offset in the error case for nocow

Message ID 1540893844-3480-1-git-send-email-robbieko@synology.com (mailing list archive)
State New, archived
Headers show
Series Btrfs: fix cur_offset in the error case for nocow | expand

Commit Message

robbieko Oct. 30, 2018, 10:04 a.m. UTC
From: Robbie Ko <robbieko@synology.com>

When the cow_file_range fail, the related resources are
unlocked according to the range (start-end), so the unlock
cannot be repeated in run_delalloc_nocow.

In some cases (e.g. cur_offset <= end && cow_start!= -1),
cur_offset is not updated correctly, so move the cur_offset
update before cow_file_range.

------------[ cut here ]------------
kernel BUG at mm/page-writeback.c:2663!
Internal error: Oops - BUG: 0 [#1] SMP
CPU: 3 PID: 31525 Comm: kworker/u8:7 Tainted: P O
Hardware name: Realtek_RTD1296 (DT)
Workqueue: writeback wb_workfn (flush-btrfs-1)
task: ffffffc076db3380 ti: ffffffc02e9ac000 task.ti: ffffffc02e9ac000
PC is at clear_page_dirty_for_io+0x1bc/0x1e8
LR is at clear_page_dirty_for_io+0x14/0x1e8
pc : [<ffffffc00033c91c>] lr : [<ffffffc00033c774>] pstate: 40000145
sp : ffffffc02e9af4f0
Process kworker/u8:7 (pid: 31525, stack limit = 0xffffffc02e9ac020)
Call trace:
[<ffffffc00033c91c>] clear_page_dirty_for_io+0x1bc/0x1e8
[<ffffffbffc514674>] extent_clear_unlock_delalloc+0x1e4/0x210 [btrfs]
[<ffffffbffc4fb168>] run_delalloc_nocow+0x3b8/0x948 [btrfs]
[<ffffffbffc4fb948>] run_delalloc_range+0x250/0x3a8 [btrfs]
[<ffffffbffc514c0c>] writepage_delalloc.isra.21+0xbc/0x1d8 [btrfs]
[<ffffffbffc516048>] __extent_writepage+0xe8/0x248 [btrfs]
[<ffffffbffc51630c>] extent_write_cache_pages.isra.17+0x164/0x378 [btrfs]
[<ffffffbffc5185a8>] extent_writepages+0x48/0x68 [btrfs]
[<ffffffbffc4f5828>] btrfs_writepages+0x20/0x30 [btrfs]
[<ffffffc00033d758>] do_writepages+0x30/0x88
[<ffffffc0003ba0f4>] __writeback_single_inode+0x34/0x198
[<ffffffc0003ba6c4>] writeback_sb_inodes+0x184/0x3c0
[<ffffffc0003ba96c>] __writeback_inodes_wb+0x6c/0xc0
[<ffffffc0003bac20>] wb_writeback+0x1b8/0x1c0
[<ffffffc0003bb0f0>] wb_workfn+0x150/0x250
[<ffffffc0002b0014>] process_one_work+0x1dc/0x388
[<ffffffc0002b02f0>] worker_thread+0x130/0x500
[<ffffffc0002b6344>] kthread+0x10c/0x110
[<ffffffc000284590>] ret_from_fork+0x10/0x40
Code: d503201f a9025bb5 a90363b7 f90023b9 (d4210000)
---[ end trace 65fecee7c2296f25 ]---

Signed-off-by: Robbie Ko <robbieko@synology.com>
---
 fs/btrfs/inode.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Filipe Manana Oct. 30, 2018, 11:45 a.m. UTC | #1
On Tue, Oct 30, 2018 at 10:05 AM robbieko <robbieko@synology.com> wrote:
>
> From: Robbie Ko <robbieko@synology.com>
>
> When the cow_file_range fail, the related resources are
> unlocked according to the range (start-end), so the unlock
> cannot be repeated in run_delalloc_nocow.
>
> In some cases (e.g. cur_offset <= end && cow_start!= -1),
> cur_offset is not updated correctly, so move the cur_offset
> update before cow_file_range.
>
> ------------[ cut here ]------------
> kernel BUG at mm/page-writeback.c:2663!
> Internal error: Oops - BUG: 0 [#1] SMP
> CPU: 3 PID: 31525 Comm: kworker/u8:7 Tainted: P O
> Hardware name: Realtek_RTD1296 (DT)
> Workqueue: writeback wb_workfn (flush-btrfs-1)
> task: ffffffc076db3380 ti: ffffffc02e9ac000 task.ti: ffffffc02e9ac000
> PC is at clear_page_dirty_for_io+0x1bc/0x1e8
> LR is at clear_page_dirty_for_io+0x14/0x1e8
> pc : [<ffffffc00033c91c>] lr : [<ffffffc00033c774>] pstate: 40000145
> sp : ffffffc02e9af4f0
> Process kworker/u8:7 (pid: 31525, stack limit = 0xffffffc02e9ac020)
> Call trace:
> [<ffffffc00033c91c>] clear_page_dirty_for_io+0x1bc/0x1e8
> [<ffffffbffc514674>] extent_clear_unlock_delalloc+0x1e4/0x210 [btrfs]
> [<ffffffbffc4fb168>] run_delalloc_nocow+0x3b8/0x948 [btrfs]
> [<ffffffbffc4fb948>] run_delalloc_range+0x250/0x3a8 [btrfs]
> [<ffffffbffc514c0c>] writepage_delalloc.isra.21+0xbc/0x1d8 [btrfs]
> [<ffffffbffc516048>] __extent_writepage+0xe8/0x248 [btrfs]
> [<ffffffbffc51630c>] extent_write_cache_pages.isra.17+0x164/0x378 [btrfs]
> [<ffffffbffc5185a8>] extent_writepages+0x48/0x68 [btrfs]
> [<ffffffbffc4f5828>] btrfs_writepages+0x20/0x30 [btrfs]
> [<ffffffc00033d758>] do_writepages+0x30/0x88
> [<ffffffc0003ba0f4>] __writeback_single_inode+0x34/0x198
> [<ffffffc0003ba6c4>] writeback_sb_inodes+0x184/0x3c0
> [<ffffffc0003ba96c>] __writeback_inodes_wb+0x6c/0xc0
> [<ffffffc0003bac20>] wb_writeback+0x1b8/0x1c0
> [<ffffffc0003bb0f0>] wb_workfn+0x150/0x250
> [<ffffffc0002b0014>] process_one_work+0x1dc/0x388
> [<ffffffc0002b02f0>] worker_thread+0x130/0x500
> [<ffffffc0002b6344>] kthread+0x10c/0x110
> [<ffffffc000284590>] ret_from_fork+0x10/0x40
> Code: d503201f a9025bb5 a90363b7 f90023b9 (d4210000)
> ---[ end trace 65fecee7c2296f25 ]---
>
> Signed-off-by: Robbie Ko <robbieko@synology.com>
> ---
>  fs/btrfs/inode.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
> index 181c58b..b62299b 100644
> --- a/fs/btrfs/inode.c
> +++ b/fs/btrfs/inode.c
> @@ -1532,10 +1532,10 @@ static noinline int run_delalloc_nocow(struct inode *inode,
>
>         if (cur_offset <= end && cow_start == (u64)-1) {
>                 cow_start = cur_offset;
> -               cur_offset = end;
>         }

Also remove the { }

Other than that, it looks good to me and you can add:

Reviewed-by: Filipe Manana <fdmanana@suse.com>

thanks

>
>         if (cow_start != (u64)-1) {
> +               cur_offset = end;
>                 ret = cow_file_range(inode, locked_page, cow_start, end, end,
>                                      page_started, nr_written, 1, NULL);
>                 if (ret)
> --
> 1.9.1
>
David Sterba Oct. 30, 2018, 4:31 p.m. UTC | #2
On Tue, Oct 30, 2018 at 06:04:04PM +0800, robbieko wrote:
> From: Robbie Ko <robbieko@synology.com>
> 
> When the cow_file_range fail, the related resources are
> unlocked according to the range (start-end), so the unlock
> cannot be repeated in run_delalloc_nocow.
> 
> In some cases (e.g. cur_offset <= end && cow_start!= -1),
> cur_offset is not updated correctly, so move the cur_offset
> update before cow_file_range.
> 
> ------------[ cut here ]------------
> kernel BUG at mm/page-writeback.c:2663!
> Internal error: Oops - BUG: 0 [#1] SMP
> CPU: 3 PID: 31525 Comm: kworker/u8:7 Tainted: P O
> Hardware name: Realtek_RTD1296 (DT)
> Workqueue: writeback wb_workfn (flush-btrfs-1)
> task: ffffffc076db3380 ti: ffffffc02e9ac000 task.ti: ffffffc02e9ac000
> PC is at clear_page_dirty_for_io+0x1bc/0x1e8
> LR is at clear_page_dirty_for_io+0x14/0x1e8
> pc : [<ffffffc00033c91c>] lr : [<ffffffc00033c774>] pstate: 40000145
> sp : ffffffc02e9af4f0
> Process kworker/u8:7 (pid: 31525, stack limit = 0xffffffc02e9ac020)
> Call trace:
> [<ffffffc00033c91c>] clear_page_dirty_for_io+0x1bc/0x1e8
> [<ffffffbffc514674>] extent_clear_unlock_delalloc+0x1e4/0x210 [btrfs]
> [<ffffffbffc4fb168>] run_delalloc_nocow+0x3b8/0x948 [btrfs]
> [<ffffffbffc4fb948>] run_delalloc_range+0x250/0x3a8 [btrfs]
> [<ffffffbffc514c0c>] writepage_delalloc.isra.21+0xbc/0x1d8 [btrfs]
> [<ffffffbffc516048>] __extent_writepage+0xe8/0x248 [btrfs]
> [<ffffffbffc51630c>] extent_write_cache_pages.isra.17+0x164/0x378 [btrfs]
> [<ffffffbffc5185a8>] extent_writepages+0x48/0x68 [btrfs]
> [<ffffffbffc4f5828>] btrfs_writepages+0x20/0x30 [btrfs]
> [<ffffffc00033d758>] do_writepages+0x30/0x88
> [<ffffffc0003ba0f4>] __writeback_single_inode+0x34/0x198
> [<ffffffc0003ba6c4>] writeback_sb_inodes+0x184/0x3c0
> [<ffffffc0003ba96c>] __writeback_inodes_wb+0x6c/0xc0
> [<ffffffc0003bac20>] wb_writeback+0x1b8/0x1c0
> [<ffffffc0003bb0f0>] wb_workfn+0x150/0x250
> [<ffffffc0002b0014>] process_one_work+0x1dc/0x388
> [<ffffffc0002b02f0>] worker_thread+0x130/0x500
> [<ffffffc0002b6344>] kthread+0x10c/0x110
> [<ffffffc000284590>] ret_from_fork+0x10/0x40
> Code: d503201f a9025bb5 a90363b7 f90023b9 (d4210000)
> ---[ end trace 65fecee7c2296f25 ]---
> 
> Signed-off-by: Robbie Ko <robbieko@synology.com>

As there's a reviewed-by I can fix the small issues at commit time, no
need to resend. Thanks.
diff mbox series

Patch

diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
index 181c58b..b62299b 100644
--- a/fs/btrfs/inode.c
+++ b/fs/btrfs/inode.c
@@ -1532,10 +1532,10 @@  static noinline int run_delalloc_nocow(struct inode *inode,
 
 	if (cur_offset <= end && cow_start == (u64)-1) {
 		cow_start = cur_offset;
-		cur_offset = end;
 	}
 
 	if (cow_start != (u64)-1) {
+		cur_offset = end;
 		ret = cow_file_range(inode, locked_page, cow_start, end, end,
 				     page_started, nr_written, 1, NULL);
 		if (ret)