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 | |
David Sterba | a758781 | 2017-06-23 03:05:23 +0200 | [diff] [blame] | 74 | typedef blk_status_t (extent_submit_bio_start_t)(void *private_data, |
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 | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 77 | struct extent_io_ops { |
David Sterba | 4d53ddd | 2017-02-17 15:27:44 +0100 | [diff] [blame] | 78 | /* |
Andrea Gelmini | 52042d8 | 2018-11-28 12:05:13 +0100 | [diff] [blame] | 79 | * The following callbacks must be always defined, the function |
David Sterba | 4d53ddd | 2017-02-17 15:27:44 +0100 | [diff] [blame] | 80 | * pointer will be called unconditionally. |
| 81 | */ |
Omar Sandoval | 77d5d68 | 2020-04-16 14:46:25 -0700 | [diff] [blame] | 82 | submit_bio_hook_t *submit_bio_hook; |
Miao Xie | facc8a22 | 2013-07-25 19:22:34 +0800 | [diff] [blame] | 83 | int (*readpage_end_io_hook)(struct btrfs_io_bio *io_bio, u64 phy_offset, |
| 84 | struct page *page, u64 start, u64 end, |
| 85 | int mirror); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 86 | }; |
| 87 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 88 | |
Chris Mason | 727011e | 2010-08-06 13:21:20 -0400 | [diff] [blame] | 89 | #define INLINE_EXTENT_BUFFER_PAGES 16 |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 90 | #define MAX_INLINE_EXTENT_BUFFER_SIZE (INLINE_EXTENT_BUFFER_PAGES * PAGE_SIZE) |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 91 | struct extent_buffer { |
| 92 | u64 start; |
| 93 | unsigned long len; |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 94 | unsigned long bflags; |
Josef Bacik | f28491e | 2013-12-16 13:24:27 -0500 | [diff] [blame] | 95 | struct btrfs_fs_info *fs_info; |
Josef Bacik | 3083ee2 | 2012-03-09 16:01:49 -0500 | [diff] [blame] | 96 | spinlock_t refs_lock; |
Chris Mason | 727011e | 2010-08-06 13:21:20 -0400 | [diff] [blame] | 97 | atomic_t refs; |
Josef Bacik | 0b32f4b | 2012-03-13 09:38:00 -0400 | [diff] [blame] | 98 | atomic_t io_pages; |
Josef Bacik | 5cf1ab5 | 2012-04-16 09:42:26 -0400 | [diff] [blame] | 99 | int read_mirror; |
Miao Xie | 19fe0a8 | 2010-10-26 20:57:29 -0400 | [diff] [blame] | 100 | struct rcu_head rcu_head; |
Arne Jansen | 5b25f70 | 2011-09-13 10:55:48 +0200 | [diff] [blame] | 101 | pid_t lock_owner; |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 102 | |
David Sterba | 06297d8 | 2019-05-02 16:47:23 +0200 | [diff] [blame] | 103 | int blocking_writers; |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 104 | atomic_t blocking_readers; |
David Sterba | ed1b4ed | 2018-08-24 16:31:17 +0200 | [diff] [blame] | 105 | bool lock_nested; |
Filipe Manana | 656f30d | 2014-09-26 12:25:56 +0100 | [diff] [blame] | 106 | /* >= 0 if eb belongs to a log tree, -1 otherwise */ |
| 107 | short log_index; |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 108 | |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 109 | /* protects write locks */ |
| 110 | rwlock_t lock; |
| 111 | |
| 112 | /* readers use lock_wq while they wait for the write |
| 113 | * lock holders to unlock |
Chris Mason | b4ce94d | 2009-02-04 09:25:08 -0500 | [diff] [blame] | 114 | */ |
Chris Mason | bd68151 | 2011-07-16 15:23:14 -0400 | [diff] [blame] | 115 | wait_queue_head_t write_lock_wq; |
| 116 | |
| 117 | /* writers use read_lock_wq while they wait for readers |
| 118 | * to unlock |
| 119 | */ |
| 120 | wait_queue_head_t read_lock_wq; |
David Sterba | b8dae31 | 2013-02-28 14:54:18 +0000 | [diff] [blame] | 121 | struct page *pages[INLINE_EXTENT_BUFFER_PAGES]; |
Eric Sandeen | 6d49ba1 | 2013-04-22 16:12:31 +0000 | [diff] [blame] | 122 | #ifdef CONFIG_BTRFS_DEBUG |
David Sterba | f3dc24c | 2019-05-02 16:51:53 +0200 | [diff] [blame] | 123 | int spinning_writers; |
David Sterba | afd495a | 2018-08-24 15:57:38 +0200 | [diff] [blame] | 124 | atomic_t spinning_readers; |
David Sterba | 5c9c799 | 2018-08-24 16:15:51 +0200 | [diff] [blame] | 125 | atomic_t read_locks; |
David Sterba | 00801ae | 2019-05-02 16:53:47 +0200 | [diff] [blame] | 126 | int write_locks; |
Eric Sandeen | 6d49ba1 | 2013-04-22 16:12:31 +0000 | [diff] [blame] | 127 | struct list_head leak_list; |
| 128 | #endif |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 129 | }; |
| 130 | |
Qu Wenruo | ac46777 | 2015-10-12 12:08:16 +0800 | [diff] [blame] | 131 | /* |
| 132 | * Structure to record how many bytes and which ranges are set/cleared |
| 133 | */ |
| 134 | struct extent_changeset { |
| 135 | /* How many bytes are set/cleared in this operation */ |
Qu Wenruo | 7bc329c | 2017-02-27 15:10:36 +0800 | [diff] [blame] | 136 | unsigned int bytes_changed; |
Qu Wenruo | ac46777 | 2015-10-12 12:08:16 +0800 | [diff] [blame] | 137 | |
| 138 | /* Changed ranges */ |
David Sterba | 53d3235 | 2017-02-13 13:42:29 +0100 | [diff] [blame] | 139 | struct ulist range_changed; |
Qu Wenruo | ac46777 | 2015-10-12 12:08:16 +0800 | [diff] [blame] | 140 | }; |
| 141 | |
Qu Wenruo | 364ecf3 | 2017-02-27 15:10:38 +0800 | [diff] [blame] | 142 | static inline void extent_changeset_init(struct extent_changeset *changeset) |
| 143 | { |
| 144 | changeset->bytes_changed = 0; |
| 145 | ulist_init(&changeset->range_changed); |
| 146 | } |
| 147 | |
| 148 | static inline struct extent_changeset *extent_changeset_alloc(void) |
| 149 | { |
| 150 | struct extent_changeset *ret; |
| 151 | |
| 152 | ret = kmalloc(sizeof(*ret), GFP_KERNEL); |
| 153 | if (!ret) |
| 154 | return NULL; |
| 155 | |
| 156 | extent_changeset_init(ret); |
| 157 | return ret; |
| 158 | } |
| 159 | |
| 160 | static inline void extent_changeset_release(struct extent_changeset *changeset) |
| 161 | { |
| 162 | if (!changeset) |
| 163 | return; |
| 164 | changeset->bytes_changed = 0; |
| 165 | ulist_release(&changeset->range_changed); |
| 166 | } |
| 167 | |
| 168 | static inline void extent_changeset_free(struct extent_changeset *changeset) |
| 169 | { |
| 170 | if (!changeset) |
| 171 | return; |
| 172 | extent_changeset_release(changeset); |
| 173 | kfree(changeset); |
| 174 | } |
| 175 | |
Li Zefan | 261507a0 | 2010-12-17 14:21:50 +0800 | [diff] [blame] | 176 | static inline void extent_set_compress_type(unsigned long *bio_flags, |
| 177 | int compress_type) |
| 178 | { |
| 179 | *bio_flags |= compress_type << EXTENT_BIO_FLAG_SHIFT; |
| 180 | } |
| 181 | |
| 182 | static inline int extent_compress_type(unsigned long bio_flags) |
| 183 | { |
| 184 | return bio_flags >> EXTENT_BIO_FLAG_SHIFT; |
| 185 | } |
| 186 | |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 187 | struct extent_map_tree; |
| 188 | |
Nikolay Borisov | fc4f21b1 | 2017-02-20 13:51:06 +0200 | [diff] [blame] | 189 | typedef struct extent_map *(get_extent_t)(struct btrfs_inode *inode, |
Omar Sandoval | 39b07b5 | 2019-12-02 17:34:23 -0800 | [diff] [blame] | 190 | struct page *page, size_t pg_offset, |
| 191 | u64 start, u64 len); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 192 | |
Nikolay Borisov | 477a30b | 2018-04-19 10:46:34 +0300 | [diff] [blame] | 193 | int try_release_extent_mapping(struct page *page, gfp_t mask); |
David Sterba | f7a52a4 | 2013-04-26 14:56:29 +0000 | [diff] [blame] | 194 | int try_release_extent_buffer(struct page *page); |
David Sterba | cd716d8 | 2015-12-03 14:41:30 +0100 | [diff] [blame] | 195 | |
David Sterba | 71ad38b | 2020-02-05 19:09:35 +0100 | [diff] [blame] | 196 | int extent_read_full_page(struct page *page, get_extent_t *get_extent, |
| 197 | int mirror_num); |
Nikolay Borisov | 0a9b0e5 | 2017-12-08 15:55:59 +0200 | [diff] [blame] | 198 | int extent_write_full_page(struct page *page, struct writeback_control *wbc); |
Nikolay Borisov | 5e3ee23 | 2017-12-08 15:55:58 +0200 | [diff] [blame] | 199 | int extent_write_locked_range(struct inode *inode, u64 start, u64 end, |
Chris Mason | 771ed68 | 2008-11-06 22:02:51 -0500 | [diff] [blame] | 200 | int mode); |
Nikolay Borisov | 8ae225a | 2018-04-19 10:46:38 +0300 | [diff] [blame] | 201 | int extent_writepages(struct address_space *mapping, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 202 | struct writeback_control *wbc); |
Josef Bacik | 0b32f4b | 2012-03-13 09:38:00 -0400 | [diff] [blame] | 203 | int btree_write_cache_pages(struct address_space *mapping, |
| 204 | struct writeback_control *wbc); |
Matthew Wilcox (Oracle) | ba206a0 | 2020-06-01 21:47:05 -0700 | [diff] [blame] | 205 | void extent_readahead(struct readahead_control *rac); |
Yehuda Sadeh | 1506fcc | 2009-01-21 14:39:14 -0500 | [diff] [blame] | 206 | int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
David Sterba | 2135fb9 | 2017-06-23 04:09:57 +0200 | [diff] [blame] | 207 | __u64 start, __u64 len); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 208 | void set_page_extent_mapped(struct page *page); |
| 209 | |
Josef Bacik | f28491e | 2013-12-16 13:24:27 -0500 | [diff] [blame] | 210 | struct extent_buffer *alloc_extent_buffer(struct btrfs_fs_info *fs_info, |
David Sterba | ce3e698 | 2014-06-15 03:00:04 +0200 | [diff] [blame] | 211 | u64 start); |
Omar Sandoval | 0f33122 | 2015-09-29 20:50:31 -0700 | [diff] [blame] | 212 | struct extent_buffer *__alloc_dummy_extent_buffer(struct btrfs_fs_info *fs_info, |
| 213 | u64 start, unsigned long len); |
David Sterba | 3f556f7 | 2014-06-15 03:20:26 +0200 | [diff] [blame] | 214 | 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] | 215 | u64 start); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 216 | struct extent_buffer *btrfs_clone_extent_buffer(const struct extent_buffer *src); |
Josef Bacik | f28491e | 2013-12-16 13:24:27 -0500 | [diff] [blame] | 217 | struct extent_buffer *find_extent_buffer(struct btrfs_fs_info *fs_info, |
Chandra Seetharaman | 452c75c | 2013-10-07 10:45:25 -0500 | [diff] [blame] | 218 | u64 start); |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 219 | void free_extent_buffer(struct extent_buffer *eb); |
Josef Bacik | 3083ee2 | 2012-03-09 16:01:49 -0500 | [diff] [blame] | 220 | void free_extent_buffer_stale(struct extent_buffer *eb); |
Arne Jansen | bb82ab8 | 2011-06-10 14:06:53 +0200 | [diff] [blame] | 221 | #define WAIT_NONE 0 |
| 222 | #define WAIT_COMPLETE 1 |
| 223 | #define WAIT_PAGE_LOCK 2 |
Nikolay Borisov | c2ccfbc | 2019-04-10 17:24:40 +0300 | [diff] [blame] | 224 | int read_extent_buffer_pages(struct extent_buffer *eb, int wait, |
David Sterba | 6af49db | 2017-06-23 04:09:57 +0200 | [diff] [blame] | 225 | int mirror_num); |
Josef Bacik | fd8b2b6 | 2013-04-24 16:41:19 -0400 | [diff] [blame] | 226 | void wait_on_extent_buffer_writeback(struct extent_buffer *eb); |
Robin Dong | 479ed9a | 2012-09-29 02:07:47 -0600 | [diff] [blame] | 227 | |
David Sterba | cc5e31a | 2018-03-01 18:20:27 +0100 | [diff] [blame] | 228 | static inline int num_extent_pages(const struct extent_buffer *eb) |
Robin Dong | 479ed9a | 2012-09-29 02:07:47 -0600 | [diff] [blame] | 229 | { |
David Sterba | 8791d43 | 2018-07-04 17:49:31 +0200 | [diff] [blame] | 230 | return (round_up(eb->start + eb->len, PAGE_SIZE) >> PAGE_SHIFT) - |
| 231 | (eb->start >> PAGE_SHIFT); |
Robin Dong | 479ed9a | 2012-09-29 02:07:47 -0600 | [diff] [blame] | 232 | } |
| 233 | |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 234 | static inline int extent_buffer_uptodate(const struct extent_buffer *eb) |
Anand Jain | ba02049 | 2018-02-13 12:35:44 +0800 | [diff] [blame] | 235 | { |
| 236 | return test_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags); |
| 237 | } |
| 238 | |
Jeff Mahoney | 1cbb1f4 | 2017-06-28 21:56:53 -0600 | [diff] [blame] | 239 | int memcmp_extent_buffer(const struct extent_buffer *eb, const void *ptrv, |
| 240 | unsigned long start, unsigned long len); |
| 241 | void read_extent_buffer(const struct extent_buffer *eb, void *dst, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 242 | unsigned long start, |
| 243 | unsigned long len); |
Jeff Mahoney | 1cbb1f4 | 2017-06-28 21:56:53 -0600 | [diff] [blame] | 244 | int read_extent_buffer_to_user(const struct extent_buffer *eb, |
| 245 | void __user *dst, unsigned long start, |
Gerhard Heift | 550ac1d | 2014-01-30 16:24:01 +0100 | [diff] [blame] | 246 | unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 247 | void write_extent_buffer_fsid(const struct extent_buffer *eb, const void *src); |
| 248 | void write_extent_buffer_chunk_tree_uuid(const struct extent_buffer *eb, |
David Sterba | f157bf7 | 2016-11-09 17:43:38 +0100 | [diff] [blame] | 249 | const void *src); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 250 | void write_extent_buffer(const struct extent_buffer *eb, const void *src, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 251 | unsigned long start, unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 252 | void copy_extent_buffer_full(const struct extent_buffer *dst, |
| 253 | const struct extent_buffer *src); |
| 254 | void copy_extent_buffer(const struct extent_buffer *dst, |
| 255 | const struct extent_buffer *src, |
Chris Mason | d1310b2 | 2008-01-24 16:13:08 -0500 | [diff] [blame] | 256 | unsigned long dst_offset, unsigned long src_offset, |
| 257 | unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 258 | void memcpy_extent_buffer(const struct extent_buffer *dst, |
| 259 | unsigned long dst_offset, unsigned long src_offset, |
| 260 | unsigned long len); |
| 261 | void memmove_extent_buffer(const struct extent_buffer *dst, |
| 262 | unsigned long dst_offset, unsigned long src_offset, |
David Sterba | b159fa2 | 2016-11-08 18:09:03 +0100 | [diff] [blame] | 263 | unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 264 | void memzero_extent_buffer(const struct extent_buffer *eb, unsigned long start, |
| 265 | unsigned long len); |
| 266 | 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] | 267 | unsigned long pos); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 268 | 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] | 269 | unsigned long pos, unsigned long len); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 270 | void extent_buffer_bitmap_clear(const struct extent_buffer *eb, |
| 271 | unsigned long start, unsigned long pos, |
| 272 | unsigned long len); |
| 273 | void clear_extent_buffer_dirty(const struct extent_buffer *eb); |
Liu Bo | abb57ef | 2018-09-14 01:44:42 +0800 | [diff] [blame] | 274 | bool set_extent_buffer_dirty(struct extent_buffer *eb); |
David Sterba | 09c25a8 | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 275 | void set_extent_buffer_uptodate(struct extent_buffer *eb); |
David Sterba | 69ba392 | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 276 | void clear_extent_buffer_uptodate(struct extent_buffer *eb); |
David Sterba | 2b48966 | 2020-04-29 03:04:10 +0200 | [diff] [blame] | 277 | int extent_buffer_under_io(const struct extent_buffer *eb); |
David Sterba | bd1fa4f | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 278 | 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] | 279 | void extent_range_redirty_for_io(struct inode *inode, u64 start, u64 end); |
David Sterba | a9d93e1 | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 280 | void extent_clear_unlock_delalloc(struct inode *inode, u64 start, u64 end, |
Nikolay Borisov | 74e9194 | 2019-07-17 16:18:16 +0300 | [diff] [blame] | 281 | struct page *locked_page, |
| 282 | unsigned bits_to_clear, |
| 283 | unsigned long page_ops); |
David Sterba | e749af44 | 2019-06-18 20:00:16 +0200 | [diff] [blame] | 284 | struct bio *btrfs_bio_alloc(u64 first_byte); |
David Sterba | c5e4c3d | 2017-06-12 17:29:41 +0200 | [diff] [blame] | 285 | struct bio *btrfs_io_bio_alloc(unsigned int nr_iovecs); |
David Sterba | 8b6c1d5 | 2017-06-02 17:48:13 +0200 | [diff] [blame] | 286 | struct bio *btrfs_bio_clone(struct bio *bio); |
Liu Bo | e477094 | 2017-05-16 10:57:14 -0700 | [diff] [blame] | 287 | 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] | 288 | |
Stefan Behrens | 3ec706c | 2012-11-05 15:46:42 +0100 | [diff] [blame] | 289 | struct btrfs_fs_info; |
Nikolay Borisov | 9d4f7f8 | 2017-02-20 13:50:55 +0200 | [diff] [blame] | 290 | struct btrfs_inode; |
Jan Schmidt | 4a54c8c | 2011-07-22 15:41:52 +0200 | [diff] [blame] | 291 | |
Josef Bacik | 6ec656b | 2017-05-05 11:57:14 -0400 | [diff] [blame] | 292 | int repair_io_failure(struct btrfs_fs_info *fs_info, u64 ino, u64 start, |
| 293 | u64 length, u64 logical, struct page *page, |
| 294 | unsigned int pg_offset, int mirror_num); |
David Sterba | b5227c0 | 2015-12-03 13:08:59 +0100 | [diff] [blame] | 295 | 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] | 296 | 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] | 297 | |
| 298 | /* |
| 299 | * When IO fails, either with EIO or csum verification fails, we |
| 300 | * try other mirrors that might have a good copy of the data. This |
| 301 | * io_failure_record is used to record state as we go through all the |
| 302 | * mirrors. If another mirror has good data, the page is set up to date |
| 303 | * and things continue. If a good mirror can't be found, the original |
| 304 | * bio end_io callback is called to indicate things have failed. |
| 305 | */ |
| 306 | struct io_failure_record { |
| 307 | struct page *page; |
| 308 | u64 start; |
| 309 | u64 len; |
| 310 | u64 logical; |
| 311 | unsigned long bio_flags; |
| 312 | int this_mirror; |
| 313 | int failed_mirror; |
| 314 | int in_validation; |
| 315 | }; |
| 316 | |
Nikolay Borisov | 4ac1f4a | 2017-02-20 13:50:52 +0200 | [diff] [blame] | 317 | |
Omar Sandoval | 77d5d68 | 2020-04-16 14:46:25 -0700 | [diff] [blame] | 318 | blk_status_t btrfs_submit_read_repair(struct inode *inode, |
| 319 | struct bio *failed_bio, u64 phy_offset, |
| 320 | struct page *page, unsigned int pgoff, |
| 321 | u64 start, u64 end, int failed_mirror, |
| 322 | submit_bio_hook_t *submit_bio_hook); |
| 323 | |
Josef Bacik | 294e30f | 2013-10-09 12:00:56 -0400 | [diff] [blame] | 324 | #ifdef CONFIG_BTRFS_FS_RUN_SANITY_TESTS |
Goldwyn Rodrigues | 9978059 | 2019-06-21 10:02:54 -0500 | [diff] [blame] | 325 | bool find_lock_delalloc_range(struct inode *inode, |
Johannes Thumshirn | ce9f967 | 2018-11-19 10:38:17 +0100 | [diff] [blame] | 326 | struct page *locked_page, u64 *start, |
| 327 | u64 *end); |
Chris Mason | 0d4cf4e | 2014-10-07 13:24:20 -0700 | [diff] [blame] | 328 | #endif |
Josef Bacik | faa2dbf | 2014-05-07 17:06:09 -0400 | [diff] [blame] | 329 | 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] | 330 | u64 start); |
Josef Bacik | 3fd6372 | 2020-02-14 16:11:40 -0500 | [diff] [blame] | 331 | |
| 332 | #ifdef CONFIG_BTRFS_DEBUG |
| 333 | void btrfs_extent_buffer_leak_debug_check(struct btrfs_fs_info *fs_info); |
| 334 | #else |
| 335 | #define btrfs_extent_buffer_leak_debug_check(fs_info) do {} while (0) |
| 336 | #endif |
| 337 | |
Josef Bacik | 294e30f | 2013-10-09 12:00:56 -0400 | [diff] [blame] | 338 | #endif |