Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Christoph Hellwig | 199a31c | 2016-06-21 09:22:39 +1000 | [diff] [blame] | 2 | #ifndef LINUX_IOMAP_H |
| 3 | #define LINUX_IOMAP_H 1 |
| 4 | |
Christoph Hellwig | 9dc55f1 | 2018-07-11 22:26:05 -0700 | [diff] [blame] | 5 | #include <linux/atomic.h> |
| 6 | #include <linux/bitmap.h> |
Christoph Hellwig | 598ecfb | 2019-10-17 13:12:15 -0700 | [diff] [blame] | 7 | #include <linux/blk_types.h> |
Christoph Hellwig | 9dc55f1 | 2018-07-11 22:26:05 -0700 | [diff] [blame] | 8 | #include <linux/mm.h> |
Christoph Hellwig | 199a31c | 2016-06-21 09:22:39 +1000 | [diff] [blame] | 9 | #include <linux/types.h> |
Souptick Joarder | 5780a02 | 2018-10-26 15:02:59 -0700 | [diff] [blame] | 10 | #include <linux/mm_types.h> |
Darrick J. Wong | db07443 | 2019-07-15 08:50:59 -0700 | [diff] [blame] | 11 | #include <linux/blkdev.h> |
Christoph Hellwig | 199a31c | 2016-06-21 09:22:39 +1000 | [diff] [blame] | 12 | |
Christoph Hellwig | 89eb190 | 2018-06-01 09:03:08 -0700 | [diff] [blame] | 13 | struct address_space; |
Christoph Hellwig | 8be9f56 | 2016-06-21 09:38:45 +1000 | [diff] [blame] | 14 | struct fiemap_extent_info; |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 15 | struct inode; |
Christoph Hellwig | c3d4ed1 | 2020-09-28 08:51:08 -0700 | [diff] [blame] | 16 | struct iomap_dio; |
Christoph Hellwig | 598ecfb | 2019-10-17 13:12:15 -0700 | [diff] [blame] | 17 | struct iomap_writepage_ctx; |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 18 | struct iov_iter; |
| 19 | struct kiocb; |
Christoph Hellwig | 63899c6 | 2018-06-19 15:10:56 -0700 | [diff] [blame] | 20 | struct page; |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 21 | struct vm_area_struct; |
| 22 | struct vm_fault; |
| 23 | |
| 24 | /* |
| 25 | * Types of block ranges for iomap mappings: |
| 26 | */ |
Christoph Hellwig | eb81cf9 | 2019-10-18 16:43:08 -0700 | [diff] [blame] | 27 | #define IOMAP_HOLE 0 /* no blocks allocated, need allocation */ |
| 28 | #define IOMAP_DELALLOC 1 /* delayed allocation blocks */ |
| 29 | #define IOMAP_MAPPED 2 /* blocks allocated at @addr */ |
| 30 | #define IOMAP_UNWRITTEN 3 /* blocks allocated at @addr in unwritten state */ |
| 31 | #define IOMAP_INLINE 4 /* data inline in the inode */ |
Christoph Hellwig | 199a31c | 2016-06-21 09:22:39 +1000 | [diff] [blame] | 32 | |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 33 | /* |
Christoph Hellwig | 65a60e8 | 2019-10-18 16:40:17 -0700 | [diff] [blame] | 34 | * Flags reported by the file system from iomap_begin: |
| 35 | * |
| 36 | * IOMAP_F_NEW indicates that the blocks have been newly allocated and need |
| 37 | * zeroing for areas that no data is copied to. |
Linus Torvalds | a3841f9 | 2017-11-17 09:51:57 -0800 | [diff] [blame] | 38 | * |
Jan Kara | caa51d2 | 2017-11-01 16:36:42 +0100 | [diff] [blame] | 39 | * IOMAP_F_DIRTY indicates the inode has uncommitted metadata needed to access |
| 40 | * written data and requires fdatasync to commit them to persistent storage. |
Dave Chinner | 7684e2c | 2019-10-17 13:12:01 -0700 | [diff] [blame] | 41 | * This needs to take into account metadata changes that *may* be made at IO |
| 42 | * completion, such as file size updates from direct IO. |
Christoph Hellwig | 65a60e8 | 2019-10-18 16:40:17 -0700 | [diff] [blame] | 43 | * |
| 44 | * IOMAP_F_SHARED indicates that the blocks are shared, and will need to be |
| 45 | * unshared as part a write. |
| 46 | * |
| 47 | * IOMAP_F_MERGED indicates that the iomap contains the merge of multiple block |
| 48 | * mappings. |
| 49 | * |
| 50 | * IOMAP_F_BUFFER_HEAD indicates that the file system requires the use of |
| 51 | * buffer heads for this mapping. |
Dave Chinner | 54a37e5 | 2024-05-01 11:40:55 -0700 | [diff] [blame] | 52 | * |
| 53 | * IOMAP_F_XATTR indicates that the iomap is for an extended attribute extent |
| 54 | * rather than a file data extent. |
Christoph Hellwig | 17de0a9 | 2016-08-29 11:33:58 +1000 | [diff] [blame] | 55 | */ |
Dave Chinner | 54a37e5 | 2024-05-01 11:40:55 -0700 | [diff] [blame] | 56 | #define IOMAP_F_NEW (1U << 0) |
| 57 | #define IOMAP_F_DIRTY (1U << 1) |
| 58 | #define IOMAP_F_SHARED (1U << 2) |
| 59 | #define IOMAP_F_MERGED (1U << 3) |
| 60 | #define IOMAP_F_BUFFER_HEAD (1U << 4) |
| 61 | #define IOMAP_F_ZONE_APPEND (1U << 5) |
| 62 | #define IOMAP_F_XATTR (1U << 6) |
Christoph Hellwig | d33fd77 | 2016-10-20 15:51:28 +1100 | [diff] [blame] | 63 | |
| 64 | /* |
Christoph Hellwig | 65a60e8 | 2019-10-18 16:40:17 -0700 | [diff] [blame] | 65 | * Flags set by the core iomap code during operations: |
| 66 | * |
| 67 | * IOMAP_F_SIZE_CHANGED indicates to the iomap_end method that the file size |
| 68 | * has changed as the result of this write operation. |
Dave Chinner | 54a37e5 | 2024-05-01 11:40:55 -0700 | [diff] [blame] | 69 | * |
| 70 | * IOMAP_F_STALE indicates that the iomap is not valid any longer and the file |
| 71 | * range it covers needs to be remapped by the high level before the operation |
| 72 | * can proceed. |
Christoph Hellwig | d33fd77 | 2016-10-20 15:51:28 +1100 | [diff] [blame] | 73 | */ |
Dave Chinner | 54a37e5 | 2024-05-01 11:40:55 -0700 | [diff] [blame] | 74 | #define IOMAP_F_SIZE_CHANGED (1U << 8) |
| 75 | #define IOMAP_F_STALE (1U << 9) |
Christoph Hellwig | 17de0a9 | 2016-08-29 11:33:58 +1000 | [diff] [blame] | 76 | |
| 77 | /* |
Christoph Hellwig | 7ee66c0 | 2018-06-01 09:03:07 -0700 | [diff] [blame] | 78 | * Flags from 0x1000 up are for file system specific usage: |
| 79 | */ |
Dave Chinner | 54a37e5 | 2024-05-01 11:40:55 -0700 | [diff] [blame] | 80 | #define IOMAP_F_PRIVATE (1U << 12) |
Christoph Hellwig | 7ee66c0 | 2018-06-01 09:03:07 -0700 | [diff] [blame] | 81 | |
| 82 | |
| 83 | /* |
Andreas Gruenbacher | 19fe5f6 | 2017-10-01 17:55:54 -0400 | [diff] [blame] | 84 | * Magic value for addr: |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 85 | */ |
Andreas Gruenbacher | 19fe5f6 | 2017-10-01 17:55:54 -0400 | [diff] [blame] | 86 | #define IOMAP_NULL_ADDR -1ULL /* addr is not valid */ |
Christoph Hellwig | 199a31c | 2016-06-21 09:22:39 +1000 | [diff] [blame] | 87 | |
Andreas Gruenbacher | df0db3e | 2019-04-30 08:45:34 -0700 | [diff] [blame] | 88 | struct iomap_page_ops; |
| 89 | |
Christoph Hellwig | 199a31c | 2016-06-21 09:22:39 +1000 | [diff] [blame] | 90 | struct iomap { |
Andreas Gruenbacher | 19fe5f6 | 2017-10-01 17:55:54 -0400 | [diff] [blame] | 91 | u64 addr; /* disk offset of mapping, bytes */ |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 92 | loff_t offset; /* file offset of mapping, bytes */ |
| 93 | u64 length; /* length of mapping, bytes */ |
Christoph Hellwig | 17de0a9 | 2016-08-29 11:33:58 +1000 | [diff] [blame] | 94 | u16 type; /* type of mapping */ |
| 95 | u16 flags; /* flags for mapping */ |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 96 | struct block_device *bdev; /* block device for I/O */ |
Dan Williams | fa5d932 | 2017-01-27 12:04:59 -0800 | [diff] [blame] | 97 | struct dax_device *dax_dev; /* dax_dev for dax operations */ |
Andreas Gruenbacher | 19e0c58 | 2018-06-19 15:10:56 -0700 | [diff] [blame] | 98 | void *inline_data; |
Andreas Gruenbacher | e184fde | 2018-06-19 15:10:57 -0700 | [diff] [blame] | 99 | void *private; /* filesystem private */ |
Andreas Gruenbacher | df0db3e | 2019-04-30 08:45:34 -0700 | [diff] [blame] | 100 | const struct iomap_page_ops *page_ops; |
Dave Chinner | 54a37e5 | 2024-05-01 11:40:55 -0700 | [diff] [blame] | 101 | u64 validity_cookie; /* used with .iomap_valid() */ |
Andreas Gruenbacher | df0db3e | 2019-04-30 08:45:34 -0700 | [diff] [blame] | 102 | }; |
Christoph Hellwig | 63899c6 | 2018-06-19 15:10:56 -0700 | [diff] [blame] | 103 | |
Christoph Hellwig | 66b8165 | 2021-08-10 18:33:04 -0700 | [diff] [blame] | 104 | static inline sector_t iomap_sector(const struct iomap *iomap, loff_t pos) |
Darrick J. Wong | db07443 | 2019-07-15 08:50:59 -0700 | [diff] [blame] | 105 | { |
| 106 | return (iomap->addr + pos - iomap->offset) >> SECTOR_SHIFT; |
| 107 | } |
| 108 | |
Andreas Gruenbacher | df0db3e | 2019-04-30 08:45:34 -0700 | [diff] [blame] | 109 | /* |
Gao Xiang | 69f4a26 | 2021-08-03 09:38:22 -0700 | [diff] [blame] | 110 | * Returns the inline data pointer for logical offset @pos. |
| 111 | */ |
Christoph Hellwig | 4495c33 | 2021-08-10 18:33:04 -0700 | [diff] [blame] | 112 | static inline void *iomap_inline_data(const struct iomap *iomap, loff_t pos) |
Gao Xiang | 69f4a26 | 2021-08-03 09:38:22 -0700 | [diff] [blame] | 113 | { |
| 114 | return iomap->inline_data + pos - iomap->offset; |
| 115 | } |
| 116 | |
| 117 | /* |
| 118 | * Check if the mapping's length is within the valid range for inline data. |
| 119 | * This is used to guard against accessing data beyond the page inline_data |
| 120 | * points at. |
| 121 | */ |
Christoph Hellwig | e3c4ffb | 2021-08-10 18:33:05 -0700 | [diff] [blame] | 122 | static inline bool iomap_inline_data_valid(const struct iomap *iomap) |
Gao Xiang | 69f4a26 | 2021-08-03 09:38:22 -0700 | [diff] [blame] | 123 | { |
| 124 | return iomap->length <= PAGE_SIZE - offset_in_page(iomap->inline_data); |
| 125 | } |
| 126 | |
| 127 | /* |
Andreas Gruenbacher | df0db3e | 2019-04-30 08:45:34 -0700 | [diff] [blame] | 128 | * When a filesystem sets page_ops in an iomap mapping it returns, page_prepare |
| 129 | * and page_done will be called for each page written to. This only applies to |
| 130 | * buffered writes as unbuffered writes will not typically have pages |
| 131 | * associated with them. |
| 132 | * |
| 133 | * When page_prepare succeeds, page_done will always be called to do any |
| 134 | * cleanup work necessary. In that page_done call, @page will be NULL if the |
| 135 | * associated page could not be obtained. |
| 136 | */ |
| 137 | struct iomap_page_ops { |
Christoph Hellwig | 1d25d0a | 2021-08-10 18:33:03 -0700 | [diff] [blame] | 138 | int (*page_prepare)(struct inode *inode, loff_t pos, unsigned len); |
Christoph Hellwig | 63899c6 | 2018-06-19 15:10:56 -0700 | [diff] [blame] | 139 | void (*page_done)(struct inode *inode, loff_t pos, unsigned copied, |
Christoph Hellwig | 1d25d0a | 2021-08-10 18:33:03 -0700 | [diff] [blame] | 140 | struct page *page); |
Dave Chinner | 54a37e5 | 2024-05-01 11:40:55 -0700 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * Check that the cached iomap still maps correctly to the filesystem's |
| 144 | * internal extent map. FS internal extent maps can change while iomap |
| 145 | * is iterating a cached iomap, so this hook allows iomap to detect that |
| 146 | * the iomap needs to be refreshed during a long running write |
| 147 | * operation. |
| 148 | * |
| 149 | * The filesystem can store internal state (e.g. a sequence number) in |
| 150 | * iomap->validity_cookie when the iomap is first mapped to be able to |
| 151 | * detect changes between mapping time and whenever .iomap_valid() is |
| 152 | * called. |
| 153 | * |
| 154 | * This is called with the folio over the specified file position held |
| 155 | * locked by the iomap code. |
| 156 | */ |
| 157 | bool (*iomap_valid)(struct inode *inode, const struct iomap *iomap); |
Christoph Hellwig | 199a31c | 2016-06-21 09:22:39 +1000 | [diff] [blame] | 158 | }; |
| 159 | |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 160 | /* |
| 161 | * Flags for iomap_begin / iomap_end. No flag implies a read. |
| 162 | */ |
Christoph Hellwig | d33fd77 | 2016-10-20 15:51:28 +1100 | [diff] [blame] | 163 | #define IOMAP_WRITE (1 << 0) /* writing, must allocate blocks */ |
| 164 | #define IOMAP_ZERO (1 << 1) /* zeroing operation, may skip holes */ |
| 165 | #define IOMAP_REPORT (1 << 2) /* report extent status, e.g. FIEMAP */ |
Jan Kara | 9484ab1 | 2016-11-10 10:26:50 +1100 | [diff] [blame] | 166 | #define IOMAP_FAULT (1 << 3) /* mapping for page fault */ |
Christoph Hellwig | ff6a929 | 2016-11-30 14:36:01 +1100 | [diff] [blame] | 167 | #define IOMAP_DIRECT (1 << 4) /* direct I/O */ |
Christoph Hellwig | 9ecac0e | 2018-06-01 09:03:07 -0700 | [diff] [blame] | 168 | #define IOMAP_NOWAIT (1 << 5) /* do not block */ |
Christoph Hellwig | 213f627 | 2021-01-23 10:06:10 -0800 | [diff] [blame] | 169 | #define IOMAP_OVERWRITE_ONLY (1 << 6) /* only pure overwrites allowed */ |
Christoph Hellwig | b74b129 | 2021-08-10 18:33:14 -0700 | [diff] [blame] | 170 | #define IOMAP_UNSHARE (1 << 7) /* unshare_file_range */ |
Christoph Hellwig | 952da06 | 2021-11-29 11:21:58 +0100 | [diff] [blame] | 171 | #ifdef CONFIG_FS_DAX |
| 172 | #define IOMAP_DAX (1 << 8) /* DAX mapping */ |
| 173 | #else |
| 174 | #define IOMAP_DAX 0 |
| 175 | #endif /* CONFIG_FS_DAX */ |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 176 | |
| 177 | struct iomap_ops { |
| 178 | /* |
| 179 | * Return the existing mapping at pos, or reserve space starting at |
| 180 | * pos for up to length, as long as we can do it as a single mapping. |
| 181 | * The actual length is returned in iomap->length. |
| 182 | */ |
| 183 | int (*iomap_begin)(struct inode *inode, loff_t pos, loff_t length, |
Goldwyn Rodrigues | c039b99 | 2019-10-18 16:44:10 -0700 | [diff] [blame] | 184 | unsigned flags, struct iomap *iomap, |
| 185 | struct iomap *srcmap); |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 186 | |
| 187 | /* |
| 188 | * Commit and/or unreserve space previous allocated using iomap_begin. |
| 189 | * Written indicates the length of the successful write operation which |
| 190 | * needs to be commited, while the rest needs to be unreserved. |
| 191 | * Written might be zero if no data was written. |
| 192 | */ |
| 193 | int (*iomap_end)(struct inode *inode, loff_t pos, loff_t length, |
| 194 | ssize_t written, unsigned flags, struct iomap *iomap); |
| 195 | }; |
| 196 | |
Christoph Hellwig | f4b896c | 2021-08-10 18:33:07 -0700 | [diff] [blame] | 197 | /** |
| 198 | * struct iomap_iter - Iterate through a range of a file |
| 199 | * @inode: Set at the start of the iteration and should not change. |
| 200 | * @pos: The current file position we are operating on. It is updated by |
| 201 | * calls to iomap_iter(). Treat as read-only in the body. |
| 202 | * @len: The remaining length of the file segment we're operating on. |
| 203 | * It is updated at the same time as @pos. |
| 204 | * @processed: The number of bytes processed by the body in the most recent |
| 205 | * iteration, or a negative errno. 0 causes the iteration to stop. |
| 206 | * @flags: Zero or more of the iomap_begin flags above. |
| 207 | * @iomap: Map describing the I/O iteration |
| 208 | * @srcmap: Source map for COW operations |
| 209 | */ |
| 210 | struct iomap_iter { |
| 211 | struct inode *inode; |
| 212 | loff_t pos; |
| 213 | u64 len; |
| 214 | s64 processed; |
| 215 | unsigned flags; |
| 216 | struct iomap iomap; |
| 217 | struct iomap srcmap; |
Christoph Hellwig | 786f847 | 2022-05-05 15:11:11 -0500 | [diff] [blame] | 218 | void *private; |
Christoph Hellwig | f4b896c | 2021-08-10 18:33:07 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops); |
| 222 | |
| 223 | /** |
| 224 | * iomap_length - length of the current iomap iteration |
| 225 | * @iter: iteration structure |
| 226 | * |
| 227 | * Returns the length that the operation applies to for the current iteration. |
| 228 | */ |
| 229 | static inline u64 iomap_length(const struct iomap_iter *iter) |
| 230 | { |
| 231 | u64 end = iter->iomap.offset + iter->iomap.length; |
| 232 | |
| 233 | if (iter->srcmap.type != IOMAP_HOLE) |
| 234 | end = min(end, iter->srcmap.offset + iter->srcmap.length); |
| 235 | return min(iter->len, end - iter->pos); |
| 236 | } |
| 237 | |
| 238 | /** |
| 239 | * iomap_iter_srcmap - return the source map for the current iomap iteration |
| 240 | * @i: iteration structure |
| 241 | * |
| 242 | * Write operations on file systems with reflink support might require a |
| 243 | * source and a destination map. This function retourns the source map |
| 244 | * for a given operation, which may or may no be identical to the destination |
| 245 | * map in &i->iomap. |
| 246 | */ |
Christoph Hellwig | fad0a1a | 2021-08-10 18:33:16 -0700 | [diff] [blame] | 247 | static inline const struct iomap *iomap_iter_srcmap(const struct iomap_iter *i) |
Christoph Hellwig | f4b896c | 2021-08-10 18:33:07 -0700 | [diff] [blame] | 248 | { |
| 249 | if (i->srcmap.type != IOMAP_HOLE) |
| 250 | return &i->srcmap; |
| 251 | return &i->iomap; |
| 252 | } |
| 253 | |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 254 | ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from, |
Christoph Hellwig | 8ff6daa | 2017-01-27 23:20:26 -0800 | [diff] [blame] | 255 | const struct iomap_ops *ops); |
Dave Chinner | 12339ec | 2024-05-01 11:40:52 -0700 | [diff] [blame] | 256 | int iomap_file_buffered_write_punch_delalloc(struct inode *inode, |
| 257 | struct iomap *iomap, loff_t pos, loff_t length, ssize_t written, |
| 258 | int (*punch)(struct inode *inode, loff_t pos, loff_t length)); |
| 259 | |
Matthew Wilcox (Oracle) | 7479c50 | 2022-04-29 08:54:32 -0400 | [diff] [blame] | 260 | int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops); |
Matthew Wilcox (Oracle) | 9d24a13 | 2020-06-01 21:47:34 -0700 | [diff] [blame] | 261 | void iomap_readahead(struct readahead_control *, const struct iomap_ops *ops); |
Matthew Wilcox (Oracle) | 2e7e80f | 2022-02-09 20:21:27 +0000 | [diff] [blame] | 262 | bool iomap_is_partially_uptodate(struct folio *, size_t from, size_t count); |
Matthew Wilcox (Oracle) | 8597447 | 2022-04-30 23:01:08 -0400 | [diff] [blame] | 263 | bool iomap_release_folio(struct folio *folio, gfp_t gfp_flags); |
Matthew Wilcox (Oracle) | 8306a5f5 | 2021-04-28 07:51:36 -0400 | [diff] [blame] | 264 | void iomap_invalidate_folio(struct folio *folio, size_t offset, size_t len); |
Christoph Hellwig | 3590c4d | 2019-10-18 16:41:34 -0700 | [diff] [blame] | 265 | int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, |
Christoph Hellwig | 8ff6daa | 2017-01-27 23:20:26 -0800 | [diff] [blame] | 266 | const struct iomap_ops *ops); |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 267 | int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, |
Christoph Hellwig | 8ff6daa | 2017-01-27 23:20:26 -0800 | [diff] [blame] | 268 | bool *did_zero, const struct iomap_ops *ops); |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 269 | int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, |
Christoph Hellwig | 8ff6daa | 2017-01-27 23:20:26 -0800 | [diff] [blame] | 270 | const struct iomap_ops *ops); |
Souptick Joarder | 5780a02 | 2018-10-26 15:02:59 -0700 | [diff] [blame] | 271 | vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, |
| 272 | const struct iomap_ops *ops); |
Christoph Hellwig | 8be9f56 | 2016-06-21 09:38:45 +1000 | [diff] [blame] | 273 | int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
Christoph Hellwig | 2732881 | 2020-05-23 09:30:12 +0200 | [diff] [blame] | 274 | u64 start, u64 len, const struct iomap_ops *ops); |
Andreas Gruenbacher | 0ed3b0d | 2017-06-29 11:43:21 -0700 | [diff] [blame] | 275 | loff_t iomap_seek_hole(struct inode *inode, loff_t offset, |
| 276 | const struct iomap_ops *ops); |
| 277 | loff_t iomap_seek_data(struct inode *inode, loff_t offset, |
| 278 | const struct iomap_ops *ops); |
Christoph Hellwig | 89eb190 | 2018-06-01 09:03:08 -0700 | [diff] [blame] | 279 | sector_t iomap_bmap(struct address_space *mapping, sector_t bno, |
| 280 | const struct iomap_ops *ops); |
Christoph Hellwig | ae259a9 | 2016-06-21 09:23:11 +1000 | [diff] [blame] | 281 | |
Christoph Hellwig | ff6a929 | 2016-11-30 14:36:01 +1100 | [diff] [blame] | 282 | /* |
Christoph Hellwig | 598ecfb | 2019-10-17 13:12:15 -0700 | [diff] [blame] | 283 | * Structure for writeback I/O completions. |
| 284 | */ |
| 285 | struct iomap_ioend { |
| 286 | struct list_head io_list; /* next ioend in chain */ |
| 287 | u16 io_type; |
| 288 | u16 io_flags; /* IOMAP_F_* */ |
Dave Chinner | ebb7fb1 | 2022-01-26 09:19:20 -0800 | [diff] [blame] | 289 | u32 io_folios; /* folios added to ioend */ |
Christoph Hellwig | 598ecfb | 2019-10-17 13:12:15 -0700 | [diff] [blame] | 290 | struct inode *io_inode; /* file being written to */ |
| 291 | size_t io_size; /* size of the extent */ |
| 292 | loff_t io_offset; /* offset in the file */ |
Dave Chinner | ebb7fb1 | 2022-01-26 09:19:20 -0800 | [diff] [blame] | 293 | sector_t io_sector; /* start sector of ioend */ |
Christoph Hellwig | 598ecfb | 2019-10-17 13:12:15 -0700 | [diff] [blame] | 294 | struct bio *io_bio; /* bio being built */ |
| 295 | struct bio io_inline_bio; /* MUST BE LAST! */ |
| 296 | }; |
| 297 | |
| 298 | struct iomap_writeback_ops { |
| 299 | /* |
| 300 | * Required, maps the blocks so that writeback can be performed on |
| 301 | * the range starting at offset. |
| 302 | */ |
| 303 | int (*map_blocks)(struct iomap_writepage_ctx *wpc, struct inode *inode, |
| 304 | loff_t offset); |
| 305 | |
| 306 | /* |
| 307 | * Optional, allows the file systems to perform actions just before |
| 308 | * submitting the bio and/or override the bio end_io handler for complex |
| 309 | * operations like copy on write extent manipulation or unwritten extent |
| 310 | * conversions. |
| 311 | */ |
| 312 | int (*prepare_ioend)(struct iomap_ioend *ioend, int status); |
| 313 | |
| 314 | /* |
| 315 | * Optional, allows the file system to discard state on a page where |
| 316 | * we failed to submit any I/O. |
| 317 | */ |
Matthew Wilcox (Oracle) | 6e47852 | 2021-07-30 09:56:05 -0400 | [diff] [blame] | 318 | void (*discard_folio)(struct folio *folio, loff_t pos); |
Christoph Hellwig | 598ecfb | 2019-10-17 13:12:15 -0700 | [diff] [blame] | 319 | }; |
| 320 | |
| 321 | struct iomap_writepage_ctx { |
| 322 | struct iomap iomap; |
| 323 | struct iomap_ioend *ioend; |
| 324 | const struct iomap_writeback_ops *ops; |
| 325 | }; |
| 326 | |
| 327 | void iomap_finish_ioends(struct iomap_ioend *ioend, int error); |
| 328 | void iomap_ioend_try_merge(struct iomap_ioend *ioend, |
Brian Foster | 6e55249 | 2021-05-04 08:54:29 -0700 | [diff] [blame] | 329 | struct list_head *more_ioends); |
Christoph Hellwig | 598ecfb | 2019-10-17 13:12:15 -0700 | [diff] [blame] | 330 | void iomap_sort_ioends(struct list_head *ioend_list); |
Christoph Hellwig | 598ecfb | 2019-10-17 13:12:15 -0700 | [diff] [blame] | 331 | int iomap_writepages(struct address_space *mapping, |
| 332 | struct writeback_control *wbc, struct iomap_writepage_ctx *wpc, |
| 333 | const struct iomap_writeback_ops *ops); |
| 334 | |
| 335 | /* |
Christoph Hellwig | ff6a929 | 2016-11-30 14:36:01 +1100 | [diff] [blame] | 336 | * Flags for direct I/O ->end_io: |
| 337 | */ |
| 338 | #define IOMAP_DIO_UNWRITTEN (1 << 0) /* covers unwritten extent(s) */ |
| 339 | #define IOMAP_DIO_COW (1 << 1) /* covers COW extent(s) */ |
Christoph Hellwig | 838c4f3 | 2019-09-19 15:32:45 -0700 | [diff] [blame] | 340 | |
| 341 | struct iomap_dio_ops { |
| 342 | int (*end_io)(struct kiocb *iocb, ssize_t size, int error, |
| 343 | unsigned flags); |
Christoph Hellwig | 3e08773 | 2021-10-12 13:12:24 +0200 | [diff] [blame] | 344 | void (*submit_io)(const struct iomap_iter *iter, struct bio *bio, |
| 345 | loff_t file_offset); |
Christoph Hellwig | 908c549 | 2022-05-05 15:11:10 -0500 | [diff] [blame] | 346 | |
| 347 | /* |
| 348 | * Filesystems wishing to attach private information to a direct io bio |
| 349 | * must provide a ->submit_io method that attaches the additional |
| 350 | * information to the bio and changes the ->bi_end_io callback to a |
| 351 | * custom function. This function should, at a minimum, perform any |
| 352 | * relevant post-processing of the bio and end with a call to |
| 353 | * iomap_dio_bio_end_io. |
| 354 | */ |
| 355 | struct bio_set *bio_set; |
Christoph Hellwig | 838c4f3 | 2019-09-19 15:32:45 -0700 | [diff] [blame] | 356 | }; |
| 357 | |
Christoph Hellwig | 2f63296 | 2021-01-23 10:06:09 -0800 | [diff] [blame] | 358 | /* |
| 359 | * Wait for the I/O to complete in iomap_dio_rw even if the kiocb is not |
| 360 | * synchronous. |
| 361 | */ |
| 362 | #define IOMAP_DIO_FORCE_WAIT (1 << 0) |
| 363 | |
Christoph Hellwig | 213f627 | 2021-01-23 10:06:10 -0800 | [diff] [blame] | 364 | /* |
| 365 | * Do not allocate blocks or zero partial blocks, but instead fall back to |
| 366 | * the caller by returning -EAGAIN. Used to optimize direct I/O writes that |
| 367 | * are not aligned to the file system block size. |
| 368 | */ |
| 369 | #define IOMAP_DIO_OVERWRITE_ONLY (1 << 1) |
| 370 | |
Andreas Gruenbacher | 97308f8 | 2021-07-23 01:59:41 +0200 | [diff] [blame] | 371 | /* |
| 372 | * When a page fault occurs, return a partial synchronous result and allow |
| 373 | * the caller to retry the rest of the operation after dealing with the page |
| 374 | * fault. |
| 375 | */ |
| 376 | #define IOMAP_DIO_PARTIAL (1 << 2) |
| 377 | |
Al Viro | 36518b6 | 2022-06-07 16:04:03 -0400 | [diff] [blame] | 378 | /* |
| 379 | * The caller will sync the write if needed; do not sync it within |
| 380 | * iomap_dio_rw. Overrides IOMAP_DIO_FORCE_WAIT. |
| 381 | */ |
| 382 | #define IOMAP_DIO_NOSYNC (1 << 3) |
| 383 | |
Christoph Hellwig | ff6a929 | 2016-11-30 14:36:01 +1100 | [diff] [blame] | 384 | ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, |
Jan Kara | 13ef954 | 2019-10-15 08:43:42 -0700 | [diff] [blame] | 385 | const struct iomap_ops *ops, const struct iomap_dio_ops *dops, |
Christoph Hellwig | 786f847 | 2022-05-05 15:11:11 -0500 | [diff] [blame] | 386 | unsigned int dio_flags, void *private, size_t done_before); |
Christoph Hellwig | c3d4ed1 | 2020-09-28 08:51:08 -0700 | [diff] [blame] | 387 | struct iomap_dio *__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, |
| 388 | const struct iomap_ops *ops, const struct iomap_dio_ops *dops, |
Christoph Hellwig | 786f847 | 2022-05-05 15:11:11 -0500 | [diff] [blame] | 389 | unsigned int dio_flags, void *private, size_t done_before); |
Christoph Hellwig | c3d4ed1 | 2020-09-28 08:51:08 -0700 | [diff] [blame] | 390 | ssize_t iomap_dio_complete(struct iomap_dio *dio); |
Christoph Hellwig | 908c549 | 2022-05-05 15:11:10 -0500 | [diff] [blame] | 391 | void iomap_dio_bio_end_io(struct bio *bio); |
Christoph Hellwig | ff6a929 | 2016-11-30 14:36:01 +1100 | [diff] [blame] | 392 | |
Darrick J. Wong | 67482129 | 2018-05-10 08:38:15 -0700 | [diff] [blame] | 393 | #ifdef CONFIG_SWAP |
| 394 | struct file; |
| 395 | struct swap_info_struct; |
| 396 | |
| 397 | int iomap_swapfile_activate(struct swap_info_struct *sis, |
| 398 | struct file *swap_file, sector_t *pagespan, |
| 399 | const struct iomap_ops *ops); |
| 400 | #else |
| 401 | # define iomap_swapfile_activate(sis, swapfile, pagespan, ops) (-EIO) |
| 402 | #endif /* CONFIG_SWAP */ |
| 403 | |
Christoph Hellwig | 199a31c | 2016-06-21 09:22:39 +1000 | [diff] [blame] | 404 | #endif /* LINUX_IOMAP_H */ |