]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - fs/nfs/internal.h
NFS associate sessionid with callback connection
[mirror_ubuntu-bionic-kernel.git] / fs / nfs / internal.h
CommitLineData
f7b422b1
DH
1/*
2 * NFS internal definitions
3 */
4
eedc020e 5#include "nfs4_fs.h"
f7b422b1 6#include <linux/mount.h>
f9c3a380 7#include <linux/security.h>
f7b422b1 8
08734048
DH
9#define NFS_MS_MASK (MS_RDONLY|MS_NOSUID|MS_NODEV|MS_NOEXEC|MS_SYNCHRONOUS)
10
54ceac45 11struct nfs_string;
54ceac45
DH
12
13/* Maximum number of readahead requests
14 * FIXME: this should really be a sysctl so that users may tune it to suit
15 * their needs. People that do NFS over a slow network, might for
16 * instance want to reduce it to something closer to 1 for improved
17 * interactive response.
18 */
19#define NFS_MAX_READAHEAD (RPC_DEF_SLOT_TABLE - 1)
20
eedc020e
AA
21/*
22 * Determine if sessions are in use.
23 */
24static inline int nfs4_has_session(const struct nfs_client *clp)
25{
26#ifdef CONFIG_NFS_V4_1
27 if (clp->cl_session)
28 return 1;
29#endif /* CONFIG_NFS_V4_1 */
30 return 0;
31}
32
d8cb1a7c
AB
33static inline int nfs4_has_persistent_session(const struct nfs_client *clp)
34{
35#ifdef CONFIG_NFS_V4_1
36 if (nfs4_has_session(clp))
37 return (clp->cl_session->flags & SESSION4_PERSIST);
38#endif /* CONFIG_NFS_V4_1 */
39 return 0;
40}
41
f7b422b1
DH
42struct nfs_clone_mount {
43 const struct super_block *sb;
44 const struct dentry *dentry;
45 struct nfs_fh *fh;
46 struct nfs_fattr *fattr;
47 char *hostname;
48 char *mnt_path;
6677d095
CL
49 struct sockaddr *addr;
50 size_t addrlen;
f7b422b1
DH
51 rpc_authflavor_t authflavor;
52};
53
a14017db
CL
54/*
55 * Note: RFC 1813 doesn't limit the number of auth flavors that
56 * a server can return, so make something up.
57 */
58#define NFS_MAX_SECFLAVORS (12)
59
4cfd74fc
CL
60/*
61 * Value used if the user did not specify a port value.
62 */
63#define NFS_UNSPEC_PORT (-1)
64
56e4ebf8
BS
65/*
66 * Maximum number of pages that readdir can use for creating
67 * a vmapped array of pages.
68 */
69#define NFS_MAX_READDIR_PAGES 8
70
6b18eaa0
TT
71/*
72 * In-kernel mount arguments
73 */
74struct nfs_parsed_mount_data {
75 int flags;
76 int rsize, wsize;
77 int timeo, retrans;
78 int acregmin, acregmax,
79 acdirmin, acdirmax;
80 int namlen;
b797cac7 81 unsigned int options;
6b18eaa0
TT
82 unsigned int bsize;
83 unsigned int auth_flavor_len;
84 rpc_authflavor_t auth_flavors[1];
85 char *client_address;
764302cc 86 unsigned int version;
3fd5be9e 87 unsigned int minorversion;
08734048 88 char *fscache_uniq;
6b18eaa0
TT
89
90 struct {
4c568017
CL
91 struct sockaddr_storage address;
92 size_t addrlen;
6b18eaa0 93 char *hostname;
78fa701f 94 u32 version;
4cfd74fc 95 int port;
78fa701f 96 unsigned short protocol;
6b18eaa0
TT
97 } mount_server;
98
99 struct {
4c568017
CL
100 struct sockaddr_storage address;
101 size_t addrlen;
6b18eaa0
TT
102 char *hostname;
103 char *export_path;
4cfd74fc 104 int port;
78fa701f 105 unsigned short protocol;
6b18eaa0 106 } nfs_server;
f9c3a380
EP
107
108 struct security_mnt_opts lsm_opts;
6b18eaa0
TT
109};
110
146ec944 111/* mount_clnt.c */
c5d120f8
CL
112struct nfs_mount_request {
113 struct sockaddr *sap;
114 size_t salen;
115 char *hostname;
116 char *dirpath;
117 u32 version;
118 unsigned short protocol;
119 struct nfs_fh *fh;
50a737f8 120 int noresvport;
8e02f6b9
CL
121 unsigned int *auth_flav_len;
122 rpc_authflavor_t *auth_flavs;
c5d120f8
CL
123};
124
125extern int nfs_mount(struct nfs_mount_request *info);
0b524123 126extern void nfs_umount(const struct nfs_mount_request *info);
146ec944 127
24c8dbbb 128/* client.c */
54ceac45
DH
129extern struct rpc_program nfs_program;
130
f4eecd5d 131extern void nfs_cleanup_cb_ident_idr(void);
24c8dbbb 132extern void nfs_put_client(struct nfs_client *);
ff052645 133extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
3fbd67ad 134extern struct nfs_client *nfs_find_client_next(struct nfs_client *);
2283f8d6
TT
135extern struct nfs_server *nfs_create_server(
136 const struct nfs_parsed_mount_data *,
137 struct nfs_fh *);
91ea40b9
TT
138extern struct nfs_server *nfs4_create_server(
139 const struct nfs_parsed_mount_data *,
140 struct nfs_fh *);
54ceac45
DH
141extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
142 struct nfs_fh *);
143extern void nfs_free_server(struct nfs_server *server);
144extern struct nfs_server *nfs_clone_server(struct nfs_server *,
145 struct nfs_fh *,
146 struct nfs_fattr *);
76db6d95 147extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
008f55d0 148extern int nfs4_check_client_ready(struct nfs_client *clp);
6aaca566
DH
149#ifdef CONFIG_PROC_FS
150extern int __init nfs_fs_proc_init(void);
151extern void nfs_fs_proc_exit(void);
152#else
153static inline int nfs_fs_proc_init(void)
154{
155 return 0;
156}
157static inline void nfs_fs_proc_exit(void)
158{
159}
160#endif
24c8dbbb 161
7d4e2747 162/* nfs4namespace.c */
f7b422b1
DH
163#ifdef CONFIG_NFS_V4
164extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
165#else
166static inline
167struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
168{
169 return ERR_PTR(-ENOENT);
170}
171#endif
172
173/* callback_xdr.c */
174extern struct svc_version nfs4_callback_version1;
07bccc2d 175extern struct svc_version nfs4_callback_version4;
f7b422b1
DH
176
177/* pagelist.c */
178extern int __init nfs_init_nfspagecache(void);
266bee88 179extern void nfs_destroy_nfspagecache(void);
f7b422b1 180extern int __init nfs_init_readpagecache(void);
266bee88 181extern void nfs_destroy_readpagecache(void);
f7b422b1 182extern int __init nfs_init_writepagecache(void);
266bee88 183extern void nfs_destroy_writepagecache(void);
f7b422b1 184
f7b422b1 185extern int __init nfs_init_directcache(void);
266bee88 186extern void nfs_destroy_directcache(void);
f7b422b1
DH
187
188/* nfs2xdr.c */
85828493 189extern int nfs_stat_to_errno(enum nfs_stat);
f7b422b1 190extern struct rpc_procinfo nfs_procedures[];
573c4e1e
CL
191extern int nfs2_decode_dirent(struct xdr_stream *,
192 struct nfs_entry *, int);
f7b422b1
DH
193
194/* nfs3xdr.c */
195extern struct rpc_procinfo nfs3_procedures[];
573c4e1e
CL
196extern int nfs3_decode_dirent(struct xdr_stream *,
197 struct nfs_entry *, int);
f7b422b1
DH
198
199/* nfs4xdr.c */
7d4e2747 200#ifdef CONFIG_NFS_V4
573c4e1e
CL
201extern int nfs4_decode_dirent(struct xdr_stream *,
202 struct nfs_entry *, int);
7d4e2747 203#endif
2449ea2e
AB
204#ifdef CONFIG_NFS_V4_1
205extern const u32 nfs41_maxread_overhead;
206extern const u32 nfs41_maxwrite_overhead;
207#endif
f7b422b1
DH
208
209/* nfs4proc.c */
d75d5414 210#ifdef CONFIG_NFS_V4
f7b422b1 211extern struct rpc_procinfo nfs4_procedures[];
d75d5414 212#endif
f7b422b1 213
7fe5c398
TM
214/* proc.c */
215void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
216
979df72e 217/* dir.c */
7f8275d0
DC
218extern int nfs_access_cache_shrinker(struct shrinker *shrink,
219 int nr_to_scan, gfp_t gfp_mask);
979df72e 220
f7b422b1 221/* inode.c */
5746006f 222extern struct workqueue_struct *nfsiod_workqueue;
f7b422b1
DH
223extern struct inode *nfs_alloc_inode(struct super_block *sb);
224extern void nfs_destroy_inode(struct inode *);
a9185b41 225extern int nfs_write_inode(struct inode *, struct writeback_control *);
b57922d9 226extern void nfs_evict_inode(struct inode *);
f7b422b1 227#ifdef CONFIG_NFS_V4
b57922d9 228extern void nfs4_evict_inode(struct inode *);
f7b422b1 229#endif
f41f7418 230void nfs_zap_acl_cache(struct inode *inode);
72cb77f4 231extern int nfs_wait_bit_killable(void *word);
f7b422b1
DH
232
233/* super.c */
54ceac45 234extern struct file_system_type nfs_xdev_fs_type;
f7b422b1 235#ifdef CONFIG_NFS_V4
54ceac45
DH
236extern struct file_system_type nfs4_xdev_fs_type;
237extern struct file_system_type nfs4_referral_fs_type;
f7b422b1 238#endif
4ebd9ab3 239
f7b422b1 240extern struct rpc_stat nfs_rpcstat;
4ebd9ab3 241
f7b422b1
DH
242extern int __init register_nfs_fs(void);
243extern void __exit unregister_nfs_fs(void);
1daef0a8
TM
244extern void nfs_sb_active(struct super_block *sb);
245extern void nfs_sb_deactive(struct super_block *sb);
f7b422b1
DH
246
247/* namespace.c */
54ceac45
DH
248extern char *nfs_path(const char *base,
249 const struct dentry *droot,
250 const struct dentry *dentry,
f7b422b1
DH
251 char *buffer, ssize_t buflen);
252
54ceac45
DH
253/* getroot.c */
254extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
7d4e2747 255#ifdef CONFIG_NFS_V4
54ceac45
DH
256extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
257
815409d2 258extern int nfs4_get_rootfh(struct nfs_server *server, struct nfs_fh *mntfh);
7d4e2747 259#endif
f7b422b1 260
f11c88af
AA
261/* read.c */
262extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
263
def6ed7e
AA
264/* write.c */
265extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
074cc1de
TM
266#ifdef CONFIG_MIGRATION
267extern int nfs_migrate_page(struct address_space *,
268 struct page *, struct page *);
269#else
270#define nfs_migrate_page NULL
271#endif
def6ed7e 272
cccef3b9
AA
273/* nfs4proc.c */
274extern int _nfs4_call_sync(struct nfs_server *server,
275 struct rpc_message *msg,
276 struct nfs4_sequence_args *args,
277 struct nfs4_sequence_res *res,
278 int cache_reply);
279extern int _nfs4_call_sync_session(struct nfs_server *server,
280 struct rpc_message *msg,
281 struct nfs4_sequence_args *args,
282 struct nfs4_sequence_res *res,
283 int cache_reply);
284
f7b422b1
DH
285/*
286 * Determine the device name as a string
287 */
288static inline char *nfs_devname(const struct vfsmount *mnt_parent,
54ceac45
DH
289 const struct dentry *dentry,
290 char *buffer, ssize_t buflen)
f7b422b1 291{
54ceac45
DH
292 return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
293 dentry, buffer, buflen);
f7b422b1
DH
294}
295
296/*
297 * Determine the actual block size (and log2 thereof)
298 */
299static inline
300unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
301{
302 /* make sure blocksize is a power of two */
303 if ((bsize & (bsize - 1)) || nrbitsp) {
304 unsigned char nrbits;
305
306 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
307 ;
308 bsize = 1 << nrbits;
309 if (nrbitsp)
310 *nrbitsp = nrbits;
311 }
312
313 return bsize;
314}
315
316/*
317 * Calculate the number of 512byte blocks used.
318 */
9eaa67c6 319static inline blkcnt_t nfs_calc_block_size(u64 tsize)
f7b422b1 320{
9eaa67c6 321 blkcnt_t used = (tsize + 511) >> 9;
f7b422b1
DH
322 return (used > ULONG_MAX) ? ULONG_MAX : used;
323}
324
325/*
326 * Compute and set NFS server blocksize
327 */
328static inline
329unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
330{
331 if (bsize < NFS_MIN_FILE_IO_SIZE)
332 bsize = NFS_DEF_FILE_IO_SIZE;
333 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
334 bsize = NFS_MAX_FILE_IO_SIZE;
335
336 return nfs_block_bits(bsize, nrbitsp);
337}
338
339/*
340 * Determine the maximum file size for a superblock
341 */
342static inline
343void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
344{
345 sb->s_maxbytes = (loff_t)maxfilesize;
346 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
347 sb->s_maxbytes = MAX_LFS_FILESIZE;
348}
49a70f27
TM
349
350/*
351 * Determine the number of bytes of data the page contains
352 */
353static inline
354unsigned int nfs_page_length(struct page *page)
355{
356 loff_t i_size = i_size_read(page->mapping->host);
357
358 if (i_size > 0) {
359 pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
360 if (page->index < end_index)
361 return PAGE_CACHE_SIZE;
362 if (page->index == end_index)
363 return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
364 }
365 return 0;
366}
8d5658c9 367
0b26a0bf
TM
368/*
369 * Convert a umode to a dirent->d_type
370 */
371static inline
372unsigned char nfs_umode_to_dtype(umode_t mode)
373{
374 return (mode >> 12) & 15;
375}
376
8d5658c9
TM
377/*
378 * Determine the number of pages in an array of length 'len' and
379 * with a base offset of 'base'
380 */
381static inline
382unsigned int nfs_page_array_len(unsigned int base, size_t len)
383{
384 return ((unsigned long)len + (unsigned long)base +
385 PAGE_SIZE - 1) >> PAGE_SHIFT;
386}
0110ee15
TM
387
388/*
389 * Helper for restarting RPC calls in the possible presence of NFSv4.1
390 * sessions.
391 */
d05dd4e9 392static inline int nfs_restart_rpc(struct rpc_task *task, const struct nfs_client *clp)
0110ee15
TM
393{
394 if (nfs4_has_session(clp))
d05dd4e9
TM
395 return rpc_restart_call_prepare(task);
396 return rpc_restart_call(task);
0110ee15 397}