Commit | Line | Data |
---|---|---|
cac06d84 QW |
1 | /* SPDX-License-Identifier: GPL-2.0 */ |
2 | ||
3 | #ifndef BTRFS_SUBPAGE_H | |
4 | #define BTRFS_SUBPAGE_H | |
5 | ||
6 | #include <linux/spinlock.h> | |
7 | ||
8 | /* | |
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. | |
11 | */ | |
12 | #define BTRFS_SUBPAGE_BITMAP_SIZE 16 | |
13 | ||
14 | /* | |
15 | * Structure to trace status of each sector inside a page, attached to | |
16 | * page::private for both data and metadata inodes. | |
17 | */ | |
18 | struct btrfs_subpage { | |
19 | /* Common members for both data and metadata pages */ | |
20 | spinlock_t lock; | |
a1d767c1 | 21 | u16 uptodate_bitmap; |
03a816b3 | 22 | u16 error_bitmap; |
760f991f | 23 | union { |
8ff8466d QW |
24 | /* |
25 | * Structures only used by metadata | |
26 | * | |
27 | * @eb_refs should only be operated under private_lock, as it | |
28 | * manages whether the subpage can be detached. | |
29 | */ | |
30 | atomic_t eb_refs; | |
760f991f QW |
31 | /* Structures only used by data */ |
32 | }; | |
cac06d84 QW |
33 | }; |
34 | ||
35 | enum btrfs_subpage_type { | |
36 | BTRFS_SUBPAGE_METADATA, | |
37 | BTRFS_SUBPAGE_DATA, | |
38 | }; | |
39 | ||
40 | int btrfs_attach_subpage(const struct btrfs_fs_info *fs_info, | |
41 | struct page *page, enum btrfs_subpage_type type); | |
42 | void btrfs_detach_subpage(const struct btrfs_fs_info *fs_info, | |
43 | struct page *page); | |
44 | ||
760f991f QW |
45 | /* Allocate additional data where page represents more than one sector */ |
46 | int btrfs_alloc_subpage(const struct btrfs_fs_info *fs_info, | |
47 | struct btrfs_subpage **ret, | |
48 | enum btrfs_subpage_type type); | |
49 | void btrfs_free_subpage(struct btrfs_subpage *subpage); | |
50 | ||
8ff8466d QW |
51 | void btrfs_page_inc_eb_refs(const struct btrfs_fs_info *fs_info, |
52 | struct page *page); | |
53 | void btrfs_page_dec_eb_refs(const struct btrfs_fs_info *fs_info, | |
54 | struct page *page); | |
55 | ||
a1d767c1 QW |
56 | /* |
57 | * Template for subpage related operations. | |
58 | * | |
59 | * btrfs_subpage_*() are for call sites where the page has subpage attached and | |
60 | * the range is ensured to be inside the page. | |
61 | * | |
62 | * btrfs_page_*() are for call sites where the page can either be subpage | |
63 | * specific or regular page. The function will handle both cases. | |
64 | * But the range still needs to be inside the page. | |
65 | */ | |
66 | #define DECLARE_BTRFS_SUBPAGE_OPS(name) \ | |
67 | void btrfs_subpage_set_##name(const struct btrfs_fs_info *fs_info, \ | |
68 | struct page *page, u64 start, u32 len); \ | |
69 | void btrfs_subpage_clear_##name(const struct btrfs_fs_info *fs_info, \ | |
70 | struct page *page, u64 start, u32 len); \ | |
71 | bool btrfs_subpage_test_##name(const struct btrfs_fs_info *fs_info, \ | |
72 | struct page *page, u64 start, u32 len); \ | |
73 | void btrfs_page_set_##name(const struct btrfs_fs_info *fs_info, \ | |
74 | struct page *page, u64 start, u32 len); \ | |
75 | void btrfs_page_clear_##name(const struct btrfs_fs_info *fs_info, \ | |
76 | struct page *page, u64 start, u32 len); \ | |
77 | bool btrfs_page_test_##name(const struct btrfs_fs_info *fs_info, \ | |
78 | struct page *page, u64 start, u32 len); | |
79 | ||
80 | DECLARE_BTRFS_SUBPAGE_OPS(uptodate); | |
03a816b3 | 81 | DECLARE_BTRFS_SUBPAGE_OPS(error); |
a1d767c1 | 82 | |
cac06d84 | 83 | #endif |