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/mm.h>
8#include <linux/types.h>
9#include <linux/mm_types.h>
10#include <linux/blkdev.h>
11
12struct address_space;
13struct fiemap_extent_info;
14struct inode;
15struct iov_iter;
16struct kiocb;
17struct page;
18struct vm_area_struct;
19struct vm_fault;
20
21
22
23
24#define IOMAP_HOLE 0x01
25#define IOMAP_DELALLOC 0x02
26#define IOMAP_MAPPED 0x03
27#define IOMAP_UNWRITTEN 0x04
28#define IOMAP_INLINE 0x05
29
30
31
32
33
34
35
36#define IOMAP_F_NEW 0x01
37#define IOMAP_F_DIRTY 0x02
38#define IOMAP_F_BUFFER_HEAD 0x04
39#define IOMAP_F_SIZE_CHANGED 0x08
40
41
42
43
44#define IOMAP_F_MERGED 0x10
45#define IOMAP_F_SHARED 0x20
46
47
48
49
50#define IOMAP_F_PRIVATE 0x1000
51
52
53
54
55
56#define IOMAP_NULL_ADDR -1ULL
57
58struct iomap_page_ops;
59
60struct iomap {
61 u64 addr;
62 loff_t offset;
63 u64 length;
64 u16 type;
65 u16 flags;
66 struct block_device *bdev;
67 struct dax_device *dax_dev;
68 void *inline_data;
69 void *private;
70 const struct iomap_page_ops *page_ops;
71};
72
73static inline sector_t
74iomap_sector(struct iomap *iomap, loff_t pos)
75{
76 return (iomap->addr + pos - iomap->offset) >> SECTOR_SHIFT;
77}
78
79
80
81
82
83
84
85
86
87
88
89struct iomap_page_ops {
90 int (*page_prepare)(struct inode *inode, loff_t pos, unsigned len,
91 struct iomap *iomap);
92 void (*page_done)(struct inode *inode, loff_t pos, unsigned copied,
93 struct page *page, struct iomap *iomap);
94};
95
96
97
98
99#define IOMAP_WRITE (1 << 0)
100#define IOMAP_ZERO (1 << 1)
101#define IOMAP_REPORT (1 << 2)
102#define IOMAP_FAULT (1 << 3)
103#define IOMAP_DIRECT (1 << 4)
104#define IOMAP_NOWAIT (1 << 5)
105
106struct iomap_ops {
107
108
109
110
111
112 int (*iomap_begin)(struct inode *inode, loff_t pos, loff_t length,
113 unsigned flags, struct iomap *iomap);
114
115
116
117
118
119
120
121 int (*iomap_end)(struct inode *inode, loff_t pos, loff_t length,
122 ssize_t written, unsigned flags, struct iomap *iomap);
123};
124
125
126
127
128typedef loff_t (*iomap_actor_t)(struct inode *inode, loff_t pos, loff_t len,
129 void *data, struct iomap *iomap);
130
131loff_t iomap_apply(struct inode *inode, loff_t pos, loff_t length,
132 unsigned flags, const struct iomap_ops *ops, void *data,
133 iomap_actor_t actor);
134
135
136
137
138
139struct iomap_page {
140 atomic_t read_count;
141 atomic_t write_count;
142 DECLARE_BITMAP(uptodate, PAGE_SIZE / 512);
143};
144
145static inline struct iomap_page *to_iomap_page(struct page *page)
146{
147 if (page_has_private(page))
148 return (struct iomap_page *)page_private(page);
149 return NULL;
150}
151
152ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from,
153 const struct iomap_ops *ops);
154int iomap_readpage(struct page *page, const struct iomap_ops *ops);
155int iomap_readpages(struct address_space *mapping, struct list_head *pages,
156 unsigned nr_pages, const struct iomap_ops *ops);
157int iomap_set_page_dirty(struct page *page);
158int iomap_is_partially_uptodate(struct page *page, unsigned long from,
159 unsigned long count);
160int iomap_releasepage(struct page *page, gfp_t gfp_mask);
161void iomap_invalidatepage(struct page *page, unsigned int offset,
162 unsigned int len);
163#ifdef CONFIG_MIGRATION
164int iomap_migrate_page(struct address_space *mapping, struct page *newpage,
165 struct page *page, enum migrate_mode mode);
166#else
167#define iomap_migrate_page NULL
168#endif
169int iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len,
170 const struct iomap_ops *ops);
171int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len,
172 bool *did_zero, const struct iomap_ops *ops);
173int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero,
174 const struct iomap_ops *ops);
175vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf,
176 const struct iomap_ops *ops);
177int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
178 loff_t start, loff_t len, const struct iomap_ops *ops);
179loff_t iomap_seek_hole(struct inode *inode, loff_t offset,
180 const struct iomap_ops *ops);
181loff_t iomap_seek_data(struct inode *inode, loff_t offset,
182 const struct iomap_ops *ops);
183sector_t iomap_bmap(struct address_space *mapping, sector_t bno,
184 const struct iomap_ops *ops);
185
186
187
188
189#define IOMAP_DIO_UNWRITTEN (1 << 0)
190#define IOMAP_DIO_COW (1 << 1)
191
192struct iomap_dio_ops {
193 int (*end_io)(struct kiocb *iocb, ssize_t size, int error,
194 unsigned flags);
195};
196
197ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter,
198 const struct iomap_ops *ops, const struct iomap_dio_ops *dops);
199int iomap_dio_iopoll(struct kiocb *kiocb, bool spin);
200
201#ifdef CONFIG_SWAP
202struct file;
203struct swap_info_struct;
204
205int iomap_swapfile_activate(struct swap_info_struct *sis,
206 struct file *swap_file, sector_t *pagespan,
207 const struct iomap_ops *ops);
208#else
209# define iomap_swapfile_activate(sis, swapfile, pagespan, ops) (-EIO)
210#endif
211
212#endif
213