xref: /openbmc/linux/fs/nfs/internal.h (revision 54ceac45)
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 
3024c8dbbbSDavid Howells /* client.c */
3154ceac45SDavid Howells extern struct rpc_program nfs_program;
3254ceac45SDavid Howells 
3324c8dbbbSDavid Howells extern void nfs_put_client(struct nfs_client *);
3424c8dbbbSDavid Howells extern struct nfs_client *nfs_find_client(const struct sockaddr_in *, int);
3554ceac45SDavid Howells extern struct nfs_server *nfs_create_server(const struct nfs_mount_data *,
3654ceac45SDavid Howells 					    struct nfs_fh *);
3754ceac45SDavid Howells extern struct nfs_server *nfs4_create_server(const struct nfs4_mount_data *,
3854ceac45SDavid Howells 					     const char *,
3954ceac45SDavid Howells 					     const struct sockaddr_in *,
4054ceac45SDavid Howells 					     const char *,
4154ceac45SDavid Howells 					     const char *,
4254ceac45SDavid Howells 					     rpc_authflavor_t,
4354ceac45SDavid Howells 					     struct nfs_fh *);
4454ceac45SDavid Howells extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
4554ceac45SDavid Howells 						      struct nfs_fh *);
4654ceac45SDavid Howells extern void nfs_free_server(struct nfs_server *server);
4754ceac45SDavid Howells extern struct nfs_server *nfs_clone_server(struct nfs_server *,
4854ceac45SDavid Howells 					   struct nfs_fh *,
4954ceac45SDavid Howells 					   struct nfs_fattr *);
5024c8dbbbSDavid Howells 
517d4e2747SDavid Howells /* nfs4namespace.c */
52f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
53f7b422b1SDavid Howells extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
54f7b422b1SDavid Howells #else
55f7b422b1SDavid Howells static inline
56f7b422b1SDavid Howells struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
57f7b422b1SDavid Howells {
58f7b422b1SDavid Howells 	return ERR_PTR(-ENOENT);
59f7b422b1SDavid Howells }
60f7b422b1SDavid Howells #endif
61f7b422b1SDavid Howells 
62f7b422b1SDavid Howells /* callback_xdr.c */
63f7b422b1SDavid Howells extern struct svc_version nfs4_callback_version1;
64f7b422b1SDavid Howells 
65f7b422b1SDavid Howells /* pagelist.c */
66f7b422b1SDavid Howells extern int __init nfs_init_nfspagecache(void);
67266bee88SDavid Brownell extern void nfs_destroy_nfspagecache(void);
68f7b422b1SDavid Howells extern int __init nfs_init_readpagecache(void);
69266bee88SDavid Brownell extern void nfs_destroy_readpagecache(void);
70f7b422b1SDavid Howells extern int __init nfs_init_writepagecache(void);
71266bee88SDavid Brownell extern void nfs_destroy_writepagecache(void);
72f7b422b1SDavid Howells 
73f7b422b1SDavid Howells #ifdef CONFIG_NFS_DIRECTIO
74f7b422b1SDavid Howells extern int __init nfs_init_directcache(void);
75266bee88SDavid Brownell extern void nfs_destroy_directcache(void);
76f7b422b1SDavid Howells #else
77f7b422b1SDavid Howells #define nfs_init_directcache() (0)
78f7b422b1SDavid Howells #define nfs_destroy_directcache() do {} while(0)
79f7b422b1SDavid Howells #endif
80f7b422b1SDavid Howells 
81f7b422b1SDavid Howells /* nfs2xdr.c */
827d4e2747SDavid Howells extern int nfs_stat_to_errno(int);
83f7b422b1SDavid Howells extern struct rpc_procinfo nfs_procedures[];
84f7b422b1SDavid Howells extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
85f7b422b1SDavid Howells 
86f7b422b1SDavid Howells /* nfs3xdr.c */
87f7b422b1SDavid Howells extern struct rpc_procinfo nfs3_procedures[];
88f7b422b1SDavid Howells extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
89f7b422b1SDavid Howells 
90f7b422b1SDavid Howells /* nfs4xdr.c */
917d4e2747SDavid Howells #ifdef CONFIG_NFS_V4
92f7b422b1SDavid Howells extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
937d4e2747SDavid Howells #endif
94f7b422b1SDavid Howells 
95f7b422b1SDavid Howells /* nfs4proc.c */
96d75d5414SAndrew Morton #ifdef CONFIG_NFS_V4
97f7b422b1SDavid Howells extern struct rpc_procinfo nfs4_procedures[];
98f7b422b1SDavid Howells 
99f7b422b1SDavid Howells extern int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry,
100f7b422b1SDavid Howells 				  struct nfs4_fs_locations *fs_locations,
101f7b422b1SDavid Howells 				  struct page *page);
102d75d5414SAndrew Morton #endif
103f7b422b1SDavid Howells 
104979df72eSTrond Myklebust /* dir.c */
105979df72eSTrond Myklebust extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
106979df72eSTrond Myklebust 
107f7b422b1SDavid Howells /* inode.c */
108f7b422b1SDavid Howells extern struct inode *nfs_alloc_inode(struct super_block *sb);
109f7b422b1SDavid Howells extern void nfs_destroy_inode(struct inode *);
110f7b422b1SDavid Howells extern int nfs_write_inode(struct inode *,int);
111f7b422b1SDavid Howells extern void nfs_clear_inode(struct inode *);
112f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
113f7b422b1SDavid Howells extern void nfs4_clear_inode(struct inode *);
114f7b422b1SDavid Howells #endif
115f7b422b1SDavid Howells 
116f7b422b1SDavid Howells /* super.c */
11754ceac45SDavid Howells extern struct file_system_type nfs_xdev_fs_type;
118f7b422b1SDavid Howells #ifdef CONFIG_NFS_V4
11954ceac45SDavid Howells extern struct file_system_type nfs4_xdev_fs_type;
12054ceac45SDavid Howells extern struct file_system_type nfs4_referral_fs_type;
121f7b422b1SDavid Howells #endif
1224ebd9ab3SDominik Hackl 
123f7b422b1SDavid Howells extern struct rpc_stat nfs_rpcstat;
1244ebd9ab3SDominik Hackl 
125f7b422b1SDavid Howells extern int __init register_nfs_fs(void);
126f7b422b1SDavid Howells extern void __exit unregister_nfs_fs(void);
127f7b422b1SDavid Howells 
128f7b422b1SDavid Howells /* namespace.c */
12954ceac45SDavid Howells extern char *nfs_path(const char *base,
13054ceac45SDavid Howells 		      const struct dentry *droot,
13154ceac45SDavid Howells 		      const struct dentry *dentry,
132f7b422b1SDavid Howells 		      char *buffer, ssize_t buflen);
133f7b422b1SDavid Howells 
13454ceac45SDavid Howells /* getroot.c */
13554ceac45SDavid Howells extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
1367d4e2747SDavid Howells #ifdef CONFIG_NFS_V4
13754ceac45SDavid Howells extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
13854ceac45SDavid Howells 
13954ceac45SDavid Howells extern int nfs4_path_walk(struct nfs_server *server,
14054ceac45SDavid Howells 			  struct nfs_fh *mntfh,
14154ceac45SDavid Howells 			  const char *path);
1427d4e2747SDavid Howells #endif
143f7b422b1SDavid Howells 
144f7b422b1SDavid Howells /*
145f7b422b1SDavid Howells  * Determine the device name as a string
146f7b422b1SDavid Howells  */
147f7b422b1SDavid Howells static inline char *nfs_devname(const struct vfsmount *mnt_parent,
148f7b422b1SDavid Howells 				const struct dentry *dentry,
149f7b422b1SDavid Howells 				char *buffer, ssize_t buflen)
150f7b422b1SDavid Howells {
15154ceac45SDavid Howells 	return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
15254ceac45SDavid Howells 			dentry, buffer, buflen);
153f7b422b1SDavid Howells }
154f7b422b1SDavid Howells 
155f7b422b1SDavid Howells /*
156f7b422b1SDavid Howells  * Determine the actual block size (and log2 thereof)
157f7b422b1SDavid Howells  */
158f7b422b1SDavid Howells static inline
159f7b422b1SDavid Howells unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
160f7b422b1SDavid Howells {
161f7b422b1SDavid Howells 	/* make sure blocksize is a power of two */
162f7b422b1SDavid Howells 	if ((bsize & (bsize - 1)) || nrbitsp) {
163f7b422b1SDavid Howells 		unsigned char	nrbits;
164f7b422b1SDavid Howells 
165f7b422b1SDavid Howells 		for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
166f7b422b1SDavid Howells 			;
167f7b422b1SDavid Howells 		bsize = 1 << nrbits;
168f7b422b1SDavid Howells 		if (nrbitsp)
169f7b422b1SDavid Howells 			*nrbitsp = nrbits;
170f7b422b1SDavid Howells 	}
171f7b422b1SDavid Howells 
172f7b422b1SDavid Howells 	return bsize;
173f7b422b1SDavid Howells }
174f7b422b1SDavid Howells 
175f7b422b1SDavid Howells /*
176f7b422b1SDavid Howells  * Calculate the number of 512byte blocks used.
177f7b422b1SDavid Howells  */
178f7b422b1SDavid Howells static inline unsigned long nfs_calc_block_size(u64 tsize)
179f7b422b1SDavid Howells {
180f7b422b1SDavid Howells 	loff_t used = (tsize + 511) >> 9;
181f7b422b1SDavid Howells 	return (used > ULONG_MAX) ? ULONG_MAX : used;
182f7b422b1SDavid Howells }
183f7b422b1SDavid Howells 
184f7b422b1SDavid Howells /*
185f7b422b1SDavid Howells  * Compute and set NFS server blocksize
186f7b422b1SDavid Howells  */
187f7b422b1SDavid Howells static inline
188f7b422b1SDavid Howells unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
189f7b422b1SDavid Howells {
190f7b422b1SDavid Howells 	if (bsize < NFS_MIN_FILE_IO_SIZE)
191f7b422b1SDavid Howells 		bsize = NFS_DEF_FILE_IO_SIZE;
192f7b422b1SDavid Howells 	else if (bsize >= NFS_MAX_FILE_IO_SIZE)
193f7b422b1SDavid Howells 		bsize = NFS_MAX_FILE_IO_SIZE;
194f7b422b1SDavid Howells 
195f7b422b1SDavid Howells 	return nfs_block_bits(bsize, nrbitsp);
196f7b422b1SDavid Howells }
197f7b422b1SDavid Howells 
198f7b422b1SDavid Howells /*
199f7b422b1SDavid Howells  * Determine the maximum file size for a superblock
200f7b422b1SDavid Howells  */
201f7b422b1SDavid Howells static inline
202f7b422b1SDavid Howells void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
203f7b422b1SDavid Howells {
204f7b422b1SDavid Howells 	sb->s_maxbytes = (loff_t)maxfilesize;
205f7b422b1SDavid Howells 	if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
206f7b422b1SDavid Howells 		sb->s_maxbytes = MAX_LFS_FILESIZE;
207f7b422b1SDavid Howells }
208