]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - fs/btrfs/extent_map.h
UBUNTU: Ubuntu-4.13.0-45.50
[mirror_ubuntu-artful-kernel.git] / fs / btrfs / extent_map.h
CommitLineData
a52d9a80
CM
1#ifndef __EXTENTMAP__
2#define __EXTENTMAP__
3
4#include <linux/rbtree.h>
490b54d6 5#include <linux/refcount.h>
a52d9a80 6
e248e04e
DG
7#define EXTENT_MAP_LAST_BYTE ((u64)-4)
8#define EXTENT_MAP_HOLE ((u64)-3)
9#define EXTENT_MAP_INLINE ((u64)-2)
10#define EXTENT_MAP_DELALLOC ((u64)-1)
a52d9a80 11
7f3c74fb
CM
12/* bits for the flags field */
13#define EXTENT_FLAG_PINNED 0 /* this entry not yet on disk, don't free it */
c8b97818 14#define EXTENT_FLAG_COMPRESSED 1
9036c102 15#define EXTENT_FLAG_VACANCY 2 /* no file extent item found */
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 21struct 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
50struct 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
56static inline int extent_map_in_tree(const struct extent_map *em)
57{
58 return !RB_EMPTY_NODE(&em->rb_node);
59}
60
d1310b2e
CM
61static 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
68static 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 75void extent_map_tree_init(struct extent_map_tree *tree);
a52d9a80 76struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
d1310b2e 77 u64 start, u64 len);
a52d9a80 78int add_extent_mapping(struct extent_map_tree *tree,
09a2a8f9 79 struct extent_map *em, int modified);
a52d9a80 80int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
176840b3
FM
81void replace_extent_mapping(struct extent_map_tree *tree,
82 struct extent_map *cur,
83 struct extent_map *new,
84 int modified);
d1310b2e 85
172ddd60 86struct extent_map *alloc_extent_map(void);
a52d9a80 87void free_extent_map(struct extent_map *em);
2f4cbe64 88int __init extent_map_init(void);
17636e03 89void extent_map_exit(void);
5dc562c5 90int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len, u64 gen);
201a9038 91void clear_em_logging(struct extent_map_tree *tree, struct extent_map *em);
b917b7c3
CM
92struct extent_map *search_extent_mapping(struct extent_map_tree *tree,
93 u64 start, u64 len);
a52d9a80 94#endif