.. | .. |
---|
4 | 4 | |
---|
5 | 5 | #include <linux/atomic.h> |
---|
6 | 6 | #include <linux/bitmap.h> |
---|
| 7 | +#include <linux/blk_types.h> |
---|
7 | 8 | #include <linux/mm.h> |
---|
8 | 9 | #include <linux/types.h> |
---|
| 10 | +#include <linux/mm_types.h> |
---|
| 11 | +#include <linux/blkdev.h> |
---|
9 | 12 | #include <linux/android_kabi.h> |
---|
10 | 13 | |
---|
11 | 14 | struct address_space; |
---|
12 | 15 | struct fiemap_extent_info; |
---|
13 | 16 | struct inode; |
---|
| 17 | +struct iomap_dio; |
---|
| 18 | +struct iomap_writepage_ctx; |
---|
14 | 19 | struct iov_iter; |
---|
15 | 20 | struct kiocb; |
---|
16 | 21 | struct page; |
---|
.. | .. |
---|
20 | 25 | /* |
---|
21 | 26 | * Types of block ranges for iomap mappings: |
---|
22 | 27 | */ |
---|
23 | | -#define IOMAP_HOLE 0x01 /* no blocks allocated, need allocation */ |
---|
24 | | -#define IOMAP_DELALLOC 0x02 /* delayed allocation blocks */ |
---|
25 | | -#define IOMAP_MAPPED 0x03 /* blocks allocated at @addr */ |
---|
26 | | -#define IOMAP_UNWRITTEN 0x04 /* blocks allocated at @addr in unwritten state */ |
---|
27 | | -#define IOMAP_INLINE 0x05 /* data inline in the inode */ |
---|
| 28 | +#define IOMAP_HOLE 0 /* no blocks allocated, need allocation */ |
---|
| 29 | +#define IOMAP_DELALLOC 1 /* delayed allocation blocks */ |
---|
| 30 | +#define IOMAP_MAPPED 2 /* blocks allocated at @addr */ |
---|
| 31 | +#define IOMAP_UNWRITTEN 3 /* blocks allocated at @addr in unwritten state */ |
---|
| 32 | +#define IOMAP_INLINE 4 /* data inline in the inode */ |
---|
28 | 33 | |
---|
29 | 34 | /* |
---|
30 | | - * Flags for all iomap mappings: |
---|
| 35 | + * Flags reported by the file system from iomap_begin: |
---|
| 36 | + * |
---|
| 37 | + * IOMAP_F_NEW indicates that the blocks have been newly allocated and need |
---|
| 38 | + * zeroing for areas that no data is copied to. |
---|
31 | 39 | * |
---|
32 | 40 | * IOMAP_F_DIRTY indicates the inode has uncommitted metadata needed to access |
---|
33 | 41 | * written data and requires fdatasync to commit them to persistent storage. |
---|
| 42 | + * This needs to take into account metadata changes that *may* be made at IO |
---|
| 43 | + * completion, such as file size updates from direct IO. |
---|
| 44 | + * |
---|
| 45 | + * IOMAP_F_SHARED indicates that the blocks are shared, and will need to be |
---|
| 46 | + * unshared as part a write. |
---|
| 47 | + * |
---|
| 48 | + * IOMAP_F_MERGED indicates that the iomap contains the merge of multiple block |
---|
| 49 | + * mappings. |
---|
| 50 | + * |
---|
| 51 | + * IOMAP_F_BUFFER_HEAD indicates that the file system requires the use of |
---|
| 52 | + * buffer heads for this mapping. |
---|
34 | 53 | */ |
---|
35 | | -#define IOMAP_F_NEW 0x01 /* blocks have been newly allocated */ |
---|
36 | | -#define IOMAP_F_DIRTY 0x02 /* uncommitted metadata */ |
---|
37 | | -#define IOMAP_F_BUFFER_HEAD 0x04 /* file system requires buffer heads */ |
---|
| 54 | +#define IOMAP_F_NEW 0x01 |
---|
| 55 | +#define IOMAP_F_DIRTY 0x02 |
---|
| 56 | +#define IOMAP_F_SHARED 0x04 |
---|
| 57 | +#define IOMAP_F_MERGED 0x08 |
---|
| 58 | +#define IOMAP_F_BUFFER_HEAD 0x10 |
---|
38 | 59 | |
---|
39 | 60 | /* |
---|
40 | | - * Flags that only need to be reported for IOMAP_REPORT requests: |
---|
| 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. |
---|
41 | 65 | */ |
---|
42 | | -#define IOMAP_F_MERGED 0x10 /* contains multiple blocks/extents */ |
---|
43 | | -#define IOMAP_F_SHARED 0x20 /* block shared with another file */ |
---|
| 66 | +#define IOMAP_F_SIZE_CHANGED 0x100 |
---|
44 | 67 | |
---|
45 | 68 | /* |
---|
46 | 69 | * Flags from 0x1000 up are for file system specific usage: |
---|
.. | .. |
---|
53 | 76 | */ |
---|
54 | 77 | #define IOMAP_NULL_ADDR -1ULL /* addr is not valid */ |
---|
55 | 78 | |
---|
| 79 | +struct iomap_page_ops; |
---|
| 80 | + |
---|
56 | 81 | struct iomap { |
---|
57 | 82 | u64 addr; /* disk offset of mapping, bytes */ |
---|
58 | 83 | loff_t offset; /* file offset of mapping, bytes */ |
---|
.. | .. |
---|
63 | 88 | struct dax_device *dax_dev; /* dax_dev for dax operations */ |
---|
64 | 89 | void *inline_data; |
---|
65 | 90 | void *private; /* filesystem private */ |
---|
| 91 | + const struct iomap_page_ops *page_ops; |
---|
66 | 92 | |
---|
67 | | - /* |
---|
68 | | - * Called when finished processing a page in the mapping returned in |
---|
69 | | - * this iomap. At least for now this is only supported in the buffered |
---|
70 | | - * write path. |
---|
71 | | - */ |
---|
| 93 | + ANDROID_KABI_RESERVE(1); |
---|
| 94 | +}; |
---|
| 95 | + |
---|
| 96 | +static inline sector_t |
---|
| 97 | +iomap_sector(struct iomap *iomap, loff_t pos) |
---|
| 98 | +{ |
---|
| 99 | + return (iomap->addr + pos - iomap->offset) >> SECTOR_SHIFT; |
---|
| 100 | +} |
---|
| 101 | + |
---|
| 102 | +/* |
---|
| 103 | + * When a filesystem sets page_ops in an iomap mapping it returns, page_prepare |
---|
| 104 | + * and page_done will be called for each page written to. This only applies to |
---|
| 105 | + * buffered writes as unbuffered writes will not typically have pages |
---|
| 106 | + * associated with them. |
---|
| 107 | + * |
---|
| 108 | + * When page_prepare succeeds, page_done will always be called to do any |
---|
| 109 | + * cleanup work necessary. In that page_done call, @page will be NULL if the |
---|
| 110 | + * associated page could not be obtained. |
---|
| 111 | + */ |
---|
| 112 | +struct iomap_page_ops { |
---|
| 113 | + int (*page_prepare)(struct inode *inode, loff_t pos, unsigned len, |
---|
| 114 | + struct iomap *iomap); |
---|
72 | 115 | void (*page_done)(struct inode *inode, loff_t pos, unsigned copied, |
---|
73 | 116 | struct page *page, struct iomap *iomap); |
---|
74 | 117 | }; |
---|
.. | .. |
---|
90 | 133 | * The actual length is returned in iomap->length. |
---|
91 | 134 | */ |
---|
92 | 135 | int (*iomap_begin)(struct inode *inode, loff_t pos, loff_t length, |
---|
93 | | - unsigned flags, struct iomap *iomap); |
---|
| 136 | + unsigned flags, struct iomap *iomap, |
---|
| 137 | + struct iomap *srcmap); |
---|
94 | 138 | |
---|
95 | 139 | /* |
---|
96 | 140 | * Commit and/or unreserve space previous allocated using iomap_begin. |
---|
.. | .. |
---|
106 | 150 | }; |
---|
107 | 151 | |
---|
108 | 152 | /* |
---|
109 | | - * Structure allocate for each page when block size < PAGE_SIZE to track |
---|
110 | | - * sub-page uptodate status and I/O completions. |
---|
| 153 | + * Main iomap iterator function. |
---|
111 | 154 | */ |
---|
112 | | -struct iomap_page { |
---|
113 | | - atomic_t read_count; |
---|
114 | | - atomic_t write_count; |
---|
115 | | - spinlock_t uptodate_lock; |
---|
116 | | - DECLARE_BITMAP(uptodate, PAGE_SIZE / 512); |
---|
117 | | -}; |
---|
| 155 | +typedef loff_t (*iomap_actor_t)(struct inode *inode, loff_t pos, loff_t len, |
---|
| 156 | + void *data, struct iomap *iomap, struct iomap *srcmap); |
---|
118 | 157 | |
---|
119 | | -static inline struct iomap_page *to_iomap_page(struct page *page) |
---|
120 | | -{ |
---|
121 | | - if (page_has_private(page)) |
---|
122 | | - return (struct iomap_page *)page_private(page); |
---|
123 | | - return NULL; |
---|
124 | | -} |
---|
| 158 | +loff_t iomap_apply(struct inode *inode, loff_t pos, loff_t length, |
---|
| 159 | + unsigned flags, const struct iomap_ops *ops, void *data, |
---|
| 160 | + iomap_actor_t actor); |
---|
125 | 161 | |
---|
126 | 162 | ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from, |
---|
127 | 163 | const struct iomap_ops *ops); |
---|
128 | 164 | int iomap_readpage(struct page *page, const struct iomap_ops *ops); |
---|
129 | | -int iomap_readpages(struct address_space *mapping, struct list_head *pages, |
---|
130 | | - unsigned nr_pages, const struct iomap_ops *ops); |
---|
| 165 | +void iomap_readahead(struct readahead_control *, const struct iomap_ops *ops); |
---|
131 | 166 | int iomap_set_page_dirty(struct page *page); |
---|
132 | 167 | int iomap_is_partially_uptodate(struct page *page, unsigned long from, |
---|
133 | 168 | unsigned long count); |
---|
.. | .. |
---|
140 | 175 | #else |
---|
141 | 176 | #define iomap_migrate_page NULL |
---|
142 | 177 | #endif |
---|
143 | | -int iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len, |
---|
| 178 | +int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len, |
---|
144 | 179 | const struct iomap_ops *ops); |
---|
145 | 180 | int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, |
---|
146 | 181 | bool *did_zero, const struct iomap_ops *ops); |
---|
147 | 182 | int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, |
---|
148 | 183 | const struct iomap_ops *ops); |
---|
149 | | -int iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops); |
---|
| 184 | +vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, |
---|
| 185 | + const struct iomap_ops *ops); |
---|
150 | 186 | int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
---|
151 | | - loff_t start, loff_t len, const struct iomap_ops *ops); |
---|
| 187 | + u64 start, u64 len, const struct iomap_ops *ops); |
---|
152 | 188 | loff_t iomap_seek_hole(struct inode *inode, loff_t offset, |
---|
153 | 189 | const struct iomap_ops *ops); |
---|
154 | 190 | loff_t iomap_seek_data(struct inode *inode, loff_t offset, |
---|
.. | .. |
---|
157 | 193 | const struct iomap_ops *ops); |
---|
158 | 194 | |
---|
159 | 195 | /* |
---|
| 196 | + * Structure for writeback I/O completions. |
---|
| 197 | + */ |
---|
| 198 | +struct iomap_ioend { |
---|
| 199 | + struct list_head io_list; /* next ioend in chain */ |
---|
| 200 | + u16 io_type; |
---|
| 201 | + u16 io_flags; /* IOMAP_F_* */ |
---|
| 202 | + struct inode *io_inode; /* file being written to */ |
---|
| 203 | + size_t io_size; /* size of the extent */ |
---|
| 204 | + loff_t io_offset; /* offset in the file */ |
---|
| 205 | + void *io_private; /* file system private data */ |
---|
| 206 | + struct bio *io_bio; /* bio being built */ |
---|
| 207 | + struct bio io_inline_bio; /* MUST BE LAST! */ |
---|
| 208 | +}; |
---|
| 209 | + |
---|
| 210 | +struct iomap_writeback_ops { |
---|
| 211 | + /* |
---|
| 212 | + * Required, maps the blocks so that writeback can be performed on |
---|
| 213 | + * the range starting at offset. |
---|
| 214 | + */ |
---|
| 215 | + int (*map_blocks)(struct iomap_writepage_ctx *wpc, struct inode *inode, |
---|
| 216 | + loff_t offset); |
---|
| 217 | + |
---|
| 218 | + /* |
---|
| 219 | + * Optional, allows the file systems to perform actions just before |
---|
| 220 | + * submitting the bio and/or override the bio end_io handler for complex |
---|
| 221 | + * operations like copy on write extent manipulation or unwritten extent |
---|
| 222 | + * conversions. |
---|
| 223 | + */ |
---|
| 224 | + int (*prepare_ioend)(struct iomap_ioend *ioend, int status); |
---|
| 225 | + |
---|
| 226 | + /* |
---|
| 227 | + * Optional, allows the file system to discard state on a page where |
---|
| 228 | + * we failed to submit any I/O. |
---|
| 229 | + */ |
---|
| 230 | + void (*discard_page)(struct page *page, loff_t fileoff); |
---|
| 231 | +}; |
---|
| 232 | + |
---|
| 233 | +struct iomap_writepage_ctx { |
---|
| 234 | + struct iomap iomap; |
---|
| 235 | + struct iomap_ioend *ioend; |
---|
| 236 | + const struct iomap_writeback_ops *ops; |
---|
| 237 | +}; |
---|
| 238 | + |
---|
| 239 | +void iomap_finish_ioends(struct iomap_ioend *ioend, int error); |
---|
| 240 | +void iomap_ioend_try_merge(struct iomap_ioend *ioend, |
---|
| 241 | + struct list_head *more_ioends, |
---|
| 242 | + void (*merge_private)(struct iomap_ioend *ioend, |
---|
| 243 | + struct iomap_ioend *next)); |
---|
| 244 | +void iomap_sort_ioends(struct list_head *ioend_list); |
---|
| 245 | +int iomap_writepage(struct page *page, struct writeback_control *wbc, |
---|
| 246 | + struct iomap_writepage_ctx *wpc, |
---|
| 247 | + const struct iomap_writeback_ops *ops); |
---|
| 248 | +int iomap_writepages(struct address_space *mapping, |
---|
| 249 | + struct writeback_control *wbc, struct iomap_writepage_ctx *wpc, |
---|
| 250 | + const struct iomap_writeback_ops *ops); |
---|
| 251 | + |
---|
| 252 | +/* |
---|
160 | 253 | * Flags for direct I/O ->end_io: |
---|
161 | 254 | */ |
---|
162 | 255 | #define IOMAP_DIO_UNWRITTEN (1 << 0) /* covers unwritten extent(s) */ |
---|
163 | 256 | #define IOMAP_DIO_COW (1 << 1) /* covers COW extent(s) */ |
---|
164 | | -typedef int (iomap_dio_end_io_t)(struct kiocb *iocb, ssize_t ret, |
---|
165 | | - unsigned flags); |
---|
| 257 | + |
---|
| 258 | +struct iomap_dio_ops { |
---|
| 259 | + int (*end_io)(struct kiocb *iocb, ssize_t size, int error, |
---|
| 260 | + unsigned flags); |
---|
| 261 | + blk_qc_t (*submit_io)(struct inode *inode, struct iomap *iomap, |
---|
| 262 | + struct bio *bio, loff_t file_offset); |
---|
| 263 | +}; |
---|
| 264 | + |
---|
166 | 265 | ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, |
---|
167 | | - const struct iomap_ops *ops, iomap_dio_end_io_t end_io); |
---|
| 266 | + const struct iomap_ops *ops, const struct iomap_dio_ops *dops, |
---|
| 267 | + bool wait_for_completion); |
---|
| 268 | +struct iomap_dio *__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, |
---|
| 269 | + const struct iomap_ops *ops, const struct iomap_dio_ops *dops, |
---|
| 270 | + bool wait_for_completion); |
---|
| 271 | +ssize_t iomap_dio_complete(struct iomap_dio *dio); |
---|
| 272 | +int iomap_dio_iopoll(struct kiocb *kiocb, bool spin); |
---|
168 | 273 | |
---|
169 | 274 | #ifdef CONFIG_SWAP |
---|
170 | 275 | struct file; |
---|