Message ID | 162880453171.3369675.3704943108660112470.stgit@warthog.procyon.org.uk (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [RFC] folio: Add a function to get the host inode for a folio | expand |
On Thu, Aug 12, 2021 at 10:42:11PM +0100, David Howells wrote: > 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]. Seems like a good idea. Across my entire devel tree, I find 36 occurrences: $ git log -p origin..devel |grep folio.*mapping.*host + struct inode *inode = folio->mapping->host; + struct inode *dir = folio->mapping->host; + unsigned int nr_blocks = i_blocks_per_folio(page->mapping->host, folio); + struct btrfs_fs_info *fs_info = btrfs_sb(folio->mapping->host->i_sb); + struct afs_vnode *dvnode = AFS_FS_I(folio->mapping->host); + tree = &BTRFS_I(folio->mapping->host)->io_tree; + btrfs_warn(BTRFS_I(folio->mapping->host)->root->fs_info, + struct btrfs_inode *inode = BTRFS_I(folio->mapping->host); + inode = folio->mapping->host; + struct cifsInodeInfo *cifsi = CIFS_I(folio->mapping->host); + struct inode *inode = folio->mapping->host; + struct gfs2_sbd *sdp = GFS2_SB(folio->mapping->host); + trace_iomap_invalidate_folio(folio->mapping->host, offset, len); + nfs_wb_page_cancel(folio_file_mapping(folio)->host, &folio->page); + nfs_fscache_invalidate_page(&folio->page, folio->mapping->host); + struct inode *inode = folio->mapping->host; + struct inode *inode = folio->mapping->host; + struct inode *inode = folio->mapping->host; + struct inode *inode = folio->mapping->host; + struct inode *inode = folio->mapping->host; + int err = fuse_readlink_page(folio->mapping->host, &folio->page); + struct inode *inode = folio->mapping->host; + struct btrfs_inode *inode = BTRFS_I(folios[0]->mapping->host); + struct inode *inode = folio->mapping->host; + __entry->i_ino = folio->mapping->host->i_ino; + if (folio->mapping->host->i_sb) + __entry->s_dev = folio->mapping->host->i_sb->s_dev; + __entry->s_dev = folio->mapping->host->i_rdev; + struct inode *inode = folio->mapping->host; + struct inode *inode = folio->mapping->host; + struct inode *inode = folio->mapping->host; + struct inode *inode = folio->mapping->host; + trace_iomap_invalidatepage(folio->mapping->host, offset, len); + trace_iomap_releasepage(folio->mapping->host, folio_pos(folio), + struct inode *inode = folio->mapping->host; + if (folio->mapping->host->i_sb->s_iflags & SB_I_STABLE_WRITES) It's only two characters less, but it seems worth doing.
David Howells <dhowells@redhat.com> wrote: > +static inline struct inode *folio_inode(struct folio *folio) > +{ > + return folio_mapping(folio)->host; > +} I've changed my mind on how I implemented it. I think that if this is intended to be used from within filesystems, then it should be calling folio_file_mapping() instead - or possibly just doing folio->mapping->host. folio_mapping() seems unnecessarily complex for a page a filesystem is pretty sure belongs to it. David
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);
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(-)