blob: e693e1b4ac4a4ac01b907264a5a5b37278afc54b [file] [log] [blame]
Chris Masona52d9a82007-08-27 16:49:44 -04001#ifndef __EXTENTMAP__
2#define __EXTENTMAP__
3
4#include <linux/rbtree.h>
5
Chris Masond1310b22008-01-24 16:13:08 -05006#define EXTENT_MAP_LAST_BYTE (u64)-4
Chris Mason5f39d392007-10-15 16:14:19 -04007#define EXTENT_MAP_HOLE (u64)-3
Chris Masona52d9a82007-08-27 16:49:44 -04008#define EXTENT_MAP_INLINE (u64)-2
9#define EXTENT_MAP_DELALLOC (u64)-1
10
Chris Mason7f3c74f2008-07-18 12:01:11 -040011/* bits for the flags field */
12#define EXTENT_FLAG_PINNED 0 /* this entry not yet on disk, don't free it */
Chris Masonc8b97812008-10-29 14:49:59 -040013#define EXTENT_FLAG_COMPRESSED 1
Yan Zheng9036c102008-10-30 14:19:41 -040014#define EXTENT_FLAG_VACANCY 2 /* no file extent item found */
Chris Mason7f3c74f2008-07-18 12:01:11 -040015
Chris Masond1310b22008-01-24 16:13:08 -050016struct extent_map {
17 struct rb_node rb_node;
Chris Mason5f39d392007-10-15 16:14:19 -040018
Chris Masond1310b22008-01-24 16:13:08 -050019 /* all of these are in bytes */
20 u64 start;
21 u64 len;
22 u64 block_start;
Chris Masonc8b97812008-10-29 14:49:59 -040023 u64 block_len;
Chris Masond1310b22008-01-24 16:13:08 -050024 unsigned long flags;
25 struct block_device *bdev;
26 atomic_t refs;
27 int in_tree;
Chris Mason07157aa2007-08-30 08:50:51 -040028};
29
Chris Masona52d9a82007-08-27 16:49:44 -040030struct extent_map_tree {
31 struct rb_root map;
Chris Masond1310b22008-01-24 16:13:08 -050032 spinlock_t lock;
Chris Masona52d9a82007-08-27 16:49:44 -040033};
34
Chris Masond1310b22008-01-24 16:13:08 -050035static inline u64 extent_map_end(struct extent_map *em)
36{
37 if (em->start + em->len < em->start)
38 return (u64)-1;
39 return em->start + em->len;
40}
Chris Masona52d9a82007-08-27 16:49:44 -040041
Chris Masond1310b22008-01-24 16:13:08 -050042static inline u64 extent_map_block_end(struct extent_map *em)
43{
Chris Masonc8b97812008-10-29 14:49:59 -040044 if (em->block_start + em->block_len < em->block_start)
Chris Masond1310b22008-01-24 16:13:08 -050045 return (u64)-1;
Chris Masonc8b97812008-10-29 14:49:59 -040046 return em->block_start + em->block_len;
Chris Masond1310b22008-01-24 16:13:08 -050047}
Chris Mason07157aa2007-08-30 08:50:51 -040048
Chris Masond1310b22008-01-24 16:13:08 -050049void extent_map_tree_init(struct extent_map_tree *tree, gfp_t mask);
Chris Masona52d9a82007-08-27 16:49:44 -040050struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
Chris Masond1310b22008-01-24 16:13:08 -050051 u64 start, u64 len);
Chris Masona52d9a82007-08-27 16:49:44 -040052int add_extent_mapping(struct extent_map_tree *tree,
53 struct extent_map *em);
54int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
Chris Masond1310b22008-01-24 16:13:08 -050055
Chris Masona52d9a82007-08-27 16:49:44 -040056struct extent_map *alloc_extent_map(gfp_t mask);
57void free_extent_map(struct extent_map *em);
Wyatt Banks2f4cbe62007-11-19 10:22:33 -050058int __init extent_map_init(void);
Christian Hesse17636e02007-12-11 09:25:06 -050059void extent_map_exit(void);
Chris Masona52d9a82007-08-27 16:49:44 -040060#endif