Commit | Line | Data |
---|---|---|
b533a83f DH |
1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
2 | /* Network filesystem support services. | |
3 | * | |
4 | * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved. | |
5 | * Written by David Howells (dhowells@redhat.com) | |
6 | * | |
7 | * See: | |
8 | * | |
9 | * Documentation/filesystems/netfs_library.rst | |
10 | * | |
11 | * for a description of the network filesystem interface declared here. | |
12 | */ | |
13 | ||
14 | #ifndef _LINUX_NETFS_H | |
15 | #define _LINUX_NETFS_H | |
16 | ||
3d3c9504 DH |
17 | #include <linux/workqueue.h> |
18 | #include <linux/fs.h> | |
b533a83f | 19 | #include <linux/pagemap.h> |
85dd2c8f | 20 | #include <linux/uio.h> |
b533a83f | 21 | |
6cd3d6fd | 22 | enum netfs_sreq_ref_trace; |
d9f85a04 | 23 | typedef struct mempool_s mempool_t; |
6cd3d6fd | 24 | |
99bff93c | 25 | /** |
2e9d7e4b | 26 | * folio_start_private_2 - Start an fscache write on a folio. [DEPRECATED] |
6abbaa5b | 27 | * @folio: The folio. |
99bff93c | 28 | * |
6abbaa5b MWO |
29 | * Call this function before writing a folio to a local cache. Starting a |
30 | * second write before the first one finishes is not allowed. | |
2e9d7e4b DH |
31 | * |
32 | * Note that this should no longer be used. | |
99bff93c | 33 | */ |
2e9d7e4b | 34 | static inline void folio_start_private_2(struct folio *folio) |
99bff93c | 35 | { |
6abbaa5b MWO |
36 | VM_BUG_ON_FOLIO(folio_test_private_2(folio), folio); |
37 | folio_get(folio); | |
38 | folio_set_private_2(folio); | |
99bff93c DH |
39 | } |
40 | ||
7d828a06 DH |
41 | /* Marks used on xarray-based buffers */ |
42 | #define NETFS_BUF_PUT_MARK XA_MARK_0 /* - Page needs putting */ | |
43 | #define NETFS_BUF_PAGECACHE_MARK XA_MARK_1 /* - Page needs wb/dirty flag wrangling */ | |
44 | ||
6a19114b | 45 | enum netfs_io_source { |
3d3c9504 DH |
46 | NETFS_FILL_WITH_ZEROES, |
47 | NETFS_DOWNLOAD_FROM_SERVER, | |
48 | NETFS_READ_FROM_CACHE, | |
49 | NETFS_INVALID_READ, | |
16af134c DH |
50 | NETFS_UPLOAD_TO_SERVER, |
51 | NETFS_WRITE_TO_CACHE, | |
52 | NETFS_INVALID_WRITE, | |
3d3c9504 DH |
53 | } __mode(byte); |
54 | ||
726218fd DH |
55 | typedef void (*netfs_io_terminated_t)(void *priv, ssize_t transferred_or_error, |
56 | bool was_async); | |
57 | ||
bc899ee1 | 58 | /* |
874c8ca1 | 59 | * Per-inode context. This wraps the VFS inode. |
bc899ee1 | 60 | */ |
874c8ca1 DH |
61 | struct netfs_inode { |
62 | struct inode inode; /* The VFS inode */ | |
bc899ee1 DH |
63 | const struct netfs_request_ops *ops; |
64 | #if IS_ENABLED(CONFIG_FSCACHE) | |
65 | struct fscache_cookie *cache; | |
66 | #endif | |
288ace2f | 67 | struct mutex wb_lock; /* Writeback serialisation */ |
4058f742 | 68 | loff_t remote_i_size; /* Size of the remote file */ |
100ccd18 DH |
69 | loff_t zero_point; /* Size after which we assume there's no data |
70 | * on the server */ | |
f89ea63f | 71 | atomic_t io_count; /* Number of outstanding reqs */ |
46ed60dc DH |
72 | unsigned long flags; |
73 | #define NETFS_ICTX_ODIRECT 0 /* The file has DIO in progress */ | |
153a9961 | 74 | #define NETFS_ICTX_UNBUFFERED 1 /* I/O should not use the pagecache */ |
41d8e767 | 75 | #define NETFS_ICTX_WRITETHROUGH 2 /* Write-through caching */ |
2ff1e975 DH |
76 | #define NETFS_ICTX_USE_PGPRIV2 31 /* [DEPRECATED] Use PG_private_2 to mark |
77 | * write to cache on read */ | |
bc899ee1 DH |
78 | }; |
79 | ||
9ebff83e DH |
80 | /* |
81 | * A netfs group - for instance a ceph snap. This is marked on dirty pages and | |
82 | * pages marked with a group must be flushed before they can be written under | |
83 | * the domain of another group. | |
84 | */ | |
85 | struct netfs_group { | |
86 | refcount_t ref; | |
87 | void (*free)(struct netfs_group *netfs_group); | |
88 | }; | |
89 | ||
90 | /* | |
91 | * Information about a dirty page (attached only if necessary). | |
92 | * folio->private | |
93 | */ | |
94 | struct netfs_folio { | |
95 | struct netfs_group *netfs_group; /* Filesystem's grouping marker (or NULL). */ | |
96 | unsigned int dirty_offset; /* Write-streaming dirty data offset */ | |
97 | unsigned int dirty_len; /* Write-streaming dirty data length */ | |
98 | }; | |
99 | #define NETFS_FOLIO_INFO 0x1UL /* OR'd with folio->private. */ | |
2ff1e975 | 100 | #define NETFS_FOLIO_COPY_TO_CACHE ((struct netfs_group *)0x356UL) /* Write to the cache only */ |
9ebff83e | 101 | |
2ff1e975 | 102 | static inline bool netfs_is_folio_info(const void *priv) |
9ebff83e | 103 | { |
2ff1e975 DH |
104 | return (unsigned long)priv & NETFS_FOLIO_INFO; |
105 | } | |
9ebff83e | 106 | |
2ff1e975 DH |
107 | static inline struct netfs_folio *__netfs_folio_info(const void *priv) |
108 | { | |
109 | if (netfs_is_folio_info(priv)) | |
9ebff83e DH |
110 | return (struct netfs_folio *)((unsigned long)priv & ~NETFS_FOLIO_INFO); |
111 | return NULL; | |
112 | } | |
113 | ||
2ff1e975 DH |
114 | static inline struct netfs_folio *netfs_folio_info(struct folio *folio) |
115 | { | |
116 | return __netfs_folio_info(folio_get_private(folio)); | |
117 | } | |
118 | ||
9ebff83e DH |
119 | static inline struct netfs_group *netfs_folio_group(struct folio *folio) |
120 | { | |
121 | struct netfs_folio *finfo; | |
122 | void *priv = folio_get_private(folio); | |
123 | ||
124 | finfo = netfs_folio_info(folio); | |
125 | if (finfo) | |
126 | return finfo->netfs_group; | |
127 | return priv; | |
128 | } | |
129 | ||
288ace2f DH |
130 | /* |
131 | * Stream of I/O subrequests going to a particular destination, such as the | |
132 | * server or the local cache. This is mainly intended for writing where we may | |
133 | * have to write to multiple destinations concurrently. | |
134 | */ | |
135 | struct netfs_io_stream { | |
136 | /* Submission tracking */ | |
137 | struct netfs_io_subrequest *construct; /* Op being constructed */ | |
138 | unsigned int submit_off; /* Folio offset we're submitting from */ | |
139 | unsigned int submit_len; /* Amount of data left to submit */ | |
140 | unsigned int submit_max_len; /* Amount I/O can be rounded up to */ | |
141 | void (*prepare_write)(struct netfs_io_subrequest *subreq); | |
142 | void (*issue_write)(struct netfs_io_subrequest *subreq); | |
143 | /* Collection tracking */ | |
144 | struct list_head subrequests; /* Contributory I/O operations */ | |
145 | struct netfs_io_subrequest *front; /* Op being collected */ | |
146 | unsigned long long collected_to; /* Position we've collected results to */ | |
147 | size_t transferred; /* The amount transferred from this stream */ | |
148 | enum netfs_io_source source; /* Where to read from/write to */ | |
149 | unsigned short error; /* Aggregate error for the stream */ | |
150 | unsigned char stream_nr; /* Index of stream in parent table */ | |
151 | bool avail; /* T if stream is available */ | |
152 | bool active; /* T if stream is active */ | |
153 | bool need_retry; /* T if this stream needs retrying */ | |
154 | bool failed; /* T if this stream failed */ | |
155 | }; | |
156 | ||
726218fd DH |
157 | /* |
158 | * Resources required to do operations on a cache. | |
159 | */ | |
160 | struct netfs_cache_resources { | |
161 | const struct netfs_cache_ops *ops; | |
162 | void *cache_priv; | |
163 | void *cache_priv2; | |
a7e20e31 | 164 | unsigned int debug_id; /* Cookie debug ID */ |
d24af13e | 165 | unsigned int inval_counter; /* object->inval_counter at begin_op */ |
726218fd DH |
166 | }; |
167 | ||
3d3c9504 | 168 | /* |
16af134c DH |
169 | * Descriptor for a single component subrequest. Each operation represents an |
170 | * individual read/write from/to a server, a cache, a journal, etc.. | |
171 | * | |
172 | * The buffer iterator is persistent for the life of the subrequest struct and | |
173 | * the pages it points to can be relied on to exist for the duration. | |
3d3c9504 | 174 | */ |
6a19114b | 175 | struct netfs_io_subrequest { |
f18a3785 | 176 | struct netfs_io_request *rreq; /* Supervising I/O request */ |
040a82be | 177 | struct work_struct work; |
3d3c9504 | 178 | struct list_head rreq_link; /* Link in rreq->subrequests */ |
92b6cc5d | 179 | struct iov_iter io_iter; /* Iterator for this subrequest */ |
7ba167c4 | 180 | unsigned long long start; /* Where to start the I/O */ |
288ace2f | 181 | size_t max_len; /* Maximum size of the I/O */ |
3d3c9504 DH |
182 | size_t len; /* Size of the I/O */ |
183 | size_t transferred; /* Amount of data transferred */ | |
6cd3d6fd | 184 | refcount_t ref; |
3d3c9504 DH |
185 | short error; /* 0 or error that occurred */ |
186 | unsigned short debug_index; /* Index in list (for debugging output) */ | |
288ace2f | 187 | unsigned int nr_segs; /* Number of segs in io_iter */ |
768ddb1e | 188 | unsigned int max_nr_segs; /* 0 or max number of segments in an iterator */ |
f18a3785 | 189 | enum netfs_io_source source; /* Where to read from/write to */ |
288ace2f | 190 | unsigned char stream_nr; /* I/O stream this belongs to */ |
3d3c9504 | 191 | unsigned long flags; |
f18a3785 | 192 | #define NETFS_SREQ_COPY_TO_CACHE 0 /* Set if should copy the data to the cache */ |
3d3c9504 | 193 | #define NETFS_SREQ_CLEAR_TAIL 1 /* Set if the rest of the read should be cleared */ |
f18a3785 | 194 | #define NETFS_SREQ_SHORT_IO 2 /* Set if the I/O was short */ |
3d3c9504 DH |
195 | #define NETFS_SREQ_SEEK_DATA_READ 3 /* Set if ->read() should SEEK_DATA first */ |
196 | #define NETFS_SREQ_NO_PROGRESS 4 /* Set if we didn't manage to read any data */ | |
9032b6e8 | 197 | #define NETFS_SREQ_ONDEMAND 5 /* Set if it's from on-demand read mode */ |
288ace2f DH |
198 | #define NETFS_SREQ_BOUNDARY 6 /* Set if ends on hard boundary (eg. ceph object) */ |
199 | #define NETFS_SREQ_IN_PROGRESS 8 /* Unlocked when the subrequest completes */ | |
200 | #define NETFS_SREQ_NEED_RETRY 9 /* Set if the filesystem requests a retry */ | |
201 | #define NETFS_SREQ_RETRYING 10 /* Set if we're retrying */ | |
202 | #define NETFS_SREQ_FAILED 11 /* Set if the subreq failed unretryably */ | |
3d3c9504 DH |
203 | }; |
204 | ||
663dfb65 DH |
205 | enum netfs_io_origin { |
206 | NETFS_READAHEAD, /* This read was triggered by readahead */ | |
207 | NETFS_READPAGE, /* This read is a synchronous read */ | |
208 | NETFS_READ_FOR_WRITE, /* This read is to prepare a write */ | |
2ff1e975 | 209 | NETFS_COPY_TO_CACHE, /* This write is to copy a read to the cache */ |
16af134c | 210 | NETFS_WRITEBACK, /* This write was triggered by writepages */ |
41d8e767 | 211 | NETFS_WRITETHROUGH, /* This write was made by netfs_perform_write() */ |
153a9961 | 212 | NETFS_UNBUFFERED_WRITE, /* This is an unbuffered write */ |
016dc851 | 213 | NETFS_DIO_READ, /* This is a direct I/O read */ |
153a9961 | 214 | NETFS_DIO_WRITE, /* This is a direct I/O write */ |
16af134c | 215 | nr__netfs_io_origin |
663dfb65 DH |
216 | } __mode(byte); |
217 | ||
3d3c9504 | 218 | /* |
f18a3785 DH |
219 | * Descriptor for an I/O helper request. This is used to make multiple I/O |
220 | * operations to a variety of data stores and then stitch the result together. | |
3d3c9504 | 221 | */ |
6a19114b | 222 | struct netfs_io_request { |
87b57a04 DH |
223 | union { |
224 | struct work_struct work; | |
225 | struct rcu_head rcu; | |
226 | }; | |
3d3c9504 DH |
227 | struct inode *inode; /* The file being accessed */ |
228 | struct address_space *mapping; /* The mapping being accessed */ | |
016dc851 | 229 | struct kiocb *iocb; /* AIO completion vector */ |
726218fd | 230 | struct netfs_cache_resources cache_resources; |
87b57a04 | 231 | struct list_head proc_link; /* Link in netfs_iorequests */ |
f18a3785 | 232 | struct list_head subrequests; /* Contributory I/O operations */ |
288ace2f DH |
233 | struct netfs_io_stream io_streams[2]; /* Streams of parallel I/O operations */ |
234 | #define NR_IO_STREAMS 2 //wreq->nr_io_streams | |
235 | struct netfs_group *group; /* Writeback group being written back */ | |
92b6cc5d DH |
236 | struct iov_iter iter; /* Unencrypted-side iterator */ |
237 | struct iov_iter io_iter; /* I/O (Encrypted-side) iterator */ | |
3d3c9504 | 238 | void *netfs_priv; /* Private data for the netfs */ |
1ecb146f | 239 | void *netfs_priv2; /* Private data for the netfs */ |
21d706d5 DH |
240 | struct bio_vec *direct_bv; /* DIO buffer list (when handling iovec-iter) */ |
241 | unsigned int direct_bv_count; /* Number of elements in direct_bv[] */ | |
3d3c9504 | 242 | unsigned int debug_id; |
016dc851 | 243 | unsigned int rsize; /* Maximum read size (0 for none) */ |
0e0f2dfe | 244 | unsigned int wsize; /* Maximum write size (0 for none) */ |
93bf1cc0 | 245 | atomic_t subreq_counter; /* Next subreq->debug_index */ |
288ace2f DH |
246 | unsigned int nr_group_rel; /* Number of refs to release on ->group */ |
247 | spinlock_t lock; /* Lock for queuing subreqs */ | |
f18a3785 DH |
248 | atomic_t nr_outstanding; /* Number of ops in progress */ |
249 | atomic_t nr_copy_ops; /* Number of copy-to-cache ops in progress */ | |
e0ace6ca | 250 | size_t upper_len; /* Length can be extended to here */ |
7ba167c4 DH |
251 | unsigned long long submitted; /* Amount submitted for I/O so far */ |
252 | unsigned long long len; /* Length of the request */ | |
016dc851 | 253 | size_t transferred; /* Amount to be indicated as transferred */ |
3d3c9504 | 254 | short error; /* 0 or error that occurred */ |
663dfb65 | 255 | enum netfs_io_origin origin; /* Origin of the request */ |
21d706d5 | 256 | bool direct_bv_unpin; /* T if direct_bv[] must be unpinned */ |
7ba167c4 DH |
257 | unsigned long long i_size; /* Size of the file */ |
258 | unsigned long long start; /* Start position */ | |
288ace2f DH |
259 | atomic64_t issued_to; /* Write issuer folio cursor */ |
260 | unsigned long long contiguity; /* Tracking for gaps in the writeback sequence */ | |
261 | unsigned long long collected_to; /* Point we've collected to */ | |
262 | unsigned long long cleaned_to; /* Position we've cleaned folios to */ | |
78525c74 | 263 | pgoff_t no_unlock_folio; /* Don't unlock this folio after read */ |
de74023b | 264 | refcount_t ref; |
3d3c9504 DH |
265 | unsigned long flags; |
266 | #define NETFS_RREQ_INCOMPLETE_IO 0 /* Some ioreqs terminated short or with error */ | |
f18a3785 | 267 | #define NETFS_RREQ_COPY_TO_CACHE 1 /* Need to write to the cache */ |
78525c74 DH |
268 | #define NETFS_RREQ_NO_UNLOCK_FOLIO 2 /* Don't unlock no_unlock_folio on completion */ |
269 | #define NETFS_RREQ_DONT_UNLOCK_FOLIOS 3 /* Don't unlock the folios on completion */ | |
3d3c9504 DH |
270 | #define NETFS_RREQ_FAILED 4 /* The request failed */ |
271 | #define NETFS_RREQ_IN_PROGRESS 5 /* Unlocked when the request completes */ | |
16af134c DH |
272 | #define NETFS_RREQ_WRITE_TO_CACHE 7 /* Need to write to the cache */ |
273 | #define NETFS_RREQ_UPLOAD_TO_SERVER 8 /* Need to write to the server */ | |
016dc851 DH |
274 | #define NETFS_RREQ_NONBLOCK 9 /* Don't block if possible (O_NONBLOCK) */ |
275 | #define NETFS_RREQ_BLOCKED 10 /* We blocked */ | |
288ace2f DH |
276 | #define NETFS_RREQ_PAUSE 11 /* Pause subrequest generation */ |
277 | #define NETFS_RREQ_USE_IO_ITER 12 /* Use ->io_iter rather than ->i_pages */ | |
278 | #define NETFS_RREQ_ALL_QUEUED 13 /* All subreqs are now queued */ | |
2ff1e975 DH |
279 | #define NETFS_RREQ_USE_PGPRIV2 31 /* [DEPRECATED] Use PG_private_2 to mark |
280 | * write to cache on read */ | |
6a19114b | 281 | const struct netfs_request_ops *netfs_ops; |
0e0f2dfe | 282 | void (*cleanup)(struct netfs_io_request *req); |
3d3c9504 DH |
283 | }; |
284 | ||
285 | /* | |
286 | * Operations the network filesystem can/must provide to the helpers. | |
287 | */ | |
6a19114b | 288 | struct netfs_request_ops { |
d9f85a04 DH |
289 | mempool_t *request_pool; |
290 | mempool_t *subrequest_pool; | |
2de16041 | 291 | int (*init_request)(struct netfs_io_request *rreq, struct file *file); |
40a81101 | 292 | void (*free_request)(struct netfs_io_request *rreq); |
5f5ce7ba | 293 | void (*free_subrequest)(struct netfs_io_subrequest *rreq); |
40a81101 | 294 | |
c6dc54dd | 295 | /* Read request handling */ |
6a19114b DH |
296 | void (*expand_readahead)(struct netfs_io_request *rreq); |
297 | bool (*clamp_length)(struct netfs_io_subrequest *subreq); | |
f18a3785 | 298 | void (*issue_read)(struct netfs_io_subrequest *subreq); |
6a19114b | 299 | bool (*is_still_valid)(struct netfs_io_request *rreq); |
e1b1240c | 300 | int (*check_write_begin)(struct file *file, loff_t pos, unsigned len, |
fac47b43 | 301 | struct folio **foliop, void **_fsdata); |
6a19114b | 302 | void (*done)(struct netfs_io_request *rreq); |
c6dc54dd DH |
303 | |
304 | /* Modification handling */ | |
305 | void (*update_i_size)(struct inode *inode, loff_t i_size); | |
69c3c023 | 306 | void (*post_modify)(struct inode *inode); |
0e0f2dfe DH |
307 | |
308 | /* Write request handling */ | |
288ace2f DH |
309 | void (*begin_writeback)(struct netfs_io_request *wreq); |
310 | void (*prepare_write)(struct netfs_io_subrequest *subreq); | |
311 | void (*issue_write)(struct netfs_io_subrequest *subreq); | |
1ecb146f | 312 | void (*retry_request)(struct netfs_io_request *wreq, struct netfs_io_stream *stream); |
0e0f2dfe | 313 | void (*invalidate_cache)(struct netfs_io_request *wreq); |
3d3c9504 DH |
314 | }; |
315 | ||
3a11b3a8 DH |
316 | /* |
317 | * How to handle reading from a hole. | |
318 | */ | |
319 | enum netfs_read_from_hole { | |
320 | NETFS_READ_HOLE_IGNORE, | |
321 | NETFS_READ_HOLE_CLEAR, | |
322 | NETFS_READ_HOLE_FAIL, | |
323 | }; | |
324 | ||
726218fd | 325 | /* |
4498a8ec | 326 | * Table of operations for access to a cache. |
726218fd DH |
327 | */ |
328 | struct netfs_cache_ops { | |
329 | /* End an operation */ | |
330 | void (*end_operation)(struct netfs_cache_resources *cres); | |
331 | ||
332 | /* Read data from the cache */ | |
333 | int (*read)(struct netfs_cache_resources *cres, | |
334 | loff_t start_pos, | |
335 | struct iov_iter *iter, | |
3a11b3a8 | 336 | enum netfs_read_from_hole read_hole, |
726218fd DH |
337 | netfs_io_terminated_t term_func, |
338 | void *term_func_priv); | |
339 | ||
340 | /* Write data to the cache */ | |
341 | int (*write)(struct netfs_cache_resources *cres, | |
342 | loff_t start_pos, | |
343 | struct iov_iter *iter, | |
344 | netfs_io_terminated_t term_func, | |
345 | void *term_func_priv); | |
346 | ||
288ace2f DH |
347 | /* Write data to the cache from a netfs subrequest. */ |
348 | void (*issue_write)(struct netfs_io_subrequest *subreq); | |
349 | ||
726218fd DH |
350 | /* Expand readahead request */ |
351 | void (*expand_readahead)(struct netfs_cache_resources *cres, | |
7ba167c4 DH |
352 | unsigned long long *_start, |
353 | unsigned long long *_len, | |
354 | unsigned long long i_size); | |
726218fd DH |
355 | |
356 | /* Prepare a read operation, shortening it to a cached/uncached | |
357 | * boundary as appropriate. | |
358 | */ | |
6a19114b | 359 | enum netfs_io_source (*prepare_read)(struct netfs_io_subrequest *subreq, |
7ba167c4 | 360 | unsigned long long i_size); |
726218fd | 361 | |
288ace2f DH |
362 | /* Prepare a write subrequest, working out if we're allowed to do it |
363 | * and finding out the maximum amount of data to gather before | |
364 | * attempting to submit. If we're not permitted to do it, the | |
365 | * subrequest should be marked failed. | |
366 | */ | |
367 | void (*prepare_write_subreq)(struct netfs_io_subrequest *subreq); | |
368 | ||
726218fd DH |
369 | /* Prepare a write operation, working out what part of the write we can |
370 | * actually do. | |
371 | */ | |
372 | int (*prepare_write)(struct netfs_cache_resources *cres, | |
e0ace6ca DH |
373 | loff_t *_start, size_t *_len, size_t upper_len, |
374 | loff_t i_size, bool no_space_allocated_yet); | |
bee9f655 | 375 | |
86692475 JX |
376 | /* Prepare an on-demand read operation, shortening it to a cached/uncached |
377 | * boundary as appropriate. | |
378 | */ | |
379 | enum netfs_io_source (*prepare_ondemand_read)(struct netfs_cache_resources *cres, | |
380 | loff_t start, size_t *_len, | |
381 | loff_t i_size, | |
382 | unsigned long *_flags, ino_t ino); | |
383 | ||
bee9f655 DH |
384 | /* Query the occupancy of the cache in a region, returning where the |
385 | * next chunk of data starts and how long it is. | |
386 | */ | |
387 | int (*query_occupancy)(struct netfs_cache_resources *cres, | |
388 | loff_t start, size_t len, size_t granularity, | |
389 | loff_t *_data_start, size_t *_data_len); | |
726218fd DH |
390 | }; |
391 | ||
016dc851 | 392 | /* High-level read API. */ |
14b1cd25 | 393 | ssize_t netfs_unbuffered_read_iter_locked(struct kiocb *iocb, struct iov_iter *iter); |
016dc851 | 394 | ssize_t netfs_unbuffered_read_iter(struct kiocb *iocb, struct iov_iter *iter); |
80645bd4 DH |
395 | ssize_t netfs_buffered_read_iter(struct kiocb *iocb, struct iov_iter *iter); |
396 | ssize_t netfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter); | |
016dc851 | 397 | |
c38f4e96 DH |
398 | /* High-level write API */ |
399 | ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter, | |
400 | struct netfs_group *netfs_group); | |
938e13a7 DH |
401 | ssize_t netfs_buffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *from, |
402 | struct netfs_group *netfs_group); | |
153a9961 | 403 | ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from); |
16e00683 SF |
404 | ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter, |
405 | struct netfs_group *netfs_group); | |
938e13a7 | 406 | ssize_t netfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from); |
c38f4e96 DH |
407 | |
408 | /* Address operations API */ | |
3d3c9504 | 409 | struct readahead_control; |
0e8e08cc | 410 | void netfs_readahead(struct readahead_control *); |
6c62371b | 411 | int netfs_read_folio(struct file *, struct folio *); |
0e8e08cc | 412 | int netfs_write_begin(struct netfs_inode *, struct file *, |
c1ec4d7c DH |
413 | struct address_space *, loff_t pos, unsigned int len, |
414 | struct folio **, void **fsdata); | |
62c3b748 DH |
415 | int netfs_writepages(struct address_space *mapping, |
416 | struct writeback_control *wbc); | |
c9c4ff12 DH |
417 | bool netfs_dirty_folio(struct address_space *mapping, struct folio *folio); |
418 | int netfs_unpin_writeback(struct inode *inode, struct writeback_control *wbc); | |
419 | void netfs_clear_inode_writeback(struct inode *inode, const void *aux); | |
c1ec4d7c DH |
420 | void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t length); |
421 | bool netfs_release_folio(struct folio *folio, gfp_t gfp); | |
0e8e08cc | 422 | |
102a7e2c DH |
423 | /* VMA operations API. */ |
424 | vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group); | |
425 | ||
426 | /* (Sub)request management API. */ | |
0e8e08cc MWO |
427 | void netfs_subreq_terminated(struct netfs_io_subrequest *, ssize_t, bool); |
428 | void netfs_get_subrequest(struct netfs_io_subrequest *subreq, | |
429 | enum netfs_sreq_ref_trace what); | |
430 | void netfs_put_subrequest(struct netfs_io_subrequest *subreq, | |
431 | bool was_async, enum netfs_sreq_ref_trace what); | |
85dd2c8f DH |
432 | ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len, |
433 | struct iov_iter *new, | |
434 | iov_iter_extraction_t extraction_flags); | |
cae932d3 DH |
435 | size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset, |
436 | size_t max_size, size_t max_segs); | |
288ace2f | 437 | void netfs_prepare_write_failed(struct netfs_io_subrequest *subreq); |
0e0f2dfe DH |
438 | void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error, |
439 | bool was_async); | |
440 | void netfs_queue_write_request(struct netfs_io_subrequest *subreq); | |
3d3c9504 | 441 | |
46ed60dc DH |
442 | int netfs_start_io_read(struct inode *inode); |
443 | void netfs_end_io_read(struct inode *inode); | |
444 | int netfs_start_io_write(struct inode *inode); | |
445 | void netfs_end_io_write(struct inode *inode); | |
446 | int netfs_start_io_direct(struct inode *inode); | |
447 | void netfs_end_io_direct(struct inode *inode); | |
448 | ||
bc899ee1 | 449 | /** |
874c8ca1 | 450 | * netfs_inode - Get the netfs inode context from the inode |
bc899ee1 DH |
451 | * @inode: The inode to query |
452 | * | |
453 | * Get the netfs lib inode context from the network filesystem's inode. The | |
454 | * context struct is expected to directly follow on from the VFS inode struct. | |
455 | */ | |
874c8ca1 | 456 | static inline struct netfs_inode *netfs_inode(struct inode *inode) |
bc899ee1 | 457 | { |
874c8ca1 | 458 | return container_of(inode, struct netfs_inode, inode); |
bc899ee1 DH |
459 | } |
460 | ||
461 | /** | |
874c8ca1 | 462 | * netfs_inode_init - Initialise a netfslib inode context |
018ab4fa | 463 | * @ctx: The netfs inode to initialise |
bc899ee1 | 464 | * @ops: The netfs's operations list |
100ccd18 | 465 | * @use_zero_point: True to use the zero_point read optimisation |
bc899ee1 DH |
466 | * |
467 | * Initialise the netfs library context struct. This is expected to follow on | |
468 | * directly from the VFS inode struct. | |
469 | */ | |
e81fb419 | 470 | static inline void netfs_inode_init(struct netfs_inode *ctx, |
100ccd18 DH |
471 | const struct netfs_request_ops *ops, |
472 | bool use_zero_point) | |
bc899ee1 | 473 | { |
bc899ee1 | 474 | ctx->ops = ops; |
e81fb419 | 475 | ctx->remote_i_size = i_size_read(&ctx->inode); |
100ccd18 | 476 | ctx->zero_point = LLONG_MAX; |
46ed60dc | 477 | ctx->flags = 0; |
f89ea63f | 478 | atomic_set(&ctx->io_count, 0); |
874c8ca1 DH |
479 | #if IS_ENABLED(CONFIG_FSCACHE) |
480 | ctx->cache = NULL; | |
481 | #endif | |
288ace2f | 482 | mutex_init(&ctx->wb_lock); |
100ccd18 DH |
483 | /* ->releasepage() drives zero_point */ |
484 | if (use_zero_point) { | |
485 | ctx->zero_point = ctx->remote_i_size; | |
486 | mapping_set_release_always(ctx->inode.i_mapping); | |
487 | } | |
4058f742 DH |
488 | } |
489 | ||
490 | /** | |
491 | * netfs_resize_file - Note that a file got resized | |
e81fb419 | 492 | * @ctx: The netfs inode being resized |
4058f742 | 493 | * @new_i_size: The new file size |
100ccd18 | 494 | * @changed_on_server: The change was applied to the server |
4058f742 DH |
495 | * |
496 | * Inform the netfs lib that a file got resized so that it can adjust its state. | |
497 | */ | |
100ccd18 DH |
498 | static inline void netfs_resize_file(struct netfs_inode *ctx, loff_t new_i_size, |
499 | bool changed_on_server) | |
4058f742 | 500 | { |
100ccd18 DH |
501 | if (changed_on_server) |
502 | ctx->remote_i_size = new_i_size; | |
503 | if (new_i_size < ctx->zero_point) | |
504 | ctx->zero_point = new_i_size; | |
bc899ee1 DH |
505 | } |
506 | ||
507 | /** | |
508 | * netfs_i_cookie - Get the cache cookie from the inode | |
e81fb419 | 509 | * @ctx: The netfs inode to query |
bc899ee1 DH |
510 | * |
511 | * Get the caching cookie (if enabled) from the network filesystem's inode. | |
512 | */ | |
e81fb419 | 513 | static inline struct fscache_cookie *netfs_i_cookie(struct netfs_inode *ctx) |
bc899ee1 DH |
514 | { |
515 | #if IS_ENABLED(CONFIG_FSCACHE) | |
bc899ee1 DH |
516 | return ctx->cache; |
517 | #else | |
518 | return NULL; | |
519 | #endif | |
520 | } | |
521 | ||
f89ea63f DH |
522 | /** |
523 | * netfs_wait_for_outstanding_io - Wait for outstanding I/O to complete | |
524 | * @ctx: The netfs inode to wait on | |
525 | * | |
526 | * Wait for outstanding I/O requests of any type to complete. This is intended | |
527 | * to be called from inode eviction routines. This makes sure that any | |
528 | * resources held by those requests are cleaned up before we let the inode get | |
529 | * cleaned up. | |
530 | */ | |
531 | static inline void netfs_wait_for_outstanding_io(struct inode *inode) | |
532 | { | |
533 | struct netfs_inode *ictx = netfs_inode(inode); | |
534 | ||
535 | wait_var_event(&ictx->io_count, atomic_read(&ictx->io_count) == 0); | |
536 | } | |
537 | ||
b533a83f | 538 | #endif /* _LINUX_NETFS_H */ |