xref: /openbmc/linux/fs/nfs/internal.h (revision ce8866f0)
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 
366b18eaa0S\"Talpey, Thomas\ /*
37a14017dbSChuck Lever  * Note: RFC 1813 doesn't limit the number of auth flavors that
38a14017dbSChuck Lever  * a server can return, so make something up.
39a14017dbSChuck Lever  */
40a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS	(12)
41a14017dbSChuck Lever 
42a14017dbSChuck Lever /*
434cfd74fcSChuck Lever  * Value used if the user did not specify a port value.
444cfd74fcSChuck Lever  */
454cfd74fcSChuck Lever #define NFS_UNSPEC_PORT		(-1)
464cfd74fcSChuck Lever 
47a956bedaSTrond Myklebust #define NFS_UNSPEC_RETRANS	(UINT_MAX)
48a956bedaSTrond Myklebust #define NFS_UNSPEC_TIMEO	(UINT_MAX)
49a956bedaSTrond Myklebust 
504cfd74fcSChuck Lever /*
5156e4ebf8SBryan Schumaker  * Maximum number of pages that readdir can use for creating
5256e4ebf8SBryan Schumaker  * a vmapped array of pages.
5356e4ebf8SBryan Schumaker  */
54db531db9SMax Kellermann #define NFS_MAX_READDIR_PAGES 8
5556e4ebf8SBryan Schumaker 
56fcf10398SBryan Schumaker struct nfs_client_initdata {
57fcf10398SBryan Schumaker 	unsigned long init_flags;
585c6e5b60STrond Myklebust 	const char *hostname;			/* Hostname of the server */
595c6e5b60STrond Myklebust 	const struct sockaddr *addr;		/* Address of the server */
605c6e5b60STrond Myklebust 	const char *nodename;			/* Hostname of the client */
615c6e5b60STrond Myklebust 	const char *ip_addr;			/* IP address of the client */
62fcf10398SBryan Schumaker 	size_t addrlen;
63ab7017a3SBryan Schumaker 	struct nfs_subversion *nfs_mod;
64fcf10398SBryan Schumaker 	int proto;
65fcf10398SBryan Schumaker 	u32 minorversion;
666619079dSTrond Myklebust 	unsigned int nconnect;
67fcf10398SBryan Schumaker 	struct net *net;
685c6e5b60STrond Myklebust 	const struct rpc_timeout *timeparms;
691a58e8a0STrond Myklebust 	const struct cred *cred;
70fcf10398SBryan Schumaker };
71fcf10398SBryan Schumaker 
7256e4ebf8SBryan Schumaker /*
736b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
746b18eaa0S\"Talpey, Thomas\  */
755eb005caSDavid Howells struct nfs_fs_context {
76f2aedb71SDavid Howells 	bool			internal;
77f2aedb71SDavid Howells 	bool			skip_reconfig_option_check;
78f2aedb71SDavid Howells 	bool			need_mount;
79f2aedb71SDavid Howells 	bool			sloppy;
80e558100fSDavid Howells 	unsigned int		flags;		/* NFS{,4}_MOUNT_* flags */
818cb7f74eSChuck Lever 	unsigned int		rsize, wsize;
828cb7f74eSChuck Lever 	unsigned int		timeo, retrans;
83e558100fSDavid Howells 	unsigned int		acregmin, acregmax;
84e558100fSDavid Howells 	unsigned int		acdirmin, acdirmax;
858cb7f74eSChuck Lever 	unsigned int		namlen;
86b797cac7SDavid Howells 	unsigned int		options;
876b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
88a3f73c27SWeston Andros Adamson 	struct nfs_auth_info	auth_info;
89a3f73c27SWeston Andros Adamson 	rpc_authflavor_t	selected_flavor;
906b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
91764302ccSChuck Lever 	unsigned int		version;
923fd5be9eSMike Sager 	unsigned int		minorversion;
9308734048SDavid Howells 	char			*fscache_uniq;
94f8ee01e3SDavid Howells 	unsigned short		protofamily;
95f8ee01e3SDavid Howells 	unsigned short		mountfamily;
966b18eaa0S\"Talpey, Thomas\ 
976b18eaa0S\"Talpey, Thomas\ 	struct {
98e558100fSDavid Howells 		union {
99e558100fSDavid Howells 			struct sockaddr	address;
100e558100fSDavid Howells 			struct sockaddr_storage	_address;
101e558100fSDavid Howells 		};
1024c568017SChuck Lever 		size_t			addrlen;
1036b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
10478fa701fSChuck Lever 		u32			version;
1054cfd74fcSChuck Lever 		int			port;
10678fa701fSChuck Lever 		unsigned short		protocol;
1076b18eaa0S\"Talpey, Thomas\ 	} mount_server;
1086b18eaa0S\"Talpey, Thomas\ 
1096b18eaa0S\"Talpey, Thomas\ 	struct {
110e558100fSDavid Howells 		union {
111e558100fSDavid Howells 			struct sockaddr	address;
112e558100fSDavid Howells 			struct sockaddr_storage	_address;
113e558100fSDavid Howells 		};
1144c568017SChuck Lever 		size_t			addrlen;
1156b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
1166b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
1174cfd74fcSChuck Lever 		int			port;
11878fa701fSChuck Lever 		unsigned short		protocol;
11928cc5cd8STrond Myklebust 		unsigned short		nconnect;
120f2aedb71SDavid Howells 		unsigned short		export_path_len;
1216b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
122f9c3a380SEric Paris 
12362a55d08SScott Mayhew 	struct nfs_fh		*mntfh;
12462a55d08SScott Mayhew 	struct nfs_server	*server;
12562a55d08SScott Mayhew 	struct nfs_subversion	*nfs_mod;
12648be8a66SDavid Howells 
12762a55d08SScott Mayhew 	/* Information for a cloned mount. */
12862a55d08SScott Mayhew 	struct nfs_clone_mount {
12962a55d08SScott Mayhew 		struct super_block	*sb;
13062a55d08SScott Mayhew 		struct dentry		*dentry;
13162a55d08SScott Mayhew 		struct nfs_fattr	*fattr;
13262a55d08SScott Mayhew 		unsigned int		inherited_bsize;
13362a55d08SScott Mayhew 	} clone_data;
1346b18eaa0S\"Talpey, Thomas\ };
1356b18eaa0S\"Talpey, Thomas\ 
136ce8866f0SScott Mayhew #define nfs_errorf(fc, fmt, ...) errorf(fc, fmt, ## __VA_ARGS__)
137ce8866f0SScott Mayhew #define nfs_invalf(fc, fmt, ...) invalf(fc, fmt, ## __VA_ARGS__)
138ce8866f0SScott Mayhew #define nfs_warnf(fc, fmt, ...) warnf(fc, fmt, ## __VA_ARGS__)
139ce8866f0SScott Mayhew 
140f2aedb71SDavid Howells static inline struct nfs_fs_context *nfs_fc2context(const struct fs_context *fc)
141f2aedb71SDavid Howells {
142f2aedb71SDavid Howells 	return fc->fs_private;
143f2aedb71SDavid Howells }
144f2aedb71SDavid Howells 
145146ec944SChuck Lever /* mount_clnt.c */
146c5d120f8SChuck Lever struct nfs_mount_request {
147c5d120f8SChuck Lever 	struct sockaddr		*sap;
148c5d120f8SChuck Lever 	size_t			salen;
149c5d120f8SChuck Lever 	char			*hostname;
150c5d120f8SChuck Lever 	char			*dirpath;
151c5d120f8SChuck Lever 	u32			version;
152c5d120f8SChuck Lever 	unsigned short		protocol;
153c5d120f8SChuck Lever 	struct nfs_fh		*fh;
15450a737f8SChuck Lever 	int			noresvport;
1558e02f6b9SChuck Lever 	unsigned int		*auth_flav_len;
1568e02f6b9SChuck Lever 	rpc_authflavor_t	*auth_flavs;
1576d59b8d5SStanislav Kinsbursky 	struct net		*net;
158c5d120f8SChuck Lever };
159c5d120f8SChuck Lever 
160c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info);
1610b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info);
162146ec944SChuck Lever 
16324c8dbbbSDavid Howells /* client.c */
164a613fa16STrond Myklebust extern const struct rpc_program nfs_program;
1656b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net);
16610b7a70cSTrond Myklebust extern void nfs_clients_exit(struct net *net);
1676663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
1685c6e5b60STrond Myklebust int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
1697d38de3fSAnna Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
170fcf10398SBryan Schumaker int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
171fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *);
17232e62b7cSChuck Lever void nfs_server_remove_lists(struct nfs_server *);
173a956bedaSTrond Myklebust void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
174fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
175fcf10398SBryan Schumaker 		rpc_authflavor_t);
176fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void);
177fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
17854ceac45SDavid Howells 
17924c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
180cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *);
18128cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
182c36fca52SAndy Adamson extern struct nfs_client *
183c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
184459de2edSBryan Schumaker 				struct nfs4_sessionid *, u32);
18562a55d08SScott Mayhew extern struct nfs_server *nfs_create_server(struct fs_context *);
18662a55d08SScott Mayhew extern struct nfs_server *nfs4_create_server(struct fs_context *);
18762a55d08SScott Mayhew extern struct nfs_server *nfs4_create_referral_server(struct fs_context *);
18832e62b7cSChuck Lever extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
189292f503cSTrond Myklebust 					struct sockaddr *sap, size_t salen,
190292f503cSTrond Myklebust 					struct net *net);
19154ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
19254ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
19354ceac45SDavid Howells 					   struct nfs_fh *,
1947e6eb683SBryan Schumaker 					   struct nfs_fattr *,
1957e6eb683SBryan Schumaker 					   rpc_authflavor_t);
196a33e4b03SWeston Andros Adamson extern bool nfs_client_init_is_complete(const struct nfs_client *clp);
197a33e4b03SWeston Andros Adamson extern int nfs_client_init_status(const struct nfs_client *clp);
1984697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
19976db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
2003fc75f12STigran Mkrtchyan extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
201d83217c1SAndy Adamson 					     const struct sockaddr *ds_addr,
20298fc685aSAndy Adamson 					     int ds_addrlen, int ds_proto,
20398fc685aSAndy Adamson 					     unsigned int ds_timeo,
204064172f3SPeng Tao 					     unsigned int ds_retrans,
2057d38de3fSAnna Schumaker 					     u32 minor_version);
2060e20162eSAndy Adamson extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
2070e20162eSAndy Adamson 						struct inode *);
208b224f7cbSTigran Mkrtchyan extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
2091a04c6e1SPeng Tao 			const struct sockaddr *ds_addr, int ds_addrlen,
2101a04c6e1SPeng Tao 			int ds_proto, unsigned int ds_timeo,
2117d38de3fSAnna Schumaker 			unsigned int ds_retrans);
2126aaca566SDavid Howells #ifdef CONFIG_PROC_FS
2136aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
2146aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
21565b38851SEric W. Biederman extern int nfs_fs_proc_net_init(struct net *net);
21665b38851SEric W. Biederman extern void nfs_fs_proc_net_exit(struct net *net);
2176aaca566SDavid Howells #else
21865b38851SEric W. Biederman static inline int nfs_fs_proc_net_init(struct net *net)
21965b38851SEric W. Biederman {
22065b38851SEric W. Biederman 	return 0;
22165b38851SEric W. Biederman }
22265b38851SEric W. Biederman static inline void nfs_fs_proc_net_exit(struct net *net)
22365b38851SEric W. Biederman {
22465b38851SEric W. Biederman }
2256aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
2266aaca566SDavid Howells {
2276aaca566SDavid Howells 	return 0;
2286aaca566SDavid Howells }
2296aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
2306aaca566SDavid Howells {
2316aaca566SDavid Howells }
2326aaca566SDavid Howells #endif
23324c8dbbbSDavid Howells 
234f7b422b1SDavid Howells /* callback_xdr.c */
235e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version1;
236e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version4;
237f7b422b1SDavid Howells 
238f2aedb71SDavid Howells /* fs_context.c */
239f2aedb71SDavid Howells extern struct file_system_type nfs_fs_type;
2409954bf92SDavid Howells 
241f7b422b1SDavid Howells /* pagelist.c */
242f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
243266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
244f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
245266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
246f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
247266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
248f7b422b1SDavid Howells 
249f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
250266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
2514db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
2524db6e0b7SFred Isaman 			      struct nfs_pgio_header *hdr,
2534db6e0b7SFred Isaman 			      void (*release)(struct nfs_pgio_header *hdr));
2544db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
255210c7c17SBenjamin Coddington int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
256577b4232STrond Myklebust 
25741d8d5b7SAnna Schumaker extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
2581e7f3a48SWeston Andros Adamson struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
2591e7f3a48SWeston Andros Adamson void nfs_pgio_header_free(struct nfs_pgio_header *);
260ef2c488cSAnna Schumaker int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
26146a5ab47SPeng Tao int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
262a52458b4SNeilBrown 		      const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
26346a5ab47SPeng Tao 		      const struct rpc_call_ops *call_ops, int how, int flags);
264d4581383SWeston Andros Adamson void nfs_free_request(struct nfs_page *req);
26548d635f1SPeng Tao struct nfs_pgio_mirror *
26648d635f1SPeng Tao nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
26700bfa30aSAnna Schumaker 
26847af81f2SPeng Tao static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc)
26947af81f2SPeng Tao {
27047af81f2SPeng Tao 	WARN_ON_ONCE(desc->pg_mirror_count < 1);
27147af81f2SPeng Tao 	return desc->pg_mirror_count > 1;
27247af81f2SPeng Tao }
27347af81f2SPeng Tao 
274138a2935STrond Myklebust static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
275138a2935STrond Myklebust 		const struct nfs_open_context *ctx2)
276138a2935STrond Myklebust {
277a52458b4SNeilBrown 	return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state;
278138a2935STrond Myklebust }
279138a2935STrond Myklebust 
280f7b422b1SDavid Howells /* nfs2xdr.c */
281499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs_procedures[];
282573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *,
283a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
284f7b422b1SDavid Howells 
285f7b422b1SDavid Howells /* nfs3xdr.c */
286499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs3_procedures[];
287573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *,
288a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
289f7b422b1SDavid Howells 
290f7b422b1SDavid Howells /* nfs4xdr.c */
29189d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
292573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *,
293a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
2947d4e2747SDavid Howells #endif
2952449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
2962449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead;
2972449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead;
298f1c097beSAndy Adamson extern const u32 nfs41_maxgetdevinfo_overhead;
2992449ea2eSAlexandros Batsakis #endif
300f7b422b1SDavid Howells 
301f7b422b1SDavid Howells /* nfs4proc.c */
30289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
303499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs4_procedures[];
304d75d5414SAndrew Morton #endif
305f7b422b1SDavid Howells 
306694e096fSAnna Schumaker #ifdef CONFIG_NFS_V4_SECURITY_LABEL
307694e096fSAnna Schumaker extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
308a49c2691SKinglong Mee static inline struct nfs4_label *
309a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
310a49c2691SKinglong Mee {
311a49c2691SKinglong Mee 	if (!dst || !src)
312a49c2691SKinglong Mee 		return NULL;
313a49c2691SKinglong Mee 
314a49c2691SKinglong Mee 	if (src->len > NFS4_MAXLABELLEN)
315a49c2691SKinglong Mee 		return NULL;
316a49c2691SKinglong Mee 
317a49c2691SKinglong Mee 	dst->lfs = src->lfs;
318a49c2691SKinglong Mee 	dst->pi = src->pi;
319a49c2691SKinglong Mee 	dst->len = src->len;
320a49c2691SKinglong Mee 	memcpy(dst->label, src->label, src->len);
321a49c2691SKinglong Mee 
322a49c2691SKinglong Mee 	return dst;
323a49c2691SKinglong Mee }
324694e096fSAnna Schumaker static inline void nfs4_label_free(struct nfs4_label *label)
325694e096fSAnna Schumaker {
326694e096fSAnna Schumaker 	if (label) {
327694e096fSAnna Schumaker 		kfree(label->label);
328694e096fSAnna Schumaker 		kfree(label);
329694e096fSAnna Schumaker 	}
330694e096fSAnna Schumaker 	return;
331694e096fSAnna Schumaker }
332fd1defc2STrond Myklebust 
333fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
334fd1defc2STrond Myklebust {
335fd1defc2STrond Myklebust 	if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
336fd1defc2STrond Myklebust 		nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
337fd1defc2STrond Myklebust }
338694e096fSAnna Schumaker #else
339694e096fSAnna Schumaker static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
340694e096fSAnna Schumaker static inline void nfs4_label_free(void *label) {}
341fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
342fd1defc2STrond Myklebust {
343fd1defc2STrond Myklebust }
344a49c2691SKinglong Mee static inline struct nfs4_label *
345a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
346a49c2691SKinglong Mee {
347a49c2691SKinglong Mee 	return NULL;
348a49c2691SKinglong Mee }
349694e096fSAnna Schumaker #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
350694e096fSAnna Schumaker 
3517fe5c398STrond Myklebust /* proc.c */
3527fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
3538cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
3545c6e5b60STrond Myklebust 			   const struct nfs_client_initdata *);
3557fe5c398STrond Myklebust 
356979df72eSTrond Myklebust /* dir.c */
3571bcf4c5cSTrond Myklebust extern void nfs_advise_use_readdirplus(struct inode *dir);
358311324adSTrond Myklebust extern void nfs_force_use_readdirplus(struct inode *dir);
3591ab6c499SDave Chinner extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
3601ab6c499SDave Chinner 					    struct shrink_control *sc);
3611ab6c499SDave Chinner extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
3621495f230SYing Han 					   struct shrink_control *sc);
363597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
364597d9289SBryan Schumaker int nfs_create(struct inode *, struct dentry *, umode_t, bool);
365597d9289SBryan Schumaker int nfs_mkdir(struct inode *, struct dentry *, umode_t);
366597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *);
367597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *);
368597d9289SBryan Schumaker int nfs_symlink(struct inode *, struct dentry *, const char *);
369597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *);
370597d9289SBryan Schumaker int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
3711cd66c93SMiklos Szeredi int nfs_rename(struct inode *, struct dentry *,
3721cd66c93SMiklos Szeredi 	       struct inode *, struct dentry *, unsigned int);
373979df72eSTrond Myklebust 
374ce4ef7c0SBryan Schumaker /* file.c */
3754ff79bc7SChristoph Hellwig int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
376ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int);
3773aa2d199SAl Viro ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
378ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *);
379edaf4369SAl Viro ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
380ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *);
381ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *);
382ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *);
383ce4ef7c0SBryan Schumaker int nfs_check_flags(int);
384ce4ef7c0SBryan Schumaker 
385f7b422b1SDavid Howells /* inode.c */
3865746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
387f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
388ca1a199eSAl Viro extern void nfs_free_inode(struct inode *);
389a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *);
390eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *);
39119d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *);
392b57922d9SAl Viro extern void nfs_evict_inode(struct inode *);
393f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode);
39461540bf6STrond Myklebust extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
395dfd01f02SPeter Zijlstra extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
3965e4def20SDavid Howells extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode);
397f7b422b1SDavid Howells 
398f7b422b1SDavid Howells /* super.c */
3996a74490dSBryan Schumaker extern const struct super_operations nfs_sops;
4004d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
401f2aedb71SDavid Howells int nfs_try_get_tree(struct fs_context *);
402f2aedb71SDavid Howells int nfs_get_tree_common(struct fs_context *);
403fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *);
4044ebd9ab3SDominik Hackl 
405f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
4064ebd9ab3SDominik Hackl 
407f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
408f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
409ea7c38feSTrond Myklebust extern bool nfs_sb_active(struct super_block *sb);
4101daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb);
411f7b422b1SDavid Howells 
412a5864c99STrond Myklebust /* io.c */
413a5864c99STrond Myklebust extern void nfs_start_io_read(struct inode *inode);
414a5864c99STrond Myklebust extern void nfs_end_io_read(struct inode *inode);
415a5864c99STrond Myklebust extern void nfs_start_io_write(struct inode *inode);
416a5864c99STrond Myklebust extern void nfs_end_io_write(struct inode *inode);
417a5864c99STrond Myklebust extern void nfs_start_io_direct(struct inode *inode);
418a5864c99STrond Myklebust extern void nfs_end_io_direct(struct inode *inode);
419a5864c99STrond Myklebust 
420651b0e70STrond Myklebust static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
421651b0e70STrond Myklebust {
422651b0e70STrond Myklebust 	return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
423651b0e70STrond Myklebust }
424651b0e70STrond Myklebust 
425f7b422b1SDavid Howells /* namespace.c */
42697a54868SBen Hutchings #define NFS_PATH_CANONICAL 1
427b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry,
42897a54868SBen Hutchings 		      char *buffer, ssize_t buflen, unsigned flags);
42936d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path);
430f2aedb71SDavid Howells int nfs_submount(struct fs_context *, struct nfs_server *);
431f2aedb71SDavid Howells int nfs_do_submount(struct fs_context *);
432f7b422b1SDavid Howells 
43354ceac45SDavid Howells /* getroot.c */
43462a55d08SScott Mayhew extern int nfs_get_root(struct super_block *s, struct fs_context *fc);
43589d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
4365e6b1990STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
4377d4e2747SDavid Howells #endif
438f7b422b1SDavid Howells 
439061ae2edSFred Isaman struct nfs_pgio_completion_ops;
440f11c88afSAndy Adamson /* read.c */
441584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
442fab5fc25SChristoph Hellwig 			struct inode *inode, bool force_mds,
443584aa810SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
444f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
445493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
446e885de1aSTrond Myklebust 
447fbdefd64SBryan Schumaker /* super.c */
448fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *);
449fbdefd64SBryan Schumaker int  nfs_statfs(struct dentry *, struct kstatfs *);
450fbdefd64SBryan Schumaker int  nfs_show_options(struct seq_file *, struct dentry *);
451fbdefd64SBryan Schumaker int  nfs_show_devname(struct seq_file *, struct dentry *);
452fbdefd64SBryan Schumaker int  nfs_show_path(struct seq_file *, struct dentry *);
453fbdefd64SBryan Schumaker int  nfs_show_stats(struct seq_file *, struct dentry *);
454f2aedb71SDavid Howells int  nfs_reconfigure(struct fs_context *);
455fbdefd64SBryan Schumaker 
456def6ed7eSAndy Adamson /* write.c */
4571763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
458a20c93e3SChristoph Hellwig 			struct inode *inode, int ioflags, bool force_mds,
4591763da12SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
460dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
4610b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p);
462def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
4630b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
4640b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt,
4650b7c0153SFred Isaman 			       struct nfs_commit_data *data,
466c36aae9aSPeng Tao 			       const struct nfs_rpc_ops *nfs_ops,
467e0c2b380SFred Isaman 			       const struct rpc_call_ops *call_ops,
4689f0ec176SAndy Adamson 			       int how, int flags);
4690b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data,
470e0c2b380SFred Isaman 			    struct list_head *head,
471f453a54aSFred Isaman 			    struct pnfs_layout_segment *lseg,
472f453a54aSFred Isaman 			    struct nfs_commit_info *cinfo);
4731763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
4741763da12SFred Isaman 			 struct nfs_commit_info *cinfo, int max);
475ce59515cSAnna Schumaker unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
4761763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst,
4771763da12SFred Isaman 		    struct nfs_commit_info *cinfo);
4781763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req,
4791763da12SFred Isaman 			     struct pnfs_layout_segment *lseg,
480b57ff130SWeston Andros Adamson 			     struct nfs_commit_info *cinfo,
481b57ff130SWeston Andros Adamson 			     u32 ds_commit_idx);
482c65e6254SWeston Andros Adamson int nfs_write_need_commit(struct nfs_pgio_header *);
483a08a8cd3STrond Myklebust void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
4841763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
4851763da12SFred Isaman 			    int how, struct nfs_commit_info *cinfo);
486e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list,
487ea2cf228SFred Isaman 		      struct pnfs_layout_segment *lseg,
488b57ff130SWeston Andros Adamson 		      struct nfs_commit_info *cinfo,
489b57ff130SWeston Andros Adamson 		      u32 ds_commit_idx);
4900b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data);
4916272dcc6SAnna Schumaker void nfs_request_add_commit_list(struct nfs_page *req,
492ea2cf228SFred Isaman 				 struct nfs_commit_info *cinfo);
49386d80f97STrond Myklebust void nfs_request_add_commit_list_locked(struct nfs_page *req,
49486d80f97STrond Myklebust 		struct list_head *dst,
49586d80f97STrond Myklebust 		struct nfs_commit_info *cinfo);
496ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req,
497ea2cf228SFred Isaman 				    struct nfs_commit_info *cinfo);
498ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo,
499ea2cf228SFred Isaman 		    struct inode *inode,
500ea2cf228SFred Isaman 		    struct nfs_direct_req *dreq);
501dc24826bSAndy Adamson int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
502ce52914eSScott Mayhew bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode);
503a7d42ddbSWeston Andros Adamson void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
504e0c2b380SFred Isaman 
505837bb1d7STrond Myklebust int nfs_filemap_write_and_wait_range(struct address_space *mapping,
506837bb1d7STrond Myklebust 		loff_t lstart, loff_t lend);
507837bb1d7STrond Myklebust 
508a5314a74STrond Myklebust #ifdef CONFIG_NFS_V4_1
509a5314a74STrond Myklebust static inline
510a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
511a5314a74STrond Myklebust {
512a5314a74STrond Myklebust 	int i;
513a5314a74STrond Myklebust 
514a5314a74STrond Myklebust 	for (i = 0; i < cinfo->nbuckets; i++)
515a5314a74STrond Myklebust 		cinfo->buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
516a5314a74STrond Myklebust }
517a5314a74STrond Myklebust #else
518a5314a74STrond Myklebust static inline
519a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
520a5314a74STrond Myklebust {
521a5314a74STrond Myklebust }
522a5314a74STrond Myklebust #endif
523a5314a74STrond Myklebust 
524074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION
525074cc1deSTrond Myklebust extern int nfs_migrate_page(struct address_space *,
526a6bc32b8SMel Gorman 		struct page *, struct page *, enum migrate_mode);
527074cc1deSTrond Myklebust #endif
528def6ed7eSAndy Adamson 
5298fc3c386STrond Myklebust static inline int
5308fc3c386STrond Myklebust nfs_write_verifier_cmp(const struct nfs_write_verifier *v1,
5318fc3c386STrond Myklebust 		const struct nfs_write_verifier *v2)
5328fc3c386STrond Myklebust {
5338fc3c386STrond Myklebust 	return memcmp(v1->data, v2->data, sizeof(v1->data));
5348fc3c386STrond Myklebust }
5358fc3c386STrond Myklebust 
5360e862a40SJeff Layton /* unlink.c */
5370e862a40SJeff Layton extern struct rpc_task *
5380e862a40SJeff Layton nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
5390e862a40SJeff Layton 		 struct dentry *old_dentry, struct dentry *new_dentry,
5400e862a40SJeff Layton 		 void (*complete)(struct rpc_task *, struct nfs_renamedata *));
5410e862a40SJeff Layton extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
5420e862a40SJeff Layton 
5431763da12SFred Isaman /* direct.c */
5441763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
5451763da12SFred Isaman 			      struct nfs_direct_req *dreq);
5466296556fSPeng Tao extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
5471763da12SFred Isaman 
548cccef3b9SAndy Adamson /* nfs4proc.c */
5498cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
5505c6e5b60STrond Myklebust 			    const struct nfs_client_initdata *);
55105f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp,
55205f4c350SChuck Lever 				struct nfs_client **result,
553a52458b4SNeilBrown 				const struct cred *cred);
55405f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp,
55505f4c350SChuck Lever 				struct nfs_client **result,
556a52458b4SNeilBrown 				const struct cred *cred);
55710e037d1SSantosh kumar pradhan extern void nfs4_test_session_trunk(struct rpc_clnt *clnt,
55810e037d1SSantosh kumar pradhan 				struct rpc_xprt *xprt,
55910e037d1SSantosh kumar pradhan 				void *data);
560cccef3b9SAndy Adamson 
561ea7c38feSTrond Myklebust static inline struct inode *nfs_igrab_and_active(struct inode *inode)
562ea7c38feSTrond Myklebust {
563ea7c38feSTrond Myklebust 	inode = igrab(inode);
564ea7c38feSTrond Myklebust 	if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
565ea7c38feSTrond Myklebust 		iput(inode);
566ea7c38feSTrond Myklebust 		inode = NULL;
567ea7c38feSTrond Myklebust 	}
568ea7c38feSTrond Myklebust 	return inode;
569ea7c38feSTrond Myklebust }
570ea7c38feSTrond Myklebust 
571ea7c38feSTrond Myklebust static inline void nfs_iput_and_deactive(struct inode *inode)
572ea7c38feSTrond Myklebust {
573ea7c38feSTrond Myklebust 	if (inode != NULL) {
574ea7c38feSTrond Myklebust 		struct super_block *sb = inode->i_sb;
575ea7c38feSTrond Myklebust 
576ea7c38feSTrond Myklebust 		iput(inode);
577ea7c38feSTrond Myklebust 		nfs_sb_deactive(sb);
578ea7c38feSTrond Myklebust 	}
579ea7c38feSTrond Myklebust }
580ea7c38feSTrond Myklebust 
581557134a3SAndy Adamson /*
582f7b422b1SDavid Howells  * Determine the device name as a string
583f7b422b1SDavid Howells  */
584b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry,
585f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
586f7b422b1SDavid Howells {
587b514f872SAl Viro 	char *dummy;
58897a54868SBen Hutchings 	return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
589f7b422b1SDavid Howells }
590f7b422b1SDavid Howells 
591f7b422b1SDavid Howells /*
592f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
593f7b422b1SDavid Howells  */
594f7b422b1SDavid Howells static inline
595f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
596f7b422b1SDavid Howells {
597f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
598f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
599f7b422b1SDavid Howells 		unsigned char	nrbits;
600f7b422b1SDavid Howells 
601f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
602f7b422b1SDavid Howells 			;
603f7b422b1SDavid Howells 		bsize = 1 << nrbits;
604f7b422b1SDavid Howells 		if (nrbitsp)
605f7b422b1SDavid Howells 			*nrbitsp = nrbits;
606f7b422b1SDavid Howells 	}
607f7b422b1SDavid Howells 
608f7b422b1SDavid Howells 	return bsize;
609f7b422b1SDavid Howells }
610f7b422b1SDavid Howells 
611f7b422b1SDavid Howells /*
612f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
613f7b422b1SDavid Howells  */
6149eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
615f7b422b1SDavid Howells {
6169eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
617f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
618f7b422b1SDavid Howells }
619f7b422b1SDavid Howells 
620f7b422b1SDavid Howells /*
621f7b422b1SDavid Howells  * Compute and set NFS server blocksize
622f7b422b1SDavid Howells  */
623f7b422b1SDavid Howells static inline
624f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
625f7b422b1SDavid Howells {
626f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
627f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
628f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
629f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
630f7b422b1SDavid Howells 
631f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
632f7b422b1SDavid Howells }
633f7b422b1SDavid Howells 
634f7b422b1SDavid Howells /*
635f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
636f7b422b1SDavid Howells  */
637f7b422b1SDavid Howells static inline
638f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
639f7b422b1SDavid Howells {
640f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
641f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
642f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
643f7b422b1SDavid Howells }
64449a70f27STrond Myklebust 
64549a70f27STrond Myklebust /*
646d15bc38dSTom Haynes  * Record the page as unstable and mark its inode as dirty.
647d15bc38dSTom Haynes  */
648d15bc38dSTom Haynes static inline
64986d80f97STrond Myklebust void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo)
650d15bc38dSTom Haynes {
65186d80f97STrond Myklebust 	if (!cinfo->dreq) {
652d15bc38dSTom Haynes 		struct inode *inode = page_file_mapping(page)->host;
653d15bc38dSTom Haynes 
65411fb9989SMel Gorman 		inc_node_page_state(page, NR_UNSTABLE_NFS);
65593f78d88STejun Heo 		inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE);
656d15bc38dSTom Haynes 		__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
657d15bc38dSTom Haynes 	}
65886d80f97STrond Myklebust }
659d15bc38dSTom Haynes 
660d15bc38dSTom Haynes /*
66149a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
66249a70f27STrond Myklebust  */
66349a70f27STrond Myklebust static inline
66449a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
66549a70f27STrond Myklebust {
666d56b4ddfSMel Gorman 	loff_t i_size = i_size_read(page_file_mapping(page)->host);
66749a70f27STrond Myklebust 
66849a70f27STrond Myklebust 	if (i_size > 0) {
6698cd79788SHuang Ying 		pgoff_t index = page_index(page);
67009cbfeafSKirill A. Shutemov 		pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT;
6718cd79788SHuang Ying 		if (index < end_index)
67209cbfeafSKirill A. Shutemov 			return PAGE_SIZE;
6738cd79788SHuang Ying 		if (index == end_index)
67409cbfeafSKirill A. Shutemov 			return ((i_size - 1) & ~PAGE_MASK) + 1;
67549a70f27STrond Myklebust 	}
67649a70f27STrond Myklebust 	return 0;
67749a70f27STrond Myklebust }
6788d5658c9STrond Myklebust 
6798d5658c9STrond Myklebust /*
6800b26a0bfSTrond Myklebust  * Convert a umode to a dirent->d_type
6810b26a0bfSTrond Myklebust  */
6820b26a0bfSTrond Myklebust static inline
6830b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode)
6840b26a0bfSTrond Myklebust {
6850b26a0bfSTrond Myklebust 	return (mode >> 12) & 15;
6860b26a0bfSTrond Myklebust }
6870b26a0bfSTrond Myklebust 
6880b26a0bfSTrond Myklebust /*
6898d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
6908d5658c9STrond Myklebust  * with a base offset of 'base'
6918d5658c9STrond Myklebust  */
6928d5658c9STrond Myklebust static inline
6938d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len)
6948d5658c9STrond Myklebust {
6958d5658c9STrond Myklebust 	return ((unsigned long)len + (unsigned long)base +
6968d5658c9STrond Myklebust 		PAGE_SIZE - 1) >> PAGE_SHIFT;
6978d5658c9STrond Myklebust }
6980110ee15STrond Myklebust 
6993a1556e8STrond Myklebust /*
7003a1556e8STrond Myklebust  * Convert a struct timespec into a 64-bit change attribute
7013a1556e8STrond Myklebust  *
7023a1556e8STrond Myklebust  * This does approximately the same thing as timespec_to_ns(),
7033a1556e8STrond Myklebust  * but for calculation efficiency, we multiply the seconds by
7043a1556e8STrond Myklebust  * 1024*1024*1024.
7053a1556e8STrond Myklebust  */
7063a1556e8STrond Myklebust static inline
707e86d5a02STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec64 *ts)
7083a1556e8STrond Myklebust {
7093a1556e8STrond Myklebust 	return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
7103a1556e8STrond Myklebust }
7111264a2f0STrond Myklebust 
7121264a2f0STrond Myklebust #ifdef CONFIG_CRC32
7131264a2f0STrond Myklebust /**
7141264a2f0STrond Myklebust  * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
7151264a2f0STrond Myklebust  * @fh - pointer to filehandle
7161264a2f0STrond Myklebust  *
7171264a2f0STrond Myklebust  * returns a crc32 hash for the filehandle that is compatible with
7181264a2f0STrond Myklebust  * the one displayed by "wireshark".
7191264a2f0STrond Myklebust  */
7201264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
7211264a2f0STrond Myklebust {
7221264a2f0STrond Myklebust 	return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
7231264a2f0STrond Myklebust }
72448c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid)
72548c9579aSOlga Kornievskaia {
72648c9579aSOlga Kornievskaia 	return ~crc32_le(0xFFFFFFFF, &stateid->other[0],
72748c9579aSOlga Kornievskaia 				NFS4_STATEID_OTHER_SIZE);
72848c9579aSOlga Kornievskaia }
7291264a2f0STrond Myklebust #else
7301264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
7311264a2f0STrond Myklebust {
7321264a2f0STrond Myklebust 	return 0;
7331264a2f0STrond Myklebust }
73448c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
73548c9579aSOlga Kornievskaia {
73648c9579aSOlga Kornievskaia 	return 0;
73748c9579aSOlga Kornievskaia }
7381264a2f0STrond Myklebust #endif
7390bcbf039SPeng Tao 
7400bcbf039SPeng Tao static inline bool nfs_error_is_fatal(int err)
7410bcbf039SPeng Tao {
7420bcbf039SPeng Tao 	switch (err) {
7430bcbf039SPeng Tao 	case -ERESTARTSYS:
7447dc58ca5STrond Myklebust 	case -EINTR:
74554551d85STrond Myklebust 	case -EACCES:
74654551d85STrond Myklebust 	case -EDQUOT:
74754551d85STrond Myklebust 	case -EFBIG:
7480bcbf039SPeng Tao 	case -EIO:
7490bcbf039SPeng Tao 	case -ENOSPC:
7500bcbf039SPeng Tao 	case -EROFS:
75154551d85STrond Myklebust 	case -ESTALE:
7520bcbf039SPeng Tao 	case -E2BIG:
7532dc23affSTrond Myklebust 	case -ENOMEM:
75411982a7cSTrond Myklebust 	case -ETIMEDOUT:
7550bcbf039SPeng Tao 		return true;
7560bcbf039SPeng Tao 	default:
7570bcbf039SPeng Tao 		return false;
7580bcbf039SPeng Tao 	}
7590bcbf039SPeng Tao }
760bf4b4905SNeilBrown 
7618f54c7a4STrond Myklebust static inline bool nfs_error_is_fatal_on_server(int err)
7628f54c7a4STrond Myklebust {
7638f54c7a4STrond Myklebust 	switch (err) {
7648f54c7a4STrond Myklebust 	case 0:
7658f54c7a4STrond Myklebust 	case -ERESTARTSYS:
7668f54c7a4STrond Myklebust 	case -EINTR:
7678f54c7a4STrond Myklebust 		return false;
7688f54c7a4STrond Myklebust 	}
7698f54c7a4STrond Myklebust 	return nfs_error_is_fatal(err);
7708f54c7a4STrond Myklebust }
7719954bf92SDavid Howells 
7729954bf92SDavid Howells /*
7739954bf92SDavid Howells  * Select between a default port value and a user-specified port value.
7749954bf92SDavid Howells  * If a zero value is set, then autobind will be used.
7759954bf92SDavid Howells  */
7769954bf92SDavid Howells static inline void nfs_set_port(struct sockaddr *sap, int *port,
7779954bf92SDavid Howells 				const unsigned short default_port)
7789954bf92SDavid Howells {
7799954bf92SDavid Howells 	if (*port == NFS_UNSPEC_PORT)
7809954bf92SDavid Howells 		*port = default_port;
7819954bf92SDavid Howells 
7829954bf92SDavid Howells 	rpc_set_port(sap, *port);
7839954bf92SDavid Howells }
784