]>
Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
a52d9a80 CM |
2 | #ifndef __EXTENTMAP__ |
3 | #define __EXTENTMAP__ | |
4 | ||
5 | #include <linux/rbtree.h> | |
490b54d6 | 6 | #include <linux/refcount.h> |
a52d9a80 | 7 | |
e248e04e DG |
8 | #define EXTENT_MAP_LAST_BYTE ((u64)-4) |
9 | #define EXTENT_MAP_HOLE ((u64)-3) | |
10 | #define EXTENT_MAP_INLINE ((u64)-2) | |
11 | #define EXTENT_MAP_DELALLOC ((u64)-1) | |
a52d9a80 | 12 | |
7f3c74fb CM |
13 | /* bits for the flags field */ |
14 | #define EXTENT_FLAG_PINNED 0 /* this entry not yet on disk, don't free it */ | |
c8b97818 | 15 | #define EXTENT_FLAG_COMPRESSED 1 |
d899e052 | 16 | #define EXTENT_FLAG_PREALLOC 3 /* pre-allocated extent */ |
ff44c6e3 | 17 | #define EXTENT_FLAG_LOGGING 4 /* Logging this extent */ |
b11e234d | 18 | #define EXTENT_FLAG_FILLING 5 /* Filling in a preallocated extent */ |
298a8f9c | 19 | #define EXTENT_FLAG_FS_MAPPING 6 /* filesystem extent mapping type */ |
7f3c74fb | 20 | |
a52d9a80 | 21 | struct extent_map { |
a52d9a80 | 22 | struct rb_node rb_node; |
d1310b2e CM |
23 | |
24 | /* all of these are in bytes */ | |
25 | u64 start; | |
26 | u64 len; | |
4e2f84e6 LB |
27 | u64 mod_start; |
28 | u64 mod_len; | |
ff5b7ee3 | 29 | u64 orig_start; |
b4939680 | 30 | u64 orig_block_len; |
cc95bef6 | 31 | u64 ram_bytes; |
a52d9a80 | 32 | u64 block_start; |
c8b97818 | 33 | u64 block_len; |
5dc562c5 | 34 | u64 generation; |
d1310b2e | 35 | unsigned long flags; |
95617d69 JM |
36 | union { |
37 | struct block_device *bdev; | |
38 | ||
39 | /* | |
40 | * used for chunk mappings | |
41 | * flags & EXTENT_FLAG_FS_MAPPING must be set | |
42 | */ | |
43 | struct map_lookup *map_lookup; | |
44 | }; | |
490b54d6 | 45 | refcount_t refs; |
c08782da | 46 | unsigned int compress_type; |
5dc562c5 | 47 | struct list_head list; |
a52d9a80 CM |
48 | }; |
49 | ||
d1310b2e CM |
50 | struct extent_map_tree { |
51 | struct rb_root map; | |
5dc562c5 | 52 | struct list_head modified_extents; |
890871be | 53 | rwlock_t lock; |
a52d9a80 CM |
54 | }; |
55 | ||
cbc0e928 FM |
56 | static inline int extent_map_in_tree(const struct extent_map *em) |
57 | { | |
58 | return !RB_EMPTY_NODE(&em->rb_node); | |
59 | } | |
60 | ||
d1310b2e CM |
61 | static inline u64 extent_map_end(struct extent_map *em) |
62 | { | |
63 | if (em->start + em->len < em->start) | |
64 | return (u64)-1; | |
65 | return em->start + em->len; | |
66 | } | |
67 | ||
68 | static inline u64 extent_map_block_end(struct extent_map *em) | |
69 | { | |
c8b97818 | 70 | if (em->block_start + em->block_len < em->block_start) |
d1310b2e | 71 | return (u64)-1; |
c8b97818 | 72 | return em->block_start + em->block_len; |
d1310b2e | 73 | } |
a52d9a80 | 74 | |
a8067e02 | 75 | void extent_map_tree_init(struct extent_map_tree *tree); |
a52d9a80 | 76 | struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree, |
d1310b2e | 77 | u64 start, u64 len); |
a52d9a80 | 78 | int add_extent_mapping(struct extent_map_tree *tree, |
09a2a8f9 | 79 | struct extent_map *em, int modified); |
a52d9a80 | 80 | int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em); |
176840b3 FM |
81 | void replace_extent_mapping(struct extent_map_tree *tree, |
82 | struct extent_map *cur, | |
83 | struct extent_map *new, | |
84 | int modified); | |
d1310b2e | 85 | |
172ddd60 | 86 | struct extent_map *alloc_extent_map(void); |
a52d9a80 | 87 | void free_extent_map(struct extent_map *em); |
2f4cbe64 | 88 | int __init extent_map_init(void); |
17636e03 | 89 | void extent_map_exit(void); |
5dc562c5 | 90 | int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len, u64 gen); |
201a9038 | 91 | void clear_em_logging(struct extent_map_tree *tree, struct extent_map *em); |
b917b7c3 CM |
92 | struct extent_map *search_extent_mapping(struct extent_map_tree *tree, |
93 | u64 start, u64 len); | |
c04e61b5 LB |
94 | int btrfs_add_extent_mapping(struct extent_map_tree *em_tree, |
95 | struct extent_map **em_in, u64 start, u64 len); | |
a52d9a80 | 96 | #endif |