xref: /openbmc/linux/fs/nfs/internal.h (revision 459de2ed)
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>
8f7b422b1SDavid Howells 
908734048SDavid Howells #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
1008734048SDavid Howells 
1154ceac45SDavid Howells struct nfs_string;
1254ceac45SDavid Howells 
1354ceac45SDavid Howells /* Maximum number of readahead requests
1454ceac45SDavid Howells  * FIXME: this should really be a sysctl so that users may tune it to suit
1554ceac45SDavid Howells  *        their needs. People that do NFS over a slow network, might for
1654ceac45SDavid Howells  *        instance want to reduce it to something closer to 1 for improved
1754ceac45SDavid Howells  *        interactive response.
1854ceac45SDavid Howells  */
1954ceac45SDavid Howells #define NFS_MAX_READAHEAD	(RPC_DEF_SLOT_TABLE - 1)
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 
34533eb461SAndy Adamson 	fattr->fileid = fattr->mounted_on_fileid;
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 
614cfd74fcSChuck Lever /*
6256e4ebf8SBryan Schumaker  * Maximum number of pages that readdir can use for creating
6356e4ebf8SBryan Schumaker  * a vmapped array of pages.
6456e4ebf8SBryan Schumaker  */
6556e4ebf8SBryan Schumaker #define NFS_MAX_READDIR_PAGES 8
6656e4ebf8SBryan Schumaker 
67fcf10398SBryan Schumaker struct nfs_client_initdata {
68fcf10398SBryan Schumaker 	unsigned long init_flags;
69fcf10398SBryan Schumaker 	const char *hostname;
70fcf10398SBryan Schumaker 	const struct sockaddr *addr;
71fcf10398SBryan Schumaker 	size_t addrlen;
72ab7017a3SBryan Schumaker 	struct nfs_subversion *nfs_mod;
73fcf10398SBryan Schumaker 	int proto;
74fcf10398SBryan Schumaker 	u32 minorversion;
75fcf10398SBryan Schumaker 	struct net *net;
76fcf10398SBryan Schumaker };
77fcf10398SBryan Schumaker 
7856e4ebf8SBryan Schumaker /*
796b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
806b18eaa0S\"Talpey, Thomas\  */
816b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data {
826b18eaa0S\"Talpey, Thomas\ 	int			flags;
838cb7f74eSChuck Lever 	unsigned int		rsize, wsize;
848cb7f74eSChuck Lever 	unsigned int		timeo, retrans;
858cb7f74eSChuck Lever 	unsigned int		acregmin, acregmax,
866b18eaa0S\"Talpey, Thomas\ 				acdirmin, acdirmax;
878cb7f74eSChuck Lever 	unsigned int		namlen;
88b797cac7SDavid Howells 	unsigned int		options;
896b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
906b18eaa0S\"Talpey, Thomas\ 	unsigned int		auth_flavor_len;
916b18eaa0S\"Talpey, Thomas\ 	rpc_authflavor_t	auth_flavors[1];
926b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
93764302ccSChuck Lever 	unsigned int		version;
943fd5be9eSMike Sager 	unsigned int		minorversion;
9508734048SDavid Howells 	char			*fscache_uniq;
96b72e4f42SBryan Schumaker 	bool			need_mount;
976b18eaa0S\"Talpey, Thomas\ 
986b18eaa0S\"Talpey, Thomas\ 	struct {
994c568017SChuck Lever 		struct sockaddr_storage	address;
1004c568017SChuck Lever 		size_t			addrlen;
1016b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
10278fa701fSChuck Lever 		u32			version;
1034cfd74fcSChuck Lever 		int			port;
10478fa701fSChuck Lever 		unsigned short		protocol;
1056b18eaa0S\"Talpey, Thomas\ 	} mount_server;
1066b18eaa0S\"Talpey, Thomas\ 
1076b18eaa0S\"Talpey, Thomas\ 	struct {
1084c568017SChuck Lever 		struct sockaddr_storage	address;
1094c568017SChuck Lever 		size_t			addrlen;
1106b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
1116b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
1124cfd74fcSChuck Lever 		int			port;
11378fa701fSChuck Lever 		unsigned short		protocol;
1146b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
115f9c3a380SEric Paris 
116f9c3a380SEric Paris 	struct security_mnt_opts lsm_opts;
117e50a7a1aSStanislav Kinsbursky 	struct net		*net;
1186b18eaa0S\"Talpey, Thomas\ };
1196b18eaa0S\"Talpey, Thomas\ 
120146ec944SChuck Lever /* mount_clnt.c */
121c5d120f8SChuck Lever struct nfs_mount_request {
122c5d120f8SChuck Lever 	struct sockaddr		*sap;
123c5d120f8SChuck Lever 	size_t			salen;
124c5d120f8SChuck Lever 	char			*hostname;
125c5d120f8SChuck Lever 	char			*dirpath;
126c5d120f8SChuck Lever 	u32			version;
127c5d120f8SChuck Lever 	unsigned short		protocol;
128c5d120f8SChuck Lever 	struct nfs_fh		*fh;
12950a737f8SChuck Lever 	int			noresvport;
1308e02f6b9SChuck Lever 	unsigned int		*auth_flav_len;
1318e02f6b9SChuck Lever 	rpc_authflavor_t	*auth_flavs;
1326d59b8d5SStanislav Kinsbursky 	struct net		*net;
133c5d120f8SChuck Lever };
134c5d120f8SChuck Lever 
135fbdefd64SBryan Schumaker struct nfs_mount_info {
136fbdefd64SBryan Schumaker 	void (*fill_super)(struct super_block *, struct nfs_mount_info *);
137fbdefd64SBryan Schumaker 	int (*set_security)(struct super_block *, struct dentry *, struct nfs_mount_info *);
138fbdefd64SBryan Schumaker 	struct nfs_parsed_mount_data *parsed;
139fbdefd64SBryan Schumaker 	struct nfs_clone_mount *cloned;
140fbdefd64SBryan Schumaker 	struct nfs_fh *mntfh;
141fbdefd64SBryan Schumaker };
142fbdefd64SBryan Schumaker 
143c5d120f8SChuck Lever extern int nfs_mount(struct nfs_mount_request *info);
1440b524123SChuck Lever extern void nfs_umount(const struct nfs_mount_request *info);
145146ec944SChuck Lever 
14624c8dbbbSDavid Howells /* client.c */
147a613fa16STrond Myklebust extern const struct rpc_program nfs_program;
1486b13168bSStanislav Kinsbursky extern void nfs_clients_init(struct net *net);
1496663ee7fSBryan Schumaker extern struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *);
150428360d7SBryan Schumaker int nfs_create_rpc_client(struct nfs_client *, const struct rpc_timeout *, rpc_authflavor_t);
151fcf10398SBryan Schumaker struct nfs_client *nfs_get_client(const struct nfs_client_initdata *,
152fcf10398SBryan Schumaker 				  const struct rpc_timeout *, const char *,
153fcf10398SBryan Schumaker 				  rpc_authflavor_t);
154fcf10398SBryan Schumaker int nfs_probe_fsinfo(struct nfs_server *server, struct nfs_fh *, struct nfs_fattr *);
155fcf10398SBryan Schumaker void nfs_server_insert_lists(struct nfs_server *);
156fcf10398SBryan Schumaker void nfs_init_timeout_values(struct rpc_timeout *, int, unsigned int, unsigned int);
157fcf10398SBryan Schumaker int nfs_init_server_rpcclient(struct nfs_server *, const struct rpc_timeout *t,
158fcf10398SBryan Schumaker 		rpc_authflavor_t);
159fcf10398SBryan Schumaker struct nfs_server *nfs_alloc_server(void);
160fcf10398SBryan Schumaker void nfs_server_copy_userdata(struct nfs_server *, struct nfs_server *);
16154ceac45SDavid Howells 
16228cd1b3fSStanislav Kinsbursky extern void nfs_cleanup_cb_ident_idr(struct net *);
16324c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
164cdb7ecedSBryan Schumaker extern void nfs_free_client(struct nfs_client *);
16528cd1b3fSStanislav Kinsbursky extern struct nfs_client *nfs4_find_client_ident(struct net *, int);
166c36fca52SAndy Adamson extern struct nfs_client *
167c7add9a9SStanislav Kinsbursky nfs4_find_client_sessionid(struct net *, const struct sockaddr *,
168459de2edSBryan Schumaker 				struct nfs4_sessionid *, u32);
1691179acc6SBryan Schumaker extern struct nfs_server *nfs_create_server(struct nfs_mount_info *,
170ab7017a3SBryan Schumaker 					struct nfs_subversion *);
17191ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server(
1721179acc6SBryan Schumaker 					struct nfs_mount_info *,
1731179acc6SBryan Schumaker 					struct nfs_subversion *);
17454ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
17554ceac45SDavid Howells 						      struct nfs_fh *);
17654ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
17754ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
17854ceac45SDavid Howells 					   struct nfs_fh *,
1797e6eb683SBryan Schumaker 					   struct nfs_fattr *,
1807e6eb683SBryan Schumaker 					   rpc_authflavor_t);
1814697bd5eSTrond Myklebust extern int nfs_wait_client_init_complete(const struct nfs_client *clp);
18276db6d95SAndy Adamson extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
183d83217c1SAndy Adamson extern struct nfs_client *nfs4_set_ds_client(struct nfs_client* mds_clp,
184d83217c1SAndy Adamson 					     const struct sockaddr *ds_addr,
18598fc685aSAndy Adamson 					     int ds_addrlen, int ds_proto,
18698fc685aSAndy Adamson 					     unsigned int ds_timeo,
18798fc685aSAndy Adamson 					     unsigned int ds_retrans);
1886aaca566SDavid Howells #ifdef CONFIG_PROC_FS
1896aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
1906aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
1916aaca566SDavid Howells #else
1926aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
1936aaca566SDavid Howells {
1946aaca566SDavid Howells 	return 0;
1956aaca566SDavid Howells }
1966aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
1976aaca566SDavid Howells {
1986aaca566SDavid Howells }
1996aaca566SDavid Howells #endif
20024c8dbbbSDavid Howells 
201fcf10398SBryan Schumaker #ifdef CONFIG_NFS_V4_1
202fcf10398SBryan Schumaker int nfs_sockaddr_match_ipaddr(const struct sockaddr *, const struct sockaddr *);
203fcf10398SBryan Schumaker #endif
204fcf10398SBryan Schumaker 
2051179acc6SBryan Schumaker /* nfs3client.c */
2061c606fb7SBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V3)
2071179acc6SBryan Schumaker struct nfs_server *nfs3_create_server(struct nfs_mount_info *, struct nfs_subversion *);
2081179acc6SBryan Schumaker struct nfs_server *nfs3_clone_server(struct nfs_server *, struct nfs_fh *,
2091179acc6SBryan Schumaker 				     struct nfs_fattr *, rpc_authflavor_t);
2101179acc6SBryan Schumaker #endif
2111179acc6SBryan Schumaker 
212f7b422b1SDavid Howells /* callback_xdr.c */
213f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1;
21407bccc2dSAlexandros Batsakis extern struct svc_version nfs4_callback_version4;
215f7b422b1SDavid Howells 
2164db6e0b7SFred Isaman struct nfs_pageio_descriptor;
217f7b422b1SDavid Howells /* pagelist.c */
218f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
219266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
220f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
221266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
222f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
223266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
224f7b422b1SDavid Howells 
225f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
226266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
22730dd374fSFred Isaman extern bool nfs_pgarray_set(struct nfs_page_array *p, unsigned int pagecount);
2284db6e0b7SFred Isaman extern void nfs_pgheader_init(struct nfs_pageio_descriptor *desc,
2294db6e0b7SFred Isaman 			      struct nfs_pgio_header *hdr,
2304db6e0b7SFred Isaman 			      void (*release)(struct nfs_pgio_header *hdr));
2314db6e0b7SFred Isaman void nfs_set_pgio_error(struct nfs_pgio_header *hdr, int error, loff_t pos);
232577b4232STrond Myklebust int nfs_iocounter_wait(struct nfs_io_counter *c);
233577b4232STrond Myklebust 
234577b4232STrond Myklebust static inline void nfs_iocounter_init(struct nfs_io_counter *c)
235577b4232STrond Myklebust {
236577b4232STrond Myklebust 	c->flags = 0;
237577b4232STrond Myklebust 	atomic_set(&c->io_count, 0);
238577b4232STrond Myklebust }
239f7b422b1SDavid Howells 
240f7b422b1SDavid Howells /* nfs2xdr.c */
241f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[];
242573c4e1eSChuck Lever extern int nfs2_decode_dirent(struct xdr_stream *,
243573c4e1eSChuck Lever 				struct nfs_entry *, int);
244f7b422b1SDavid Howells 
245f7b422b1SDavid Howells /* nfs3xdr.c */
246f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[];
247573c4e1eSChuck Lever extern int nfs3_decode_dirent(struct xdr_stream *,
248573c4e1eSChuck Lever 				struct nfs_entry *, int);
249f7b422b1SDavid Howells 
250f7b422b1SDavid Howells /* nfs4xdr.c */
25189d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
252573c4e1eSChuck Lever extern int nfs4_decode_dirent(struct xdr_stream *,
253573c4e1eSChuck Lever 				struct nfs_entry *, int);
2547d4e2747SDavid Howells #endif
2552449ea2eSAlexandros Batsakis #ifdef CONFIG_NFS_V4_1
2562449ea2eSAlexandros Batsakis extern const u32 nfs41_maxread_overhead;
2572449ea2eSAlexandros Batsakis extern const u32 nfs41_maxwrite_overhead;
2582449ea2eSAlexandros Batsakis #endif
259f7b422b1SDavid Howells 
260f7b422b1SDavid Howells /* nfs4proc.c */
26189d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
262f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[];
263d75d5414SAndrew Morton #endif
264f7b422b1SDavid Howells 
2657fe5c398STrond Myklebust /* proc.c */
2667fe5c398STrond Myklebust void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
2678cab4c39SChuck Lever extern struct nfs_client *nfs_init_client(struct nfs_client *clp,
26845a52a02SAndy Adamson 			   const struct rpc_timeout *timeparms,
2694bf590e0SChuck Lever 			   const char *ip_addr, rpc_authflavor_t authflavour);
2707fe5c398STrond Myklebust 
271979df72eSTrond Myklebust /* dir.c */
2727f8275d0SDave Chinner extern int nfs_access_cache_shrinker(struct shrinker *shrink,
2731495f230SYing Han 					struct shrink_control *sc);
274597d9289SBryan Schumaker struct dentry *nfs_lookup(struct inode *, struct dentry *, unsigned int);
275597d9289SBryan Schumaker int nfs_create(struct inode *, struct dentry *, umode_t, bool);
276597d9289SBryan Schumaker int nfs_mkdir(struct inode *, struct dentry *, umode_t);
277597d9289SBryan Schumaker int nfs_rmdir(struct inode *, struct dentry *);
278597d9289SBryan Schumaker int nfs_unlink(struct inode *, struct dentry *);
279597d9289SBryan Schumaker int nfs_symlink(struct inode *, struct dentry *, const char *);
280597d9289SBryan Schumaker int nfs_link(struct dentry *, struct inode *, struct dentry *);
281597d9289SBryan Schumaker int nfs_mknod(struct inode *, struct dentry *, umode_t, dev_t);
282597d9289SBryan Schumaker int nfs_rename(struct inode *, struct dentry *, struct inode *, struct dentry *);
283979df72eSTrond Myklebust 
284ce4ef7c0SBryan Schumaker /* file.c */
285ce4ef7c0SBryan Schumaker int nfs_file_fsync_commit(struct file *, loff_t, loff_t, int);
286ce4ef7c0SBryan Schumaker loff_t nfs_file_llseek(struct file *, loff_t, int);
287ce4ef7c0SBryan Schumaker int nfs_file_flush(struct file *, fl_owner_t);
288ce4ef7c0SBryan Schumaker ssize_t nfs_file_read(struct kiocb *, const struct iovec *, unsigned long, loff_t);
289ce4ef7c0SBryan Schumaker ssize_t nfs_file_splice_read(struct file *, loff_t *, struct pipe_inode_info *,
290ce4ef7c0SBryan Schumaker 			     size_t, unsigned int);
291ce4ef7c0SBryan Schumaker int nfs_file_mmap(struct file *, struct vm_area_struct *);
292ce4ef7c0SBryan Schumaker ssize_t nfs_file_write(struct kiocb *, const struct iovec *, unsigned long, loff_t);
293ce4ef7c0SBryan Schumaker int nfs_file_release(struct inode *, struct file *);
294ce4ef7c0SBryan Schumaker int nfs_lock(struct file *, int, struct file_lock *);
295ce4ef7c0SBryan Schumaker int nfs_flock(struct file *, int, struct file_lock *);
296ce4ef7c0SBryan Schumaker ssize_t nfs_file_splice_write(struct pipe_inode_info *, struct file *, loff_t *,
297ce4ef7c0SBryan Schumaker 			      size_t, unsigned int);
298ce4ef7c0SBryan Schumaker int nfs_check_flags(int);
299ce4ef7c0SBryan Schumaker int nfs_setlease(struct file *, long, struct file_lock **);
300ce4ef7c0SBryan Schumaker 
301f7b422b1SDavid Howells /* inode.c */
3025746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
303f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
304f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *);
305a9185b41SChristoph Hellwig extern int nfs_write_inode(struct inode *, struct writeback_control *);
306eed99357STrond Myklebust extern int nfs_drop_inode(struct inode *);
30719d87ca3SBryan Schumaker extern void nfs_clear_inode(struct inode *);
308b57922d9SAl Viro extern void nfs_evict_inode(struct inode *);
309f41f7418STrond Myklebust void nfs_zap_acl_cache(struct inode *inode);
31072cb77f4STrond Myklebust extern int nfs_wait_bit_killable(void *word);
311f7b422b1SDavid Howells 
312f7b422b1SDavid Howells /* super.c */
3136a74490dSBryan Schumaker extern const struct super_operations nfs_sops;
314ab7017a3SBryan Schumaker extern struct file_system_type nfs_fs_type;
31554ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type;
31689d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
31754ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type;
31854ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type;
319f7b422b1SDavid Howells #endif
320ff9099f2SBryan Schumaker struct dentry *nfs_try_mount(int, const char *, struct nfs_mount_info *,
321ff9099f2SBryan Schumaker 			struct nfs_subversion *);
322fbdefd64SBryan Schumaker void nfs_initialise_sb(struct super_block *);
323fbdefd64SBryan Schumaker int nfs_set_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
324fbdefd64SBryan Schumaker int nfs_clone_sb_security(struct super_block *, struct dentry *, struct nfs_mount_info *);
325ab7017a3SBryan Schumaker struct dentry *nfs_fs_mount_common(struct nfs_server *, int, const char *,
326ab7017a3SBryan Schumaker 				   struct nfs_mount_info *, struct nfs_subversion *);
327fbdefd64SBryan Schumaker struct dentry *nfs_fs_mount(struct file_system_type *, int, const char *, void *);
328fbdefd64SBryan Schumaker struct dentry * nfs_xdev_mount_common(struct file_system_type *, int,
329fbdefd64SBryan Schumaker 		const char *, struct nfs_mount_info *);
330fbdefd64SBryan Schumaker void nfs_kill_super(struct super_block *);
331fbdefd64SBryan Schumaker void nfs_fill_super(struct super_block *, struct nfs_mount_info *);
3324ebd9ab3SDominik Hackl 
333f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
3344ebd9ab3SDominik Hackl 
335f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
336f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
3371daef0a8STrond Myklebust extern void nfs_sb_active(struct super_block *sb);
3381daef0a8STrond Myklebust extern void nfs_sb_deactive(struct super_block *sb);
339f7b422b1SDavid Howells 
340f7b422b1SDavid Howells /* namespace.c */
34197a54868SBen Hutchings #define NFS_PATH_CANONICAL 1
342b514f872SAl Viro extern char *nfs_path(char **p, struct dentry *dentry,
34397a54868SBen Hutchings 		      char *buffer, ssize_t buflen, unsigned flags);
34436d43a43SDavid Howells extern struct vfsmount *nfs_d_automount(struct path *path);
345281cad46SBryan Schumaker struct vfsmount *nfs_submount(struct nfs_server *, struct dentry *,
346281cad46SBryan Schumaker 			      struct nfs_fh *, struct nfs_fattr *);
347281cad46SBryan Schumaker struct vfsmount *nfs_do_submount(struct dentry *, struct nfs_fh *,
348281cad46SBryan Schumaker 				 struct nfs_fattr *, rpc_authflavor_t);
349f7b422b1SDavid Howells 
35054ceac45SDavid Howells /* getroot.c */
3510d5839adSAl Viro extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *,
3520d5839adSAl Viro 				   const char *);
35389d77c8fSBryan Schumaker #if IS_ENABLED(CONFIG_NFS_V4)
3540d5839adSAl Viro extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *,
3550d5839adSAl Viro 				    const char *);
35654ceac45SDavid Howells 
357815409d2STrond Myklebust extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
3587d4e2747SDavid Howells #endif
359f7b422b1SDavid Howells 
360061ae2edSFred Isaman struct nfs_pgio_completion_ops;
361f11c88afSAndy Adamson /* read.c */
3624db6e0b7SFred Isaman extern struct nfs_read_header *nfs_readhdr_alloc(void);
363cd841605SFred Isaman extern void nfs_readhdr_free(struct nfs_pgio_header *hdr);
364584aa810SFred Isaman extern void nfs_pageio_init_read(struct nfs_pageio_descriptor *pgio,
365584aa810SFred Isaman 			struct inode *inode,
366584aa810SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
367c5996c4eSFred Isaman extern int nfs_initiate_read(struct rpc_clnt *clnt,
368c5996c4eSFred Isaman 			     struct nfs_read_data *data,
3699f0ec176SAndy Adamson 			     const struct rpc_call_ops *call_ops, int flags);
370f11c88afSAndy Adamson extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
371493292ddSTrond Myklebust extern int nfs_generic_pagein(struct nfs_pageio_descriptor *desc,
3724db6e0b7SFred Isaman 			      struct nfs_pgio_header *hdr);
373493292ddSTrond Myklebust extern void nfs_pageio_reset_read_mds(struct nfs_pageio_descriptor *pgio);
374493292ddSTrond Myklebust extern void nfs_readdata_release(struct nfs_read_data *rdata);
375e885de1aSTrond Myklebust 
376fbdefd64SBryan Schumaker /* super.c */
377fbdefd64SBryan Schumaker void nfs_clone_super(struct super_block *, struct nfs_mount_info *);
378fbdefd64SBryan Schumaker void nfs_umount_begin(struct super_block *);
379fbdefd64SBryan Schumaker int  nfs_statfs(struct dentry *, struct kstatfs *);
380fbdefd64SBryan Schumaker int  nfs_show_options(struct seq_file *, struct dentry *);
381fbdefd64SBryan Schumaker int  nfs_show_devname(struct seq_file *, struct dentry *);
382fbdefd64SBryan Schumaker int  nfs_show_path(struct seq_file *, struct dentry *);
383fbdefd64SBryan Schumaker int  nfs_show_stats(struct seq_file *, struct dentry *);
384fbdefd64SBryan Schumaker void nfs_put_super(struct super_block *);
385fbdefd64SBryan Schumaker int nfs_remount(struct super_block *sb, int *flags, char *raw_data);
386fbdefd64SBryan Schumaker 
387def6ed7eSAndy Adamson /* write.c */
3881763da12SFred Isaman extern void nfs_pageio_init_write(struct nfs_pageio_descriptor *pgio,
3891763da12SFred Isaman 			struct inode *inode, int ioflags,
3901763da12SFred Isaman 			const struct nfs_pgio_completion_ops *compl_ops);
3916c75dc0dSFred Isaman extern struct nfs_write_header *nfs_writehdr_alloc(void);
392cd841605SFred Isaman extern void nfs_writehdr_free(struct nfs_pgio_header *hdr);
393dce81290STrond Myklebust extern int nfs_generic_flush(struct nfs_pageio_descriptor *desc,
3946c75dc0dSFred Isaman 			     struct nfs_pgio_header *hdr);
395dce81290STrond Myklebust extern void nfs_pageio_reset_write_mds(struct nfs_pageio_descriptor *pgio);
396dce81290STrond Myklebust extern void nfs_writedata_release(struct nfs_write_data *wdata);
3970b7c0153SFred Isaman extern void nfs_commit_free(struct nfs_commit_data *p);
398c5996c4eSFred Isaman extern int nfs_initiate_write(struct rpc_clnt *clnt,
399c5996c4eSFred Isaman 			      struct nfs_write_data *data,
400a69aef14SFred Isaman 			      const struct rpc_call_ops *call_ops,
4019f0ec176SAndy Adamson 			      int how, int flags);
402def6ed7eSAndy Adamson extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
4030b7c0153SFred Isaman extern void nfs_commit_prepare(struct rpc_task *task, void *calldata);
4040b7c0153SFred Isaman extern int nfs_initiate_commit(struct rpc_clnt *clnt,
4050b7c0153SFred Isaman 			       struct nfs_commit_data *data,
406e0c2b380SFred Isaman 			       const struct rpc_call_ops *call_ops,
4079f0ec176SAndy Adamson 			       int how, int flags);
4080b7c0153SFred Isaman extern void nfs_init_commit(struct nfs_commit_data *data,
409e0c2b380SFred Isaman 			    struct list_head *head,
410f453a54aSFred Isaman 			    struct pnfs_layout_segment *lseg,
411f453a54aSFred Isaman 			    struct nfs_commit_info *cinfo);
4121763da12SFred Isaman int nfs_scan_commit_list(struct list_head *src, struct list_head *dst,
4131763da12SFred Isaman 			 struct nfs_commit_info *cinfo, int max);
4141763da12SFred Isaman int nfs_scan_commit(struct inode *inode, struct list_head *dst,
4151763da12SFred Isaman 		    struct nfs_commit_info *cinfo);
4161763da12SFred Isaman void nfs_mark_request_commit(struct nfs_page *req,
4171763da12SFred Isaman 			     struct pnfs_layout_segment *lseg,
4181763da12SFred Isaman 			     struct nfs_commit_info *cinfo);
4191763da12SFred Isaman int nfs_generic_commit_list(struct inode *inode, struct list_head *head,
4201763da12SFred Isaman 			    int how, struct nfs_commit_info *cinfo);
421e0c2b380SFred Isaman void nfs_retry_commit(struct list_head *page_list,
422ea2cf228SFred Isaman 		      struct pnfs_layout_segment *lseg,
423ea2cf228SFred Isaman 		      struct nfs_commit_info *cinfo);
4240b7c0153SFred Isaman void nfs_commitdata_release(struct nfs_commit_data *data);
425ea2cf228SFred Isaman void nfs_request_add_commit_list(struct nfs_page *req, struct list_head *dst,
426ea2cf228SFred Isaman 				 struct nfs_commit_info *cinfo);
427ea2cf228SFred Isaman void nfs_request_remove_commit_list(struct nfs_page *req,
428ea2cf228SFred Isaman 				    struct nfs_commit_info *cinfo);
429ea2cf228SFred Isaman void nfs_init_cinfo(struct nfs_commit_info *cinfo,
430ea2cf228SFred Isaman 		    struct inode *inode,
431ea2cf228SFred Isaman 		    struct nfs_direct_req *dreq);
432e0c2b380SFred Isaman 
433074cc1deSTrond Myklebust #ifdef CONFIG_MIGRATION
434074cc1deSTrond Myklebust extern int nfs_migrate_page(struct address_space *,
435a6bc32b8SMel Gorman 		struct page *, struct page *, enum migrate_mode);
436074cc1deSTrond Myklebust #else
437074cc1deSTrond Myklebust #define nfs_migrate_page NULL
438074cc1deSTrond Myklebust #endif
439def6ed7eSAndy Adamson 
4401763da12SFred Isaman /* direct.c */
4411763da12SFred Isaman void nfs_init_cinfo_from_dreq(struct nfs_commit_info *cinfo,
4421763da12SFred Isaman 			      struct nfs_direct_req *dreq);
4431d59d61fSTrond Myklebust static inline void nfs_inode_dio_wait(struct inode *inode)
4441d59d61fSTrond Myklebust {
4451d59d61fSTrond Myklebust 	inode_dio_wait(inode);
4461d59d61fSTrond Myklebust }
4476296556fSPeng Tao extern ssize_t nfs_dreq_bytes_left(struct nfs_direct_req *dreq);
4481763da12SFred Isaman 
449cccef3b9SAndy Adamson /* nfs4proc.c */
450d20581aaSBenny Halevy extern void __nfs4_read_done_cb(struct nfs_read_data *);
4518cab4c39SChuck Lever extern struct nfs_client *nfs4_init_client(struct nfs_client *clp,
45245a52a02SAndy Adamson 			    const struct rpc_timeout *timeparms,
45345a52a02SAndy Adamson 			    const char *ip_addr,
4544bf590e0SChuck Lever 			    rpc_authflavor_t authflavour);
45505f4c350SChuck Lever extern int nfs40_walk_client_list(struct nfs_client *clp,
45605f4c350SChuck Lever 				struct nfs_client **result,
45705f4c350SChuck Lever 				struct rpc_cred *cred);
45805f4c350SChuck Lever extern int nfs41_walk_client_list(struct nfs_client *clp,
45905f4c350SChuck Lever 				struct nfs_client **result,
46005f4c350SChuck Lever 				struct rpc_cred *cred);
461cccef3b9SAndy Adamson 
462557134a3SAndy Adamson /*
463f7b422b1SDavid Howells  * Determine the device name as a string
464f7b422b1SDavid Howells  */
465b514f872SAl Viro static inline char *nfs_devname(struct dentry *dentry,
466f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
467f7b422b1SDavid Howells {
468b514f872SAl Viro 	char *dummy;
46997a54868SBen Hutchings 	return nfs_path(&dummy, dentry, buffer, buflen, NFS_PATH_CANONICAL);
470f7b422b1SDavid Howells }
471f7b422b1SDavid Howells 
472f7b422b1SDavid Howells /*
473f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
474f7b422b1SDavid Howells  */
475f7b422b1SDavid Howells static inline
476f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
477f7b422b1SDavid Howells {
478f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
479f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
480f7b422b1SDavid Howells 		unsigned char	nrbits;
481f7b422b1SDavid Howells 
482f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
483f7b422b1SDavid Howells 			;
484f7b422b1SDavid Howells 		bsize = 1 << nrbits;
485f7b422b1SDavid Howells 		if (nrbitsp)
486f7b422b1SDavid Howells 			*nrbitsp = nrbits;
487f7b422b1SDavid Howells 	}
488f7b422b1SDavid Howells 
489f7b422b1SDavid Howells 	return bsize;
490f7b422b1SDavid Howells }
491f7b422b1SDavid Howells 
492f7b422b1SDavid Howells /*
493f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
494f7b422b1SDavid Howells  */
4959eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
496f7b422b1SDavid Howells {
4979eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
498f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
499f7b422b1SDavid Howells }
500f7b422b1SDavid Howells 
501f7b422b1SDavid Howells /*
502f7b422b1SDavid Howells  * Compute and set NFS server blocksize
503f7b422b1SDavid Howells  */
504f7b422b1SDavid Howells static inline
505f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
506f7b422b1SDavid Howells {
507f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
508f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
509f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
510f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
511f7b422b1SDavid Howells 
512f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
513f7b422b1SDavid Howells }
514f7b422b1SDavid Howells 
515f7b422b1SDavid Howells /*
516f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
517f7b422b1SDavid Howells  */
518f7b422b1SDavid Howells static inline
519f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
520f7b422b1SDavid Howells {
521f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
522f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
523f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
524f7b422b1SDavid Howells }
52549a70f27STrond Myklebust 
52649a70f27STrond Myklebust /*
52749a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
52849a70f27STrond Myklebust  */
52949a70f27STrond Myklebust static inline
53049a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
53149a70f27STrond Myklebust {
532d56b4ddfSMel Gorman 	loff_t i_size = i_size_read(page_file_mapping(page)->host);
53349a70f27STrond Myklebust 
53449a70f27STrond Myklebust 	if (i_size > 0) {
535d56b4ddfSMel Gorman 		pgoff_t page_index = page_file_index(page);
53649a70f27STrond Myklebust 		pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
537d56b4ddfSMel Gorman 		if (page_index < end_index)
53849a70f27STrond Myklebust 			return PAGE_CACHE_SIZE;
539d56b4ddfSMel Gorman 		if (page_index == end_index)
54049a70f27STrond Myklebust 			return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
54149a70f27STrond Myklebust 	}
54249a70f27STrond Myklebust 	return 0;
54349a70f27STrond Myklebust }
5448d5658c9STrond Myklebust 
5458d5658c9STrond Myklebust /*
5460b26a0bfSTrond Myklebust  * Convert a umode to a dirent->d_type
5470b26a0bfSTrond Myklebust  */
5480b26a0bfSTrond Myklebust static inline
5490b26a0bfSTrond Myklebust unsigned char nfs_umode_to_dtype(umode_t mode)
5500b26a0bfSTrond Myklebust {
5510b26a0bfSTrond Myklebust 	return (mode >> 12) & 15;
5520b26a0bfSTrond Myklebust }
5530b26a0bfSTrond Myklebust 
5540b26a0bfSTrond Myklebust /*
5558d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
5568d5658c9STrond Myklebust  * with a base offset of 'base'
5578d5658c9STrond Myklebust  */
5588d5658c9STrond Myklebust static inline
5598d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len)
5608d5658c9STrond Myklebust {
5618d5658c9STrond Myklebust 	return ((unsigned long)len + (unsigned long)base +
5628d5658c9STrond Myklebust 		PAGE_SIZE - 1) >> PAGE_SHIFT;
5638d5658c9STrond Myklebust }
5640110ee15STrond Myklebust 
5653a1556e8STrond Myklebust /*
5663a1556e8STrond Myklebust  * Convert a struct timespec into a 64-bit change attribute
5673a1556e8STrond Myklebust  *
5683a1556e8STrond Myklebust  * This does approximately the same thing as timespec_to_ns(),
5693a1556e8STrond Myklebust  * but for calculation efficiency, we multiply the seconds by
5703a1556e8STrond Myklebust  * 1024*1024*1024.
5713a1556e8STrond Myklebust  */
5723a1556e8STrond Myklebust static inline
5733a1556e8STrond Myklebust u64 nfs_timespec_to_change_attr(const struct timespec *ts)
5743a1556e8STrond Myklebust {
5753a1556e8STrond Myklebust 	return ((u64)ts->tv_sec << 30) + ts->tv_nsec;
5763a1556e8STrond Myklebust }
577