[RFC PATCH] folio: Add a function to get the host inode for a folio

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Add a convenience function, folio_inode() that will get the host inode from
a folio's mapping.

[Includes netfs and afs changes for illustration, but I'd move those to a
different patch].

Signed-off-by: David Howells <dhowells@xxxxxxxxxx>
---

 fs/afs/dir.c            |    4 ++--
 fs/afs/file.c           |    4 ++--
 fs/afs/write.c          |    3 +--
 fs/netfs/read_helper.c  |    2 +-
 include/linux/pagemap.h |   14 ++++++++++++++
 5 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/fs/afs/dir.c b/fs/afs/dir.c
index db5bc874bf0b..37e6f4713f4f 100644
--- a/fs/afs/dir.c
+++ b/fs/afs/dir.c
@@ -2023,7 +2023,7 @@ static int afs_rename(struct user_namespace *mnt_userns, struct inode *old_dir,
 static int afs_dir_releasepage(struct page *subpage, gfp_t gfp_flags)
 {
 	struct folio *folio = page_folio(subpage);
-	struct afs_vnode *dvnode = AFS_FS_I(folio_mapping(folio)->host);
+	struct afs_vnode *dvnode = AFS_FS_I(folio_inode(folio));
 
 	_enter("{{%llx:%llu}[%lu]}", dvnode->fid.vid, dvnode->fid.vnode, folio_index(folio));
 
@@ -2042,7 +2042,7 @@ static void afs_dir_invalidatepage(struct page *subpage, unsigned int offset,
 				   unsigned int length)
 {
 	struct folio *folio = page_folio(subpage);
-	struct afs_vnode *dvnode = AFS_FS_I(folio_mapping(folio)->host);
+	struct afs_vnode *dvnode = AFS_FS_I(folio_inode(folio));
 
 	_enter("{%lu},%u,%u", folio_index(folio), offset, length);
 
diff --git a/fs/afs/file.c b/fs/afs/file.c
index 8d72ad7571e4..3585b90486af 100644
--- a/fs/afs/file.c
+++ b/fs/afs/file.c
@@ -392,7 +392,7 @@ static void afs_readahead(struct readahead_control *ractl)
 static void afs_invalidate_dirty(struct folio *folio, unsigned int offset,
 				 unsigned int length)
 {
-	struct afs_vnode *vnode = AFS_FS_I(folio_mapping(folio)->host);
+	struct afs_vnode *vnode = AFS_FS_I(folio_inode(folio));
 	unsigned long priv;
 	unsigned int f, t, end = offset + length;
 
@@ -470,7 +470,7 @@ static void afs_invalidatepage(struct page *page, unsigned int offset,
 static int afs_releasepage(struct page *page, gfp_t gfp_flags)
 {
 	struct folio *folio = page_folio(page);
-	struct afs_vnode *vnode = AFS_FS_I(folio_mapping(folio)->host);
+	struct afs_vnode *vnode = AFS_FS_I(folio_inode(folio));
 
 	_enter("{{%llx:%llu}[%lu],%lx},%x",
 	       vnode->fid.vid, vnode->fid.vnode, folio_index(folio), folio->flags,
diff --git a/fs/afs/write.c b/fs/afs/write.c
index a639fb94298c..44f3f2323486 100644
--- a/fs/afs/write.c
+++ b/fs/afs/write.c
@@ -911,8 +911,7 @@ void afs_prune_wb_keys(struct afs_vnode *vnode)
 int afs_launder_page(struct page *subpage)
 {
 	struct folio *folio = page_folio(subpage);
-	struct address_space *mapping = folio_mapping(folio);
-	struct afs_vnode *vnode = AFS_FS_I(mapping->host);
+	struct afs_vnode *vnode = AFS_FS_I(folio_inode(folio));
 	struct iov_iter iter;
 	struct bio_vec bv[1];
 	unsigned long priv;
diff --git a/fs/netfs/read_helper.c b/fs/netfs/read_helper.c
index fd4ca897785f..5a6aa7b1ae79 100644
--- a/fs/netfs/read_helper.c
+++ b/fs/netfs/read_helper.c
@@ -1024,7 +1024,7 @@ EXPORT_SYMBOL(netfs_readpage);
  */
 static bool netfs_skip_folio_read(struct folio *folio, loff_t pos, size_t len)
 {
-	struct inode *inode = folio_mapping(folio)->host;
+	struct inode *inode = folio_inode(folio);
 	loff_t i_size = i_size_read(inode);
 	size_t offset = offset_in_folio(folio, pos);
 
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 72149be4373b..696306a93e45 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -203,6 +203,20 @@ static inline struct address_space *page_mapping_file(struct page *page)
 	return folio_mapping(folio);
 }
 
+/**
+ * folio_inode - Get the host inode for this folio.
+ * @folio: The folio.
+ *
+ * For folios which are in the page cache, return the inode that is hosting
+ * this folio belongs to.
+ *
+ * Do not call this for folios which aren't in the page cache.
+ */
+static inline struct inode *folio_inode(struct folio *folio)
+{
+	return folio_mapping(folio)->host;
+}
+
 static inline bool page_cache_add_speculative(struct page *page, int count)
 {
 	VM_BUG_ON_PAGE(PageTail(page), page);






[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux OMAP]     [Linux MIPS]     [eCos]     [Asterisk Internet PBX]     [Linux API]

  Powered by Linux