File: /usr/include/linux/nfs_fs.h

1     /*
2      *  linux/include/linux/nfs_fs.h
3      *
4      *  Copyright (C) 1992  Rick Sladkey
5      *
6      *  OS-specific nfs filesystem definitions and declarations
7      */
8     
9     #ifndef _LINUX_NFS_FS_H
10     #define _LINUX_NFS_FS_H
11     
12     #include <linux/config.h>
13     #include <linux/in.h>
14     #include <linux/mm.h>
15     #include <linux/pagemap.h>
16     
17     #include <linux/sunrpc/debug.h>
18     #include <linux/sunrpc/auth.h>
19     
20     #include <linux/nfs.h>
21     #include <linux/nfs2.h>
22     #include <linux/nfs3.h>
23     #include <linux/nfs_xdr.h>
24     
25     /*
26      * Enable debugging support for nfs client.
27      * Requires RPC_DEBUG.
28      */
29     #ifdef RPC_DEBUG
30     # define NFS_DEBUG
31     #endif
32     
33     /*
34      * NFS_MAX_DIRCACHE controls the number of simultaneously cached
35      * directory chunks. Each chunk holds the list of nfs_entry's returned
36      * in a single readdir call in a memory region of size PAGE_SIZE.
37      *
38      * Note that at most server->rsize bytes of the cache memory are used.
39      */
40     #define NFS_MAX_DIRCACHE		16
41     
42     #define NFS_MAX_FILE_IO_BUFFER_SIZE	32768
43     #define NFS_DEF_FILE_IO_BUFFER_SIZE	4096
44     
45     /*
46      * The upper limit on timeouts for the exponential backoff algorithm.
47      */
48     #define NFS_MAX_RPC_TIMEOUT		(6*HZ)
49     #define NFS_READ_DELAY			(2*HZ)
50     #define NFS_WRITEBACK_DELAY		(5*HZ)
51     #define NFS_WRITEBACK_LOCKDELAY		(60*HZ)
52     #define NFS_COMMIT_DELAY		(5*HZ)
53     
54     /*
55      * Size of the lookup cache in units of number of entries cached.
56      * It is better not to make this too large although the optimum
57      * depends on a usage and environment.
58      */
59     #define NFS_LOOKUP_CACHE_SIZE		64
60     
61     /*
62      * superblock magic number for NFS
63      */
64     #define NFS_SUPER_MAGIC			0x6969
65     
66     #define NFS_FH(inode)			(&(inode)->u.nfs_i.fh)
67     #define NFS_SERVER(inode)		(&(inode)->i_sb->u.nfs_sb.s_server)
68     #define NFS_CLIENT(inode)		(NFS_SERVER(inode)->client)
69     #define NFS_PROTO(inode)		(NFS_SERVER(inode)->rpc_ops)
70     #define NFS_REQUESTLIST(inode)		(NFS_SERVER(inode)->rw_requests)
71     #define NFS_ADDR(inode)			(RPC_PEERADDR(NFS_CLIENT(inode)))
72     #define NFS_CONGESTED(inode)		(RPC_CONGESTED(NFS_CLIENT(inode)))
73     #define NFS_COOKIEVERF(inode)		((inode)->u.nfs_i.cookieverf)
74     #define NFS_READTIME(inode)		((inode)->u.nfs_i.read_cache_jiffies)
75     #define NFS_CACHE_CTIME(inode)		((inode)->u.nfs_i.read_cache_ctime)
76     #define NFS_CACHE_MTIME(inode)		((inode)->u.nfs_i.read_cache_mtime)
77     #define NFS_CACHE_ATIME(inode)		((inode)->u.nfs_i.read_cache_atime)
78     #define NFS_CACHE_ISIZE(inode)		((inode)->u.nfs_i.read_cache_isize)
79     #define NFS_NEXTSCAN(inode)		((inode)->u.nfs_i.nextscan)
80     #define NFS_CACHEINV(inode) \
81     do { \
82     	NFS_READTIME(inode) = jiffies - NFS_MAXATTRTIMEO(inode) - 1; \
83     } while (0)
84     #define NFS_ATTRTIMEO(inode)		((inode)->u.nfs_i.attrtimeo)
85     #define NFS_MINATTRTIMEO(inode) \
86     	(S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmin \
87     			       : NFS_SERVER(inode)->acregmin)
88     #define NFS_MAXATTRTIMEO(inode) \
89     	(S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmax \
90     			       : NFS_SERVER(inode)->acregmax)
91     #define NFS_ATTRTIMEO_UPDATE(inode)	((inode)->u.nfs_i.attrtimeo_timestamp)
92     
93     #define NFS_FLAGS(inode)		((inode)->u.nfs_i.flags)
94     #define NFS_REVALIDATING(inode)		(NFS_FLAGS(inode) & NFS_INO_REVALIDATING)
95     #define NFS_STALE(inode)		(NFS_FLAGS(inode) & NFS_INO_STALE)
96     
97     #define NFS_FILEID(inode)		((inode)->u.nfs_i.fileid)
98     #define NFS_FSID(inode)			((inode)->u.nfs_i.fsid)
99     
100     /* Inode Flags */
101     #define NFS_USE_READDIRPLUS(inode)	((NFS_FLAGS(inode) & NFS_INO_ADVISE_RDPLUS) ? 1 : 0)
102     
103     /*
104      * These are the default flags for swap requests
105      */
106     #define NFS_RPC_SWAPFLAGS		(RPC_TASK_SWAPPER|RPC_TASK_ROOTCREDS)
107     
108     /* Flags in the RPC client structure */
109     #define NFS_CLNTF_BUFSIZE	0x0001	/* readdir buffer in longwords */
110     
111     #define NFS_RW_SYNC		0x0001	/* O_SYNC handling */
112     #define NFS_RW_SWAP		0x0002	/* This is a swap request */
113     
114     /*
115      * When flushing a cluster of dirty pages, there can be different
116      * strategies:
117      */
118     #define FLUSH_AGING		0	/* only flush old buffers */
119     #define FLUSH_SYNC		1	/* file being synced, or contention */
120     #define FLUSH_WAIT		2	/* wait for completion */
121     #define FLUSH_STABLE		4	/* commit to stable storage */
122     
123     static inline
124     loff_t page_offset(struct page *page)
125     {
126     	return ((loff_t)page->index) << PAGE_CACHE_SHIFT;
127     }
128     
129     static inline
130     unsigned long page_index(struct page *page)
131     {
132     	return page->index;
133     }
134     
135     #ifdef __KERNEL__
136     /*
137      * linux/fs/nfs/inode.c
138      */
139     extern struct super_block *nfs_read_super(struct super_block *, void *, int);
140     extern int init_nfs_fs(void);
141     extern void nfs_zap_caches(struct inode *);
142     extern int nfs_inode_is_stale(struct inode *, struct nfs_fh *,
143     				struct nfs_fattr *);
144     extern struct inode *nfs_fhget(struct dentry *, struct nfs_fh *,
145     				struct nfs_fattr *);
146     extern int nfs_refresh_inode(struct inode *, struct nfs_fattr *);
147     extern int nfs_revalidate(struct dentry *);
148     extern int nfs_permission(struct inode *, int);
149     extern int nfs_open(struct inode *, struct file *);
150     extern int nfs_release(struct inode *, struct file *);
151     extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
152     extern int nfs_notify_change(struct dentry *, struct iattr *);
153     
154     /*
155      * linux/fs/nfs/file.c
156      */
157     extern struct inode_operations nfs_file_inode_operations;
158     extern struct file_operations nfs_file_operations;
159     extern struct address_space_operations nfs_file_aops;
160     
161     static __inline__ struct rpc_cred *
162     nfs_file_cred(struct file *file)
163     {
164     	struct rpc_cred *cred = (struct rpc_cred *)(file->private_data);
165     #ifdef RPC_DEBUG
166     	if (cred && cred->cr_magic != RPCAUTH_CRED_MAGIC)
167     		BUG();
168     #endif
169     	return cred;
170     }
171     
172     /*
173      * linux/fs/nfs/dir.c
174      */
175     extern struct inode_operations nfs_dir_inode_operations;
176     extern struct file_operations nfs_dir_operations;
177     extern struct dentry_operations nfs_dentry_operations;
178     
179     /*
180      * linux/fs/nfs/symlink.c
181      */
182     extern struct inode_operations nfs_symlink_inode_operations;
183     
184     /*
185      * linux/fs/nfs/locks.c
186      */
187     extern int nfs_lock(struct file *, int, struct file_lock *);
188     
189     /*
190      * linux/fs/nfs/unlink.c
191      */
192     extern int  nfs_async_unlink(struct dentry *);
193     extern void nfs_complete_unlink(struct dentry *);
194     
195     /*
196      * linux/fs/nfs/write.c
197      */
198     extern int  nfs_writepage(struct page *);
199     extern int  nfs_flush_incompatible(struct file *file, struct page *page);
200     extern int  nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
201     /*
202      * Try to write back everything synchronously (but check the
203      * return value!)
204      */
205     extern int  nfs_sync_file(struct inode *, struct file *, unsigned long, unsigned int, int);
206     extern int  nfs_flush_file(struct inode *, struct file *, unsigned long, unsigned int, int);
207     extern int  nfs_flush_timeout(struct inode *, int);
208     #ifdef CONFIG_NFS_V3
209     extern int  nfs_commit_file(struct inode *, struct file *, unsigned long, unsigned int, int);
210     extern int  nfs_commit_timeout(struct inode *, int);
211     #endif
212     
213     static inline int
214     nfs_have_read(struct inode *inode)
215     {
216     	return !list_empty(&inode->u.nfs_i.read);
217     }
218     
219     static inline int
220     nfs_have_writebacks(struct inode *inode)
221     {
222     	return !list_empty(&inode->u.nfs_i.writeback);
223     }
224     
225     static inline int
226     nfs_wb_all(struct inode *inode)
227     {
228     	int error = nfs_sync_file(inode, 0, 0, 0, FLUSH_WAIT);
229     	return (error < 0) ? error : 0;
230     }
231     
232     /*
233      * Write back all requests on one page - we do this before reading it.
234      */
235     static inline int
236     nfs_wb_page(struct inode *inode, struct page* page)
237     {
238     	int error = nfs_sync_file(inode, 0, page_index(page), 1, FLUSH_WAIT | FLUSH_STABLE);
239     	return (error < 0) ? error : 0;
240     }
241     
242     /*
243      * Write back all pending writes for one user.. 
244      */
245     static inline int
246     nfs_wb_file(struct inode *inode, struct file *file)
247     {
248     	int error = nfs_sync_file(inode, file, 0, 0, FLUSH_WAIT);
249     	return (error < 0) ? error : 0;
250     }
251     
252     /*
253      * linux/fs/nfs/read.c
254      */
255     extern int  nfs_readpage(struct file *, struct page *);
256     extern int  nfs_pagein_inode(struct inode *, unsigned long, unsigned int);
257     extern int  nfs_pagein_timeout(struct inode *);
258     
259     /*
260      * linux/fs/mount_clnt.c
261      * (Used only by nfsroot module)
262      */
263     extern int  nfs_mount(struct sockaddr_in *, char *, struct nfs3_fh *);
264     extern int  nfs3_mount(struct sockaddr_in *, char *, struct nfs3_fh *);
265     
266     /*
267      * inline functions
268      */
269     static inline int
270     nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
271     {
272     	if (time_before(jiffies, NFS_READTIME(inode)+NFS_ATTRTIMEO(inode)))
273     		return NFS_STALE(inode) ? -ESTALE : 0;
274     	return __nfs_revalidate_inode(server, inode);
275     }
276     
277     static inline loff_t
278     nfs_size_to_loff_t(__u64 size)
279     {
280     	loff_t maxsz = (((loff_t) ULONG_MAX) << PAGE_CACHE_SHIFT) + PAGE_CACHE_SIZE - 1;
281     	if (size > maxsz)
282     		return maxsz;
283     	return (loff_t) size;
284     }
285     
286     static inline ino_t
287     nfs_fileid_to_ino_t(u64 fileid)
288     {
289     	ino_t ino = (ino_t) fileid;
290     	if (sizeof(ino_t) < sizeof(u64))
291     		ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8;
292     	return ino;
293     }
294     
295     static inline time_t
296     nfs_time_to_secs(__u64 time)
297     {
298     	return (time_t)(time >> 32);
299     }
300     
301     /* NFS root */
302     
303     extern void * nfs_root_data(void);
304     
305     #define nfs_wait_event(clnt, wq, condition)				\
306     ({									\
307     	int __retval = 0;						\
308     	if (clnt->cl_intr) {						\
309     		sigset_t oldmask;					\
310     		rpc_clnt_sigmask(clnt, &oldmask);			\
311     		__retval = wait_event_interruptible(wq, condition);	\
312     		rpc_clnt_sigunmask(clnt, &oldmask);			\
313     	} else								\
314     		wait_event(wq, condition);				\
315     	__retval;							\
316     })
317     
318     #endif /* __KERNEL__ */
319     
320     /*
321      * NFS debug flags
322      */
323     #define NFSDBG_VFS		0x0001
324     #define NFSDBG_DIRCACHE		0x0002
325     #define NFSDBG_LOOKUPCACHE	0x0004
326     #define NFSDBG_PAGECACHE	0x0008
327     #define NFSDBG_PROC		0x0010
328     #define NFSDBG_XDR		0x0020
329     #define NFSDBG_FILE		0x0040
330     #define NFSDBG_ROOT		0x0080
331     #define NFSDBG_ALL		0xFFFF
332     
333     #ifdef __KERNEL__
334     # undef ifdebug
335     # ifdef NFS_DEBUG
336     #  define ifdebug(fac)		if (nfs_debug & NFSDBG_##fac)
337     # else
338     #  define ifdebug(fac)		if (0)
339     # endif
340     #endif /* __KERNEL */
341     
342     #endif
343