diff mbox series

[v4,05/18] btrfs: make grab_extent_buffer_from_page() to handle subpage case

Message ID 20210116071533.105780-6-wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: add read-only support for subpage sector size | expand

Commit Message

Qu Wenruo Jan. 16, 2021, 7:15 a.m. UTC
For subpage case, grab_extent_buffer() can't really get an extent buffer
just from btrfs_subpage.

Thankfully we have radix tree lock protecting us from inserting the same
eb into the tree.

Thus we don't really need to do the extra hassle, just let
alloc_extent_buffer() to handle existing eb in radix tree.

Now if two ebs are being allocated as the same time, one will fail with
-EEIXST when inserting its eb into the radix tree.

So for grab_extent_buffer(), just always return NULL for subpage case.

Signed-off-by: Qu Wenruo <wqu@suse.com>
 fs/btrfs/extent_io.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
diff mbox series


diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index 320731487ac0..b2f8ac5e9a9e 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -5282,10 +5282,19 @@  struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info,
-static struct extent_buffer *grab_extent_buffer(struct page *page)
+static struct extent_buffer *grab_extent_buffer(
+		struct btrfs_fs_info *fs_info, struct page *page)
 	struct extent_buffer *exists;
+	/*
+	 * For subpage case, we completely rely on radix tree to ensure we
+	 * don't try to insert two eb for the same bytenr.
+	 * So here we alwasy return NULL and just continue.
+	 */
+	if (fs_info->sectorsize < PAGE_SIZE)
+		return NULL;
 	/* Page not yet attached to an extent buffer */
 	if (!PagePrivate(page))
 		return NULL;
@@ -5366,7 +5375,7 @@  struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info,
-		exists = grab_extent_buffer(p);
+		exists = grab_extent_buffer(fs_info, p);
 		if (exists) {