xref: /openbmc/linux/fs/nfs/internal.h (revision 48be8a66)
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"
7f7b422b1SDavid Howells #include <linux/mount.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 
141751e8a6SLinus Torvalds #define NFS_MS_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;
1954ceac45SDavid Howells 
207ebb9315SBryan Schumaker static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
217ebb9315SBryan Schumaker {
227ebb9315SBryan Schumaker 	if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
237ebb9315SBryan Schumaker 		fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT;
247ebb9315SBryan Schumaker }
257ebb9315SBryan Schumaker 
26533eb461SAndy Adamson static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)
27533eb461SAndy Adamson {
28533eb461SAndy Adamson 	if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) ||
29533eb461SAndy Adamson 	    (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) &&
30533eb461SAndy Adamson 	     ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0)))
31533eb461SAndy Adamson 		return 0;
32533eb461SAndy Adamson 	return 1;
33533eb461SAndy Adamson }
34533eb461SAndy Adamson 
35f7b422b1SDavid Howells struct nfs_clone_mount {
36f7b422b1SDavid Howells 	const struct super_block *sb;
37f7b422b1SDavid Howells 	const struct dentry *dentry;
38f7b422b1SDavid Howells 	char *hostname;
39f7b422b1SDavid Howells 	char *mnt_path;
406677d095SChuck Lever 	struct sockaddr *addr;
416677d095SChuck Lever 	size_t addrlen;
42f7b422b1SDavid Howells 	rpc_authflavor_t authflavor;
43f7b422b1SDavid Howells };
44f7b422b1SDavid Howells 
456b18eaa0S\"Talpey, Thomas\ /*
46a14017dbSChuck Lever  * Note: RFC 1813 doesn't limit the number of auth flavors that
47a14017dbSChuck Lever  * a server can return, so make something up.
48a14017dbSChuck Lever  */
49a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS	(12)
50a14017dbSChuck Lever 
51a14017dbSChuck Lever /*
524cfd74fcSChuck Lever  * Value used if the user did not specify a port value.
534cfd74fcSChuck Lever  */
544cfd74fcSChuck Lever #define NFS_UNSPEC_PORT		(-1)
554cfd74fcSChuck Lever 
56a956bedaSTrond Myklebust #define NFS_UNSPEC_RETRANS	(UINT_MAX)
57a956bedaSTrond Myklebust #define NFS_UNSPEC_TIMEO	(UINT_MAX)
58a956bedaSTrond Myklebust 
594cfd74fcSChuck Lever /*
6056e4ebf8SBryan Schumaker  * Maximum number of pages that readdir can use for creating
6156e4ebf8SBryan Schumaker  * a vmapped array of pages.
6256e4ebf8SBryan Schumaker  */
63db531db9SMax Kellermann #define NFS_MAX_READDIR_PAGES 8
6456e4ebf8SBryan Schumaker 
65fcf10398SBryan Schumaker struct nfs_client_initdata {
66fcf10398SBryan Schumaker 	unsigned long init_flags;
675c6e5b60STrond Myklebust 	const char *hostname;			/* Hostname of the server */
685c6e5b60STrond Myklebust 	const struct sockaddr *addr;		/* Address of the server */
695c6e5b60STrond Myklebust 	const char *nodename;			/* Hostname of the client */
705c6e5b60STrond Myklebust 	const char *ip_addr;			/* IP address of the client */
71fcf10398SBryan Schumaker 	size_t addrlen;
72ab7017a3SBryan Schumaker 	struct nfs_subversion *nfs_mod;
73fcf10398SBryan Schumaker 	int proto;
74fcf10398SBryan Schumaker 	u32 minorversion;
756619079dSTrond Myklebust 	unsigned int nconnect;
76fcf10398SBryan Schumaker 	struct net *net;
775c6e5b60STrond Myklebust 	const struct rpc_timeout *timeparms;
781a58e8a0STrond Myklebust 	const struct cred *cred;
79fcf10398SBryan Schumaker };
80fcf10398SBryan Schumaker 
8156e4ebf8SBryan Schumaker /*
826b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
836b18eaa0S\"Talpey, Thomas\  */
845eb005caSDavid Howells struct nfs_fs_context {
856b18eaa0S\"Talpey, Thomas\ 	int			flags;
868cb7f74eSChuck Lever 	unsigned int		rsize, wsize;
878cb7f74eSChuck Lever 	unsigned int		timeo, retrans;
888cb7f74eSChuck Lever 	unsigned int		acregmin, acregmax,
896b18eaa0S\"Talpey, Thomas\ 				acdirmin, acdirmax;
908cb7f74eSChuck Lever 	unsigned int		namlen;
91b797cac7SDavid Howells 	unsigned int		options;
926b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
93a3f73c27SWeston Andros Adamson 	struct nfs_auth_info	auth_info;
94a3f73c27SWeston Andros Adamson 	rpc_authflavor_t	selected_flavor;
956b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
96764302ccSChuck Lever 	unsigned int		version;
973fd5be9eSMike Sager 	unsigned int		minorversion;
9808734048SDavid Howells 	char			*fscache_uniq;
99f8ee01e3SDavid Howells 	unsigned short		protofamily;
100f8ee01e3SDavid Howells 	unsigned short		mountfamily;
101b72e4f42SBryan Schumaker 	bool			need_mount;
102f8ee01e3SDavid Howells 	bool			sloppy;
1036b18eaa0S\"Talpey, Thomas\ 
1046b18eaa0S\"Talpey, Thomas\ 	struct {
1054c568017SChuck Lever 		struct sockaddr_storage	address;
1064c568017SChuck Lever 		size_t			addrlen;
1076b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
10878fa701fSChuck Lever 		u32			version;
1094cfd74fcSChuck Lever 		int			port;
11078fa701fSChuck Lever 		unsigned short		protocol;
1116b18eaa0S\"Talpey, Thomas\ 	} mount_server;
1126b18eaa0S\"Talpey, Thomas\ 
1136b18eaa0S\"Talpey, Thomas\ 	struct {
1144c568017SChuck Lever 		struct sockaddr_storage	address;
1154c568017SChuck Lever 		size_t			addrlen;
1166b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
1176b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
1184cfd74fcSChuck Lever 		int			port;
11978fa701fSChuck Lever 		unsigned short		protocol;
12028cc5cd8STrond Myklebust 		unsigned short		nconnect;
1216b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
122f9c3a380SEric Paris 
123204cc0ccSAl Viro 	void			*lsm_opts;
124e50a7a1aSStanislav Kinsbursky 	struct net		*net;
12548be8a66SDavid Howells 
12648be8a66SDavid Howells 	char			buf[32];	/* Parse buffer */
1276b18eaa0S\"Talpey, Thomas\ };
1286b18eaa0S\"Talpey, Thomas\ 
129146ec944SChuck Lever /* mount_clnt.c */
130c5d120f8SChuck Lever struct nfs_mount_request {
131c5d120f8SChuck Lever 	struct sockaddr		*sap;
132c5d120f8SChuck Lever 	size_t			salen;
133c5d120f8SChuck Lever 	char			*hostname;
134c5d120f8SChuck Lever 	char			*dirpath;
135c5d120f8SChuck Lever 	u32			version;
136c5d120f8SChuck Lever 	unsigned short		protocol;
137c5d120f8SChuck Lever 	struct nfs_fh		*fh;
13850a737f8SChuck Lever 	int			noresvport;
1398e02f6b9SChuck Lever 	unsigned int		*auth_flav_len;
1408e02f6b9SChuck Lever 	rpc_authflavor_t	*auth_flavs;
1416d59b8d5SStanislav Kinsbursky 	struct net		*net;
142c5d120f8SChuck Lever };
143c5d120f8SChuck Lever 
144fbdefd64SBryan Schumaker struct nfs_mount_info {
145ab88dca3SAl Viro 	unsigned int inherited_bsize;
1465eb005caSDavid Howells 	struct nfs_fs_context *ctx;
147fbdefd64SBryan Schumaker 	struct nfs_clone_mount *cloned;
148d0b779d4SAl Viro 	struct nfs_server *server;
149fbdefd64SBryan Schumaker 	struct nfs_fh *mntfh;
1506a3f7a39SAl Viro 	struct nfs_subversion *nfs_mod;
151fbdefd64SBryan Schumaker };
152fbdefd64SBryan Schumaker 
153c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info);
1540b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info);
155146ec944SChuck Lever 
15624c8dbbbSDavid Howells /* client.c */
157a613fa16STrond Myklebust extern const struct rpc_program nfs_program;
1586b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net);
15910b7a70cSTrond Myklebust extern void nfs_clients_exit(struct net *net);
1606663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
1615c6e5b60STrond Myklebust int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
1627d38de3fSAnna Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
163fcf10398SBryan Schumaker int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
164fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *);
16532e62b7cSChuck Lever void nfs_server_remove_lists(struct nfs_server *);
166a956bedaSTrond Myklebust void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
167fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
168fcf10398SBryan Schumaker 		rpc_authflavor_t);
169fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void);
170fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
17154ceac45SDavid Howells 
17224c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
173cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *);
17428cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
175c36fca52SAndy Adamson extern struct nfs_client *
176c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
177459de2edSBryan Schumaker 				struct nfs4_sessionid *, u32);
1780c38f213SAl Viro extern struct nfs_server *nfs_create_server(struct nfs_mount_info *);
1790c38f213SAl Viro extern struct nfs_server *nfs4_create_server(struct nfs_mount_info *);
18054ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
18154ceac45SDavid Howells 						      struct nfs_fh *);
18232e62b7cSChuck Lever extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
183292f503cSTrond Myklebust 					struct sockaddr *sap, size_t salen,
184292f503cSTrond Myklebust 					struct net *net);
18554ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
18654ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
18754ceac45SDavid Howells 					   struct nfs_fh *,
1887e6eb683SBryan Schumaker 					   struct nfs_fattr *,
1897e6eb683SBryan Schumaker 					   rpc_authflavor_t);
190a33e4b03SWeston Andros Adamson extern bool nfs_client_init_is_complete(const struct nfs_client *clp);
191a33e4b03SWeston Andros Adamson extern int nfs_client_init_status(const struct nfs_client *clp);
1924697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
19376db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
1943fc75f12STigran Mkrtchyan extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
195d83217c1SAndy Adamson 					     const struct sockaddr *ds_addr,
19698fc685aSAndy Adamson 					     int ds_addrlen, int ds_proto,
19798fc685aSAndy Adamson 					     unsigned int ds_timeo,
198064172f3SPeng Tao 					     unsigned int ds_retrans,
1997d38de3fSAnna Schumaker 					     u32 minor_version);
2000e20162eSAndy Adamson extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
2010e20162eSAndy Adamson 						struct inode *);
202b224f7cbSTigran Mkrtchyan extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
2031a04c6e1SPeng Tao 			const struct sockaddr *ds_addr, int ds_addrlen,
2041a04c6e1SPeng Tao 			int ds_proto, unsigned int ds_timeo,
2057d38de3fSAnna Schumaker 			unsigned int ds_retrans);
2066aaca566SDavid Howells #ifdef CONFIG_PROC_FS
2076aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
2086aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
20965b38851SEric W. Biederman extern int nfs_fs_proc_net_init(struct net *net);
21065b38851SEric W. Biederman extern void nfs_fs_proc_net_exit(struct net *net);
2116aaca566SDavid Howells #else
21265b38851SEric W. Biederman static inline int nfs_fs_proc_net_init(struct net *net)
21365b38851SEric W. Biederman {
21465b38851SEric W. Biederman 	return 0;
21565b38851SEric W. Biederman }
21665b38851SEric W. Biederman static inline void nfs_fs_proc_net_exit(struct net *net)
21765b38851SEric W. Biederman {
21865b38851SEric W. Biederman }
2196aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
2206aaca566SDavid Howells {
2216aaca566SDavid Howells 	return 0;
2226aaca566SDavid Howells }
2236aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
2246aaca566SDavid Howells {
2256aaca566SDavid Howells }
2266aaca566SDavid Howells #endif
22724c8dbbbSDavid Howells 
228f7b422b1SDavid Howells /* callback_xdr.c */
229e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version1;
230e9679189SChristoph Hellwig extern const struct svc_version nfs4_callback_version4;
231f7b422b1SDavid Howells 
2324db6e0b7SFred Isaman struct nfs_pageio_descriptor;
2339954bf92SDavid Howells 
2349954bf92SDavid Howells /* mount.c */
2359954bf92SDavid Howells #define NFS_TEXT_DATA		1
2369954bf92SDavid Howells 
2375eb005caSDavid Howells extern struct nfs_fs_context *nfs_alloc_parsed_mount_data(void);
2385eb005caSDavid Howells extern void nfs_free_parsed_mount_data(struct nfs_fs_context *ctx);
2395eb005caSDavid Howells extern int nfs_parse_mount_options(char *raw, struct nfs_fs_context *ctx);
2409954bf92SDavid Howells extern int nfs_validate_mount_data(struct file_system_type *fs_type,
2419954bf92SDavid Howells 				   void *options,
2425eb005caSDavid Howells 				   struct nfs_fs_context *ctx,
2439954bf92SDavid Howells 				   struct nfs_fh *mntfh,
2449954bf92SDavid Howells 				   const char *dev_name);
2459954bf92SDavid Howells extern int nfs_validate_text_mount_data(void *options,
2465eb005caSDavid Howells 					struct nfs_fs_context *ctx,
2479954bf92SDavid Howells 					const char *dev_name);
2489954bf92SDavid Howells 
249f7b422b1SDavid Howells /* pagelist.c */
250f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
251266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
252f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
253266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
254f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
255266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
256f7b422b1SDavid Howells 
257f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
258266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
2594db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
2604db6e0b7SFred Isaman 			      struct nfs_pgio_header *hdr,
2614db6e0b7SFred Isaman 			      void (*release)(struct nfs_pgio_header *hdr));
2624db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
263210c7c17SBenjamin Coddington int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
264577b4232STrond Myklebust 
26541d8d5b7SAnna Schumaker extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
2661e7f3a48SWeston Andros Adamson struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
2671e7f3a48SWeston Andros Adamson void nfs_pgio_header_free(struct nfs_pgio_header *);
268ef2c488cSAnna Schumaker int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
26946a5ab47SPeng Tao int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
270a52458b4SNeilBrown 		      const struct cred *cred, const struct nfs_rpc_ops *rpc_ops,
27146a5ab47SPeng Tao 		      const struct rpc_call_ops *call_ops, int how, int flags);
272d4581383SWeston Andros Adamson void nfs_free_request(struct nfs_page *req);
27348d635f1SPeng Tao struct nfs_pgio_mirror *
27448d635f1SPeng Tao nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
27500bfa30aSAnna Schumaker 
27647af81f2SPeng Tao static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc)
27747af81f2SPeng Tao {
27847af81f2SPeng Tao 	WARN_ON_ONCE(desc->pg_mirror_count < 1);
27947af81f2SPeng Tao 	return desc->pg_mirror_count > 1;
28047af81f2SPeng Tao }
28147af81f2SPeng Tao 
282138a2935STrond Myklebust static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
283138a2935STrond Myklebust 		const struct nfs_open_context *ctx2)
284138a2935STrond Myklebust {
285a52458b4SNeilBrown 	return cred_fscmp(ctx1->cred, ctx2->cred) == 0 && ctx1->state == ctx2->state;
286138a2935STrond Myklebust }
287138a2935STrond Myklebust 
288f7b422b1SDavid Howells /* nfs2xdr.c */
289499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs_procedures[];
290573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *,
291a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
292f7b422b1SDavid Howells 
293f7b422b1SDavid Howells /* nfs3xdr.c */
294499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs3_procedures[];
295573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *,
296a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
297f7b422b1SDavid Howells 
298f7b422b1SDavid Howells /* nfs4xdr.c */
29989d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
300573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *,
301a7a3b1e9SBenjamin Coddington 				struct nfs_entry *, bool);
3027d4e2747SDavid Howells #endif
3032449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
3042449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead;
3052449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead;
306f1c097beSAndy Adamson extern const u32 nfs41_maxgetdevinfo_overhead;
3072449ea2eSAlexandros Batsakis #endif
308f7b422b1SDavid Howells 
309f7b422b1SDavid Howells /* nfs4proc.c */
31089d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
311499b4988SChristoph Hellwig extern const struct rpc_procinfo nfs4_procedures[];
312d75d5414SAndrew Morton #endif
313f7b422b1SDavid Howells 
314694e096fSAnna Schumaker #ifdef CONFIG_NFS_V4_SECURITY_LABEL
315694e096fSAnna Schumaker extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
316a49c2691SKinglong Mee static inline struct nfs4_label *
317a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
318a49c2691SKinglong Mee {
319a49c2691SKinglong Mee 	if (!dst || !src)
320a49c2691SKinglong Mee 		return NULL;
321a49c2691SKinglong Mee 
322a49c2691SKinglong Mee 	if (src->len > NFS4_MAXLABELLEN)
323a49c2691SKinglong Mee 		return NULL;
324a49c2691SKinglong Mee 
325a49c2691SKinglong Mee 	dst->lfs = src->lfs;
326a49c2691SKinglong Mee 	dst->pi = src->pi;
327a49c2691SKinglong Mee 	dst->len = src->len;
328a49c2691SKinglong Mee 	memcpy(dst->label, src->label, src->len);
329a49c2691SKinglong Mee 
330a49c2691SKinglong Mee 	return dst;
331a49c2691SKinglong Mee }
332694e096fSAnna Schumaker static inline void nfs4_label_free(struct nfs4_label *label)
333694e096fSAnna Schumaker {
334694e096fSAnna Schumaker 	if (label) {
335694e096fSAnna Schumaker 		kfree(label->label);
336694e096fSAnna Schumaker 		kfree(label);
337694e096fSAnna Schumaker 	}
338694e096fSAnna Schumaker 	return;
339694e096fSAnna Schumaker }
340fd1defc2STrond Myklebust 
341fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
342fd1defc2STrond Myklebust {
343fd1defc2STrond Myklebust 	if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
344fd1defc2STrond Myklebust 		nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
345fd1defc2STrond Myklebust }
346694e096fSAnna Schumaker #else
347694e096fSAnna Schumaker static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
348694e096fSAnna Schumaker static inline void nfs4_label_free(void *label) {}
349fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
350fd1defc2STrond Myklebust {
351fd1defc2STrond Myklebust }
352a49c2691SKinglong Mee static inline struct nfs4_label *
353a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
354a49c2691SKinglong Mee {
355a49c2691SKinglong Mee 	return NULL;
356a49c2691SKinglong Mee }
357694e096fSAnna Schumaker #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
358694e096fSAnna Schumaker 
3597fe5c398STrond Myklebust /* proc.c */
3607fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
3618cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
3625c6e5b60STrond Myklebust 			   const struct nfs_client_initdata *);
3637fe5c398STrond Myklebust 
364979df72eSTrond Myklebust /* dir.c */
3651bcf4c5cSTrond Myklebust extern void nfs_advise_use_readdirplus(struct inode *dir);
366311324adSTrond Myklebust extern void nfs_force_use_readdirplus(struct inode *dir);
3671ab6c499SDave Chinner extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
3681ab6c499SDave Chinner 					    struct shrink_control *sc);
3691ab6c499SDave Chinner extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
3701495f230SYing Han 					   struct shrink_control *sc);
371597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
372597d9289SBryan Schumaker int nfs_create(struct inode *, struct dentry *, umode_t, bool);
373597d9289SBryan Schumaker int nfs_mkdir(struct inode *, struct dentry *, umode_t);
374597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *);
375597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *);
376597d9289SBryan Schumaker int nfs_symlink(struct inode *, struct dentry *, const char *);
377597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *);
378597d9289SBryan Schumaker int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
3791cd66c93SMiklos Szeredi int nfs_rename(struct inode *, struct dentry *,
3801cd66c93SMiklos Szeredi 	       struct inode *, struct dentry *, unsigned int);
381979df72eSTrond Myklebust 
382ce4ef7c0SBryan Schumaker /* file.c */
3834ff79bc7SChristoph Hellwig int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
384ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int);
3853aa2d199SAl Viro ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
386ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *);
387edaf4369SAl Viro ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
388ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *);
389ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *);
390ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *);
391ce4ef7c0SBryan Schumaker int nfs_check_flags(int);
392ce4ef7c0SBryan Schumaker 
393f7b422b1SDavid Howells /* inode.c */
3945746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
395f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
396ca1a199eSAl Viro extern void nfs_free_inode(struct inode *);
397a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *);
398eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *);
39919d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *);
400b57922d9SAl Viro extern void nfs_evict_inode(struct inode *);
401f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode);
40261540bf6STrond Myklebust extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
403dfd01f02SPeter Zijlstra extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
4045e4def20SDavid Howells extern int nfs_wait_atomic_killable(atomic_t *p, unsigned int mode);
405f7b422b1SDavid Howells 
406f7b422b1SDavid Howells /* super.c */
4076a74490dSBryan Schumaker extern const struct super_operations nfs_sops;
408ab7017a3SBryan Schumaker extern struct file_system_type nfs_fs_type;
40982eaed2bSAl Viro extern struct file_system_type nfs_prepared_fs_type;
41089d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
41154ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type;
412f7b422b1SDavid Howells #endif
4134d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
414a55d3297SAl Viro struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *);
415fbdefd64SBryan Schumaker struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *);
416fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *);
4174ebd9ab3SDominik Hackl 
418f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
4194ebd9ab3SDominik Hackl 
420f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
421f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
422ea7c38feSTrond Myklebust extern bool nfs_sb_active(struct super_block *sb);
4231daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb);
424f7b422b1SDavid Howells 
425a5864c99STrond Myklebust /* io.c */
426a5864c99STrond Myklebust extern void nfs_start_io_read(struct inode *inode);
427a5864c99STrond Myklebust extern void nfs_end_io_read(struct inode *inode);
428a5864c99STrond Myklebust extern void nfs_start_io_write(struct inode *inode);
429a5864c99STrond Myklebust extern void nfs_end_io_write(struct inode *inode);
430a5864c99STrond Myklebust extern void nfs_start_io_direct(struct inode *inode);
431a5864c99STrond Myklebust extern void nfs_end_io_direct(struct inode *inode);
432a5864c99STrond Myklebust 
433651b0e70STrond Myklebust static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
434651b0e70STrond Myklebust {
435651b0e70STrond Myklebust 	return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
436651b0e70STrond Myklebust }
437651b0e70STrond Myklebust 
438f7b422b1SDavid Howells /* namespace.c */
43997a54868SBen Hutchings #define NFS_PATH_CANONICAL 1
440b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry,
44197a54868SBen Hutchings 		      char *buffer, ssize_t buflen, unsigned flags);
44236d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path);
443281cad46SBryan Schumaker struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
444281cad46SBryan Schumaker 			      struct nfs_fh *, struct nfs_fattr *);
445281cad46SBryan Schumaker struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
446281cad46SBryan Schumaker 				 struct nfs_fattr *, rpc_authflavor_t);
447f7b422b1SDavid Howells 
44854ceac45SDavid Howells /* getroot.c */
4490d5839adSAl Viro extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
4500d5839adSAl Viro 				   const char *);
45189d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
4520d5839adSAl Viro extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
4530d5839adSAl Viro 				    const char *);
45454ceac45SDavid Howells 
4555e6b1990STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
4567d4e2747SDavid Howells #endif
457f7b422b1SDavid Howells 
458061ae2edSFred Isaman struct nfs_pgio_completion_ops;
459f11c88afSAndy Adamson /* read.c */
460584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
461fab5fc25SChristoph Hellwig 			struct inode *inode, bool force_mds,
462584aa810SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
463f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
464493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
465e885de1aSTrond Myklebust 
466fbdefd64SBryan Schumaker /* super.c */
467fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *);
468fbdefd64SBryan Schumaker int  nfs_statfs(struct dentry *, struct kstatfs *);
469fbdefd64SBryan Schumaker int  nfs_show_options(struct seq_file *, struct dentry *);
470fbdefd64SBryan Schumaker int  nfs_show_devname(struct seq_file *, struct dentry *);
471fbdefd64SBryan Schumaker int  nfs_show_path(struct seq_file *, struct dentry *);
472fbdefd64SBryan Schumaker int  nfs_show_stats(struct seq_file *, struct dentry *);
473fbdefd64SBryan Schumaker int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
474fbdefd64SBryan Schumaker 
475def6ed7eSAndy Adamson /* write.c */
4761763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
477a20c93e3SChristoph Hellwig 			struct inode *inode, int ioflags, bool force_mds,
4781763da12SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
479dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
4800b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p);
481def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
4820b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
4830b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt,
4840b7c0153SFred Isaman 			       struct nfs_commit_data *data,
485c36aae9aSPeng Tao 			       const struct nfs_rpc_ops *nfs_ops,
486e0c2b380SFred Isaman 			       const struct rpc_call_ops *call_ops,
4879f0ec176SAndy Adamson 			       int how, int flags);
4880b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data,
489e0c2b380SFred Isaman 			    struct list_head *head,
490f453a54aSFred Isaman 			    struct pnfs_layout_segment *lseg,
491f453a54aSFred Isaman 			    struct nfs_commit_info *cinfo);
4921763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
4931763da12SFred Isaman 			 struct nfs_commit_info *cinfo, int max);
494ce59515cSAnna Schumaker unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
4951763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst,
4961763da12SFred Isaman 		    struct nfs_commit_info *cinfo);
4971763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req,
4981763da12SFred Isaman 			     struct pnfs_layout_segment *lseg,
499b57ff130SWeston Andros Adamson 			     struct nfs_commit_info *cinfo,
500b57ff130SWeston Andros Adamson 			     u32 ds_commit_idx);
501c65e6254SWeston Andros Adamson int nfs_write_need_commit(struct nfs_pgio_header *);
502a08a8cd3STrond Myklebust void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
5031763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
5041763da12SFred Isaman 			    int how, struct nfs_commit_info *cinfo);
505e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list,
506ea2cf228SFred Isaman 		      struct pnfs_layout_segment *lseg,
507b57ff130SWeston Andros Adamson 		      struct nfs_commit_info *cinfo,
508b57ff130SWeston Andros Adamson 		      u32 ds_commit_idx);
5090b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data);
5106272dcc6SAnna Schumaker void nfs_request_add_commit_list(struct nfs_page *req,
511ea2cf228SFred Isaman 				 struct nfs_commit_info *cinfo);
51286d80f97STrond Myklebust void nfs_request_add_commit_list_locked(struct nfs_page *req,
51386d80f97STrond Myklebust 		struct list_head *dst,
51486d80f97STrond Myklebust 		struct nfs_commit_info *cinfo);
515ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req,
516ea2cf228SFred Isaman 				    struct nfs_commit_info *cinfo);
517ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo,
518ea2cf228SFred Isaman 		    struct inode *inode,
519ea2cf228SFred Isaman 		    struct nfs_direct_req *dreq);
520dc24826bSAndy Adamson int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
521ce52914eSScott Mayhew bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode);
522a7d42ddbSWeston Andros Adamson void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
523e0c2b380SFred Isaman 
524837bb1d7STrond Myklebust int nfs_filemap_write_and_wait_range(struct address_space *mapping,
525837bb1d7STrond Myklebust 		loff_t lstart, loff_t lend);
526837bb1d7STrond Myklebust 
527a5314a74STrond Myklebust #ifdef CONFIG_NFS_V4_1
528a5314a74STrond Myklebust static inline
529a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
530a5314a74STrond Myklebust {
531a5314a74STrond Myklebust 	int i;
532a5314a74STrond Myklebust 
533a5314a74STrond Myklebust 	for (i = 0; i < cinfo->nbuckets; i++)
534a5314a74STrond Myklebust 		cinfo->buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
535a5314a74STrond Myklebust }
536a5314a74STrond Myklebust #else
537a5314a74STrond Myklebust static inline
538a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
539a5314a74STrond Myklebust {
540a5314a74STrond Myklebust }
541a5314a74STrond Myklebust #endif
542a5314a74STrond Myklebust 
543074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION
544074cc1deSTrond Myklebust extern int nfs_migrate_page(struct address_space *,
545a6bc32b8SMel Gorman 		struct page *, struct page *, enum migrate_mode);
546074cc1deSTrond Myklebust #endif
547def6ed7eSAndy Adamson 
5488fc3c386STrond Myklebust static inline int
5498fc3c386STrond Myklebust nfs_write_verifier_cmp(const struct nfs_write_verifier *v1,
5508fc3c386STrond Myklebust 		const struct nfs_write_verifier *v2)
5518fc3c386STrond Myklebust {
5528fc3c386STrond Myklebust 	return memcmp(v1->data, v2->data, sizeof(v1->data));
5538fc3c386STrond Myklebust }
5548fc3c386STrond Myklebust 
5550e862a40SJeff Layton /* unlink.c */
5560e862a40SJeff Layton extern struct rpc_task *
5570e862a40SJeff Layton nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
5580e862a40SJeff Layton 		 struct dentry *old_dentry, struct dentry *new_dentry,
5590e862a40SJeff Layton 		 void (*complete)(struct rpc_task *, struct nfs_renamedata *));
5600e862a40SJeff Layton extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
5610e862a40SJeff Layton 
5621763da12SFred Isaman /* direct.c */
5631763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
5641763da12SFred Isaman 			      struct nfs_direct_req *dreq);
5656296556fSPeng Tao extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
5661763da12SFred Isaman 
567cccef3b9SAndy Adamson /* nfs4proc.c */
5688cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
5695c6e5b60STrond Myklebust 			    const struct nfs_client_initdata *);
57005f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp,
57105f4c350SChuck Lever 				struct nfs_client **result,
572a52458b4SNeilBrown 				const struct cred *cred);
57305f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp,
57405f4c350SChuck Lever 				struct nfs_client **result,
575a52458b4SNeilBrown 				const struct cred *cred);
57610e037d1SSantosh kumar pradhan extern void nfs4_test_session_trunk(struct rpc_clnt *clnt,
57710e037d1SSantosh kumar pradhan 				struct rpc_xprt *xprt,
57810e037d1SSantosh kumar pradhan 				void *data);
579cccef3b9SAndy Adamson 
580ea7c38feSTrond Myklebust static inline struct inode *nfs_igrab_and_active(struct inode *inode)
581ea7c38feSTrond Myklebust {
582ea7c38feSTrond Myklebust 	inode = igrab(inode);
583ea7c38feSTrond Myklebust 	if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
584ea7c38feSTrond Myklebust 		iput(inode);
585ea7c38feSTrond Myklebust 		inode = NULL;
586ea7c38feSTrond Myklebust 	}
587ea7c38feSTrond Myklebust 	return inode;
588ea7c38feSTrond Myklebust }
589ea7c38feSTrond Myklebust 
590ea7c38feSTrond Myklebust static inline void nfs_iput_and_deactive(struct inode *inode)
591ea7c38feSTrond Myklebust {
592ea7c38feSTrond Myklebust 	if (inode != NULL) {
593ea7c38feSTrond Myklebust 		struct super_block *sb = inode->i_sb;
594ea7c38feSTrond Myklebust 
595ea7c38feSTrond Myklebust 		iput(inode);
596ea7c38feSTrond Myklebust 		nfs_sb_deactive(sb);
597ea7c38feSTrond Myklebust 	}
598ea7c38feSTrond Myklebust }
599ea7c38feSTrond Myklebust 
600557134a3SAndy Adamson /*
601f7b422b1SDavid Howells  * Determine the device name as a string
602f7b422b1SDavid Howells  */
603b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry,
604f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
605f7b422b1SDavid Howells {
606b514f872SAl Viro 	char *dummy;
60797a54868SBen Hutchings 	return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
608f7b422b1SDavid Howells }
609f7b422b1SDavid Howells 
610f7b422b1SDavid Howells /*
611f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
612f7b422b1SDavid Howells  */
613f7b422b1SDavid Howells static inline
614f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
615f7b422b1SDavid Howells {
616f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
617f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
618f7b422b1SDavid Howells 		unsigned char	nrbits;
619f7b422b1SDavid Howells 
620f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
621f7b422b1SDavid Howells 			;
622f7b422b1SDavid Howells 		bsize = 1 << nrbits;
623f7b422b1SDavid Howells 		if (nrbitsp)
624f7b422b1SDavid Howells 			*nrbitsp = nrbits;
625f7b422b1SDavid Howells 	}
626f7b422b1SDavid Howells 
627f7b422b1SDavid Howells 	return bsize;
628f7b422b1SDavid Howells }
629f7b422b1SDavid Howells 
630f7b422b1SDavid Howells /*
631f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
632f7b422b1SDavid Howells  */
6339eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
634f7b422b1SDavid Howells {
6359eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
636f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
637f7b422b1SDavid Howells }
638f7b422b1SDavid Howells 
639f7b422b1SDavid Howells /*
640f7b422b1SDavid Howells  * Compute and set NFS server blocksize
641f7b422b1SDavid Howells  */
642f7b422b1SDavid Howells static inline
643f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
644f7b422b1SDavid Howells {
645f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
646f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
647f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
648f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
649f7b422b1SDavid Howells 
650f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
651f7b422b1SDavid Howells }
652f7b422b1SDavid Howells 
653f7b422b1SDavid Howells /*
654f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
655f7b422b1SDavid Howells  */
656f7b422b1SDavid Howells static inline
657f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
658f7b422b1SDavid Howells {
659f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
660f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
661f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
662f7b422b1SDavid Howells }
66349a70f27STrond Myklebust 
66449a70f27STrond Myklebust /*
665d15bc38dSTom Haynes  * Record the page as unstable and mark its inode as dirty.
666d15bc38dSTom Haynes  */
667d15bc38dSTom Haynes static inline
66886d80f97STrond Myklebust void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo)
669d15bc38dSTom Haynes {
67086d80f97STrond Myklebust 	if (!cinfo->dreq) {
671d15bc38dSTom Haynes 		struct inode *inode = page_file_mapping(page)->host;
672d15bc38dSTom Haynes 
67311fb9989SMel Gorman 		inc_node_page_state(page, NR_UNSTABLE_NFS);
67493f78d88STejun Heo 		inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE);
675d15bc38dSTom Haynes 		__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
676d15bc38dSTom Haynes 	}
67786d80f97STrond Myklebust }
678d15bc38dSTom Haynes 
679d15bc38dSTom Haynes /*
68049a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
68149a70f27STrond Myklebust  */
68249a70f27STrond Myklebust static inline
68349a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
68449a70f27STrond Myklebust {
685d56b4ddfSMel Gorman 	loff_t i_size = i_size_read(page_file_mapping(page)->host);
68649a70f27STrond Myklebust 
68749a70f27STrond Myklebust 	if (i_size > 0) {
6888cd79788SHuang Ying 		pgoff_t index = page_index(page);
68909cbfeafSKirill A. Shutemov 		pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT;
6908cd79788SHuang Ying 		if (index < end_index)
69109cbfeafSKirill A. Shutemov 			return PAGE_SIZE;
6928cd79788SHuang Ying 		if (index == end_index)
69309cbfeafSKirill A. Shutemov 			return ((i_size - 1) & ~PAGE_MASK) + 1;
69449a70f27STrond Myklebust 	}
69549a70f27STrond Myklebust 	return 0;
69649a70f27STrond Myklebust }
6978d5658c9STrond Myklebust 
6988d5658c9STrond Myklebust /*
6990b26a0bfSTrond Myklebust  * Convert a umode to a dirent->d_type
7000b26a0bfSTrond Myklebust  */
7010b26a0bfSTrond Myklebust static inline
7020b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode)
7030b26a0bfSTrond Myklebust {
7040b26a0bfSTrond Myklebust 	return (mode >> 12) & 15;
7050b26a0bfSTrond Myklebust }
7060b26a0bfSTrond Myklebust 
7070b26a0bfSTrond Myklebust /*
7088d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
7098d5658c9STrond Myklebust  * with a base offset of 'base'
7108d5658c9STrond Myklebust  */
7118d5658c9STrond Myklebust static inline
7128d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len)
7138d5658c9STrond Myklebust {
7148d5658c9STrond Myklebust 	return ((unsigned long)len + (unsigned long)base +
7158d5658c9STrond Myklebust 		PAGE_SIZE - 1) >> PAGE_SHIFT;
7168d5658c9STrond Myklebust }
7170110ee15STrond Myklebust 
7183a1556e8STrond Myklebust /*
7193a1556e8STrond Myklebust  * Convert a struct timespec into a 64-bit change attribute
7203a1556e8STrond Myklebust  *
7213a1556e8STrond Myklebust  * This does approximately the same thing as timespec_to_ns(),
7223a1556e8STrond Myklebust  * but for calculation efficiency, we multiply the seconds by
7233a1556e8STrond Myklebust  * 1024*1024*1024.
7243a1556e8STrond Myklebust  */
7253a1556e8STrond Myklebust static inline
726e86d5a02STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec64 *ts)
7273a1556e8STrond Myklebust {
7283a1556e8STrond Myklebust 	return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
7293a1556e8STrond Myklebust }
7301264a2f0STrond Myklebust 
7311264a2f0STrond Myklebust #ifdef CONFIG_CRC32
7321264a2f0STrond Myklebust /**
7331264a2f0STrond Myklebust  * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
7341264a2f0STrond Myklebust  * @fh - pointer to filehandle
7351264a2f0STrond Myklebust  *
7361264a2f0STrond Myklebust  * returns a crc32 hash for the filehandle that is compatible with
7371264a2f0STrond Myklebust  * the one displayed by "wireshark".
7381264a2f0STrond Myklebust  */
7391264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
7401264a2f0STrond Myklebust {
7411264a2f0STrond Myklebust 	return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
7421264a2f0STrond Myklebust }
74348c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid)
74448c9579aSOlga Kornievskaia {
74548c9579aSOlga Kornievskaia 	return ~crc32_le(0xFFFFFFFF, &stateid->other[0],
74648c9579aSOlga Kornievskaia 				NFS4_STATEID_OTHER_SIZE);
74748c9579aSOlga Kornievskaia }
7481264a2f0STrond Myklebust #else
7491264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
7501264a2f0STrond Myklebust {
7511264a2f0STrond Myklebust 	return 0;
7521264a2f0STrond Myklebust }
75348c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
75448c9579aSOlga Kornievskaia {
75548c9579aSOlga Kornievskaia 	return 0;
75648c9579aSOlga Kornievskaia }
7571264a2f0STrond Myklebust #endif
7580bcbf039SPeng Tao 
7590bcbf039SPeng Tao static inline bool nfs_error_is_fatal(int err)
7600bcbf039SPeng Tao {
7610bcbf039SPeng Tao 	switch (err) {
7620bcbf039SPeng Tao 	case -ERESTARTSYS:
7637dc58ca5STrond Myklebust 	case -EINTR:
76454551d85STrond Myklebust 	case -EACCES:
76554551d85STrond Myklebust 	case -EDQUOT:
76654551d85STrond Myklebust 	case -EFBIG:
7670bcbf039SPeng Tao 	case -EIO:
7680bcbf039SPeng Tao 	case -ENOSPC:
7690bcbf039SPeng Tao 	case -EROFS:
77054551d85STrond Myklebust 	case -ESTALE:
7710bcbf039SPeng Tao 	case -E2BIG:
7722dc23affSTrond Myklebust 	case -ENOMEM:
77311982a7cSTrond Myklebust 	case -ETIMEDOUT:
7740bcbf039SPeng Tao 		return true;
7750bcbf039SPeng Tao 	default:
7760bcbf039SPeng Tao 		return false;
7770bcbf039SPeng Tao 	}
7780bcbf039SPeng Tao }
779bf4b4905SNeilBrown 
7808f54c7a4STrond Myklebust static inline bool nfs_error_is_fatal_on_server(int err)
7818f54c7a4STrond Myklebust {
7828f54c7a4STrond Myklebust 	switch (err) {
7838f54c7a4STrond Myklebust 	case 0:
7848f54c7a4STrond Myklebust 	case -ERESTARTSYS:
7858f54c7a4STrond Myklebust 	case -EINTR:
7868f54c7a4STrond Myklebust 		return false;
7878f54c7a4STrond Myklebust 	}
7888f54c7a4STrond Myklebust 	return nfs_error_is_fatal(err);
7898f54c7a4STrond Myklebust }
7909954bf92SDavid Howells 
7919954bf92SDavid Howells /*
7929954bf92SDavid Howells  * Select between a default port value and a user-specified port value.
7939954bf92SDavid Howells  * If a zero value is set, then autobind will be used.
7949954bf92SDavid Howells  */
7959954bf92SDavid Howells static inline void nfs_set_port(struct sockaddr *sap, int *port,
7969954bf92SDavid Howells 				const unsigned short default_port)
7979954bf92SDavid Howells {
7989954bf92SDavid Howells 	if (*port == NFS_UNSPEC_PORT)
7999954bf92SDavid Howells 		*port = default_port;
8009954bf92SDavid Howells 
8019954bf92SDavid Howells 	rpc_set_port(sap, *port);
8029954bf92SDavid Howells }
803