xref: /openbmc/linux/fs/nfs/internal.h (revision 5746006f)
1f7b422b1SDavid Howells /*
2f7b422b1SDavid Howells  * NFS internal definitions
3f7b422b1SDavid Howells  */
4f7b422b1SDavid Howells 
5f7b422b1SDavid Howells #include <linux/mount.h>
6f7b422b1SDavid Howells 
754ceac45SDavid Howells struct nfs_string;
854ceac45SDavid Howells 
954ceac45SDavid Howells /* Maximum number of readahead requests
1054ceac45SDavid Howells  * FIXME: this should really be a sysctl so that users may tune it to suit
1154ceac45SDavid Howells  *        their needs. People that do NFS over a slow network, might for
1254ceac45SDavid Howells  *        instance want to reduce it to something closer to 1 for improved
1354ceac45SDavid Howells  *        interactive response.
1454ceac45SDavid Howells  */
1554ceac45SDavid Howells #define NFS_MAX_READAHEAD	(RPC_DEF_SLOT_TABLE - 1)
1654ceac45SDavid Howells 
17f7b422b1SDavid Howells struct nfs_clone_mount {
18f7b422b1SDavid Howells 	const struct super_block *sb;
19f7b422b1SDavid Howells 	const struct dentry *dentry;
20f7b422b1SDavid Howells 	struct nfs_fh *fh;
21f7b422b1SDavid Howells 	struct nfs_fattr *fattr;
22f7b422b1SDavid Howells 	char *hostname;
23f7b422b1SDavid Howells 	char *mnt_path;
246677d095SChuck Lever 	struct sockaddr *addr;
256677d095SChuck Lever 	size_t addrlen;
26f7b422b1SDavid Howells 	rpc_authflavor_t authflavor;
27f7b422b1SDavid Howells };
28f7b422b1SDavid Howells 
296b18eaa0S\"Talpey, Thomas\ /*
306b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
316b18eaa0S\"Talpey, Thomas\  */
326b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data {
336b18eaa0S\"Talpey, Thomas\ 	int			flags;
346b18eaa0S\"Talpey, Thomas\ 	int			rsize, wsize;
356b18eaa0S\"Talpey, Thomas\ 	int			timeo, retrans;
366b18eaa0S\"Talpey, Thomas\ 	int			acregmin, acregmax,
376b18eaa0S\"Talpey, Thomas\ 				acdirmin, acdirmax;
386b18eaa0S\"Talpey, Thomas\ 	int			namlen;
396b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
406b18eaa0S\"Talpey, Thomas\ 	unsigned int		auth_flavor_len;
416b18eaa0S\"Talpey, Thomas\ 	rpc_authflavor_t	auth_flavors[1];
426b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
436b18eaa0S\"Talpey, Thomas\ 
446b18eaa0S\"Talpey, Thomas\ 	struct {
454c568017SChuck Lever 		struct sockaddr_storage	address;
464c568017SChuck Lever 		size_t			addrlen;
476b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
486b18eaa0S\"Talpey, Thomas\ 		unsigned int		version;
496b18eaa0S\"Talpey, Thomas\ 		unsigned short		port;
506b18eaa0S\"Talpey, Thomas\ 		int			protocol;
516b18eaa0S\"Talpey, Thomas\ 	} mount_server;
526b18eaa0S\"Talpey, Thomas\ 
536b18eaa0S\"Talpey, Thomas\ 	struct {
544c568017SChuck Lever 		struct sockaddr_storage	address;
554c568017SChuck Lever 		size_t			addrlen;
566b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
576b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
586b18eaa0S\"Talpey, Thomas\ 		int			protocol;
596b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
606b18eaa0S\"Talpey, Thomas\ };
616b18eaa0S\"Talpey, Thomas\ 
6224c8dbbbSDavid Howells /* client.c */
6354ceac45SDavid Howells extern struct rpc_program nfs_program;
6454ceac45SDavid Howells 
6524c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
66ff052645SChuck Lever extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
673fbd67adSTrond Myklebust extern struct nfs_client *nfs_find_client_next(struct nfs_client *);
682283f8d6S\"Talpey, Thomas\ extern struct nfs_server *nfs_create_server(
692283f8d6S\"Talpey, Thomas\ 					const struct nfs_parsed_mount_data *,
7054ceac45SDavid Howells 					struct nfs_fh *);
7191ea40b9S\"Talpey, Thomas\ extern struct nfs_server *nfs4_create_server(
7291ea40b9S\"Talpey, Thomas\ 					const struct nfs_parsed_mount_data *,
7354ceac45SDavid Howells 					struct nfs_fh *);
7454ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
7554ceac45SDavid Howells 						      struct nfs_fh *);
7654ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
7754ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
7854ceac45SDavid Howells 					   struct nfs_fh *,
7954ceac45SDavid Howells 					   struct nfs_fattr *);
806aaca566SDavid Howells #ifdef CONFIG_PROC_FS
816aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
826aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
836aaca566SDavid Howells #else
846aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
856aaca566SDavid Howells {
866aaca566SDavid Howells 	return 0;
876aaca566SDavid Howells }
886aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
896aaca566SDavid Howells {
906aaca566SDavid Howells }
916aaca566SDavid Howells #endif
9224c8dbbbSDavid Howells 
937d4e2747SDavid Howells /* nfs4namespace.c */
94f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
95f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
96f7b422b1SDavid Howells #else
97f7b422b1SDavid Howells static inline
98f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
99f7b422b1SDavid Howells {
100f7b422b1SDavid Howells 	return ERR_PTR(-ENOENT);
101f7b422b1SDavid Howells }
102f7b422b1SDavid Howells #endif
103f7b422b1SDavid Howells 
104f7b422b1SDavid Howells /* callback_xdr.c */
105f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1;
106f7b422b1SDavid Howells 
107f7b422b1SDavid Howells /* pagelist.c */
108f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
109266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
110f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
111266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
112f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
113266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
114f7b422b1SDavid Howells 
115f7b422b1SDavid Howells #ifdef CONFIG_NFS_DIRECTIO
116f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
117266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
118f7b422b1SDavid Howells #else
119f7b422b1SDavid Howells #define nfs_init_directcache() (0)
120f7b422b1SDavid Howells #define nfs_destroy_directcache() do {} while(0)
121f7b422b1SDavid Howells #endif
122f7b422b1SDavid Howells 
123f7b422b1SDavid Howells /* nfs2xdr.c */
1247d4e2747SDavid Howells extern int nfs_stat_to_errno(int);
125f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[];
1260dbb4c67SAl Viro extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
127f7b422b1SDavid Howells 
128f7b422b1SDavid Howells /* nfs3xdr.c */
129f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[];
1300dbb4c67SAl Viro extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
131f7b422b1SDavid Howells 
132f7b422b1SDavid Howells /* nfs4xdr.c */
1337d4e2747SDavid Howells #ifdef CONFIG_NFS_V4
1340dbb4c67SAl Viro extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
1357d4e2747SDavid Howells #endif
136f7b422b1SDavid Howells 
137f7b422b1SDavid Howells /* nfs4proc.c */
138d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4
139f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[];
140d75d5414SAndrew Morton #endif
141f7b422b1SDavid Howells 
142979df72eSTrond Myklebust /* dir.c */
143979df72eSTrond Myklebust extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
144979df72eSTrond Myklebust 
145f7b422b1SDavid Howells /* inode.c */
1465746006fSTrond Myklebust extern struct workqueue_struct *nfsiod_workqueue;
147f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
148f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *);
149f7b422b1SDavid Howells extern int nfs_write_inode(struct inode *,int);
150f7b422b1SDavid Howells extern void nfs_clear_inode(struct inode *);
151f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
152f7b422b1SDavid Howells extern void nfs4_clear_inode(struct inode *);
153f7b422b1SDavid Howells #endif
154f7b422b1SDavid Howells 
155f7b422b1SDavid Howells /* super.c */
15654ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type;
157f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
15854ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type;
15954ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type;
160f7b422b1SDavid Howells #endif
1614ebd9ab3SDominik Hackl 
162f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
1634ebd9ab3SDominik Hackl 
164f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
165f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
166ef818a28SSteve Dickson extern void nfs_sb_active(struct nfs_server *server);
167ef818a28SSteve Dickson extern void nfs_sb_deactive(struct nfs_server *server);
168f7b422b1SDavid Howells 
169f7b422b1SDavid Howells /* namespace.c */
17054ceac45SDavid Howells extern char *nfs_path(const char *base,
17154ceac45SDavid Howells 		      const struct dentry *droot,
17254ceac45SDavid Howells 		      const struct dentry *dentry,
173f7b422b1SDavid Howells 		      char *buffer, ssize_t buflen);
174f7b422b1SDavid Howells 
17554ceac45SDavid Howells /* getroot.c */
17654ceac45SDavid Howells extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
1777d4e2747SDavid Howells #ifdef CONFIG_NFS_V4
17854ceac45SDavid Howells extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
17954ceac45SDavid Howells 
18054ceac45SDavid Howells extern int nfs4_path_walk(struct nfs_server *server,
18154ceac45SDavid Howells 			  struct nfs_fh *mntfh,
18254ceac45SDavid Howells 			  const char *path);
1837d4e2747SDavid Howells #endif
184f7b422b1SDavid Howells 
185f7b422b1SDavid Howells /*
186f7b422b1SDavid Howells  * Determine the device name as a string
187f7b422b1SDavid Howells  */
188f7b422b1SDavid Howells static inline char *nfs_devname(const struct vfsmount *mnt_parent,
189f7b422b1SDavid Howells 				const struct dentry *dentry,
190f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
191f7b422b1SDavid Howells {
19254ceac45SDavid Howells 	return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
19354ceac45SDavid Howells 			dentry, buffer, buflen);
194f7b422b1SDavid Howells }
195f7b422b1SDavid Howells 
196f7b422b1SDavid Howells /*
197f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
198f7b422b1SDavid Howells  */
199f7b422b1SDavid Howells static inline
200f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
201f7b422b1SDavid Howells {
202f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
203f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
204f7b422b1SDavid Howells 		unsigned char	nrbits;
205f7b422b1SDavid Howells 
206f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
207f7b422b1SDavid Howells 			;
208f7b422b1SDavid Howells 		bsize = 1 << nrbits;
209f7b422b1SDavid Howells 		if (nrbitsp)
210f7b422b1SDavid Howells 			*nrbitsp = nrbits;
211f7b422b1SDavid Howells 	}
212f7b422b1SDavid Howells 
213f7b422b1SDavid Howells 	return bsize;
214f7b422b1SDavid Howells }
215f7b422b1SDavid Howells 
216f7b422b1SDavid Howells /*
217f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
218f7b422b1SDavid Howells  */
2199eaa67c6SChuck Lever static inline blkcnt_t nfs_calc_block_size(u64 tsize)
220f7b422b1SDavid Howells {
2219eaa67c6SChuck Lever 	blkcnt_t used = (tsize + 511) >> 9;
222f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
223f7b422b1SDavid Howells }
224f7b422b1SDavid Howells 
225f7b422b1SDavid Howells /*
226f7b422b1SDavid Howells  * Compute and set NFS server blocksize
227f7b422b1SDavid Howells  */
228f7b422b1SDavid Howells static inline
229f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
230f7b422b1SDavid Howells {
231f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
232f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
233f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
234f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
235f7b422b1SDavid Howells 
236f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
237f7b422b1SDavid Howells }
238f7b422b1SDavid Howells 
239f7b422b1SDavid Howells /*
240f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
241f7b422b1SDavid Howells  */
242f7b422b1SDavid Howells static inline
243f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
244f7b422b1SDavid Howells {
245f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
246f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
247f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
248f7b422b1SDavid Howells }
24949a70f27STrond Myklebust 
25049a70f27STrond Myklebust /*
25149a70f27STrond Myklebust  * Determine the number of bytes of data the page contains
25249a70f27STrond Myklebust  */
25349a70f27STrond Myklebust static inline
25449a70f27STrond Myklebust unsigned int nfs_page_length(struct page *page)
25549a70f27STrond Myklebust {
25649a70f27STrond Myklebust 	loff_t i_size = i_size_read(page->mapping->host);
25749a70f27STrond Myklebust 
25849a70f27STrond Myklebust 	if (i_size > 0) {
25949a70f27STrond Myklebust 		pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
26049a70f27STrond Myklebust 		if (page->index < end_index)
26149a70f27STrond Myklebust 			return PAGE_CACHE_SIZE;
26249a70f27STrond Myklebust 		if (page->index == end_index)
26349a70f27STrond Myklebust 			return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
26449a70f27STrond Myklebust 	}
26549a70f27STrond Myklebust 	return 0;
26649a70f27STrond Myklebust }
2678d5658c9STrond Myklebust 
2688d5658c9STrond Myklebust /*
2698d5658c9STrond Myklebust  * Determine the number of pages in an array of length 'len' and
2708d5658c9STrond Myklebust  * with a base offset of 'base'
2718d5658c9STrond Myklebust  */
2728d5658c9STrond Myklebust static inline
2738d5658c9STrond Myklebust unsigned int nfs_page_array_len(unsigned int base, size_t len)
2748d5658c9STrond Myklebust {
2758d5658c9STrond Myklebust 	return ((unsigned long)len + (unsigned long)base +
2768d5658c9STrond Myklebust 		PAGE_SIZE - 1) >> PAGE_SHIFT;
2778d5658c9STrond Myklebust }
2788d5658c9STrond Myklebust 
279