blob: 75dd4e252cae5031213a9e9aea0e26275892f83b [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\6b18eaa2007-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 {
45 struct sockaddr_in address;
46 char *hostname;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -040047 unsigned int version;
48 unsigned short port;
49 int protocol;
50 } mount_server;
51
52 struct {
53 struct sockaddr_in address;
54 char *hostname;
55 char *export_path;
\"Talpey, Thomas\6b18eaa2007-09-10 13:43:29 -040056 int protocol;
57 } nfs_server;
58};
59
David Howells24c8dbb2006-08-22 20:06:10 -040060/* client.c */
David Howells54ceac42006-08-22 20:06:13 -040061extern struct rpc_program nfs_program;
62
David Howells24c8dbb2006-08-22 20:06:10 -040063extern void nfs_put_client(struct nfs_client *);
Chuck Leverff052642007-12-10 14:58:44 -050064extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
\"Talpey, Thomas\2283f8d2007-09-10 13:43:56 -040065extern struct nfs_server *nfs_create_server(
66 const struct nfs_parsed_mount_data *,
67 struct nfs_fh *);
\"Talpey, Thomas\91ea40b2007-09-10 13:44:33 -040068extern struct nfs_server *nfs4_create_server(
69 const struct nfs_parsed_mount_data *,
70 struct nfs_fh *);
David Howells54ceac42006-08-22 20:06:13 -040071extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
72 struct nfs_fh *);
73extern void nfs_free_server(struct nfs_server *server);
74extern struct nfs_server *nfs_clone_server(struct nfs_server *,
75 struct nfs_fh *,
76 struct nfs_fattr *);
David Howells6aaca562006-08-22 20:06:13 -040077#ifdef CONFIG_PROC_FS
78extern int __init nfs_fs_proc_init(void);
79extern void nfs_fs_proc_exit(void);
80#else
81static inline int nfs_fs_proc_init(void)
82{
83 return 0;
84}
85static inline void nfs_fs_proc_exit(void)
86{
87}
88#endif
David Howells24c8dbb2006-08-22 20:06:10 -040089
David Howells7d4e2742006-08-22 20:06:07 -040090/* nfs4namespace.c */
David Howellsf7b422b2006-06-09 09:34:33 -040091#ifdef CONFIG_NFS_V4
92extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
93#else
94static inline
95struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
96{
97 return ERR_PTR(-ENOENT);
98}
99#endif
100
101/* callback_xdr.c */
102extern struct svc_version nfs4_callback_version1;
103
104/* pagelist.c */
105extern int __init nfs_init_nfspagecache(void);
David Brownell266bee82006-06-27 12:59:15 -0700106extern void nfs_destroy_nfspagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400107extern int __init nfs_init_readpagecache(void);
David Brownell266bee82006-06-27 12:59:15 -0700108extern void nfs_destroy_readpagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400109extern int __init nfs_init_writepagecache(void);
David Brownell266bee82006-06-27 12:59:15 -0700110extern void nfs_destroy_writepagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400111
112#ifdef CONFIG_NFS_DIRECTIO
113extern int __init nfs_init_directcache(void);
David Brownell266bee82006-06-27 12:59:15 -0700114extern void nfs_destroy_directcache(void);
David Howellsf7b422b2006-06-09 09:34:33 -0400115#else
116#define nfs_init_directcache() (0)
117#define nfs_destroy_directcache() do {} while(0)
118#endif
119
120/* nfs2xdr.c */
David Howells7d4e2742006-08-22 20:06:07 -0400121extern int nfs_stat_to_errno(int);
David Howellsf7b422b2006-06-09 09:34:33 -0400122extern struct rpc_procinfo nfs_procedures[];
Al Viro0dbb4c62006-10-19 23:28:49 -0700123extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
David Howellsf7b422b2006-06-09 09:34:33 -0400124
125/* nfs3xdr.c */
126extern struct rpc_procinfo nfs3_procedures[];
Al Viro0dbb4c62006-10-19 23:28:49 -0700127extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
David Howellsf7b422b2006-06-09 09:34:33 -0400128
129/* nfs4xdr.c */
David Howells7d4e2742006-08-22 20:06:07 -0400130#ifdef CONFIG_NFS_V4
Al Viro0dbb4c62006-10-19 23:28:49 -0700131extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
David Howells7d4e2742006-08-22 20:06:07 -0400132#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400133
134/* nfs4proc.c */
Andrew Mortond75d5412006-06-25 02:41:26 -0700135#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -0400136extern struct rpc_procinfo nfs4_procedures[];
Andrew Mortond75d5412006-06-25 02:41:26 -0700137#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400138
Trond Myklebust979df722006-07-25 11:28:19 -0400139/* dir.c */
140extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
141
David Howellsf7b422b2006-06-09 09:34:33 -0400142/* inode.c */
143extern struct inode *nfs_alloc_inode(struct super_block *sb);
144extern void nfs_destroy_inode(struct inode *);
145extern int nfs_write_inode(struct inode *,int);
146extern void nfs_clear_inode(struct inode *);
147#ifdef CONFIG_NFS_V4
148extern void nfs4_clear_inode(struct inode *);
149#endif
150
151/* super.c */
David Howells54ceac42006-08-22 20:06:13 -0400152extern struct file_system_type nfs_xdev_fs_type;
David Howellsf7b422b2006-06-09 09:34:33 -0400153#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -0400154extern struct file_system_type nfs4_xdev_fs_type;
155extern struct file_system_type nfs4_referral_fs_type;
David Howellsf7b422b2006-06-09 09:34:33 -0400156#endif
Dominik Hackl4ebd9ab2006-07-02 17:29:26 +0200157
David Howellsf7b422b2006-06-09 09:34:33 -0400158extern struct rpc_stat nfs_rpcstat;
Dominik Hackl4ebd9ab2006-07-02 17:29:26 +0200159
David Howellsf7b422b2006-06-09 09:34:33 -0400160extern int __init register_nfs_fs(void);
161extern void __exit unregister_nfs_fs(void);
Steve Dicksonef818a22007-11-08 04:05:04 -0500162extern void nfs_sb_active(struct nfs_server *server);
163extern void nfs_sb_deactive(struct nfs_server *server);
David Howellsf7b422b2006-06-09 09:34:33 -0400164
165/* namespace.c */
David Howells54ceac42006-08-22 20:06:13 -0400166extern char *nfs_path(const char *base,
167 const struct dentry *droot,
168 const struct dentry *dentry,
David Howellsf7b422b2006-06-09 09:34:33 -0400169 char *buffer, ssize_t buflen);
170
David Howells54ceac42006-08-22 20:06:13 -0400171/* getroot.c */
172extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
David Howells7d4e2742006-08-22 20:06:07 -0400173#ifdef CONFIG_NFS_V4
David Howells54ceac42006-08-22 20:06:13 -0400174extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
175
176extern int nfs4_path_walk(struct nfs_server *server,
177 struct nfs_fh *mntfh,
178 const char *path);
David Howells7d4e2742006-08-22 20:06:07 -0400179#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400180
181/*
182 * Determine the device name as a string
183 */
184static inline char *nfs_devname(const struct vfsmount *mnt_parent,
David Howells54ceac42006-08-22 20:06:13 -0400185 const struct dentry *dentry,
186 char *buffer, ssize_t buflen)
David Howellsf7b422b2006-06-09 09:34:33 -0400187{
David Howells54ceac42006-08-22 20:06:13 -0400188 return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
189 dentry, buffer, buflen);
David Howellsf7b422b2006-06-09 09:34:33 -0400190}
191
192/*
193 * Determine the actual block size (and log2 thereof)
194 */
195static inline
196unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
197{
198 /* make sure blocksize is a power of two */
199 if ((bsize & (bsize - 1)) || nrbitsp) {
200 unsigned char nrbits;
201
202 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
203 ;
204 bsize = 1 << nrbits;
205 if (nrbitsp)
206 *nrbitsp = nrbits;
207 }
208
209 return bsize;
210}
211
212/*
213 * Calculate the number of 512byte blocks used.
214 */
Chuck Lever9eaa67c2007-07-01 12:12:19 -0400215static inline blkcnt_t nfs_calc_block_size(u64 tsize)
David Howellsf7b422b2006-06-09 09:34:33 -0400216{
Chuck Lever9eaa67c2007-07-01 12:12:19 -0400217 blkcnt_t used = (tsize + 511) >> 9;
David Howellsf7b422b2006-06-09 09:34:33 -0400218 return (used > ULONG_MAX) ? ULONG_MAX : used;
219}
220
221/*
222 * Compute and set NFS server blocksize
223 */
224static inline
225unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
226{
227 if (bsize < NFS_MIN_FILE_IO_SIZE)
228 bsize = NFS_DEF_FILE_IO_SIZE;
229 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
230 bsize = NFS_MAX_FILE_IO_SIZE;
231
232 return nfs_block_bits(bsize, nrbitsp);
233}
234
235/*
236 * Determine the maximum file size for a superblock
237 */
238static inline
239void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
240{
241 sb->s_maxbytes = (loff_t)maxfilesize;
242 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
243 sb->s_maxbytes = MAX_LFS_FILESIZE;
244}
Trond Myklebust49a70f22006-12-05 00:35:38 -0500245
246/*
247 * Determine the number of bytes of data the page contains
248 */
249static inline
250unsigned int nfs_page_length(struct page *page)
251{
252 loff_t i_size = i_size_read(page->mapping->host);
253
254 if (i_size > 0) {
255 pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
256 if (page->index < end_index)
257 return PAGE_CACHE_SIZE;
258 if (page->index == end_index)
259 return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
260 }
261 return 0;
262}
Trond Myklebust8d5658c2007-04-10 09:26:35 -0400263
264/*
265 * Determine the number of pages in an array of length 'len' and
266 * with a base offset of 'base'
267 */
268static inline
269unsigned int nfs_page_array_len(unsigned int base, size_t len)
270{
271 return ((unsigned long)len + (unsigned long)base +
272 PAGE_SIZE - 1) >> PAGE_SHIFT;
273}
274