xref: /openbmc/linux/include/linux/netfs.h (revision f5f82cd1)
1b533a83fSDavid Howells /* SPDX-License-Identifier: GPL-2.0-or-later */
2b533a83fSDavid Howells /* Network filesystem support services.
3b533a83fSDavid Howells  *
4b533a83fSDavid Howells  * Copyright (C) 2021 Red Hat, Inc. All Rights Reserved.
5b533a83fSDavid Howells  * Written by David Howells (dhowells@redhat.com)
6b533a83fSDavid Howells  *
7b533a83fSDavid Howells  * See:
8b533a83fSDavid Howells  *
9b533a83fSDavid Howells  *	Documentation/filesystems/netfs_library.rst
10b533a83fSDavid Howells  *
11b533a83fSDavid Howells  * for a description of the network filesystem interface declared here.
12b533a83fSDavid Howells  */
13b533a83fSDavid Howells 
14b533a83fSDavid Howells #ifndef _LINUX_NETFS_H
15b533a83fSDavid Howells #define _LINUX_NETFS_H
16b533a83fSDavid Howells 
173d3c9504SDavid Howells #include <linux/workqueue.h>
183d3c9504SDavid Howells #include <linux/fs.h>
19b533a83fSDavid Howells #include <linux/pagemap.h>
20*85dd2c8fSDavid Howells #include <linux/uio.h>
21b533a83fSDavid Howells 
226cd3d6fdSDavid Howells enum netfs_sreq_ref_trace;
236cd3d6fdSDavid Howells 
24b533a83fSDavid Howells /*
25b533a83fSDavid Howells  * Overload PG_private_2 to give us PG_fscache - this is used to indicate that
26b533a83fSDavid Howells  * a page is currently backed by a local disk cache
27b533a83fSDavid Howells  */
286abbaa5bSMatthew Wilcox (Oracle) #define folio_test_fscache(folio)	folio_test_private_2(folio)
29b533a83fSDavid Howells #define PageFsCache(page)		PagePrivate2((page))
30b533a83fSDavid Howells #define SetPageFsCache(page)		SetPagePrivate2((page))
31b533a83fSDavid Howells #define ClearPageFsCache(page)		ClearPagePrivate2((page))
32b533a83fSDavid Howells #define TestSetPageFsCache(page)	TestSetPagePrivate2((page))
33b533a83fSDavid Howells #define TestClearPageFsCache(page)	TestClearPagePrivate2((page))
34b533a83fSDavid Howells 
3599bff93cSDavid Howells /**
366abbaa5bSMatthew Wilcox (Oracle)  * folio_start_fscache - Start an fscache write on a folio.
376abbaa5bSMatthew Wilcox (Oracle)  * @folio: The folio.
3899bff93cSDavid Howells  *
396abbaa5bSMatthew Wilcox (Oracle)  * Call this function before writing a folio to a local cache.  Starting a
406abbaa5bSMatthew Wilcox (Oracle)  * second write before the first one finishes is not allowed.
4199bff93cSDavid Howells  */
folio_start_fscache(struct folio * folio)426abbaa5bSMatthew Wilcox (Oracle) static inline void folio_start_fscache(struct folio *folio)
4399bff93cSDavid Howells {
446abbaa5bSMatthew Wilcox (Oracle) 	VM_BUG_ON_FOLIO(folio_test_private_2(folio), folio);
456abbaa5bSMatthew Wilcox (Oracle) 	folio_get(folio);
466abbaa5bSMatthew Wilcox (Oracle) 	folio_set_private_2(folio);
4799bff93cSDavid Howells }
4899bff93cSDavid Howells 
4999bff93cSDavid Howells /**
506abbaa5bSMatthew Wilcox (Oracle)  * folio_end_fscache - End an fscache write on a folio.
516abbaa5bSMatthew Wilcox (Oracle)  * @folio: The folio.
5299bff93cSDavid Howells  *
536abbaa5bSMatthew Wilcox (Oracle)  * Call this function after the folio has been written to the local cache.
546abbaa5bSMatthew Wilcox (Oracle)  * This will wake any sleepers waiting on this folio.
5599bff93cSDavid Howells  */
folio_end_fscache(struct folio * folio)566abbaa5bSMatthew Wilcox (Oracle) static inline void folio_end_fscache(struct folio *folio)
5799bff93cSDavid Howells {
586abbaa5bSMatthew Wilcox (Oracle) 	folio_end_private_2(folio);
5999bff93cSDavid Howells }
6099bff93cSDavid Howells 
6199bff93cSDavid Howells /**
626abbaa5bSMatthew Wilcox (Oracle)  * folio_wait_fscache - Wait for an fscache write on this folio to end.
636abbaa5bSMatthew Wilcox (Oracle)  * @folio: The folio.
6499bff93cSDavid Howells  *
656abbaa5bSMatthew Wilcox (Oracle)  * If this folio is currently being written to a local cache, wait for
666abbaa5bSMatthew Wilcox (Oracle)  * the write to finish.  Another write may start after this one finishes,
676abbaa5bSMatthew Wilcox (Oracle)  * unless the caller holds the folio lock.
6899bff93cSDavid Howells  */
folio_wait_fscache(struct folio * folio)696abbaa5bSMatthew Wilcox (Oracle) static inline void folio_wait_fscache(struct folio *folio)
7099bff93cSDavid Howells {
716abbaa5bSMatthew Wilcox (Oracle) 	folio_wait_private_2(folio);
7299bff93cSDavid Howells }
7399bff93cSDavid Howells 
7499bff93cSDavid Howells /**
756abbaa5bSMatthew Wilcox (Oracle)  * folio_wait_fscache_killable - Wait for an fscache write on this folio to end.
766abbaa5bSMatthew Wilcox (Oracle)  * @folio: The folio.
7799bff93cSDavid Howells  *
786abbaa5bSMatthew Wilcox (Oracle)  * If this folio is currently being written to a local cache, wait
796abbaa5bSMatthew Wilcox (Oracle)  * for the write to finish or for a fatal signal to be received.
806abbaa5bSMatthew Wilcox (Oracle)  * Another write may start after this one finishes, unless the caller
816abbaa5bSMatthew Wilcox (Oracle)  * holds the folio lock.
8299bff93cSDavid Howells  *
8399bff93cSDavid Howells  * Return:
8499bff93cSDavid Howells  * - 0 if successful.
8599bff93cSDavid Howells  * - -EINTR if a fatal signal was encountered.
8699bff93cSDavid Howells  */
folio_wait_fscache_killable(struct folio * folio)876abbaa5bSMatthew Wilcox (Oracle) static inline int folio_wait_fscache_killable(struct folio *folio)
886abbaa5bSMatthew Wilcox (Oracle) {
896abbaa5bSMatthew Wilcox (Oracle) 	return folio_wait_private_2_killable(folio);
906abbaa5bSMatthew Wilcox (Oracle) }
916abbaa5bSMatthew Wilcox (Oracle) 
set_page_fscache(struct page * page)926abbaa5bSMatthew Wilcox (Oracle) static inline void set_page_fscache(struct page *page)
936abbaa5bSMatthew Wilcox (Oracle) {
946abbaa5bSMatthew Wilcox (Oracle) 	folio_start_fscache(page_folio(page));
956abbaa5bSMatthew Wilcox (Oracle) }
966abbaa5bSMatthew Wilcox (Oracle) 
end_page_fscache(struct page * page)976abbaa5bSMatthew Wilcox (Oracle) static inline void end_page_fscache(struct page *page)
986abbaa5bSMatthew Wilcox (Oracle) {
996abbaa5bSMatthew Wilcox (Oracle) 	folio_end_private_2(page_folio(page));
1006abbaa5bSMatthew Wilcox (Oracle) }
1016abbaa5bSMatthew Wilcox (Oracle) 
wait_on_page_fscache(struct page * page)1026abbaa5bSMatthew Wilcox (Oracle) static inline void wait_on_page_fscache(struct page *page)
1036abbaa5bSMatthew Wilcox (Oracle) {
1046abbaa5bSMatthew Wilcox (Oracle) 	folio_wait_private_2(page_folio(page));
1056abbaa5bSMatthew Wilcox (Oracle) }
1066abbaa5bSMatthew Wilcox (Oracle) 
wait_on_page_fscache_killable(struct page * page)10799bff93cSDavid Howells static inline int wait_on_page_fscache_killable(struct page *page)
10899bff93cSDavid Howells {
109b47393f8SMatthew Wilcox (Oracle) 	return folio_wait_private_2_killable(page_folio(page));
11099bff93cSDavid Howells }
11199bff93cSDavid Howells 
1126a19114bSDavid Howells enum netfs_io_source {
1133d3c9504SDavid Howells 	NETFS_FILL_WITH_ZEROES,
1143d3c9504SDavid Howells 	NETFS_DOWNLOAD_FROM_SERVER,
1153d3c9504SDavid Howells 	NETFS_READ_FROM_CACHE,
1163d3c9504SDavid Howells 	NETFS_INVALID_READ,
1173d3c9504SDavid Howells } __mode(byte);
1183d3c9504SDavid Howells 
119726218fdSDavid Howells typedef void (*netfs_io_terminated_t)(void *priv, ssize_t transferred_or_error,
120726218fdSDavid Howells 				      bool was_async);
121726218fdSDavid Howells 
122726218fdSDavid Howells /*
123874c8ca1SDavid Howells  * Per-inode context.  This wraps the VFS inode.
124bc899ee1SDavid Howells  */
125874c8ca1SDavid Howells struct netfs_inode {
126874c8ca1SDavid Howells 	struct inode		inode;		/* The VFS inode */
127bc899ee1SDavid Howells 	const struct netfs_request_ops *ops;
128bc899ee1SDavid Howells #if IS_ENABLED(CONFIG_FSCACHE)
129bc899ee1SDavid Howells 	struct fscache_cookie	*cache;
130bc899ee1SDavid Howells #endif
1314058f742SDavid Howells 	loff_t			remote_i_size;	/* Size of the remote file */
132bc899ee1SDavid Howells };
133bc899ee1SDavid Howells 
134bc899ee1SDavid Howells /*
135726218fdSDavid Howells  * Resources required to do operations on a cache.
136726218fdSDavid Howells  */
137726218fdSDavid Howells struct netfs_cache_resources {
138726218fdSDavid Howells 	const struct netfs_cache_ops	*ops;
139726218fdSDavid Howells 	void				*cache_priv;
140726218fdSDavid Howells 	void				*cache_priv2;
141a7e20e31SDavid Howells 	unsigned int			debug_id;	/* Cookie debug ID */
142d24af13eSDavid Howells 	unsigned int			inval_counter;	/* object->inval_counter at begin_op */
143726218fdSDavid Howells };
144726218fdSDavid Howells 
1453d3c9504SDavid Howells /*
1463d3c9504SDavid Howells  * Descriptor for a single component subrequest.
1473d3c9504SDavid Howells  */
1486a19114bSDavid Howells struct netfs_io_subrequest {
149f18a3785SDavid Howells 	struct netfs_io_request *rreq;		/* Supervising I/O request */
1503d3c9504SDavid Howells 	struct list_head	rreq_link;	/* Link in rreq->subrequests */
1513d3c9504SDavid Howells 	loff_t			start;		/* Where to start the I/O */
1523d3c9504SDavid Howells 	size_t			len;		/* Size of the I/O */
1533d3c9504SDavid Howells 	size_t			transferred;	/* Amount of data transferred */
1546cd3d6fdSDavid Howells 	refcount_t		ref;
1553d3c9504SDavid Howells 	short			error;		/* 0 or error that occurred */
1563d3c9504SDavid Howells 	unsigned short		debug_index;	/* Index in list (for debugging output) */
157f18a3785SDavid Howells 	enum netfs_io_source	source;		/* Where to read from/write to */
1583d3c9504SDavid Howells 	unsigned long		flags;
159f18a3785SDavid Howells #define NETFS_SREQ_COPY_TO_CACHE	0	/* Set if should copy the data to the cache */
1603d3c9504SDavid Howells #define NETFS_SREQ_CLEAR_TAIL		1	/* Set if the rest of the read should be cleared */
161f18a3785SDavid Howells #define NETFS_SREQ_SHORT_IO		2	/* Set if the I/O was short */
1623d3c9504SDavid Howells #define NETFS_SREQ_SEEK_DATA_READ	3	/* Set if ->read() should SEEK_DATA first */
1633d3c9504SDavid Howells #define NETFS_SREQ_NO_PROGRESS		4	/* Set if we didn't manage to read any data */
1649032b6e8SJeffle Xu #define NETFS_SREQ_ONDEMAND		5	/* Set if it's from on-demand read mode */
1653d3c9504SDavid Howells };
1663d3c9504SDavid Howells 
167663dfb65SDavid Howells enum netfs_io_origin {
168663dfb65SDavid Howells 	NETFS_READAHEAD,		/* This read was triggered by readahead */
169663dfb65SDavid Howells 	NETFS_READPAGE,			/* This read is a synchronous read */
170663dfb65SDavid Howells 	NETFS_READ_FOR_WRITE,		/* This read is to prepare a write */
171663dfb65SDavid Howells } __mode(byte);
172663dfb65SDavid Howells 
1733d3c9504SDavid Howells /*
174f18a3785SDavid Howells  * Descriptor for an I/O helper request.  This is used to make multiple I/O
175f18a3785SDavid Howells  * operations to a variety of data stores and then stitch the result together.
1763d3c9504SDavid Howells  */
1776a19114bSDavid Howells struct netfs_io_request {
1783d3c9504SDavid Howells 	struct work_struct	work;
1793d3c9504SDavid Howells 	struct inode		*inode;		/* The file being accessed */
1803d3c9504SDavid Howells 	struct address_space	*mapping;	/* The mapping being accessed */
181726218fdSDavid Howells 	struct netfs_cache_resources cache_resources;
182f18a3785SDavid Howells 	struct list_head	subrequests;	/* Contributory I/O operations */
1833d3c9504SDavid Howells 	void			*netfs_priv;	/* Private data for the netfs */
1843d3c9504SDavid Howells 	unsigned int		debug_id;
185f18a3785SDavid Howells 	atomic_t		nr_outstanding;	/* Number of ops in progress */
186f18a3785SDavid Howells 	atomic_t		nr_copy_ops;	/* Number of copy-to-cache ops in progress */
1873d3c9504SDavid Howells 	size_t			submitted;	/* Amount submitted for I/O so far */
1883d3c9504SDavid Howells 	size_t			len;		/* Length of the request */
1893d3c9504SDavid Howells 	short			error;		/* 0 or error that occurred */
190663dfb65SDavid Howells 	enum netfs_io_origin	origin;		/* Origin of the request */
1913d3c9504SDavid Howells 	loff_t			i_size;		/* Size of the file */
1923d3c9504SDavid Howells 	loff_t			start;		/* Start position */
19378525c74SDavid Howells 	pgoff_t			no_unlock_folio; /* Don't unlock this folio after read */
194de74023bSDavid Howells 	refcount_t		ref;
1953d3c9504SDavid Howells 	unsigned long		flags;
1963d3c9504SDavid Howells #define NETFS_RREQ_INCOMPLETE_IO	0	/* Some ioreqs terminated short or with error */
197f18a3785SDavid Howells #define NETFS_RREQ_COPY_TO_CACHE	1	/* Need to write to the cache */
19878525c74SDavid Howells #define NETFS_RREQ_NO_UNLOCK_FOLIO	2	/* Don't unlock no_unlock_folio on completion */
19978525c74SDavid Howells #define NETFS_RREQ_DONT_UNLOCK_FOLIOS	3	/* Don't unlock the folios on completion */
2003d3c9504SDavid Howells #define NETFS_RREQ_FAILED		4	/* The request failed */
2013d3c9504SDavid Howells #define NETFS_RREQ_IN_PROGRESS		5	/* Unlocked when the request completes */
2026a19114bSDavid Howells 	const struct netfs_request_ops *netfs_ops;
2033d3c9504SDavid Howells };
2043d3c9504SDavid Howells 
2053d3c9504SDavid Howells /*
2063d3c9504SDavid Howells  * Operations the network filesystem can/must provide to the helpers.
2073d3c9504SDavid Howells  */
2086a19114bSDavid Howells struct netfs_request_ops {
2092de16041SDavid Howells 	int (*init_request)(struct netfs_io_request *rreq, struct file *file);
21040a81101SDavid Howells 	void (*free_request)(struct netfs_io_request *rreq);
2116a19114bSDavid Howells 	int (*begin_cache_operation)(struct netfs_io_request *rreq);
21240a81101SDavid Howells 
2136a19114bSDavid Howells 	void (*expand_readahead)(struct netfs_io_request *rreq);
2146a19114bSDavid Howells 	bool (*clamp_length)(struct netfs_io_subrequest *subreq);
215f18a3785SDavid Howells 	void (*issue_read)(struct netfs_io_subrequest *subreq);
2166a19114bSDavid Howells 	bool (*is_still_valid)(struct netfs_io_request *rreq);
217e1b1240cSDavid Howells 	int (*check_write_begin)(struct file *file, loff_t pos, unsigned len,
218fac47b43SXiubo Li 				 struct folio **foliop, void **_fsdata);
2196a19114bSDavid Howells 	void (*done)(struct netfs_io_request *rreq);
2203d3c9504SDavid Howells };
2213d3c9504SDavid Howells 
222726218fdSDavid Howells /*
2233a11b3a8SDavid Howells  * How to handle reading from a hole.
2243a11b3a8SDavid Howells  */
2253a11b3a8SDavid Howells enum netfs_read_from_hole {
2263a11b3a8SDavid Howells 	NETFS_READ_HOLE_IGNORE,
2273a11b3a8SDavid Howells 	NETFS_READ_HOLE_CLEAR,
2283a11b3a8SDavid Howells 	NETFS_READ_HOLE_FAIL,
2293a11b3a8SDavid Howells };
2303a11b3a8SDavid Howells 
2313a11b3a8SDavid Howells /*
232726218fdSDavid Howells  * Table of operations for access to a cache.  This is obtained by
233726218fdSDavid Howells  * rreq->ops->begin_cache_operation().
234726218fdSDavid Howells  */
235726218fdSDavid Howells struct netfs_cache_ops {
236726218fdSDavid Howells 	/* End an operation */
237726218fdSDavid Howells 	void (*end_operation)(struct netfs_cache_resources *cres);
238726218fdSDavid Howells 
239726218fdSDavid Howells 	/* Read data from the cache */
240726218fdSDavid Howells 	int (*read)(struct netfs_cache_resources *cres,
241726218fdSDavid Howells 		    loff_t start_pos,
242726218fdSDavid Howells 		    struct iov_iter *iter,
2433a11b3a8SDavid Howells 		    enum netfs_read_from_hole read_hole,
244726218fdSDavid Howells 		    netfs_io_terminated_t term_func,
245726218fdSDavid Howells 		    void *term_func_priv);
246726218fdSDavid Howells 
247726218fdSDavid Howells 	/* Write data to the cache */
248726218fdSDavid Howells 	int (*write)(struct netfs_cache_resources *cres,
249726218fdSDavid Howells 		     loff_t start_pos,
250726218fdSDavid Howells 		     struct iov_iter *iter,
251726218fdSDavid Howells 		     netfs_io_terminated_t term_func,
252726218fdSDavid Howells 		     void *term_func_priv);
253726218fdSDavid Howells 
254726218fdSDavid Howells 	/* Expand readahead request */
255726218fdSDavid Howells 	void (*expand_readahead)(struct netfs_cache_resources *cres,
256726218fdSDavid Howells 				 loff_t *_start, size_t *_len, loff_t i_size);
257726218fdSDavid Howells 
258726218fdSDavid Howells 	/* Prepare a read operation, shortening it to a cached/uncached
259726218fdSDavid Howells 	 * boundary as appropriate.
260726218fdSDavid Howells 	 */
2616a19114bSDavid Howells 	enum netfs_io_source (*prepare_read)(struct netfs_io_subrequest *subreq,
262726218fdSDavid Howells 					     loff_t i_size);
263726218fdSDavid Howells 
264726218fdSDavid Howells 	/* Prepare a write operation, working out what part of the write we can
265726218fdSDavid Howells 	 * actually do.
266726218fdSDavid Howells 	 */
267726218fdSDavid Howells 	int (*prepare_write)(struct netfs_cache_resources *cres,
268a39c41b8SDavid Howells 			     loff_t *_start, size_t *_len, loff_t i_size,
269a39c41b8SDavid Howells 			     bool no_space_allocated_yet);
270bee9f655SDavid Howells 
27186692475SJingbo Xu 	/* Prepare an on-demand read operation, shortening it to a cached/uncached
27286692475SJingbo Xu 	 * boundary as appropriate.
27386692475SJingbo Xu 	 */
27486692475SJingbo Xu 	enum netfs_io_source (*prepare_ondemand_read)(struct netfs_cache_resources *cres,
27586692475SJingbo Xu 						      loff_t start, size_t *_len,
27686692475SJingbo Xu 						      loff_t i_size,
27786692475SJingbo Xu 						      unsigned long *_flags, ino_t ino);
27886692475SJingbo Xu 
279bee9f655SDavid Howells 	/* Query the occupancy of the cache in a region, returning where the
280bee9f655SDavid Howells 	 * next chunk of data starts and how long it is.
281bee9f655SDavid Howells 	 */
282bee9f655SDavid Howells 	int (*query_occupancy)(struct netfs_cache_resources *cres,
283bee9f655SDavid Howells 			       loff_t start, size_t len, size_t granularity,
284bee9f655SDavid Howells 			       loff_t *_data_start, size_t *_data_len);
285726218fdSDavid Howells };
286726218fdSDavid Howells 
2873d3c9504SDavid Howells struct readahead_control;
2880e8e08ccSMatthew Wilcox (Oracle) void netfs_readahead(struct readahead_control *);
2896c62371bSMatthew Wilcox (Oracle) int netfs_read_folio(struct file *, struct folio *);
2900e8e08ccSMatthew Wilcox (Oracle) int netfs_write_begin(struct netfs_inode *, struct file *,
2910e8e08ccSMatthew Wilcox (Oracle) 		struct address_space *, loff_t pos, unsigned int len,
2920e8e08ccSMatthew Wilcox (Oracle) 		struct folio **, void **fsdata);
2933d3c9504SDavid Howells 
2940e8e08ccSMatthew Wilcox (Oracle) void netfs_subreq_terminated(struct netfs_io_subrequest *, ssize_t, bool);
2950e8e08ccSMatthew Wilcox (Oracle) void netfs_get_subrequest(struct netfs_io_subrequest *subreq,
2966cd3d6fdSDavid Howells 			  enum netfs_sreq_ref_trace what);
2970e8e08ccSMatthew Wilcox (Oracle) void netfs_put_subrequest(struct netfs_io_subrequest *subreq,
2986cd3d6fdSDavid Howells 			  bool was_async, enum netfs_sreq_ref_trace what);
2990e8e08ccSMatthew Wilcox (Oracle) void netfs_stats_show(struct seq_file *);
300*85dd2c8fSDavid Howells ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len,
301*85dd2c8fSDavid Howells 				struct iov_iter *new,
302*85dd2c8fSDavid Howells 				iov_iter_extraction_t extraction_flags);
3033d3c9504SDavid Howells 
304bc899ee1SDavid Howells /**
305874c8ca1SDavid Howells  * netfs_inode - Get the netfs inode context from the inode
306bc899ee1SDavid Howells  * @inode: The inode to query
307bc899ee1SDavid Howells  *
308bc899ee1SDavid Howells  * Get the netfs lib inode context from the network filesystem's inode.  The
309bc899ee1SDavid Howells  * context struct is expected to directly follow on from the VFS inode struct.
310bc899ee1SDavid Howells  */
netfs_inode(struct inode * inode)311874c8ca1SDavid Howells static inline struct netfs_inode *netfs_inode(struct inode *inode)
312bc899ee1SDavid Howells {
313874c8ca1SDavid Howells 	return container_of(inode, struct netfs_inode, inode);
314bc899ee1SDavid Howells }
315bc899ee1SDavid Howells 
316bc899ee1SDavid Howells /**
317874c8ca1SDavid Howells  * netfs_inode_init - Initialise a netfslib inode context
318018ab4faSLinus Torvalds  * @ctx: The netfs inode to initialise
319bc899ee1SDavid Howells  * @ops: The netfs's operations list
320bc899ee1SDavid Howells  *
321bc899ee1SDavid Howells  * Initialise the netfs library context struct.  This is expected to follow on
322bc899ee1SDavid Howells  * directly from the VFS inode struct.
323bc899ee1SDavid Howells  */
netfs_inode_init(struct netfs_inode * ctx,const struct netfs_request_ops * ops)324e81fb419SLinus Torvalds static inline void netfs_inode_init(struct netfs_inode *ctx,
325bc899ee1SDavid Howells 				    const struct netfs_request_ops *ops)
326bc899ee1SDavid Howells {
327bc899ee1SDavid Howells 	ctx->ops = ops;
328e81fb419SLinus Torvalds 	ctx->remote_i_size = i_size_read(&ctx->inode);
329874c8ca1SDavid Howells #if IS_ENABLED(CONFIG_FSCACHE)
330874c8ca1SDavid Howells 	ctx->cache = NULL;
331874c8ca1SDavid Howells #endif
3324058f742SDavid Howells }
3334058f742SDavid Howells 
3344058f742SDavid Howells /**
3354058f742SDavid Howells  * netfs_resize_file - Note that a file got resized
336e81fb419SLinus Torvalds  * @ctx: The netfs inode being resized
3374058f742SDavid Howells  * @new_i_size: The new file size
3384058f742SDavid Howells  *
3394058f742SDavid Howells  * Inform the netfs lib that a file got resized so that it can adjust its state.
3404058f742SDavid Howells  */
netfs_resize_file(struct netfs_inode * ctx,loff_t new_i_size)341e81fb419SLinus Torvalds static inline void netfs_resize_file(struct netfs_inode *ctx, loff_t new_i_size)
3424058f742SDavid Howells {
3434058f742SDavid Howells 	ctx->remote_i_size = new_i_size;
344bc899ee1SDavid Howells }
345bc899ee1SDavid Howells 
346bc899ee1SDavid Howells /**
347bc899ee1SDavid Howells  * netfs_i_cookie - Get the cache cookie from the inode
348e81fb419SLinus Torvalds  * @ctx: The netfs inode to query
349bc899ee1SDavid Howells  *
350bc899ee1SDavid Howells  * Get the caching cookie (if enabled) from the network filesystem's inode.
351bc899ee1SDavid Howells  */
netfs_i_cookie(struct netfs_inode * ctx)352e81fb419SLinus Torvalds static inline struct fscache_cookie *netfs_i_cookie(struct netfs_inode *ctx)
353bc899ee1SDavid Howells {
354bc899ee1SDavid Howells #if IS_ENABLED(CONFIG_FSCACHE)
355bc899ee1SDavid Howells 	return ctx->cache;
356bc899ee1SDavid Howells #else
357bc899ee1SDavid Howells 	return NULL;
358bc899ee1SDavid Howells #endif
359bc899ee1SDavid Howells }
360bc899ee1SDavid Howells 
361b533a83fSDavid Howells #endif /* _LINUX_NETFS_H */
362