1
2#ifndef LINUX_IOMAP_H
3#define LINUX_IOMAP_H 1
4
5#include <linux/atomic.h>
6#include <linux/bitmap.h>
7#include <linux/blk_types.h>
8#include <linux/mm.h>
9#include <linux/types.h>
10#include <linux/mm_types.h>
11#include <linux/blkdev.h>
12
13struct address_space;
14struct fiemap_extent_info;
15struct inode;
16struct iomap_dio;
17struct iomap_writepage_ctx;
18struct iov_iter;
19struct kiocb;
20struct page;
21struct vm_area_struct;
22struct vm_fault;
23
24
25
26
27#define IOMAP_HOLE 0
28#define IOMAP_DELALLOC 1
29#define IOMAP_MAPPED 2
30#define IOMAP_UNWRITTEN 3
31#define IOMAP_INLINE 4
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
58#define IOMAP_F_ZONE_APPEND 0x20
59
60
61
62
63
64
65
66#define IOMAP_F_SIZE_CHANGED 0x100
67
68
69
70
71#define IOMAP_F_PRIVATE 0x1000
72
73
74
75
76
77#define IOMAP_NULL_ADDR -1ULL
78
79struct iomap_page_ops;
80
81struct iomap {
82 u64 addr;
83 loff_t offset;
84 u64 length;
85 u16 type;
86 u16 flags;
87 struct block_device *bdev;
88 struct dax_device *dax_dev;
89 void *inline_data;
90 void *private;
91 const struct iomap_page_ops *page_ops;
92};
93
94static inline sector_t iomap_sector(const struct iomap *iomap, loff_t pos)
95{
96 return (iomap->addr + pos - iomap->offset) >> SECTOR_SHIFT;
97}
98
99
100
101
102static inline void *iomap_inline_data(const struct iomap *iomap, loff_t pos)
103{
104 return iomap->inline_data + pos - iomap->offset;
105}
106
107
108
109
110
111
112static inline bool iomap_inline_data_valid(const struct iomap *iomap)
113{
114 return iomap->length <= PAGE_SIZE - offset_in_page(iomap->inline_data);
115}
116
117
118
119
120
121
122
123
124
125
126
127struct iomap_page_ops {
128 int (*page_prepare)(struct inode *inode, loff_t pos, unsigned len);
129 void (*page_done)(struct inode *inode, loff_t pos, unsigned copied,
130 struct page *page);
131};
132
133
134
135
136#define IOMAP_WRITE (1 << 0)
137#define IOMAP_ZERO (1 << 1)
138#define IOMAP_REPORT (1 << 2)
139#define IOMAP_FAULT (1 << 3)
140#define IOMAP_DIRECT (1 << 4)
141#define IOMAP_NOWAIT (1 << 5)
142#define IOMAP_OVERWRITE_ONLY (1 << 6)
143#define IOMAP_UNSHARE (1 << 7)
144
145struct iomap_ops {
146
147
148
149
150
151 int (*iomap_begin)(struct inode *inode, loff_t pos, loff_t length,
152 unsigned flags, struct iomap *iomap,
153 struct iomap *srcmap);
154
155
156
157
158
159
160
161 int (*iomap_end)(struct inode *inode, loff_t pos, loff_t length,
162 ssize_t written, unsigned flags, struct iomap *iomap);
163};
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178struct iomap_iter {
179 struct inode *inode;
180 loff_t pos;
181 u64 len;
182 s64 processed;
183 unsigned flags;
184 struct iomap iomap;
185 struct iomap srcmap;
186};
187
188int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops);
189
190
191
192
193
194
195
196static inline u64 iomap_length(const struct iomap_iter *iter)
197{
198 u64 end = iter->iomap.offset + iter->iomap.length;
199
200 if (iter->srcmap.type != IOMAP_HOLE)
201 end = min(end, iter->srcmap.offset + iter->srcmap.length);
202 return min(iter->len, end - iter->pos);
203}
204
205
206
207
208
209
210
211
212
213
214static inline const struct iomap *iomap_iter_srcmap(const struct iomap_iter *i)
215{
216 if (i->srcmap.type != IOMAP_HOLE)
217 return &i->srcmap;
218 return &i->iomap;
219}
220
221ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from,
222 const struct iomap_ops *ops);
223int iomap_readpage(struct page *page, const struct iomap_ops *ops);
224void iomap_readahead(struct readahead_control *, const struct iomap_ops *ops);
225int iomap_is_partially_uptodate(struct page *page, unsigned long from,
226 unsigned long count);
227int iomap_releasepage(struct page *page, gfp_t gfp_mask);
228void iomap_invalidatepage(struct page *page, unsigned int offset,
229 unsigned int len);
230#ifdef CONFIG_MIGRATION
231int iomap_migrate_page(struct address_space *mapping, struct page *newpage,
232 struct page *page, enum migrate_mode mode);
233#else
234#define iomap_migrate_page NULL
235#endif
236int iomap_file_unshare(struct inode *inode, loff_t pos, loff_t len,
237 const struct iomap_ops *ops);
238int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len,
239 bool *did_zero, const struct iomap_ops *ops);
240int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
241 const struct iomap_ops *ops);
242vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf,
243 const struct iomap_ops *ops);
244int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
245 u64 start, u64 len, const struct iomap_ops *ops);
246loff_t iomap_seek_hole(struct inode *inode, loff_t offset,
247 const struct iomap_ops *ops);
248loff_t iomap_seek_data(struct inode *inode, loff_t offset,
249 const struct iomap_ops *ops);
250sector_t iomap_bmap(struct address_space *mapping, sector_t bno,
251 const struct iomap_ops *ops);
252
253
254
255
256struct iomap_ioend {
257 struct list_head io_list;
258 u16 io_type;
259 u16 io_flags;
260 struct inode *io_inode;
261 size_t io_size;
262 loff_t io_offset;
263 struct bio *io_bio;
264 struct bio io_inline_bio;
265};
266
267struct iomap_writeback_ops {
268
269
270
271
272 int (*map_blocks)(struct iomap_writepage_ctx *wpc, struct inode *inode,
273 loff_t offset);
274
275
276
277
278
279
280
281 int (*prepare_ioend)(struct iomap_ioend *ioend, int status);
282
283
284
285
286
287 void (*discard_page)(struct page *page, loff_t fileoff);
288};
289
290struct iomap_writepage_ctx {
291 struct iomap iomap;
292 struct iomap_ioend *ioend;
293 const struct iomap_writeback_ops *ops;
294};
295
296void iomap_finish_ioends(struct iomap_ioend *ioend, int error);
297void iomap_ioend_try_merge(struct iomap_ioend *ioend,
298 struct list_head *more_ioends);
299void iomap_sort_ioends(struct list_head *ioend_list);
300int iomap_writepage(struct page *page, struct writeback_control *wbc,
301 struct iomap_writepage_ctx *wpc,
302 const struct iomap_writeback_ops *ops);
303int iomap_writepages(struct address_space *mapping,
304 struct writeback_control *wbc, struct iomap_writepage_ctx *wpc,
305 const struct iomap_writeback_ops *ops);
306
307
308
309
310#define IOMAP_DIO_UNWRITTEN (1 << 0)
311#define IOMAP_DIO_COW (1 << 1)
312
313struct iomap_dio_ops {
314 int (*end_io)(struct kiocb *iocb, ssize_t size, int error,
315 unsigned flags);
316 blk_qc_t (*submit_io)(const struct iomap_iter *iter, struct bio *bio,
317 loff_t file_offset);
318};
319
320
321
322
323
324#define IOMAP_DIO_FORCE_WAIT (1 << 0)
325
326
327
328
329
330
331#define IOMAP_DIO_OVERWRITE_ONLY (1 << 1)
332
333ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
334 const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
335 unsigned int dio_flags);
336struct iomap_dio *__iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
337 const struct iomap_ops *ops, const struct iomap_dio_ops *dops,
338 unsigned int dio_flags);
339ssize_t iomap_dio_complete(struct iomap_dio *dio);
340int iomap_dio_iopoll(struct kiocb *kiocb, bool spin);
341
342#ifdef CONFIG_SWAP
343struct file;
344struct swap_info_struct;
345
346int iomap_swapfile_activate(struct swap_info_struct *sis,
347 struct file *swap_file, sector_t *pagespan,
348 const struct iomap_ops *ops);
349#else
350# define iomap_swapfile_activate(sis, swapfile, pagespan, ops) (-EIO)
351#endif
352
353#endif
354