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,
309 extern ssize_t nfs_file_direct_read(struct kiocb *iocb, char __user *buf,
310 size_t count, loff_t pos);
311 extern ssize_t nfs_file_direct_write(struct kiocb *iocb, const char __user *buf,
312 size_t count, loff_t pos);
317 extern struct inode_operations nfs_dir_inode_operations;
318 extern struct file_operations nfs_dir_operations;
319 extern struct dentry_operations nfs_dentry_operations;
322 * linux/fs/nfs/symlink.c
324 extern struct inode_operations nfs_symlink_inode_operations;
327 * linux/fs/nfs/locks.c
329 extern int nfs_lock(struct file *, int, struct file_lock *);
332 * linux/fs/nfs/unlink.c
334 extern int nfs_async_unlink(struct dentry *);
335 extern void nfs_complete_unlink(struct dentry *);
338 * linux/fs/nfs/write.c
340 extern int nfs_writepage(struct page *page, struct writeback_control *wbc);
341 extern int nfs_writepages(struct address_space *, struct writeback_control *);
342 extern int nfs_flush_incompatible(struct file *file, struct page *page);
343 extern int nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
344 extern void nfs_writeback_done(struct rpc_task *task);
346 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
347 extern void nfs_commit_done(struct rpc_task *);
351 * Try to write back everything synchronously (but check the
354 extern int nfs_sync_inode(struct inode *, unsigned long, unsigned int, int);
355 extern int nfs_flush_inode(struct inode *, unsigned long, unsigned int, int);
356 extern int nfs_flush_list(struct list_head *, int, int);
357 #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
358 extern int nfs_commit_inode(struct inode *, unsigned long, unsigned int, int);
359 extern int nfs_commit_list(struct list_head *, int);
362 nfs_commit_inode(struct inode *inode, unsigned long idx_start, unsigned int npages, int how)
369 nfs_have_writebacks(struct inode *inode)
371 return NFS_I(inode)->npages != 0;
375 nfs_wb_all(struct inode *inode)
377 int error = nfs_sync_inode(inode, 0, 0, FLUSH_WAIT);
378 return (error < 0) ? error : 0;
382 * Write back all requests on one page - we do this before reading it.
384 static inline int nfs_wb_page_priority(struct inode *inode, struct page* page, int how)
386 int error = nfs_sync_inode(inode, page->index, 1,
387 how | FLUSH_WAIT | FLUSH_STABLE);
388 return (error < 0) ? error : 0;
391 static inline int nfs_wb_page(struct inode *inode, struct page* page)
393 return nfs_wb_page_priority(inode, page, 0);
396 /* Hack for future NFS swap support */
398 # define IS_SWAPFILE(inode) (0)
402 * linux/fs/nfs/read.c
404 extern int nfs_readpage(struct file *, struct page *);
405 extern int nfs_readpages(struct file *, struct address_space *,
406 struct list_head *, unsigned);
407 extern int nfs_pagein_list(struct list_head *, int);
408 extern void nfs_readpage_result(struct rpc_task *);
411 * linux/fs/mount_clnt.c
412 * (Used only by nfsroot module)
414 extern int nfsroot_mount(struct sockaddr_in *, char *, struct nfs_fh *,
421 static inline int nfs_attribute_timeout(struct inode *inode)
423 struct nfs_inode *nfsi = NFS_I(inode);
425 return time_after(jiffies, nfsi->read_cache_jiffies+nfsi->attrtimeo);
429 * nfs_revalidate_inode - Revalidate the inode attributes
430 * @server - pointer to nfs_server struct
431 * @inode - pointer to inode struct
433 * Updates inode attribute information by retrieving the data from the server.
435 static inline int nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
437 if (!(NFS_FLAGS(inode) & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA))
438 && !nfs_attribute_timeout(inode))
439 return NFS_STALE(inode) ? -ESTALE : 0;
440 return __nfs_revalidate_inode(server, inode);
444 nfs_size_to_loff_t(__u64 size)
446 loff_t maxsz = (((loff_t) ULONG_MAX) << PAGE_CACHE_SHIFT) + PAGE_CACHE_SIZE - 1;
449 return (loff_t) size;
453 nfs_fileid_to_ino_t(u64 fileid)
455 ino_t ino = (ino_t) fileid;
456 if (sizeof(ino_t) < sizeof(u64))
457 ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8;
463 extern void * nfs_root_data(void);
465 #define nfs_wait_event(clnt, wq, condition) \
468 if (clnt->cl_intr) { \
470 rpc_clnt_sigmask(clnt, &oldmask); \
471 __retval = wait_event_interruptible(wq, condition); \
472 rpc_clnt_sigunmask(clnt, &oldmask); \
474 wait_event(wq, condition); \
478 #define NFS_JUKEBOX_RETRY_TIME (5 * HZ)
485 * In a seqid-mutating op, this macro controls which error return
486 * values trigger incrementation of the seqid.
489 * The client MUST monotonically increment the sequence number for the
490 * CLOSE, LOCK, LOCKU, OPEN, OPEN_CONFIRM, and OPEN_DOWNGRADE
491 * operations. This is true even in the event that the previous
492 * operation that used the sequence number received an error. The only
493 * exception to this rule is if the previous operation received one of
494 * the following errors: NFSERR_STALE_CLIENTID, NFSERR_STALE_STATEID,
495 * NFSERR_BAD_STATEID, NFSERR_BAD_SEQID, NFSERR_BADXDR,
496 * NFSERR_RESOURCE, NFSERR_NOFILEHANDLE.
499 #define seqid_mutating_err(err) \
500 (((err) != NFSERR_STALE_CLIENTID) && \
501 ((err) != NFSERR_STALE_STATEID) && \
502 ((err) != NFSERR_BAD_STATEID) && \
503 ((err) != NFSERR_BAD_SEQID) && \
504 ((err) != NFSERR_BAD_XDR) && \
505 ((err) != NFSERR_RESOURCE) && \
506 ((err) != NFSERR_NOFILEHANDLE))
508 enum nfs4_client_state {
511 NFS4CLNT_SETUP_STATE,
515 * The nfs4_client identifies our client state to the server.
518 struct list_head cl_servers; /* Global list of servers */
519 struct in_addr cl_addr; /* Server identifier */
520 u64 cl_clientid; /* constant */
521 nfs4_verifier cl_confirm;
522 unsigned long cl_state;
528 * The following rwsem ensures exclusive access to the server
529 * while we recover the state following a lease expiration.
531 struct rw_semaphore cl_sem;
533 struct list_head cl_state_owners;
534 struct list_head cl_unused;
539 struct rpc_clnt * cl_rpcclient;
540 struct rpc_cred * cl_cred;
542 struct list_head cl_superblocks; /* List of nfs_server structs */
544 unsigned long cl_lease_time;
545 unsigned long cl_last_renewal;
546 struct work_struct cl_renewd;
547 struct work_struct cl_recoverd;
549 wait_queue_head_t cl_waitq;
550 struct rpc_wait_queue cl_rpcwaitq;
553 struct idmap * cl_idmap;
555 /* Our own IP address, as a null-terminated string.
556 * This is used to generate the clientid, and the callback address.
562 * NFS4 state_owners and lock_owners are simply labels for ordered
563 * sequences of RPC calls. Their sole purpose is to provide once-only
564 * semantics by allowing the server to identify replayed requests.
566 * The ->so_sema is held during all state_owner seqid-mutating operations:
567 * OPEN, OPEN_DOWNGRADE, and CLOSE. Its purpose is to properly serialize
570 struct nfs4_state_owner {
571 struct list_head so_list; /* per-clientid list of state_owners */
572 struct nfs4_client *so_client;
573 u32 so_id; /* 32-bit identifier, unique */
574 struct semaphore so_sema;
575 u32 so_seqid; /* protected by so_sema */
576 unsigned int so_flags; /* protected by so_sema */
580 struct rpc_cred *so_cred; /* Associated cred */
581 struct list_head so_states;
585 * struct nfs4_state maintains the client-side state for a given
586 * (state_owner,inode) tuple (OPEN) or state_owner (LOCK).
589 * In order to know when to OPEN_DOWNGRADE or CLOSE the state on the server,
590 * we need to know how many files are open for reading or writing on a
591 * given inode. This information too is stored here.
593 * LOCK: one nfs4_state (LOCK) to hold the lock stateid nfs4_state(OPEN)
596 struct nfs4_lock_state {
597 struct list_head ls_locks; /* Other lock stateids */
598 fl_owner_t ls_owner; /* POSIX lock owner */
599 struct nfs4_state * ls_parent; /* Parent nfs4_state */
602 nfs4_stateid ls_stateid;
606 /* bits for nfs4_state->flags */
612 struct list_head open_states; /* List of states for the same state_owner */
613 struct list_head inode_states; /* List of states for the same inode */
614 struct list_head lock_states; /* List of subservient lock stateids */
616 struct nfs4_state_owner *owner; /* Pointer to the open owner */
617 struct inode *inode; /* Pointer to the inode */
619 unsigned long flags; /* Do we hold any locks? */
620 struct semaphore lock_sema; /* Serializes file locking operations */
621 rwlock_t state_lock; /* Protects the lock_states list */
623 nfs4_stateid stateid;
625 unsigned int nreaders;
626 unsigned int nwriters;
627 int state; /* State on the server (R,W, or RW) */
632 extern struct dentry_operations nfs4_dentry_operations;
633 extern struct inode_operations nfs4_dir_inode_operations;
636 extern int nfs4_proc_setclientid(struct nfs4_client *, u32, unsigned short);
637 extern int nfs4_proc_setclientid_confirm(struct nfs4_client *);
638 extern int nfs4_open_reclaim(struct nfs4_state_owner *, struct nfs4_state *);
639 extern int nfs4_proc_async_renew(struct nfs4_client *);
640 extern int nfs4_proc_renew(struct nfs4_client *);
641 extern int nfs4_do_close(struct inode *, struct nfs4_state *);
642 int nfs4_do_downgrade(struct inode *inode, struct nfs4_state *state, mode_t mode);
643 extern int nfs4_wait_clnt_recover(struct rpc_clnt *, struct nfs4_client *);
644 extern struct inode *nfs4_atomic_open(struct inode *, struct dentry *, struct nameidata *);
645 extern int nfs4_open_revalidate(struct inode *, struct dentry *, int);
648 extern void nfs4_schedule_state_renewal(struct nfs4_client *);
649 extern void nfs4_renewd_prepare_shutdown(struct nfs_server *);
650 extern void nfs4_kill_renewd(struct nfs4_client *);
653 extern void init_nfsv4_state(struct nfs_server *);
654 extern void destroy_nfsv4_state(struct nfs_server *);
655 extern struct nfs4_client *nfs4_get_client(struct in_addr *);
656 extern void nfs4_put_client(struct nfs4_client *clp);
657 extern u32 nfs4_alloc_lockowner_id(struct nfs4_client *);
659 extern struct nfs4_state_owner * nfs4_get_state_owner(struct nfs_server *, struct rpc_cred *);
660 extern void nfs4_put_state_owner(struct nfs4_state_owner *);
661 extern struct nfs4_state * nfs4_get_open_state(struct inode *, struct nfs4_state_owner *);
662 extern void nfs4_put_open_state(struct nfs4_state *);
663 extern void nfs4_close_state(struct nfs4_state *, mode_t);
664 extern struct nfs4_state *nfs4_find_state(struct inode *, struct rpc_cred *, mode_t mode);
665 extern void nfs4_increment_seqid(int status, struct nfs4_state_owner *sp);
666 extern int nfs4_handle_error(struct nfs_server *, int);
667 extern void nfs4_schedule_state_recovery(struct nfs4_client *);
668 extern struct nfs4_lock_state *nfs4_find_lock_state(struct nfs4_state *state, fl_owner_t);
669 extern struct nfs4_lock_state *nfs4_alloc_lock_state(struct nfs4_state *state, fl_owner_t);
670 extern void nfs4_put_lock_state(struct nfs4_lock_state *state);
671 extern void nfs4_increment_lock_seqid(int status, struct nfs4_lock_state *ls);
672 extern void nfs4_notify_setlk(struct inode *, struct file_lock *, struct nfs4_lock_state *);
673 extern void nfs4_notify_unlck(struct inode *, struct file_lock *, struct nfs4_lock_state *);
674 extern void nfs4_copy_stateid(nfs4_stateid *, struct nfs4_state *, fl_owner_t);
678 struct nfs4_mount_data;
680 #define init_nfsv4_state(server) do { } while (0)
681 #define destroy_nfsv4_state(server) do { } while (0)
682 #define nfs4_put_state_owner(inode, owner) do { } while (0)
683 #define nfs4_put_open_state(state) do { } while (0)
684 #define nfs4_renewd_prepare_shutdown(server) do { } while (0)
687 #endif /* __KERNEL__ */
692 #define NFSDBG_VFS 0x0001
693 #define NFSDBG_DIRCACHE 0x0002
694 #define NFSDBG_LOOKUPCACHE 0x0004
695 #define NFSDBG_PAGECACHE 0x0008
696 #define NFSDBG_PROC 0x0010
697 #define NFSDBG_XDR 0x0020
698 #define NFSDBG_FILE 0x0040
699 #define NFSDBG_ROOT 0x0080
700 #define NFSDBG_ALL 0xFFFF
705 # define ifdebug(fac) if (unlikely(nfs_debug & NFSDBG_##fac))
707 # define ifdebug(fac) if (0)
709 #endif /* __KERNEL */