Skip to contentSkip to conversation

vfs/dedupe: Pass file pointer to read_mapping_page

PATCH In review Matthew Wilcox (Oracle) 2 participants 2 messages May 11, 2021 VFS

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 vfs/dedupe: Pass file pointer to read_mapping_page

Some filesystems (mostly networking) need a valid file pointer for their ->readpage operation to supply credentials. Since there are no bug reports, I assume none of them currently support deduplication. It's just as easy to pass the struct file around as it is to pass the struct inode around, and it sets a good example for other users as well as being good future-proofing.

---
 fs/remap_range.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
fs/remap_range.c +8 -8
index e4a5fdd7ad7b..56f44a9b4ab6 100644
@@ -158,11 +158,11 @@ static int generic_remap_check_len(struct inode *inode_in,
 }
 
 /* Read a page's worth of file data into the page cache. */
-static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset)
+static struct page *vfs_dedupe_get_page(struct file *file, loff_t offset)
 {
 	struct page *page;
 
-	page = read_mapping_page(inode->i_mapping, offset >> PAGE_SHIFT, NULL);
+	page = read_mapping_page(file->f_mapping, offset >> PAGE_SHIFT, file);
 	if (IS_ERR(page))
 		return page;
 	if (!PageUptodate(page)) {
@@ -199,8 +199,8 @@ static void vfs_unlock_two_pages(struct page *page1, struct page *page2)
  * Compare extents of two files to see if they are the same.
  * Caller must have locked both inodes to prevent write races.
  */
-static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
-					 struct inode *dest, loff_t destoff,
+static int vfs_dedupe_file_range_compare(struct file *src, loff_t srcoff,
+					 struct file *dest, loff_t destoff,
 					 loff_t len, bool *is_same)
 {
 	loff_t src_poff;
@@ -244,8 +244,8 @@ static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
 		 * someone is invalidating pages on us and we lose.
 		 */
 		if (!PageUptodate(src_page) || !PageUptodate(dest_page) ||
-		    src_page->mapping != src->i_mapping ||
-		    dest_page->mapping != dest->i_mapping) {
+		    src_page->mapping != src->f_mapping ||
+		    dest_page->mapping != dest->f_mapping) {
 			same = false;
 			goto unlock;
 		}
@@ -351,8 +351,8 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
 	if (remap_flags & REMAP_FILE_DEDUP) {
 		bool		is_same = false;
 
-		ret = vfs_dedupe_file_range_compare(inode_in, pos_in,
-				inode_out, pos_out, *len, &is_same);
+		ret = vfs_dedupe_file_range_compare(file_in, pos_in,
+				file_out, pos_out, *len, &is_same);
 		if (ret)
 			return ret;
 		if (!is_same)
Signature · 1 line
2.30.2
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Matthew Wilcox (Oracle)

Some filesystems (mostly networking) need a valid file pointer for their ->readpage operation to supply credentials. Since there are no bug reports, I assume none of them currently support deduplication. It's just as easy to pass the struct file around as it is to pass the struct inode around, and it sets a good example for other users as well as being good future-proofing.

Sorry for getting this wrong from the start, or "Yay fixes!" :)

--D

Quoted 58 lines
---
 fs/remap_range.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
fs/remap_range.c +8 -8
index e4a5fdd7ad7b..56f44a9b4ab6 100644
@@ -158,11 +158,11 @@ static int generic_remap_check_len(struct inode *inode_in,
 }
 
 /* Read a page's worth of file data into the page cache. */
-static struct page *vfs_dedupe_get_page(struct inode *inode, loff_t offset)
+static struct page *vfs_dedupe_get_page(struct file *file, loff_t offset)
 {
 	struct page *page;
 
-	page = read_mapping_page(inode->i_mapping, offset >> PAGE_SHIFT, NULL);
+	page = read_mapping_page(file->f_mapping, offset >> PAGE_SHIFT, file);
 	if (IS_ERR(page))
 		return page;
 	if (!PageUptodate(page)) {
@@ -199,8 +199,8 @@ static void vfs_unlock_two_pages(struct page *page1, struct page *page2)
  * Compare extents of two files to see if they are the same.
  * Caller must have locked both inodes to prevent write races.
  */
-static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
-					 struct inode *dest, loff_t destoff,
+static int vfs_dedupe_file_range_compare(struct file *src, loff_t srcoff,
+					 struct file *dest, loff_t destoff,
 					 loff_t len, bool *is_same)
 {
 	loff_t src_poff;
@@ -244,8 +244,8 @@ static int vfs_dedupe_file_range_compare(struct inode *src, loff_t srcoff,
 		 * someone is invalidating pages on us and we lose.
 		 */
 		if (!PageUptodate(src_page) || !PageUptodate(dest_page) ||
-		    src_page->mapping != src->i_mapping ||
-		    dest_page->mapping != dest->i_mapping) {
+		    src_page->mapping != src->f_mapping ||
+		    dest_page->mapping != dest->f_mapping) {
 			same = false;
 			goto unlock;
 		}
@@ -351,8 +351,8 @@ int generic_remap_file_range_prep(struct file *file_in, loff_t pos_in,
 	if (remap_flags & REMAP_FILE_DEDUP) {
 		bool		is_same = false;
 
-		ret = vfs_dedupe_file_range_compare(inode_in, pos_in,
-				inode_out, pos_out, *len, &is_same);
+		ret = vfs_dedupe_file_range_compare(file_in, pos_in,
+				file_out, pos_out, *len, &is_same);
 		if (ret)
 			return ret;
 		if (!is_same)
Signature · 1 line
2.30.2