Skip to content

Commit 4750af3

Browse files
adam900710kdave
authored andcommitted
btrfs: prevent extent_clear_unlock_delalloc() to unlock page not locked by __process_pages_contig()
In cow_file_range(), after we have succeeded creating an inline extent, we unlock the page with extent_clear_unlock_delalloc() by passing locked_page == NULL. For sectorsize == PAGE_SIZE case, this is just making the page lock and unlock harder to grab. But for incoming subpage case, it can be a big problem. For incoming subpage case, page locking have two entry points: - __process_pages_contig() In that case, we know exactly the range we want to lock (which only requires sector alignment). To handle the subpage requirement, we introduce btrfs_subpage::writers to page::private, and will update it in __process_pages_contig(). - Other directly lock/unlock_page() call sites Those won't touch btrfs_subpage::writers at all. This means, page locked by __process_pages_contig() can only be unlocked by __process_pages_contig(). Thankfully we already have the existing infrastructure in the form of @locked_page in various call sites. Unfortunately, extent_clear_unlock_delalloc() in cow_file_range() after creating an inline extent is the exception. It intentionally call extent_clear_unlock_delalloc() with locked_page == NULL, to also unlock current page (and clear its dirty/writeback bits). To co-operate with incoming subpage modifications, and make the page lock/unlock pair easier to understand, this patch will still call extent_clear_unlock_delalloc() with locked_page, and only unlock the page in __extent_writepage(). Tested-by: Ritesh Harjani <riteshh@linux.ibm.com> # [ppc64] Tested-by: Anand Jain <anand.jain@oracle.com> # [aarch64] Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent a33a8e9 commit 4750af3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

fs/btrfs/inode.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1091,14 +1091,28 @@ static noinline int cow_file_range(struct btrfs_inode *inode,
10911091
* our outstanding extent for clearing delalloc for this
10921092
* range.
10931093
*/
1094-
extent_clear_unlock_delalloc(inode, start, end, NULL,
1094+
extent_clear_unlock_delalloc(inode, start, end,
1095+
locked_page,
10951096
EXTENT_LOCKED | EXTENT_DELALLOC |
10961097
EXTENT_DELALLOC_NEW | EXTENT_DEFRAG |
10971098
EXTENT_DO_ACCOUNTING, PAGE_UNLOCK |
10981099
PAGE_START_WRITEBACK | PAGE_END_WRITEBACK);
10991100
*nr_written = *nr_written +
11001101
(end - start + PAGE_SIZE) / PAGE_SIZE;
11011102
*page_started = 1;
1103+
/*
1104+
* locked_page is locked by the caller of
1105+
* writepage_delalloc(), not locked by
1106+
* __process_pages_contig().
1107+
*
1108+
* We can't let __process_pages_contig() to unlock it,
1109+
* as it doesn't have any subpage::writers recorded.
1110+
*
1111+
* Here we manually unlock the page, since the caller
1112+
* can't use page_started to determine if it's an
1113+
* inline extent or a compressed extent.
1114+
*/
1115+
unlock_page(locked_page);
11021116
goto out;
11031117
} else if (ret < 0) {
11041118
goto out_unlock;

0 commit comments

Comments
 (0)