xref: /openbmc/linux/fs/nfs/internal.h (revision 6b18eaa0)
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 struct nfs_mount_data;
954ceac45SDavid Howells struct nfs4_mount_data;
1054ceac45SDavid Howells 
1154ceac45SDavid Howells /* Maximum number of readahead requests
1254ceac45SDavid Howells  * FIXME: this should really be a sysctl so that users may tune it to suit
1354ceac45SDavid Howells  *        their needs. People that do NFS over a slow network, might for
1454ceac45SDavid Howells  *        instance want to reduce it to something closer to 1 for improved
1554ceac45SDavid Howells  *        interactive response.
1654ceac45SDavid Howells  */
1754ceac45SDavid Howells #define NFS_MAX_READAHEAD	(RPC_DEF_SLOT_TABLE - 1)
1854ceac45SDavid Howells 
19f7b422b1SDavid Howells struct nfs_clone_mount {
20f7b422b1SDavid Howells 	const struct super_block *sb;
21f7b422b1SDavid Howells 	const struct dentry *dentry;
22f7b422b1SDavid Howells 	struct nfs_fh *fh;
23f7b422b1SDavid Howells 	struct nfs_fattr *fattr;
24f7b422b1SDavid Howells 	char *hostname;
25f7b422b1SDavid Howells 	char *mnt_path;
26f7b422b1SDavid Howells 	struct sockaddr_in *addr;
27f7b422b1SDavid Howells 	rpc_authflavor_t authflavor;
28f7b422b1SDavid Howells };
29f7b422b1SDavid Howells 
306b18eaa0S\"Talpey, Thomas\ /*
316b18eaa0S\"Talpey, Thomas\  * In-kernel mount arguments
326b18eaa0S\"Talpey, Thomas\  */
336b18eaa0S\"Talpey, Thomas\ struct nfs_parsed_mount_data {
346b18eaa0S\"Talpey, Thomas\ 	int			flags;
356b18eaa0S\"Talpey, Thomas\ 	int			rsize, wsize;
366b18eaa0S\"Talpey, Thomas\ 	int			timeo, retrans;
376b18eaa0S\"Talpey, Thomas\ 	int			acregmin, acregmax,
386b18eaa0S\"Talpey, Thomas\ 				acdirmin, acdirmax;
396b18eaa0S\"Talpey, Thomas\ 	int			namlen;
406b18eaa0S\"Talpey, Thomas\ 	unsigned int		bsize;
416b18eaa0S\"Talpey, Thomas\ 	unsigned int		auth_flavor_len;
426b18eaa0S\"Talpey, Thomas\ 	rpc_authflavor_t	auth_flavors[1];
436b18eaa0S\"Talpey, Thomas\ 	char			*client_address;
446b18eaa0S\"Talpey, Thomas\ 
456b18eaa0S\"Talpey, Thomas\ 	struct {
466b18eaa0S\"Talpey, Thomas\ 		struct sockaddr_in	address;
476b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
486b18eaa0S\"Talpey, Thomas\ 		unsigned int		program;
496b18eaa0S\"Talpey, Thomas\ 		unsigned int		version;
506b18eaa0S\"Talpey, Thomas\ 		unsigned short		port;
516b18eaa0S\"Talpey, Thomas\ 		int			protocol;
526b18eaa0S\"Talpey, Thomas\ 	} mount_server;
536b18eaa0S\"Talpey, Thomas\ 
546b18eaa0S\"Talpey, Thomas\ 	struct {
556b18eaa0S\"Talpey, Thomas\ 		struct sockaddr_in	address;
566b18eaa0S\"Talpey, Thomas\ 		char			*hostname;
576b18eaa0S\"Talpey, Thomas\ 		char			*export_path;
586b18eaa0S\"Talpey, Thomas\ 		unsigned int		program;
596b18eaa0S\"Talpey, Thomas\ 		int			protocol;
606b18eaa0S\"Talpey, Thomas\ 	} nfs_server;
616b18eaa0S\"Talpey, Thomas\ };
626b18eaa0S\"Talpey, Thomas\ 
6324c8dbbbSDavid Howells /* client.c */
6454ceac45SDavid Howells extern struct rpc_program nfs_program;
6554ceac45SDavid Howells 
6624c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
6724c8dbbbSDavid Howells extern struct nfs_client *nfs_find_client(const struct sockaddr_in *, int);
6854ceac45SDavid Howells extern struct nfs_server *nfs_create_server(const struct nfs_mount_data *,
6954ceac45SDavid Howells 					    struct nfs_fh *);
7054ceac45SDavid Howells extern struct nfs_server *nfs4_create_server(const struct nfs4_mount_data *,
7154ceac45SDavid Howells 					     const char *,
7254ceac45SDavid Howells 					     const struct sockaddr_in *,
7354ceac45SDavid Howells 					     const char *,
7454ceac45SDavid Howells 					     const char *,
7554ceac45SDavid Howells 					     rpc_authflavor_t,
7654ceac45SDavid Howells 					     struct nfs_fh *);
7754ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
7854ceac45SDavid Howells 						      struct nfs_fh *);
7954ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
8054ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
8154ceac45SDavid Howells 					   struct nfs_fh *,
8254ceac45SDavid Howells 					   struct nfs_fattr *);
836aaca566SDavid Howells #ifdef CONFIG_PROC_FS
846aaca566SDavid Howells extern int __init nfs_fs_proc_init(void);
856aaca566SDavid Howells extern void nfs_fs_proc_exit(void);
866aaca566SDavid Howells #else
876aaca566SDavid Howells static inline int nfs_fs_proc_init(void)
886aaca566SDavid Howells {
896aaca566SDavid Howells 	return 0;
906aaca566SDavid Howells }
916aaca566SDavid Howells static inline void nfs_fs_proc_exit(void)
926aaca566SDavid Howells {
936aaca566SDavid Howells }
946aaca566SDavid Howells #endif
9524c8dbbbSDavid Howells 
967d4e2747SDavid Howells /* nfs4namespace.c */
97f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
98f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
99f7b422b1SDavid Howells #else
100f7b422b1SDavid Howells static inline
101f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
102f7b422b1SDavid Howells {
103f7b422b1SDavid Howells 	return ERR_PTR(-ENOENT);
104f7b422b1SDavid Howells }
105f7b422b1SDavid Howells #endif
106f7b422b1SDavid Howells 
107f7b422b1SDavid Howells /* callback_xdr.c */
108f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1;
109f7b422b1SDavid Howells 
110f7b422b1SDavid Howells /* pagelist.c */
111f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
112266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
113f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
114266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
115f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
116266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
117f7b422b1SDavid Howells 
118f7b422b1SDavid Howells #ifdef CONFIG_NFS_DIRECTIO
119f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
120266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
121f7b422b1SDavid Howells #else
122f7b422b1SDavid Howells #define nfs_init_directcache() (0)
123f7b422b1SDavid Howells #define nfs_destroy_directcache() do {} while(0)
124f7b422b1SDavid Howells #endif
125f7b422b1SDavid Howells 
126f7b422b1SDavid Howells /* nfs2xdr.c */
1277d4e2747SDavid Howells extern int nfs_stat_to_errno(int);
128f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[];
1290dbb4c67SAl Viro extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
130f7b422b1SDavid Howells 
131f7b422b1SDavid Howells /* nfs3xdr.c */
132f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[];
1330dbb4c67SAl Viro extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
134f7b422b1SDavid Howells 
135f7b422b1SDavid Howells /* nfs4xdr.c */
1367d4e2747SDavid Howells #ifdef CONFIG_NFS_V4
1370dbb4c67SAl Viro extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
1387d4e2747SDavid Howells #endif
139f7b422b1SDavid Howells 
140f7b422b1SDavid Howells /* nfs4proc.c */
141d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4
142f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[];
143d75d5414SAndrew Morton #endif
144f7b422b1SDavid Howells 
145979df72eSTrond Myklebust /* dir.c */
146979df72eSTrond Myklebust extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
147979df72eSTrond Myklebust 
148f7b422b1SDavid Howells /* inode.c */
149f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
150f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *);
151f7b422b1SDavid Howells extern int nfs_write_inode(struct inode *,int);
152f7b422b1SDavid Howells extern void nfs_clear_inode(struct inode *);
153f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
154f7b422b1SDavid Howells extern void nfs4_clear_inode(struct inode *);
155f7b422b1SDavid Howells #endif
156f7b422b1SDavid Howells 
157f7b422b1SDavid Howells /* super.c */
15854ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type;
159f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
16054ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type;
16154ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type;
162f7b422b1SDavid Howells #endif
1634ebd9ab3SDominik Hackl 
164f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
1654ebd9ab3SDominik Hackl 
166f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
167f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
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