Skip to content

Commit 10baad8

Browse files
kdaveroxanan1996
authored andcommitted
btrfs: add helpers to get inode from page/folio pointers
BugLink: https://bugs.launchpad.net/bugs/2060531 [ Upstream commit c8293894afa718653688b2fa98ab68317c875a00 ] Add convenience helpers to get a struct btrfs_inode from a page or folio pointer instead of open coding the chain or intermediate BTRFS_I. This is implemented as a macro (still with type checking) so we don't need full definitions of struct page or address_space. Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com> Stable-dep-of: 86211eea8ae1 ("btrfs: qgroup: validate btrfs_qgroup_inherit parameter") Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Paolo Pisati <paolo.pisati@canonical.com>
1 parent b183d0e commit 10baad8

File tree

4 files changed

+12
-6
lines changed

4 files changed

+12
-6
lines changed

fs/btrfs/disk-io.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,8 @@ static void btree_invalidate_folio(struct folio *folio, size_t offset,
529529
size_t length)
530530
{
531531
struct extent_io_tree *tree;
532-
tree = &BTRFS_I(folio->mapping->host)->io_tree;
532+
533+
tree = &folio_to_inode(folio)->io_tree;
533534
extent_invalidate_folio(tree, folio, offset);
534535
btree_release_folio(folio, GFP_NOFS);
535536
if (folio_get_private(folio)) {

fs/btrfs/extent_io.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -827,7 +827,7 @@ static void submit_extent_page(struct btrfs_bio_ctrl *bio_ctrl,
827827
u64 disk_bytenr, struct page *page,
828828
size_t size, unsigned long pg_offset)
829829
{
830-
struct btrfs_inode *inode = BTRFS_I(page->mapping->host);
830+
struct btrfs_inode *inode = page_to_inode(page);
831831

832832
ASSERT(pg_offset + size <= PAGE_SIZE);
833833
ASSERT(bio_ctrl->end_io_func);
@@ -1161,7 +1161,7 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached,
11611161
int btrfs_read_folio(struct file *file, struct folio *folio)
11621162
{
11631163
struct page *page = &folio->page;
1164-
struct btrfs_inode *inode = BTRFS_I(page->mapping->host);
1164+
struct btrfs_inode *inode = page_to_inode(page);
11651165
u64 start = page_offset(page);
11661166
u64 end = start + PAGE_SIZE - 1;
11671167
struct btrfs_bio_ctrl bio_ctrl = { .opf = REQ_OP_READ };
@@ -1184,7 +1184,7 @@ static inline void contiguous_readpages(struct page *pages[], int nr_pages,
11841184
struct btrfs_bio_ctrl *bio_ctrl,
11851185
u64 *prev_em_start)
11861186
{
1187-
struct btrfs_inode *inode = BTRFS_I(pages[0]->mapping->host);
1187+
struct btrfs_inode *inode = page_to_inode(pages[0]);
11881188
int index;
11891189

11901190
btrfs_lock_and_flush_ordered_range(inode, start, end, NULL);
@@ -2382,7 +2382,7 @@ int try_release_extent_mapping(struct page *page, gfp_t mask)
23822382
struct extent_map *em;
23832383
u64 start = page_offset(page);
23842384
u64 end = start + PAGE_SIZE - 1;
2385-
struct btrfs_inode *btrfs_inode = BTRFS_I(page->mapping->host);
2385+
struct btrfs_inode *btrfs_inode = page_to_inode(page);
23862386
struct extent_io_tree *tree = &btrfs_inode->io_tree;
23872387
struct extent_map_tree *map = &btrfs_inode->extent_tree;
23882388

fs/btrfs/fs.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,11 @@ struct btrfs_fs_info {
829829
#endif
830830
};
831831

832+
#define page_to_inode(_page) (BTRFS_I(_Generic((_page), \
833+
struct page *: (_page))->mapping->host))
834+
#define folio_to_inode(_folio) (BTRFS_I(_Generic((_folio), \
835+
struct folio *: (_folio))->mapping->host))
836+
832837
static inline u64 btrfs_get_fs_generation(const struct btrfs_fs_info *fs_info)
833838
{
834839
return READ_ONCE(fs_info->generation);

fs/btrfs/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7970,7 +7970,7 @@ static int btrfs_migrate_folio(struct address_space *mapping,
79707970
static void btrfs_invalidate_folio(struct folio *folio, size_t offset,
79717971
size_t length)
79727972
{
7973-
struct btrfs_inode *inode = BTRFS_I(folio->mapping->host);
7973+
struct btrfs_inode *inode = folio_to_inode(folio);
79747974
struct btrfs_fs_info *fs_info = inode->root->fs_info;
79757975
struct extent_io_tree *tree = &inode->io_tree;
79767976
struct extent_state *cached_state = NULL;

0 commit comments

Comments
 (0)