blob: fb6eeef06bb0a88abcf9297c2c6d9156a35af552 [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 */
Yan Zhengd899e052008-10-30 14:25:28 -040015#define EXTENT_FLAG_PREALLOC 3 /* pre-allocated extent */
Chris Mason7f3c74f2008-07-18 12:01:11 -040016
Chris Masond1310b22008-01-24 16:13:08 -050017struct extent_map {
18 struct rb_node rb_node;
Chris Mason5f39d392007-10-15 16:14:19 -040019
Chris Masond1310b22008-01-24 16:13:08 -050020 /* all of these are in bytes */
21 u64 start;
22 u64 len;
Yan Zhengff5b7ee2008-11-10 07:34:43 -050023 u64 orig_start;
Chris Masond1310b22008-01-24 16:13:08 -050024 u64 block_start;
Chris Masonc8b97812008-10-29 14:49:59 -040025 u64 block_len;
Chris Masond1310b22008-01-24 16:13:08 -050026 unsigned long flags;
27 struct block_device *bdev;
28 atomic_t refs;
29 int in_tree;
Chris Mason07157aa2007-08-30 08:50:51 -040030};
31
Chris Masona52d9a82007-08-27 16:49:44 -040032struct extent_map_tree {
33 struct rb_root map;
Chris Masond1310b22008-01-24 16:13:08 -050034 spinlock_t lock;
Chris Masona52d9a82007-08-27 16:49:44 -040035};
36
Chris Masond1310b22008-01-24 16:13:08 -050037static inline u64 extent_map_end(struct extent_map *em)
38{
39 if (em->start + em->len < em->start)
40 return (u64)-1;
41 return em->start + em->len;
42}
Chris Masona52d9a82007-08-27 16:49:44 -040043
Chris Masond1310b22008-01-24 16:13:08 -050044static inline u64 extent_map_block_end(struct extent_map *em)
45{
Chris Masonc8b97812008-10-29 14:49:59 -040046 if (em->block_start + em->block_len < em->block_start)
Chris Masond1310b22008-01-24 16:13:08 -050047 return (u64)-1;
Chris Masonc8b97812008-10-29 14:49:59 -040048 return em->block_start + em->block_len;
Chris Masond1310b22008-01-24 16:13:08 -050049}
Chris Mason07157aa2007-08-30 08:50:51 -040050
Chris Masond1310b22008-01-24 16:13:08 -050051void extent_map_tree_init(struct extent_map_tree *tree, gfp_t mask);
Chris Masona52d9a82007-08-27 16:49:44 -040052struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
Chris Masond1310b22008-01-24 16:13:08 -050053 u64 start, u64 len);
Chris Masona52d9a82007-08-27 16:49:44 -040054int add_extent_mapping(struct extent_map_tree *tree,
55 struct extent_map *em);
56int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
Chris Masond1310b22008-01-24 16:13:08 -050057
Chris Masona52d9a82007-08-27 16:49:44 -040058struct extent_map *alloc_extent_map(gfp_t mask);
59void free_extent_map(struct extent_map *em);
Wyatt Banks2f4cbe62007-11-19 10:22:33 -050060int __init extent_map_init(void);
Christian Hesse17636e02007-12-11 09:25:06 -050061void extent_map_exit(void);
Chris Masona52d9a82007-08-27 16:49:44 -040062#endif