extent_io.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. #ifndef __EXTENTIO__
  2. #define __EXTENTIO__
  3. #include <linux/rbtree.h>
  4. /* bits for the extent state */
  5. #define EXTENT_DIRTY 1
  6. #define EXTENT_WRITEBACK (1 << 1)
  7. #define EXTENT_UPTODATE (1 << 2)
  8. #define EXTENT_LOCKED (1 << 3)
  9. #define EXTENT_NEW (1 << 4)
  10. #define EXTENT_DELALLOC (1 << 5)
  11. #define EXTENT_DEFRAG (1 << 6)
  12. #define EXTENT_DEFRAG_DONE (1 << 7)
  13. #define EXTENT_BUFFER_FILLED (1 << 8)
  14. #define EXTENT_CSUM (1 << 9)
  15. #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
  16. /*
  17. * page->private values. Every page that is controlled by the extent
  18. * map has page->private set to one.
  19. */
  20. #define EXTENT_PAGE_PRIVATE 1
  21. #define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
  22. struct extent_state;
  23. struct extent_io_ops {
  24. int (*fill_delalloc)(struct inode *inode, u64 start, u64 end);
  25. int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
  26. int (*submit_bio_hook)(struct inode *inode, int rw, struct bio *bio);
  27. int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
  28. int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
  29. struct extent_state *state);
  30. void (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
  31. struct extent_state *state);
  32. int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
  33. unsigned long old, unsigned long bits);
  34. int (*clear_bit_hook)(struct inode *inode, u64 start, u64 end,
  35. unsigned long old, unsigned long bits);
  36. };
  37. struct extent_io_tree {
  38. struct rb_root state;
  39. struct address_space *mapping;
  40. u64 dirty_bytes;
  41. spinlock_t lock;
  42. struct extent_io_ops *ops;
  43. spinlock_t lru_lock;
  44. struct list_head buffer_lru;
  45. int lru_size;
  46. struct extent_state *last;
  47. };
  48. struct extent_state {
  49. u64 start;
  50. u64 end; /* inclusive */
  51. struct rb_node rb_node;
  52. struct extent_io_tree *tree;
  53. wait_queue_head_t wq;
  54. atomic_t refs;
  55. unsigned long state;
  56. /* for use by the FS */
  57. u64 private;
  58. struct list_head list;
  59. };
  60. struct extent_buffer {
  61. u64 start;
  62. unsigned long len;
  63. char *map_token;
  64. char *kaddr;
  65. unsigned long map_start;
  66. unsigned long map_len;
  67. struct page *first_page;
  68. struct list_head lru;
  69. atomic_t refs;
  70. int flags;
  71. };
  72. struct extent_map_tree;
  73. static inline struct extent_state *extent_state_next(struct extent_state *state)
  74. {
  75. struct rb_node *node;
  76. node = rb_next(&state->rb_node);
  77. if (!node)
  78. return NULL;
  79. return rb_entry(node, struct extent_state, rb_node);
  80. }
  81. typedef struct extent_map *(get_extent_t)(struct inode *inode,
  82. struct page *page,
  83. size_t page_offset,
  84. u64 start, u64 len,
  85. int create);
  86. void extent_io_tree_init(struct extent_io_tree *tree,
  87. struct address_space *mapping, gfp_t mask);
  88. void extent_io_tree_empty_lru(struct extent_io_tree *tree);
  89. int try_release_extent_mapping(struct extent_map_tree *map,
  90. struct extent_io_tree *tree, struct page *page,
  91. gfp_t mask);
  92. int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
  93. int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
  94. int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
  95. get_extent_t *get_extent);
  96. int __init extent_io_init(void);
  97. void extent_io_exit(void);
  98. u64 count_range_bits(struct extent_io_tree *tree,
  99. u64 *start, u64 search_end,
  100. u64 max_bytes, unsigned long bits);
  101. int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
  102. int bits, int filled);
  103. int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
  104. int bits, gfp_t mask);
  105. int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
  106. int bits, gfp_t mask);
  107. int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
  108. gfp_t mask);
  109. int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
  110. gfp_t mask);
  111. int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
  112. gfp_t mask);
  113. int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
  114. gfp_t mask);
  115. int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
  116. gfp_t mask);
  117. int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
  118. u64 *start_ret, u64 *end_ret, int bits);
  119. struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
  120. u64 start, int bits);
  121. int extent_invalidatepage(struct extent_io_tree *tree,
  122. struct page *page, unsigned long offset);
  123. int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
  124. get_extent_t *get_extent,
  125. struct writeback_control *wbc);
  126. int extent_writepages(struct extent_io_tree *tree,
  127. struct address_space *mapping,
  128. get_extent_t *get_extent,
  129. struct writeback_control *wbc);
  130. int extent_readpages(struct extent_io_tree *tree,
  131. struct address_space *mapping,
  132. struct list_head *pages, unsigned nr_pages,
  133. get_extent_t get_extent);
  134. int extent_prepare_write(struct extent_io_tree *tree,
  135. struct inode *inode, struct page *page,
  136. unsigned from, unsigned to, get_extent_t *get_extent);
  137. int extent_commit_write(struct extent_io_tree *tree,
  138. struct inode *inode, struct page *page,
  139. unsigned from, unsigned to);
  140. sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
  141. get_extent_t *get_extent);
  142. int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
  143. int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
  144. int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
  145. void set_page_extent_mapped(struct page *page);
  146. struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
  147. u64 start, unsigned long len,
  148. struct page *page0,
  149. gfp_t mask);
  150. struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
  151. u64 start, unsigned long len,
  152. gfp_t mask);
  153. void free_extent_buffer(struct extent_buffer *eb);
  154. int read_extent_buffer_pages(struct extent_io_tree *tree,
  155. struct extent_buffer *eb, u64 start, int wait,
  156. get_extent_t *get_extent);
  157. static inline void extent_buffer_get(struct extent_buffer *eb)
  158. {
  159. atomic_inc(&eb->refs);
  160. }
  161. int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
  162. unsigned long start,
  163. unsigned long len);
  164. void read_extent_buffer(struct extent_buffer *eb, void *dst,
  165. unsigned long start,
  166. unsigned long len);
  167. void write_extent_buffer(struct extent_buffer *eb, const void *src,
  168. unsigned long start, unsigned long len);
  169. void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
  170. unsigned long dst_offset, unsigned long src_offset,
  171. unsigned long len);
  172. void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
  173. unsigned long src_offset, unsigned long len);
  174. void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
  175. unsigned long src_offset, unsigned long len);
  176. void memset_extent_buffer(struct extent_buffer *eb, char c,
  177. unsigned long start, unsigned long len);
  178. int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
  179. struct extent_buffer *eb);
  180. int clear_extent_buffer_dirty(struct extent_io_tree *tree,
  181. struct extent_buffer *eb);
  182. int set_extent_buffer_dirty(struct extent_io_tree *tree,
  183. struct extent_buffer *eb);
  184. int set_extent_buffer_uptodate(struct extent_io_tree *tree,
  185. struct extent_buffer *eb);
  186. int extent_buffer_uptodate(struct extent_io_tree *tree,
  187. struct extent_buffer *eb);
  188. int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
  189. unsigned long min_len, char **token, char **map,
  190. unsigned long *map_start,
  191. unsigned long *map_len, int km);
  192. int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
  193. unsigned long min_len, char **token, char **map,
  194. unsigned long *map_start,
  195. unsigned long *map_len, int km);
  196. void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
  197. #endif