xref: /linux-6.15/include/linux/netfs.h (revision 31fc366a)
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 ([email protected])
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 
17 #include <linux/workqueue.h>
18 #include <linux/fs.h>
19 #include <linux/pagemap.h>
20 #include <linux/uio.h>
21 #include <linux/rolling_buffer.h>
22 
23 enum netfs_sreq_ref_trace;
24 typedef struct mempool_s mempool_t;
25 struct folio_queue;
26 
27 /**
28  * folio_start_private_2 - Start an fscache write on a folio.  [DEPRECATED]
29  * @folio: The folio.
30  *
31  * Call this function before writing a folio to a local cache.  Starting a
32  * second write before the first one finishes is not allowed.
33  *
34  * Note that this should no longer be used.
35  */
36 static inline void folio_start_private_2(struct folio *folio)
37 {
38 	VM_BUG_ON_FOLIO(folio_test_private_2(folio), folio);
39 	folio_get(folio);
40 	folio_set_private_2(folio);
41 }
42 
43 enum netfs_io_source {
44 	NETFS_SOURCE_UNKNOWN,
45 	NETFS_FILL_WITH_ZEROES,
46 	NETFS_DOWNLOAD_FROM_SERVER,
47 	NETFS_READ_FROM_CACHE,
48 	NETFS_INVALID_READ,
49 	NETFS_UPLOAD_TO_SERVER,
50 	NETFS_WRITE_TO_CACHE,
51 	NETFS_INVALID_WRITE,
52 } __mode(byte);
53 
54 typedef void (*netfs_io_terminated_t)(void *priv, ssize_t transferred_or_error,
55 				      bool was_async);
56 
57 /*
58  * Per-inode context.  This wraps the VFS inode.
59  */
60 struct netfs_inode {
61 	struct inode		inode;		/* The VFS inode */
62 	const struct netfs_request_ops *ops;
63 #if IS_ENABLED(CONFIG_FSCACHE)
64 	struct fscache_cookie	*cache;
65 #endif
66 	struct mutex		wb_lock;	/* Writeback serialisation */
67 	loff_t			remote_i_size;	/* Size of the remote file */
68 	loff_t			zero_point;	/* Size after which we assume there's no data
69 						 * on the server */
70 	atomic_t		io_count;	/* Number of outstanding reqs */
71 	unsigned long		flags;
72 #define NETFS_ICTX_ODIRECT	0		/* The file has DIO in progress */
73 #define NETFS_ICTX_UNBUFFERED	1		/* I/O should not use the pagecache */
74 #define NETFS_ICTX_WRITETHROUGH	2		/* Write-through caching */
75 #define NETFS_ICTX_MODIFIED_ATTR 3		/* Indicate change in mtime/ctime */
76 };
77 
78 /*
79  * A netfs group - for instance a ceph snap.  This is marked on dirty pages and
80  * pages marked with a group must be flushed before they can be written under
81  * the domain of another group.
82  */
83 struct netfs_group {
84 	refcount_t		ref;
85 	void (*free)(struct netfs_group *netfs_group);
86 };
87 
88 /*
89  * Information about a dirty page (attached only if necessary).
90  * folio->private
91  */
92 struct netfs_folio {
93 	struct netfs_group	*netfs_group;	/* Filesystem's grouping marker (or NULL). */
94 	unsigned int		dirty_offset;	/* Write-streaming dirty data offset */
95 	unsigned int		dirty_len;	/* Write-streaming dirty data length */
96 };
97 #define NETFS_FOLIO_INFO	0x1UL	/* OR'd with folio->private. */
98 #define NETFS_FOLIO_COPY_TO_CACHE ((struct netfs_group *)0x356UL) /* Write to the cache only */
99 
100 static inline bool netfs_is_folio_info(const void *priv)
101 {
102 	return (unsigned long)priv & NETFS_FOLIO_INFO;
103 }
104 
105 static inline struct netfs_folio *__netfs_folio_info(const void *priv)
106 {
107 	if (netfs_is_folio_info(priv))
108 		return (struct netfs_folio *)((unsigned long)priv & ~NETFS_FOLIO_INFO);
109 	return NULL;
110 }
111 
112 static inline struct netfs_folio *netfs_folio_info(struct folio *folio)
113 {
114 	return __netfs_folio_info(folio_get_private(folio));
115 }
116 
117 static inline struct netfs_group *netfs_folio_group(struct folio *folio)
118 {
119 	struct netfs_folio *finfo;
120 	void *priv = folio_get_private(folio);
121 
122 	finfo = netfs_folio_info(folio);
123 	if (finfo)
124 		return finfo->netfs_group;
125 	return priv;
126 }
127 
128 /*
129  * Stream of I/O subrequests going to a particular destination, such as the
130  * server or the local cache.  This is mainly intended for writing where we may
131  * have to write to multiple destinations concurrently.
132  */
133 struct netfs_io_stream {
134 	/* Submission tracking */
135 	struct netfs_io_subrequest *construct;	/* Op being constructed */
136 	size_t			sreq_max_len;	/* Maximum size of a subrequest */
137 	unsigned int		sreq_max_segs;	/* 0 or max number of segments in an iterator */
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_extendable_to; /* 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 
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;
164 	unsigned int			debug_id;	/* Cookie debug ID */
165 	unsigned int			inval_counter;	/* object->inval_counter at begin_op */
166 };
167 
168 /*
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.
174  */
175 struct netfs_io_subrequest {
176 	struct netfs_io_request *rreq;		/* Supervising I/O request */
177 	struct work_struct	work;
178 	struct list_head	rreq_link;	/* Link in rreq->subrequests */
179 	struct iov_iter		io_iter;	/* Iterator for this subrequest */
180 	unsigned long long	start;		/* Where to start the I/O */
181 	size_t			len;		/* Size of the I/O */
182 	size_t			transferred;	/* Amount of data transferred */
183 	size_t			consumed;	/* Amount of read data consumed */
184 	size_t			prev_donated;	/* Amount of data donated from previous subreq */
185 	size_t			next_donated;	/* Amount of data donated from next subreq */
186 	refcount_t		ref;
187 	short			error;		/* 0 or error that occurred */
188 	unsigned short		debug_index;	/* Index in list (for debugging output) */
189 	unsigned int		nr_segs;	/* Number of segs in io_iter */
190 	u8			retry_count;	/* The number of retries (0 on initial pass) */
191 	enum netfs_io_source	source;		/* Where to read from/write to */
192 	unsigned char		stream_nr;	/* I/O stream this belongs to */
193 	unsigned char		curr_folioq_slot; /* Folio currently being read */
194 	unsigned char		curr_folio_order; /* Order of folio */
195 	struct folio_queue	*curr_folioq;	/* Queue segment in which current folio resides */
196 	unsigned long		flags;
197 #define NETFS_SREQ_COPY_TO_CACHE	0	/* Set if should copy the data to the cache */
198 #define NETFS_SREQ_CLEAR_TAIL		1	/* Set if the rest of the read should be cleared */
199 #define NETFS_SREQ_SEEK_DATA_READ	3	/* Set if ->read() should SEEK_DATA first */
200 #define NETFS_SREQ_MADE_PROGRESS	4	/* Set if we transferred at least some data */
201 #define NETFS_SREQ_ONDEMAND		5	/* Set if it's from on-demand read mode */
202 #define NETFS_SREQ_BOUNDARY		6	/* Set if ends on hard boundary (eg. ceph object) */
203 #define NETFS_SREQ_HIT_EOF		7	/* Set if short due to EOF */
204 #define NETFS_SREQ_IN_PROGRESS		8	/* Unlocked when the subrequest completes */
205 #define NETFS_SREQ_NEED_RETRY		9	/* Set if the filesystem requests a retry */
206 #define NETFS_SREQ_FAILED		10	/* Set if the subreq failed unretryably */
207 };
208 
209 enum netfs_io_origin {
210 	NETFS_READAHEAD,		/* This read was triggered by readahead */
211 	NETFS_READPAGE,			/* This read is a synchronous read */
212 	NETFS_READ_GAPS,		/* This read is a synchronous read to fill gaps */
213 	NETFS_READ_FOR_WRITE,		/* This read is to prepare a write */
214 	NETFS_DIO_READ,			/* This is a direct I/O read */
215 	NETFS_WRITEBACK,		/* This write was triggered by writepages */
216 	NETFS_WRITETHROUGH,		/* This write was made by netfs_perform_write() */
217 	NETFS_UNBUFFERED_WRITE,		/* This is an unbuffered write */
218 	NETFS_DIO_WRITE,		/* This is a direct I/O write */
219 	NETFS_PGPRIV2_COPY_TO_CACHE,	/* [DEPRECATED] This is writing read data to the cache */
220 	nr__netfs_io_origin
221 } __mode(byte);
222 
223 /*
224  * Descriptor for an I/O helper request.  This is used to make multiple I/O
225  * operations to a variety of data stores and then stitch the result together.
226  */
227 struct netfs_io_request {
228 	union {
229 		struct work_struct work;
230 		struct rcu_head rcu;
231 	};
232 	struct inode		*inode;		/* The file being accessed */
233 	struct address_space	*mapping;	/* The mapping being accessed */
234 	struct kiocb		*iocb;		/* AIO completion vector */
235 	struct netfs_cache_resources cache_resources;
236 	struct readahead_control *ractl;	/* Readahead descriptor */
237 	struct list_head	proc_link;	/* Link in netfs_iorequests */
238 	struct list_head	subrequests;	/* Contributory I/O operations */
239 	struct netfs_io_stream	io_streams[2];	/* Streams of parallel I/O operations */
240 #define NR_IO_STREAMS 2 //wreq->nr_io_streams
241 	struct netfs_group	*group;		/* Writeback group being written back */
242 	struct rolling_buffer	buffer;		/* Unencrypted buffer */
243 #define NETFS_ROLLBUF_PUT_MARK		ROLLBUF_MARK_1
244 #define NETFS_ROLLBUF_PAGECACHE_MARK	ROLLBUF_MARK_2
245 	void			*netfs_priv;	/* Private data for the netfs */
246 	void			*netfs_priv2;	/* Private data for the netfs */
247 	struct bio_vec		*direct_bv;	/* DIO buffer list (when handling iovec-iter) */
248 	unsigned int		direct_bv_count; /* Number of elements in direct_bv[] */
249 	unsigned int		debug_id;
250 	unsigned int		rsize;		/* Maximum read size (0 for none) */
251 	unsigned int		wsize;		/* Maximum write size (0 for none) */
252 	atomic_t		subreq_counter;	/* Next subreq->debug_index */
253 	unsigned int		nr_group_rel;	/* Number of refs to release on ->group */
254 	spinlock_t		lock;		/* Lock for queuing subreqs */
255 	atomic_t		nr_outstanding;	/* Number of ops in progress */
256 	unsigned long long	submitted;	/* Amount submitted for I/O so far */
257 	unsigned long long	len;		/* Length of the request */
258 	size_t			transferred;	/* Amount to be indicated as transferred */
259 	long			error;		/* 0 or error that occurred */
260 	enum netfs_io_origin	origin;		/* Origin of the request */
261 	bool			direct_bv_unpin; /* T if direct_bv[] must be unpinned */
262 	unsigned long long	i_size;		/* Size of the file */
263 	unsigned long long	start;		/* Start position */
264 	atomic64_t		issued_to;	/* Write issuer folio cursor */
265 	unsigned long long	collected_to;	/* Point we've collected to */
266 	unsigned long long	cleaned_to;	/* Position we've cleaned folios to */
267 	pgoff_t			no_unlock_folio; /* Don't unlock this folio after read */
268 	size_t			prev_donated;	/* Fallback for subreq->prev_donated */
269 	refcount_t		ref;
270 	unsigned long		flags;
271 #define NETFS_RREQ_NO_UNLOCK_FOLIO	2	/* Don't unlock no_unlock_folio on completion */
272 #define NETFS_RREQ_DONT_UNLOCK_FOLIOS	3	/* Don't unlock the folios on completion */
273 #define NETFS_RREQ_FAILED		4	/* The request failed */
274 #define NETFS_RREQ_IN_PROGRESS		5	/* Unlocked when the request completes */
275 #define NETFS_RREQ_UPLOAD_TO_SERVER	8	/* Need to write to the server */
276 #define NETFS_RREQ_NONBLOCK		9	/* Don't block if possible (O_NONBLOCK) */
277 #define NETFS_RREQ_BLOCKED		10	/* We blocked */
278 #define NETFS_RREQ_PAUSE		11	/* Pause subrequest generation */
279 #define NETFS_RREQ_USE_IO_ITER		12	/* Use ->io_iter rather than ->i_pages */
280 #define NETFS_RREQ_ALL_QUEUED		13	/* All subreqs are now queued */
281 #define NETFS_RREQ_NEED_RETRY		14	/* Need to try retrying */
282 #define NETFS_RREQ_USE_PGPRIV2		31	/* [DEPRECATED] Use PG_private_2 to mark
283 						 * write to cache on read */
284 	const struct netfs_request_ops *netfs_ops;
285 	void (*cleanup)(struct netfs_io_request *req);
286 };
287 
288 /*
289  * Operations the network filesystem can/must provide to the helpers.
290  */
291 struct netfs_request_ops {
292 	mempool_t *request_pool;
293 	mempool_t *subrequest_pool;
294 	int (*init_request)(struct netfs_io_request *rreq, struct file *file);
295 	void (*free_request)(struct netfs_io_request *rreq);
296 	void (*free_subrequest)(struct netfs_io_subrequest *rreq);
297 
298 	/* Read request handling */
299 	void (*expand_readahead)(struct netfs_io_request *rreq);
300 	int (*prepare_read)(struct netfs_io_subrequest *subreq);
301 	void (*issue_read)(struct netfs_io_subrequest *subreq);
302 	bool (*is_still_valid)(struct netfs_io_request *rreq);
303 	int (*check_write_begin)(struct file *file, loff_t pos, unsigned len,
304 				 struct folio **foliop, void **_fsdata);
305 	void (*done)(struct netfs_io_request *rreq);
306 
307 	/* Modification handling */
308 	void (*update_i_size)(struct inode *inode, loff_t i_size);
309 	void (*post_modify)(struct inode *inode);
310 
311 	/* Write request handling */
312 	void (*begin_writeback)(struct netfs_io_request *wreq);
313 	void (*prepare_write)(struct netfs_io_subrequest *subreq);
314 	void (*issue_write)(struct netfs_io_subrequest *subreq);
315 	void (*retry_request)(struct netfs_io_request *wreq, struct netfs_io_stream *stream);
316 	void (*invalidate_cache)(struct netfs_io_request *wreq);
317 };
318 
319 /*
320  * How to handle reading from a hole.
321  */
322 enum netfs_read_from_hole {
323 	NETFS_READ_HOLE_IGNORE,
324 	NETFS_READ_HOLE_CLEAR,
325 	NETFS_READ_HOLE_FAIL,
326 };
327 
328 /*
329  * Table of operations for access to a cache.
330  */
331 struct netfs_cache_ops {
332 	/* End an operation */
333 	void (*end_operation)(struct netfs_cache_resources *cres);
334 
335 	/* Read data from the cache */
336 	int (*read)(struct netfs_cache_resources *cres,
337 		    loff_t start_pos,
338 		    struct iov_iter *iter,
339 		    enum netfs_read_from_hole read_hole,
340 		    netfs_io_terminated_t term_func,
341 		    void *term_func_priv);
342 
343 	/* Write data to the cache */
344 	int (*write)(struct netfs_cache_resources *cres,
345 		     loff_t start_pos,
346 		     struct iov_iter *iter,
347 		     netfs_io_terminated_t term_func,
348 		     void *term_func_priv);
349 
350 	/* Write data to the cache from a netfs subrequest. */
351 	void (*issue_write)(struct netfs_io_subrequest *subreq);
352 
353 	/* Expand readahead request */
354 	void (*expand_readahead)(struct netfs_cache_resources *cres,
355 				 unsigned long long *_start,
356 				 unsigned long long *_len,
357 				 unsigned long long i_size);
358 
359 	/* Prepare a read operation, shortening it to a cached/uncached
360 	 * boundary as appropriate.
361 	 */
362 	enum netfs_io_source (*prepare_read)(struct netfs_io_subrequest *subreq,
363 					     unsigned long long i_size);
364 
365 	/* Prepare a write subrequest, working out if we're allowed to do it
366 	 * and finding out the maximum amount of data to gather before
367 	 * attempting to submit.  If we're not permitted to do it, the
368 	 * subrequest should be marked failed.
369 	 */
370 	void (*prepare_write_subreq)(struct netfs_io_subrequest *subreq);
371 
372 	/* Prepare a write operation, working out what part of the write we can
373 	 * actually do.
374 	 */
375 	int (*prepare_write)(struct netfs_cache_resources *cres,
376 			     loff_t *_start, size_t *_len, size_t upper_len,
377 			     loff_t i_size, bool no_space_allocated_yet);
378 
379 	/* Prepare an on-demand read operation, shortening it to a cached/uncached
380 	 * boundary as appropriate.
381 	 */
382 	enum netfs_io_source (*prepare_ondemand_read)(struct netfs_cache_resources *cres,
383 						      loff_t start, size_t *_len,
384 						      loff_t i_size,
385 						      unsigned long *_flags, ino_t ino);
386 
387 	/* Query the occupancy of the cache in a region, returning where the
388 	 * next chunk of data starts and how long it is.
389 	 */
390 	int (*query_occupancy)(struct netfs_cache_resources *cres,
391 			       loff_t start, size_t len, size_t granularity,
392 			       loff_t *_data_start, size_t *_data_len);
393 };
394 
395 /* High-level read API. */
396 ssize_t netfs_unbuffered_read_iter_locked(struct kiocb *iocb, struct iov_iter *iter);
397 ssize_t netfs_unbuffered_read_iter(struct kiocb *iocb, struct iov_iter *iter);
398 ssize_t netfs_buffered_read_iter(struct kiocb *iocb, struct iov_iter *iter);
399 ssize_t netfs_file_read_iter(struct kiocb *iocb, struct iov_iter *iter);
400 
401 /* High-level write API */
402 ssize_t netfs_perform_write(struct kiocb *iocb, struct iov_iter *iter,
403 			    struct netfs_group *netfs_group);
404 ssize_t netfs_buffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *from,
405 					 struct netfs_group *netfs_group);
406 ssize_t netfs_unbuffered_write_iter(struct kiocb *iocb, struct iov_iter *from);
407 ssize_t netfs_unbuffered_write_iter_locked(struct kiocb *iocb, struct iov_iter *iter,
408 					   struct netfs_group *netfs_group);
409 ssize_t netfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from);
410 
411 /* Address operations API */
412 struct readahead_control;
413 void netfs_readahead(struct readahead_control *);
414 int netfs_read_folio(struct file *, struct folio *);
415 int netfs_write_begin(struct netfs_inode *, struct file *,
416 		      struct address_space *, loff_t pos, unsigned int len,
417 		      struct folio **, void **fsdata);
418 int netfs_writepages(struct address_space *mapping,
419 		     struct writeback_control *wbc);
420 bool netfs_dirty_folio(struct address_space *mapping, struct folio *folio);
421 int netfs_unpin_writeback(struct inode *inode, struct writeback_control *wbc);
422 void netfs_clear_inode_writeback(struct inode *inode, const void *aux);
423 void netfs_invalidate_folio(struct folio *folio, size_t offset, size_t length);
424 bool netfs_release_folio(struct folio *folio, gfp_t gfp);
425 
426 /* VMA operations API. */
427 vm_fault_t netfs_page_mkwrite(struct vm_fault *vmf, struct netfs_group *netfs_group);
428 
429 /* (Sub)request management API. */
430 void netfs_read_subreq_progress(struct netfs_io_subrequest *subreq);
431 void netfs_read_subreq_terminated(struct netfs_io_subrequest *subreq);
432 void netfs_read_subreq_termination_worker(struct work_struct *work);
433 void netfs_get_subrequest(struct netfs_io_subrequest *subreq,
434 			  enum netfs_sreq_ref_trace what);
435 void netfs_put_subrequest(struct netfs_io_subrequest *subreq,
436 			  bool was_async, enum netfs_sreq_ref_trace what);
437 ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len,
438 				struct iov_iter *new,
439 				iov_iter_extraction_t extraction_flags);
440 size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset,
441 			size_t max_size, size_t max_segs);
442 void netfs_prepare_write_failed(struct netfs_io_subrequest *subreq);
443 void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error,
444 				       bool was_async);
445 void netfs_queue_write_request(struct netfs_io_subrequest *subreq);
446 
447 int netfs_start_io_read(struct inode *inode);
448 void netfs_end_io_read(struct inode *inode);
449 int netfs_start_io_write(struct inode *inode);
450 void netfs_end_io_write(struct inode *inode);
451 int netfs_start_io_direct(struct inode *inode);
452 void netfs_end_io_direct(struct inode *inode);
453 
454 /* Miscellaneous APIs. */
455 struct folio_queue *netfs_folioq_alloc(unsigned int rreq_id, gfp_t gfp,
456 				       unsigned int trace /*enum netfs_folioq_trace*/);
457 void netfs_folioq_free(struct folio_queue *folioq,
458 		       unsigned int trace /*enum netfs_trace_folioq*/);
459 
460 /**
461  * netfs_inode - Get the netfs inode context from the inode
462  * @inode: The inode to query
463  *
464  * Get the netfs lib inode context from the network filesystem's inode.  The
465  * context struct is expected to directly follow on from the VFS inode struct.
466  */
467 static inline struct netfs_inode *netfs_inode(struct inode *inode)
468 {
469 	return container_of(inode, struct netfs_inode, inode);
470 }
471 
472 /**
473  * netfs_inode_init - Initialise a netfslib inode context
474  * @ctx: The netfs inode to initialise
475  * @ops: The netfs's operations list
476  * @use_zero_point: True to use the zero_point read optimisation
477  *
478  * Initialise the netfs library context struct.  This is expected to follow on
479  * directly from the VFS inode struct.
480  */
481 static inline void netfs_inode_init(struct netfs_inode *ctx,
482 				    const struct netfs_request_ops *ops,
483 				    bool use_zero_point)
484 {
485 	ctx->ops = ops;
486 	ctx->remote_i_size = i_size_read(&ctx->inode);
487 	ctx->zero_point = LLONG_MAX;
488 	ctx->flags = 0;
489 	atomic_set(&ctx->io_count, 0);
490 #if IS_ENABLED(CONFIG_FSCACHE)
491 	ctx->cache = NULL;
492 #endif
493 	mutex_init(&ctx->wb_lock);
494 	/* ->releasepage() drives zero_point */
495 	if (use_zero_point) {
496 		ctx->zero_point = ctx->remote_i_size;
497 		mapping_set_release_always(ctx->inode.i_mapping);
498 	}
499 }
500 
501 /**
502  * netfs_resize_file - Note that a file got resized
503  * @ctx: The netfs inode being resized
504  * @new_i_size: The new file size
505  * @changed_on_server: The change was applied to the server
506  *
507  * Inform the netfs lib that a file got resized so that it can adjust its state.
508  */
509 static inline void netfs_resize_file(struct netfs_inode *ctx, loff_t new_i_size,
510 				     bool changed_on_server)
511 {
512 	if (changed_on_server)
513 		ctx->remote_i_size = new_i_size;
514 	if (new_i_size < ctx->zero_point)
515 		ctx->zero_point = new_i_size;
516 }
517 
518 /**
519  * netfs_i_cookie - Get the cache cookie from the inode
520  * @ctx: The netfs inode to query
521  *
522  * Get the caching cookie (if enabled) from the network filesystem's inode.
523  */
524 static inline struct fscache_cookie *netfs_i_cookie(struct netfs_inode *ctx)
525 {
526 #if IS_ENABLED(CONFIG_FSCACHE)
527 	return ctx->cache;
528 #else
529 	return NULL;
530 #endif
531 }
532 
533 /**
534  * netfs_wait_for_outstanding_io - Wait for outstanding I/O to complete
535  * @inode: The netfs inode to wait on
536  *
537  * Wait for outstanding I/O requests of any type to complete.  This is intended
538  * to be called from inode eviction routines.  This makes sure that any
539  * resources held by those requests are cleaned up before we let the inode get
540  * cleaned up.
541  */
542 static inline void netfs_wait_for_outstanding_io(struct inode *inode)
543 {
544 	struct netfs_inode *ictx = netfs_inode(inode);
545 
546 	wait_var_event(&ictx->io_count, atomic_read(&ictx->io_count) == 0);
547 }
548 
549 #endif /* _LINUX_NETFS_H */
550