NFS: Add dentry materialisation op
[linux-block.git] / fs / nfs / internal.h
CommitLineData
f7b422b1
DH
1/*
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
18/* namespace-nfs4.c */
19#ifdef CONFIG_NFS_V4
20extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
21#else
22static inline
23struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
24{
25 return ERR_PTR(-ENOENT);
26}
27#endif
28
29/* callback_xdr.c */
30extern struct svc_version nfs4_callback_version1;
31
32/* pagelist.c */
33extern int __init nfs_init_nfspagecache(void);
266bee88 34extern void nfs_destroy_nfspagecache(void);
f7b422b1 35extern int __init nfs_init_readpagecache(void);
266bee88 36extern void nfs_destroy_readpagecache(void);
f7b422b1 37extern int __init nfs_init_writepagecache(void);
266bee88 38extern void nfs_destroy_writepagecache(void);
f7b422b1
DH
39
40#ifdef CONFIG_NFS_DIRECTIO
41extern int __init nfs_init_directcache(void);
266bee88 42extern void nfs_destroy_directcache(void);
f7b422b1
DH
43#else
44#define nfs_init_directcache() (0)
45#define nfs_destroy_directcache() do {} while(0)
46#endif
47
48/* nfs2xdr.c */
49extern struct rpc_procinfo nfs_procedures[];
50extern u32 * nfs_decode_dirent(u32 *, struct nfs_entry *, int);
51
52/* nfs3xdr.c */
53extern struct rpc_procinfo nfs3_procedures[];
54extern u32 *nfs3_decode_dirent(u32 *, struct nfs_entry *, int);
55
56/* nfs4xdr.c */
57extern int nfs_stat_to_errno(int);
58extern u32 *nfs4_decode_dirent(u32 *p, struct nfs_entry *entry, int plus);
59
60/* nfs4proc.c */
d75d5414 61#ifdef CONFIG_NFS_V4
f7b422b1
DH
62extern struct rpc_procinfo nfs4_procedures[];
63
64extern int nfs4_proc_fs_locations(struct inode *dir, struct dentry *dentry,
65 struct nfs4_fs_locations *fs_locations,
66 struct page *page);
d75d5414 67#endif
f7b422b1 68
979df72e
TM
69/* dir.c */
70extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
71
f7b422b1
DH
72/* inode.c */
73extern struct inode *nfs_alloc_inode(struct super_block *sb);
74extern void nfs_destroy_inode(struct inode *);
75extern int nfs_write_inode(struct inode *,int);
76extern void nfs_clear_inode(struct inode *);
77#ifdef CONFIG_NFS_V4
78extern void nfs4_clear_inode(struct inode *);
79#endif
80
81/* super.c */
82extern struct file_system_type nfs_referral_nfs4_fs_type;
83extern struct file_system_type clone_nfs_fs_type;
84#ifdef CONFIG_NFS_V4
85extern struct file_system_type clone_nfs4_fs_type;
86#endif
4ebd9ab3 87
f7b422b1 88extern struct rpc_stat nfs_rpcstat;
4ebd9ab3 89
f7b422b1
DH
90extern int __init register_nfs_fs(void);
91extern void __exit unregister_nfs_fs(void);
92
93/* namespace.c */
94extern char *nfs_path(const char *base, const struct dentry *dentry,
95 char *buffer, ssize_t buflen);
96
97/*
98 * Determine the mount path as a string
99 */
d75d5414
AM
100static inline char *
101nfs4_path(const struct dentry *dentry, char *buffer, ssize_t buflen)
f7b422b1 102{
d75d5414 103#ifdef CONFIG_NFS_V4
f7b422b1 104 return nfs_path(NFS_SB(dentry->d_sb)->mnt_path, dentry, buffer, buflen);
d75d5414
AM
105#else
106 return NULL;
107#endif
f7b422b1
DH
108}
109
110/*
111 * Determine the device name as a string
112 */
113static inline char *nfs_devname(const struct vfsmount *mnt_parent,
114 const struct dentry *dentry,
115 char *buffer, ssize_t buflen)
116{
117 return nfs_path(mnt_parent->mnt_devname, dentry, buffer, buflen);
118}
119
120/*
121 * Determine the actual block size (and log2 thereof)
122 */
123static inline
124unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
125{
126 /* make sure blocksize is a power of two */
127 if ((bsize & (bsize - 1)) || nrbitsp) {
128 unsigned char nrbits;
129
130 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
131 ;
132 bsize = 1 << nrbits;
133 if (nrbitsp)
134 *nrbitsp = nrbits;
135 }
136
137 return bsize;
138}
139
140/*
141 * Calculate the number of 512byte blocks used.
142 */
143static inline unsigned long nfs_calc_block_size(u64 tsize)
144{
145 loff_t used = (tsize + 511) >> 9;
146 return (used > ULONG_MAX) ? ULONG_MAX : used;
147}
148
149/*
150 * Compute and set NFS server blocksize
151 */
152static inline
153unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
154{
155 if (bsize < NFS_MIN_FILE_IO_SIZE)
156 bsize = NFS_DEF_FILE_IO_SIZE;
157 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
158 bsize = NFS_MAX_FILE_IO_SIZE;
159
160 return nfs_block_bits(bsize, nrbitsp);
161}
162
163/*
164 * Determine the maximum file size for a superblock
165 */
166static inline
167void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
168{
169 sb->s_maxbytes = (loff_t)maxfilesize;
170 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
171 sb->s_maxbytes = MAX_LFS_FILESIZE;
172}
173
174/*
175 * Check if the string represents a "valid" IPv4 address
176 */
177static inline int valid_ipaddr4(const char *buf)
178{
179 int rc, count, in[4];
180
181 rc = sscanf(buf, "%d.%d.%d.%d", &in[0], &in[1], &in[2], &in[3]);
182 if (rc != 4)
183 return -EINVAL;
184 for (count = 0; count < 4; count++) {
185 if (in[count] > 255)
186 return -EINVAL;
187 }
188 return 0;
189}