diff mbox series

[v4,35/68] btrfs: extent_io: make set/clear_extent_buffer_uptodate() to support subpage size

Message ID 20201021062554.68132-36-wqu@suse.com
State New, archived
Headers show
Series btrfs: add basic rw support for subpage sector size | expand

Commit Message

Qu Wenruo Oct. 21, 2020, 6:25 a.m. UTC
For those two functions, to support subpage size they just need the
follow work:
- set/clear the EXTENT_UPTODATE bits for io_tree
- set page Uptodate if the full range of the page is uptodate

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

Patch

diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c
index d899a75db977..1e959e6e8ce8 100644
--- a/fs/btrfs/extent_io.c
+++ b/fs/btrfs/extent_io.c
@@ -5631,10 +5631,18 @@  bool set_extent_buffer_dirty(struct extent_buffer *eb)
 void clear_extent_buffer_uptodate(struct extent_buffer *eb)
 {
 	int i;
-	struct page *page;
+	struct page *page = eb->pages[0];
 	int num_pages;
 
 	clear_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags);
+
+	if (btrfs_is_subpage(eb->fs_info) && page->mapping) {
+		struct extent_io_tree *io_tree =
+			info_to_btree_io_tree(eb->fs_info);
+
+		clear_extent_uptodate(io_tree, eb->start,
+				      eb->start + eb->len - 1, NULL);
+	}
 	num_pages = num_extent_pages(eb);
 	for (i = 0; i < num_pages; i++) {
 		page = eb->pages[i];
@@ -5646,10 +5654,26 @@  void clear_extent_buffer_uptodate(struct extent_buffer *eb)
 void set_extent_buffer_uptodate(struct extent_buffer *eb)
 {
 	int i;
-	struct page *page;
+	struct page *page = eb->pages[0];
 	int num_pages;
 
 	set_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags);
+
+	if (btrfs_is_subpage(eb->fs_info) && page->mapping) {
+		struct extent_state *cached = NULL;
+		struct extent_io_tree *io_tree =
+			info_to_btree_io_tree(eb->fs_info);
+		u64 page_start = page_offset(page);
+		u64 page_end = page_offset(page) + PAGE_SIZE - 1;
+
+		set_extent_uptodate(io_tree, eb->start, eb->start + eb->len - 1,
+				    &cached, GFP_NOFS);
+		if (test_range_bit(io_tree, page_start, page_end,
+				   EXTENT_UPTODATE, 1, cached))
+			SetPageUptodate(page);
+		free_extent_state(cached);
+		return;
+	}
 	num_pages = num_extent_pages(eb);
 	for (i = 0; i < num_pages; i++) {
 		page = eb->pages[i];