xref: /openbmc/linux/fs/nfs/internal.h (revision d6ea0e12)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
2f7b422b1SDavid Howells /*
3f7b422b1SDavid Howells  * NFS internal definitions
4f7b422b1SDavid Howells  */
5f7b422b1SDavid Howells 
6eedc020eSAndy Adamson #include "nfs4_fs.h"
7f2aedb71SDavid Howells #include <linux/fs_context.h>
8f9c3a380SEric Paris #include <linux/security.h>
91264a2f0STrond Myklebust #include <linux/crc32.h>
109954bf92SDavid Howells #include <linux/sunrpc/addr.h>
1147af81f2SPeng Tao #include <linux/nfs_page.h>
125dd43ce2SIngo Molnar #include <linux/wait_bit.h>
13f7b422b1SDavid Howells 
1462a55d08SScott Mayhew #define NFS_SB_MASK (SB_RDONLY|SB_NOSUID|SB_NODEV|SB_NOEXEC|SB_SYNCHRONOUS)
1508734048SDavid Howells 
1620fa1902SPeng Tao extern const struct export_operations nfs_export_ops;
1720fa1902SPeng Tao 
1854ceac45SDavid Howells struct nfs_string;
19f2aedb71SDavid Howells struct nfs_pageio_descriptor;
2054ceac45SDavid Howells 
nfs_attr_check_mountpoint(struct super_block * parent,struct nfs_fattr * fattr)217ebb9315SBryan Schumaker static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
227ebb9315SBryan Schumaker {
237ebb9315SBryan Schumaker 	if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
247ebb9315SBryan Schumaker 		fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT;
257ebb9315SBryan Schumaker }
267ebb9315SBryan Schumaker 
nfs_attr_use_mounted_on_fileid(struct nfs_fattr * fattr)27533eb461SAndy Adamson static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)
28533eb461SAndy Adamson {
29533eb461SAndy Adamson 	if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) ||
30533eb461SAndy Adamson 	    (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) &&
31533eb461SAndy Adamson 	     ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0)))
32533eb461SAndy Adamson 		return 0;
33533eb461SAndy Adamson 	return 1;
34533eb461SAndy Adamson }
35533eb461SAndy Adamson 
nfs_lookup_is_soft_revalidate(const struct dentry * dentry)36f7b37b8bSTrond Myklebust static inline bool nfs_lookup_is_soft_revalidate(const struct dentry *dentry)
37f7b37b8bSTrond Myklebust {
38f7b37b8bSTrond Myklebust 	if (!(NFS_SB(dentry->d_sb)->flags & NFS_MOUNT_SOFTREVAL))
39f7b37b8bSTrond Myklebust 		return false;
40f7b37b8bSTrond Myklebust 	if (!d_is_positive(dentry) || !NFS_FH(d_inode(dentry))->size)
41f7b37b8bSTrond Myklebust 		return false;
42f7b37b8bSTrond Myklebust 	return true;
43f7b37b8bSTrond Myklebust }
44f7b37b8bSTrond Myklebust 
flags_to_mode(int flags)45b243874fSChenXiaoSong static inline fmode_t flags_to_mode(int flags)
46b243874fSChenXiaoSong {
47b243874fSChenXiaoSong 	fmode_t res = (__force fmode_t)flags & FMODE_EXEC;
48b243874fSChenXiaoSong 	if ((flags & O_ACCMODE) != O_WRONLY)
49b243874fSChenXiaoSong 		res |= FMODE_READ;
50b243874fSChenXiaoSong 	if ((flags & O_ACCMODE) != O_RDONLY)
51b243874fSChenXiaoSong 		res |= FMODE_WRITE;
52b243874fSChenXiaoSong 	return res;
53b243874fSChenXiaoSong }
54b243874fSChenXiaoSong 
556b18eaa0S\"Talpey, Thomas\ /*
56a14017dbSChuck Lever  * Note: RFC 1813 doesn't limit the number of auth flavors that
57a14017dbSChuck Lever  * a server can return, so make something up.
58a14017dbSChuck Lever  */
59a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS	(12)
60a14017dbSChuck Lever 
61a14017dbSChuck Lever /*
624cfd74fcSChuck Lever  * Value used if the user did not specify a port value.
634cfd74fcSChuck Lever  */
644cfd74fcSChuck Lever #define NFS_UNSPEC_PORT		(-1)
654cfd74fcSChuck Lever 
66a956bedaSTrond Myklebust #define NFS_UNSPEC_RETRANS	(UINT_MAX)
67a956bedaSTrond Myklebust #define NFS_UNSPEC_TIMEO	(UINT_MAX)
68a956bedaSTrond Myklebust 
69fcf10398SBryan Schumaker struct nfs_client_initdata {
70fcf10398SBryan Schumaker 	unsigned long init_flags;
715c6e5b60STrond Myklebust 	const char *hostname;			/* Hostname of the server */
72cf0d7e7fSKees Cook 	const struct sockaddr_storage *addr;	/* Address of the server */
735c6e5b60STrond Myklebust 	const char *nodename;			/* Hostname of the client */
745c6e5b60STrond Myklebust 	const char *ip_addr;			/* IP address of the client */
75fcf10398SBryan Schumaker 	size_t addrlen;
76ab7017a3SBryan Schumaker 	struct nfs_subversion *nfs_mod;
77fcf10398SBryan Schumaker 	int proto;
78fcf10398SBryan Schumaker 	u32 minorversion;
796619079dSTrond Myklebust 	unsigned int nconnect;
807e134205SOlga Kornievskaia 	unsigned int max_connect;
81fcf10398SBryan Schumaker 	struct net *net;
825c6e5b60STrond Myklebust 	const struct rpc_timeout *timeparms;
831a58e8a0STrond Myklebust 	const struct cred *cred;
846c0a8c5fSChuck Lever 	struct xprtsec_parms xprtsec;
85537935f7STrond Myklebust 	unsigned long connect_timeout;
86537935f7STrond Myklebust 	unsigned long reconnect_timeout;
87fcf10398SBryan Schumaker };
88fcf10398SBryan Schumaker 
8956e4ebf8SBryan Schumaker /*
906b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
916b18eaa0S\"Talpey, Thomas\  */
925eb005caSDavid Howells struct nfs_fs_context {
93f2aedb71SDavid Howells 	bool			internal;
94f2aedb71SDavid Howells 	bool			skip_reconfig_option_check;
95f2aedb71SDavid Howells 	bool			need_mount;
96f2aedb71SDavid Howells 	bool			sloppy;
97e558100fSDavid Howells 	unsigned int		flags;		/* NFS{,4}_MOUNT_* flags */
988cb7f74eSChuck Lever 	unsigned int		rsize, wsize;
998cb7f74eSChuck Lever 	unsigned int		timeo, retrans;
100e558100fSDavid Howells 	unsigned int		acregmin, acregmax;
101e558100fSDavid Howells 	unsigned int		acdirmin, acdirmax;
1028cb7f74eSChuck Lever 	unsigned int		namlen;
103b797cac7SDavid Howells 	unsigned int		options;
1046b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
105a3f73c27SWeston Andros Adamson 	struct nfs_auth_info	auth_info;
106a3f73c27SWeston Andros Adamson 	rpc_authflavor_t	selected_flavor;
107c8407f2eSChuck Lever 	struct xprtsec_parms	xprtsec;
1086b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
109764302ccSChuck Lever 	unsigned int		version;
1103fd5be9eSMike Sager 	unsigned int		minorversion;
11108734048SDavid Howells 	char			*fscache_uniq;
112f8ee01e3SDavid Howells 	unsigned short		protofamily;
113f8ee01e3SDavid Howells 	unsigned short		mountfamily;
114ec1ade6aSOlga Kornievskaia 	bool			has_sec_mnt_opts;
1156b18eaa0S\"Talpey, Thomas\ 
1166b18eaa0S\"Talpey, Thomas\ 	struct {
117e558100fSDavid Howells 		union {
118e558100fSDavid Howells 			struct sockaddr	address;
119e558100fSDavid Howells 			struct sockaddr_storage	_address;
120e558100fSDavid Howells 		};
1214c568017SChuck Lever 		size_t			addrlen;
1226b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
12378fa701fSChuck Lever 		u32			version;
1244cfd74fcSChuck Lever 		int			port;
12578fa701fSChuck Lever 		unsigned short		protocol;
1266b18eaa0S\"Talpey, Thomas\ 	} mount_server;
1276b18eaa0S\"Talpey, Thomas\ 
1286b18eaa0S\"Talpey, Thomas\ 	struct {
129e558100fSDavid Howells 		union {
130e558100fSDavid Howells 			struct sockaddr	address;
131e558100fSDavid Howells 			struct sockaddr_storage	_address;
132e558100fSDavid Howells 		};
1334c568017SChuck Lever 		size_t			addrlen;
1346b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
1356b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
1364cfd74fcSChuck Lever 		int			port;
13778fa701fSChuck Lever 		unsigned short		protocol;
13828cc5cd8STrond Myklebust 		unsigned short		nconnect;
1397e134205SOlga Kornievskaia 		unsigned short		max_connect;
140f2aedb71SDavid Howells 		unsigned short		export_path_len;
1416b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
142f9c3a380SEric Paris 
14362a55d08SScott Mayhew 	struct nfs_fh		*mntfh;
14462a55d08SScott Mayhew 	struct nfs_server	*server;
14562a55d08SScott Mayhew 	struct nfs_subversion	*nfs_mod;
14648be8a66SDavid Howells 
14762a55d08SScott Mayhew 	/* Information for a cloned mount. */
14862a55d08SScott Mayhew 	struct nfs_clone_mount {
14962a55d08SScott Mayhew 		struct super_block	*sb;
15062a55d08SScott Mayhew 		struct dentry		*dentry;
15162a55d08SScott Mayhew 		struct nfs_fattr	*fattr;
15262a55d08SScott Mayhew 		unsigned int		inherited_bsize;
15362a55d08SScott Mayhew 	} clone_data;
1546b18eaa0S\"Talpey, Thomas\ };
1556b18eaa0S\"Talpey, Thomas\ 
156c98e9daaSScott Mayhew #define nfs_errorf(fc, fmt, ...) ((fc)->log.log ?		\
157c98e9daaSScott Mayhew 	errorf(fc, fmt, ## __VA_ARGS__) :			\
158c98e9daaSScott Mayhew 	({ dprintk(fmt "\n", ## __VA_ARGS__); }))
159c98e9daaSScott Mayhew 
160c98e9daaSScott Mayhew #define nfs_ferrorf(fc, fac, fmt, ...) ((fc)->log.log ?		\
161c98e9daaSScott Mayhew 	errorf(fc, fmt, ## __VA_ARGS__) :			\
162c98e9daaSScott Mayhew 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
163c98e9daaSScott Mayhew 
164c98e9daaSScott Mayhew #define nfs_invalf(fc, fmt, ...) ((fc)->log.log ?		\
165c98e9daaSScott Mayhew 	invalf(fc, fmt, ## __VA_ARGS__) :			\
166c98e9daaSScott Mayhew 	({ dprintk(fmt "\n", ## __VA_ARGS__);  -EINVAL; }))
167c98e9daaSScott Mayhew 
168c98e9daaSScott Mayhew #define nfs_finvalf(fc, fac, fmt, ...) ((fc)->log.log ?		\
169c98e9daaSScott Mayhew 	invalf(fc, fmt, ## __VA_ARGS__) :			\
170c98e9daaSScott Mayhew 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__);  -EINVAL; }))
171c98e9daaSScott Mayhew 
172c98e9daaSScott Mayhew #define nfs_warnf(fc, fmt, ...) ((fc)->log.log ?		\
173c98e9daaSScott Mayhew 	warnf(fc, fmt, ## __VA_ARGS__) :			\
174c98e9daaSScott Mayhew 	({ dprintk(fmt "\n", ## __VA_ARGS__); }))
175c98e9daaSScott Mayhew 
176c98e9daaSScott Mayhew #define nfs_fwarnf(fc, fac, fmt, ...) ((fc)->log.log ?		\
177c98e9daaSScott Mayhew 	warnf(fc, fmt, ## __VA_ARGS__) :			\
178c98e9daaSScott Mayhew 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
179ce8866f0SScott Mayhew 
nfs_fc2context(const struct fs_context * fc)180f2aedb71SDavid Howells static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
181f2aedb71SDavid Howells {
182f2aedb71SDavid Howells 	return fc->fs_private;
183f2aedb71SDavid Howells }
184f2aedb71SDavid Howells 
185146ec944SChuck Lever /* mount_clnt.c */
186c5d120f8SChuck Lever struct nfs_mount_request {
187cf0d7e7fSKees Cook 	struct sockaddr_storage	*sap;
188c5d120f8SChuck Lever 	size_t			salen;
189c5d120f8SChuck Lever 	char			*hostname;
190c5d120f8SChuck Lever 	char			*dirpath;
191c5d120f8SChuck Lever 	u32			version;
192c5d120f8SChuck Lever 	unsigned short		protocol;
193c5d120f8SChuck Lever 	struct nfs_fh		*fh;
19450a737f8SChuck Lever 	int			noresvport;
1958e02f6b9SChuck Lever 	unsigned int		*auth_flav_len;
1968e02f6b9SChuck Lever 	rpc_authflavor_t	*auth_flavs;
1976d59b8d5SStanislav Kinsbursky 	struct net		*net;
198c5d120f8SChuck Lever };
199c5d120f8SChuck Lever 
200c9301cb3SEryu Guan extern int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans);
2010b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info);
202146ec944SChuck Lever 
20324c8dbbbSDavid Howells /* client.c */
204a613fa16STrond Myklebust extern const struct rpc_program nfs_program;
2056b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net);
20610b7a70cSTrond Myklebust extern void nfs_clients_exit(struct net *net);
2076663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
2085c6e5b60STrond Myklebust int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
2097d38de3fSAnna Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
210e5731131SAnna Schumaker int nfs_probe_server(struct nfs_server *, struct nfs_fh *);
211fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *);
21232e62b7cSChuck Lever void nfs_server_remove_lists(struct nfs_server *);
213a956bedaSTrond Myklebust void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
214fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
215fcf10398SBryan Schumaker 		rpc_authflavor_t);
216fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void);
217fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
21854ceac45SDavid Howells 
21924c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
220cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *);
22128cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
222c36fca52SAndy Adamson extern struct nfs_client *
223c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
224459de2edSBryan Schumaker 				struct nfs4_sessionid *, u32);
22562a55d08SScott Mayhew extern struct nfs_server *nfs_create_server(struct fs_context *);
22601dde76eSAnna Schumaker extern void nfs4_server_set_init_caps(struct nfs_server *);
22762a55d08SScott Mayhew extern struct nfs_server *nfs4_create_server(struct fs_context *);
22862a55d08SScott Mayhew extern struct nfs_server *nfs4_create_referral_server(struct fs_context *);
22932e62b7cSChuck Lever extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
230cf0d7e7fSKees Cook 					struct sockaddr_storage *sap, size_t salen,
231292f503cSTrond Myklebust 					struct net *net);
23254ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
23354ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
23454ceac45SDavid Howells 					   struct nfs_fh *,
2357e6eb683SBryan Schumaker 					   struct nfs_fattr *,
2367e6eb683SBryan Schumaker 					   rpc_authflavor_t);
237a33e4b03SWeston Andros Adamson extern bool nfs_client_init_is_complete(const struct nfs_client *clp);
238a33e4b03SWeston Andros Adamson extern int nfs_client_init_status(const struct nfs_client *clp);
2394697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
24076db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
2413fc75f12STigran Mkrtchyan extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
242cf0d7e7fSKees Cook 					     const struct sockaddr_storage *ds_addr,
24398fc685aSAndy Adamson 					     int ds_addrlen, int ds_proto,
24498fc685aSAndy Adamson 					     unsigned int ds_timeo,
245064172f3SPeng Tao 					     unsigned int ds_retrans,
2467d38de3fSAnna Schumaker 					     u32 minor_version);
2470e20162eSAndy Adamson extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
2480e20162eSAndy Adamson 						struct inode *);
249b224f7cbSTigran Mkrtchyan extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
250cf0d7e7fSKees Cook 			const struct sockaddr_storage *ds_addr, int ds_addrlen,
2511a04c6e1SPeng Tao 			int ds_proto, unsigned int ds_timeo,
2527d38de3fSAnna Schumaker 			unsigned int ds_retrans);
2536aaca566SDavid Howells #ifdef CONFIG_PROC_FS
2546aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
2556aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
25665b38851SEric W. Biederman extern int nfs_fs_proc_net_init(struct net *net);
25765b38851SEric W. Biederman extern void nfs_fs_proc_net_exit(struct net *net);
2586aaca566SDavid Howells #else
nfs_fs_proc_net_init(struct net * net)25965b38851SEric W. Biederman static inline int nfs_fs_proc_net_init(struct net *net)
26065b38851SEric W. Biederman {
26165b38851SEric W. Biederman 	return 0;
26265b38851SEric W. Biederman }
nfs_fs_proc_net_exit(struct net * net)26365b38851SEric W. Biederman static inline void nfs_fs_proc_net_exit(struct net *net)
26465b38851SEric W. Biederman {
26565b38851SEric W. Biederman }
nfs_fs_proc_init(void)2666aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
2676aaca566SDavid Howells {
2686aaca566SDavid Howells 	return 0;
2696aaca566SDavid Howells }
nfs_fs_proc_exit(void)2706aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
2716aaca566SDavid Howells {
2726aaca566SDavid Howells }
2736aaca566SDavid Howells #endif
27424c8dbbbSDavid Howells 
275f7b422b1SDavid Howells /* callback_xdr.c */
276e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version1;
277e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version4;
278f7b422b1SDavid Howells 
279f2aedb71SDavid Howells /* fs_context.c */
280f2aedb71SDavid Howells extern struct file_system_type nfs_fs_type;
2819954bf92SDavid Howells 
282f7b422b1SDavid Howells /* pagelist.c */
283f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
284266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
285f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
286266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
287f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
288266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
289f7b422b1SDavid Howells 
290f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
291266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
2924db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
2934db6e0b7SFred Isaman 			      struct nfs_pgio_header *hdr,
2944db6e0b7SFred Isaman 			      void (*release)(struct nfs_pgio_header *hdr));
2954db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
296210c7c17SBenjamin Coddington int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
297577b4232STrond Myklebust 
29841d8d5b7SAnna Schumaker extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
2991e7f3a48SWeston Andros Adamson struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
3001e7f3a48SWeston Andros Adamson void nfs_pgio_header_free(struct nfs_pgio_header *);
301ef2c488cSAnna Schumaker int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
30246a5ab47SPeng Tao int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
303a52458b4SNeilBrown 		      const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
30446a5ab47SPeng Tao 		      const struct rpc_call_ops *call_ops, int how, int flags);
305d4581383SWeston Andros Adamson void nfs_free_request(struct nfs_page *req);
30648d635f1SPeng Tao struct nfs_pgio_mirror *
30748d635f1SPeng Tao nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
30800bfa30aSAnna Schumaker 
nfs_match_open_context(const struct nfs_open_context * ctx1,const struct nfs_open_context * ctx2)309138a2935STrond Myklebust static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
310138a2935STrond Myklebust 		const struct nfs_open_context *ctx2)
311138a2935STrond Myklebust {
312a52458b4SNeilBrown 	return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state;
313138a2935STrond Myklebust }
314138a2935STrond Myklebust 
315f7b422b1SDavid Howells /* nfs2xdr.c */
316499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs_procedures[];
317573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *,
318a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
319f7b422b1SDavid Howells 
320f7b422b1SDavid Howells /* nfs3xdr.c */
321499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs3_procedures[];
322573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *,
323a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
324f7b422b1SDavid Howells 
325f7b422b1SDavid Howells /* nfs4xdr.c */
32689d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
327573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *,
328a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
3297d4e2747SDavid Howells #endif
3302449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
3312449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead;
3322449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead;
333f1c097beSAndy Adamson extern const u32 nfs41_maxgetdevinfo_overhead;
3342449ea2eSAlexandros Batsakis #endif
335f7b422b1SDavid Howells 
336f7b422b1SDavid Howells /* nfs4proc.c */
33789d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
338499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs4_procedures[];
339d75d5414SAndrew Morton #endif
340f7b422b1SDavid Howells 
341694e096fSAnna Schumaker #ifdef CONFIG_NFS_V4_SECURITY_LABEL
342694e096fSAnna Schumaker extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
343a49c2691SKinglong Mee static inline struct nfs4_label *
nfs4_label_copy(struct nfs4_label * dst,struct nfs4_label * src)344a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
345a49c2691SKinglong Mee {
346a49c2691SKinglong Mee 	if (!dst || !src)
347a49c2691SKinglong Mee 		return NULL;
348a49c2691SKinglong Mee 
349a49c2691SKinglong Mee 	if (src->len > NFS4_MAXLABELLEN)
350a49c2691SKinglong Mee 		return NULL;
351a49c2691SKinglong Mee 
352a49c2691SKinglong Mee 	dst->lfs = src->lfs;
353a49c2691SKinglong Mee 	dst->pi = src->pi;
354a49c2691SKinglong Mee 	dst->len = src->len;
355a49c2691SKinglong Mee 	memcpy(dst->label, src->label, src->len);
356a49c2691SKinglong Mee 
357a49c2691SKinglong Mee 	return dst;
358a49c2691SKinglong Mee }
359fd1defc2STrond Myklebust 
nfs_zap_label_cache_locked(struct nfs_inode * nfsi)360fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
361fd1defc2STrond Myklebust {
362fd1defc2STrond Myklebust 	if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
363fd1defc2STrond Myklebust 		nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
364fd1defc2STrond Myklebust }
365694e096fSAnna Schumaker #else
nfs4_label_alloc(struct nfs_server * server,gfp_t flags)366694e096fSAnna Schumaker static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
nfs_zap_label_cache_locked(struct nfs_inode * nfsi)367fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
368fd1defc2STrond Myklebust {
369fd1defc2STrond Myklebust }
370a49c2691SKinglong Mee static inline struct nfs4_label *
nfs4_label_copy(struct nfs4_label * dst,struct nfs4_label * src)371a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
372a49c2691SKinglong Mee {
373a49c2691SKinglong Mee 	return NULL;
374a49c2691SKinglong Mee }
375694e096fSAnna Schumaker #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
376694e096fSAnna Schumaker 
3777fe5c398STrond Myklebust /* proc.c */
3787fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
3798cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
3805c6e5b60STrond Myklebust 			   const struct nfs_client_initdata *);
3817fe5c398STrond Myklebust 
382979df72eSTrond Myklebust /* dir.c */
383230bc98fSTrond Myklebust extern void nfs_readdir_record_entry_cache_hit(struct inode *dir);
384230bc98fSTrond Myklebust extern void nfs_readdir_record_entry_cache_miss(struct inode *dir);
3851ab6c499SDave Chinner extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
3861ab6c499SDave Chinner 					    struct shrink_control *sc);
3871ab6c499SDave Chinner extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
3881495f230SYing Han 					   struct shrink_control *sc);
389597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
39000bdadc7STrond Myklebust void nfs_d_prune_case_insensitive_aliases(struct inode *inode);
3916c960e68SChristian Brauner int nfs_create(struct mnt_idmap *, struct inode *, struct dentry *,
392549c7297SChristian Brauner 	       umode_t, bool);
393c54bd91eSChristian Brauner int nfs_mkdir(struct mnt_idmap *, struct inode *, struct dentry *,
394549c7297SChristian Brauner 	      umode_t);
395597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *);
396597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *);
3977a77db95SChristian Brauner int nfs_symlink(struct mnt_idmap *, struct inode *, struct dentry *,
398549c7297SChristian Brauner 		const char *);
399597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *);
4005ebb29beSChristian Brauner int nfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *, umode_t,
401549c7297SChristian Brauner 	      dev_t);
402e18275aeSChristian Brauner int nfs_rename(struct mnt_idmap *, struct inode *, struct dentry *,
4031cd66c93SMiklos Szeredi 	       struct inode *, struct dentry *, unsigned int);
404979df72eSTrond Myklebust 
40584631f84STrond Myklebust #ifdef CONFIG_NFS_V4_2
nfs_access_xattr_mask(const struct nfs_server * server)40684631f84STrond Myklebust static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server)
40784631f84STrond Myklebust {
40884631f84STrond Myklebust 	if (!(server->caps & NFS_CAP_XATTR))
40984631f84STrond Myklebust 		return 0;
41084631f84STrond Myklebust 	return NFS4_ACCESS_XAREAD | NFS4_ACCESS_XAWRITE | NFS4_ACCESS_XALIST;
41184631f84STrond Myklebust }
41284631f84STrond Myklebust #else
nfs_access_xattr_mask(const struct nfs_server * server)41384631f84STrond Myklebust static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server)
41484631f84STrond Myklebust {
41584631f84STrond Myklebust 	return 0;
41684631f84STrond Myklebust }
41784631f84STrond Myklebust #endif
41884631f84STrond Myklebust 
419ce4ef7c0SBryan Schumaker /* file.c */
4204ff79bc7SChristoph Hellwig int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
421ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int);
4223aa2d199SAl Viro ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
423a7db5034SDavid Howells ssize_t nfs_file_splice_read(struct file *in, loff_t *ppos, struct pipe_inode_info *pipe,
424a7db5034SDavid Howells 			     size_t len, unsigned int flags);
425ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *);
426edaf4369SAl Viro ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
427ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *);
428ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *);
429ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *);
430ce4ef7c0SBryan Schumaker int nfs_check_flags(int);
431ce4ef7c0SBryan Schumaker 
432f7b422b1SDavid Howells /* inode.c */
4335746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
434f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
435ca1a199eSAl Viro extern void nfs_free_inode(struct inode *);
436a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *);
437eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *);
43819d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *);
439b57922d9SAl Viro extern void nfs_evict_inode(struct inode *);
440fd6d3feeSTrond Myklebust extern void nfs_zap_acl_cache(struct inode *inode);
441fd6d3feeSTrond Myklebust extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags);
44261540bf6STrond Myklebust extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
443dfd01f02SPeter Zijlstra extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
444f7b422b1SDavid Howells 
445f7b422b1SDavid Howells /* super.c */
4466a74490dSBryan Schumaker extern const struct super_operations nfs_sops;
4474d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
448f2aedb71SDavid Howells int nfs_try_get_tree(struct fs_context *);
449f2aedb71SDavid Howells int nfs_get_tree_common(struct fs_context *);
450fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *);
4514ebd9ab3SDominik Hackl 
452f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
453f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
454ea7c38feSTrond Myklebust extern bool nfs_sb_active(struct super_block *sb);
4551daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb);
4563c9e502bSTrond Myklebust extern int nfs_client_for_each_server(struct nfs_client *clp,
4573c9e502bSTrond Myklebust 				      int (*fn)(struct nfs_server *, void *),
4583c9e502bSTrond Myklebust 				      void *data);
459000dbe0bSDave Wysochanski #ifdef CONFIG_NFS_FSCACHE
460000dbe0bSDave Wysochanski extern const struct netfs_request_ops nfs_netfs_ops;
461000dbe0bSDave Wysochanski #endif
462000dbe0bSDave Wysochanski 
463a5864c99STrond Myklebust /* io.c */
464a5864c99STrond Myklebust extern void nfs_start_io_read(struct inode *inode);
465a5864c99STrond Myklebust extern void nfs_end_io_read(struct inode *inode);
466a5864c99STrond Myklebust extern void nfs_start_io_write(struct inode *inode);
467a5864c99STrond Myklebust extern void nfs_end_io_write(struct inode *inode);
468a5864c99STrond Myklebust extern void nfs_start_io_direct(struct inode *inode);
469a5864c99STrond Myklebust extern void nfs_end_io_direct(struct inode *inode);
470a5864c99STrond Myklebust 
nfs_file_io_is_buffered(struct nfs_inode * nfsi)471651b0e70STrond Myklebust static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
472651b0e70STrond Myklebust {
473651b0e70STrond Myklebust 	return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
474651b0e70STrond Myklebust }
475651b0e70STrond Myklebust 
476f7b422b1SDavid Howells /* namespace.c */
47797a54868SBen Hutchings #define NFS_PATH_CANONICAL 1
478b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry,
47997a54868SBen Hutchings 		      char *buffer, ssize_t buflen, unsigned flags);
48036d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path);
481f2aedb71SDavid Howells int nfs_submount(struct fs_context *, struct nfs_server *);
482f2aedb71SDavid Howells int nfs_do_submount(struct fs_context *);
483f7b422b1SDavid Howells 
48454ceac45SDavid Howells /* getroot.c */
48562a55d08SScott Mayhew extern int nfs_get_root(struct super_block *s, struct fs_context *fc);
48689d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
4875e6b1990STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
4887d4e2747SDavid Howells #endif
489f7b422b1SDavid Howells 
490061ae2edSFred Isaman struct nfs_pgio_completion_ops;
491f11c88afSAndy Adamson /* read.c */
492000dbe0bSDave Wysochanski extern const struct nfs_pgio_completion_ops nfs_async_read_completion_ops;
493584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
494fab5fc25SChristoph Hellwig 			struct inode *inode, bool force_mds,
495584aa810SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
496303a7805SAnna Schumaker extern bool nfs_read_alloc_scratch(struct nfs_pgio_header *hdr, size_t size);
497000dbe0bSDave Wysochanski extern int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio,
498000dbe0bSDave Wysochanski 			       struct nfs_open_context *ctx,
499000dbe0bSDave Wysochanski 			       struct folio *folio);
500000dbe0bSDave Wysochanski extern void nfs_pageio_complete_read(struct nfs_pageio_descriptor *pgio);
501f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
502493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
503e885de1aSTrond Myklebust 
504fbdefd64SBryan Schumaker /* super.c */
505fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *);
506fbdefd64SBryan Schumaker int  nfs_statfs(struct dentry *, struct kstatfs *);
507fbdefd64SBryan Schumaker int  nfs_show_options(struct seq_file *, struct dentry *);
508fbdefd64SBryan Schumaker int  nfs_show_devname(struct seq_file *, struct dentry *);
509fbdefd64SBryan Schumaker int  nfs_show_path(struct seq_file *, struct dentry *);
510fbdefd64SBryan Schumaker int  nfs_show_stats(struct seq_file *, struct dentry *);
511f2aedb71SDavid Howells int  nfs_reconfigure(struct fs_context *);
512fbdefd64SBryan Schumaker 
513def6ed7eSAndy Adamson /* write.c */
5141763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
515a20c93e3SChristoph Hellwig 			struct inode *inode, int ioflags, bool force_mds,
5161763da12SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
517dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
5180b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p);
5190b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
5200b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt,
5210b7c0153SFred Isaman 			       struct nfs_commit_data *data,
522c36aae9aSPeng Tao 			       const struct nfs_rpc_ops *nfs_ops,
523e0c2b380SFred Isaman 			       const struct rpc_call_ops *call_ops,
5249f0ec176SAndy Adamson 			       int how, int flags);
5250b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data,
526e0c2b380SFred Isaman 			    struct list_head *head,
527f453a54aSFred Isaman 			    struct pnfs_layout_segment *lseg,
528f453a54aSFred Isaman 			    struct nfs_commit_info *cinfo);
5291763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
5301763da12SFred Isaman 			 struct nfs_commit_info *cinfo, int max);
531ce59515cSAnna Schumaker unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
5321763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst,
5331763da12SFred Isaman 		    struct nfs_commit_info *cinfo);
5341763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req,
5351763da12SFred Isaman 			     struct pnfs_layout_segment *lseg,
536b57ff130SWeston Andros Adamson 			     struct nfs_commit_info *cinfo,
537b57ff130SWeston Andros Adamson 			     u32 ds_commit_idx);
538c65e6254SWeston Andros Adamson int nfs_write_need_commit(struct nfs_pgio_header *);
539a08a8cd3STrond Myklebust void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
5401763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
5411763da12SFred Isaman 			    int how, struct nfs_commit_info *cinfo);
542e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list,
543ea2cf228SFred Isaman 		      struct pnfs_layout_segment *lseg,
544b57ff130SWeston Andros Adamson 		      struct nfs_commit_info *cinfo,
545b57ff130SWeston Andros Adamson 		      u32 ds_commit_idx);
5460b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data);
5476272dcc6SAnna Schumaker void nfs_request_add_commit_list(struct nfs_page *req,
548ea2cf228SFred Isaman 				 struct nfs_commit_info *cinfo);
54986d80f97STrond Myklebust void nfs_request_add_commit_list_locked(struct nfs_page *req,
55086d80f97STrond Myklebust 		struct list_head *dst,
55186d80f97STrond Myklebust 		struct nfs_commit_info *cinfo);
552ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req,
553ea2cf228SFred Isaman 				    struct nfs_commit_info *cinfo);
554ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo,
555ea2cf228SFred Isaman 		    struct inode *inode,
556ea2cf228SFred Isaman 		    struct nfs_direct_req *dreq);
557dc24826bSAndy Adamson int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
558ce52914eSScott Mayhew bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode);
559a7d42ddbSWeston Andros Adamson void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
560e0c2b380SFred Isaman 
561837bb1d7STrond Myklebust int nfs_filemap_write_and_wait_range(struct address_space *mapping,
562837bb1d7STrond Myklebust 		loff_t lstart, loff_t lend);
563837bb1d7STrond Myklebust 
564a5314a74STrond Myklebust #ifdef CONFIG_NFS_V4_1
565e3b9f7e6STrond Myklebust static inline void
pnfs_bucket_clear_pnfs_ds_commit_verifiers(struct pnfs_commit_bucket * buckets,unsigned int nbuckets)566e3b9f7e6STrond Myklebust pnfs_bucket_clear_pnfs_ds_commit_verifiers(struct pnfs_commit_bucket *buckets,
567e3b9f7e6STrond Myklebust 		unsigned int nbuckets)
568e3b9f7e6STrond Myklebust {
569e3b9f7e6STrond Myklebust 	unsigned int i;
570e3b9f7e6STrond Myklebust 
571e3b9f7e6STrond Myklebust 	for (i = 0; i < nbuckets; i++)
572e3b9f7e6STrond Myklebust 		buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
573e3b9f7e6STrond Myklebust }
574a5314a74STrond Myklebust static inline
nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info * cinfo)575a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
576a5314a74STrond Myklebust {
577e3b9f7e6STrond Myklebust 	struct pnfs_commit_array *array;
578a5314a74STrond Myklebust 
579a9901899STrond Myklebust 	rcu_read_lock();
580a9901899STrond Myklebust 	list_for_each_entry_rcu(array, &cinfo->commits, cinfo_list)
581e3b9f7e6STrond Myklebust 		pnfs_bucket_clear_pnfs_ds_commit_verifiers(array->buckets,
582e3b9f7e6STrond Myklebust 				array->nbuckets);
583a9901899STrond Myklebust 	rcu_read_unlock();
584a5314a74STrond Myklebust }
585a5314a74STrond Myklebust #else
586a5314a74STrond Myklebust static inline
nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info * cinfo)587a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
588a5314a74STrond Myklebust {
589a5314a74STrond Myklebust }
590a5314a74STrond Myklebust #endif
591a5314a74STrond Myklebust 
592074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION
5934ae84a80SMatthew Wilcox (Oracle) int nfs_migrate_folio(struct address_space *, struct folio *dst,
5944ae84a80SMatthew Wilcox (Oracle) 		struct folio *src, enum migrate_mode);
5954ae84a80SMatthew Wilcox (Oracle) #else
5964ae84a80SMatthew Wilcox (Oracle) #define nfs_migrate_folio NULL
597074cc1deSTrond Myklebust #endif
598def6ed7eSAndy Adamson 
5998fc3c386STrond Myklebust static inline int
nfs_write_verifier_cmp(const struct nfs_write_verifier * v1,const struct nfs_write_verifier * v2)6008fc3c386STrond Myklebust nfs_write_verifier_cmp(const struct nfs_write_verifier *v1,
6018fc3c386STrond Myklebust 		const struct nfs_write_verifier *v2)
6028fc3c386STrond Myklebust {
6038fc3c386STrond Myklebust 	return memcmp(v1->data, v2->data, sizeof(v1->data));
6048fc3c386STrond Myklebust }
6058fc3c386STrond Myklebust 
6061f28476dSTrond Myklebust static inline bool
nfs_write_match_verf(const struct nfs_writeverf * verf,struct nfs_page * req)6071f28476dSTrond Myklebust nfs_write_match_verf(const struct nfs_writeverf *verf,
6081f28476dSTrond Myklebust 		struct nfs_page *req)
6091f28476dSTrond Myklebust {
6101f28476dSTrond Myklebust 	return verf->committed > NFS_UNSTABLE &&
6111f28476dSTrond Myklebust 		!nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier);
6121f28476dSTrond Myklebust }
6131f28476dSTrond Myklebust 
nfs_io_gfp_mask(void)614515dcdcdSTrond Myklebust static inline gfp_t nfs_io_gfp_mask(void)
615515dcdcdSTrond Myklebust {
616515dcdcdSTrond Myklebust 	if (current->flags & PF_WQ_WORKER)
617515dcdcdSTrond Myklebust 		return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
618515dcdcdSTrond Myklebust 	return GFP_KERNEL;
619515dcdcdSTrond Myklebust }
620515dcdcdSTrond Myklebust 
621d7a51186SAnna Schumaker /*
622d7a51186SAnna Schumaker  * Special version of should_remove_suid() that ignores capabilities.
623d7a51186SAnna Schumaker  */
nfs_should_remove_suid(const struct inode * inode)624d7a51186SAnna Schumaker static inline int nfs_should_remove_suid(const struct inode *inode)
625d7a51186SAnna Schumaker {
626d7a51186SAnna Schumaker 	umode_t mode = inode->i_mode;
627d7a51186SAnna Schumaker 	int kill = 0;
628d7a51186SAnna Schumaker 
629d7a51186SAnna Schumaker 	/* suid always must be killed */
630d7a51186SAnna Schumaker 	if (unlikely(mode & S_ISUID))
631d7a51186SAnna Schumaker 		kill = ATTR_KILL_SUID;
632d7a51186SAnna Schumaker 
633d7a51186SAnna Schumaker 	/*
634d7a51186SAnna Schumaker 	 * sgid without any exec bits is just a mandatory locking mark; leave
635d7a51186SAnna Schumaker 	 * it alone.  If some exec bits are set, it's a real sgid; kill it.
636d7a51186SAnna Schumaker 	 */
637d7a51186SAnna Schumaker 	if (unlikely((mode & S_ISGID) && (mode & S_IXGRP)))
638d7a51186SAnna Schumaker 		kill |= ATTR_KILL_SGID;
639d7a51186SAnna Schumaker 
640d7a51186SAnna Schumaker 	if (unlikely(kill && S_ISREG(mode)))
641d7a51186SAnna Schumaker 		return kill;
642d7a51186SAnna Schumaker 
643d7a51186SAnna Schumaker 	return 0;
644d7a51186SAnna Schumaker }
645d7a51186SAnna Schumaker 
6460e862a40SJeff Layton /* unlink.c */
6470e862a40SJeff Layton extern struct rpc_task *
6480e862a40SJeff Layton nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
6490e862a40SJeff Layton 		 struct dentry *old_dentry, struct dentry *new_dentry,
6500e862a40SJeff Layton 		 void (*complete)(struct rpc_task *, struct nfs_renamedata *));
6510e862a40SJeff Layton extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
6520e862a40SJeff Layton 
6531763da12SFred Isaman /* direct.c */
6541763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
6551763da12SFred Isaman 			      struct nfs_direct_req *dreq);
65675aa038dSTrond Myklebust extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq, loff_t offset);
6571763da12SFred Isaman 
658cccef3b9SAndy Adamson /* nfs4proc.c */
6598cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
6605c6e5b60STrond Myklebust 			    const struct nfs_client_initdata *);
66105f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp,
66205f4c350SChuck Lever 				struct nfs_client **result,
663a52458b4SNeilBrown 				const struct cred *cred);
66405f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp,
66505f4c350SChuck Lever 				struct nfs_client **result,
666a52458b4SNeilBrown 				const struct cred *cred);
66710e037d1SSantosh kumar pradhan extern void nfs4_test_session_trunk(struct rpc_clnt *clnt,
66810e037d1SSantosh kumar pradhan 				struct rpc_xprt *xprt,
66910e037d1SSantosh kumar pradhan 				void *data);
670cccef3b9SAndy Adamson 
nfs_igrab_and_active(struct inode * inode)671ea7c38feSTrond Myklebust static inline struct inode *nfs_igrab_and_active(struct inode *inode)
672ea7c38feSTrond Myklebust {
673896567eeSTrond Myklebust 	struct super_block *sb = inode->i_sb;
674896567eeSTrond Myklebust 
675896567eeSTrond Myklebust 	if (sb && nfs_sb_active(sb)) {
676896567eeSTrond Myklebust 		if (igrab(inode))
677ea7c38feSTrond Myklebust 			return inode;
678896567eeSTrond Myklebust 		nfs_sb_deactive(sb);
679896567eeSTrond Myklebust 	}
680896567eeSTrond Myklebust 	return NULL;
681ea7c38feSTrond Myklebust }
682ea7c38feSTrond Myklebust 
nfs_iput_and_deactive(struct inode * inode)683ea7c38feSTrond Myklebust static inline void nfs_iput_and_deactive(struct inode *inode)
684ea7c38feSTrond Myklebust {
685ea7c38feSTrond Myklebust 	if (inode != NULL) {
686ea7c38feSTrond Myklebust 		struct super_block *sb = inode->i_sb;
687ea7c38feSTrond Myklebust 
688ea7c38feSTrond Myklebust 		iput(inode);
689ea7c38feSTrond Myklebust 		nfs_sb_deactive(sb);
690ea7c38feSTrond Myklebust 	}
691ea7c38feSTrond Myklebust }
692ea7c38feSTrond Myklebust 
693557134a3SAndy Adamson /*
694f7b422b1SDavid Howells  * Determine the device name as a string
695f7b422b1SDavid Howells  */
nfs_devname(struct dentry * dentry,char * buffer,ssize_t buflen)696b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry,
697f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
698f7b422b1SDavid Howells {
699b514f872SAl Viro 	char *dummy;
70097a54868SBen Hutchings 	return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
701f7b422b1SDavid Howells }
702f7b422b1SDavid Howells 
703f7b422b1SDavid Howells /*
704f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
705f7b422b1SDavid Howells  */
706f7b422b1SDavid Howells static inline
nfs_block_bits(unsigned long bsize,unsigned char * nrbitsp)707f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
708f7b422b1SDavid Howells {
709f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
710f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
711f7b422b1SDavid Howells 		unsigned char	nrbits;
712f7b422b1SDavid Howells 
713d6ea0e12SSergey Shtylyov 		for (nrbits = 31; nrbits && !(bsize & (1UL << nrbits)); nrbits--)
714f7b422b1SDavid Howells 			;
715d6ea0e12SSergey Shtylyov 		bsize = 1UL << nrbits;
716f7b422b1SDavid Howells 		if (nrbitsp)
717f7b422b1SDavid Howells 			*nrbitsp = nrbits;
718f7b422b1SDavid Howells 	}
719f7b422b1SDavid Howells 
720f7b422b1SDavid Howells 	return bsize;
721f7b422b1SDavid Howells }
722f7b422b1SDavid Howells 
723f7b422b1SDavid Howells /*
724f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
725f7b422b1SDavid Howells  */
nfs_calc_block_size(u64 tsize)7269eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
727f7b422b1SDavid Howells {
7289eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
729f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
730f7b422b1SDavid Howells }
731f7b422b1SDavid Howells 
732f7b422b1SDavid Howells /*
733f7b422b1SDavid Howells  * Compute and set NFS server blocksize
734f7b422b1SDavid Howells  */
735f7b422b1SDavid Howells static inline
nfs_block_size(unsigned long bsize,unsigned char * nrbitsp)736f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
737f7b422b1SDavid Howells {
738f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
739f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
740f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
741f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
742f7b422b1SDavid Howells 
743f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
744f7b422b1SDavid Howells }
745f7b422b1SDavid Howells 
746f7b422b1SDavid Howells /*
747940261a1SAnna Schumaker  * Compute and set NFS server rsize / wsize
748940261a1SAnna Schumaker  */
749940261a1SAnna Schumaker static inline
nfs_io_size(unsigned long iosize,enum xprt_transports proto)750940261a1SAnna Schumaker unsigned long nfs_io_size(unsigned long iosize, enum xprt_transports proto)
751940261a1SAnna Schumaker {
752940261a1SAnna Schumaker 	if (iosize < NFS_MIN_FILE_IO_SIZE)
753940261a1SAnna Schumaker 		iosize = NFS_DEF_FILE_IO_SIZE;
754940261a1SAnna Schumaker 	else if (iosize >= NFS_MAX_FILE_IO_SIZE)
755940261a1SAnna Schumaker 		iosize = NFS_MAX_FILE_IO_SIZE;
756940261a1SAnna Schumaker 
757a60214c2SAnna Schumaker 	if (proto == XPRT_TRANSPORT_UDP || iosize < PAGE_SIZE)
758940261a1SAnna Schumaker 		return nfs_block_bits(iosize, NULL);
759a60214c2SAnna Schumaker 	return iosize & PAGE_MASK;
760940261a1SAnna Schumaker }
761940261a1SAnna Schumaker 
762940261a1SAnna Schumaker /*
763f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
764f7b422b1SDavid Howells  */
765f7b422b1SDavid Howells static inline
nfs_super_set_maxbytes(struct super_block * sb,__u64 maxfilesize)766f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
767f7b422b1SDavid Howells {
768f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
769f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
770f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
771f7b422b1SDavid Howells }
77249a70f27STrond Myklebust 
77349a70f27STrond Myklebust /*
7748d92890bSNeilBrown  * Record the page as unstable (an extra writeback period) and mark its
7758d92890bSNeilBrown  * inode as dirty.
776d15bc38dSTom Haynes  */
nfs_folio_mark_unstable(struct folio * folio,struct nfs_commit_info * cinfo)7770c493b5cSTrond Myklebust static inline void nfs_folio_mark_unstable(struct folio *folio,
7780c493b5cSTrond Myklebust 					   struct nfs_commit_info *cinfo)
779d15bc38dSTom Haynes {
7800c493b5cSTrond Myklebust 	if (folio && !cinfo->dreq) {
7810c493b5cSTrond Myklebust 		struct inode *inode = folio_file_mapping(folio)->host;
7820c493b5cSTrond Myklebust 		long nr = folio_nr_pages(folio);
783d15bc38dSTom Haynes 
7848d92890bSNeilBrown 		/* This page is really still in write-back - just that the
7858d92890bSNeilBrown 		 * writeback is happening on the server now.
7868d92890bSNeilBrown 		 */
7870c493b5cSTrond Myklebust 		node_stat_mod_folio(folio, NR_WRITEBACK, nr);
7880c493b5cSTrond Myklebust 		wb_stat_mod(&inode_to_bdi(inode)->wb, WB_WRITEBACK, nr);
789d15bc38dSTom Haynes 		__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
790d15bc38dSTom Haynes 	}
79186d80f97STrond Myklebust }
792d15bc38dSTom Haynes 
793d15bc38dSTom Haynes /*
79449a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
79549a70f27STrond Myklebust  */
79649a70f27STrond Myklebust static inline
nfs_page_length(struct page * page)79749a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
79849a70f27STrond Myklebust {
799d56b4ddfSMel Gorman 	loff_t i_size = i_size_read(page_file_mapping(page)->host);
80049a70f27STrond Myklebust 
80149a70f27STrond Myklebust 	if (i_size > 0) {
8028cd79788SHuang Ying 		pgoff_t index = page_index(page);
80309cbfeafSKirill A. Shutemov 		pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT;
8048cd79788SHuang Ying 		if (index < end_index)
80509cbfeafSKirill A. Shutemov 			return PAGE_SIZE;
8068cd79788SHuang Ying 		if (index == end_index)
80709cbfeafSKirill A. Shutemov 			return ((i_size - 1) & ~PAGE_MASK) + 1;
80849a70f27STrond Myklebust 	}
80949a70f27STrond Myklebust 	return 0;
81049a70f27STrond Myklebust }
8118d5658c9STrond Myklebust 
8128d5658c9STrond Myklebust /*
813ab75bff1STrond Myklebust  * Determine the number of bytes of data the page contains
814ab75bff1STrond Myklebust  */
nfs_folio_length(struct folio * folio)815ab75bff1STrond Myklebust static inline size_t nfs_folio_length(struct folio *folio)
816ab75bff1STrond Myklebust {
817ab75bff1STrond Myklebust 	loff_t i_size = i_size_read(folio_file_mapping(folio)->host);
818ab75bff1STrond Myklebust 
819ab75bff1STrond Myklebust 	if (i_size > 0) {
820ab75bff1STrond Myklebust 		pgoff_t index = folio_index(folio) >> folio_order(folio);
821ab75bff1STrond Myklebust 		pgoff_t end_index = (i_size - 1) >> folio_shift(folio);
822ab75bff1STrond Myklebust 		if (index < end_index)
823ab75bff1STrond Myklebust 			return folio_size(folio);
824ab75bff1STrond Myklebust 		if (index == end_index)
825ab75bff1STrond Myklebust 			return offset_in_folio(folio, i_size - 1) + 1;
826ab75bff1STrond Myklebust 	}
827ab75bff1STrond Myklebust 	return 0;
828ab75bff1STrond Myklebust }
829ab75bff1STrond Myklebust 
830ab75bff1STrond Myklebust /*
8310b26a0bfSTrond Myklebust  * Convert a umode to a dirent->d_type
8320b26a0bfSTrond Myklebust  */
8330b26a0bfSTrond Myklebust static inline
nfs_umode_to_dtype(umode_t mode)8340b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode)
8350b26a0bfSTrond Myklebust {
8360b26a0bfSTrond Myklebust 	return (mode >> 12) & 15;
8370b26a0bfSTrond Myklebust }
8380b26a0bfSTrond Myklebust 
8390b26a0bfSTrond Myklebust /*
8408d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
8418d5658c9STrond Myklebust  * with a base offset of 'base'
8428d5658c9STrond Myklebust  */
nfs_page_array_len(unsigned int base,size_t len)843eb9f2a5aSTrond Myklebust static inline unsigned int nfs_page_array_len(unsigned int base, size_t len)
8448d5658c9STrond Myklebust {
845eb9f2a5aSTrond Myklebust 	return ((unsigned long)len + (unsigned long)base + PAGE_SIZE - 1) >>
846eb9f2a5aSTrond Myklebust 	       PAGE_SHIFT;
8478d5658c9STrond Myklebust }
8480110ee15STrond Myklebust 
8493a1556e8STrond Myklebust /*
850ae08483cSArnd Bergmann  * Convert a struct timespec64 into a 64-bit change attribute
8513a1556e8STrond Myklebust  *
852ae08483cSArnd Bergmann  * This does approximately the same thing as timespec64_to_ns(),
8533a1556e8STrond Myklebust  * but for calculation efficiency, we multiply the seconds by
8543a1556e8STrond Myklebust  * 1024*1024*1024.
8553a1556e8STrond Myklebust  */
8563a1556e8STrond Myklebust static inline
nfs_timespec_to_change_attr(const struct timespec64 * ts)857e86d5a02STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec64 *ts)
8583a1556e8STrond Myklebust {
8593a1556e8STrond Myklebust 	return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
8603a1556e8STrond Myklebust }
8611264a2f0STrond Myklebust 
8621264a2f0STrond Myklebust #ifdef CONFIG_CRC32
nfs_stateid_hash(const nfs4_stateid * stateid)86348c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid)
86448c9579aSOlga Kornievskaia {
86548c9579aSOlga Kornievskaia 	return ~crc32_le(0xFFFFFFFF, &stateid->other[0],
86648c9579aSOlga Kornievskaia 				NFS4_STATEID_OTHER_SIZE);
86748c9579aSOlga Kornievskaia }
8681264a2f0STrond Myklebust #else
nfs_stateid_hash(nfs4_stateid * stateid)86948c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
87048c9579aSOlga Kornievskaia {
87148c9579aSOlga Kornievskaia 	return 0;
87248c9579aSOlga Kornievskaia }
8731264a2f0STrond Myklebust #endif
8740bcbf039SPeng Tao 
nfs_error_is_fatal(int err)8750bcbf039SPeng Tao static inline bool nfs_error_is_fatal(int err)
8760bcbf039SPeng Tao {
8770bcbf039SPeng Tao 	switch (err) {
8780bcbf039SPeng Tao 	case -ERESTARTSYS:
8797dc58ca5STrond Myklebust 	case -EINTR:
88054551d85STrond Myklebust 	case -EACCES:
88154551d85STrond Myklebust 	case -EDQUOT:
88254551d85STrond Myklebust 	case -EFBIG:
8830bcbf039SPeng Tao 	case -EIO:
8840bcbf039SPeng Tao 	case -ENOSPC:
8850bcbf039SPeng Tao 	case -EROFS:
88654551d85STrond Myklebust 	case -ESTALE:
8870bcbf039SPeng Tao 	case -E2BIG:
8882dc23affSTrond Myklebust 	case -ENOMEM:
88911982a7cSTrond Myklebust 	case -ETIMEDOUT:
8900bcbf039SPeng Tao 		return true;
8910bcbf039SPeng Tao 	default:
8920bcbf039SPeng Tao 		return false;
8930bcbf039SPeng Tao 	}
8940bcbf039SPeng Tao }
895bf4b4905SNeilBrown 
nfs_error_is_fatal_on_server(int err)8968f54c7a4STrond Myklebust static inline bool nfs_error_is_fatal_on_server(int err)
8978f54c7a4STrond Myklebust {
8988f54c7a4STrond Myklebust 	switch (err) {
8998f54c7a4STrond Myklebust 	case 0:
9008f54c7a4STrond Myklebust 	case -ERESTARTSYS:
9018f54c7a4STrond Myklebust 	case -EINTR:
90245228440STrond Myklebust 	case -ENOMEM:
9038f54c7a4STrond Myklebust 		return false;
9048f54c7a4STrond Myklebust 	}
9058f54c7a4STrond Myklebust 	return nfs_error_is_fatal(err);
9068f54c7a4STrond Myklebust }
9079954bf92SDavid Howells 
9089954bf92SDavid Howells /*
9099954bf92SDavid Howells  * Select between a default port value and a user-specified port value.
9109954bf92SDavid Howells  * If a zero value is set, then autobind will be used.
9119954bf92SDavid Howells  */
nfs_set_port(struct sockaddr_storage * sap,int * port,const unsigned short default_port)912cf0d7e7fSKees Cook static inline void nfs_set_port(struct sockaddr_storage *sap, int *port,
9139954bf92SDavid Howells 				const unsigned short default_port)
9149954bf92SDavid Howells {
9159954bf92SDavid Howells 	if (*port == NFS_UNSPEC_PORT)
9169954bf92SDavid Howells 		*port = default_port;
9179954bf92SDavid Howells 
918cf0d7e7fSKees Cook 	rpc_set_port((struct sockaddr *)sap, *port);
9199954bf92SDavid Howells }
9208efc4bbeSJeff Layton 
9218efc4bbeSJeff Layton struct nfs_direct_req {
9228efc4bbeSJeff Layton 	struct kref		kref;		/* release manager */
9238efc4bbeSJeff Layton 
9248efc4bbeSJeff Layton 	/* I/O parameters */
9258efc4bbeSJeff Layton 	struct nfs_open_context	*ctx;		/* file open context info */
9268efc4bbeSJeff Layton 	struct nfs_lock_context *l_ctx;		/* Lock context info */
9278efc4bbeSJeff Layton 	struct kiocb *		iocb;		/* controlling i/o request */
9288efc4bbeSJeff Layton 	struct inode *		inode;		/* target file of i/o */
9298efc4bbeSJeff Layton 
9308efc4bbeSJeff Layton 	/* completion state */
9318efc4bbeSJeff Layton 	atomic_t		io_count;	/* i/os we're waiting for */
9328efc4bbeSJeff Layton 	spinlock_t		lock;		/* protect completion state */
9338efc4bbeSJeff Layton 
9348efc4bbeSJeff Layton 	loff_t			io_start;	/* Start offset for I/O */
9358efc4bbeSJeff Layton 	ssize_t			count,		/* bytes actually processed */
9368efc4bbeSJeff Layton 				max_count,	/* max expected count */
9378efc4bbeSJeff Layton 				bytes_left,	/* bytes left to be sent */
9388efc4bbeSJeff Layton 				error;		/* any reported error */
9398efc4bbeSJeff Layton 	struct completion	completion;	/* wait for i/o completion */
9408efc4bbeSJeff Layton 
9418efc4bbeSJeff Layton 	/* commit state */
9428efc4bbeSJeff Layton 	struct nfs_mds_commit_info mds_cinfo;	/* Storage for cinfo */
9438efc4bbeSJeff Layton 	struct pnfs_ds_commit_info ds_cinfo;	/* Storage for cinfo */
9448efc4bbeSJeff Layton 	struct work_struct	work;
9458efc4bbeSJeff Layton 	int			flags;
9468efc4bbeSJeff Layton 	/* for write */
9478efc4bbeSJeff Layton #define NFS_ODIRECT_DO_COMMIT		(1)	/* an unstable reply was received */
9488efc4bbeSJeff Layton #define NFS_ODIRECT_RESCHED_WRITES	(2)	/* write verification failed */
9498efc4bbeSJeff Layton 	/* for read */
9508efc4bbeSJeff Layton #define NFS_ODIRECT_SHOULD_DIRTY	(3)	/* dirty user-space page after read */
9518efc4bbeSJeff Layton #define NFS_ODIRECT_DONE		INT_MAX	/* write verification failed */
9528efc4bbeSJeff Layton };
953