2 * linux/include/linux/nfs_fs.h
4 * Copyright (C) 1992 Rick Sladkey
6 * OS-specific nfs filesystem definitions and declarations
9 #ifndef _LINUX_NFS_FS_H
10 #define _LINUX_NFS_FS_H
12 #include <linux/config.h>
15 #include <linux/pagemap.h>
16 #include <linux/rwsem.h>
17 #include <linux/wait.h>
18 #include <linux/uio.h>
20 #include <linux/nfs_fs_sb.h>
22 #include <linux/sunrpc/debug.h>
23 #include <linux/sunrpc/auth.h>
24 #include <linux/sunrpc/clnt.h>
26 #include <linux/nfs.h>
27 #include <linux/nfs2.h>
28 #include <linux/nfs3.h>
29 #include <linux/nfs4.h>
30 #include <linux/nfs_xdr.h>
31 #include <linux/workqueue.h>
34 * Enable debugging support for nfs client.
41 #define NFS_MAX_FILE_IO_BUFFER_SIZE 32768
42 #define NFS_DEF_FILE_IO_BUFFER_SIZE 4096
45 * The upper limit on timeouts for the exponential backoff algorithm.
47 #define NFS_WRITEBACK_DELAY (5*HZ)
48 #define NFS_WRITEBACK_LOCKDELAY (60*HZ)
49 #define NFS_COMMIT_DELAY (5*HZ)
52 * superblock magic number for NFS
54 #define NFS_SUPER_MAGIC 0x6969
57 * These are the default flags for swap requests
59 #define NFS_RPC_SWAPFLAGS (RPC_TASK_SWAPPER|RPC_TASK_ROOTCREDS)
61 #define NFS_RW_SYNC 0x0001 /* O_SYNC handling */
62 #define NFS_RW_SWAP 0x0002 /* This is a swap request */
65 * When flushing a cluster of dirty pages, there can be different
68 #define FLUSH_AGING 0 /* only flush old buffers */
69 #define FLUSH_SYNC 1 /* file being synced, or contention */
70 #define FLUSH_WAIT 2 /* wait for completion */
71 #define FLUSH_STABLE 4 /* commit to stable storage */
72 #define FLUSH_LOWPRI 8 /* low priority background flush */
73 #define FLUSH_HIGHPRI 16 /* high priority memory reclaim flush */
78 * NFSv3 Access mode cache
80 struct nfs_access_cache {
81 unsigned long jiffies;
82 struct rpc_cred * cred;
88 * nfs fs inode data in memory
92 * The 64bit 'inode number'
107 * read_cache_jiffies is when we started read-caching this inode,
108 * and read_cache_mtime is the mtime of the inode at that time.
109 * attrtimeo is for how long the cached information is assumed
110 * to be valid. A successful attribute revalidation doubles
111 * attrtimeo (up to acregmax/acdirmax), a failure resets it to
114 * We need to revalidate the cached attrs for this inode if
116 * jiffies - read_cache_jiffies > attrtimeo
118 * and invalidate any cached data/flush out any dirty pages if
121 * mtime != read_cache_mtime
123 unsigned long readdir_timestamp;
124 unsigned long read_cache_jiffies;
125 unsigned long attrtimeo;
126 unsigned long attrtimeo_timestamp;
127 __u64 change_attr; /* v4 only */
129 /* "Generation counter" for the attribute cache. This is
130 * bumped whenever we update the metadata on the
133 unsigned long cache_change_attribute;
135 * Counter indicating the number of outstanding requests that
136 * will cause a file data update.
138 atomic_t data_updates;
140 struct nfs_access_cache cache_access;
143 * This is the cookie verifier used for NFSv3 readdir
149 * This is the list of dirty unwritten pages.
151 struct list_head dirty;
152 struct list_head commit;
153 struct radix_tree_root nfs_page_tree;
159 /* Credentials for shared mmap */
160 struct rpc_cred *mm_cred;
162 wait_queue_head_t nfs_i_wait;
166 struct list_head open_states;
167 #endif /* CONFIG_NFS_V4*/
169 struct inode vfs_inode;
173 * Legal inode flag values
175 #define NFS_INO_STALE 0x0001 /* possible stale inode */
176 #define NFS_INO_ADVISE_RDPLUS 0x0002 /* advise readdirplus */
177 #define NFS_INO_REVALIDATING 0x0004 /* revalidating attrs */
178 #define NFS_INO_INVALID_ATTR 0x0008 /* cached attrs are invalid */
179 #define NFS_INO_INVALID_DATA 0x0010 /* cached data is invalid */
180 #define NFS_INO_INVALID_ATIME 0x0020 /* cached atime is invalid */
182 static inline struct nfs_inode *NFS_I(struct inode *inode)
184 return container_of(inode, struct nfs_inode, vfs_inode);
186 #define NFS_SB(s) ((struct nfs_server *)(s->s_fs_info))
188 #define NFS_FH(inode) (&NFS_I(inode)->fh)
189 #define NFS_SERVER(inode) (NFS_SB(inode->i_sb))
190 #define NFS_CLIENT(inode) (NFS_SERVER(inode)->client)
191 #define NFS_PROTO(inode) (NFS_SERVER(inode)->rpc_ops)
192 #define NFS_ADDR(inode) (RPC_PEERADDR(NFS_CLIENT(inode)))
193 #define NFS_COOKIEVERF(inode) (NFS_I(inode)->cookieverf)
194 #define NFS_READTIME(inode) (NFS_I(inode)->read_cache_jiffies)
195 #define NFS_CHANGE_ATTR(inode) (NFS_I(inode)->change_attr)
196 #define NFS_ATTRTIMEO(inode) (NFS_I(inode)->attrtimeo)
197 #define NFS_MINATTRTIMEO(inode) \
198 (S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmin \
199 : NFS_SERVER(inode)->acregmin)
200 #define NFS_MAXATTRTIMEO(inode) \
201 (S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmax \
202 : NFS_SERVER(inode)->acregmax)
203 #define NFS_ATTRTIMEO_UPDATE(inode) (NFS_I(inode)->attrtimeo_timestamp)
205 #define NFS_FLAGS(inode) (NFS_I(inode)->flags)
206 #define NFS_REVALIDATING(inode) (NFS_FLAGS(inode) & NFS_INO_REVALIDATING)
207 #define NFS_STALE(inode) (NFS_FLAGS(inode) & NFS_INO_STALE)
209 #define NFS_FILEID(inode) (NFS_I(inode)->fileid)
211 static inline int nfs_caches_unstable(struct inode *inode)
213 return atomic_read(&NFS_I(inode)->data_updates) != 0;
216 static inline void NFS_CACHEINV(struct inode *inode)
218 if (!nfs_caches_unstable(inode))
219 NFS_FLAGS(inode) |= NFS_INO_INVALID_ATTR;
222 static inline int nfs_server_capable(struct inode *inode, int cap)
224 return NFS_SERVER(inode)->caps & cap;
227 static inline int NFS_USE_READDIRPLUS(struct inode *inode)
229 return NFS_FLAGS(inode) & NFS_INO_ADVISE_RDPLUS;
233 loff_t page_offset(struct page *page)
235 return ((loff_t)page->index) << PAGE_CACHE_SHIFT;
239 * nfs_save_change_attribute - Returns the inode attribute change cookie
240 * @inode - pointer to inode
241 * The "change attribute" is updated every time we finish an operation
242 * that will result in a metadata change on the server.
244 static inline long nfs_save_change_attribute(struct inode *inode)
246 return NFS_I(inode)->cache_change_attribute;
250 * nfs_verify_change_attribute - Detects NFS inode cache updates
251 * @inode - pointer to inode
252 * @chattr - previously saved change attribute
253 * Return "false" if metadata has been updated (or is in the process of
254 * being updated) since the change attribute was saved.
256 static inline int nfs_verify_change_attribute(struct inode *inode, unsigned long chattr)
258 return !nfs_caches_unstable(inode)
259 && chattr == NFS_I(inode)->cache_change_attribute;
263 * linux/fs/nfs/inode.c
265 extern void nfs_zap_caches(struct inode *);
266 extern struct inode *nfs_fhget(struct super_block *, struct nfs_fh *,
268 extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *);
269 extern int nfs_getattr(struct vfsmount *, struct dentry *, struct kstat *);
270 extern int nfs_permission(struct inode *, int, struct nameidata *);
271 extern void nfs_set_mmcred(struct inode *, struct rpc_cred *);
272 extern int nfs_open(struct inode *, struct file *);
273 extern int nfs_release(struct inode *, struct file *);
274 extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
275 extern int nfs_setattr(struct dentry *, struct iattr *);
276 extern void nfs_begin_attr_update(struct inode *);
277 extern void nfs_end_attr_update(struct inode *);
278 extern void nfs_begin_data_update(struct inode *);
279 extern void nfs_end_data_update(struct inode *);
280 extern void nfs_end_data_update_defer(struct inode *);
282 /* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */
283 extern u32 root_nfs_parse_addr(char *name); /*__init*/
286 * linux/fs/nfs/file.c
288 extern struct inode_operations nfs_file_inode_operations;
289 extern struct file_operations nfs_file_operations;
290 extern struct address_space_operations nfs_file_aops;
292 static __inline__ struct rpc_cred *
293 nfs_file_cred(struct file *file)
295 struct rpc_cred *cred = NULL;
297 cred = (struct rpc_cred *)file->private_data;
299 BUG_ON(cred && cred->cr_magic != RPCAUTH_CRED_MAGIC);
305 * linux/fs/nfs/direct.c
307 extern ssize_t nfs_direct_IO(int, struct kiocb *, const struct iovec *, loff_t,
313 extern struct inode_operations nfs_dir_inode_operations;
314 extern struct file_operations nfs_dir_operations;
315 extern struct dentry_operations nfs_dentry_operations;
318 * linux/fs/nfs/symlink.c
320 extern struct inode_operations nfs_symlink_inode_operations;
323 * linux/fs/nfs/locks.c
325 extern int nfs_lock(struct file *, int, struct file_lock *);
328 * linux/fs/nfs/unlink.c
330 extern int nfs_async_unlink(struct dentry *);
331 extern void nfs_complete_unlink(struct dentry *);
334 * linux/fs/nfs/write.c
336 extern int nfs_writepage(struct page *page, struct writeback_control *wbc);
337 extern int nfs_writepages(struct address_space *, struct writeback_control *);
338 extern int nfs_flush_incompatible(struct file *file, struct page *page);
339 extern int nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
340 extern void nfs_writeback_done(struct rpc_task *task);
342 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
343 extern void nfs_commit_done(struct rpc_task *);
347 * Try to write back everything synchronously (but check the
350 extern int nfs_sync_inode(struct inode *, unsigned long, unsigned int, int);
351 extern int nfs_flush_inode(struct inode *, unsigned long, unsigned int, int);
352 extern int nfs_flush_list(struct list_head *, int, int);
353 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
354 extern int nfs_commit_inode(struct inode *, unsigned long, unsigned int, int);
355 extern int nfs_commit_list(struct list_head *, int);
358 nfs_commit_inode(struct inode *inode, unsigned long idx_start, unsigned int npages, int how)
365 nfs_have_writebacks(struct inode *inode)
367 return NFS_I(inode)->npages != 0;
371 nfs_wb_all(struct inode *inode)
373 int error = nfs_sync_inode(inode, 0, 0, FLUSH_WAIT);
374 return (error < 0) ? error : 0;
378 * Write back all requests on one page - we do this before reading it.
380 static inline int nfs_wb_page_priority(struct inode *inode, struct page* page, int how)
382 int error = nfs_sync_inode(inode, page->index, 1,
383 how | FLUSH_WAIT | FLUSH_STABLE);
384 return (error < 0) ? error : 0;
387 static inline int nfs_wb_page(struct inode *inode, struct page* page)
389 return nfs_wb_page_priority(inode, page, 0);
392 /* Hack for future NFS swap support */
394 # define IS_SWAPFILE(inode) (0)
398 * linux/fs/nfs/read.c
400 extern int nfs_readpage(struct file *, struct page *);
401 extern int nfs_readpages(struct file *, struct address_space *,
402 struct list_head *, unsigned);
403 extern int nfs_pagein_list(struct list_head *, int);
404 extern void nfs_readpage_result(struct rpc_task *);
407 * linux/fs/mount_clnt.c
408 * (Used only by nfsroot module)
410 extern int nfsroot_mount(struct sockaddr_in *, char *, struct nfs_fh *,
417 static inline int nfs_attribute_timeout(struct inode *inode)
419 struct nfs_inode *nfsi = NFS_I(inode);
421 return time_after(jiffies, nfsi->read_cache_jiffies+nfsi->attrtimeo);
425 * nfs_revalidate_inode - Revalidate the inode attributes
426 * @server - pointer to nfs_server struct
427 * @inode - pointer to inode struct
429 * Updates inode attribute information by retrieving the data from the server.
431 static inline int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
433 if (!(NFS_FLAGS(inode) & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))
434 && !nfs_attribute_timeout(inode))
435 return NFS_STALE(inode) ? -ESTALE : 0;
436 return __nfs_revalidate_inode(server, inode);
440 nfs_size_to_loff_t(__u64 size)
442 loff_t maxsz = (((loff_t) ULONG_MAX) << PAGE_CACHE_SHIFT) + PAGE_CACHE_SIZE - 1;
445 return (loff_t) size;
449 nfs_fileid_to_ino_t(u64 fileid)
451 ino_t ino = (ino_t) fileid;
452 if (sizeof(ino_t) < sizeof(u64))
453 ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8;
459 extern void * nfs_root_data(void);
461 #define nfs_wait_event(clnt, wq, condition) \
464 if (clnt->cl_intr) { \
466 rpc_clnt_sigmask(clnt, &oldmask); \
467 __retval = wait_event_interruptible(wq, condition); \
468 rpc_clnt_sigunmask(clnt, &oldmask); \
470 wait_event(wq, condition); \
474 #define NFS_JUKEBOX_RETRY_TIME (5 * HZ)
481 * In a seqid-mutating op, this macro controls which error return
482 * values trigger incrementation of the seqid.
485 * The client MUST monotonically increment the sequence number for the
486 * CLOSE, LOCK, LOCKU, OPEN, OPEN_CONFIRM, and OPEN_DOWNGRADE
487 * operations. This is true even in the event that the previous
488 * operation that used the sequence number received an error. The only
489 * exception to this rule is if the previous operation received one of
490 * the following errors: NFSERR_STALE_CLIENTID, NFSERR_STALE_STATEID,
491 * NFSERR_BAD_STATEID, NFSERR_BAD_SEQID, NFSERR_BADXDR,
492 * NFSERR_RESOURCE, NFSERR_NOFILEHANDLE.
495 #define seqid_mutating_err(err) \
496 (((err) != NFSERR_STALE_CLIENTID) && \
497 ((err) != NFSERR_STALE_STATEID) && \
498 ((err) != NFSERR_BAD_STATEID) && \
499 ((err) != NFSERR_BAD_SEQID) && \
500 ((err) != NFSERR_BAD_XDR) && \
501 ((err) != NFSERR_RESOURCE) && \
502 ((err) != NFSERR_NOFILEHANDLE))
504 enum nfs4_client_state {
507 NFS4CLNT_SETUP_STATE,
511 * The nfs4_client identifies our client state to the server.
514 struct list_head cl_servers; /* Global list of servers */
515 struct in_addr cl_addr; /* Server identifier */
516 u64 cl_clientid; /* constant */
517 nfs4_verifier cl_confirm;
518 unsigned long cl_state;
524 * The following rwsem ensures exclusive access to the server
525 * while we recover the state following a lease expiration.
527 struct rw_semaphore cl_sem;
529 struct list_head cl_state_owners;
530 struct list_head cl_unused;
535 struct rpc_clnt * cl_rpcclient;
536 struct rpc_cred * cl_cred;
538 struct list_head cl_superblocks; /* List of nfs_server structs */
540 unsigned long cl_lease_time;
541 unsigned long cl_last_renewal;
542 struct work_struct cl_renewd;
543 struct work_struct cl_recoverd;
545 wait_queue_head_t cl_waitq;
546 struct rpc_wait_queue cl_rpcwaitq;
549 struct idmap * cl_idmap;
551 /* Our own IP address, as a null-terminated string.
552 * This is used to generate the clientid, and the callback address.
558 * NFS4 state_owners and lock_owners are simply labels for ordered
559 * sequences of RPC calls. Their sole purpose is to provide once-only
560 * semantics by allowing the server to identify replayed requests.
562 * The ->so_sema is held during all state_owner seqid-mutating operations:
563 * OPEN, OPEN_DOWNGRADE, and CLOSE. Its purpose is to properly serialize
566 struct nfs4_state_owner {
567 struct list_head so_list; /* per-clientid list of state_owners */
568 struct nfs4_client *so_client;
569 u32 so_id; /* 32-bit identifier, unique */
570 struct semaphore so_sema;
571 u32 so_seqid; /* protected by so_sema */
572 unsigned int so_flags; /* protected by so_sema */
576 struct rpc_cred *so_cred; /* Associated cred */
577 struct list_head so_states;
581 * struct nfs4_state maintains the client-side state for a given
582 * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
585 * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
586 * we need to know how many files are open for reading or writing on a
587 * given inode. This information too is stored here.
589 * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
592 struct nfs4_lock_state {
593 struct list_head ls_locks; /* Other lock stateids */
594 fl_owner_t ls_owner; /* POSIX lock owner */
595 struct nfs4_state * ls_parent; /* Parent nfs4_state */
598 nfs4_stateid ls_stateid;
602 /* bits for nfs4_state->flags */
608 struct list_head open_states; /* List of states for the same state_owner */
609 struct list_head inode_states; /* List of states for the same inode */
610 struct list_head lock_states; /* List of subservient lock stateids */
612 struct nfs4_state_owner *owner; /* Pointer to the open owner */
613 struct inode *inode; /* Pointer to the inode */
615 unsigned long flags; /* Do we hold any locks? */
616 struct semaphore lock_sema; /* Serializes file locking operations */
617 rwlock_t state_lock; /* Protects the lock_states list */
619 nfs4_stateid stateid;
621 unsigned int nreaders;
622 unsigned int nwriters;
623 int state; /* State on the server (R,W, or RW) */
628 extern struct dentry_operations nfs4_dentry_operations;
629 extern struct inode_operations nfs4_dir_inode_operations;
632 extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short);
633 extern int nfs4_proc_setclientid_confirm(struct nfs4_client *);
634 extern int nfs4_open_reclaim(struct nfs4_state_owner *, struct nfs4_state *);
635 extern int nfs4_proc_async_renew(struct nfs4_client *);
636 extern int nfs4_proc_renew(struct nfs4_client *);
637 extern int nfs4_do_close(struct inode *, struct nfs4_state *);
638 int nfs4_do_downgrade(struct inode *inode, struct nfs4_state *state, mode_t mode);
639 extern int nfs4_wait_clnt_recover(struct rpc_clnt *, struct nfs4_client *);
640 extern struct inode *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
641 extern int nfs4_open_revalidate(struct inode *, struct dentry *, int);
644 extern void nfs4_schedule_state_renewal(struct nfs4_client *);
645 extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
646 extern void nfs4_kill_renewd(struct nfs4_client *);
649 extern void init_nfsv4_state(struct nfs_server *);
650 extern void destroy_nfsv4_state(struct nfs_server *);
651 extern struct nfs4_client *nfs4_get_client(struct in_addr *);
652 extern void nfs4_put_client(struct nfs4_client *clp);
653 extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
655 extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
656 extern void nfs4_put_state_owner(struct nfs4_state_owner *);
657 extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
658 extern void nfs4_put_open_state(struct nfs4_state *);
659 extern void nfs4_close_state(struct nfs4_state *, mode_t);
660 extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode);
661 extern void nfs4_increment_seqid(int status, struct nfs4_state_owner *sp);
662 extern int nfs4_handle_error(struct nfs_server *, int);
663 extern void nfs4_schedule_state_recovery(struct nfs4_client *);
664 extern struct nfs4_lock_state *nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t);
665 extern struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t);
666 extern void nfs4_put_lock_state(struct nfs4_lock_state *state);
667 extern void nfs4_increment_lock_seqid(int status, struct nfs4_lock_state *ls);
668 extern void nfs4_notify_setlk(struct inode *, struct file_lock *, struct nfs4_lock_state *);
669 extern void nfs4_notify_unlck(struct inode *, struct file_lock *, struct nfs4_lock_state *);
670 extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
674 struct nfs4_mount_data;
676 #define init_nfsv4_state(server) do { } while (0)
677 #define destroy_nfsv4_state(server) do { } while (0)
678 #define nfs4_put_state_owner(inode, owner) do { } while (0)
679 #define nfs4_put_open_state(state) do { } while (0)
680 #define nfs4_renewd_prepare_shutdown(server) do { } while (0)
683 #endif /* __KERNEL__ */
688 #define NFSDBG_VFS 0x0001
689 #define NFSDBG_DIRCACHE 0x0002
690 #define NFSDBG_LOOKUPCACHE 0x0004
691 #define NFSDBG_PAGECACHE 0x0008
692 #define NFSDBG_PROC 0x0010
693 #define NFSDBG_XDR 0x0020
694 #define NFSDBG_FILE 0x0040
695 #define NFSDBG_ROOT 0x0080
696 #define NFSDBG_ALL 0xFFFF
701 # define ifdebug(fac) if (unlikely(nfs_debug & NFSDBG_##fac))
703 # define ifdebug(fac) if (0)
705 #endif /* __KERNEL */