xref: /openbmc/linux/fs/nfs/internal.h (revision c54bd91e)
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;
84fcf10398SBryan Schumaker };
85fcf10398SBryan Schumaker 
8656e4ebf8SBryan Schumaker /*
876b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
886b18eaa0S\"Talpey, Thomas\  */
895eb005caSDavid Howells struct nfs_fs_context {
90f2aedb71SDavid Howells 	bool			internal;
91f2aedb71SDavid Howells 	bool			skip_reconfig_option_check;
92f2aedb71SDavid Howells 	bool			need_mount;
93f2aedb71SDavid Howells 	bool			sloppy;
94e558100fSDavid Howells 	unsigned int		flags;		/* NFS{,4}_MOUNT_* flags */
958cb7f74eSChuck Lever 	unsigned int		rsize, wsize;
968cb7f74eSChuck Lever 	unsigned int		timeo, retrans;
97e558100fSDavid Howells 	unsigned int		acregmin, acregmax;
98e558100fSDavid Howells 	unsigned int		acdirmin, acdirmax;
998cb7f74eSChuck Lever 	unsigned int		namlen;
100b797cac7SDavid Howells 	unsigned int		options;
1016b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
102a3f73c27SWeston Andros Adamson 	struct nfs_auth_info	auth_info;
103a3f73c27SWeston Andros Adamson 	rpc_authflavor_t	selected_flavor;
1046b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
105764302ccSChuck Lever 	unsigned int		version;
1063fd5be9eSMike Sager 	unsigned int		minorversion;
10708734048SDavid Howells 	char			*fscache_uniq;
108f8ee01e3SDavid Howells 	unsigned short		protofamily;
109f8ee01e3SDavid Howells 	unsigned short		mountfamily;
110ec1ade6aSOlga Kornievskaia 	bool			has_sec_mnt_opts;
1116b18eaa0S\"Talpey, Thomas\ 
1126b18eaa0S\"Talpey, Thomas\ 	struct {
113e558100fSDavid Howells 		union {
114e558100fSDavid Howells 			struct sockaddr	address;
115e558100fSDavid Howells 			struct sockaddr_storage	_address;
116e558100fSDavid Howells 		};
1174c568017SChuck Lever 		size_t			addrlen;
1186b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
11978fa701fSChuck Lever 		u32			version;
1204cfd74fcSChuck Lever 		int			port;
12178fa701fSChuck Lever 		unsigned short		protocol;
1226b18eaa0S\"Talpey, Thomas\ 	} mount_server;
1236b18eaa0S\"Talpey, Thomas\ 
1246b18eaa0S\"Talpey, Thomas\ 	struct {
125e558100fSDavid Howells 		union {
126e558100fSDavid Howells 			struct sockaddr	address;
127e558100fSDavid Howells 			struct sockaddr_storage	_address;
128e558100fSDavid Howells 		};
1294c568017SChuck Lever 		size_t			addrlen;
1306b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
1316b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
1324cfd74fcSChuck Lever 		int			port;
13378fa701fSChuck Lever 		unsigned short		protocol;
13428cc5cd8STrond Myklebust 		unsigned short		nconnect;
1357e134205SOlga Kornievskaia 		unsigned short		max_connect;
136f2aedb71SDavid Howells 		unsigned short		export_path_len;
1376b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
138f9c3a380SEric Paris 
13962a55d08SScott Mayhew 	struct nfs_fh		*mntfh;
14062a55d08SScott Mayhew 	struct nfs_server	*server;
14162a55d08SScott Mayhew 	struct nfs_subversion	*nfs_mod;
14248be8a66SDavid Howells 
14362a55d08SScott Mayhew 	/* Information for a cloned mount. */
14462a55d08SScott Mayhew 	struct nfs_clone_mount {
14562a55d08SScott Mayhew 		struct super_block	*sb;
14662a55d08SScott Mayhew 		struct dentry		*dentry;
14762a55d08SScott Mayhew 		struct nfs_fattr	*fattr;
14862a55d08SScott Mayhew 		unsigned int		inherited_bsize;
14962a55d08SScott Mayhew 	} clone_data;
1506b18eaa0S\"Talpey, Thomas\ };
1516b18eaa0S\"Talpey, Thomas\ 
152c98e9daaSScott Mayhew #define nfs_errorf(fc, fmt, ...) ((fc)->log.log ?		\
153c98e9daaSScott Mayhew 	errorf(fc, fmt, ## __VA_ARGS__) :			\
154c98e9daaSScott Mayhew 	({ dprintk(fmt "\n", ## __VA_ARGS__); }))
155c98e9daaSScott Mayhew 
156c98e9daaSScott Mayhew #define nfs_ferrorf(fc, fac, fmt, ...) ((fc)->log.log ?		\
157c98e9daaSScott Mayhew 	errorf(fc, fmt, ## __VA_ARGS__) :			\
158c98e9daaSScott Mayhew 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
159c98e9daaSScott Mayhew 
160c98e9daaSScott Mayhew #define nfs_invalf(fc, fmt, ...) ((fc)->log.log ?		\
161c98e9daaSScott Mayhew 	invalf(fc, fmt, ## __VA_ARGS__) :			\
162c98e9daaSScott Mayhew 	({ dprintk(fmt "\n", ## __VA_ARGS__);  -EINVAL; }))
163c98e9daaSScott Mayhew 
164c98e9daaSScott Mayhew #define nfs_finvalf(fc, fac, fmt, ...) ((fc)->log.log ?		\
165c98e9daaSScott Mayhew 	invalf(fc, fmt, ## __VA_ARGS__) :			\
166c98e9daaSScott Mayhew 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__);  -EINVAL; }))
167c98e9daaSScott Mayhew 
168c98e9daaSScott Mayhew #define nfs_warnf(fc, fmt, ...) ((fc)->log.log ?		\
169c98e9daaSScott Mayhew 	warnf(fc, fmt, ## __VA_ARGS__) :			\
170c98e9daaSScott Mayhew 	({ dprintk(fmt "\n", ## __VA_ARGS__); }))
171c98e9daaSScott Mayhew 
172c98e9daaSScott Mayhew #define nfs_fwarnf(fc, fac, fmt, ...) ((fc)->log.log ?		\
173c98e9daaSScott Mayhew 	warnf(fc, fmt, ## __VA_ARGS__) :			\
174c98e9daaSScott Mayhew 	({ dfprintk(fac, fmt "\n", ## __VA_ARGS__); }))
175ce8866f0SScott Mayhew 
176f2aedb71SDavid Howells static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
177f2aedb71SDavid Howells {
178f2aedb71SDavid Howells 	return fc->fs_private;
179f2aedb71SDavid Howells }
180f2aedb71SDavid Howells 
181146ec944SChuck Lever /* mount_clnt.c */
182c5d120f8SChuck Lever struct nfs_mount_request {
183cf0d7e7fSKees Cook 	struct sockaddr_storage	*sap;
184c5d120f8SChuck Lever 	size_t			salen;
185c5d120f8SChuck Lever 	char			*hostname;
186c5d120f8SChuck Lever 	char			*dirpath;
187c5d120f8SChuck Lever 	u32			version;
188c5d120f8SChuck Lever 	unsigned short		protocol;
189c5d120f8SChuck Lever 	struct nfs_fh		*fh;
19050a737f8SChuck Lever 	int			noresvport;
1918e02f6b9SChuck Lever 	unsigned int		*auth_flav_len;
1928e02f6b9SChuck Lever 	rpc_authflavor_t	*auth_flavs;
1936d59b8d5SStanislav Kinsbursky 	struct net		*net;
194c5d120f8SChuck Lever };
195c5d120f8SChuck Lever 
196c9301cb3SEryu Guan extern int nfs_mount(struct nfs_mount_request *info, int timeo, int retrans);
1970b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info);
198146ec944SChuck Lever 
19924c8dbbbSDavid Howells /* client.c */
200a613fa16STrond Myklebust extern const struct rpc_program nfs_program;
2016b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net);
20210b7a70cSTrond Myklebust extern void nfs_clients_exit(struct net *net);
2036663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
2045c6e5b60STrond Myklebust int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
2057d38de3fSAnna Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
206e5731131SAnna Schumaker int nfs_probe_server(struct nfs_server *, struct nfs_fh *);
207fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *);
20832e62b7cSChuck Lever void nfs_server_remove_lists(struct nfs_server *);
209a956bedaSTrond Myklebust void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
210fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
211fcf10398SBryan Schumaker 		rpc_authflavor_t);
212fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void);
213fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
21454ceac45SDavid Howells 
21524c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
216cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *);
21728cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
218c36fca52SAndy Adamson extern struct nfs_client *
219c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
220459de2edSBryan Schumaker 				struct nfs4_sessionid *, u32);
22162a55d08SScott Mayhew extern struct nfs_server *nfs_create_server(struct fs_context *);
22201dde76eSAnna Schumaker extern void nfs4_server_set_init_caps(struct nfs_server *);
22362a55d08SScott Mayhew extern struct nfs_server *nfs4_create_server(struct fs_context *);
22462a55d08SScott Mayhew extern struct nfs_server *nfs4_create_referral_server(struct fs_context *);
22532e62b7cSChuck Lever extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
226cf0d7e7fSKees Cook 					struct sockaddr_storage *sap, size_t salen,
227292f503cSTrond Myklebust 					struct net *net);
22854ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
22954ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
23054ceac45SDavid Howells 					   struct nfs_fh *,
2317e6eb683SBryan Schumaker 					   struct nfs_fattr *,
2327e6eb683SBryan Schumaker 					   rpc_authflavor_t);
233a33e4b03SWeston Andros Adamson extern bool nfs_client_init_is_complete(const struct nfs_client *clp);
234a33e4b03SWeston Andros Adamson extern int nfs_client_init_status(const struct nfs_client *clp);
2354697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
23676db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
2373fc75f12STigran Mkrtchyan extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
238cf0d7e7fSKees Cook 					     const struct sockaddr_storage *ds_addr,
23998fc685aSAndy Adamson 					     int ds_addrlen, int ds_proto,
24098fc685aSAndy Adamson 					     unsigned int ds_timeo,
241064172f3SPeng Tao 					     unsigned int ds_retrans,
2427d38de3fSAnna Schumaker 					     u32 minor_version);
2430e20162eSAndy Adamson extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
2440e20162eSAndy Adamson 						struct inode *);
245b224f7cbSTigran Mkrtchyan extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
246cf0d7e7fSKees Cook 			const struct sockaddr_storage *ds_addr, int ds_addrlen,
2471a04c6e1SPeng Tao 			int ds_proto, unsigned int ds_timeo,
2487d38de3fSAnna Schumaker 			unsigned int ds_retrans);
2496aaca566SDavid Howells #ifdef CONFIG_PROC_FS
2506aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
2516aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
25265b38851SEric W. Biederman extern int nfs_fs_proc_net_init(struct net *net);
25365b38851SEric W. Biederman extern void nfs_fs_proc_net_exit(struct net *net);
2546aaca566SDavid Howells #else
25565b38851SEric W. Biederman static inline int nfs_fs_proc_net_init(struct net *net)
25665b38851SEric W. Biederman {
25765b38851SEric W. Biederman 	return 0;
25865b38851SEric W. Biederman }
25965b38851SEric W. Biederman static inline void nfs_fs_proc_net_exit(struct net *net)
26065b38851SEric W. Biederman {
26165b38851SEric W. Biederman }
2626aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
2636aaca566SDavid Howells {
2646aaca566SDavid Howells 	return 0;
2656aaca566SDavid Howells }
2666aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
2676aaca566SDavid Howells {
2686aaca566SDavid Howells }
2696aaca566SDavid Howells #endif
27024c8dbbbSDavid Howells 
271f7b422b1SDavid Howells /* callback_xdr.c */
272e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version1;
273e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version4;
274f7b422b1SDavid Howells 
275f2aedb71SDavid Howells /* fs_context.c */
276f2aedb71SDavid Howells extern struct file_system_type nfs_fs_type;
2779954bf92SDavid Howells 
278f7b422b1SDavid Howells /* pagelist.c */
279f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
280266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
281f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
282266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
283f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
284266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
285f7b422b1SDavid Howells 
286f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
287266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
2884db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
2894db6e0b7SFred Isaman 			      struct nfs_pgio_header *hdr,
2904db6e0b7SFred Isaman 			      void (*release)(struct nfs_pgio_header *hdr));
2914db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
292210c7c17SBenjamin Coddington int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
293577b4232STrond Myklebust 
29441d8d5b7SAnna Schumaker extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
2951e7f3a48SWeston Andros Adamson struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
2961e7f3a48SWeston Andros Adamson void nfs_pgio_header_free(struct nfs_pgio_header *);
297ef2c488cSAnna Schumaker int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
29846a5ab47SPeng Tao int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
299a52458b4SNeilBrown 		      const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
30046a5ab47SPeng Tao 		      const struct rpc_call_ops *call_ops, int how, int flags);
301d4581383SWeston Andros Adamson void nfs_free_request(struct nfs_page *req);
30248d635f1SPeng Tao struct nfs_pgio_mirror *
30348d635f1SPeng Tao nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
30400bfa30aSAnna Schumaker 
305138a2935STrond Myklebust static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
306138a2935STrond Myklebust 		const struct nfs_open_context *ctx2)
307138a2935STrond Myklebust {
308a52458b4SNeilBrown 	return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state;
309138a2935STrond Myklebust }
310138a2935STrond Myklebust 
311f7b422b1SDavid Howells /* nfs2xdr.c */
312499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs_procedures[];
313573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *,
314a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
315f7b422b1SDavid Howells 
316f7b422b1SDavid Howells /* nfs3xdr.c */
317499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs3_procedures[];
318573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *,
319a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
320f7b422b1SDavid Howells 
321f7b422b1SDavid Howells /* nfs4xdr.c */
32289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
323573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *,
324a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
3257d4e2747SDavid Howells #endif
3262449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
3272449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead;
3282449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead;
329f1c097beSAndy Adamson extern const u32 nfs41_maxgetdevinfo_overhead;
3302449ea2eSAlexandros Batsakis #endif
331f7b422b1SDavid Howells 
332f7b422b1SDavid Howells /* nfs4proc.c */
33389d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
334499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs4_procedures[];
335d75d5414SAndrew Morton #endif
336f7b422b1SDavid Howells 
337694e096fSAnna Schumaker #ifdef CONFIG_NFS_V4_SECURITY_LABEL
338694e096fSAnna Schumaker extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
339a49c2691SKinglong Mee static inline struct nfs4_label *
340a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
341a49c2691SKinglong Mee {
342a49c2691SKinglong Mee 	if (!dst || !src)
343a49c2691SKinglong Mee 		return NULL;
344a49c2691SKinglong Mee 
345a49c2691SKinglong Mee 	if (src->len > NFS4_MAXLABELLEN)
346a49c2691SKinglong Mee 		return NULL;
347a49c2691SKinglong Mee 
348a49c2691SKinglong Mee 	dst->lfs = src->lfs;
349a49c2691SKinglong Mee 	dst->pi = src->pi;
350a49c2691SKinglong Mee 	dst->len = src->len;
351a49c2691SKinglong Mee 	memcpy(dst->label, src->label, src->len);
352a49c2691SKinglong Mee 
353a49c2691SKinglong Mee 	return dst;
354a49c2691SKinglong Mee }
355fd1defc2STrond Myklebust 
356fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
357fd1defc2STrond Myklebust {
358fd1defc2STrond Myklebust 	if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
359fd1defc2STrond Myklebust 		nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
360fd1defc2STrond Myklebust }
361694e096fSAnna Schumaker #else
362694e096fSAnna Schumaker static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
363fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
364fd1defc2STrond Myklebust {
365fd1defc2STrond Myklebust }
366a49c2691SKinglong Mee static inline struct nfs4_label *
367a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
368a49c2691SKinglong Mee {
369a49c2691SKinglong Mee 	return NULL;
370a49c2691SKinglong Mee }
371694e096fSAnna Schumaker #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
372694e096fSAnna Schumaker 
3737fe5c398STrond Myklebust /* proc.c */
3747fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
3758cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
3765c6e5b60STrond Myklebust 			   const struct nfs_client_initdata *);
3777fe5c398STrond Myklebust 
378979df72eSTrond Myklebust /* dir.c */
379230bc98fSTrond Myklebust extern void nfs_readdir_record_entry_cache_hit(struct inode *dir);
380230bc98fSTrond Myklebust extern void nfs_readdir_record_entry_cache_miss(struct inode *dir);
3811ab6c499SDave Chinner extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
3821ab6c499SDave Chinner 					    struct shrink_control *sc);
3831ab6c499SDave Chinner extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
3841495f230SYing Han 					   struct shrink_control *sc);
385597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
38600bdadc7STrond Myklebust void nfs_d_prune_case_insensitive_aliases(struct inode *inode);
3876c960e68SChristian Brauner int nfs_create(struct mnt_idmap *, struct inode *, struct dentry *,
388549c7297SChristian Brauner 	       umode_t, bool);
389*c54bd91eSChristian Brauner int nfs_mkdir(struct mnt_idmap *, struct inode *, struct dentry *,
390549c7297SChristian Brauner 	      umode_t);
391597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *);
392597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *);
3937a77db95SChristian Brauner int nfs_symlink(struct mnt_idmap *, struct inode *, struct dentry *,
394549c7297SChristian Brauner 		const char *);
395597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *);
396549c7297SChristian Brauner int nfs_mknod(struct user_namespace *, struct inode *, struct dentry *, umode_t,
397549c7297SChristian Brauner 	      dev_t);
398549c7297SChristian Brauner int nfs_rename(struct user_namespace *, struct inode *, struct dentry *,
3991cd66c93SMiklos Szeredi 	       struct inode *, struct dentry *, unsigned int);
400979df72eSTrond Myklebust 
40184631f84STrond Myklebust #ifdef CONFIG_NFS_V4_2
40284631f84STrond Myklebust static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server)
40384631f84STrond Myklebust {
40484631f84STrond Myklebust 	if (!(server->caps & NFS_CAP_XATTR))
40584631f84STrond Myklebust 		return 0;
40684631f84STrond Myklebust 	return NFS4_ACCESS_XAREAD | NFS4_ACCESS_XAWRITE | NFS4_ACCESS_XALIST;
40784631f84STrond Myklebust }
40884631f84STrond Myklebust #else
40984631f84STrond Myklebust static inline __u32 nfs_access_xattr_mask(const struct nfs_server *server)
41084631f84STrond Myklebust {
41184631f84STrond Myklebust 	return 0;
41284631f84STrond Myklebust }
41384631f84STrond Myklebust #endif
41484631f84STrond Myklebust 
415ce4ef7c0SBryan Schumaker /* file.c */
4164ff79bc7SChristoph Hellwig int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
417ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int);
4183aa2d199SAl Viro ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
419ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *);
420edaf4369SAl Viro ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
421ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *);
422ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *);
423ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *);
424ce4ef7c0SBryan Schumaker int nfs_check_flags(int);
425ce4ef7c0SBryan Schumaker 
426f7b422b1SDavid Howells /* inode.c */
4275746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
428f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
429ca1a199eSAl Viro extern void nfs_free_inode(struct inode *);
430a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *);
431eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *);
43219d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *);
433b57922d9SAl Viro extern void nfs_evict_inode(struct inode *);
434fd6d3feeSTrond Myklebust extern void nfs_zap_acl_cache(struct inode *inode);
435fd6d3feeSTrond Myklebust extern void nfs_set_cache_invalid(struct inode *inode, unsigned long flags);
43661540bf6STrond Myklebust extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
437dfd01f02SPeter Zijlstra extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
438f7b422b1SDavid Howells 
439f7b422b1SDavid Howells /* super.c */
4406a74490dSBryan Schumaker extern const struct super_operations nfs_sops;
4414d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
442f2aedb71SDavid Howells int nfs_try_get_tree(struct fs_context *);
443f2aedb71SDavid Howells int nfs_get_tree_common(struct fs_context *);
444fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *);
4454ebd9ab3SDominik Hackl 
446f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
4474ebd9ab3SDominik Hackl 
448f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
449f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
450ea7c38feSTrond Myklebust extern bool nfs_sb_active(struct super_block *sb);
4511daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb);
4523c9e502bSTrond Myklebust extern int nfs_client_for_each_server(struct nfs_client *clp,
4533c9e502bSTrond Myklebust 				      int (*fn)(struct nfs_server *, void *),
4543c9e502bSTrond Myklebust 				      void *data);
455a5864c99STrond Myklebust /* io.c */
456a5864c99STrond Myklebust extern void nfs_start_io_read(struct inode *inode);
457a5864c99STrond Myklebust extern void nfs_end_io_read(struct inode *inode);
458a5864c99STrond Myklebust extern void nfs_start_io_write(struct inode *inode);
459a5864c99STrond Myklebust extern void nfs_end_io_write(struct inode *inode);
460a5864c99STrond Myklebust extern void nfs_start_io_direct(struct inode *inode);
461a5864c99STrond Myklebust extern void nfs_end_io_direct(struct inode *inode);
462a5864c99STrond Myklebust 
463651b0e70STrond Myklebust static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
464651b0e70STrond Myklebust {
465651b0e70STrond Myklebust 	return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
466651b0e70STrond Myklebust }
467651b0e70STrond Myklebust 
468f7b422b1SDavid Howells /* namespace.c */
46997a54868SBen Hutchings #define NFS_PATH_CANONICAL 1
470b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry,
47197a54868SBen Hutchings 		      char *buffer, ssize_t buflen, unsigned flags);
47236d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path);
473f2aedb71SDavid Howells int nfs_submount(struct fs_context *, struct nfs_server *);
474f2aedb71SDavid Howells int nfs_do_submount(struct fs_context *);
475f7b422b1SDavid Howells 
47654ceac45SDavid Howells /* getroot.c */
47762a55d08SScott Mayhew extern int nfs_get_root(struct super_block *s, struct fs_context *fc);
47889d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
4795e6b1990STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
4807d4e2747SDavid Howells #endif
481f7b422b1SDavid Howells 
482061ae2edSFred Isaman struct nfs_pgio_completion_ops;
483f11c88afSAndy Adamson /* read.c */
484584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
485fab5fc25SChristoph Hellwig 			struct inode *inode, bool force_mds,
486584aa810SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
487f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
488493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
489e885de1aSTrond Myklebust 
490fbdefd64SBryan Schumaker /* super.c */
491fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *);
492fbdefd64SBryan Schumaker int  nfs_statfs(struct dentry *, struct kstatfs *);
493fbdefd64SBryan Schumaker int  nfs_show_options(struct seq_file *, struct dentry *);
494fbdefd64SBryan Schumaker int  nfs_show_devname(struct seq_file *, struct dentry *);
495fbdefd64SBryan Schumaker int  nfs_show_path(struct seq_file *, struct dentry *);
496fbdefd64SBryan Schumaker int  nfs_show_stats(struct seq_file *, struct dentry *);
497f2aedb71SDavid Howells int  nfs_reconfigure(struct fs_context *);
498fbdefd64SBryan Schumaker 
499def6ed7eSAndy Adamson /* write.c */
5001763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
501a20c93e3SChristoph Hellwig 			struct inode *inode, int ioflags, bool force_mds,
5021763da12SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
503dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
5040b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p);
5050b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
5060b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt,
5070b7c0153SFred Isaman 			       struct nfs_commit_data *data,
508c36aae9aSPeng Tao 			       const struct nfs_rpc_ops *nfs_ops,
509e0c2b380SFred Isaman 			       const struct rpc_call_ops *call_ops,
5109f0ec176SAndy Adamson 			       int how, int flags);
5110b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data,
512e0c2b380SFred Isaman 			    struct list_head *head,
513f453a54aSFred Isaman 			    struct pnfs_layout_segment *lseg,
514f453a54aSFred Isaman 			    struct nfs_commit_info *cinfo);
5151763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
5161763da12SFred Isaman 			 struct nfs_commit_info *cinfo, int max);
517ce59515cSAnna Schumaker unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
5181763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst,
5191763da12SFred Isaman 		    struct nfs_commit_info *cinfo);
5201763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req,
5211763da12SFred Isaman 			     struct pnfs_layout_segment *lseg,
522b57ff130SWeston Andros Adamson 			     struct nfs_commit_info *cinfo,
523b57ff130SWeston Andros Adamson 			     u32 ds_commit_idx);
524c65e6254SWeston Andros Adamson int nfs_write_need_commit(struct nfs_pgio_header *);
525a08a8cd3STrond Myklebust void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
5261763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
5271763da12SFred Isaman 			    int how, struct nfs_commit_info *cinfo);
528e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list,
529ea2cf228SFred Isaman 		      struct pnfs_layout_segment *lseg,
530b57ff130SWeston Andros Adamson 		      struct nfs_commit_info *cinfo,
531b57ff130SWeston Andros Adamson 		      u32 ds_commit_idx);
5320b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data);
5336272dcc6SAnna Schumaker void nfs_request_add_commit_list(struct nfs_page *req,
534ea2cf228SFred Isaman 				 struct nfs_commit_info *cinfo);
53586d80f97STrond Myklebust void nfs_request_add_commit_list_locked(struct nfs_page *req,
53686d80f97STrond Myklebust 		struct list_head *dst,
53786d80f97STrond Myklebust 		struct nfs_commit_info *cinfo);
538ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req,
539ea2cf228SFred Isaman 				    struct nfs_commit_info *cinfo);
540ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo,
541ea2cf228SFred Isaman 		    struct inode *inode,
542ea2cf228SFred Isaman 		    struct nfs_direct_req *dreq);
543dc24826bSAndy Adamson int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
544ce52914eSScott Mayhew bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode);
545a7d42ddbSWeston Andros Adamson void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
546e0c2b380SFred Isaman 
547837bb1d7STrond Myklebust int nfs_filemap_write_and_wait_range(struct address_space *mapping,
548837bb1d7STrond Myklebust 		loff_t lstart, loff_t lend);
549837bb1d7STrond Myklebust 
550a5314a74STrond Myklebust #ifdef CONFIG_NFS_V4_1
551e3b9f7e6STrond Myklebust static inline void
552e3b9f7e6STrond Myklebust pnfs_bucket_clear_pnfs_ds_commit_verifiers(struct pnfs_commit_bucket *buckets,
553e3b9f7e6STrond Myklebust 		unsigned int nbuckets)
554e3b9f7e6STrond Myklebust {
555e3b9f7e6STrond Myklebust 	unsigned int i;
556e3b9f7e6STrond Myklebust 
557e3b9f7e6STrond Myklebust 	for (i = 0; i < nbuckets; i++)
558e3b9f7e6STrond Myklebust 		buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
559e3b9f7e6STrond Myklebust }
560a5314a74STrond Myklebust static inline
561a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
562a5314a74STrond Myklebust {
563e3b9f7e6STrond Myklebust 	struct pnfs_commit_array *array;
564a5314a74STrond Myklebust 
565a9901899STrond Myklebust 	rcu_read_lock();
566a9901899STrond Myklebust 	list_for_each_entry_rcu(array, &cinfo->commits, cinfo_list)
567e3b9f7e6STrond Myklebust 		pnfs_bucket_clear_pnfs_ds_commit_verifiers(array->buckets,
568e3b9f7e6STrond Myklebust 				array->nbuckets);
569a9901899STrond Myklebust 	rcu_read_unlock();
570a5314a74STrond Myklebust }
571a5314a74STrond Myklebust #else
572a5314a74STrond Myklebust static inline
573a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
574a5314a74STrond Myklebust {
575a5314a74STrond Myklebust }
576a5314a74STrond Myklebust #endif
577a5314a74STrond Myklebust 
578074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION
5794ae84a80SMatthew Wilcox (Oracle) int nfs_migrate_folio(struct address_space *, struct folio *dst,
5804ae84a80SMatthew Wilcox (Oracle) 		struct folio *src, enum migrate_mode);
5814ae84a80SMatthew Wilcox (Oracle) #else
5824ae84a80SMatthew Wilcox (Oracle) #define nfs_migrate_folio NULL
583074cc1deSTrond Myklebust #endif
584def6ed7eSAndy Adamson 
5858fc3c386STrond Myklebust static inline int
5868fc3c386STrond Myklebust nfs_write_verifier_cmp(const struct nfs_write_verifier *v1,
5878fc3c386STrond Myklebust 		const struct nfs_write_verifier *v2)
5888fc3c386STrond Myklebust {
5898fc3c386STrond Myklebust 	return memcmp(v1->data, v2->data, sizeof(v1->data));
5908fc3c386STrond Myklebust }
5918fc3c386STrond Myklebust 
5921f28476dSTrond Myklebust static inline bool
5931f28476dSTrond Myklebust nfs_write_match_verf(const struct nfs_writeverf *verf,
5941f28476dSTrond Myklebust 		struct nfs_page *req)
5951f28476dSTrond Myklebust {
5961f28476dSTrond Myklebust 	return verf->committed > NFS_UNSTABLE &&
5971f28476dSTrond Myklebust 		!nfs_write_verifier_cmp(&req->wb_verf, &verf->verifier);
5981f28476dSTrond Myklebust }
5991f28476dSTrond Myklebust 
600515dcdcdSTrond Myklebust static inline gfp_t nfs_io_gfp_mask(void)
601515dcdcdSTrond Myklebust {
602515dcdcdSTrond Myklebust 	if (current->flags & PF_WQ_WORKER)
603515dcdcdSTrond Myklebust 		return GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN;
604515dcdcdSTrond Myklebust 	return GFP_KERNEL;
605515dcdcdSTrond Myklebust }
606515dcdcdSTrond Myklebust 
607d7a51186SAnna Schumaker /*
608d7a51186SAnna Schumaker  * Special version of should_remove_suid() that ignores capabilities.
609d7a51186SAnna Schumaker  */
610d7a51186SAnna Schumaker static inline int nfs_should_remove_suid(const struct inode *inode)
611d7a51186SAnna Schumaker {
612d7a51186SAnna Schumaker 	umode_t mode = inode->i_mode;
613d7a51186SAnna Schumaker 	int kill = 0;
614d7a51186SAnna Schumaker 
615d7a51186SAnna Schumaker 	/* suid always must be killed */
616d7a51186SAnna Schumaker 	if (unlikely(mode & S_ISUID))
617d7a51186SAnna Schumaker 		kill = ATTR_KILL_SUID;
618d7a51186SAnna Schumaker 
619d7a51186SAnna Schumaker 	/*
620d7a51186SAnna Schumaker 	 * sgid without any exec bits is just a mandatory locking mark; leave
621d7a51186SAnna Schumaker 	 * it alone.  If some exec bits are set, it's a real sgid; kill it.
622d7a51186SAnna Schumaker 	 */
623d7a51186SAnna Schumaker 	if (unlikely((mode & S_ISGID) && (mode & S_IXGRP)))
624d7a51186SAnna Schumaker 		kill |= ATTR_KILL_SGID;
625d7a51186SAnna Schumaker 
626d7a51186SAnna Schumaker 	if (unlikely(kill && S_ISREG(mode)))
627d7a51186SAnna Schumaker 		return kill;
628d7a51186SAnna Schumaker 
629d7a51186SAnna Schumaker 	return 0;
630d7a51186SAnna Schumaker }
631d7a51186SAnna Schumaker 
6320e862a40SJeff Layton /* unlink.c */
6330e862a40SJeff Layton extern struct rpc_task *
6340e862a40SJeff Layton nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
6350e862a40SJeff Layton 		 struct dentry *old_dentry, struct dentry *new_dentry,
6360e862a40SJeff Layton 		 void (*complete)(struct rpc_task *, struct nfs_renamedata *));
6370e862a40SJeff Layton extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
6380e862a40SJeff Layton 
6391763da12SFred Isaman /* direct.c */
6401763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
6411763da12SFred Isaman 			      struct nfs_direct_req *dreq);
6426296556fSPeng Tao extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
6431763da12SFred Isaman 
644cccef3b9SAndy Adamson /* nfs4proc.c */
6458cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
6465c6e5b60STrond Myklebust 			    const struct nfs_client_initdata *);
64705f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp,
64805f4c350SChuck Lever 				struct nfs_client **result,
649a52458b4SNeilBrown 				const struct cred *cred);
65005f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp,
65105f4c350SChuck Lever 				struct nfs_client **result,
652a52458b4SNeilBrown 				const struct cred *cred);
65310e037d1SSantosh kumar pradhan extern void nfs4_test_session_trunk(struct rpc_clnt *clnt,
65410e037d1SSantosh kumar pradhan 				struct rpc_xprt *xprt,
65510e037d1SSantosh kumar pradhan 				void *data);
656cccef3b9SAndy Adamson 
657ea7c38feSTrond Myklebust static inline struct inode *nfs_igrab_and_active(struct inode *inode)
658ea7c38feSTrond Myklebust {
659896567eeSTrond Myklebust 	struct super_block *sb = inode->i_sb;
660896567eeSTrond Myklebust 
661896567eeSTrond Myklebust 	if (sb && nfs_sb_active(sb)) {
662896567eeSTrond Myklebust 		if (igrab(inode))
663ea7c38feSTrond Myklebust 			return inode;
664896567eeSTrond Myklebust 		nfs_sb_deactive(sb);
665896567eeSTrond Myklebust 	}
666896567eeSTrond Myklebust 	return NULL;
667ea7c38feSTrond Myklebust }
668ea7c38feSTrond Myklebust 
669ea7c38feSTrond Myklebust static inline void nfs_iput_and_deactive(struct inode *inode)
670ea7c38feSTrond Myklebust {
671ea7c38feSTrond Myklebust 	if (inode != NULL) {
672ea7c38feSTrond Myklebust 		struct super_block *sb = inode->i_sb;
673ea7c38feSTrond Myklebust 
674ea7c38feSTrond Myklebust 		iput(inode);
675ea7c38feSTrond Myklebust 		nfs_sb_deactive(sb);
676ea7c38feSTrond Myklebust 	}
677ea7c38feSTrond Myklebust }
678ea7c38feSTrond Myklebust 
679557134a3SAndy Adamson /*
680f7b422b1SDavid Howells  * Determine the device name as a string
681f7b422b1SDavid Howells  */
682b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry,
683f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
684f7b422b1SDavid Howells {
685b514f872SAl Viro 	char *dummy;
68697a54868SBen Hutchings 	return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
687f7b422b1SDavid Howells }
688f7b422b1SDavid Howells 
689f7b422b1SDavid Howells /*
690f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
691f7b422b1SDavid Howells  */
692f7b422b1SDavid Howells static inline
693f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
694f7b422b1SDavid Howells {
695f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
696f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
697f7b422b1SDavid Howells 		unsigned char	nrbits;
698f7b422b1SDavid Howells 
699f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
700f7b422b1SDavid Howells 			;
701f7b422b1SDavid Howells 		bsize = 1 << nrbits;
702f7b422b1SDavid Howells 		if (nrbitsp)
703f7b422b1SDavid Howells 			*nrbitsp = nrbits;
704f7b422b1SDavid Howells 	}
705f7b422b1SDavid Howells 
706f7b422b1SDavid Howells 	return bsize;
707f7b422b1SDavid Howells }
708f7b422b1SDavid Howells 
709f7b422b1SDavid Howells /*
710f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
711f7b422b1SDavid Howells  */
7129eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
713f7b422b1SDavid Howells {
7149eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
715f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
716f7b422b1SDavid Howells }
717f7b422b1SDavid Howells 
718f7b422b1SDavid Howells /*
719f7b422b1SDavid Howells  * Compute and set NFS server blocksize
720f7b422b1SDavid Howells  */
721f7b422b1SDavid Howells static inline
722f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
723f7b422b1SDavid Howells {
724f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
725f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
726f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
727f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
728f7b422b1SDavid Howells 
729f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
730f7b422b1SDavid Howells }
731f7b422b1SDavid Howells 
732f7b422b1SDavid Howells /*
733940261a1SAnna Schumaker  * Compute and set NFS server rsize / wsize
734940261a1SAnna Schumaker  */
735940261a1SAnna Schumaker static inline
736940261a1SAnna Schumaker unsigned long nfs_io_size(unsigned long iosize, enum xprt_transports proto)
737940261a1SAnna Schumaker {
738940261a1SAnna Schumaker 	if (iosize < NFS_MIN_FILE_IO_SIZE)
739940261a1SAnna Schumaker 		iosize = NFS_DEF_FILE_IO_SIZE;
740940261a1SAnna Schumaker 	else if (iosize >= NFS_MAX_FILE_IO_SIZE)
741940261a1SAnna Schumaker 		iosize = NFS_MAX_FILE_IO_SIZE;
742940261a1SAnna Schumaker 
743a60214c2SAnna Schumaker 	if (proto == XPRT_TRANSPORT_UDP || iosize < PAGE_SIZE)
744940261a1SAnna Schumaker 		return nfs_block_bits(iosize, NULL);
745a60214c2SAnna Schumaker 	return iosize & PAGE_MASK;
746940261a1SAnna Schumaker }
747940261a1SAnna Schumaker 
748940261a1SAnna Schumaker /*
749f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
750f7b422b1SDavid Howells  */
751f7b422b1SDavid Howells static inline
752f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
753f7b422b1SDavid Howells {
754f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
755f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
756f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
757f7b422b1SDavid Howells }
75849a70f27STrond Myklebust 
75949a70f27STrond Myklebust /*
7608d92890bSNeilBrown  * Record the page as unstable (an extra writeback period) and mark its
7618d92890bSNeilBrown  * inode as dirty.
762d15bc38dSTom Haynes  */
763d15bc38dSTom Haynes static inline
76486d80f97STrond Myklebust void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo)
765d15bc38dSTom Haynes {
76686d80f97STrond Myklebust 	if (!cinfo->dreq) {
767d15bc38dSTom Haynes 		struct inode *inode = page_file_mapping(page)->host;
768d15bc38dSTom Haynes 
7698d92890bSNeilBrown 		/* This page is really still in write-back - just that the
7708d92890bSNeilBrown 		 * writeback is happening on the server now.
7718d92890bSNeilBrown 		 */
7728d92890bSNeilBrown 		inc_node_page_state(page, NR_WRITEBACK);
7738d92890bSNeilBrown 		inc_wb_stat(&inode_to_bdi(inode)->wb, WB_WRITEBACK);
774d15bc38dSTom Haynes 		__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
775d15bc38dSTom Haynes 	}
77686d80f97STrond Myklebust }
777d15bc38dSTom Haynes 
778d15bc38dSTom Haynes /*
77949a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
78049a70f27STrond Myklebust  */
78149a70f27STrond Myklebust static inline
78249a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
78349a70f27STrond Myklebust {
784d56b4ddfSMel Gorman 	loff_t i_size = i_size_read(page_file_mapping(page)->host);
78549a70f27STrond Myklebust 
78649a70f27STrond Myklebust 	if (i_size > 0) {
7878cd79788SHuang Ying 		pgoff_t index = page_index(page);
78809cbfeafSKirill A. Shutemov 		pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT;
7898cd79788SHuang Ying 		if (index < end_index)
79009cbfeafSKirill A. Shutemov 			return PAGE_SIZE;
7918cd79788SHuang Ying 		if (index == end_index)
79209cbfeafSKirill A. Shutemov 			return ((i_size - 1) & ~PAGE_MASK) + 1;
79349a70f27STrond Myklebust 	}
79449a70f27STrond Myklebust 	return 0;
79549a70f27STrond Myklebust }
7968d5658c9STrond Myklebust 
7978d5658c9STrond Myklebust /*
7980b26a0bfSTrond Myklebust  * Convert a umode to a dirent->d_type
7990b26a0bfSTrond Myklebust  */
8000b26a0bfSTrond Myklebust static inline
8010b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode)
8020b26a0bfSTrond Myklebust {
8030b26a0bfSTrond Myklebust 	return (mode >> 12) & 15;
8040b26a0bfSTrond Myklebust }
8050b26a0bfSTrond Myklebust 
8060b26a0bfSTrond Myklebust /*
8078d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
8088d5658c9STrond Myklebust  * with a base offset of 'base'
8098d5658c9STrond Myklebust  */
8108d5658c9STrond Myklebust static inline
8118d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len)
8128d5658c9STrond Myklebust {
8138d5658c9STrond Myklebust 	return ((unsigned long)len + (unsigned long)base +
8148d5658c9STrond Myklebust 		PAGE_SIZE - 1) >> PAGE_SHIFT;
8158d5658c9STrond Myklebust }
8160110ee15STrond Myklebust 
8173a1556e8STrond Myklebust /*
818ae08483cSArnd Bergmann  * Convert a struct timespec64 into a 64-bit change attribute
8193a1556e8STrond Myklebust  *
820ae08483cSArnd Bergmann  * This does approximately the same thing as timespec64_to_ns(),
8213a1556e8STrond Myklebust  * but for calculation efficiency, we multiply the seconds by
8223a1556e8STrond Myklebust  * 1024*1024*1024.
8233a1556e8STrond Myklebust  */
8243a1556e8STrond Myklebust static inline
825e86d5a02STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec64 *ts)
8263a1556e8STrond Myklebust {
8273a1556e8STrond Myklebust 	return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
8283a1556e8STrond Myklebust }
8291264a2f0STrond Myklebust 
8301264a2f0STrond Myklebust #ifdef CONFIG_CRC32
8311264a2f0STrond Myklebust /**
8321264a2f0STrond Myklebust  * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
8331264a2f0STrond Myklebust  * @fh - pointer to filehandle
8341264a2f0STrond Myklebust  *
8351264a2f0STrond Myklebust  * returns a crc32 hash for the filehandle that is compatible with
8361264a2f0STrond Myklebust  * the one displayed by "wireshark".
8371264a2f0STrond Myklebust  */
8381264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
8391264a2f0STrond Myklebust {
8401264a2f0STrond Myklebust 	return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
8411264a2f0STrond Myklebust }
84248c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid)
84348c9579aSOlga Kornievskaia {
84448c9579aSOlga Kornievskaia 	return ~crc32_le(0xFFFFFFFF, &stateid->other[0],
84548c9579aSOlga Kornievskaia 				NFS4_STATEID_OTHER_SIZE);
84648c9579aSOlga Kornievskaia }
8471264a2f0STrond Myklebust #else
8481264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
8491264a2f0STrond Myklebust {
8501264a2f0STrond Myklebust 	return 0;
8511264a2f0STrond Myklebust }
85248c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
85348c9579aSOlga Kornievskaia {
85448c9579aSOlga Kornievskaia 	return 0;
85548c9579aSOlga Kornievskaia }
8561264a2f0STrond Myklebust #endif
8570bcbf039SPeng Tao 
8580bcbf039SPeng Tao static inline bool nfs_error_is_fatal(int err)
8590bcbf039SPeng Tao {
8600bcbf039SPeng Tao 	switch (err) {
8610bcbf039SPeng Tao 	case -ERESTARTSYS:
8627dc58ca5STrond Myklebust 	case -EINTR:
86354551d85STrond Myklebust 	case -EACCES:
86454551d85STrond Myklebust 	case -EDQUOT:
86554551d85STrond Myklebust 	case -EFBIG:
8660bcbf039SPeng Tao 	case -EIO:
8670bcbf039SPeng Tao 	case -ENOSPC:
8680bcbf039SPeng Tao 	case -EROFS:
86954551d85STrond Myklebust 	case -ESTALE:
8700bcbf039SPeng Tao 	case -E2BIG:
8712dc23affSTrond Myklebust 	case -ENOMEM:
87211982a7cSTrond Myklebust 	case -ETIMEDOUT:
8730bcbf039SPeng Tao 		return true;
8740bcbf039SPeng Tao 	default:
8750bcbf039SPeng Tao 		return false;
8760bcbf039SPeng Tao 	}
8770bcbf039SPeng Tao }
878bf4b4905SNeilBrown 
8798f54c7a4STrond Myklebust static inline bool nfs_error_is_fatal_on_server(int err)
8808f54c7a4STrond Myklebust {
8818f54c7a4STrond Myklebust 	switch (err) {
8828f54c7a4STrond Myklebust 	case 0:
8838f54c7a4STrond Myklebust 	case -ERESTARTSYS:
8848f54c7a4STrond Myklebust 	case -EINTR:
88545228440STrond Myklebust 	case -ENOMEM:
8868f54c7a4STrond Myklebust 		return false;
8878f54c7a4STrond Myklebust 	}
8888f54c7a4STrond Myklebust 	return nfs_error_is_fatal(err);
8898f54c7a4STrond Myklebust }
8909954bf92SDavid Howells 
8919954bf92SDavid Howells /*
8929954bf92SDavid Howells  * Select between a default port value and a user-specified port value.
8939954bf92SDavid Howells  * If a zero value is set, then autobind will be used.
8949954bf92SDavid Howells  */
895cf0d7e7fSKees Cook static inline void nfs_set_port(struct sockaddr_storage *sap, int *port,
8969954bf92SDavid Howells 				const unsigned short default_port)
8979954bf92SDavid Howells {
8989954bf92SDavid Howells 	if (*port == NFS_UNSPEC_PORT)
8999954bf92SDavid Howells 		*port = default_port;
9009954bf92SDavid Howells 
901cf0d7e7fSKees Cook 	rpc_set_port((struct sockaddr *)sap, *port);
9029954bf92SDavid Howells }
9038efc4bbeSJeff Layton 
9048efc4bbeSJeff Layton struct nfs_direct_req {
9058efc4bbeSJeff Layton 	struct kref		kref;		/* release manager */
9068efc4bbeSJeff Layton 
9078efc4bbeSJeff Layton 	/* I/O parameters */
9088efc4bbeSJeff Layton 	struct nfs_open_context	*ctx;		/* file open context info */
9098efc4bbeSJeff Layton 	struct nfs_lock_context *l_ctx;		/* Lock context info */
9108efc4bbeSJeff Layton 	struct kiocb *		iocb;		/* controlling i/o request */
9118efc4bbeSJeff Layton 	struct inode *		inode;		/* target file of i/o */
9128efc4bbeSJeff Layton 
9138efc4bbeSJeff Layton 	/* completion state */
9148efc4bbeSJeff Layton 	atomic_t		io_count;	/* i/os we're waiting for */
9158efc4bbeSJeff Layton 	spinlock_t		lock;		/* protect completion state */
9168efc4bbeSJeff Layton 
9178efc4bbeSJeff Layton 	loff_t			io_start;	/* Start offset for I/O */
9188efc4bbeSJeff Layton 	ssize_t			count,		/* bytes actually processed */
9198efc4bbeSJeff Layton 				max_count,	/* max expected count */
9208efc4bbeSJeff Layton 				bytes_left,	/* bytes left to be sent */
9218efc4bbeSJeff Layton 				error;		/* any reported error */
9228efc4bbeSJeff Layton 	struct completion	completion;	/* wait for i/o completion */
9238efc4bbeSJeff Layton 
9248efc4bbeSJeff Layton 	/* commit state */
9258efc4bbeSJeff Layton 	struct nfs_mds_commit_info mds_cinfo;	/* Storage for cinfo */
9268efc4bbeSJeff Layton 	struct pnfs_ds_commit_info ds_cinfo;	/* Storage for cinfo */
9278efc4bbeSJeff Layton 	struct work_struct	work;
9288efc4bbeSJeff Layton 	int			flags;
9298efc4bbeSJeff Layton 	/* for write */
9308efc4bbeSJeff Layton #define NFS_ODIRECT_DO_COMMIT		(1)	/* an unstable reply was received */
9318efc4bbeSJeff Layton #define NFS_ODIRECT_RESCHED_WRITES	(2)	/* write verification failed */
9328efc4bbeSJeff Layton 	/* for read */
9338efc4bbeSJeff Layton #define NFS_ODIRECT_SHOULD_DIRTY	(3)	/* dirty user-space page after read */
9348efc4bbeSJeff Layton #define NFS_ODIRECT_DONE		INT_MAX	/* write verification failed */
9358efc4bbeSJeff Layton };
936