extent_io.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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_ORDERED (1 << 9)
  15. #define EXTENT_ORDERED_METADATA (1 << 10)
  16. #define EXTENT_BOUNDARY (1 << 11)
  17. #define EXTENT_IOBITS (EXTENT_LOCKED | EXTENT_WRITEBACK)
  18. /*
  19. * page->private values. Every page that is controlled by the extent
  20. * map has page->private set to one.
  21. */
  22. #define EXTENT_PAGE_PRIVATE 1
  23. #define EXTENT_PAGE_PRIVATE_FIRST_PAGE 3
  24. struct extent_state;
  25. typedef int (extent_submit_bio_hook_t)(struct inode *inode, int rw,
  26. struct bio *bio, int mirror_num);
  27. struct extent_io_ops {
  28. int (*fill_delalloc)(struct inode *inode, u64 start, u64 end);
  29. int (*writepage_start_hook)(struct page *page, u64 start, u64 end);
  30. int (*writepage_io_hook)(struct page *page, u64 start, u64 end);
  31. extent_submit_bio_hook_t *submit_bio_hook;
  32. int (*merge_bio_hook)(struct page *page, unsigned long offset,
  33. size_t size, struct bio *bio);
  34. int (*readpage_io_hook)(struct page *page, u64 start, u64 end);
  35. int (*readpage_io_failed_hook)(struct bio *bio, struct page *page,
  36. u64 start, u64 end,
  37. struct extent_state *state);
  38. int (*writepage_io_failed_hook)(struct bio *bio, struct page *page,
  39. u64 start, u64 end,
  40. struct extent_state *state);
  41. int (*readpage_end_io_hook)(struct page *page, u64 start, u64 end,
  42. struct extent_state *state);
  43. int (*writepage_end_io_hook)(struct page *page, u64 start, u64 end,
  44. struct extent_state *state, int uptodate);
  45. int (*set_bit_hook)(struct inode *inode, u64 start, u64 end,
  46. unsigned long old, unsigned long bits);
  47. int (*clear_bit_hook)(struct inode *inode, u64 start, u64 end,
  48. unsigned long old, unsigned long bits);
  49. int (*write_cache_pages_lock_hook)(struct page *page);
  50. };
  51. struct extent_io_tree {
  52. struct rb_root state;
  53. struct rb_root buffer;
  54. struct address_space *mapping;
  55. u64 dirty_bytes;
  56. spinlock_t lock;
  57. spinlock_t buffer_lock;
  58. struct extent_io_ops *ops;
  59. };
  60. struct extent_state {
  61. u64 start;
  62. u64 end; /* inclusive */
  63. struct rb_node rb_node;
  64. struct extent_io_tree *tree;
  65. wait_queue_head_t wq;
  66. atomic_t refs;
  67. unsigned long state;
  68. /* for use by the FS */
  69. u64 private;
  70. struct list_head leak_list;
  71. };
  72. struct extent_buffer {
  73. u64 start;
  74. unsigned long len;
  75. char *map_token;
  76. char *kaddr;
  77. unsigned long map_start;
  78. unsigned long map_len;
  79. struct page *first_page;
  80. atomic_t refs;
  81. int flags;
  82. struct list_head leak_list;
  83. struct rb_node rb_node;
  84. struct mutex mutex;
  85. };
  86. struct extent_map_tree;
  87. static inline struct extent_state *extent_state_next(struct extent_state *state)
  88. {
  89. struct rb_node *node;
  90. node = rb_next(&state->rb_node);
  91. if (!node)
  92. return NULL;
  93. return rb_entry(node, struct extent_state, rb_node);
  94. }
  95. typedef struct extent_map *(get_extent_t)(struct inode *inode,
  96. struct page *page,
  97. size_t page_offset,
  98. u64 start, u64 len,
  99. int create);
  100. void extent_io_tree_init(struct extent_io_tree *tree,
  101. struct address_space *mapping, gfp_t mask);
  102. int try_release_extent_mapping(struct extent_map_tree *map,
  103. struct extent_io_tree *tree, struct page *page,
  104. gfp_t mask);
  105. int try_release_extent_buffer(struct extent_io_tree *tree, struct page *page);
  106. int try_release_extent_state(struct extent_map_tree *map,
  107. struct extent_io_tree *tree, struct page *page,
  108. gfp_t mask);
  109. int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
  110. int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask);
  111. int extent_read_full_page(struct extent_io_tree *tree, struct page *page,
  112. get_extent_t *get_extent);
  113. int __init extent_io_init(void);
  114. void extent_io_exit(void);
  115. u64 count_range_bits(struct extent_io_tree *tree,
  116. u64 *start, u64 search_end,
  117. u64 max_bytes, unsigned long bits);
  118. int test_range_bit(struct extent_io_tree *tree, u64 start, u64 end,
  119. int bits, int filled);
  120. int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
  121. int bits, gfp_t mask);
  122. int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end,
  123. int bits, int wake, int delete, gfp_t mask);
  124. int set_extent_bits(struct extent_io_tree *tree, u64 start, u64 end,
  125. int bits, gfp_t mask);
  126. int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end,
  127. gfp_t mask);
  128. int set_extent_new(struct extent_io_tree *tree, u64 start, u64 end,
  129. gfp_t mask);
  130. int set_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
  131. gfp_t mask);
  132. int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end,
  133. gfp_t mask);
  134. int clear_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
  135. gfp_t mask);
  136. int clear_extent_ordered_metadata(struct extent_io_tree *tree, u64 start,
  137. u64 end, gfp_t mask);
  138. int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end,
  139. gfp_t mask);
  140. int set_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end,
  141. gfp_t mask);
  142. int find_first_extent_bit(struct extent_io_tree *tree, u64 start,
  143. u64 *start_ret, u64 *end_ret, int bits);
  144. struct extent_state *find_first_extent_bit_state(struct extent_io_tree *tree,
  145. u64 start, int bits);
  146. int extent_invalidatepage(struct extent_io_tree *tree,
  147. struct page *page, unsigned long offset);
  148. int extent_write_full_page(struct extent_io_tree *tree, struct page *page,
  149. get_extent_t *get_extent,
  150. struct writeback_control *wbc);
  151. int extent_writepages(struct extent_io_tree *tree,
  152. struct address_space *mapping,
  153. get_extent_t *get_extent,
  154. struct writeback_control *wbc);
  155. int extent_readpages(struct extent_io_tree *tree,
  156. struct address_space *mapping,
  157. struct list_head *pages, unsigned nr_pages,
  158. get_extent_t get_extent);
  159. int extent_prepare_write(struct extent_io_tree *tree,
  160. struct inode *inode, struct page *page,
  161. unsigned from, unsigned to, get_extent_t *get_extent);
  162. int extent_commit_write(struct extent_io_tree *tree,
  163. struct inode *inode, struct page *page,
  164. unsigned from, unsigned to);
  165. sector_t extent_bmap(struct address_space *mapping, sector_t iblock,
  166. get_extent_t *get_extent);
  167. int set_range_dirty(struct extent_io_tree *tree, u64 start, u64 end);
  168. int set_state_private(struct extent_io_tree *tree, u64 start, u64 private);
  169. int get_state_private(struct extent_io_tree *tree, u64 start, u64 *private);
  170. void set_page_extent_mapped(struct page *page);
  171. struct extent_buffer *alloc_extent_buffer(struct extent_io_tree *tree,
  172. u64 start, unsigned long len,
  173. struct page *page0,
  174. gfp_t mask);
  175. struct extent_buffer *find_extent_buffer(struct extent_io_tree *tree,
  176. u64 start, unsigned long len,
  177. gfp_t mask);
  178. void free_extent_buffer(struct extent_buffer *eb);
  179. int read_extent_buffer_pages(struct extent_io_tree *tree,
  180. struct extent_buffer *eb, u64 start, int wait,
  181. get_extent_t *get_extent, int mirror_num);
  182. static inline void extent_buffer_get(struct extent_buffer *eb)
  183. {
  184. atomic_inc(&eb->refs);
  185. }
  186. int memcmp_extent_buffer(struct extent_buffer *eb, const void *ptrv,
  187. unsigned long start,
  188. unsigned long len);
  189. void read_extent_buffer(struct extent_buffer *eb, void *dst,
  190. unsigned long start,
  191. unsigned long len);
  192. void write_extent_buffer(struct extent_buffer *eb, const void *src,
  193. unsigned long start, unsigned long len);
  194. void copy_extent_buffer(struct extent_buffer *dst, struct extent_buffer *src,
  195. unsigned long dst_offset, unsigned long src_offset,
  196. unsigned long len);
  197. void memcpy_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
  198. unsigned long src_offset, unsigned long len);
  199. void memmove_extent_buffer(struct extent_buffer *dst, unsigned long dst_offset,
  200. unsigned long src_offset, unsigned long len);
  201. void memset_extent_buffer(struct extent_buffer *eb, char c,
  202. unsigned long start, unsigned long len);
  203. int wait_on_extent_buffer_writeback(struct extent_io_tree *tree,
  204. struct extent_buffer *eb);
  205. int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end);
  206. int wait_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, int bits);
  207. int clear_extent_buffer_dirty(struct extent_io_tree *tree,
  208. struct extent_buffer *eb);
  209. int set_extent_buffer_dirty(struct extent_io_tree *tree,
  210. struct extent_buffer *eb);
  211. int set_extent_buffer_uptodate(struct extent_io_tree *tree,
  212. struct extent_buffer *eb);
  213. int clear_extent_buffer_uptodate(struct extent_io_tree *tree,
  214. struct extent_buffer *eb);
  215. int extent_buffer_uptodate(struct extent_io_tree *tree,
  216. struct extent_buffer *eb);
  217. int map_extent_buffer(struct extent_buffer *eb, unsigned long offset,
  218. unsigned long min_len, char **token, char **map,
  219. unsigned long *map_start,
  220. unsigned long *map_len, int km);
  221. int map_private_extent_buffer(struct extent_buffer *eb, unsigned long offset,
  222. unsigned long min_len, char **token, char **map,
  223. unsigned long *map_start,
  224. unsigned long *map_len, int km);
  225. void unmap_extent_buffer(struct extent_buffer *eb, char *token, int km);
  226. int release_extent_buffer_tail_pages(struct extent_buffer *eb);
  227. int extent_range_uptodate(struct extent_io_tree *tree,
  228. u64 start, u64 end);
  229. #endif