linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: David Howells <dhowells@redhat.com>
To: willy@infradead.org
Cc: dhowells@redhat.com, linux-mm@kvack.org
Subject: [RFC PATCH] folio: Add a function to get the host inode for a folio
Date: Thu, 12 Aug 2021 22:42:11 +0100	[thread overview]
Message-ID: <162880453171.3369675.3704943108660112470.stgit@warthog.procyon.org.uk> (raw)

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@redhat.com>
---

 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);




             reply	other threads:[~2021-08-12 21:42 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-12 21:42 David Howells [this message]
2021-08-12 22:44 ` Matthew Wilcox
2021-08-13 10:15 ` David Howells

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=162880453171.3369675.3704943108660112470.stgit@warthog.procyon.org.uk \
    --to=dhowells@redhat.com \
    --cc=linux-mm@kvack.org \
    --cc=willy@infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox