1
2
3
4
5
6
7
8
9#ifndef _LINUX_NFS_FS_H
10#define _LINUX_NFS_FS_H
11
12#include <linux/magic.h>
13
14
15#define NFS_DEF_UDP_TIMEO (11)
16#define NFS_DEF_UDP_RETRANS (3)
17#define NFS_DEF_TCP_TIMEO (600)
18#define NFS_DEF_TCP_RETRANS (2)
19
20#define NFS_MAX_UDP_TIMEOUT (60*HZ)
21#define NFS_MAX_TCP_TIMEOUT (600*HZ)
22
23#define NFS_DEF_ACREGMIN (3)
24#define NFS_DEF_ACREGMAX (60)
25#define NFS_DEF_ACDIRMIN (30)
26#define NFS_DEF_ACDIRMAX (60)
27
28
29
30
31
32#define FLUSH_SYNC 1
33#define FLUSH_STABLE 4
34#define FLUSH_LOWPRI 8
35#define FLUSH_HIGHPRI 16
36#define FLUSH_NOCOMMIT 32
37#define FLUSH_INVALIDATE 64
38#define FLUSH_NOWRITEPAGE 128
39
40#ifdef __KERNEL__
41
42#include <linux/in.h>
43#include <linux/mm.h>
44#include <linux/pagemap.h>
45#include <linux/rbtree.h>
46#include <linux/rwsem.h>
47#include <linux/wait.h>
48
49#include <linux/sunrpc/debug.h>
50#include <linux/sunrpc/auth.h>
51#include <linux/sunrpc/clnt.h>
52
53#include <linux/nfs.h>
54#include <linux/nfs2.h>
55#include <linux/nfs3.h>
56#include <linux/nfs4.h>
57#include <linux/nfs_xdr.h>
58#include <linux/nfs_fs_sb.h>
59
60#include <linux/mempool.h>
61
62
63
64
65#define NFS_RPC_SWAPFLAGS (RPC_TASK_SWAPPER|RPC_TASK_ROOTCREDS)
66
67
68
69
70struct nfs_access_entry {
71 struct rb_node rb_node;
72 struct list_head lru;
73 unsigned long jiffies;
74 struct rpc_cred * cred;
75 int mask;
76};
77
78struct nfs4_state;
79struct nfs_open_context {
80 atomic_t count;
81 struct path path;
82 struct rpc_cred *cred;
83 struct nfs4_state *state;
84 fl_owner_t lockowner;
85 fmode_t mode;
86
87 unsigned long flags;
88#define NFS_CONTEXT_ERROR_WRITE (0)
89 int error;
90
91 struct list_head list;
92
93 __u64 dir_cookie;
94};
95
96
97
98
99struct nfs_delegation;
100
101struct posix_acl;
102
103
104
105
106struct nfs_inode {
107
108
109
110 __u64 fileid;
111
112
113
114
115 struct nfs_fh fh;
116
117
118
119
120 unsigned long flags;
121 unsigned long cache_validity;
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137 unsigned long read_cache_jiffies;
138 unsigned long attrtimeo;
139 unsigned long attrtimeo_timestamp;
140 __u64 change_attr;
141
142 unsigned long attr_gencount;
143
144
145
146
147 unsigned long cache_change_attribute;
148
149 struct rb_root access_cache;
150 struct list_head access_cache_entry_lru;
151 struct list_head access_cache_inode_lru;
152#ifdef CONFIG_NFS_V3_ACL
153 struct posix_acl *acl_access;
154 struct posix_acl *acl_default;
155#endif
156
157
158
159
160
161 __be32 cookieverf[2];
162
163
164
165
166 struct radix_tree_root nfs_page_tree;
167
168 unsigned long npages;
169
170
171 struct list_head open_files;
172
173
174 atomic_t silly_count;
175
176 struct hlist_head silly_list;
177 wait_queue_head_t waitqueue;
178
179#ifdef CONFIG_NFS_V4
180 struct nfs4_cached_acl *nfs4_acl;
181
182 struct list_head open_states;
183 struct nfs_delegation *delegation;
184 fmode_t delegation_state;
185 struct rw_semaphore rwsem;
186#endif
187#ifdef CONFIG_NFS_FSCACHE
188 struct fscache_cookie *fscache;
189#endif
190 struct inode vfs_inode;
191};
192
193
194
195
196#define NFS_INO_INVALID_ATTR 0x0001
197#define NFS_INO_INVALID_DATA 0x0002
198#define NFS_INO_INVALID_ATIME 0x0004
199#define NFS_INO_INVALID_ACCESS 0x0008
200#define NFS_INO_INVALID_ACL 0x0010
201#define NFS_INO_REVAL_PAGECACHE 0x0020
202#define NFS_INO_REVAL_FORCED 0x0040
203
204
205
206
207#define NFS_INO_ADVISE_RDPLUS (0)
208#define NFS_INO_STALE (1)
209#define NFS_INO_ACL_LRU_SET (2)
210#define NFS_INO_MOUNTPOINT (3)
211#define NFS_INO_FLUSHING (4)
212#define NFS_INO_FSCACHE (5)
213#define NFS_INO_FSCACHE_LOCK (6)
214
215static inline struct nfs_inode *NFS_I(const struct inode *inode)
216{
217 return container_of(inode, struct nfs_inode, vfs_inode);
218}
219
220static inline struct nfs_server *NFS_SB(const struct super_block *s)
221{
222 return (struct nfs_server *)(s->s_fs_info);
223}
224
225static inline struct nfs_fh *NFS_FH(const struct inode *inode)
226{
227 return &NFS_I(inode)->fh;
228}
229
230static inline struct nfs_server *NFS_SERVER(const struct inode *inode)
231{
232 return NFS_SB(inode->i_sb);
233}
234
235static inline struct rpc_clnt *NFS_CLIENT(const struct inode *inode)
236{
237 return NFS_SERVER(inode)->client;
238}
239
240static inline const struct nfs_rpc_ops *NFS_PROTO(const struct inode *inode)
241{
242 return NFS_SERVER(inode)->nfs_client->rpc_ops;
243}
244
245static inline __be32 *NFS_COOKIEVERF(const struct inode *inode)
246{
247 return NFS_I(inode)->cookieverf;
248}
249
250static inline unsigned NFS_MINATTRTIMEO(const struct inode *inode)
251{
252 struct nfs_server *nfss = NFS_SERVER(inode);
253 return S_ISDIR(inode->i_mode) ? nfss->acdirmin : nfss->acregmin;
254}
255
256static inline unsigned NFS_MAXATTRTIMEO(const struct inode *inode)
257{
258 struct nfs_server *nfss = NFS_SERVER(inode);
259 return S_ISDIR(inode->i_mode) ? nfss->acdirmax : nfss->acregmax;
260}
261
262static inline int NFS_STALE(const struct inode *inode)
263{
264 return test_bit(NFS_INO_STALE, &NFS_I(inode)->flags);
265}
266
267static inline int NFS_FSCACHE(const struct inode *inode)
268{
269 return test_bit(NFS_INO_FSCACHE, &NFS_I(inode)->flags);
270}
271
272static inline __u64 NFS_FILEID(const struct inode *inode)
273{
274 return NFS_I(inode)->fileid;
275}
276
277static inline void set_nfs_fileid(struct inode *inode, __u64 fileid)
278{
279 NFS_I(inode)->fileid = fileid;
280}
281
282static inline void nfs_mark_for_revalidate(struct inode *inode)
283{
284 struct nfs_inode *nfsi = NFS_I(inode);
285
286 spin_lock(&inode->i_lock);
287 nfsi->cache_validity |= NFS_INO_INVALID_ATTR|NFS_INO_INVALID_ACCESS;
288 if (S_ISDIR(inode->i_mode))
289 nfsi->cache_validity |= NFS_INO_REVAL_PAGECACHE|NFS_INO_INVALID_DATA;
290 spin_unlock(&inode->i_lock);
291}
292
293static inline int nfs_server_capable(struct inode *inode, int cap)
294{
295 return NFS_SERVER(inode)->caps & cap;
296}
297
298static inline int NFS_USE_READDIRPLUS(struct inode *inode)
299{
300 return test_bit(NFS_INO_ADVISE_RDPLUS, &NFS_I(inode)->flags);
301}
302
303static inline void nfs_set_verifier(struct dentry * dentry, unsigned long verf)
304{
305 dentry->d_time = verf;
306}
307
308
309
310
311
312
313
314static inline unsigned long nfs_save_change_attribute(struct inode *dir)
315{
316 return NFS_I(dir)->cache_change_attribute;
317}
318
319
320
321
322
323
324
325
326
327static inline int nfs_verify_change_attribute(struct inode *dir, unsigned long chattr)
328{
329 return chattr == NFS_I(dir)->cache_change_attribute;
330}
331
332
333
334
335extern int nfs_sync_mapping(struct address_space *mapping);
336extern void nfs_zap_mapping(struct inode *inode, struct address_space *mapping);
337extern void nfs_zap_caches(struct inode *);
338extern void nfs_invalidate_atime(struct inode *);
339extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *,
340 struct nfs_fattr *);
341extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *);
342extern int nfs_post_op_update_inode(struct inode *inode, struct nfs_fattr *fattr);
343extern int nfs_post_op_update_inode_force_wcc(struct inode *inode, struct nfs_fattr *fattr);
344extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
345extern int nfs_permission(struct inode *, int);
346extern int nfs_open(struct inode *, struct file *);
347extern int nfs_release(struct inode *, struct file *);
348extern int nfs_attribute_timeout(struct inode *inode);
349extern int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode);
350extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
351extern int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping);
352extern int nfs_revalidate_mapping_nolock(struct inode *inode, struct address_space *mapping);
353extern int nfs_setattr(struct dentry *, struct iattr *);
354extern void nfs_setattr_update_inode(struct inode *inode, struct iattr *attr);
355extern struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx);
356extern void put_nfs_open_context(struct nfs_open_context *ctx);
357extern struct nfs_open_context *nfs_find_open_context(struct inode *inode, struct rpc_cred *cred, fmode_t mode);
358extern u64 nfs_compat_user_ino64(u64 fileid);
359extern void nfs_fattr_init(struct nfs_fattr *fattr);
360
361
362extern __be32 root_nfs_parse_addr(char *name);
363extern unsigned long nfs_inc_attr_generation_counter(void);
364
365
366
367
368extern const struct inode_operations nfs_file_inode_operations;
369#ifdef CONFIG_NFS_V3
370extern const struct inode_operations nfs3_file_inode_operations;
371#endif
372extern const struct file_operations nfs_file_operations;
373extern const struct address_space_operations nfs_file_aops;
374
375static inline struct nfs_open_context *nfs_file_open_context(struct file *filp)
376{
377 return filp->private_data;
378}
379
380static inline struct rpc_cred *nfs_file_cred(struct file *file)
381{
382 if (file != NULL) {
383 struct nfs_open_context *ctx =
384 nfs_file_open_context(file);
385 if (ctx)
386 return ctx->cred;
387 }
388 return NULL;
389}
390
391
392
393
394#ifdef CONFIG_NFS_V3_ACL
395extern ssize_t nfs3_listxattr(struct dentry *, char *, size_t);
396extern ssize_t nfs3_getxattr(struct dentry *, const char *, void *, size_t);
397extern int nfs3_setxattr(struct dentry *, const char *,
398 const void *, size_t, int);
399extern int nfs3_removexattr (struct dentry *, const char *name);
400#else
401# define nfs3_listxattr NULL
402# define nfs3_getxattr NULL
403# define nfs3_setxattr NULL
404# define nfs3_removexattr NULL
405#endif
406
407
408
409
410extern ssize_t nfs_direct_IO(int, struct kiocb *, const struct iovec *, loff_t,
411 unsigned long);
412extern ssize_t nfs_file_direct_read(struct kiocb *iocb,
413 const struct iovec *iov, unsigned long nr_segs,
414 loff_t pos);
415extern ssize_t nfs_file_direct_write(struct kiocb *iocb,
416 const struct iovec *iov, unsigned long nr_segs,
417 loff_t pos);
418
419
420
421
422extern const struct inode_operations nfs_dir_inode_operations;
423#ifdef CONFIG_NFS_V3
424extern const struct inode_operations nfs3_dir_inode_operations;
425#endif
426extern const struct file_operations nfs_dir_operations;
427extern const struct dentry_operations nfs_dentry_operations;
428
429extern void nfs_force_lookup_revalidate(struct inode *dir);
430extern int nfs_instantiate(struct dentry *dentry, struct nfs_fh *fh, struct nfs_fattr *fattr);
431extern int nfs_may_open(struct inode *inode, struct rpc_cred *cred, int openflags);
432extern void nfs_access_zap_cache(struct inode *inode);
433
434
435
436
437extern const struct inode_operations nfs_symlink_inode_operations;
438
439
440
441
442#ifdef CONFIG_SYSCTL
443extern int nfs_register_sysctl(void);
444extern void nfs_unregister_sysctl(void);
445#else
446#define nfs_register_sysctl() 0
447#define nfs_unregister_sysctl() do { } while(0)
448#endif
449
450
451
452
453extern const struct inode_operations nfs_mountpoint_inode_operations;
454extern const struct inode_operations nfs_referral_inode_operations;
455extern int nfs_mountpoint_expiry_timeout;
456extern void nfs_release_automount_timer(void);
457
458
459
460
461extern int nfs_async_unlink(struct inode *dir, struct dentry *dentry);
462extern void nfs_complete_unlink(struct dentry *dentry, struct inode *);
463extern void nfs_block_sillyrename(struct dentry *dentry);
464extern void nfs_unblock_sillyrename(struct dentry *dentry);
465
466
467
468
469extern int nfs_congestion_kb;
470extern int nfs_writepage(struct page *page, struct writeback_control *wbc);
471extern int nfs_writepages(struct address_space *, struct writeback_control *);
472extern int nfs_flush_incompatible(struct file *file, struct page *page);
473extern int nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
474extern int nfs_writeback_done(struct rpc_task *, struct nfs_write_data *);
475
476
477
478
479
480extern long nfs_sync_mapping_wait(struct address_space *, struct writeback_control *, int);
481extern int nfs_wb_all(struct inode *inode);
482extern int nfs_wb_nocommit(struct inode *inode);
483extern int nfs_wb_page(struct inode *inode, struct page* page);
484extern int nfs_wb_page_cancel(struct inode *inode, struct page* page);
485#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
486extern int nfs_commit_inode(struct inode *, int);
487extern struct nfs_write_data *nfs_commitdata_alloc(void);
488extern void nfs_commit_free(struct nfs_write_data *wdata);
489#else
490static inline int
491nfs_commit_inode(struct inode *inode, int how)
492{
493 return 0;
494}
495#endif
496
497static inline int
498nfs_have_writebacks(struct inode *inode)
499{
500 return NFS_I(inode)->npages != 0;
501}
502
503
504
505
506extern struct nfs_write_data *nfs_writedata_alloc(unsigned int npages);
507extern void nfs_writedata_free(struct nfs_write_data *);
508
509
510
511
512extern int nfs_readpage(struct file *, struct page *);
513extern int nfs_readpages(struct file *, struct address_space *,
514 struct list_head *, unsigned);
515extern int nfs_readpage_result(struct rpc_task *, struct nfs_read_data *);
516extern int nfs_readpage_async(struct nfs_open_context *, struct inode *,
517 struct page *);
518
519
520
521
522extern struct nfs_read_data *nfs_readdata_alloc(unsigned int npages);
523extern void nfs_readdata_free(struct nfs_read_data *);
524
525
526
527
528#ifdef CONFIG_NFS_V3_ACL
529extern struct posix_acl *nfs3_proc_getacl(struct inode *inode, int type);
530extern int nfs3_proc_setacl(struct inode *inode, int type,
531 struct posix_acl *acl);
532extern int nfs3_proc_set_default_acl(struct inode *dir, struct inode *inode,
533 mode_t mode);
534extern void nfs3_forget_cached_acls(struct inode *inode);
535#else
536static inline int nfs3_proc_set_default_acl(struct inode *dir,
537 struct inode *inode,
538 mode_t mode)
539{
540 return 0;
541}
542
543static inline void nfs3_forget_cached_acls(struct inode *inode)
544{
545}
546#endif
547
548
549
550
551
552static inline loff_t nfs_size_to_loff_t(__u64 size)
553{
554 if (size > (__u64) OFFSET_MAX - 1)
555 return OFFSET_MAX - 1;
556 return (loff_t) size;
557}
558
559static inline ino_t
560nfs_fileid_to_ino_t(u64 fileid)
561{
562 ino_t ino = (ino_t) fileid;
563 if (sizeof(ino_t) < sizeof(u64))
564 ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8;
565 return ino;
566}
567
568
569
570extern void * nfs_root_data(void);
571
572#define nfs_wait_event(clnt, wq, condition) \
573({ \
574 int __retval = wait_event_killable(wq, condition); \
575 __retval; \
576})
577
578#define NFS_JUKEBOX_RETRY_TIME (5 * HZ)
579
580#endif
581
582
583
584
585#define NFSDBG_VFS 0x0001
586#define NFSDBG_DIRCACHE 0x0002
587#define NFSDBG_LOOKUPCACHE 0x0004
588#define NFSDBG_PAGECACHE 0x0008
589#define NFSDBG_PROC 0x0010
590#define NFSDBG_XDR 0x0020
591#define NFSDBG_FILE 0x0040
592#define NFSDBG_ROOT 0x0080
593#define NFSDBG_CALLBACK 0x0100
594#define NFSDBG_CLIENT 0x0200
595#define NFSDBG_MOUNT 0x0400
596#define NFSDBG_FSCACHE 0x0800
597#define NFSDBG_ALL 0xFFFF
598
599#ifdef __KERNEL__
600
601
602
603
604
605#ifdef RPC_DEBUG
606# define NFS_DEBUG
607#endif
608
609# undef ifdebug
610# ifdef NFS_DEBUG
611# define ifdebug(fac) if (unlikely(nfs_debug & NFSDBG_##fac))
612# else
613# define ifdebug(fac) if (0)
614# endif
615#endif
616
617#endif
618