extent_map.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #ifndef __EXTENTMAP__
  2. #define __EXTENTMAP__
  3. #include <linux/rbtree.h>
  4. #define EXTENT_MAP_LAST_BYTE ((u64)-4)
  5. #define EXTENT_MAP_HOLE ((u64)-3)
  6. #define EXTENT_MAP_INLINE ((u64)-2)
  7. #define EXTENT_MAP_DELALLOC ((u64)-1)
  8. /* bits for the flags field */
  9. #define EXTENT_FLAG_PINNED 0 /* this entry not yet on disk, don't free it */
  10. #define EXTENT_FLAG_COMPRESSED 1
  11. #define EXTENT_FLAG_VACANCY 2 /* no file extent item found */
  12. #define EXTENT_FLAG_PREALLOC 3 /* pre-allocated extent */
  13. #define EXTENT_FLAG_LOGGING 4 /* Logging this extent */
  14. #define EXTENT_FLAG_FILLING 5 /* Filling in a preallocated extent */
  15. #define EXTENT_FLAG_FS_MAPPING 6 /* filesystem extent mapping type */
  16. struct extent_map {
  17. struct rb_node rb_node;
  18. /* all of these are in bytes */
  19. u64 start;
  20. u64 len;
  21. u64 mod_start;
  22. u64 mod_len;
  23. u64 orig_start;
  24. u64 orig_block_len;
  25. u64 ram_bytes;
  26. u64 block_start;
  27. u64 block_len;
  28. u64 generation;
  29. unsigned long flags;
  30. struct block_device *bdev;
  31. atomic_t refs;
  32. unsigned int compress_type;
  33. struct list_head list;
  34. };
  35. struct extent_map_tree {
  36. struct rb_root map;
  37. struct list_head modified_extents;
  38. rwlock_t lock;
  39. };
  40. static inline int extent_map_in_tree(const struct extent_map *em)
  41. {
  42. return !RB_EMPTY_NODE(&em->rb_node);
  43. }
  44. static inline u64 extent_map_end(struct extent_map *em)
  45. {
  46. if (em->start + em->len < em->start)
  47. return (u64)-1;
  48. return em->start + em->len;
  49. }
  50. static inline u64 extent_map_block_end(struct extent_map *em)
  51. {
  52. if (em->block_start + em->block_len < em->block_start)
  53. return (u64)-1;
  54. return em->block_start + em->block_len;
  55. }
  56. void extent_map_tree_init(struct extent_map_tree *tree);
  57. struct extent_map *lookup_extent_mapping(struct extent_map_tree *tree,
  58. u64 start, u64 len);
  59. int add_extent_mapping(struct extent_map_tree *tree,
  60. struct extent_map *em, int modified);
  61. int remove_extent_mapping(struct extent_map_tree *tree, struct extent_map *em);
  62. void replace_extent_mapping(struct extent_map_tree *tree,
  63. struct extent_map *cur,
  64. struct extent_map *new,
  65. int modified);
  66. struct extent_map *alloc_extent_map(void);
  67. void free_extent_map(struct extent_map *em);
  68. int __init extent_map_init(void);
  69. void extent_map_exit(void);
  70. int unpin_extent_cache(struct extent_map_tree *tree, u64 start, u64 len, u64 gen);
  71. void clear_em_logging(struct extent_map_tree *tree, struct extent_map *em);
  72. struct extent_map *search_extent_mapping(struct extent_map_tree *tree,
  73. u64 start, u64 len);
  74. #endif