blob: a806211990865d56fde9a37d42a1fd7e6d076a08 [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * NFS internal definitions
3 */
4
5#include <linux/mount.h>
6
David Howells54ceac42006-08-22 20:06:13 -04007struct nfs_string;
David Howells54ceac42006-08-22 20:06:13 -04008
9/* Maximum number of readahead requests
10 * FIXME: this should really be a sysctl so that users may tune it to suit
11 * their needs. People that do NFS over a slow network, might for
12 * instance want to reduce it to something closer to 1 for improved
13 * interactive response.
14 */
15#define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
16
David Howellsf7b422b2006-06-09 09:34:33 -040017struct nfs_clone_mount {
18 const struct super_block *sb;
19 const struct dentry *dentry;
20 struct nfs_fh *fh;
21 struct nfs_fattr *fattr;
22 char *hostname;
23 char *mnt_path;
Chuck Lever6677d092007-12-10 14:59:06 -050024 struct sockaddr *addr;
25 size_t addrlen;
David Howellsf7b422b2006-06-09 09:34:33 -040026 rpc_authflavor_t authflavor;
27};
28
\"Talpey, Thomas\6b18eaa02007-09-10 13:43:29 -040029/*
30 * In-kernel mount arguments
31 */
32struct nfs_parsed_mount_data {
33 int flags;
34 int rsize, wsize;
35 int timeo, retrans;
36 int acregmin, acregmax,
37 acdirmin, acdirmax;
38 int namlen;
39 unsigned int bsize;
40 unsigned int auth_flavor_len;
41 rpc_authflavor_t auth_flavors[1];
42 char *client_address;
43
44 struct {
Chuck Lever4c568012007-12-10 14:59:28 -050045 struct sockaddr_storage address;
46 size_t addrlen;
\"Talpey, Thomas\6b18eaa02007-09-10 13:43:29 -040047 char *hostname;
\"Talpey, Thomas\6b18eaa02007-09-10 13:43:29 -040048 unsigned int version;
49 unsigned short port;
50 int protocol;
51 } mount_server;
52
53 struct {
Chuck Lever4c568012007-12-10 14:59:28 -050054 struct sockaddr_storage address;
55 size_t addrlen;
\"Talpey, Thomas\6b18eaa02007-09-10 13:43:29 -040056 char *hostname;
57 char *export_path;
\"Talpey, Thomas\6b18eaa02007-09-10 13:43:29 -040058 int protocol;
59 } nfs_server;
60};
61
David Howells24c8dbb2006-08-22 20:06:10 -040062/* client.c */
David Howells54ceac42006-08-22 20:06:13 -040063extern struct rpc_program nfs_program;
64
David Howells24c8dbb2006-08-22 20:06:10 -040065extern void nfs_put_client(struct nfs_client *);
Chuck Leverff052642007-12-10 14:58:44 -050066extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -040067extern struct nfs_server *nfs_create_server(
68 const struct nfs_parsed_mount_data *,
69 struct nfs_fh *);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -040070extern struct nfs_server *nfs4_create_server(
71 const struct nfs_parsed_mount_data *,
72 struct nfs_fh *);
David Howells54ceac42006-08-22 20:06:13 -040073extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
74 struct nfs_fh *);
75extern void nfs_free_server(struct nfs_server *server);
76extern struct nfs_server *nfs_clone_server(struct nfs_server *,
77 struct nfs_fh *,
78 struct nfs_fattr *);
David Howells6aaca562006-08-22 20:06:13 -040079#ifdef CONFIG_PROC_FS
80extern int __init nfs_fs_proc_init(void);
81extern void nfs_fs_proc_exit(void);
82#else
83static inline int nfs_fs_proc_init(void)
84{
85 return 0;
86}
87static inline void nfs_fs_proc_exit(void)
88{
89}
90#endif
David Howells24c8dbb2006-08-22 20:06:10 -040091
David Howells7d4e2742006-08-22 20:06:07 -040092/* nfs4namespace.c */
David Howellsf7b422b2006-06-09 09:34:33 -040093#ifdef CONFIG_NFS_V4
94extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
95#else
96static inline
97struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
98{
99 return ERR_PTR(-ENOENT);
100}
101#endif
102
103/* callback_xdr.c */
104extern struct svc_version nfs4_callback_version1;
105
106/* pagelist.c */
107extern int __init nfs_init_nfspagecache(void);
David Brownell266bee82006-06-27 12:59:15 -0700108extern void nfs_destroy_nfspagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400109extern int __init nfs_init_readpagecache(void);
David Brownell266bee82006-06-27 12:59:15 -0700110extern void nfs_destroy_readpagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400111extern int __init nfs_init_writepagecache(void);
David Brownell266bee82006-06-27 12:59:15 -0700112extern void nfs_destroy_writepagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400113
114#ifdef CONFIG_NFS_DIRECTIO
115extern int __init nfs_init_directcache(void);
David Brownell266bee82006-06-27 12:59:15 -0700116extern void nfs_destroy_directcache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400117#else
118#define nfs_init_directcache() (0)
119#define nfs_destroy_directcache() do {} while(0)
120#endif
121
122/* nfs2xdr.c */
David Howells7d4e2742006-08-22 20:06:07 -0400123extern int nfs_stat_to_errno(int);
David Howellsf7b422b2006-06-09 09:34:33 -0400124extern struct rpc_procinfo nfs_procedures[];
Al Viro0dbb4c62006-10-19 23:28:49 -0700125extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
David Howellsf7b422b2006-06-09 09:34:33 -0400126
127/* nfs3xdr.c */
128extern struct rpc_procinfo nfs3_procedures[];
Al Viro0dbb4c62006-10-19 23:28:49 -0700129extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
David Howellsf7b422b2006-06-09 09:34:33 -0400130
131/* nfs4xdr.c */
David Howells7d4e2742006-08-22 20:06:07 -0400132#ifdef CONFIG_NFS_V4
Al Viro0dbb4c62006-10-19 23:28:49 -0700133extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
David Howells7d4e2742006-08-22 20:06:07 -0400134#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400135
136/* nfs4proc.c */
Andrew Mortond75d5412006-06-25 02:41:26 -0700137#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400138extern struct rpc_procinfo nfs4_procedures[];
Andrew Mortond75d5412006-06-25 02:41:26 -0700139#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400140
Trond Myklebust979df722006-07-25 11:28:19 -0400141/* dir.c */
142extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
143
David Howellsf7b422b2006-06-09 09:34:33 -0400144/* inode.c */
145extern struct inode *nfs_alloc_inode(struct super_block *sb);
146extern void nfs_destroy_inode(struct inode *);
147extern int nfs_write_inode(struct inode *,int);
148extern void nfs_clear_inode(struct inode *);
149#ifdef CONFIG_NFS_V4
150extern void nfs4_clear_inode(struct inode *);
151#endif
152
153/* super.c */
David Howells54ceac42006-08-22 20:06:13 -0400154extern struct file_system_type nfs_xdev_fs_type;
David Howellsf7b422b2006-06-09 09:34:33 -0400155#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -0400156extern struct file_system_type nfs4_xdev_fs_type;
157extern struct file_system_type nfs4_referral_fs_type;
David Howellsf7b422b2006-06-09 09:34:33 -0400158#endif
Dominik Hackl4ebd9ab2006-07-02 17:29:26 +0200159
David Howellsf7b422b2006-06-09 09:34:33 -0400160extern struct rpc_stat nfs_rpcstat;
Dominik Hackl4ebd9ab2006-07-02 17:29:26 +0200161
David Howellsf7b422b2006-06-09 09:34:33 -0400162extern int __init register_nfs_fs(void);
163extern void __exit unregister_nfs_fs(void);
Steve Dicksonef818a22007-11-08 04:05:04 -0500164extern void nfs_sb_active(struct nfs_server *server);
165extern void nfs_sb_deactive(struct nfs_server *server);
David Howellsf7b422b2006-06-09 09:34:33 -0400166
167/* namespace.c */
David Howells54ceac42006-08-22 20:06:13 -0400168extern char *nfs_path(const char *base,
169 const struct dentry *droot,
170 const struct dentry *dentry,
David Howellsf7b422b2006-06-09 09:34:33 -0400171 char *buffer, ssize_t buflen);
172
David Howells54ceac42006-08-22 20:06:13 -0400173/* getroot.c */
174extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
David Howells7d4e2742006-08-22 20:06:07 -0400175#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -0400176extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
177
178extern int nfs4_path_walk(struct nfs_server *server,
179 struct nfs_fh *mntfh,
180 const char *path);
David Howells7d4e2742006-08-22 20:06:07 -0400181#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400182
183/*
184 * Determine the device name as a string
185 */
186static inline char *nfs_devname(const struct vfsmount *mnt_parent,
David Howells54ceac42006-08-22 20:06:13 -0400187 const struct dentry *dentry,
188 char *buffer, ssize_t buflen)
David Howellsf7b422b2006-06-09 09:34:33 -0400189{
David Howells54ceac42006-08-22 20:06:13 -0400190 return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
191 dentry, buffer, buflen);
David Howellsf7b422b2006-06-09 09:34:33 -0400192}
193
194/*
195 * Determine the actual block size (and log2 thereof)
196 */
197static inline
198unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
199{
200 /* make sure blocksize is a power of two */
201 if ((bsize & (bsize - 1)) || nrbitsp) {
202 unsigned char nrbits;
203
204 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
205 ;
206 bsize = 1 << nrbits;
207 if (nrbitsp)
208 *nrbitsp = nrbits;
209 }
210
211 return bsize;
212}
213
214/*
215 * Calculate the number of 512byte blocks used.
216 */
Chuck Lever9eaa67c2007-07-01 12:12:19 -0400217static inline blkcnt_t nfs_calc_block_size(u64 tsize)
David Howellsf7b422b2006-06-09 09:34:33 -0400218{
Chuck Lever9eaa67c2007-07-01 12:12:19 -0400219 blkcnt_t used = (tsize + 511) >> 9;
David Howellsf7b422b2006-06-09 09:34:33 -0400220 return (used > ULONG_MAX) ? ULONG_MAX : used;
221}
222
223/*
224 * Compute and set NFS server blocksize
225 */
226static inline
227unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
228{
229 if (bsize < NFS_MIN_FILE_IO_SIZE)
230 bsize = NFS_DEF_FILE_IO_SIZE;
231 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
232 bsize = NFS_MAX_FILE_IO_SIZE;
233
234 return nfs_block_bits(bsize, nrbitsp);
235}
236
237/*
238 * Determine the maximum file size for a superblock
239 */
240static inline
241void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
242{
243 sb->s_maxbytes = (loff_t)maxfilesize;
244 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
245 sb->s_maxbytes = MAX_LFS_FILESIZE;
246}
Trond Myklebust49a70f2782006-12-05 00:35:38 -0500247
248/*
249 * Determine the number of bytes of data the page contains
250 */
251static inline
252unsigned int nfs_page_length(struct page *page)
253{
254 loff_t i_size = i_size_read(page->mapping->host);
255
256 if (i_size > 0) {
257 pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
258 if (page->index < end_index)
259 return PAGE_CACHE_SIZE;
260 if (page->index == end_index)
261 return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
262 }
263 return 0;
264}
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400265
266/*
267 * Determine the number of pages in an array of length 'len' and
268 * with a base offset of 'base'
269 */
270static inline
271unsigned int nfs_page_array_len(unsigned int base, size_t len)
272{
273 return ((unsigned long)len + (unsigned long)base +
274 PAGE_SIZE - 1) >> PAGE_SHIFT;
275}
276