xref: /openbmc/linux/fs/nfs/internal.h (revision 6c0a8c5f)
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 
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 
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 
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 
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;
84*6c0a8c5fSChuck Lever 	struct xprtsec_parms xprtsec;
85fcf10398SBryan Schumaker };
86fcf10398SBryan Schumaker 
8756e4ebf8SBryan Schumaker /*
886b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
896b18eaa0S\"Talpey, Thomas\  */
905eb005caSDavid Howells struct nfs_fs_context {
91f2aedb71SDavid Howells 	bool			internal;
92f2aedb71SDavid Howells 	bool			skip_reconfig_option_check;
93f2aedb71SDavid Howells 	bool			need_mount;
94f2aedb71SDavid Howells 	bool			sloppy;
95e558100fSDavid Howells 	unsigned int		flags;		/* NFS{,4}_MOUNT_* flags */
968cb7f74eSChuck Lever 	unsigned int		rsize, wsize;
978cb7f74eSChuck Lever 	unsigned int		timeo, retrans;
98e558100fSDavid Howells 	unsigned int		acregmin, acregmax;
99e558100fSDavid Howells 	unsigned int		acdirmin, acdirmax;
1008cb7f74eSChuck Lever 	unsigned int		namlen;
101b797cac7SDavid Howells 	unsigned int		options;
1026b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
103a3f73c27SWeston Andros Adamson 	struct nfs_auth_info	auth_info;
104a3f73c27SWeston Andros Adamson 	rpc_authflavor_t	selected_flavor;
1056b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
106764302ccSChuck Lever 	unsigned int		version;
1073fd5be9eSMike Sager 	unsigned int		minorversion;
10808734048SDavid Howells 	char			*fscache_uniq;
109f8ee01e3SDavid Howells 	unsigned short		protofamily;
110f8ee01e3SDavid Howells 	unsigned short		mountfamily;
111ec1ade6aSOlga Kornievskaia 	bool			has_sec_mnt_opts;
1126b18eaa0S\"Talpey, Thomas\ 
1136b18eaa0S\"Talpey, Thomas\ 	struct {
114e558100fSDavid Howells 		union {
115e558100fSDavid Howells 			struct sockaddr	address;
116e558100fSDavid Howells 			struct sockaddr_storage	_address;
117e558100fSDavid Howells 		};
1184c568017SChuck Lever 		size_t			addrlen;
1196b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
12078fa701fSChuck Lever 		u32			version;
1214cfd74fcSChuck Lever 		int			port;
12278fa701fSChuck Lever 		unsigned short		protocol;
1236b18eaa0S\"Talpey, Thomas\ 	} mount_server;
1246b18eaa0S\"Talpey, Thomas\ 
1256b18eaa0S\"Talpey, Thomas\ 	struct {
126e558100fSDavid Howells 		union {
127e558100fSDavid Howells 			struct sockaddr	address;
128e558100fSDavid Howells 			struct sockaddr_storage	_address;
129e558100fSDavid Howells 		};
1304c568017SChuck Lever 		size_t			addrlen;
1316b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
1326b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
1334cfd74fcSChuck Lever 		int			port;
13478fa701fSChuck Lever 		unsigned short		protocol;
13528cc5cd8STrond Myklebust 		unsigned short		nconnect;
1367e134205SOlga Kornievskaia 		unsigned short		max_connect;
137f2aedb71SDavid Howells 		unsigned short		export_path_len;
1386b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
139f9c3a380SEric Paris 
14062a55d08SScott Mayhew 	struct nfs_fh		*mntfh;
14162a55d08SScott Mayhew 	struct nfs_server	*server;
14262a55d08SScott Mayhew 	struct nfs_subversion	*nfs_mod;
14348be8a66SDavid Howells 
14462a55d08SScott Mayhew 	/* Information for a cloned mount. */
14562a55d08SScott Mayhew 	struct nfs_clone_mount {
14662a55d08SScott Mayhew 		struct super_block	*sb;
14762a55d08SScott Mayhew 		struct dentry		*dentry;
14862a55d08SScott Mayhew 		struct nfs_fattr	*fattr;
14962a55d08SScott Mayhew 		unsigned int		inherited_bsize;
15062a55d08SScott Mayhew 	} clone_data;
1516b18eaa0S\"Talpey, Thomas\ };
1526b18eaa0S\"Talpey, Thomas\ 
153c98e9daaSScott Mayhew #define nfs_errorf(fc, fmt, ...) ((fc)->log.log ?		\
154c98e9daaSScott Mayhew 	errorf(fc, fmt, ## __VA_ARGS__) :			\
155c98e9daaSScott Mayhew 	({ dprintk(fmt "\n", ## __VA_ARGS__); }))
156c98e9daaSScott Mayhew 
157c98e9daaSScott Mayhew #define nfs_ferrorf(fc, fac, fmt, ...) ((fc)->log.log ?		\
158c98e9daaSScott Mayhew 	errorf(fc, fmt, ## __VA_ARGS__) :			\
159c98e9daaSScott Mayhew 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
160c98e9daaSScott Mayhew 
161c98e9daaSScott Mayhew #define nfs_invalf(fc, fmt, ...) ((fc)->log.log ?		\
162c98e9daaSScott Mayhew 	invalf(fc, fmt, ## __VA_ARGS__) :			\
163c98e9daaSScott Mayhew 	({ dprintk(fmt "\n", ## __VA_ARGS__);  -EINVAL; }))
164c98e9daaSScott Mayhew 
165c98e9daaSScott Mayhew #define nfs_finvalf(fc, fac, fmt, ...) ((fc)->log.log ?		\
166c98e9daaSScott Mayhew 	invalf(fc, fmt, ## __VA_ARGS__) :			\
167c98e9daaSScott Mayhew 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__);  -EINVAL; }))
168c98e9daaSScott Mayhew 
169c98e9daaSScott Mayhew #define nfs_warnf(fc, fmt, ...) ((fc)->log.log ?		\
170c98e9daaSScott Mayhew 	warnf(fc, fmt, ## __VA_ARGS__) :			\
171c98e9daaSScott Mayhew 	({ dprintk(fmt "\n", ## __VA_ARGS__); }))
172c98e9daaSScott Mayhew 
173c98e9daaSScott Mayhew #define nfs_fwarnf(fc, fac, fmt, ...) ((fc)->log.log ?		\
174c98e9daaSScott Mayhew 	warnf(fc, fmt, ## __VA_ARGS__) :			\
175c98e9daaSScott Mayhew 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
176ce8866f0SScott Mayhew 
177f2aedb71SDavid Howells static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
178f2aedb71SDavid Howells {
179f2aedb71SDavid Howells 	return fc->fs_private;
180f2aedb71SDavid Howells }
181f2aedb71SDavid Howells 
182146ec944SChuck Lever /* mount_clnt.c */
183c5d120f8SChuck Lever struct nfs_mount_request {
184cf0d7e7fSKees Cook 	struct sockaddr_storage	*sap;
185c5d120f8SChuck Lever 	size_t			salen;
186c5d120f8SChuck Lever 	char			*hostname;
187c5d120f8SChuck Lever 	char			*dirpath;
188c5d120f8SChuck Lever 	u32			version;
189c5d120f8SChuck Lever 	unsigned short		protocol;
190c5d120f8SChuck Lever 	struct nfs_fh		*fh;
19150a737f8SChuck Lever 	int			noresvport;
1928e02f6b9SChuck Lever 	unsigned int		*auth_flav_len;
1938e02f6b9SChuck Lever 	rpc_authflavor_t	*auth_flavs;
1946d59b8d5SStanislav Kinsbursky 	struct net		*net;
195c5d120f8SChuck Lever };
196c5d120f8SChuck Lever 
197c9301cb3SEryu Guan extern int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans);
1980b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info);
199146ec944SChuck Lever 
20024c8dbbbSDavid Howells /* client.c */
201a613fa16STrond Myklebust extern const struct rpc_program nfs_program;
2026b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net);
20310b7a70cSTrond Myklebust extern void nfs_clients_exit(struct net *net);
2046663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
2055c6e5b60STrond Myklebust int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
2067d38de3fSAnna Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
207e5731131SAnna Schumaker int nfs_probe_server(struct nfs_server *, struct nfs_fh *);
208fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *);
20932e62b7cSChuck Lever void nfs_server_remove_lists(struct nfs_server *);
210a956bedaSTrond Myklebust void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
211fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
212fcf10398SBryan Schumaker 		rpc_authflavor_t);
213fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void);
214fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
21554ceac45SDavid Howells 
21624c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
217cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *);
21828cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
219c36fca52SAndy Adamson extern struct nfs_client *
220c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
221459de2edSBryan Schumaker 				struct nfs4_sessionid *, u32);
22262a55d08SScott Mayhew extern struct nfs_server *nfs_create_server(struct fs_context *);
22301dde76eSAnna Schumaker extern void nfs4_server_set_init_caps(struct nfs_server *);
22462a55d08SScott Mayhew extern struct nfs_server *nfs4_create_server(struct fs_context *);
22562a55d08SScott Mayhew extern struct nfs_server *nfs4_create_referral_server(struct fs_context *);
22632e62b7cSChuck Lever extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
227cf0d7e7fSKees Cook 					struct sockaddr_storage *sap, size_t salen,
228292f503cSTrond Myklebust 					struct net *net);
22954ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
23054ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
23154ceac45SDavid Howells 					   struct nfs_fh *,
2327e6eb683SBryan Schumaker 					   struct nfs_fattr *,
2337e6eb683SBryan Schumaker 					   rpc_authflavor_t);
234a33e4b03SWeston Andros Adamson extern bool nfs_client_init_is_complete(const struct nfs_client *clp);
235a33e4b03SWeston Andros Adamson extern int nfs_client_init_status(const struct nfs_client *clp);
2364697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
23776db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
2383fc75f12STigran Mkrtchyan extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
239cf0d7e7fSKees Cook 					     const struct sockaddr_storage *ds_addr,
24098fc685aSAndy Adamson 					     int ds_addrlen, int ds_proto,
24198fc685aSAndy Adamson 					     unsigned int ds_timeo,
242064172f3SPeng Tao 					     unsigned int ds_retrans,
2437d38de3fSAnna Schumaker 					     u32 minor_version);
2440e20162eSAndy Adamson extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
2450e20162eSAndy Adamson 						struct inode *);
246b224f7cbSTigran Mkrtchyan extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
247cf0d7e7fSKees Cook 			const struct sockaddr_storage *ds_addr, int ds_addrlen,
2481a04c6e1SPeng Tao 			int ds_proto, unsigned int ds_timeo,
2497d38de3fSAnna Schumaker 			unsigned int ds_retrans);
2506aaca566SDavid Howells #ifdef CONFIG_PROC_FS
2516aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
2526aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
25365b38851SEric W. Biederman extern int nfs_fs_proc_net_init(struct net *net);
25465b38851SEric W. Biederman extern void nfs_fs_proc_net_exit(struct net *net);
2556aaca566SDavid Howells #else
25665b38851SEric W. Biederman static inline int nfs_fs_proc_net_init(struct net *net)
25765b38851SEric W. Biederman {
25865b38851SEric W. Biederman 	return 0;
25965b38851SEric W. Biederman }
26065b38851SEric W. Biederman static inline void nfs_fs_proc_net_exit(struct net *net)
26165b38851SEric W. Biederman {
26265b38851SEric W. Biederman }
2636aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
2646aaca566SDavid Howells {
2656aaca566SDavid Howells 	return 0;
2666aaca566SDavid Howells }
2676aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
2686aaca566SDavid Howells {
2696aaca566SDavid Howells }
2706aaca566SDavid Howells #endif
27124c8dbbbSDavid Howells 
272f7b422b1SDavid Howells /* callback_xdr.c */
273e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version1;
274e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version4;
275f7b422b1SDavid Howells 
276f2aedb71SDavid Howells /* fs_context.c */
277f2aedb71SDavid Howells extern struct file_system_type nfs_fs_type;
2789954bf92SDavid Howells 
279f7b422b1SDavid Howells /* pagelist.c */
280f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
281266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
282f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
283266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
284f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
285266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
286f7b422b1SDavid Howells 
287f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
288266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
2894db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
2904db6e0b7SFred Isaman 			      struct nfs_pgio_header *hdr,
2914db6e0b7SFred Isaman 			      void (*release)(struct nfs_pgio_header *hdr));
2924db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
293210c7c17SBenjamin Coddington int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
294577b4232STrond Myklebust 
29541d8d5b7SAnna Schumaker extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
2961e7f3a48SWeston Andros Adamson struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
2971e7f3a48SWeston Andros Adamson void nfs_pgio_header_free(struct nfs_pgio_header *);
298ef2c488cSAnna Schumaker int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
29946a5ab47SPeng Tao int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
300a52458b4SNeilBrown 		      const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
30146a5ab47SPeng Tao 		      const struct rpc_call_ops *call_ops, int how, int flags);
302d4581383SWeston Andros Adamson void nfs_free_request(struct nfs_page *req);
30348d635f1SPeng Tao struct nfs_pgio_mirror *
30448d635f1SPeng Tao nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
30500bfa30aSAnna Schumaker 
306138a2935STrond Myklebust static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
307138a2935STrond Myklebust 		const struct nfs_open_context *ctx2)
308138a2935STrond Myklebust {
309a52458b4SNeilBrown 	return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state;
310138a2935STrond Myklebust }
311138a2935STrond Myklebust 
312f7b422b1SDavid Howells /* nfs2xdr.c */
313499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs_procedures[];
314573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *,
315a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
316f7b422b1SDavid Howells 
317f7b422b1SDavid Howells /* nfs3xdr.c */
318499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs3_procedures[];
319573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *,
320a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
321f7b422b1SDavid Howells 
322f7b422b1SDavid Howells /* nfs4xdr.c */
32389d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
324573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *,
325a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
3267d4e2747SDavid Howells #endif
3272449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
3282449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead;
3292449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead;
330f1c097beSAndy Adamson extern const u32 nfs41_maxgetdevinfo_overhead;
3312449ea2eSAlexandros Batsakis #endif
332f7b422b1SDavid Howells 
333f7b422b1SDavid Howells /* nfs4proc.c */
33489d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
335499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs4_procedures[];
336d75d5414SAndrew Morton #endif
337f7b422b1SDavid Howells 
338694e096fSAnna Schumaker #ifdef CONFIG_NFS_V4_SECURITY_LABEL
339694e096fSAnna Schumaker extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
340a49c2691SKinglong Mee static inline struct nfs4_label *
341a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
342a49c2691SKinglong Mee {
343a49c2691SKinglong Mee 	if (!dst || !src)
344a49c2691SKinglong Mee 		return NULL;
345a49c2691SKinglong Mee 
346a49c2691SKinglong Mee 	if (src->len > NFS4_MAXLABELLEN)
347a49c2691SKinglong Mee 		return NULL;
348a49c2691SKinglong Mee 
349a49c2691SKinglong Mee 	dst->lfs = src->lfs;
350a49c2691SKinglong Mee 	dst->pi = src->pi;
351a49c2691SKinglong Mee 	dst->len = src->len;
352a49c2691SKinglong Mee 	memcpy(dst->label, src->label, src->len);
353a49c2691SKinglong Mee 
354a49c2691SKinglong Mee 	return dst;
355a49c2691SKinglong Mee }
356fd1defc2STrond Myklebust 
357fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
358fd1defc2STrond Myklebust {
359fd1defc2STrond Myklebust 	if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
360fd1defc2STrond Myklebust 		nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
361fd1defc2STrond Myklebust }
362694e096fSAnna Schumaker #else
363694e096fSAnna Schumaker static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
364fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
365fd1defc2STrond Myklebust {
366fd1defc2STrond Myklebust }
367a49c2691SKinglong Mee static inline struct nfs4_label *
368a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
369a49c2691SKinglong Mee {
370a49c2691SKinglong Mee 	return NULL;
371a49c2691SKinglong Mee }
372694e096fSAnna Schumaker #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
373694e096fSAnna Schumaker 
3747fe5c398STrond Myklebust /* proc.c */
3757fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
3768cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
3775c6e5b60STrond Myklebust 			   const struct nfs_client_initdata *);
3787fe5c398STrond Myklebust 
379979df72eSTrond Myklebust /* dir.c */
380230bc98fSTrond Myklebust extern void nfs_readdir_record_entry_cache_hit(struct inode *dir);
381230bc98fSTrond Myklebust extern void nfs_readdir_record_entry_cache_miss(struct inode *dir);
3821ab6c499SDave Chinner extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
3831ab6c499SDave Chinner 					    struct shrink_control *sc);
3841ab6c499SDave Chinner extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
3851495f230SYing Han 					   struct shrink_control *sc);
386597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
38700bdadc7STrond Myklebust void nfs_d_prune_case_insensitive_aliases(struct inode *inode);
3886c960e68SChristian Brauner int nfs_create(struct mnt_idmap *, struct inode *, struct dentry *,
389549c7297SChristian Brauner 	       umode_t, bool);
390c54bd91eSChristian Brauner int nfs_mkdir(struct mnt_idmap *, struct inode *, struct dentry *,
391549c7297SChristian Brauner 	      umode_t);
392597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *);
393597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *);
3947a77db95SChristian Brauner int nfs_symlink(struct mnt_idmap *, struct inode *, struct dentry *,
395549c7297SChristian Brauner 		const char *);
396597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *);
3975ebb29beSChristian Brauner int nfs_mknod(struct mnt_idmap *, struct inode *, struct dentry *, umode_t,
398549c7297SChristian Brauner 	      dev_t);
399e18275aeSChristian Brauner int nfs_rename(struct mnt_idmap *, struct inode *, struct dentry *,
4001cd66c93SMiklos Szeredi 	       struct inode *, struct dentry *, unsigned int);
401979df72eSTrond Myklebust 
40284631f84STrond Myklebust #ifdef CONFIG_NFS_V4_2
40384631f84STrond Myklebust static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server)
40484631f84STrond Myklebust {
40584631f84STrond Myklebust 	if (!(server->caps & NFS_CAP_XATTR))
40684631f84STrond Myklebust 		return 0;
40784631f84STrond Myklebust 	return NFS4_ACCESS_XAREAD | NFS4_ACCESS_XAWRITE | NFS4_ACCESS_XALIST;
40884631f84STrond Myklebust }
40984631f84STrond Myklebust #else
41084631f84STrond Myklebust static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server)
41184631f84STrond Myklebust {
41284631f84STrond Myklebust 	return 0;
41384631f84STrond Myklebust }
41484631f84STrond Myklebust #endif
41584631f84STrond Myklebust 
416ce4ef7c0SBryan Schumaker /* file.c */
4174ff79bc7SChristoph Hellwig int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
418ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int);
4193aa2d199SAl Viro ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
420ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *);
421edaf4369SAl Viro ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
422ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *);
423ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *);
424ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *);
425ce4ef7c0SBryan Schumaker int nfs_check_flags(int);
426ce4ef7c0SBryan Schumaker 
427f7b422b1SDavid Howells /* inode.c */
4285746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
429f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
430ca1a199eSAl Viro extern void nfs_free_inode(struct inode *);
431a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *);
432eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *);
43319d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *);
434b57922d9SAl Viro extern void nfs_evict_inode(struct inode *);
435fd6d3feeSTrond Myklebust extern void nfs_zap_acl_cache(struct inode *inode);
436fd6d3feeSTrond Myklebust extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags);
43761540bf6STrond Myklebust extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
438dfd01f02SPeter Zijlstra extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
439f7b422b1SDavid Howells 
440f7b422b1SDavid Howells /* super.c */
4416a74490dSBryan Schumaker extern const struct super_operations nfs_sops;
4424d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
443f2aedb71SDavid Howells int nfs_try_get_tree(struct fs_context *);
444f2aedb71SDavid Howells int nfs_get_tree_common(struct fs_context *);
445fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *);
4464ebd9ab3SDominik Hackl 
447f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
4484ebd9ab3SDominik Hackl 
449f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
450f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
451ea7c38feSTrond Myklebust extern bool nfs_sb_active(struct super_block *sb);
4521daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb);
4533c9e502bSTrond Myklebust extern int nfs_client_for_each_server(struct nfs_client *clp,
4543c9e502bSTrond Myklebust 				      int (*fn)(struct nfs_server *, void *),
4553c9e502bSTrond Myklebust 				      void *data);
456000dbe0bSDave Wysochanski #ifdef CONFIG_NFS_FSCACHE
457000dbe0bSDave Wysochanski extern const struct netfs_request_ops nfs_netfs_ops;
458000dbe0bSDave Wysochanski #endif
459000dbe0bSDave Wysochanski 
460a5864c99STrond Myklebust /* io.c */
461a5864c99STrond Myklebust extern void nfs_start_io_read(struct inode *inode);
462a5864c99STrond Myklebust extern void nfs_end_io_read(struct inode *inode);
463a5864c99STrond Myklebust extern void nfs_start_io_write(struct inode *inode);
464a5864c99STrond Myklebust extern void nfs_end_io_write(struct inode *inode);
465a5864c99STrond Myklebust extern void nfs_start_io_direct(struct inode *inode);
466a5864c99STrond Myklebust extern void nfs_end_io_direct(struct inode *inode);
467a5864c99STrond Myklebust 
468651b0e70STrond Myklebust static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
469651b0e70STrond Myklebust {
470651b0e70STrond Myklebust 	return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
471651b0e70STrond Myklebust }
472651b0e70STrond Myklebust 
473f7b422b1SDavid Howells /* namespace.c */
47497a54868SBen Hutchings #define NFS_PATH_CANONICAL 1
475b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry,
47697a54868SBen Hutchings 		      char *buffer, ssize_t buflen, unsigned flags);
47736d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path);
478f2aedb71SDavid Howells int nfs_submount(struct fs_context *, struct nfs_server *);
479f2aedb71SDavid Howells int nfs_do_submount(struct fs_context *);
480f7b422b1SDavid Howells 
48154ceac45SDavid Howells /* getroot.c */
48262a55d08SScott Mayhew extern int nfs_get_root(struct super_block *s, struct fs_context *fc);
48389d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
4845e6b1990STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
4857d4e2747SDavid Howells #endif
486f7b422b1SDavid Howells 
487061ae2edSFred Isaman struct nfs_pgio_completion_ops;
488f11c88afSAndy Adamson /* read.c */
489000dbe0bSDave Wysochanski extern const struct nfs_pgio_completion_ops nfs_async_read_completion_ops;
490584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
491fab5fc25SChristoph Hellwig 			struct inode *inode, bool force_mds,
492584aa810SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
493000dbe0bSDave Wysochanski extern int nfs_read_add_folio(struct nfs_pageio_descriptor *pgio,
494000dbe0bSDave Wysochanski 			       struct nfs_open_context *ctx,
495000dbe0bSDave Wysochanski 			       struct folio *folio);
496000dbe0bSDave Wysochanski extern void nfs_pageio_complete_read(struct nfs_pageio_descriptor *pgio);
497f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
498493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
499e885de1aSTrond Myklebust 
500fbdefd64SBryan Schumaker /* super.c */
501fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *);
502fbdefd64SBryan Schumaker int  nfs_statfs(struct dentry *, struct kstatfs *);
503fbdefd64SBryan Schumaker int  nfs_show_options(struct seq_file *, struct dentry *);
504fbdefd64SBryan Schumaker int  nfs_show_devname(struct seq_file *, struct dentry *);
505fbdefd64SBryan Schumaker int  nfs_show_path(struct seq_file *, struct dentry *);
506fbdefd64SBryan Schumaker int  nfs_show_stats(struct seq_file *, struct dentry *);
507f2aedb71SDavid Howells int  nfs_reconfigure(struct fs_context *);
508fbdefd64SBryan Schumaker 
509def6ed7eSAndy Adamson /* write.c */
5101763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
511a20c93e3SChristoph Hellwig 			struct inode *inode, int ioflags, bool force_mds,
5121763da12SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
513dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
5140b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p);
5150b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
5160b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt,
5170b7c0153SFred Isaman 			       struct nfs_commit_data *data,
518c36aae9aSPeng Tao 			       const struct nfs_rpc_ops *nfs_ops,
519e0c2b380SFred Isaman 			       const struct rpc_call_ops *call_ops,
5209f0ec176SAndy Adamson 			       int how, int flags);
5210b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data,
522e0c2b380SFred Isaman 			    struct list_head *head,
523f453a54aSFred Isaman 			    struct pnfs_layout_segment *lseg,
524f453a54aSFred Isaman 			    struct nfs_commit_info *cinfo);
5251763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
5261763da12SFred Isaman 			 struct nfs_commit_info *cinfo, int max);
527ce59515cSAnna Schumaker unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
5281763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst,
5291763da12SFred Isaman 		    struct nfs_commit_info *cinfo);
5301763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req,
5311763da12SFred Isaman 			     struct pnfs_layout_segment *lseg,
532b57ff130SWeston Andros Adamson 			     struct nfs_commit_info *cinfo,
533b57ff130SWeston Andros Adamson 			     u32 ds_commit_idx);
534c65e6254SWeston Andros Adamson int nfs_write_need_commit(struct nfs_pgio_header *);
535a08a8cd3STrond Myklebust void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
5361763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
5371763da12SFred Isaman 			    int how, struct nfs_commit_info *cinfo);
538e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list,
539ea2cf228SFred Isaman 		      struct pnfs_layout_segment *lseg,
540b57ff130SWeston Andros Adamson 		      struct nfs_commit_info *cinfo,
541b57ff130SWeston Andros Adamson 		      u32 ds_commit_idx);
5420b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data);
5436272dcc6SAnna Schumaker void nfs_request_add_commit_list(struct nfs_page *req,
544ea2cf228SFred Isaman 				 struct nfs_commit_info *cinfo);
54586d80f97STrond Myklebust void nfs_request_add_commit_list_locked(struct nfs_page *req,
54686d80f97STrond Myklebust 		struct list_head *dst,
54786d80f97STrond Myklebust 		struct nfs_commit_info *cinfo);
548ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req,
549ea2cf228SFred Isaman 				    struct nfs_commit_info *cinfo);
550ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo,
551ea2cf228SFred Isaman 		    struct inode *inode,
552ea2cf228SFred Isaman 		    struct nfs_direct_req *dreq);
553dc24826bSAndy Adamson int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
554ce52914eSScott Mayhew bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode);
555a7d42ddbSWeston Andros Adamson void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
556e0c2b380SFred Isaman 
557837bb1d7STrond Myklebust int nfs_filemap_write_and_wait_range(struct address_space *mapping,
558837bb1d7STrond Myklebust 		loff_t lstart, loff_t lend);
559837bb1d7STrond Myklebust 
560a5314a74STrond Myklebust #ifdef CONFIG_NFS_V4_1
561e3b9f7e6STrond Myklebust static inline void
562e3b9f7e6STrond Myklebust pnfs_bucket_clear_pnfs_ds_commit_verifiers(struct pnfs_commit_bucket *buckets,
563e3b9f7e6STrond Myklebust 		unsigned int nbuckets)
564e3b9f7e6STrond Myklebust {
565e3b9f7e6STrond Myklebust 	unsigned int i;
566e3b9f7e6STrond Myklebust 
567e3b9f7e6STrond Myklebust 	for (i = 0; i < nbuckets; i++)
568e3b9f7e6STrond Myklebust 		buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
569e3b9f7e6STrond Myklebust }
570a5314a74STrond Myklebust static inline
571a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
572a5314a74STrond Myklebust {
573e3b9f7e6STrond Myklebust 	struct pnfs_commit_array *array;
574a5314a74STrond Myklebust 
575a9901899STrond Myklebust 	rcu_read_lock();
576a9901899STrond Myklebust 	list_for_each_entry_rcu(array, &cinfo->commits, cinfo_list)
577e3b9f7e6STrond Myklebust 		pnfs_bucket_clear_pnfs_ds_commit_verifiers(array->buckets,
578e3b9f7e6STrond Myklebust 				array->nbuckets);
579a9901899STrond Myklebust 	rcu_read_unlock();
580a5314a74STrond Myklebust }
581a5314a74STrond Myklebust #else
582a5314a74STrond Myklebust static inline
583a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
584a5314a74STrond Myklebust {
585a5314a74STrond Myklebust }
586a5314a74STrond Myklebust #endif
587a5314a74STrond Myklebust 
588074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION
5894ae84a80SMatthew Wilcox (Oracle) int nfs_migrate_folio(struct address_space *, struct folio *dst,
5904ae84a80SMatthew Wilcox (Oracle) 		struct folio *src, enum migrate_mode);
5914ae84a80SMatthew Wilcox (Oracle) #else
5924ae84a80SMatthew Wilcox (Oracle) #define nfs_migrate_folio NULL
593074cc1deSTrond Myklebust #endif
594def6ed7eSAndy Adamson 
5958fc3c386STrond Myklebust static inline int
5968fc3c386STrond Myklebust nfs_write_verifier_cmp(const struct nfs_write_verifier *v1,
5978fc3c386STrond Myklebust 		const struct nfs_write_verifier *v2)
5988fc3c386STrond Myklebust {
5998fc3c386STrond Myklebust 	return memcmp(v1->data, v2->data, sizeof(v1->data));
6008fc3c386STrond Myklebust }
6018fc3c386STrond Myklebust 
6021f28476dSTrond Myklebust static inline bool
6031f28476dSTrond Myklebust nfs_write_match_verf(const struct nfs_writeverf *verf,
6041f28476dSTrond Myklebust 		struct nfs_page *req)
6051f28476dSTrond Myklebust {
6061f28476dSTrond Myklebust 	return verf->committed > NFS_UNSTABLE &&
6071f28476dSTrond Myklebust 		!nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier);
6081f28476dSTrond Myklebust }
6091f28476dSTrond Myklebust 
610515dcdcdSTrond Myklebust static inline gfp_t nfs_io_gfp_mask(void)
611515dcdcdSTrond Myklebust {
612515dcdcdSTrond Myklebust 	if (current->flags & PF_WQ_WORKER)
613515dcdcdSTrond Myklebust 		return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
614515dcdcdSTrond Myklebust 	return GFP_KERNEL;
615515dcdcdSTrond Myklebust }
616515dcdcdSTrond Myklebust 
617d7a51186SAnna Schumaker /*
618d7a51186SAnna Schumaker  * Special version of should_remove_suid() that ignores capabilities.
619d7a51186SAnna Schumaker  */
620d7a51186SAnna Schumaker static inline int nfs_should_remove_suid(const struct inode *inode)
621d7a51186SAnna Schumaker {
622d7a51186SAnna Schumaker 	umode_t mode = inode->i_mode;
623d7a51186SAnna Schumaker 	int kill = 0;
624d7a51186SAnna Schumaker 
625d7a51186SAnna Schumaker 	/* suid always must be killed */
626d7a51186SAnna Schumaker 	if (unlikely(mode & S_ISUID))
627d7a51186SAnna Schumaker 		kill = ATTR_KILL_SUID;
628d7a51186SAnna Schumaker 
629d7a51186SAnna Schumaker 	/*
630d7a51186SAnna Schumaker 	 * sgid without any exec bits is just a mandatory locking mark; leave
631d7a51186SAnna Schumaker 	 * it alone.  If some exec bits are set, it's a real sgid; kill it.
632d7a51186SAnna Schumaker 	 */
633d7a51186SAnna Schumaker 	if (unlikely((mode & S_ISGID) && (mode & S_IXGRP)))
634d7a51186SAnna Schumaker 		kill |= ATTR_KILL_SGID;
635d7a51186SAnna Schumaker 
636d7a51186SAnna Schumaker 	if (unlikely(kill && S_ISREG(mode)))
637d7a51186SAnna Schumaker 		return kill;
638d7a51186SAnna Schumaker 
639d7a51186SAnna Schumaker 	return 0;
640d7a51186SAnna Schumaker }
641d7a51186SAnna Schumaker 
6420e862a40SJeff Layton /* unlink.c */
6430e862a40SJeff Layton extern struct rpc_task *
6440e862a40SJeff Layton nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
6450e862a40SJeff Layton 		 struct dentry *old_dentry, struct dentry *new_dentry,
6460e862a40SJeff Layton 		 void (*complete)(struct rpc_task *, struct nfs_renamedata *));
6470e862a40SJeff Layton extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
6480e862a40SJeff Layton 
6491763da12SFred Isaman /* direct.c */
6501763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
6511763da12SFred Isaman 			      struct nfs_direct_req *dreq);
6526296556fSPeng Tao extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
6531763da12SFred Isaman 
654cccef3b9SAndy Adamson /* nfs4proc.c */
6558cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
6565c6e5b60STrond Myklebust 			    const struct nfs_client_initdata *);
65705f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp,
65805f4c350SChuck Lever 				struct nfs_client **result,
659a52458b4SNeilBrown 				const struct cred *cred);
66005f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp,
66105f4c350SChuck Lever 				struct nfs_client **result,
662a52458b4SNeilBrown 				const struct cred *cred);
66310e037d1SSantosh kumar pradhan extern void nfs4_test_session_trunk(struct rpc_clnt *clnt,
66410e037d1SSantosh kumar pradhan 				struct rpc_xprt *xprt,
66510e037d1SSantosh kumar pradhan 				void *data);
666cccef3b9SAndy Adamson 
667ea7c38feSTrond Myklebust static inline struct inode *nfs_igrab_and_active(struct inode *inode)
668ea7c38feSTrond Myklebust {
669896567eeSTrond Myklebust 	struct super_block *sb = inode->i_sb;
670896567eeSTrond Myklebust 
671896567eeSTrond Myklebust 	if (sb && nfs_sb_active(sb)) {
672896567eeSTrond Myklebust 		if (igrab(inode))
673ea7c38feSTrond Myklebust 			return inode;
674896567eeSTrond Myklebust 		nfs_sb_deactive(sb);
675896567eeSTrond Myklebust 	}
676896567eeSTrond Myklebust 	return NULL;
677ea7c38feSTrond Myklebust }
678ea7c38feSTrond Myklebust 
679ea7c38feSTrond Myklebust static inline void nfs_iput_and_deactive(struct inode *inode)
680ea7c38feSTrond Myklebust {
681ea7c38feSTrond Myklebust 	if (inode != NULL) {
682ea7c38feSTrond Myklebust 		struct super_block *sb = inode->i_sb;
683ea7c38feSTrond Myklebust 
684ea7c38feSTrond Myklebust 		iput(inode);
685ea7c38feSTrond Myklebust 		nfs_sb_deactive(sb);
686ea7c38feSTrond Myklebust 	}
687ea7c38feSTrond Myklebust }
688ea7c38feSTrond Myklebust 
689557134a3SAndy Adamson /*
690f7b422b1SDavid Howells  * Determine the device name as a string
691f7b422b1SDavid Howells  */
692b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry,
693f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
694f7b422b1SDavid Howells {
695b514f872SAl Viro 	char *dummy;
69697a54868SBen Hutchings 	return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
697f7b422b1SDavid Howells }
698f7b422b1SDavid Howells 
699f7b422b1SDavid Howells /*
700f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
701f7b422b1SDavid Howells  */
702f7b422b1SDavid Howells static inline
703f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
704f7b422b1SDavid Howells {
705f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
706f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
707f7b422b1SDavid Howells 		unsigned char	nrbits;
708f7b422b1SDavid Howells 
709f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
710f7b422b1SDavid Howells 			;
711f7b422b1SDavid Howells 		bsize = 1 << nrbits;
712f7b422b1SDavid Howells 		if (nrbitsp)
713f7b422b1SDavid Howells 			*nrbitsp = nrbits;
714f7b422b1SDavid Howells 	}
715f7b422b1SDavid Howells 
716f7b422b1SDavid Howells 	return bsize;
717f7b422b1SDavid Howells }
718f7b422b1SDavid Howells 
719f7b422b1SDavid Howells /*
720f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
721f7b422b1SDavid Howells  */
7229eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
723f7b422b1SDavid Howells {
7249eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
725f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
726f7b422b1SDavid Howells }
727f7b422b1SDavid Howells 
728f7b422b1SDavid Howells /*
729f7b422b1SDavid Howells  * Compute and set NFS server blocksize
730f7b422b1SDavid Howells  */
731f7b422b1SDavid Howells static inline
732f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
733f7b422b1SDavid Howells {
734f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
735f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
736f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
737f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
738f7b422b1SDavid Howells 
739f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
740f7b422b1SDavid Howells }
741f7b422b1SDavid Howells 
742f7b422b1SDavid Howells /*
743940261a1SAnna Schumaker  * Compute and set NFS server rsize / wsize
744940261a1SAnna Schumaker  */
745940261a1SAnna Schumaker static inline
746940261a1SAnna Schumaker unsigned long nfs_io_size(unsigned long iosize, enum xprt_transports proto)
747940261a1SAnna Schumaker {
748940261a1SAnna Schumaker 	if (iosize < NFS_MIN_FILE_IO_SIZE)
749940261a1SAnna Schumaker 		iosize = NFS_DEF_FILE_IO_SIZE;
750940261a1SAnna Schumaker 	else if (iosize >= NFS_MAX_FILE_IO_SIZE)
751940261a1SAnna Schumaker 		iosize = NFS_MAX_FILE_IO_SIZE;
752940261a1SAnna Schumaker 
753a60214c2SAnna Schumaker 	if (proto == XPRT_TRANSPORT_UDP || iosize < PAGE_SIZE)
754940261a1SAnna Schumaker 		return nfs_block_bits(iosize, NULL);
755a60214c2SAnna Schumaker 	return iosize & PAGE_MASK;
756940261a1SAnna Schumaker }
757940261a1SAnna Schumaker 
758940261a1SAnna Schumaker /*
759f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
760f7b422b1SDavid Howells  */
761f7b422b1SDavid Howells static inline
762f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
763f7b422b1SDavid Howells {
764f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
765f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
766f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
767f7b422b1SDavid Howells }
76849a70f27STrond Myklebust 
76949a70f27STrond Myklebust /*
7708d92890bSNeilBrown  * Record the page as unstable (an extra writeback period) and mark its
7718d92890bSNeilBrown  * inode as dirty.
772d15bc38dSTom Haynes  */
7730c493b5cSTrond Myklebust static inline void nfs_folio_mark_unstable(struct folio *folio,
7740c493b5cSTrond Myklebust 					   struct nfs_commit_info *cinfo)
775d15bc38dSTom Haynes {
7760c493b5cSTrond Myklebust 	if (folio && !cinfo->dreq) {
7770c493b5cSTrond Myklebust 		struct inode *inode = folio_file_mapping(folio)->host;
7780c493b5cSTrond Myklebust 		long nr = folio_nr_pages(folio);
779d15bc38dSTom Haynes 
7808d92890bSNeilBrown 		/* This page is really still in write-back - just that the
7818d92890bSNeilBrown 		 * writeback is happening on the server now.
7828d92890bSNeilBrown 		 */
7830c493b5cSTrond Myklebust 		node_stat_mod_folio(folio, NR_WRITEBACK, nr);
7840c493b5cSTrond Myklebust 		wb_stat_mod(&inode_to_bdi(inode)->wb, WB_WRITEBACK, nr);
785d15bc38dSTom Haynes 		__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
786d15bc38dSTom Haynes 	}
78786d80f97STrond Myklebust }
788d15bc38dSTom Haynes 
789d15bc38dSTom Haynes /*
79049a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
79149a70f27STrond Myklebust  */
79249a70f27STrond Myklebust static inline
79349a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
79449a70f27STrond Myklebust {
795d56b4ddfSMel Gorman 	loff_t i_size = i_size_read(page_file_mapping(page)->host);
79649a70f27STrond Myklebust 
79749a70f27STrond Myklebust 	if (i_size > 0) {
7988cd79788SHuang Ying 		pgoff_t index = page_index(page);
79909cbfeafSKirill A. Shutemov 		pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT;
8008cd79788SHuang Ying 		if (index < end_index)
80109cbfeafSKirill A. Shutemov 			return PAGE_SIZE;
8028cd79788SHuang Ying 		if (index == end_index)
80309cbfeafSKirill A. Shutemov 			return ((i_size - 1) & ~PAGE_MASK) + 1;
80449a70f27STrond Myklebust 	}
80549a70f27STrond Myklebust 	return 0;
80649a70f27STrond Myklebust }
8078d5658c9STrond Myklebust 
8088d5658c9STrond Myklebust /*
809ab75bff1STrond Myklebust  * Determine the number of bytes of data the page contains
810ab75bff1STrond Myklebust  */
811ab75bff1STrond Myklebust static inline size_t nfs_folio_length(struct folio *folio)
812ab75bff1STrond Myklebust {
813ab75bff1STrond Myklebust 	loff_t i_size = i_size_read(folio_file_mapping(folio)->host);
814ab75bff1STrond Myklebust 
815ab75bff1STrond Myklebust 	if (i_size > 0) {
816ab75bff1STrond Myklebust 		pgoff_t index = folio_index(folio) >> folio_order(folio);
817ab75bff1STrond Myklebust 		pgoff_t end_index = (i_size - 1) >> folio_shift(folio);
818ab75bff1STrond Myklebust 		if (index < end_index)
819ab75bff1STrond Myklebust 			return folio_size(folio);
820ab75bff1STrond Myklebust 		if (index == end_index)
821ab75bff1STrond Myklebust 			return offset_in_folio(folio, i_size - 1) + 1;
822ab75bff1STrond Myklebust 	}
823ab75bff1STrond Myklebust 	return 0;
824ab75bff1STrond Myklebust }
825ab75bff1STrond Myklebust 
826ab75bff1STrond Myklebust /*
8270b26a0bfSTrond Myklebust  * Convert a umode to a dirent->d_type
8280b26a0bfSTrond Myklebust  */
8290b26a0bfSTrond Myklebust static inline
8300b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode)
8310b26a0bfSTrond Myklebust {
8320b26a0bfSTrond Myklebust 	return (mode >> 12) & 15;
8330b26a0bfSTrond Myklebust }
8340b26a0bfSTrond Myklebust 
8350b26a0bfSTrond Myklebust /*
8368d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
8378d5658c9STrond Myklebust  * with a base offset of 'base'
8388d5658c9STrond Myklebust  */
839eb9f2a5aSTrond Myklebust static inline unsigned int nfs_page_array_len(unsigned int base, size_t len)
8408d5658c9STrond Myklebust {
841eb9f2a5aSTrond Myklebust 	return ((unsigned long)len + (unsigned long)base + PAGE_SIZE - 1) >>
842eb9f2a5aSTrond Myklebust 	       PAGE_SHIFT;
8438d5658c9STrond Myklebust }
8440110ee15STrond Myklebust 
8453a1556e8STrond Myklebust /*
846ae08483cSArnd Bergmann  * Convert a struct timespec64 into a 64-bit change attribute
8473a1556e8STrond Myklebust  *
848ae08483cSArnd Bergmann  * This does approximately the same thing as timespec64_to_ns(),
8493a1556e8STrond Myklebust  * but for calculation efficiency, we multiply the seconds by
8503a1556e8STrond Myklebust  * 1024*1024*1024.
8513a1556e8STrond Myklebust  */
8523a1556e8STrond Myklebust static inline
853e86d5a02STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec64 *ts)
8543a1556e8STrond Myklebust {
8553a1556e8STrond Myklebust 	return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
8563a1556e8STrond Myklebust }
8571264a2f0STrond Myklebust 
8581264a2f0STrond Myklebust #ifdef CONFIG_CRC32
85948c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid)
86048c9579aSOlga Kornievskaia {
86148c9579aSOlga Kornievskaia 	return ~crc32_le(0xFFFFFFFF, &stateid->other[0],
86248c9579aSOlga Kornievskaia 				NFS4_STATEID_OTHER_SIZE);
86348c9579aSOlga Kornievskaia }
8641264a2f0STrond Myklebust #else
86548c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
86648c9579aSOlga Kornievskaia {
86748c9579aSOlga Kornievskaia 	return 0;
86848c9579aSOlga Kornievskaia }
8691264a2f0STrond Myklebust #endif
8700bcbf039SPeng Tao 
8710bcbf039SPeng Tao static inline bool nfs_error_is_fatal(int err)
8720bcbf039SPeng Tao {
8730bcbf039SPeng Tao 	switch (err) {
8740bcbf039SPeng Tao 	case -ERESTARTSYS:
8757dc58ca5STrond Myklebust 	case -EINTR:
87654551d85STrond Myklebust 	case -EACCES:
87754551d85STrond Myklebust 	case -EDQUOT:
87854551d85STrond Myklebust 	case -EFBIG:
8790bcbf039SPeng Tao 	case -EIO:
8800bcbf039SPeng Tao 	case -ENOSPC:
8810bcbf039SPeng Tao 	case -EROFS:
88254551d85STrond Myklebust 	case -ESTALE:
8830bcbf039SPeng Tao 	case -E2BIG:
8842dc23affSTrond Myklebust 	case -ENOMEM:
88511982a7cSTrond Myklebust 	case -ETIMEDOUT:
8860bcbf039SPeng Tao 		return true;
8870bcbf039SPeng Tao 	default:
8880bcbf039SPeng Tao 		return false;
8890bcbf039SPeng Tao 	}
8900bcbf039SPeng Tao }
891bf4b4905SNeilBrown 
8928f54c7a4STrond Myklebust static inline bool nfs_error_is_fatal_on_server(int err)
8938f54c7a4STrond Myklebust {
8948f54c7a4STrond Myklebust 	switch (err) {
8958f54c7a4STrond Myklebust 	case 0:
8968f54c7a4STrond Myklebust 	case -ERESTARTSYS:
8978f54c7a4STrond Myklebust 	case -EINTR:
89845228440STrond Myklebust 	case -ENOMEM:
8998f54c7a4STrond Myklebust 		return false;
9008f54c7a4STrond Myklebust 	}
9018f54c7a4STrond Myklebust 	return nfs_error_is_fatal(err);
9028f54c7a4STrond Myklebust }
9039954bf92SDavid Howells 
9049954bf92SDavid Howells /*
9059954bf92SDavid Howells  * Select between a default port value and a user-specified port value.
9069954bf92SDavid Howells  * If a zero value is set, then autobind will be used.
9079954bf92SDavid Howells  */
908cf0d7e7fSKees Cook static inline void nfs_set_port(struct sockaddr_storage *sap, int *port,
9099954bf92SDavid Howells 				const unsigned short default_port)
9109954bf92SDavid Howells {
9119954bf92SDavid Howells 	if (*port == NFS_UNSPEC_PORT)
9129954bf92SDavid Howells 		*port = default_port;
9139954bf92SDavid Howells 
914cf0d7e7fSKees Cook 	rpc_set_port((struct sockaddr *)sap, *port);
9159954bf92SDavid Howells }
9168efc4bbeSJeff Layton 
9178efc4bbeSJeff Layton struct nfs_direct_req {
9188efc4bbeSJeff Layton 	struct kref		kref;		/* release manager */
9198efc4bbeSJeff Layton 
9208efc4bbeSJeff Layton 	/* I/O parameters */
9218efc4bbeSJeff Layton 	struct nfs_open_context	*ctx;		/* file open context info */
9228efc4bbeSJeff Layton 	struct nfs_lock_context *l_ctx;		/* Lock context info */
9238efc4bbeSJeff Layton 	struct kiocb *		iocb;		/* controlling i/o request */
9248efc4bbeSJeff Layton 	struct inode *		inode;		/* target file of i/o */
9258efc4bbeSJeff Layton 
9268efc4bbeSJeff Layton 	/* completion state */
9278efc4bbeSJeff Layton 	atomic_t		io_count;	/* i/os we're waiting for */
9288efc4bbeSJeff Layton 	spinlock_t		lock;		/* protect completion state */
9298efc4bbeSJeff Layton 
9308efc4bbeSJeff Layton 	loff_t			io_start;	/* Start offset for I/O */
9318efc4bbeSJeff Layton 	ssize_t			count,		/* bytes actually processed */
9328efc4bbeSJeff Layton 				max_count,	/* max expected count */
9338efc4bbeSJeff Layton 				bytes_left,	/* bytes left to be sent */
9348efc4bbeSJeff Layton 				error;		/* any reported error */
9358efc4bbeSJeff Layton 	struct completion	completion;	/* wait for i/o completion */
9368efc4bbeSJeff Layton 
9378efc4bbeSJeff Layton 	/* commit state */
9388efc4bbeSJeff Layton 	struct nfs_mds_commit_info mds_cinfo;	/* Storage for cinfo */
9398efc4bbeSJeff Layton 	struct pnfs_ds_commit_info ds_cinfo;	/* Storage for cinfo */
9408efc4bbeSJeff Layton 	struct work_struct	work;
9418efc4bbeSJeff Layton 	int			flags;
9428efc4bbeSJeff Layton 	/* for write */
9438efc4bbeSJeff Layton #define NFS_ODIRECT_DO_COMMIT		(1)	/* an unstable reply was received */
9448efc4bbeSJeff Layton #define NFS_ODIRECT_RESCHED_WRITES	(2)	/* write verification failed */
9458efc4bbeSJeff Layton 	/* for read */
9468efc4bbeSJeff Layton #define NFS_ODIRECT_SHOULD_DIRTY	(3)	/* dirty user-space page after read */
9478efc4bbeSJeff Layton #define NFS_ODIRECT_DONE		INT_MAX	/* write verification failed */
9488efc4bbeSJeff Layton };
949