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