nfs41: use rpc prepare call state for session reset
[deliverable/linux.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
f7b422b1
DH
33struct nfs_clone_mount {
34 const struct super_block *sb;
35 const struct dentry *dentry;
36 struct nfs_fh *fh;
37 struct nfs_fattr *fattr;
38 char *hostname;
39 char *mnt_path;
6677d095
CL
40 struct sockaddr *addr;
41 size_t addrlen;
f7b422b1
DH
42 rpc_authflavor_t authflavor;
43};
44
6b18eaa0
TT
45/*
46 * In-kernel mount arguments
47 */
48struct nfs_parsed_mount_data {
49 int flags;
50 int rsize, wsize;
51 int timeo, retrans;
52 int acregmin, acregmax,
53 acdirmin, acdirmax;
54 int namlen;
b797cac7 55 unsigned int options;
6b18eaa0
TT
56 unsigned int bsize;
57 unsigned int auth_flavor_len;
58 rpc_authflavor_t auth_flavors[1];
59 char *client_address;
3fd5be9e 60 unsigned int minorversion;
08734048 61 char *fscache_uniq;
6b18eaa0
TT
62
63 struct {
4c568017
CL
64 struct sockaddr_storage address;
65 size_t addrlen;
6b18eaa0 66 char *hostname;
78fa701f 67 u32 version;
6b18eaa0 68 unsigned short port;
78fa701f 69 unsigned short protocol;
6b18eaa0
TT
70 } mount_server;
71
72 struct {
4c568017
CL
73 struct sockaddr_storage address;
74 size_t addrlen;
6b18eaa0
TT
75 char *hostname;
76 char *export_path;
f22d6d79 77 unsigned short port;
78fa701f 78 unsigned short protocol;
6b18eaa0 79 } nfs_server;
f9c3a380
EP
80
81 struct security_mnt_opts lsm_opts;
6b18eaa0
TT
82};
83
146ec944 84/* mount_clnt.c */
c5d120f8
CL
85struct nfs_mount_request {
86 struct sockaddr *sap;
87 size_t salen;
88 char *hostname;
89 char *dirpath;
90 u32 version;
91 unsigned short protocol;
92 struct nfs_fh *fh;
50a737f8 93 int noresvport;
c5d120f8
CL
94};
95
96extern int nfs_mount(struct nfs_mount_request *info);
146ec944 97
24c8dbbb 98/* client.c */
54ceac45
DH
99extern struct rpc_program nfs_program;
100
24c8dbbb 101extern void nfs_put_client(struct nfs_client *);
ff052645 102extern struct nfs_client *nfs_find_client(const struct sockaddr *, u32);
3fbd67ad 103extern struct nfs_client *nfs_find_client_next(struct nfs_client *);
2283f8d6
TT
104extern struct nfs_server *nfs_create_server(
105 const struct nfs_parsed_mount_data *,
106 struct nfs_fh *);
91ea40b9
TT
107extern struct nfs_server *nfs4_create_server(
108 const struct nfs_parsed_mount_data *,
109 struct nfs_fh *);
54ceac45
DH
110extern struct nfs_server *nfs4_create_referral_server(struct nfs_clone_mount *,
111 struct nfs_fh *);
112extern void nfs_free_server(struct nfs_server *server);
113extern struct nfs_server *nfs_clone_server(struct nfs_server *,
114 struct nfs_fh *,
115 struct nfs_fattr *);
76db6d95 116extern void nfs_mark_client_ready(struct nfs_client *clp, int state);
6aaca566
DH
117#ifdef CONFIG_PROC_FS
118extern int __init nfs_fs_proc_init(void);
119extern void nfs_fs_proc_exit(void);
120#else
121static inline int nfs_fs_proc_init(void)
122{
123 return 0;
124}
125static inline void nfs_fs_proc_exit(void)
126{
127}
128#endif
24c8dbbb 129
7d4e2747 130/* nfs4namespace.c */
f7b422b1
DH
131#ifdef CONFIG_NFS_V4
132extern struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry);
133#else
134static inline
135struct vfsmount *nfs_do_refmount(const struct vfsmount *mnt_parent, struct dentry *dentry)
136{
137 return ERR_PTR(-ENOENT);
138}
139#endif
140
141/* callback_xdr.c */
142extern struct svc_version nfs4_callback_version1;
143
144/* pagelist.c */
145extern int __init nfs_init_nfspagecache(void);
266bee88 146extern void nfs_destroy_nfspagecache(void);
f7b422b1 147extern int __init nfs_init_readpagecache(void);
266bee88 148extern void nfs_destroy_readpagecache(void);
f7b422b1 149extern int __init nfs_init_writepagecache(void);
266bee88 150extern void nfs_destroy_writepagecache(void);
f7b422b1 151
f7b422b1 152extern int __init nfs_init_directcache(void);
266bee88 153extern void nfs_destroy_directcache(void);
f7b422b1
DH
154
155/* nfs2xdr.c */
7d4e2747 156extern int nfs_stat_to_errno(int);
f7b422b1 157extern struct rpc_procinfo nfs_procedures[];
0dbb4c67 158extern __be32 * nfs_decode_dirent(__be32 *, struct nfs_entry *, int);
f7b422b1
DH
159
160/* nfs3xdr.c */
161extern struct rpc_procinfo nfs3_procedures[];
0dbb4c67 162extern __be32 *nfs3_decode_dirent(__be32 *, struct nfs_entry *, int);
f7b422b1 163
eedc020e
AA
164/* nfs4proc.c */
165static inline void nfs4_restart_rpc(struct rpc_task *task,
166 const struct nfs_client *clp)
167{
168#ifdef CONFIG_NFS_V4_1
169 if (nfs4_has_session(clp) &&
170 test_bit(NFS4CLNT_SESSION_SETUP, &clp->cl_state)) {
171 rpc_restart_call_prepare(task);
172 return;
173 }
174#endif /* CONFIG_NFS_V4_1 */
175 rpc_restart_call(task);
176}
177
f7b422b1 178/* nfs4xdr.c */
7d4e2747 179#ifdef CONFIG_NFS_V4
0dbb4c67 180extern __be32 *nfs4_decode_dirent(__be32 *p, struct nfs_entry *entry, int plus);
7d4e2747 181#endif
f7b422b1
DH
182
183/* nfs4proc.c */
d75d5414 184#ifdef CONFIG_NFS_V4
f7b422b1 185extern struct rpc_procinfo nfs4_procedures[];
d75d5414 186#endif
f7b422b1 187
7fe5c398
TM
188/* proc.c */
189void nfs_close_context(struct nfs_open_context *ctx, int is_sync);
190
979df72e
TM
191/* dir.c */
192extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
193
f7b422b1 194/* inode.c */
5746006f 195extern struct workqueue_struct *nfsiod_workqueue;
f7b422b1
DH
196extern struct inode *nfs_alloc_inode(struct super_block *sb);
197extern void nfs_destroy_inode(struct inode *);
198extern int nfs_write_inode(struct inode *,int);
199extern void nfs_clear_inode(struct inode *);
200#ifdef CONFIG_NFS_V4
201extern void nfs4_clear_inode(struct inode *);
202#endif
f41f7418 203void nfs_zap_acl_cache(struct inode *inode);
72cb77f4 204extern int nfs_wait_bit_killable(void *word);
f7b422b1
DH
205
206/* super.c */
ea31a443 207void nfs_parse_ip_address(char *, size_t, struct sockaddr *, size_t *);
54ceac45 208extern struct file_system_type nfs_xdev_fs_type;
f7b422b1 209#ifdef CONFIG_NFS_V4
54ceac45
DH
210extern struct file_system_type nfs4_xdev_fs_type;
211extern struct file_system_type nfs4_referral_fs_type;
f7b422b1 212#endif
4ebd9ab3 213
f7b422b1 214extern struct rpc_stat nfs_rpcstat;
4ebd9ab3 215
f7b422b1
DH
216extern int __init register_nfs_fs(void);
217extern void __exit unregister_nfs_fs(void);
1daef0a8
TM
218extern void nfs_sb_active(struct super_block *sb);
219extern void nfs_sb_deactive(struct super_block *sb);
f7b422b1
DH
220
221/* namespace.c */
54ceac45
DH
222extern char *nfs_path(const char *base,
223 const struct dentry *droot,
224 const struct dentry *dentry,
f7b422b1
DH
225 char *buffer, ssize_t buflen);
226
54ceac45
DH
227/* getroot.c */
228extern struct dentry *nfs_get_root(struct super_block *, struct nfs_fh *);
7d4e2747 229#ifdef CONFIG_NFS_V4
54ceac45
DH
230extern struct dentry *nfs4_get_root(struct super_block *, struct nfs_fh *);
231
232extern int nfs4_path_walk(struct nfs_server *server,
233 struct nfs_fh *mntfh,
234 const char *path);
7d4e2747 235#endif
f7b422b1 236
f11c88af
AA
237/* read.c */
238extern void nfs_read_prepare(struct rpc_task *task, void *calldata);
239
def6ed7e
AA
240/* write.c */
241extern void nfs_write_prepare(struct rpc_task *task, void *calldata);
242
cccef3b9
AA
243/* nfs4proc.c */
244extern int _nfs4_call_sync(struct nfs_server *server,
245 struct rpc_message *msg,
246 struct nfs4_sequence_args *args,
247 struct nfs4_sequence_res *res,
248 int cache_reply);
249extern int _nfs4_call_sync_session(struct nfs_server *server,
250 struct rpc_message *msg,
251 struct nfs4_sequence_args *args,
252 struct nfs4_sequence_res *res,
253 int cache_reply);
254
13615871
AA
255#ifdef CONFIG_NFS_V4_1
256extern void nfs41_sequence_free_slot(const struct nfs_client *,
257 struct nfs4_sequence_res *res);
258#endif /* CONFIG_NFS_V4_1 */
259
260static inline void nfs4_sequence_free_slot(const struct nfs_client *clp,
261 struct nfs4_sequence_res *res)
262{
263#ifdef CONFIG_NFS_V4_1
264 if (nfs4_has_session(clp))
265 nfs41_sequence_free_slot(clp, res);
266#endif /* CONFIG_NFS_V4_1 */
267}
268
f7b422b1
DH
269/*
270 * Determine the device name as a string
271 */
272static inline char *nfs_devname(const struct vfsmount *mnt_parent,
54ceac45
DH
273 const struct dentry *dentry,
274 char *buffer, ssize_t buflen)
f7b422b1 275{
54ceac45
DH
276 return nfs_path(mnt_parent->mnt_devname, mnt_parent->mnt_root,
277 dentry, buffer, buflen);
f7b422b1
DH
278}
279
280/*
281 * Determine the actual block size (and log2 thereof)
282 */
283static inline
284unsigned long nfs_block_bits(unsigned long bsize, unsigned char *nrbitsp)
285{
286 /* make sure blocksize is a power of two */
287 if ((bsize & (bsize - 1)) || nrbitsp) {
288 unsigned char nrbits;
289
290 for (nrbits = 31; nrbits && !(bsize & (1 << nrbits)); nrbits--)
291 ;
292 bsize = 1 << nrbits;
293 if (nrbitsp)
294 *nrbitsp = nrbits;
295 }
296
297 return bsize;
298}
299
300/*
301 * Calculate the number of 512byte blocks used.
302 */
9eaa67c6 303static inline blkcnt_t nfs_calc_block_size(u64 tsize)
f7b422b1 304{
9eaa67c6 305 blkcnt_t used = (tsize + 511) >> 9;
f7b422b1
DH
306 return (used > ULONG_MAX) ? ULONG_MAX : used;
307}
308
309/*
310 * Compute and set NFS server blocksize
311 */
312static inline
313unsigned long nfs_block_size(unsigned long bsize, unsigned char *nrbitsp)
314{
315 if (bsize < NFS_MIN_FILE_IO_SIZE)
316 bsize = NFS_DEF_FILE_IO_SIZE;
317 else if (bsize >= NFS_MAX_FILE_IO_SIZE)
318 bsize = NFS_MAX_FILE_IO_SIZE;
319
320 return nfs_block_bits(bsize, nrbitsp);
321}
322
323/*
324 * Determine the maximum file size for a superblock
325 */
326static inline
327void nfs_super_set_maxbytes(struct super_block *sb, __u64 maxfilesize)
328{
329 sb->s_maxbytes = (loff_t)maxfilesize;
330 if (sb->s_maxbytes > MAX_LFS_FILESIZE || sb->s_maxbytes <= 0)
331 sb->s_maxbytes = MAX_LFS_FILESIZE;
332}
49a70f27
TM
333
334/*
335 * Determine the number of bytes of data the page contains
336 */
337static inline
338unsigned int nfs_page_length(struct page *page)
339{
340 loff_t i_size = i_size_read(page->mapping->host);
341
342 if (i_size > 0) {
343 pgoff_t end_index = (i_size - 1) >> PAGE_CACHE_SHIFT;
344 if (page->index < end_index)
345 return PAGE_CACHE_SIZE;
346 if (page->index == end_index)
347 return ((i_size - 1) & ~PAGE_CACHE_MASK) + 1;
348 }
349 return 0;
350}
8d5658c9
TM
351
352/*
353 * Determine the number of pages in an array of length 'len' and
354 * with a base offset of 'base'
355 */
356static inline
357unsigned int nfs_page_array_len(unsigned int base, size_t len)
358{
359 return ((unsigned long)len + (unsigned long)base +
360 PAGE_SIZE - 1) >> PAGE_SHIFT;
361}
362
ea31a443 363#define IPV6_SCOPE_DELIMITER '%'
f0c92925
BF
364
365/*
366 * Set the port number in an address. Be agnostic about the address
367 * family.
368 */
369static inline void nfs_set_port(struct sockaddr *sap, unsigned short port)
370{
456018d7
BF
371 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
372 struct sockaddr_in6 *ap6 = (struct sockaddr_in6 *)sap;
373
f0c92925 374 switch (sap->sa_family) {
456018d7
BF
375 case AF_INET:
376 ap->sin_port = htons(port);
377 break;
378 case AF_INET6:
379 ap6->sin6_port = htons(port);
380 break;
f0c92925
BF
381 }
382}
This page took 0.328176 seconds and 5 git commands to generate.