xref: /openbmc/linux/fs/nfs/internal.h (revision 61540bf6)
1f7b422b1SDavid Howells /*
2f7b422b1SDavid Howells  * NFS internal definitions
3f7b422b1SDavid Howells  */
4f7b422b1SDavid Howells 
5eedc020eSAndy Adamson #include "nfs4_fs.h"
6f7b422b1SDavid Howells #include <linux/mount.h>
7f9c3a380SEric Paris #include <linux/security.h>
81264a2f0STrond Myklebust #include <linux/crc32.h>
947af81f2SPeng Tao #include <linux/nfs_page.h>
10f7b422b1SDavid Howells 
1108734048SDavid Howells #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1208734048SDavid Howells 
1354ceac45SDavid Howells struct nfs_string;
1454ceac45SDavid Howells 
1554ceac45SDavid Howells /* Maximum number of readahead requests
1654ceac45SDavid Howells  * FIXME: this should really be a sysctl so that users may tune it to suit
1754ceac45SDavid Howells  *        their needs. People that do NFS over a slow network, might for
1854ceac45SDavid Howells  *        instance want to reduce it to something closer to 1 for improved
1954ceac45SDavid Howells  *        interactive response.
2054ceac45SDavid Howells  */
2154ceac45SDavid Howells #define NFS_MAX_READAHEAD	(RPC_DEF_SLOT_TABLE - 1)
2254ceac45SDavid Howells 
237ebb9315SBryan Schumaker static inline void nfs_attr_check_mountpoint(struct super_block *parent, struct nfs_fattr *fattr)
247ebb9315SBryan Schumaker {
257ebb9315SBryan Schumaker 	if (!nfs_fsid_equal(&NFS_SB(parent)->fsid, &fattr->fsid))
267ebb9315SBryan Schumaker 		fattr->valid |= NFS_ATTR_FATTR_MOUNTPOINT;
277ebb9315SBryan Schumaker }
287ebb9315SBryan Schumaker 
29533eb461SAndy Adamson static inline int nfs_attr_use_mounted_on_fileid(struct nfs_fattr *fattr)
30533eb461SAndy Adamson {
31533eb461SAndy Adamson 	if (((fattr->valid & NFS_ATTR_FATTR_MOUNTED_ON_FILEID) == 0) ||
32533eb461SAndy Adamson 	    (((fattr->valid & NFS_ATTR_FATTR_MOUNTPOINT) == 0) &&
33533eb461SAndy Adamson 	     ((fattr->valid & NFS_ATTR_FATTR_V4_REFERRAL) == 0)))
34533eb461SAndy Adamson 		return 0;
35533eb461SAndy Adamson 	return 1;
36533eb461SAndy Adamson }
37533eb461SAndy Adamson 
38f7b422b1SDavid Howells struct nfs_clone_mount {
39f7b422b1SDavid Howells 	const struct super_block *sb;
40f7b422b1SDavid Howells 	const struct dentry *dentry;
41f7b422b1SDavid Howells 	struct nfs_fh *fh;
42f7b422b1SDavid Howells 	struct nfs_fattr *fattr;
43f7b422b1SDavid Howells 	char *hostname;
44f7b422b1SDavid Howells 	char *mnt_path;
456677d095SChuck Lever 	struct sockaddr *addr;
466677d095SChuck Lever 	size_t addrlen;
47f7b422b1SDavid Howells 	rpc_authflavor_t authflavor;
48f7b422b1SDavid Howells };
49f7b422b1SDavid Howells 
506b18eaa0S\"Talpey, Thomas\ /*
51a14017dbSChuck Lever  * Note: RFC 1813 doesn't limit the number of auth flavors that
52a14017dbSChuck Lever  * a server can return, so make something up.
53a14017dbSChuck Lever  */
54a14017dbSChuck Lever #define NFS_MAX_SECFLAVORS	(12)
55a14017dbSChuck Lever 
56a14017dbSChuck Lever /*
574cfd74fcSChuck Lever  * Value used if the user did not specify a port value.
584cfd74fcSChuck Lever  */
594cfd74fcSChuck Lever #define NFS_UNSPEC_PORT		(-1)
604cfd74fcSChuck Lever 
61a956bedaSTrond Myklebust #define NFS_UNSPEC_RETRANS	(UINT_MAX)
62a956bedaSTrond Myklebust #define NFS_UNSPEC_TIMEO	(UINT_MAX)
63a956bedaSTrond Myklebust 
644cfd74fcSChuck Lever /*
6556e4ebf8SBryan Schumaker  * Maximum number of pages that readdir can use for creating
6656e4ebf8SBryan Schumaker  * a vmapped array of pages.
6756e4ebf8SBryan Schumaker  */
6856e4ebf8SBryan Schumaker #define NFS_MAX_READDIR_PAGES 8
6956e4ebf8SBryan Schumaker 
70fcf10398SBryan Schumaker struct nfs_client_initdata {
71fcf10398SBryan Schumaker 	unsigned long init_flags;
725c6e5b60STrond Myklebust 	const char *hostname;			/* Hostname of the server */
735c6e5b60STrond Myklebust 	const struct sockaddr *addr;		/* Address of the server */
745c6e5b60STrond Myklebust 	const char *nodename;			/* Hostname of the client */
755c6e5b60STrond Myklebust 	const char *ip_addr;			/* IP address of the client */
76fcf10398SBryan Schumaker 	size_t addrlen;
77ab7017a3SBryan Schumaker 	struct nfs_subversion *nfs_mod;
78fcf10398SBryan Schumaker 	int proto;
79fcf10398SBryan Schumaker 	u32 minorversion;
80fcf10398SBryan Schumaker 	struct net *net;
815c6e5b60STrond Myklebust 	const struct rpc_timeout *timeparms;
82fcf10398SBryan Schumaker };
83fcf10398SBryan Schumaker 
8456e4ebf8SBryan Schumaker /*
856b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
866b18eaa0S\"Talpey, Thomas\  */
876b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data {
886b18eaa0S\"Talpey, Thomas\ 	int			flags;
898cb7f74eSChuck Lever 	unsigned int		rsize, wsize;
908cb7f74eSChuck Lever 	unsigned int		timeo, retrans;
918cb7f74eSChuck Lever 	unsigned int		acregmin, acregmax,
926b18eaa0S\"Talpey, Thomas\ 				acdirmin, acdirmax;
938cb7f74eSChuck Lever 	unsigned int		namlen;
94b797cac7SDavid Howells 	unsigned int		options;
956b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
96a3f73c27SWeston Andros Adamson 	struct nfs_auth_info	auth_info;
97a3f73c27SWeston Andros Adamson 	rpc_authflavor_t	selected_flavor;
986b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
99764302ccSChuck Lever 	unsigned int		version;
1003fd5be9eSMike Sager 	unsigned int		minorversion;
10108734048SDavid Howells 	char			*fscache_uniq;
102b72e4f42SBryan Schumaker 	bool			need_mount;
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;
1206b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
121f9c3a380SEric Paris 
122f9c3a380SEric Paris 	struct security_mnt_opts lsm_opts;
123e50a7a1aSStanislav Kinsbursky 	struct net		*net;
1246b18eaa0S\"Talpey, Thomas\ };
1256b18eaa0S\"Talpey, Thomas\ 
126146ec944SChuck Lever /* mount_clnt.c */
127c5d120f8SChuck Lever struct nfs_mount_request {
128c5d120f8SChuck Lever 	struct sockaddr		*sap;
129c5d120f8SChuck Lever 	size_t			salen;
130c5d120f8SChuck Lever 	char			*hostname;
131c5d120f8SChuck Lever 	char			*dirpath;
132c5d120f8SChuck Lever 	u32			version;
133c5d120f8SChuck Lever 	unsigned short		protocol;
134c5d120f8SChuck Lever 	struct nfs_fh		*fh;
13550a737f8SChuck Lever 	int			noresvport;
1368e02f6b9SChuck Lever 	unsigned int		*auth_flav_len;
1378e02f6b9SChuck Lever 	rpc_authflavor_t	*auth_flavs;
1386d59b8d5SStanislav Kinsbursky 	struct net		*net;
139c5d120f8SChuck Lever };
140c5d120f8SChuck Lever 
141fbdefd64SBryan Schumaker struct nfs_mount_info {
142fbdefd64SBryan Schumaker 	void (*fill_super)(struct super_block *, struct nfs_mount_info *);
143fbdefd64SBryan Schumaker 	int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *);
144fbdefd64SBryan Schumaker 	struct nfs_parsed_mount_data *parsed;
145fbdefd64SBryan Schumaker 	struct nfs_clone_mount *cloned;
146fbdefd64SBryan Schumaker 	struct nfs_fh *mntfh;
147fbdefd64SBryan Schumaker };
148fbdefd64SBryan Schumaker 
149c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info);
1500b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info);
151146ec944SChuck Lever 
15224c8dbbbSDavid Howells /* client.c */
153a613fa16STrond Myklebust extern const struct rpc_program nfs_program;
1546b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net);
1556663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
1565c6e5b60STrond Myklebust int nfs_create_rpc_client(struct nfs_client *, const struct nfs_client_initdata *, rpc_authflavor_t);
1577d38de3fSAnna Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *);
158fcf10398SBryan Schumaker int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
159fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *);
16032e62b7cSChuck Lever void nfs_server_remove_lists(struct nfs_server *);
161a956bedaSTrond Myklebust void nfs_init_timeout_values(struct rpc_timeout *to, int proto, int timeo, int retrans);
162fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
163fcf10398SBryan Schumaker 		rpc_authflavor_t);
164fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void);
165fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
16654ceac45SDavid Howells 
16728cd1b3fSStanislav Kinsbursky extern void nfs_cleanup_cb_ident_idr(struct net *);
16824c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
169cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *);
17028cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
171c36fca52SAndy Adamson extern struct nfs_client *
172c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
173459de2edSBryan Schumaker 				struct nfs4_sessionid *, u32);
1741179acc6SBryan Schumaker extern struct nfs_server *nfs_create_server(struct nfs_mount_info *,
175ab7017a3SBryan Schumaker 					struct nfs_subversion *);
17691ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server(
1771179acc6SBryan Schumaker 					struct nfs_mount_info *,
1781179acc6SBryan Schumaker 					struct nfs_subversion *);
17954ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
18054ceac45SDavid Howells 						      struct nfs_fh *);
18132e62b7cSChuck Lever extern int nfs4_update_server(struct nfs_server *server, const char *hostname,
182292f503cSTrond Myklebust 					struct sockaddr *sap, size_t salen,
183292f503cSTrond Myklebust 					struct net *net);
18454ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
18554ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
18654ceac45SDavid Howells 					   struct nfs_fh *,
1877e6eb683SBryan Schumaker 					   struct nfs_fattr *,
1887e6eb683SBryan Schumaker 					   rpc_authflavor_t);
1894697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
19076db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
1913fc75f12STigran Mkrtchyan extern struct nfs_client *nfs4_set_ds_client(struct nfs_server *mds_srv,
192d83217c1SAndy Adamson 					     const struct sockaddr *ds_addr,
19398fc685aSAndy Adamson 					     int ds_addrlen, int ds_proto,
19498fc685aSAndy Adamson 					     unsigned int ds_timeo,
195064172f3SPeng Tao 					     unsigned int ds_retrans,
1967d38de3fSAnna Schumaker 					     u32 minor_version);
1970e20162eSAndy Adamson extern struct rpc_clnt *nfs4_find_or_create_ds_client(struct nfs_client *,
1980e20162eSAndy Adamson 						struct inode *);
199b224f7cbSTigran Mkrtchyan extern struct nfs_client *nfs3_set_ds_client(struct nfs_server *mds_srv,
2001a04c6e1SPeng Tao 			const struct sockaddr *ds_addr, int ds_addrlen,
2011a04c6e1SPeng Tao 			int ds_proto, unsigned int ds_timeo,
2027d38de3fSAnna Schumaker 			unsigned int ds_retrans);
2036aaca566SDavid Howells #ifdef CONFIG_PROC_FS
2046aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
2056aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
20665b38851SEric W. Biederman extern int nfs_fs_proc_net_init(struct net *net);
20765b38851SEric W. Biederman extern void nfs_fs_proc_net_exit(struct net *net);
2086aaca566SDavid Howells #else
20965b38851SEric W. Biederman static inline int nfs_fs_proc_net_init(struct net *net)
21065b38851SEric W. Biederman {
21165b38851SEric W. Biederman 	return 0;
21265b38851SEric W. Biederman }
21365b38851SEric W. Biederman static inline void nfs_fs_proc_net_exit(struct net *net)
21465b38851SEric W. Biederman {
21565b38851SEric W. Biederman }
2166aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
2176aaca566SDavid Howells {
2186aaca566SDavid Howells 	return 0;
2196aaca566SDavid Howells }
2206aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
2216aaca566SDavid Howells {
2226aaca566SDavid Howells }
2236aaca566SDavid Howells #endif
22424c8dbbbSDavid Howells 
225f7b422b1SDavid Howells /* callback_xdr.c */
226f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1;
22707bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4;
228f7b422b1SDavid Howells 
2294db6e0b7SFred Isaman struct nfs_pageio_descriptor;
230f7b422b1SDavid Howells /* pagelist.c */
231f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
232266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
233f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
234266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
235f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
236266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
237f7b422b1SDavid Howells 
238f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
239266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
2404db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
2414db6e0b7SFred Isaman 			      struct nfs_pgio_header *hdr,
2424db6e0b7SFred Isaman 			      void (*release)(struct nfs_pgio_header *hdr));
2434db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
244210c7c17SBenjamin Coddington int nfs_iocounter_wait(struct nfs_lock_context *l_ctx);
245577b4232STrond Myklebust 
24641d8d5b7SAnna Schumaker extern const struct nfs_pageio_ops nfs_pgio_rw_ops;
2471e7f3a48SWeston Andros Adamson struct nfs_pgio_header *nfs_pgio_header_alloc(const struct nfs_rw_ops *);
2481e7f3a48SWeston Andros Adamson void nfs_pgio_header_free(struct nfs_pgio_header *);
249d45f60c6SWeston Andros Adamson void nfs_pgio_data_destroy(struct nfs_pgio_header *);
250ef2c488cSAnna Schumaker int nfs_generic_pgio(struct nfs_pageio_descriptor *, struct nfs_pgio_header *);
25146a5ab47SPeng Tao int nfs_initiate_pgio(struct rpc_clnt *clnt, struct nfs_pgio_header *hdr,
25246a5ab47SPeng Tao 		      struct rpc_cred *cred, const struct nfs_rpc_ops *rpc_ops,
25346a5ab47SPeng Tao 		      const struct rpc_call_ops *call_ops, int how, int flags);
254d4581383SWeston Andros Adamson void nfs_free_request(struct nfs_page *req);
25548d635f1SPeng Tao struct nfs_pgio_mirror *
25648d635f1SPeng Tao nfs_pgio_current_mirror(struct nfs_pageio_descriptor *desc);
25700bfa30aSAnna Schumaker 
25847af81f2SPeng Tao static inline bool nfs_pgio_has_mirroring(struct nfs_pageio_descriptor *desc)
25947af81f2SPeng Tao {
26047af81f2SPeng Tao 	WARN_ON_ONCE(desc->pg_mirror_count < 1);
26147af81f2SPeng Tao 	return desc->pg_mirror_count > 1;
26247af81f2SPeng Tao }
26347af81f2SPeng Tao 
264138a2935STrond Myklebust static inline bool nfs_match_open_context(const struct nfs_open_context *ctx1,
265138a2935STrond Myklebust 		const struct nfs_open_context *ctx2)
266138a2935STrond Myklebust {
267138a2935STrond Myklebust 	return ctx1->cred == ctx2->cred && ctx1->state == ctx2->state;
268138a2935STrond Myklebust }
269138a2935STrond Myklebust 
270f7b422b1SDavid Howells /* nfs2xdr.c */
271f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[];
272573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *,
273573c4e1eSChuck Lever 				struct nfs_entry *, int);
274f7b422b1SDavid Howells 
275f7b422b1SDavid Howells /* nfs3xdr.c */
276f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[];
277573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *,
278573c4e1eSChuck Lever 				struct nfs_entry *, int);
279f7b422b1SDavid Howells 
280f7b422b1SDavid Howells /* nfs4xdr.c */
28189d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
282573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *,
283573c4e1eSChuck Lever 				struct nfs_entry *, int);
2847d4e2747SDavid Howells #endif
2852449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
2862449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead;
2872449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead;
288f1c097beSAndy Adamson extern const u32 nfs41_maxgetdevinfo_overhead;
2892449ea2eSAlexandros Batsakis #endif
290f7b422b1SDavid Howells 
291f7b422b1SDavid Howells /* nfs4proc.c */
29289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
293f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[];
294d75d5414SAndrew Morton #endif
295f7b422b1SDavid Howells 
296694e096fSAnna Schumaker #ifdef CONFIG_NFS_V4_SECURITY_LABEL
297694e096fSAnna Schumaker extern struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags);
298a49c2691SKinglong Mee static inline struct nfs4_label *
299a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
300a49c2691SKinglong Mee {
301a49c2691SKinglong Mee 	if (!dst || !src)
302a49c2691SKinglong Mee 		return NULL;
303a49c2691SKinglong Mee 
304a49c2691SKinglong Mee 	if (src->len > NFS4_MAXLABELLEN)
305a49c2691SKinglong Mee 		return NULL;
306a49c2691SKinglong Mee 
307a49c2691SKinglong Mee 	dst->lfs = src->lfs;
308a49c2691SKinglong Mee 	dst->pi = src->pi;
309a49c2691SKinglong Mee 	dst->len = src->len;
310a49c2691SKinglong Mee 	memcpy(dst->label, src->label, src->len);
311a49c2691SKinglong Mee 
312a49c2691SKinglong Mee 	return dst;
313a49c2691SKinglong Mee }
314694e096fSAnna Schumaker static inline void nfs4_label_free(struct nfs4_label *label)
315694e096fSAnna Schumaker {
316694e096fSAnna Schumaker 	if (label) {
317694e096fSAnna Schumaker 		kfree(label->label);
318694e096fSAnna Schumaker 		kfree(label);
319694e096fSAnna Schumaker 	}
320694e096fSAnna Schumaker 	return;
321694e096fSAnna Schumaker }
322fd1defc2STrond Myklebust 
323fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
324fd1defc2STrond Myklebust {
325fd1defc2STrond Myklebust 	if (nfs_server_capable(&nfsi->vfs_inode, NFS_CAP_SECURITY_LABEL))
326fd1defc2STrond Myklebust 		nfsi->cache_validity |= NFS_INO_INVALID_LABEL;
327fd1defc2STrond Myklebust }
328694e096fSAnna Schumaker #else
329694e096fSAnna Schumaker static inline struct nfs4_label *nfs4_label_alloc(struct nfs_server *server, gfp_t flags) { return NULL; }
330694e096fSAnna Schumaker static inline void nfs4_label_free(void *label) {}
331fd1defc2STrond Myklebust static inline void nfs_zap_label_cache_locked(struct nfs_inode *nfsi)
332fd1defc2STrond Myklebust {
333fd1defc2STrond Myklebust }
334a49c2691SKinglong Mee static inline struct nfs4_label *
335a49c2691SKinglong Mee nfs4_label_copy(struct nfs4_label *dst, struct nfs4_label *src)
336a49c2691SKinglong Mee {
337a49c2691SKinglong Mee 	return NULL;
338a49c2691SKinglong Mee }
339694e096fSAnna Schumaker #endif /* CONFIG_NFS_V4_SECURITY_LABEL */
340694e096fSAnna Schumaker 
3417fe5c398STrond Myklebust /* proc.c */
3427fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
3438cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
3445c6e5b60STrond Myklebust 			   const struct nfs_client_initdata *);
3457fe5c398STrond Myklebust 
346979df72eSTrond Myklebust /* dir.c */
3471bcf4c5cSTrond Myklebust extern void nfs_advise_use_readdirplus(struct inode *dir);
348311324adSTrond Myklebust extern void nfs_force_use_readdirplus(struct inode *dir);
3491ab6c499SDave Chinner extern unsigned long nfs_access_cache_count(struct shrinker *shrink,
3501ab6c499SDave Chinner 					    struct shrink_control *sc);
3511ab6c499SDave Chinner extern unsigned long nfs_access_cache_scan(struct shrinker *shrink,
3521495f230SYing Han 					   struct shrink_control *sc);
353597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
354597d9289SBryan Schumaker int nfs_create(struct inode *, struct dentry *, umode_t, bool);
355597d9289SBryan Schumaker int nfs_mkdir(struct inode *, struct dentry *, umode_t);
356597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *);
357597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *);
358597d9289SBryan Schumaker int nfs_symlink(struct inode *, struct dentry *, const char *);
359597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *);
360597d9289SBryan Schumaker int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
3611cd66c93SMiklos Szeredi int nfs_rename(struct inode *, struct dentry *,
3621cd66c93SMiklos Szeredi 	       struct inode *, struct dentry *, unsigned int);
363979df72eSTrond Myklebust 
364ce4ef7c0SBryan Schumaker /* file.c */
3654ff79bc7SChristoph Hellwig int nfs_file_fsync(struct file *file, loff_t start, loff_t end, int datasync);
366ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int);
3673aa2d199SAl Viro ssize_t nfs_file_read(struct kiocb *, struct iov_iter *);
368ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *);
369edaf4369SAl Viro ssize_t nfs_file_write(struct kiocb *, struct iov_iter *);
370ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *);
371ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *);
372ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *);
373ce4ef7c0SBryan Schumaker int nfs_check_flags(int);
374ce4ef7c0SBryan Schumaker 
375f7b422b1SDavid Howells /* inode.c */
3765746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
377f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
378f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *);
379a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *);
380eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *);
38119d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *);
382b57922d9SAl Viro extern void nfs_evict_inode(struct inode *);
383f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode);
38461540bf6STrond Myklebust extern bool nfs_check_cache_invalid(struct inode *, unsigned long);
385dfd01f02SPeter Zijlstra extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode);
386210c7c17SBenjamin Coddington extern int nfs_wait_atomic_killable(atomic_t *p);
387f7b422b1SDavid Howells 
388f7b422b1SDavid Howells /* super.c */
3896a74490dSBryan Schumaker extern const struct super_operations nfs_sops;
390ab7017a3SBryan Schumaker extern struct file_system_type nfs_fs_type;
39154ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type;
39289d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
39354ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type;
39454ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type;
395f7b422b1SDavid Howells #endif
3964d4b69ddSWeston Andros Adamson bool nfs_auth_info_match(const struct nfs_auth_info *, rpc_authflavor_t);
397ff9099f2SBryan Schumaker struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *,
398ff9099f2SBryan Schumaker 			struct nfs_subversion *);
399fbdefd64SBryan Schumaker void nfs_initialise_sb(struct super_block *);
400fbdefd64SBryan Schumaker int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
401fbdefd64SBryan Schumaker int nfs_clone_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
402ab7017a3SBryan Schumaker struct dentry *nfs_fs_mount_common(struct nfs_server *, int, const char *,
403ab7017a3SBryan Schumaker 				   struct nfs_mount_info *, struct nfs_subversion *);
404fbdefd64SBryan Schumaker struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *);
405fbdefd64SBryan Schumaker struct dentry * nfs_xdev_mount_common(struct file_system_type *, int,
406fbdefd64SBryan Schumaker 		const char *, struct nfs_mount_info *);
407fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *);
408fbdefd64SBryan Schumaker void nfs_fill_super(struct super_block *, struct nfs_mount_info *);
4094ebd9ab3SDominik Hackl 
410f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
4114ebd9ab3SDominik Hackl 
412f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
413f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
414ea7c38feSTrond Myklebust extern bool nfs_sb_active(struct super_block *sb);
4151daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb);
416f7b422b1SDavid Howells 
417a5864c99STrond Myklebust /* io.c */
418a5864c99STrond Myklebust extern void nfs_start_io_read(struct inode *inode);
419a5864c99STrond Myklebust extern void nfs_end_io_read(struct inode *inode);
420a5864c99STrond Myklebust extern void nfs_start_io_write(struct inode *inode);
421a5864c99STrond Myklebust extern void nfs_end_io_write(struct inode *inode);
422a5864c99STrond Myklebust extern void nfs_start_io_direct(struct inode *inode);
423a5864c99STrond Myklebust extern void nfs_end_io_direct(struct inode *inode);
424a5864c99STrond Myklebust 
425651b0e70STrond Myklebust static inline bool nfs_file_io_is_buffered(struct nfs_inode *nfsi)
426651b0e70STrond Myklebust {
427651b0e70STrond Myklebust 	return test_bit(NFS_INO_ODIRECT, &nfsi->flags) == 0;
428651b0e70STrond Myklebust }
429651b0e70STrond Myklebust 
430f7b422b1SDavid Howells /* namespace.c */
43197a54868SBen Hutchings #define NFS_PATH_CANONICAL 1
432b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry,
43397a54868SBen Hutchings 		      char *buffer, ssize_t buflen, unsigned flags);
43436d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path);
435281cad46SBryan Schumaker struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
436281cad46SBryan Schumaker 			      struct nfs_fh *, struct nfs_fattr *);
437281cad46SBryan Schumaker struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
438281cad46SBryan Schumaker 				 struct nfs_fattr *, rpc_authflavor_t);
439f7b422b1SDavid Howells 
44054ceac45SDavid Howells /* getroot.c */
4410d5839adSAl Viro extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
4420d5839adSAl Viro 				   const char *);
44389d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
4440d5839adSAl Viro extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
4450d5839adSAl Viro 				    const char *);
44654ceac45SDavid Howells 
4475e6b1990STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh, bool);
4487d4e2747SDavid Howells #endif
449f7b422b1SDavid Howells 
450061ae2edSFred Isaman struct nfs_pgio_completion_ops;
451f11c88afSAndy Adamson /* read.c */
452584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
453fab5fc25SChristoph Hellwig 			struct inode *inode, bool force_mds,
454584aa810SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
455f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
456493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
457e885de1aSTrond Myklebust 
458fbdefd64SBryan Schumaker /* super.c */
459fbdefd64SBryan Schumaker void nfs_clone_super(struct super_block *, struct nfs_mount_info *);
460fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *);
461fbdefd64SBryan Schumaker int  nfs_statfs(struct dentry *, struct kstatfs *);
462fbdefd64SBryan Schumaker int  nfs_show_options(struct seq_file *, struct dentry *);
463fbdefd64SBryan Schumaker int  nfs_show_devname(struct seq_file *, struct dentry *);
464fbdefd64SBryan Schumaker int  nfs_show_path(struct seq_file *, struct dentry *);
465fbdefd64SBryan Schumaker int  nfs_show_stats(struct seq_file *, struct dentry *);
466fbdefd64SBryan Schumaker int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
467fbdefd64SBryan Schumaker 
468def6ed7eSAndy Adamson /* write.c */
4691763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
470a20c93e3SChristoph Hellwig 			struct inode *inode, int ioflags, bool force_mds,
4711763da12SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
472dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
4730b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p);
474def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
4750b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
4760b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt,
4770b7c0153SFred Isaman 			       struct nfs_commit_data *data,
478c36aae9aSPeng Tao 			       const struct nfs_rpc_ops *nfs_ops,
479e0c2b380SFred Isaman 			       const struct rpc_call_ops *call_ops,
4809f0ec176SAndy Adamson 			       int how, int flags);
4810b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data,
482e0c2b380SFred Isaman 			    struct list_head *head,
483f453a54aSFred Isaman 			    struct pnfs_layout_segment *lseg,
484f453a54aSFred Isaman 			    struct nfs_commit_info *cinfo);
4851763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
4861763da12SFred Isaman 			 struct nfs_commit_info *cinfo, int max);
487ce59515cSAnna Schumaker unsigned long nfs_reqs_to_commit(struct nfs_commit_info *);
4881763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst,
4891763da12SFred Isaman 		    struct nfs_commit_info *cinfo);
4901763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req,
4911763da12SFred Isaman 			     struct pnfs_layout_segment *lseg,
492b57ff130SWeston Andros Adamson 			     struct nfs_commit_info *cinfo,
493b57ff130SWeston Andros Adamson 			     u32 ds_commit_idx);
494c65e6254SWeston Andros Adamson int nfs_write_need_commit(struct nfs_pgio_header *);
495a08a8cd3STrond Myklebust void nfs_writeback_update_inode(struct nfs_pgio_header *hdr);
49667911c8fSAnna Schumaker int nfs_commit_file(struct file *file, struct nfs_write_verifier *verf);
4971763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
4981763da12SFred Isaman 			    int how, struct nfs_commit_info *cinfo);
499e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list,
500ea2cf228SFred Isaman 		      struct pnfs_layout_segment *lseg,
501b57ff130SWeston Andros Adamson 		      struct nfs_commit_info *cinfo,
502b57ff130SWeston Andros Adamson 		      u32 ds_commit_idx);
5030b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data);
5046272dcc6SAnna Schumaker void nfs_request_add_commit_list(struct nfs_page *req,
505ea2cf228SFred Isaman 				 struct nfs_commit_info *cinfo);
50686d80f97STrond Myklebust void nfs_request_add_commit_list_locked(struct nfs_page *req,
50786d80f97STrond Myklebust 		struct list_head *dst,
50886d80f97STrond Myklebust 		struct nfs_commit_info *cinfo);
509ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req,
510ea2cf228SFred Isaman 				    struct nfs_commit_info *cinfo);
511ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo,
512ea2cf228SFred Isaman 		    struct inode *inode,
513ea2cf228SFred Isaman 		    struct nfs_direct_req *dreq);
514dc24826bSAndy Adamson int nfs_key_timeout_notify(struct file *filp, struct inode *inode);
515ce52914eSScott Mayhew bool nfs_ctx_key_to_expire(struct nfs_open_context *ctx, struct inode *inode);
516a7d42ddbSWeston Andros Adamson void nfs_pageio_stop_mirroring(struct nfs_pageio_descriptor *pgio);
517e0c2b380SFred Isaman 
518837bb1d7STrond Myklebust int nfs_filemap_write_and_wait_range(struct address_space *mapping,
519837bb1d7STrond Myklebust 		loff_t lstart, loff_t lend);
520837bb1d7STrond Myklebust 
521a5314a74STrond Myklebust #ifdef CONFIG_NFS_V4_1
522a5314a74STrond Myklebust static inline
523a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
524a5314a74STrond Myklebust {
525a5314a74STrond Myklebust 	int i;
526a5314a74STrond Myklebust 
527a5314a74STrond Myklebust 	for (i = 0; i < cinfo->nbuckets; i++)
528a5314a74STrond Myklebust 		cinfo->buckets[i].direct_verf.committed = NFS_INVALID_STABLE_HOW;
529a5314a74STrond Myklebust }
530a5314a74STrond Myklebust #else
531a5314a74STrond Myklebust static inline
532a5314a74STrond Myklebust void nfs_clear_pnfs_ds_commit_verifiers(struct pnfs_ds_commit_info *cinfo)
533a5314a74STrond Myklebust {
534a5314a74STrond Myklebust }
535a5314a74STrond Myklebust #endif
536a5314a74STrond Myklebust 
537074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION
538074cc1deSTrond Myklebust extern int nfs_migrate_page(struct address_space *,
539a6bc32b8SMel Gorman 		struct page *, struct page *, enum migrate_mode);
540074cc1deSTrond Myklebust #endif
541def6ed7eSAndy Adamson 
5428fc3c386STrond Myklebust static inline int
5438fc3c386STrond Myklebust nfs_write_verifier_cmp(const struct nfs_write_verifier *v1,
5448fc3c386STrond Myklebust 		const struct nfs_write_verifier *v2)
5458fc3c386STrond Myklebust {
5468fc3c386STrond Myklebust 	return memcmp(v1->data, v2->data, sizeof(v1->data));
5478fc3c386STrond Myklebust }
5488fc3c386STrond Myklebust 
5490e862a40SJeff Layton /* unlink.c */
5500e862a40SJeff Layton extern struct rpc_task *
5510e862a40SJeff Layton nfs_async_rename(struct inode *old_dir, struct inode *new_dir,
5520e862a40SJeff Layton 		 struct dentry *old_dentry, struct dentry *new_dentry,
5530e862a40SJeff Layton 		 void (*complete)(struct rpc_task *, struct nfs_renamedata *));
5540e862a40SJeff Layton extern int nfs_sillyrename(struct inode *dir, struct dentry *dentry);
5550e862a40SJeff Layton 
5561763da12SFred Isaman /* direct.c */
5571763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
5581763da12SFred Isaman 			      struct nfs_direct_req *dreq);
5596296556fSPeng Tao extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
5601763da12SFred Isaman 
561cccef3b9SAndy Adamson /* nfs4proc.c */
5628cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
5635c6e5b60STrond Myklebust 			    const struct nfs_client_initdata *);
56405f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp,
56505f4c350SChuck Lever 				struct nfs_client **result,
56605f4c350SChuck Lever 				struct rpc_cred *cred);
56705f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp,
56805f4c350SChuck Lever 				struct nfs_client **result,
56905f4c350SChuck Lever 				struct rpc_cred *cred);
57004fa2c6bSAndy Adamson extern int nfs4_test_session_trunk(struct rpc_clnt *,
57104fa2c6bSAndy Adamson 				struct rpc_xprt *,
57204fa2c6bSAndy Adamson 				void *);
573cccef3b9SAndy Adamson 
574ea7c38feSTrond Myklebust static inline struct inode *nfs_igrab_and_active(struct inode *inode)
575ea7c38feSTrond Myklebust {
576ea7c38feSTrond Myklebust 	inode = igrab(inode);
577ea7c38feSTrond Myklebust 	if (inode != NULL && !nfs_sb_active(inode->i_sb)) {
578ea7c38feSTrond Myklebust 		iput(inode);
579ea7c38feSTrond Myklebust 		inode = NULL;
580ea7c38feSTrond Myklebust 	}
581ea7c38feSTrond Myklebust 	return inode;
582ea7c38feSTrond Myklebust }
583ea7c38feSTrond Myklebust 
584ea7c38feSTrond Myklebust static inline void nfs_iput_and_deactive(struct inode *inode)
585ea7c38feSTrond Myklebust {
586ea7c38feSTrond Myklebust 	if (inode != NULL) {
587ea7c38feSTrond Myklebust 		struct super_block *sb = inode->i_sb;
588ea7c38feSTrond Myklebust 
589ea7c38feSTrond Myklebust 		iput(inode);
590ea7c38feSTrond Myklebust 		nfs_sb_deactive(sb);
591ea7c38feSTrond Myklebust 	}
592ea7c38feSTrond Myklebust }
593ea7c38feSTrond Myklebust 
594557134a3SAndy Adamson /*
595f7b422b1SDavid Howells  * Determine the device name as a string
596f7b422b1SDavid Howells  */
597b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry,
598f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
599f7b422b1SDavid Howells {
600b514f872SAl Viro 	char *dummy;
60197a54868SBen Hutchings 	return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
602f7b422b1SDavid Howells }
603f7b422b1SDavid Howells 
604f7b422b1SDavid Howells /*
605f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
606f7b422b1SDavid Howells  */
607f7b422b1SDavid Howells static inline
608f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
609f7b422b1SDavid Howells {
610f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
611f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
612f7b422b1SDavid Howells 		unsigned char	nrbits;
613f7b422b1SDavid Howells 
614f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
615f7b422b1SDavid Howells 			;
616f7b422b1SDavid Howells 		bsize = 1 << nrbits;
617f7b422b1SDavid Howells 		if (nrbitsp)
618f7b422b1SDavid Howells 			*nrbitsp = nrbits;
619f7b422b1SDavid Howells 	}
620f7b422b1SDavid Howells 
621f7b422b1SDavid Howells 	return bsize;
622f7b422b1SDavid Howells }
623f7b422b1SDavid Howells 
624f7b422b1SDavid Howells /*
625f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
626f7b422b1SDavid Howells  */
6279eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
628f7b422b1SDavid Howells {
6299eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
630f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
631f7b422b1SDavid Howells }
632f7b422b1SDavid Howells 
633f7b422b1SDavid Howells /*
634f7b422b1SDavid Howells  * Compute and set NFS server blocksize
635f7b422b1SDavid Howells  */
636f7b422b1SDavid Howells static inline
637f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
638f7b422b1SDavid Howells {
639f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
640f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
641f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
642f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
643f7b422b1SDavid Howells 
644f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
645f7b422b1SDavid Howells }
646f7b422b1SDavid Howells 
647f7b422b1SDavid Howells /*
648f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
649f7b422b1SDavid Howells  */
650f7b422b1SDavid Howells static inline
651f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
652f7b422b1SDavid Howells {
653f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
654f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
655f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
656f7b422b1SDavid Howells }
65749a70f27STrond Myklebust 
65849a70f27STrond Myklebust /*
659d15bc38dSTom Haynes  * Record the page as unstable and mark its inode as dirty.
660d15bc38dSTom Haynes  */
661d15bc38dSTom Haynes static inline
66286d80f97STrond Myklebust void nfs_mark_page_unstable(struct page *page, struct nfs_commit_info *cinfo)
663d15bc38dSTom Haynes {
66486d80f97STrond Myklebust 	if (!cinfo->dreq) {
665d15bc38dSTom Haynes 		struct inode *inode = page_file_mapping(page)->host;
666d15bc38dSTom Haynes 
66711fb9989SMel Gorman 		inc_node_page_state(page, NR_UNSTABLE_NFS);
66893f78d88STejun Heo 		inc_wb_stat(&inode_to_bdi(inode)->wb, WB_RECLAIMABLE);
669d15bc38dSTom Haynes 		__mark_inode_dirty(inode, I_DIRTY_DATASYNC);
670d15bc38dSTom Haynes 	}
67186d80f97STrond Myklebust }
672d15bc38dSTom Haynes 
673d15bc38dSTom Haynes /*
67449a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
67549a70f27STrond Myklebust  */
67649a70f27STrond Myklebust static inline
67749a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
67849a70f27STrond Myklebust {
679d56b4ddfSMel Gorman 	loff_t i_size = i_size_read(page_file_mapping(page)->host);
68049a70f27STrond Myklebust 
68149a70f27STrond Myklebust 	if (i_size > 0) {
6828cd79788SHuang Ying 		pgoff_t index = page_index(page);
68309cbfeafSKirill A. Shutemov 		pgoff_t end_index = (i_size - 1) >> PAGE_SHIFT;
6848cd79788SHuang Ying 		if (index < end_index)
68509cbfeafSKirill A. Shutemov 			return PAGE_SIZE;
6868cd79788SHuang Ying 		if (index == end_index)
68709cbfeafSKirill A. Shutemov 			return ((i_size - 1) & ~PAGE_MASK) + 1;
68849a70f27STrond Myklebust 	}
68949a70f27STrond Myklebust 	return 0;
69049a70f27STrond Myklebust }
6918d5658c9STrond Myklebust 
6928d5658c9STrond Myklebust /*
6930b26a0bfSTrond Myklebust  * Convert a umode to a dirent->d_type
6940b26a0bfSTrond Myklebust  */
6950b26a0bfSTrond Myklebust static inline
6960b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode)
6970b26a0bfSTrond Myklebust {
6980b26a0bfSTrond Myklebust 	return (mode >> 12) & 15;
6990b26a0bfSTrond Myklebust }
7000b26a0bfSTrond Myklebust 
7010b26a0bfSTrond Myklebust /*
7028d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
7038d5658c9STrond Myklebust  * with a base offset of 'base'
7048d5658c9STrond Myklebust  */
7058d5658c9STrond Myklebust static inline
7068d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len)
7078d5658c9STrond Myklebust {
7088d5658c9STrond Myklebust 	return ((unsigned long)len + (unsigned long)base +
7098d5658c9STrond Myklebust 		PAGE_SIZE - 1) >> PAGE_SHIFT;
7108d5658c9STrond Myklebust }
7110110ee15STrond Myklebust 
7123a1556e8STrond Myklebust /*
7133a1556e8STrond Myklebust  * Convert a struct timespec into a 64-bit change attribute
7143a1556e8STrond Myklebust  *
7153a1556e8STrond Myklebust  * This does approximately the same thing as timespec_to_ns(),
7163a1556e8STrond Myklebust  * but for calculation efficiency, we multiply the seconds by
7173a1556e8STrond Myklebust  * 1024*1024*1024.
7183a1556e8STrond Myklebust  */
7193a1556e8STrond Myklebust static inline
7203a1556e8STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec *ts)
7213a1556e8STrond Myklebust {
7223a1556e8STrond Myklebust 	return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
7233a1556e8STrond Myklebust }
7241264a2f0STrond Myklebust 
7251264a2f0STrond Myklebust #ifdef CONFIG_CRC32
7261264a2f0STrond Myklebust /**
7271264a2f0STrond Myklebust  * nfs_fhandle_hash - calculate the crc32 hash for the filehandle
7281264a2f0STrond Myklebust  * @fh - pointer to filehandle
7291264a2f0STrond Myklebust  *
7301264a2f0STrond Myklebust  * returns a crc32 hash for the filehandle that is compatible with
7311264a2f0STrond Myklebust  * the one displayed by "wireshark".
7321264a2f0STrond Myklebust  */
7331264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
7341264a2f0STrond Myklebust {
7351264a2f0STrond Myklebust 	return ~crc32_le(0xFFFFFFFF, &fh->data[0], fh->size);
7361264a2f0STrond Myklebust }
73748c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(const nfs4_stateid *stateid)
73848c9579aSOlga Kornievskaia {
73948c9579aSOlga Kornievskaia 	return ~crc32_le(0xFFFFFFFF, &stateid->other[0],
74048c9579aSOlga Kornievskaia 				NFS4_STATEID_OTHER_SIZE);
74148c9579aSOlga Kornievskaia }
7421264a2f0STrond Myklebust #else
7431264a2f0STrond Myklebust static inline u32 nfs_fhandle_hash(const struct nfs_fh *fh)
7441264a2f0STrond Myklebust {
7451264a2f0STrond Myklebust 	return 0;
7461264a2f0STrond Myklebust }
74748c9579aSOlga Kornievskaia static inline u32 nfs_stateid_hash(nfs4_stateid *stateid)
74848c9579aSOlga Kornievskaia {
74948c9579aSOlga Kornievskaia 	return 0;
75048c9579aSOlga Kornievskaia }
7511264a2f0STrond Myklebust #endif
7520bcbf039SPeng Tao 
7530bcbf039SPeng Tao static inline bool nfs_error_is_fatal(int err)
7540bcbf039SPeng Tao {
7550bcbf039SPeng Tao 	switch (err) {
7560bcbf039SPeng Tao 	case -ERESTARTSYS:
7570bcbf039SPeng Tao 	case -EIO:
7580bcbf039SPeng Tao 	case -ENOSPC:
7590bcbf039SPeng Tao 	case -EROFS:
7600bcbf039SPeng Tao 	case -E2BIG:
7610bcbf039SPeng Tao 		return true;
7620bcbf039SPeng Tao 	default:
7630bcbf039SPeng Tao 		return false;
7640bcbf039SPeng Tao 	}
7650bcbf039SPeng Tao }
766