]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: add helpers to get inode from page/folio pointers
authorDavid Sterba <dsterba@suse.com>
Wed, 13 Sep 2023 14:11:29 +0000 (16:11 +0200)
committerDavid Sterba <dsterba@suse.com>
Mon, 4 Mar 2024 15:24:49 +0000 (16:24 +0100)
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>
fs/btrfs/disk-io.c
fs/btrfs/extent_io.c
fs/btrfs/fs.h
fs/btrfs/inode.c

index 0dfa3d4ed8abc5108a23acb8374e35c3842af469..cc142d5184c46702a92d68e20d278bbdb5c34415 100644 (file)
@@ -528,7 +528,8 @@ static void btree_invalidate_folio(struct folio *folio, size_t offset,
                                 size_t length)
 {
        struct extent_io_tree *tree;
-       tree = &BTRFS_I(folio->mapping->host)->io_tree;
+
+       tree = &folio_to_inode(folio)->io_tree;
        extent_invalidate_folio(tree, folio, offset);
        btree_release_folio(folio, GFP_NOFS);
        if (folio_get_private(folio)) {
index 2c4fd7d3c0e378a087e414a60e8cdd198b414fe9..e2416b55432f7871245dc879d0b17309bf2c068f 100644 (file)
@@ -819,7 +819,7 @@ static void submit_extent_page(struct btrfs_bio_ctrl *bio_ctrl,
                               u64 disk_bytenr, struct page *page,
                               size_t size, unsigned long pg_offset)
 {
-       struct btrfs_inode *inode = BTRFS_I(page->mapping->host);
+       struct btrfs_inode *inode = page_to_inode(page);
 
        ASSERT(pg_offset + size <= PAGE_SIZE);
        ASSERT(bio_ctrl->end_io_func);
@@ -1151,7 +1151,7 @@ static int btrfs_do_readpage(struct page *page, struct extent_map **em_cached,
 int btrfs_read_folio(struct file *file, struct folio *folio)
 {
        struct page *page = &folio->page;
-       struct btrfs_inode *inode = BTRFS_I(page->mapping->host);
+       struct btrfs_inode *inode = page_to_inode(page);
        u64 start = page_offset(page);
        u64 end = start + PAGE_SIZE - 1;
        struct btrfs_bio_ctrl bio_ctrl = { .opf = REQ_OP_READ };
@@ -1174,7 +1174,7 @@ static inline void contiguous_readpages(struct page *pages[], int nr_pages,
                                        struct btrfs_bio_ctrl *bio_ctrl,
                                        u64 *prev_em_start)
 {
-       struct btrfs_inode *inode = BTRFS_I(pages[0]->mapping->host);
+       struct btrfs_inode *inode = page_to_inode(pages[0]);
        int index;
 
        btrfs_lock_and_flush_ordered_range(inode, start, end, NULL);
@@ -2372,7 +2372,7 @@ int try_release_extent_mapping(struct page *page, gfp_t mask)
        struct extent_map *em;
        u64 start = page_offset(page);
        u64 end = start + PAGE_SIZE - 1;
-       struct btrfs_inode *btrfs_inode = BTRFS_I(page->mapping->host);
+       struct btrfs_inode *btrfs_inode = page_to_inode(page);
        struct extent_io_tree *tree = &btrfs_inode->io_tree;
        struct extent_map_tree *map = &btrfs_inode->extent_tree;
 
index 97d10ed4b2c12c8b54369e1a704d33101390ae3d..d9a8290152742fb3cf57474d3f7f615a0ff983bc 100644 (file)
@@ -831,6 +831,11 @@ struct btrfs_fs_info {
 #endif
 };
 
+#define page_to_inode(_page)   (BTRFS_I(_Generic((_page),                      \
+                                         struct page *: (_page))->mapping->host))
+#define folio_to_inode(_folio) (BTRFS_I(_Generic((_folio),                     \
+                                         struct folio *: (_folio))->mapping->host))
+
 static inline u64 btrfs_get_fs_generation(const struct btrfs_fs_info *fs_info)
 {
        return READ_ONCE(fs_info->generation);
index 469963c89c67b8c207c9c933b6c7507cf69cd860..e0726e62b3e62979ff3f05212ebc54e1e18be35e 100644 (file)
@@ -7971,7 +7971,7 @@ static int btrfs_migrate_folio(struct address_space *mapping,
 static void btrfs_invalidate_folio(struct folio *folio, size_t offset,
                                 size_t length)
 {
-       struct btrfs_inode *inode = BTRFS_I(folio->mapping->host);
+       struct btrfs_inode *inode = folio_to_inode(folio);
        struct btrfs_fs_info *fs_info = inode->root->fs_info;
        struct extent_io_tree *tree = &inode->io_tree;
        struct extent_state *cached_state = NULL;