]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/nfs/internal.h
NFS: Display local caching state
[mirror_ubuntu-bionic-kernel.git] / fs / nfs / internal.h
CommitLineData
f7b422b1
DH
1/*
2 * NFS internal definitions
3 */
4
5#include <linux/mount.h>
f9c3a380 6#include <linux/security.h>
f7b422b1 7
08734048
DH
8#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
9
54ceac45 10struct nfs_string;
54ceac45
DH
11
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.
17 */
18#define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
19
f7b422b1
DH
20struct 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;
6677d095
CL
27 struct sockaddr *addr;
28 size_t addrlen;
f7b422b1
DH
29 rpc_authflavor_t authflavor;
30};
31
6b18eaa0
TT
32/*
33 * In-kernel mount arguments
34 */
35struct 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;
08734048 46 char *fscache_uniq;
6b18eaa0
TT
47
48 struct {
4c568017
CL
49 struct sockaddr_storage address;
50 size_t addrlen;
6b18eaa0 51 char *hostname;
78fa701f 52 u32 version;
6b18eaa0 53 unsigned short port;
78fa701f 54 unsigned short protocol;
6b18eaa0
TT
55 } mount_server;
56
57 struct {
4c568017
CL
58 struct sockaddr_storage address;
59 size_t addrlen;
6b18eaa0
TT
60 char *hostname;
61 char *export_path;
f22d6d79 62 unsigned short port;
78fa701f 63 unsigned short protocol;
6b18eaa0 64 } nfs_server;
f9c3a380
EP
65
66 struct security_mnt_opts lsm_opts;
6b18eaa0
TT
67};
68
146ec944 69/* mount_clnt.c */
c5d120f8
CL
70struct 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;
50a737f8 78 int noresvport;
c5d120f8
CL
79};
80
81extern int nfs_mount(struct nfs_mount_request *info);
146ec944 82
24c8dbbb 83/* client.c */
54ceac45
DH
84extern struct rpc_program nfs_program;
85
24c8dbbb 86extern void nfs_put_client(struct nfs_client *);
ff052645 87extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
3fbd67ad 88extern struct nfs_client *nfs_find_client_next(struct nfs_client *);
2283f8d6
TT
89extern struct nfs_server *nfs_create_server(
90 const struct nfs_parsed_mount_data *,
91 struct nfs_fh *);
91ea40b9
TT
92extern struct nfs_server *nfs4_create_server(
93 const struct nfs_parsed_mount_data *,
94 struct nfs_fh *);
54ceac45
DH
95extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
96 struct nfs_fh *);
97extern void nfs_free_server(struct nfs_server *server);
98extern struct nfs_server *nfs_clone_server(struct nfs_server *,
99 struct nfs_fh *,
100 struct nfs_fattr *);
6aaca566
DH
101#ifdef CONFIG_PROC_FS
102extern int __init nfs_fs_proc_init(void);
103extern void nfs_fs_proc_exit(void);
104#else
105static inline int nfs_fs_proc_init(void)
106{
107 return 0;
108}
109static inline void nfs_fs_proc_exit(void)
110{
111}
112#endif
24c8dbbb 113
7d4e2747 114/* nfs4namespace.c */
f7b422b1
DH
115#ifdef CONFIG_NFS_V4
116extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
117#else
118static inline
119struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
120{
121 return ERR_PTR(-ENOENT);
122}
123#endif
124
125/* callback_xdr.c */
126extern struct svc_version nfs4_callback_version1;
127
128/* pagelist.c */
129extern int __init nfs_init_nfspagecache(void);
266bee88 130extern void nfs_destroy_nfspagecache(void);
f7b422b1 131extern int __init nfs_init_readpagecache(void);
266bee88 132extern void nfs_destroy_readpagecache(void);
f7b422b1 133extern int __init nfs_init_writepagecache(void);
266bee88 134extern void nfs_destroy_writepagecache(void);
f7b422b1 135
f7b422b1 136extern int __init nfs_init_directcache(void);
266bee88 137extern void nfs_destroy_directcache(void);
f7b422b1
DH
138
139/* nfs2xdr.c */
7d4e2747 140extern int nfs_stat_to_errno(int);
f7b422b1 141extern struct rpc_procinfo nfs_procedures[];
0dbb4c67 142extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
f7b422b1
DH
143
144/* nfs3xdr.c */
145extern struct rpc_procinfo nfs3_procedures[];
0dbb4c67 146extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
f7b422b1
DH
147
148/* nfs4xdr.c */
7d4e2747 149#ifdef CONFIG_NFS_V4
0dbb4c67 150extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
7d4e2747 151#endif
f7b422b1
DH
152
153/* nfs4proc.c */
d75d5414 154#ifdef CONFIG_NFS_V4
f7b422b1 155extern struct rpc_procinfo nfs4_procedures[];
d75d5414 156#endif
f7b422b1 157
7fe5c398
TM
158/* proc.c */
159void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
160
979df72e
TM
161/* dir.c */
162extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
163
f7b422b1 164/* inode.c */
5746006f 165extern struct workqueue_struct *nfsiod_workqueue;
f7b422b1
DH
166extern struct inode *nfs_alloc_inode(struct super_block *sb);
167extern void nfs_destroy_inode(struct inode *);
168extern int nfs_write_inode(struct inode *,int);
169extern void nfs_clear_inode(struct inode *);
170#ifdef CONFIG_NFS_V4
171extern void nfs4_clear_inode(struct inode *);
172#endif
f41f7418 173void nfs_zap_acl_cache(struct inode *inode);
72cb77f4 174extern int nfs_wait_bit_killable(void *word);
f7b422b1
DH
175
176/* super.c */
ea31a443 177void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *);
54ceac45 178extern struct file_system_type nfs_xdev_fs_type;
f7b422b1 179#ifdef CONFIG_NFS_V4
54ceac45
DH
180extern struct file_system_type nfs4_xdev_fs_type;
181extern struct file_system_type nfs4_referral_fs_type;
f7b422b1 182#endif
4ebd9ab3 183
f7b422b1 184extern struct rpc_stat nfs_rpcstat;
4ebd9ab3 185
f7b422b1
DH
186extern int __init register_nfs_fs(void);
187extern void __exit unregister_nfs_fs(void);
1daef0a8
TM
188extern void nfs_sb_active(struct super_block *sb);
189extern void nfs_sb_deactive(struct super_block *sb);
f7b422b1
DH
190
191/* namespace.c */
54ceac45
DH
192extern char *nfs_path(const char *base,
193 const struct dentry *droot,
194 const struct dentry *dentry,
f7b422b1
DH
195 char *buffer, ssize_t buflen);
196
54ceac45
DH
197/* getroot.c */
198extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
7d4e2747 199#ifdef CONFIG_NFS_V4
54ceac45
DH
200extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
201
202extern int nfs4_path_walk(struct nfs_server *server,
203 struct nfs_fh *mntfh,
204 const char *path);
7d4e2747 205#endif
f7b422b1
DH
206
207/*
208 * Determine the device name as a string
209 */
210static inline char *nfs_devname(const struct vfsmount *mnt_parent,
54ceac45
DH
211 const struct dentry *dentry,
212 char *buffer, ssize_t buflen)
f7b422b1 213{
54ceac45
DH
214 return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
215 dentry, buffer, buflen);
f7b422b1
DH
216}
217
218/*
219 * Determine the actual block size (and log2 thereof)
220 */
221static inline
222unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
223{
224 /* make sure blocksize is a power of two */
225 if ((bsize & (bsize - 1)) || nrbitsp) {
226 unsigned char nrbits;
227
228 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
229 ;
230 bsize = 1 << nrbits;
231 if (nrbitsp)
232 *nrbitsp = nrbits;
233 }
234
235 return bsize;
236}
237
238/*
239 * Calculate the number of 512byte blocks used.
240 */
9eaa67c6 241static inline blkcnt_t nfs_calc_block_size(u64 tsize)
f7b422b1 242{
9eaa67c6 243 blkcnt_t used = (tsize + 511) >> 9;
f7b422b1
DH
244 return (used > ULONG_MAX) ? ULONG_MAX : used;
245}
246
247/*
248 * Compute and set NFS server blocksize
249 */
250static inline
251unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
252{
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;
257
258 return nfs_block_bits(bsize, nrbitsp);
259}
260
261/*
262 * Determine the maximum file size for a superblock
263 */
264static inline
265void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
266{
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;
270}
49a70f27
TM
271
272/*
273 * Determine the number of bytes of data the page contains
274 */
275static inline
276unsigned int nfs_page_length(struct page *page)
277{
278 loff_t i_size = i_size_read(page->mapping->host);
279
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;
286 }
287 return 0;
288}
8d5658c9
TM
289
290/*
291 * Determine the number of pages in an array of length 'len' and
292 * with a base offset of 'base'
293 */
294static inline
295unsigned int nfs_page_array_len(unsigned int base, size_t len)
296{
297 return ((unsigned long)len + (unsigned long)base +
298 PAGE_SIZE - 1) >> PAGE_SHIFT;
299}
300
ea31a443 301#define IPV6_SCOPE_DELIMITER '%'
f0c92925
BF
302
303/*
304 * Set the port number in an address. Be agnostic about the address
305 * family.
306 */
307static inline void nfs_set_port(struct sockaddr *sap, unsigned short port)
308{
456018d7
BF
309 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
310 struct sockaddr_in6 *ap6 = (struct sockaddr_in6 *)sap;
311
f0c92925 312 switch (sap->sa_family) {
456018d7
BF
313 case AF_INET:
314 ap->sin_port = htons(port);
315 break;
316 case AF_INET6:
317 ap6->sin6_port = htons(port);
318 break;
f0c92925
BF
319 }
320}