Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
David Sterba | 9888c34 | 2018-04-03 19:16:55 +0200 | [diff] [blame] | 2 | |
| 3 | #ifndef BTRFS_EXTENT_IO_H |
| 4 | #define BTRFS_EXTENT_IO_H |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 5 | |
| 6 | #include <linux/rbtree.h> |
Elena Reshetova | b7ac31b | 2017-03-03 10:55:19 +0200 | [diff] [blame] | 7 | #include <linux/refcount.h> |
Christoph Hellwig | 10c5db2 | 2020-05-23 09:30:11 +0200 | [diff] [blame] | 8 | #include <linux/fiemap.h> |
Qu Wenruo | ac46777 | 2015-10-12 12:08:16 +0800 | [diff] [blame] | 9 | #include "ulist.h" |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 10 | |
Li Zefan | 261507a0 | 2010-12-17 14:21:50 +0800 | [diff] [blame] | 11 | /* |
| 12 | * flags for bio submission. The high bits indicate the compression |
| 13 | * type for this bio |
| 14 | */ |
Chris Mason | c8b9781 | 2008-10-29 14:49:59 -0400 | [diff] [blame] | 15 | #define EXTENT_BIO_COMPRESSED 1 |
Li Zefan | 261507a0 | 2010-12-17 14:21:50 +0800 | [diff] [blame] | 16 | #define EXTENT_BIO_FLAG_SHIFT 16 |
Chris Mason | c8b9781 | 2008-10-29 14:49:59 -0400 | [diff] [blame] | 17 | |
David Sterba | 80cb383 | 2018-11-27 15:03:20 +0100 | [diff] [blame] | 18 | enum { |
| 19 | EXTENT_BUFFER_UPTODATE, |
| 20 | EXTENT_BUFFER_DIRTY, |
| 21 | EXTENT_BUFFER_CORRUPT, |
| 22 | /* this got triggered by readahead */ |
| 23 | EXTENT_BUFFER_READAHEAD, |
| 24 | EXTENT_BUFFER_TREE_REF, |
| 25 | EXTENT_BUFFER_STALE, |
| 26 | EXTENT_BUFFER_WRITEBACK, |
| 27 | /* read IO error */ |
| 28 | EXTENT_BUFFER_READ_ERR, |
| 29 | EXTENT_BUFFER_UNMAPPED, |
| 30 | EXTENT_BUFFER_IN_TREE, |
| 31 | /* write IO error */ |
| 32 | EXTENT_BUFFER_WRITE_ERR, |
| 33 | }; |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 34 | |
Liu Bo | da2c700 | 2017-02-10 16:41:05 +0100 | [diff] [blame] | 35 | /* these are flags for __process_pages_contig */ |
Josef Bacik | c2790a2 | 2013-07-29 11:20:47 -0400 | [diff] [blame] | 36 | #define PAGE_UNLOCK (1 << 0) |
| 37 | #define PAGE_CLEAR_DIRTY (1 << 1) |
| 38 | #define PAGE_SET_WRITEBACK (1 << 2) |
| 39 | #define PAGE_END_WRITEBACK (1 << 3) |
| 40 | #define PAGE_SET_PRIVATE2 (1 << 4) |
Filipe Manana | 704de49 | 2014-10-06 22:14:22 +0100 | [diff] [blame] | 41 | #define PAGE_SET_ERROR (1 << 5) |
Liu Bo | da2c700 | 2017-02-10 16:41:05 +0100 | [diff] [blame] | 42 | #define PAGE_LOCK (1 << 6) |
Chris Mason | a791e35 | 2009-10-08 11:27:10 -0400 | [diff] [blame] | 43 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 44 | /* |
| 45 | * page->private values. Every page that is controlled by the extent |
| 46 | * map has page->private set to one. |
| 47 | */ |
| 48 | #define EXTENT_PAGE_PRIVATE 1 |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 49 | |
Omar Sandoval | 2fe1d55 | 2016-09-22 17:24:20 -0700 | [diff] [blame] | 50 | /* |
| 51 | * The extent buffer bitmap operations are done with byte granularity instead of |
| 52 | * word granularity for two reasons: |
| 53 | * 1. The bitmaps must be little-endian on disk. |
| 54 | * 2. Bitmap items are not guaranteed to be aligned to a word and therefore a |
| 55 | * single word in a bitmap may straddle two pages in the extent buffer. |
| 56 | */ |
| 57 | #define BIT_BYTE(nr) ((nr) / BITS_PER_BYTE) |
| 58 | #define BYTE_MASK ((1 << BITS_PER_BYTE) - 1) |
| 59 | #define BITMAP_FIRST_BYTE_MASK(start) \ |
| 60 | ((BYTE_MASK << ((start) & (BITS_PER_BYTE - 1))) & BYTE_MASK) |
| 61 | #define BITMAP_LAST_BYTE_MASK(nbits) \ |
| 62 | (BYTE_MASK >> (-(nbits) & (BITS_PER_BYTE - 1))) |
| 63 | |
Josef Bacik | ea46679 | 2012-03-26 21:57:36 -0400 | [diff] [blame] | 64 | struct btrfs_root; |
Nikolay Borisov | 6fc0ef6 | 2017-02-20 13:51:03 +0200 | [diff] [blame] | 65 | struct btrfs_inode; |
Miao Xie | facc8a22 | 2013-07-25 19:22:34 +0800 | [diff] [blame] | 66 | struct btrfs_io_bio; |
David Sterba | 47dc196 | 2016-02-11 13:24:13 +0100 | [diff] [blame] | 67 | struct io_failure_record; |
Josef Bacik | 9c7d3a5 | 2019-09-23 10:05:19 -0400 | [diff] [blame] | 68 | struct extent_io_tree; |
David Sterba | a758781 | 2017-06-23 03:05:23 +0200 | [diff] [blame] | 69 | |
Omar Sandoval | 77d5d68 | 2020-04-16 14:46:25 -0700 | [diff] [blame] | 70 | typedef blk_status_t (submit_bio_hook_t)(struct inode *inode, struct bio *bio, |
| 71 | int mirror_num, |
| 72 | unsigned long bio_flags); |
| 73 | |
Qu Wenruo | 8896a08 | 2020-10-21 14:24:53 +0800 | [diff] [blame^] | 74 | typedef blk_status_t (extent_submit_bio_start_t)(struct inode *inode, |
David Sterba | d077929 | 2018-03-08 13:47:33 +0100 | [diff] [blame] | 75 | struct bio *bio, u64 bio_offset); |
David Sterba | a758781 | 2017-06-23 03:05:23 +0200 | [diff] [blame] | 76 | |
Chris Mason | 727011e | 2010-08-06 13:21:20 -0400 | [diff] [blame] | 77 | #define INLINE_EXTENT_BUFFER_PAGES 16 |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 78 | #define MAX_INLINE_EXTENT_BUFFER_SIZE (INLINE_EXTENT_BUFFER_PAGES * PAGE_SIZE) |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 79 | struct extent_buffer { |
| 80 | u64 start; |
| 81 | unsigned long len; |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 82 | unsigned long bflags; |
Josef Bacik | f28491e | 2013-12-16 13:24:27 -0500 | [diff] [blame] | 83 | struct btrfs_fs_info *fs_info; |
Josef Bacik | 3083ee2 | 2012-03-09 16:01:49 -0500 | [diff] [blame] | 84 | spinlock_t refs_lock; |
Chris Mason | 727011e | 2010-08-06 13:21:20 -0400 | [diff] [blame] | 85 | atomic_t refs; |
Josef Bacik | 0b32f4b | 2012-03-13 09:38:00 -0400 | [diff] [blame] | 86 | atomic_t io_pages; |
Josef Bacik | 5cf1ab5 | 2012-04-16 09:42:26 -0400 | [diff] [blame] | 87 | int read_mirror; |
Miao Xie | 19fe0a8 | 2010-10-26 20:57:29 -0400 | [diff] [blame] | 88 | struct rcu_head rcu_head; |
Arne Jansen | 5b25f70 | 2011-09-13 10:55:48 +0200 | [diff] [blame] | 89 | pid_t lock_owner; |
Josef Bacik | 329ced7 | 2020-08-20 11:46:00 -0400 | [diff] [blame] | 90 | bool lock_recursed; |
Josef Bacik | 196d59a | 2020-08-20 11:46:09 -0400 | [diff] [blame] | 91 | struct rw_semaphore lock; |
| 92 | |
Filipe Manana | 656f30d | 2014-09-26 12:25:56 +0100 | [diff] [blame] | 93 | /* >= 0 if eb belongs to a log tree, -1 otherwise */ |
| 94 | short log_index; |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 95 | |
David Sterba | b8dae31 | 2013-02-28 14:54:18 +0000 | [diff] [blame] | 96 | struct page *pages[INLINE_EXTENT_BUFFER_PAGES]; |
Eric Sandeen | 6d49ba1 | 2013-04-22 16:12:31 +0000 | [diff] [blame] | 97 | #ifdef CONFIG_BTRFS_DEBUG |
| 98 | struct list_head leak_list; |
| 99 | #endif |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 100 | }; |
| 101 | |
Qu Wenruo | ac46777 | 2015-10-12 12:08:16 +0800 | [diff] [blame] | 102 | /* |
| 103 | * Structure to record how many bytes and which ranges are set/cleared |
| 104 | */ |
| 105 | struct extent_changeset { |
| 106 | /* How many bytes are set/cleared in this operation */ |
Qu Wenruo | 7bc329c | 2017-02-27 15:10:36 +0800 | [diff] [blame] | 107 | unsigned int bytes_changed; |
Qu Wenruo | ac46777 | 2015-10-12 12:08:16 +0800 | [diff] [blame] | 108 | |
| 109 | /* Changed ranges */ |
David Sterba | 53d3235 | 2017-02-13 13:42:29 +0100 | [diff] [blame] | 110 | struct ulist range_changed; |
Qu Wenruo | ac46777 | 2015-10-12 12:08:16 +0800 | [diff] [blame] | 111 | }; |
| 112 | |
Qu Wenruo | 364ecf3 | 2017-02-27 15:10:38 +0800 | [diff] [blame] | 113 | static inline void extent_changeset_init(struct extent_changeset *changeset) |
| 114 | { |
| 115 | changeset->bytes_changed = 0; |
| 116 | ulist_init(&changeset->range_changed); |
| 117 | } |
| 118 | |
| 119 | static inline struct extent_changeset *extent_changeset_alloc(void) |
| 120 | { |
| 121 | struct extent_changeset *ret; |
| 122 | |
| 123 | ret = kmalloc(sizeof(*ret), GFP_KERNEL); |
| 124 | if (!ret) |
| 125 | return NULL; |
| 126 | |
| 127 | extent_changeset_init(ret); |
| 128 | return ret; |
| 129 | } |
| 130 | |
| 131 | static inline void extent_changeset_release(struct extent_changeset *changeset) |
| 132 | { |
| 133 | if (!changeset) |
| 134 | return; |
| 135 | changeset->bytes_changed = 0; |
| 136 | ulist_release(&changeset->range_changed); |
| 137 | } |
| 138 | |
| 139 | static inline void extent_changeset_free(struct extent_changeset *changeset) |
| 140 | { |
| 141 | if (!changeset) |
| 142 | return; |
| 143 | extent_changeset_release(changeset); |
| 144 | kfree(changeset); |
| 145 | } |
| 146 | |
Li Zefan | 261507a0 | 2010-12-17 14:21:50 +0800 | [diff] [blame] | 147 | static inline void extent_set_compress_type(unsigned long *bio_flags, |
| 148 | int compress_type) |
| 149 | { |
| 150 | *bio_flags |= compress_type << EXTENT_BIO_FLAG_SHIFT; |
| 151 | } |
| 152 | |
| 153 | static inline int extent_compress_type(unsigned long bio_flags) |
| 154 | { |
| 155 | return bio_flags >> EXTENT_BIO_FLAG_SHIFT; |
| 156 | } |
| 157 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 158 | struct extent_map_tree; |
| 159 | |
Nikolay Borisov | fc4f21b1 | 2017-02-20 13:51:06 +0200 | [diff] [blame] | 160 | typedef struct extent_map *(get_extent_t)(struct btrfs_inode *inode, |
Omar Sandoval | 39b07b5 | 2019-12-02 17:34:23 -0800 | [diff] [blame] | 161 | struct page *page, size_t pg_offset, |
| 162 | u64 start, u64 len); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 163 | |
Nikolay Borisov | 477a30b | 2018-04-19 10:46:34 +0300 | [diff] [blame] | 164 | int try_release_extent_mapping(struct page *page, gfp_t mask); |
David Sterba | f7a52a4 | 2013-04-26 14:56:29 +0000 | [diff] [blame] | 165 | int try_release_extent_buffer(struct page *page); |
David Sterba | cd716d8 | 2015-12-03 14:41:30 +0100 | [diff] [blame] | 166 | |
Nikolay Borisov | c1be9c1 | 2020-09-14 12:37:08 +0300 | [diff] [blame] | 167 | int __must_check submit_one_bio(struct bio *bio, int mirror_num, |
| 168 | unsigned long bio_flags); |
Nikolay Borisov | 0f20881 | 2020-09-14 14:39:16 +0300 | [diff] [blame] | 169 | int btrfs_do_readpage(struct page *page, struct extent_map **em_cached, |
| 170 | struct bio **bio, unsigned long *bio_flags, |
| 171 | unsigned int read_flags, u64 *prev_em_start); |
Nikolay Borisov | 0a9b0e5 | 2017-12-08 15:55:59 +0200 | [diff] [blame] | 172 | int extent_write_full_page(struct page *page, struct writeback_control *wbc); |
Nikolay Borisov | 5e3ee23 | 2017-12-08 15:55:58 +0200 | [diff] [blame] | 173 | int extent_write_locked_range(struct inode *inode, u64 start, u64 end, |
Chris Mason | 771ed68 | 2008-11-06 22:02:51 -0500 | [diff] [blame] | 174 | int mode); |
Nikolay Borisov | 8ae225a | 2018-04-19 10:46:38 +0300 | [diff] [blame] | 175 | int extent_writepages(struct address_space *mapping, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 176 | struct writeback_control *wbc); |
Josef Bacik | 0b32f4b | 2012-03-13 09:38:00 -0400 | [diff] [blame] | 177 | int btree_write_cache_pages(struct address_space *mapping, |
| 178 | struct writeback_control *wbc); |
Matthew Wilcox (Oracle) | ba206a0 | 2020-06-01 21:47:05 -0700 | [diff] [blame] | 179 | void extent_readahead(struct readahead_control *rac); |
Nikolay Borisov | facee0a | 2020-08-31 14:42:49 +0300 | [diff] [blame] | 180 | int extent_fiemap(struct btrfs_inode *inode, struct fiemap_extent_info *fieinfo, |
David Sterba | bab16e2 | 2020-06-23 20:56:12 +0200 | [diff] [blame] | 181 | u64 start, u64 len); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 182 | void set_page_extent_mapped(struct page *page); |
| 183 | |
Josef Bacik | f28491e | 2013-12-16 13:24:27 -0500 | [diff] [blame] | 184 | struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, |
David Sterba | ce3e698 | 2014-06-15 03:00:04 +0200 | [diff] [blame] | 185 | u64 start); |
Omar Sandoval | 0f33122 | 2015-09-29 20:50:31 -0700 | [diff] [blame] | 186 | struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info, |
| 187 | u64 start, unsigned long len); |
David Sterba | 3f556f7 | 2014-06-15 03:20:26 +0200 | [diff] [blame] | 188 | struct extent_buffer *alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info, |
Jeff Mahoney | da17066 | 2016-06-15 09:22:56 -0400 | [diff] [blame] | 189 | u64 start); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 190 | struct extent_buffer *btrfs_clone_extent_buffer(const struct extent_buffer *src); |
Josef Bacik | f28491e | 2013-12-16 13:24:27 -0500 | [diff] [blame] | 191 | struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info, |
Chandra Seetharaman | 452c75c | 2013-10-07 10:45:25 -0500 | [diff] [blame] | 192 | u64 start); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 193 | void free_extent_buffer(struct extent_buffer *eb); |
Josef Bacik | 3083ee2 | 2012-03-09 16:01:49 -0500 | [diff] [blame] | 194 | void free_extent_buffer_stale(struct extent_buffer *eb); |
Arne Jansen | bb82ab8 | 2011-06-10 14:06:53 +0200 | [diff] [blame] | 195 | #define WAIT_NONE 0 |
| 196 | #define WAIT_COMPLETE 1 |
| 197 | #define WAIT_PAGE_LOCK 2 |
Nikolay Borisov | c2ccfbc | 2019-04-10 17:24:40 +0300 | [diff] [blame] | 198 | int read_extent_buffer_pages(struct extent_buffer *eb, int wait, |
David Sterba | 6af49db | 2017-06-23 04:09:57 +0200 | [diff] [blame] | 199 | int mirror_num); |
Josef Bacik | fd8b2b6 | 2013-04-24 16:41:19 -0400 | [diff] [blame] | 200 | void wait_on_extent_buffer_writeback(struct extent_buffer *eb); |
Robin Dong | 479ed9a | 2012-09-29 02:07:47 -0600 | [diff] [blame] | 201 | |
David Sterba | cc5e31a | 2018-03-01 18:20:27 +0100 | [diff] [blame] | 202 | static inline int num_extent_pages(const struct extent_buffer *eb) |
Robin Dong | 479ed9a | 2012-09-29 02:07:47 -0600 | [diff] [blame] | 203 | { |
David Sterba | 8791d43 | 2018-07-04 17:49:31 +0200 | [diff] [blame] | 204 | return (round_up(eb->start + eb->len, PAGE_SIZE) >> PAGE_SHIFT) - |
| 205 | (eb->start >> PAGE_SHIFT); |
Robin Dong | 479ed9a | 2012-09-29 02:07:47 -0600 | [diff] [blame] | 206 | } |
| 207 | |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 208 | static inline int extent_buffer_uptodate(const struct extent_buffer *eb) |
Anand Jain | ba02049 | 2018-02-13 12:35:44 +0800 | [diff] [blame] | 209 | { |
| 210 | return test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags); |
| 211 | } |
| 212 | |
Jeff Mahoney | 1cbb1f4 | 2017-06-28 21:56:53 -0600 | [diff] [blame] | 213 | int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv, |
| 214 | unsigned long start, unsigned long len); |
| 215 | void read_extent_buffer(const struct extent_buffer *eb, void *dst, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 216 | unsigned long start, |
| 217 | unsigned long len); |
Josef Bacik | a48b73e | 2020-08-10 11:42:27 -0400 | [diff] [blame] | 218 | int read_extent_buffer_to_user_nofault(const struct extent_buffer *eb, |
| 219 | void __user *dst, unsigned long start, |
| 220 | unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 221 | void write_extent_buffer_fsid(const struct extent_buffer *eb, const void *src); |
| 222 | void write_extent_buffer_chunk_tree_uuid(const struct extent_buffer *eb, |
David Sterba | f157bf7 | 2016-11-09 17:43:38 +0100 | [diff] [blame] | 223 | const void *src); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 224 | void write_extent_buffer(const struct extent_buffer *eb, const void *src, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 225 | unsigned long start, unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 226 | void copy_extent_buffer_full(const struct extent_buffer *dst, |
| 227 | const struct extent_buffer *src); |
| 228 | void copy_extent_buffer(const struct extent_buffer *dst, |
| 229 | const struct extent_buffer *src, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 230 | unsigned long dst_offset, unsigned long src_offset, |
| 231 | unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 232 | void memcpy_extent_buffer(const struct extent_buffer *dst, |
| 233 | unsigned long dst_offset, unsigned long src_offset, |
| 234 | unsigned long len); |
| 235 | void memmove_extent_buffer(const struct extent_buffer *dst, |
| 236 | unsigned long dst_offset, unsigned long src_offset, |
David Sterba | b159fa2 | 2016-11-08 18:09:03 +0100 | [diff] [blame] | 237 | unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 238 | void memzero_extent_buffer(const struct extent_buffer *eb, unsigned long start, |
| 239 | unsigned long len); |
| 240 | int extent_buffer_test_bit(const struct extent_buffer *eb, unsigned long start, |
Omar Sandoval | 3e1e8bb | 2015-09-29 20:50:30 -0700 | [diff] [blame] | 241 | unsigned long pos); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 242 | void extent_buffer_bitmap_set(const struct extent_buffer *eb, unsigned long start, |
Omar Sandoval | 3e1e8bb | 2015-09-29 20:50:30 -0700 | [diff] [blame] | 243 | unsigned long pos, unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 244 | void extent_buffer_bitmap_clear(const struct extent_buffer *eb, |
| 245 | unsigned long start, unsigned long pos, |
| 246 | unsigned long len); |
| 247 | void clear_extent_buffer_dirty(const struct extent_buffer *eb); |
Liu Bo | abb57ef | 2018-09-14 01:44:42 +0800 | [diff] [blame] | 248 | bool set_extent_buffer_dirty(struct extent_buffer *eb); |
David Sterba | 09c25a8 | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 249 | void set_extent_buffer_uptodate(struct extent_buffer *eb); |
David Sterba | 69ba392 | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 250 | void clear_extent_buffer_uptodate(struct extent_buffer *eb); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 251 | int extent_buffer_under_io(const struct extent_buffer *eb); |
David Sterba | bd1fa4f | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 252 | void extent_range_clear_dirty_for_io(struct inode *inode, u64 start, u64 end); |
David Sterba | f631157 | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 253 | void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end); |
Nikolay Borisov | ad7ff17 | 2020-06-03 08:55:06 +0300 | [diff] [blame] | 254 | void extent_clear_unlock_delalloc(struct btrfs_inode *inode, u64 start, u64 end, |
Nikolay Borisov | 74e9194 | 2019-07-17 16:18:16 +0300 | [diff] [blame] | 255 | struct page *locked_page, |
| 256 | unsigned bits_to_clear, |
| 257 | unsigned long page_ops); |
David Sterba | e749af44 | 2019-06-18 20:00:16 +0200 | [diff] [blame] | 258 | struct bio *btrfs_bio_alloc(u64 first_byte); |
David Sterba | c5e4c3d | 2017-06-12 17:29:41 +0200 | [diff] [blame] | 259 | struct bio *btrfs_io_bio_alloc(unsigned int nr_iovecs); |
David Sterba | 8b6c1d5 | 2017-06-02 17:48:13 +0200 | [diff] [blame] | 260 | struct bio *btrfs_bio_clone(struct bio *bio); |
Liu Bo | e477094 | 2017-05-16 10:57:14 -0700 | [diff] [blame] | 261 | struct bio *btrfs_bio_clone_partial(struct bio *orig, int offset, int size); |
Jan Schmidt | 4a54c8c | 2011-07-22 15:41:52 +0200 | [diff] [blame] | 262 | |
Stefan Behrens | 3ec706c | 2012-11-05 15:46:42 +0100 | [diff] [blame] | 263 | struct btrfs_fs_info; |
Nikolay Borisov | 9d4f7f8 | 2017-02-20 13:50:55 +0200 | [diff] [blame] | 264 | struct btrfs_inode; |
Jan Schmidt | 4a54c8c | 2011-07-22 15:41:52 +0200 | [diff] [blame] | 265 | |
Josef Bacik | 6ec656b | 2017-05-05 11:57:14 -0400 | [diff] [blame] | 266 | int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, |
| 267 | u64 length, u64 logical, struct page *page, |
| 268 | unsigned int pg_offset, int mirror_num); |
David Sterba | b5227c0 | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 269 | void end_extent_writepage(struct page *page, int err, u64 start, u64 end); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 270 | int btrfs_repair_eb_io_failure(const struct extent_buffer *eb, int mirror_num); |
Miao Xie | 2fe6303 | 2014-09-12 18:43:59 +0800 | [diff] [blame] | 271 | |
| 272 | /* |
| 273 | * When IO fails, either with EIO or csum verification fails, we |
| 274 | * try other mirrors that might have a good copy of the data. This |
| 275 | * io_failure_record is used to record state as we go through all the |
| 276 | * mirrors. If another mirror has good data, the page is set up to date |
| 277 | * and things continue. If a good mirror can't be found, the original |
| 278 | * bio end_io callback is called to indicate things have failed. |
| 279 | */ |
| 280 | struct io_failure_record { |
| 281 | struct page *page; |
| 282 | u64 start; |
| 283 | u64 len; |
| 284 | u64 logical; |
| 285 | unsigned long bio_flags; |
| 286 | int this_mirror; |
| 287 | int failed_mirror; |
| 288 | int in_validation; |
| 289 | }; |
| 290 | |
Nikolay Borisov | 4ac1f4a | 2017-02-20 13:50:52 +0200 | [diff] [blame] | 291 | |
Omar Sandoval | 77d5d68 | 2020-04-16 14:46:25 -0700 | [diff] [blame] | 292 | blk_status_t btrfs_submit_read_repair(struct inode *inode, |
| 293 | struct bio *failed_bio, u64 phy_offset, |
| 294 | struct page *page, unsigned int pgoff, |
| 295 | u64 start, u64 end, int failed_mirror, |
| 296 | submit_bio_hook_t *submit_bio_hook); |
| 297 | |
Josef Bacik | 294e30f | 2013-10-09 12:00:56 -0400 | [diff] [blame] | 298 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
Goldwyn Rodrigues | 9978059 | 2019-06-21 10:02:54 -0500 | [diff] [blame] | 299 | bool find_lock_delalloc_range(struct inode *inode, |
Johannes Thumshirn | ce9f967 | 2018-11-19 10:38:17 +0100 | [diff] [blame] | 300 | struct page *locked_page, u64 *start, |
| 301 | u64 *end); |
Chris Mason | 0d4cf4e | 2014-10-07 13:24:20 -0700 | [diff] [blame] | 302 | #endif |
Josef Bacik | faa2dbf | 2014-05-07 17:06:09 -0400 | [diff] [blame] | 303 | struct extent_buffer *alloc_test_extent_buffer(struct btrfs_fs_info *fs_info, |
Jeff Mahoney | da17066 | 2016-06-15 09:22:56 -0400 | [diff] [blame] | 304 | u64 start); |
Josef Bacik | 3fd6372 | 2020-02-14 16:11:40 -0500 | [diff] [blame] | 305 | |
| 306 | #ifdef CONFIG_BTRFS_DEBUG |
| 307 | void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info); |
| 308 | #else |
| 309 | #define btrfs_extent_buffer_leak_debug_check(fs_info) do {} while (0) |
| 310 | #endif |
| 311 | |
Josef Bacik | 294e30f | 2013-10-09 12:00:56 -0400 | [diff] [blame] | 312 | #endif |