1 /* SPDX-License-Identifier: GPL-2.0 */
3 #ifndef BTRFS_SUBPAGE_H
4 #define BTRFS_SUBPAGE_H
6 #include <linux/spinlock.h>
9 * Maximum page size we support is 64K, minimum sector size is 4K, u16 bitmap
10 * is sufficient. Regular bitmap_* is not used due to size reasons.
12 #define BTRFS_SUBPAGE_BITMAP_SIZE 16
15 * Structure to trace status of each sector inside a page, attached to
16 * page::private for both data and metadata inodes.
18 struct btrfs_subpage {
19 /* Common members for both data and metadata pages */
27 * Structures only used by metadata
29 * @eb_refs should only be operated under private_lock, as it
30 * manages whether the subpage can be detached.
33 /* Structures only used by data */
38 /* Tracke pending ordered extent in this sector */
44 enum btrfs_subpage_type {
45 BTRFS_SUBPAGE_METADATA,
49 int btrfs_attach_subpage(const struct btrfs_fs_info *fs_info,
50 struct page *page, enum btrfs_subpage_type type);
51 void btrfs_detach_subpage(const struct btrfs_fs_info *fs_info,
54 /* Allocate additional data where page represents more than one sector */
55 int btrfs_alloc_subpage(const struct btrfs_fs_info *fs_info,
56 struct btrfs_subpage **ret,
57 enum btrfs_subpage_type type);
58 void btrfs_free_subpage(struct btrfs_subpage *subpage);
60 void btrfs_page_inc_eb_refs(const struct btrfs_fs_info *fs_info,
62 void btrfs_page_dec_eb_refs(const struct btrfs_fs_info *fs_info,
65 void btrfs_subpage_start_reader(const struct btrfs_fs_info *fs_info,
66 struct page *page, u64 start, u32 len);
67 void btrfs_subpage_end_reader(const struct btrfs_fs_info *fs_info,
68 struct page *page, u64 start, u32 len);
70 void btrfs_subpage_start_writer(const struct btrfs_fs_info *fs_info,
71 struct page *page, u64 start, u32 len);
72 bool btrfs_subpage_end_and_test_writer(const struct btrfs_fs_info *fs_info,
73 struct page *page, u64 start, u32 len);
74 int btrfs_page_start_writer_lock(const struct btrfs_fs_info *fs_info,
75 struct page *page, u64 start, u32 len);
76 void btrfs_page_end_writer_lock(const struct btrfs_fs_info *fs_info,
77 struct page *page, u64 start, u32 len);
80 * Template for subpage related operations.
82 * btrfs_subpage_*() are for call sites where the page has subpage attached and
83 * the range is ensured to be inside the page.
85 * btrfs_page_*() are for call sites where the page can either be subpage
86 * specific or regular page. The function will handle both cases.
87 * But the range still needs to be inside the page.
89 * btrfs_page_clamp_*() are similar to btrfs_page_*(), except the range doesn't
90 * need to be inside the page. Those functions will truncate the range
93 #define DECLARE_BTRFS_SUBPAGE_OPS(name) \
94 void btrfs_subpage_set_##name(const struct btrfs_fs_info *fs_info, \
95 struct page *page, u64 start, u32 len); \
96 void btrfs_subpage_clear_##name(const struct btrfs_fs_info *fs_info, \
97 struct page *page, u64 start, u32 len); \
98 bool btrfs_subpage_test_##name(const struct btrfs_fs_info *fs_info, \
99 struct page *page, u64 start, u32 len); \
100 void btrfs_page_set_##name(const struct btrfs_fs_info *fs_info, \
101 struct page *page, u64 start, u32 len); \
102 void btrfs_page_clear_##name(const struct btrfs_fs_info *fs_info, \
103 struct page *page, u64 start, u32 len); \
104 bool btrfs_page_test_##name(const struct btrfs_fs_info *fs_info, \
105 struct page *page, u64 start, u32 len); \
106 void btrfs_page_clamp_set_##name(const struct btrfs_fs_info *fs_info, \
107 struct page *page, u64 start, u32 len); \
108 void btrfs_page_clamp_clear_##name(const struct btrfs_fs_info *fs_info, \
109 struct page *page, u64 start, u32 len); \
110 bool btrfs_page_clamp_test_##name(const struct btrfs_fs_info *fs_info, \
111 struct page *page, u64 start, u32 len);
113 DECLARE_BTRFS_SUBPAGE_OPS(uptodate);
114 DECLARE_BTRFS_SUBPAGE_OPS(error);
115 DECLARE_BTRFS_SUBPAGE_OPS(dirty);
116 DECLARE_BTRFS_SUBPAGE_OPS(writeback);
117 DECLARE_BTRFS_SUBPAGE_OPS(ordered);
119 bool btrfs_subpage_clear_and_test_dirty(const struct btrfs_fs_info *fs_info,
120 struct page *page, u64 start, u32 len);