Skip to contentSkip to conversation

Btrfs: resurrect extent_read_full_page_nolock()

PATCH Superseded [email protected] 2 participants 2 messages Feb 19, 2020 – Feb 20, 2020 Btrfs file system

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH 3/4 Btrfs: resurrect extent_read_full_page_nolock()

From: Filipe Manana <[email protected]>

Commit 7f042a8370a5bb ("Btrfs: remove no longer used function extent_read_full_page_nolock()") removed extent_read_full_page_nolock() because it was not needed anymore.

This function was used to read a page while holding the respective range locked in the inode's iotree, to avoid deadlocks when using the other APIs we have for reading a page (which lock and unlock the range themselves).

Since this type of functionality is needed for the upcoming changes to the reflink implementation dealing with cloning of inline extents, bring back this function to life.

---
 fs/btrfs/compression.c |  8 ++++++-
 fs/btrfs/extent_io.c   | 47 ++++++++++++++++++++++++++++++++++--------
 fs/btrfs/extent_io.h   |  3 +++
 3 files changed, 48 insertions(+), 10 deletions(-)
fs/btrfs/compression.c +7 -1
index 9ab610cc9114..4096cd3b1a2f 100644
@@ -722,7 +722,13 @@ blk_status_t btrfs_submit_compressed_read(struct inode *inode, struct bio *bio,
 	faili = nr_pages - 1;
 	cb->nr_pages = nr_pages;
 
-	add_ra_bio_pages(inode, em_start + em_len, cb);
+	/*
+	 * In the parent-locked case we only locked the range we are interested
+	 * in.  In all other cases, we can opportunistically cache decompressed
+	 * data that goes beyond the requested range.
+	 */
+	if (!(bio_flags & EXTENT_BIO_PARENT_LOCKED))
+		add_ra_bio_pages(inode, em_start + em_len, cb);
 
 	/* include any pages we added in add_ra-bio_pages */
 	cb->len = bio->bi_iter.bi_size;
fs/btrfs/extent_io.c +38 -9

95 lines not on this page · raw message

fs/btrfs/extent_io.h +3 -0
index 234622101230..8d891a598e24 100644
@@ -12,6 +12,7 @@
  * type for this bio
  */
 #define EXTENT_BIO_COMPRESSED 1
+#define EXTENT_BIO_PARENT_LOCKED 4
 #define EXTENT_BIO_FLAG_SHIFT 16
 
 enum {
@@ -191,6 +192,8 @@ int try_release_extent_buffer(struct page *page);
 
 int extent_read_full_page(struct page *page, get_extent_t *get_extent,
 			  int mirror_num);
+int extent_read_full_page_nolock(struct page *page, get_extent_t *get_extent,
+				 int mirror_num);
 int extent_write_full_page(struct page *page, struct writeback_control *wbc);
 int extent_write_locked_range(struct inode *inode, u64 start, u64 end,
 			      int mode);
Signature · 1 line
2.25.0
Reviewed-by on v1 3/4
#1 lore raw
Quoted 11 lines · On 2/19/20 9:06 AM, [email protected] wrote:

From: Filipe Manana <[email protected]>

Commit 7f042a8370a5bb ("Btrfs: remove no longer used function extent_read_full_page_nolock()") removed extent_read_full_page_nolock() because it was not needed anymore.

This function was used to read a page while holding the respective range locked in the inode's iotree, to avoid deadlocks when using the other APIs we have for reading a page (which lock and unlock the range themselves).

Quoted 5 lines

Since this type of functionality is needed for the upcoming changes to the reflink implementation dealing with cloning of inline extents, bring back this function to life.

Thanks,

Josef