NFS: Support non-IPv4 addresses in nfs_parsed_mount_data
[safe/jmp/linux-2.6] / fs / nfs / internal.h
1 /*
2  * NFS internal definitions
3  */
4
5 #include <linux/mount.h>
6
7 struct nfs_string;
8
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
17 struct 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;
24         struct sockaddr *addr;
25         size_t addrlen;
26         rpc_authflavor_t authflavor;
27 };
28
29 /*
30  * In-kernel mount arguments
31  */
32 struct 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_storage address;
46                 size_t                  addrlen;
47                 char                    *hostname;
48                 unsigned int            version;
49                 unsigned short          port;
50                 int                     protocol;
51         } mount_server;
52
53         struct {
54                 struct sockaddr_storage address;
55                 size_t                  addrlen;
56                 char                    *hostname;
57                 char                    *export_path;
58                 int                     protocol;
59         } nfs_server;
60 };
61
62 /* client.c */
63 extern struct rpc_program nfs_program;
64
65 extern void nfs_put_client(struct nfs_client *);
66 extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
67 extern struct nfs_server *nfs_create_server(
68                                         const struct nfs_parsed_mount_data *,
69                                         struct nfs_fh *);
70 extern struct nfs_server *nfs4_create_server(
71                                         const struct nfs_parsed_mount_data *,
72                                         struct nfs_fh *);
73 extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
74                                                       struct nfs_fh *);
75 extern void nfs_free_server(struct nfs_server *server);
76 extern struct nfs_server *nfs_clone_server(struct nfs_server *,
77                                            struct nfs_fh *,
78                                            struct nfs_fattr *);
79 #ifdef CONFIG_PROC_FS
80 extern int __init nfs_fs_proc_init(void);
81 extern void nfs_fs_proc_exit(void);
82 #else
83 static inline int nfs_fs_proc_init(void)
84 {
85         return 0;
86 }
87 static inline void nfs_fs_proc_exit(void)
88 {
89 }
90 #endif
91
92 /* nfs4namespace.c */
93 #ifdef CONFIG_NFS_V4
94 extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
95 #else
96 static inline
97 struct 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 */
104 extern struct svc_version nfs4_callback_version1;
105
106 /* pagelist.c */
107 extern int __init nfs_init_nfspagecache(void);
108 extern void nfs_destroy_nfspagecache(void);
109 extern int __init nfs_init_readpagecache(void);
110 extern void nfs_destroy_readpagecache(void);
111 extern int __init nfs_init_writepagecache(void);
112 extern void nfs_destroy_writepagecache(void);
113
114 #ifdef CONFIG_NFS_DIRECTIO
115 extern int __init nfs_init_directcache(void);
116 extern void nfs_destroy_directcache(void);
117 #else
118 #define nfs_init_directcache() (0)
119 #define nfs_destroy_directcache() do {} while(0)
120 #endif
121
122 /* nfs2xdr.c */
123 extern int nfs_stat_to_errno(int);
124 extern struct rpc_procinfo nfs_procedures[];
125 extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
126
127 /* nfs3xdr.c */
128 extern struct rpc_procinfo nfs3_procedures[];
129 extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
130
131 /* nfs4xdr.c */
132 #ifdef CONFIG_NFS_V4
133 extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
134 #endif
135
136 /* nfs4proc.c */
137 #ifdef CONFIG_NFS_V4
138 extern struct rpc_procinfo nfs4_procedures[];
139 #endif
140
141 /* dir.c */
142 extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
143
144 /* inode.c */
145 extern struct inode *nfs_alloc_inode(struct super_block *sb);
146 extern void nfs_destroy_inode(struct inode *);
147 extern int nfs_write_inode(struct inode *,int);
148 extern void nfs_clear_inode(struct inode *);
149 #ifdef CONFIG_NFS_V4
150 extern void nfs4_clear_inode(struct inode *);
151 #endif
152
153 /* super.c */
154 extern struct file_system_type nfs_xdev_fs_type;
155 #ifdef CONFIG_NFS_V4
156 extern struct file_system_type nfs4_xdev_fs_type;
157 extern struct file_system_type nfs4_referral_fs_type;
158 #endif
159
160 extern struct rpc_stat nfs_rpcstat;
161
162 extern int __init register_nfs_fs(void);
163 extern void __exit unregister_nfs_fs(void);
164 extern void nfs_sb_active(struct nfs_server *server);
165 extern void nfs_sb_deactive(struct nfs_server *server);
166
167 /* namespace.c */
168 extern char *nfs_path(const char *base,
169                       const struct dentry *droot,
170                       const struct dentry *dentry,
171                       char *buffer, ssize_t buflen);
172
173 /* getroot.c */
174 extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
175 #ifdef CONFIG_NFS_V4
176 extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
177
178 extern int nfs4_path_walk(struct nfs_server *server,
179                           struct nfs_fh *mntfh,
180                           const char *path);
181 #endif
182
183 /*
184  * Determine the device name as a string
185  */
186 static inline char *nfs_devname(const struct vfsmount *mnt_parent,
187                                 const struct dentry *dentry,
188                                 char *buffer, ssize_t buflen)
189 {
190         return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
191                         dentry, buffer, buflen);
192 }
193
194 /*
195  * Determine the actual block size (and log2 thereof)
196  */
197 static inline
198 unsigned 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  */
217 static inline blkcnt_t nfs_calc_block_size(u64 tsize)
218 {
219         blkcnt_t used = (tsize + 511) >> 9;
220         return (used > ULONG_MAX) ? ULONG_MAX : used;
221 }
222
223 /*
224  * Compute and set NFS server blocksize
225  */
226 static inline
227 unsigned 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  */
240 static inline
241 void 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 }
247
248 /*
249  * Determine the number of bytes of data the page contains
250  */
251 static inline
252 unsigned 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 }
265
266 /*
267  * Determine the number of pages in an array of length 'len' and
268  * with a base offset of 'base'
269  */
270 static inline
271 unsigned 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