NFS: Define and create superblock-level objects
[linux-2.6/verdex.git] / fs / nfs / internal.h
blob013070000c38e65fa47eb1d081750a87fc8b3b9c
1 /*
2 * NFS internal definitions
3 */
5 #include <linux/mount.h>
6 #include <linux/security.h>
8 #define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
10 struct nfs_string;
12 /* Maximum number of readahead requests
13 * FIXME: this should really be a sysctl so that users may tune it to suit
14 * their needs. People that do NFS over a slow network, might for
15 * instance want to reduce it to something closer to 1 for improved
16 * interactive response.
18 #define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
20 struct nfs_clone_mount {
21 const struct super_block *sb;
22 const struct dentry *dentry;
23 struct nfs_fh *fh;
24 struct nfs_fattr *fattr;
25 char *hostname;
26 char *mnt_path;
27 struct sockaddr *addr;
28 size_t addrlen;
29 rpc_authflavor_t authflavor;
33 * In-kernel mount arguments
35 struct nfs_parsed_mount_data {
36 int flags;
37 int rsize, wsize;
38 int timeo, retrans;
39 int acregmin, acregmax,
40 acdirmin, acdirmax;
41 int namlen;
42 unsigned int bsize;
43 unsigned int auth_flavor_len;
44 rpc_authflavor_t auth_flavors[1];
45 char *client_address;
46 char *fscache_uniq;
48 struct {
49 struct sockaddr_storage address;
50 size_t addrlen;
51 char *hostname;
52 u32 version;
53 unsigned short port;
54 unsigned short protocol;
55 } mount_server;
57 struct {
58 struct sockaddr_storage address;
59 size_t addrlen;
60 char *hostname;
61 char *export_path;
62 unsigned short port;
63 unsigned short protocol;
64 } nfs_server;
66 struct security_mnt_opts lsm_opts;
69 /* mount_clnt.c */
70 struct nfs_mount_request {
71 struct sockaddr *sap;
72 size_t salen;
73 char *hostname;
74 char *dirpath;
75 u32 version;
76 unsigned short protocol;
77 struct nfs_fh *fh;
78 int noresvport;
81 extern int nfs_mount(struct nfs_mount_request *info);
83 /* client.c */
84 extern struct rpc_program nfs_program;
86 extern void nfs_put_client(struct nfs_client *);
87 extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
88 extern struct nfs_client *nfs_find_client_next(struct nfs_client *);
89 extern struct nfs_server *nfs_create_server(
90 const struct nfs_parsed_mount_data *,
91 struct nfs_fh *);
92 extern struct nfs_server *nfs4_create_server(
93 const struct nfs_parsed_mount_data *,
94 struct nfs_fh *);
95 extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
96 struct nfs_fh *);
97 extern void nfs_free_server(struct nfs_server *server);
98 extern struct nfs_server *nfs_clone_server(struct nfs_server *,
99 struct nfs_fh *,
100 struct nfs_fattr *);
101 #ifdef CONFIG_PROC_FS
102 extern int __init nfs_fs_proc_init(void);
103 extern void nfs_fs_proc_exit(void);
104 #else
105 static inline int nfs_fs_proc_init(void)
107 return 0;
109 static inline void nfs_fs_proc_exit(void)
112 #endif
114 /* nfs4namespace.c */
115 #ifdef CONFIG_NFS_V4
116 extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
117 #else
118 static inline
119 struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
121 return ERR_PTR(-ENOENT);
123 #endif
125 /* callback_xdr.c */
126 extern struct svc_version nfs4_callback_version1;
128 /* pagelist.c */
129 extern int __init nfs_init_nfspagecache(void);
130 extern void nfs_destroy_nfspagecache(void);
131 extern int __init nfs_init_readpagecache(void);
132 extern void nfs_destroy_readpagecache(void);
133 extern int __init nfs_init_writepagecache(void);
134 extern void nfs_destroy_writepagecache(void);
136 extern int __init nfs_init_directcache(void);
137 extern void nfs_destroy_directcache(void);
139 /* nfs2xdr.c */
140 extern int nfs_stat_to_errno(int);
141 extern struct rpc_procinfo nfs_procedures[];
142 extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
144 /* nfs3xdr.c */
145 extern struct rpc_procinfo nfs3_procedures[];
146 extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
148 /* nfs4xdr.c */
149 #ifdef CONFIG_NFS_V4
150 extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
151 #endif
153 /* nfs4proc.c */
154 #ifdef CONFIG_NFS_V4
155 extern struct rpc_procinfo nfs4_procedures[];
156 #endif
158 /* proc.c */
159 void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
161 /* dir.c */
162 extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
164 /* inode.c */
165 extern struct workqueue_struct *nfsiod_workqueue;
166 extern struct inode *nfs_alloc_inode(struct super_block *sb);
167 extern void nfs_destroy_inode(struct inode *);
168 extern int nfs_write_inode(struct inode *,int);
169 extern void nfs_clear_inode(struct inode *);
170 #ifdef CONFIG_NFS_V4
171 extern void nfs4_clear_inode(struct inode *);
172 #endif
173 void nfs_zap_acl_cache(struct inode *inode);
174 extern int nfs_wait_bit_killable(void *word);
176 /* super.c */
177 void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *);
178 extern struct file_system_type nfs_xdev_fs_type;
179 #ifdef CONFIG_NFS_V4
180 extern struct file_system_type nfs4_xdev_fs_type;
181 extern struct file_system_type nfs4_referral_fs_type;
182 #endif
184 extern struct rpc_stat nfs_rpcstat;
186 extern int __init register_nfs_fs(void);
187 extern void __exit unregister_nfs_fs(void);
188 extern void nfs_sb_active(struct super_block *sb);
189 extern void nfs_sb_deactive(struct super_block *sb);
191 /* namespace.c */
192 extern char *nfs_path(const char *base,
193 const struct dentry *droot,
194 const struct dentry *dentry,
195 char *buffer, ssize_t buflen);
197 /* getroot.c */
198 extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
199 #ifdef CONFIG_NFS_V4
200 extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
202 extern int nfs4_path_walk(struct nfs_server *server,
203 struct nfs_fh *mntfh,
204 const char *path);
205 #endif
208 * Determine the device name as a string
210 static inline char *nfs_devname(const struct vfsmount *mnt_parent,
211 const struct dentry *dentry,
212 char *buffer, ssize_t buflen)
214 return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
215 dentry, buffer, buflen);
219 * Determine the actual block size (and log2 thereof)
221 static inline
222 unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
224 /* make sure blocksize is a power of two */
225 if ((bsize & (bsize - 1)) || nrbitsp) {
226 unsigned char nrbits;
228 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
230 bsize = 1 << nrbits;
231 if (nrbitsp)
232 *nrbitsp = nrbits;
235 return bsize;
239 * Calculate the number of 512byte blocks used.
241 static inline blkcnt_t nfs_calc_block_size(u64 tsize)
243 blkcnt_t used = (tsize + 511) >> 9;
244 return (used > ULONG_MAX) ? ULONG_MAX : used;
248 * Compute and set NFS server blocksize
250 static inline
251 unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
253 if (bsize < NFS_MIN_FILE_IO_SIZE)
254 bsize = NFS_DEF_FILE_IO_SIZE;
255 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
256 bsize = NFS_MAX_FILE_IO_SIZE;
258 return nfs_block_bits(bsize, nrbitsp);
262 * Determine the maximum file size for a superblock
264 static inline
265 void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
267 sb->s_maxbytes = (loff_t)maxfilesize;
268 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
269 sb->s_maxbytes = MAX_LFS_FILESIZE;
273 * Determine the number of bytes of data the page contains
275 static inline
276 unsigned int nfs_page_length(struct page *page)
278 loff_t i_size = i_size_read(page->mapping->host);
280 if (i_size > 0) {
281 pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
282 if (page->index < end_index)
283 return PAGE_CACHE_SIZE;
284 if (page->index == end_index)
285 return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
287 return 0;
291 * Determine the number of pages in an array of length 'len' and
292 * with a base offset of 'base'
294 static inline
295 unsigned int nfs_page_array_len(unsigned int base, size_t len)
297 return ((unsigned long)len + (unsigned long)base +
298 PAGE_SIZE - 1) >> PAGE_SHIFT;
301 #define IPV6_SCOPE_DELIMITER '%'
304 * Set the port number in an address. Be agnostic about the address
305 * family.
307 static inline void nfs_set_port(struct sockaddr *sap, unsigned short port)
309 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
310 struct sockaddr_in6 *ap6 = (struct sockaddr_in6 *)sap;
312 switch (sap->sa_family) {
313 case AF_INET:
314 ap->sin_port = htons(port);
315 break;
316 case AF_INET6:
317 ap6->sin6_port = htons(port);
318 break;