blob: ac370d5d44947d7b2fc9102c1a4fa02daf876f6b [file] [log] [blame]
David Howellsf7b422b2006-06-09 09:34:33 -04001/*
2 * NFS internal definitions
3 */
4
5#include <linux/mount.h>
6
7struct nfs_clone_mount {
8 const struct super_block *sb;
9 const struct dentry *dentry;
10 struct nfs_fh *fh;
11 struct nfs_fattr *fattr;
12 char *hostname;
13 char *mnt_path;
14 struct sockaddr_in *addr;
15 rpc_authflavor_t authflavor;
16};
17
David Howells24c8dbb2006-08-22 20:06:10 -040018/* client.c */
19extern void nfs_put_client(struct nfs_client *);
20extern struct nfs_client *nfs_find_client(const struct sockaddr_in *, int);
21extern struct nfs_client *nfs_get_client(const char *, const struct sockaddr_in *, int);
22extern void nfs_mark_client_ready(struct nfs_client *, int);
23
David Howells7d4e2742006-08-22 20:06:07 -040024/* nfs4namespace.c */
David Howellsf7b422b2006-06-09 09:34:33 -040025#ifdef CONFIG_NFS_V4
26extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
27#else
28static inline
29struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
30{
31 return ERR_PTR(-ENOENT);
32}
33#endif
34
35/* callback_xdr.c */
36extern struct svc_version nfs4_callback_version1;
37
38/* pagelist.c */
39extern int __init nfs_init_nfspagecache(void);
David Brownell266bee82006-06-27 12:59:15 -070040extern void nfs_destroy_nfspagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -040041extern int __init nfs_init_readpagecache(void);
David Brownell266bee82006-06-27 12:59:15 -070042extern void nfs_destroy_readpagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -040043extern int __init nfs_init_writepagecache(void);
David Brownell266bee82006-06-27 12:59:15 -070044extern void nfs_destroy_writepagecache(void);
David Howellsf7b422b2006-06-09 09:34:33 -040045
46#ifdef CONFIG_NFS_DIRECTIO
47extern int __init nfs_init_directcache(void);
David Brownell266bee82006-06-27 12:59:15 -070048extern void nfs_destroy_directcache(void);
David Howellsf7b422b2006-06-09 09:34:33 -040049#else
50#define nfs_init_directcache() (0)
51#define nfs_destroy_directcache() do {} while(0)
52#endif
53
54/* nfs2xdr.c */
David Howells7d4e2742006-08-22 20:06:07 -040055extern int nfs_stat_to_errno(int);
David Howellsf7b422b2006-06-09 09:34:33 -040056extern struct rpc_procinfo nfs_procedures[];
57extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
58
59/* nfs3xdr.c */
60extern struct rpc_procinfo nfs3_procedures[];
61extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
62
63/* nfs4xdr.c */
David Howells7d4e2742006-08-22 20:06:07 -040064#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -040065extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
David Howells7d4e2742006-08-22 20:06:07 -040066#endif
David Howellsf7b422b2006-06-09 09:34:33 -040067
68/* nfs4proc.c */
Andrew Mortond75d5412006-06-25 02:41:26 -070069#ifdef CONFIG_NFS_V4
David Howellsf7b422b2006-06-09 09:34:33 -040070extern struct rpc_procinfo nfs4_procedures[];
71
72extern int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry,
73 struct nfs4_fs_locations *fs_locations,
74 struct page *page);
Andrew Mortond75d5412006-06-25 02:41:26 -070075#endif
David Howellsf7b422b2006-06-09 09:34:33 -040076
Trond Myklebust979df722006-07-25 11:28:19 -040077/* dir.c */
78extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
79
David Howellsf7b422b2006-06-09 09:34:33 -040080/* inode.c */
81extern struct inode *nfs_alloc_inode(struct super_block *sb);
82extern void nfs_destroy_inode(struct inode *);
83extern int nfs_write_inode(struct inode *,int);
84extern void nfs_clear_inode(struct inode *);
85#ifdef CONFIG_NFS_V4
86extern void nfs4_clear_inode(struct inode *);
87#endif
88
89/* super.c */
90extern struct file_system_type nfs_referral_nfs4_fs_type;
91extern struct file_system_type clone_nfs_fs_type;
92#ifdef CONFIG_NFS_V4
93extern struct file_system_type clone_nfs4_fs_type;
94#endif
Dominik Hackl4ebd9ab2006-07-02 17:29:26 +020095
David Howellsf7b422b2006-06-09 09:34:33 -040096extern struct rpc_stat nfs_rpcstat;
Dominik Hackl4ebd9ab2006-07-02 17:29:26 +020097
David Howellsf7b422b2006-06-09 09:34:33 -040098extern int __init register_nfs_fs(void);
99extern void __exit unregister_nfs_fs(void);
100
101/* namespace.c */
102extern char *nfs_path(const char *base, const struct dentry *dentry,
103 char *buffer, ssize_t buflen);
104
105/*
106 * Determine the mount path as a string
107 */
David Howells7d4e2742006-08-22 20:06:07 -0400108#ifdef CONFIG_NFS_V4
Andrew Mortond75d5412006-06-25 02:41:26 -0700109static inline char *
110nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen)
David Howellsf7b422b2006-06-09 09:34:33 -0400111{
112 return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen);
David Howellsf7b422b2006-06-09 09:34:33 -0400113}
David Howells7d4e2742006-08-22 20:06:07 -0400114#endif
David Howellsf7b422b2006-06-09 09:34:33 -0400115
116/*
117 * Determine the device name as a string
118 */
119static inline char *nfs_devname(const struct vfsmount *mnt_parent,
120 const struct dentry *dentry,
121 char *buffer, ssize_t buflen)
122{
123 return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen);
124}
125
126/*
127 * Determine the actual block size (and log2 thereof)
128 */
129static inline
130unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
131{
132 /* make sure blocksize is a power of two */
133 if ((bsize & (bsize - 1)) || nrbitsp) {
134 unsigned char nrbits;
135
136 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
137 ;
138 bsize = 1 << nrbits;
139 if (nrbitsp)
140 *nrbitsp = nrbits;
141 }
142
143 return bsize;
144}
145
146/*
147 * Calculate the number of 512byte blocks used.
148 */
149static inline unsigned long nfs_calc_block_size(u64 tsize)
150{
151 loff_t used = (tsize + 511) >> 9;
152 return (used > ULONG_MAX) ? ULONG_MAX : used;
153}
154
155/*
156 * Compute and set NFS server blocksize
157 */
158static inline
159unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
160{
161 if (bsize < NFS_MIN_FILE_IO_SIZE)
162 bsize = NFS_DEF_FILE_IO_SIZE;
163 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
164 bsize = NFS_MAX_FILE_IO_SIZE;
165
166 return nfs_block_bits(bsize, nrbitsp);
167}
168
169/*
170 * Determine the maximum file size for a superblock
171 */
172static inline
173void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
174{
175 sb->s_maxbytes = (loff_t)maxfilesize;
176 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
177 sb->s_maxbytes = MAX_LFS_FILESIZE;
178}
179
180/*
181 * Check if the string represents a "valid" IPv4 address
182 */
183static inline int valid_ipaddr4(const char *buf)
184{
185 int rc, count, in[4];
186
187 rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
188 if (rc != 4)
189 return -EINVAL;
190 for (count = 0; count < 4; count++) {
191 if (in[count] > 255)
192 return -EINVAL;
193 }
194 return 0;
195}