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