Skip to contentSkip to conversation

btrfs: Move btrfs_lock_and_flush_ordered_range call in btrfs_do_readpage

PATCH In review Nikolay Borisov 2 participants 4 messages Sep 16, 2020 – Sep 17, 2020 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 btrfs: Move btrfs_lock_and_flush_ordered_range call in btrfs_do_readpage

btrfs_lock_and_flush_ordered_range returns with the extent range locked. Subsequently this lock is being dropped in btrfs_do_readpage. Given this it makes more sense to move the call to the locking function inside btrfs_do_readpage making btrfs_do_readpage self-contained as it calls unlock_extent a couple of times. No functional changes.

---
 fs/btrfs/extent_io.c | 2 ++
 fs/btrfs/inode.c     | 5 -----
 2 files changed, 2 insertions(+), 5 deletions(-)
fs/btrfs/extent_io.c +2 -0
index afac70ef0cc5..00e552055315 100644
@@ -3163,6 +3163,8 @@ int btrfs_do_readpage(struct page *page, struct extent_map **em_cached,
 	unsigned long this_bio_flag = 0;
 	struct extent_io_tree *tree = &BTRFS_I(inode)->io_tree;
 
+	btrfs_lock_and_flush_ordered_range(BTRFS_I(inode), start, end, NULL);
+
 	set_page_extent_mapped(page);
 
 	if (!PageUptodate(page)) {
fs/btrfs/inode.c +0 -5
index cb3fdd0798c6..ae396d799aa5 100644
@@ -8023,15 +8023,10 @@ static int btrfs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
 
 int btrfs_readpage(struct file *file, struct page *page)
 {
-	struct btrfs_inode *inode = BTRFS_I(page->mapping->host);
-	u64 start = page_offset(page);
-	u64 end = start + PAGE_SIZE - 1;
 	unsigned long bio_flags = 0;
 	struct bio *bio = NULL;
 	int ret;
 
-	btrfs_lock_and_flush_ordered_range(inode, start, end, NULL);
-
 	ret = btrfs_do_readpage(page, NULL, &bio, &bio_flags, 0, NULL);
 	if (bio)
 		ret = submit_one_bio(bio, 0, bio_flags);
Signature · 1 line
2.17.1
#3 lore raw
Quoted 3 lines · Nikolay Borisov

Actually no, this conflicts with btrfs_do_readpage call from contiguous_readpages which results in double lock.

Right didn't see it :(

But why can't we remove the btrfs_lock_and_flush_ordered_range call in contigous_readpages?