Commit | Line | Data |
---|---|---|
b2441318 | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
199a31c6 CH |
2 | #ifndef LINUX_IOMAP_H |
3 | #define LINUX_IOMAP_H 1 | |
4 | ||
9dc55f13 CH |
5 | #include <linux/atomic.h> |
6 | #include <linux/bitmap.h> | |
7 | #include <linux/mm.h> | |
199a31c6 | 8 | #include <linux/types.h> |
5780a02f | 9 | #include <linux/mm_types.h> |
199a31c6 | 10 | |
89eb1906 | 11 | struct address_space; |
8be9f564 | 12 | struct fiemap_extent_info; |
ae259a9c CH |
13 | struct inode; |
14 | struct iov_iter; | |
15 | struct kiocb; | |
63899c6f | 16 | struct page; |
ae259a9c CH |
17 | struct vm_area_struct; |
18 | struct vm_fault; | |
19 | ||
20 | /* | |
21 | * Types of block ranges for iomap mappings: | |
22 | */ | |
199a31c6 CH |
23 | #define IOMAP_HOLE 0x01 /* no blocks allocated, need allocation */ |
24 | #define IOMAP_DELALLOC 0x02 /* delayed allocation blocks */ | |
19fe5f64 AG |
25 | #define IOMAP_MAPPED 0x03 /* blocks allocated at @addr */ |
26 | #define IOMAP_UNWRITTEN 0x04 /* blocks allocated at @addr in unwritten state */ | |
19319b53 | 27 | #define IOMAP_INLINE 0x05 /* data inline in the inode */ |
199a31c6 | 28 | |
17de0a9f | 29 | /* |
d33fd776 | 30 | * Flags for all iomap mappings: |
a3841f94 | 31 | * |
caa51d26 JK |
32 | * IOMAP_F_DIRTY indicates the inode has uncommitted metadata needed to access |
33 | * written data and requires fdatasync to commit them to persistent storage. | |
17de0a9f | 34 | */ |
3974320c | 35 | #define IOMAP_F_NEW 0x01 /* blocks have been newly allocated */ |
7ee66c03 | 36 | #define IOMAP_F_DIRTY 0x02 /* uncommitted metadata */ |
c03cea42 | 37 | #define IOMAP_F_BUFFER_HEAD 0x04 /* file system requires buffer heads */ |
d33fd776 CH |
38 | |
39 | /* | |
40 | * Flags that only need to be reported for IOMAP_REPORT requests: | |
41 | */ | |
9ca250a5 AG |
42 | #define IOMAP_F_MERGED 0x10 /* contains multiple blocks/extents */ |
43 | #define IOMAP_F_SHARED 0x20 /* block shared with another file */ | |
17de0a9f | 44 | |
7ee66c03 CH |
45 | /* |
46 | * Flags from 0x1000 up are for file system specific usage: | |
47 | */ | |
48 | #define IOMAP_F_PRIVATE 0x1000 | |
49 | ||
50 | ||
ae259a9c | 51 | /* |
19fe5f64 | 52 | * Magic value for addr: |
ae259a9c | 53 | */ |
19fe5f64 | 54 | #define IOMAP_NULL_ADDR -1ULL /* addr is not valid */ |
199a31c6 CH |
55 | |
56 | struct iomap { | |
19fe5f64 | 57 | u64 addr; /* disk offset of mapping, bytes */ |
ae259a9c CH |
58 | loff_t offset; /* file offset of mapping, bytes */ |
59 | u64 length; /* length of mapping, bytes */ | |
17de0a9f CH |
60 | u16 type; /* type of mapping */ |
61 | u16 flags; /* flags for mapping */ | |
ae259a9c | 62 | struct block_device *bdev; /* block device for I/O */ |
fa5d932c | 63 | struct dax_device *dax_dev; /* dax_dev for dax operations */ |
19e0c58f | 64 | void *inline_data; |
e184fde6 | 65 | void *private; /* filesystem private */ |
63899c6f CH |
66 | |
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 | */ | |
72 | void (*page_done)(struct inode *inode, loff_t pos, unsigned copied, | |
73 | struct page *page, struct iomap *iomap); | |
ae259a9c CH |
74 | }; |
75 | ||
76 | /* | |
77 | * Flags for iomap_begin / iomap_end. No flag implies a read. | |
78 | */ | |
d33fd776 CH |
79 | #define IOMAP_WRITE (1 << 0) /* writing, must allocate blocks */ |
80 | #define IOMAP_ZERO (1 << 1) /* zeroing operation, may skip holes */ | |
81 | #define IOMAP_REPORT (1 << 2) /* report extent status, e.g. FIEMAP */ | |
9484ab1b | 82 | #define IOMAP_FAULT (1 << 3) /* mapping for page fault */ |
ff6a9292 | 83 | #define IOMAP_DIRECT (1 << 4) /* direct I/O */ |
9ecac0ef | 84 | #define IOMAP_NOWAIT (1 << 5) /* do not block */ |
ae259a9c CH |
85 | |
86 | struct iomap_ops { | |
87 | /* | |
88 | * Return the existing mapping at pos, or reserve space starting at | |
89 | * pos for up to length, as long as we can do it as a single mapping. | |
90 | * The actual length is returned in iomap->length. | |
91 | */ | |
92 | int (*iomap_begin)(struct inode *inode, loff_t pos, loff_t length, | |
93 | unsigned flags, struct iomap *iomap); | |
94 | ||
95 | /* | |
96 | * Commit and/or unreserve space previous allocated using iomap_begin. | |
97 | * Written indicates the length of the successful write operation which | |
98 | * needs to be commited, while the rest needs to be unreserved. | |
99 | * Written might be zero if no data was written. | |
100 | */ | |
101 | int (*iomap_end)(struct inode *inode, loff_t pos, loff_t length, | |
102 | ssize_t written, unsigned flags, struct iomap *iomap); | |
199a31c6 CH |
103 | }; |
104 | ||
9dc55f13 CH |
105 | /* |
106 | * Structure allocate for each page when block size < PAGE_SIZE to track | |
107 | * sub-page uptodate status and I/O completions. | |
108 | */ | |
109 | struct iomap_page { | |
110 | atomic_t read_count; | |
111 | atomic_t write_count; | |
112 | DECLARE_BITMAP(uptodate, PAGE_SIZE / 512); | |
113 | }; | |
114 | ||
115 | static inline struct iomap_page *to_iomap_page(struct page *page) | |
116 | { | |
117 | if (page_has_private(page)) | |
118 | return (struct iomap_page *)page_private(page); | |
119 | return NULL; | |
120 | } | |
121 | ||
ae259a9c | 122 | ssize_t iomap_file_buffered_write(struct kiocb *iocb, struct iov_iter *from, |
8ff6daa1 | 123 | const struct iomap_ops *ops); |
72b4daa2 CH |
124 | int iomap_readpage(struct page *page, const struct iomap_ops *ops); |
125 | int iomap_readpages(struct address_space *mapping, struct list_head *pages, | |
126 | unsigned nr_pages, const struct iomap_ops *ops); | |
c03cea42 | 127 | int iomap_set_page_dirty(struct page *page); |
9dc55f13 CH |
128 | int iomap_is_partially_uptodate(struct page *page, unsigned long from, |
129 | unsigned long count); | |
130 | int iomap_releasepage(struct page *page, gfp_t gfp_mask); | |
131 | void iomap_invalidatepage(struct page *page, unsigned int offset, | |
132 | unsigned int len); | |
133 | #ifdef CONFIG_MIGRATION | |
134 | int iomap_migrate_page(struct address_space *mapping, struct page *newpage, | |
135 | struct page *page, enum migrate_mode mode); | |
136 | #else | |
137 | #define iomap_migrate_page NULL | |
138 | #endif | |
5f4e5752 | 139 | int iomap_file_dirty(struct inode *inode, loff_t pos, loff_t len, |
8ff6daa1 | 140 | const struct iomap_ops *ops); |
ae259a9c | 141 | int iomap_zero_range(struct inode *inode, loff_t pos, loff_t len, |
8ff6daa1 | 142 | bool *did_zero, const struct iomap_ops *ops); |
ae259a9c | 143 | int iomap_truncate_page(struct inode *inode, loff_t pos, bool *did_zero, |
8ff6daa1 | 144 | const struct iomap_ops *ops); |
5780a02f SJ |
145 | vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, |
146 | const struct iomap_ops *ops); | |
8be9f564 | 147 | int iomap_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, |
8ff6daa1 | 148 | loff_t start, loff_t len, const struct iomap_ops *ops); |
0ed3b0d4 AG |
149 | loff_t iomap_seek_hole(struct inode *inode, loff_t offset, |
150 | const struct iomap_ops *ops); | |
151 | loff_t iomap_seek_data(struct inode *inode, loff_t offset, | |
152 | const struct iomap_ops *ops); | |
89eb1906 CH |
153 | sector_t iomap_bmap(struct address_space *mapping, sector_t bno, |
154 | const struct iomap_ops *ops); | |
ae259a9c | 155 | |
ff6a9292 CH |
156 | /* |
157 | * Flags for direct I/O ->end_io: | |
158 | */ | |
159 | #define IOMAP_DIO_UNWRITTEN (1 << 0) /* covers unwritten extent(s) */ | |
160 | #define IOMAP_DIO_COW (1 << 1) /* covers COW extent(s) */ | |
161 | typedef int (iomap_dio_end_io_t)(struct kiocb *iocb, ssize_t ret, | |
162 | unsigned flags); | |
163 | ssize_t iomap_dio_rw(struct kiocb *iocb, struct iov_iter *iter, | |
8ff6daa1 | 164 | const struct iomap_ops *ops, iomap_dio_end_io_t end_io); |
81214bab | 165 | int iomap_dio_iopoll(struct kiocb *kiocb, bool spin); |
ff6a9292 | 166 | |
67482129 DW |
167 | #ifdef CONFIG_SWAP |
168 | struct file; | |
169 | struct swap_info_struct; | |
170 | ||
171 | int iomap_swapfile_activate(struct swap_info_struct *sis, | |
172 | struct file *swap_file, sector_t *pagespan, | |
173 | const struct iomap_ops *ops); | |
174 | #else | |
175 | # define iomap_swapfile_activate(sis, swapfile, pagespan, ops) (-EIO) | |
176 | #endif /* CONFIG_SWAP */ | |
177 | ||
199a31c6 | 178 | #endif /* LINUX_IOMAP_H */ |