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 #include <linux/sunrpc/clnt.h>
20
21 #include <linux/nfs.h>
22 #include <linux/nfs2.h>
23 #include <linux/nfs3.h>
24 #include <linux/nfs_xdr.h>
25
26 /*
27 * Enable debugging support for nfs client.
28 * Requires RPC_DEBUG.
29 */
30 #ifdef RPC_DEBUG
31 # define NFS_DEBUG
32 #endif
33
34 /*
35 * NFS_MAX_DIRCACHE controls the number of simultaneously cached
36 * directory chunks. Each chunk holds the list of nfs_entry's returned
37 * in a single readdir call in a memory region of size PAGE_SIZE.
38 *
39 * Note that at most server->rsize bytes of the cache memory are used.
40 */
41 #define NFS_MAX_DIRCACHE 16
42
43 #define NFS_MAX_FILE_IO_BUFFER_SIZE 32768
44 #define NFS_DEF_FILE_IO_BUFFER_SIZE 4096
45
46 /*
47 * The upper limit on timeouts for the exponential backoff algorithm.
48 */
49 #define NFS_MAX_RPC_TIMEOUT (6*HZ)
50 #define NFS_READ_DELAY (2*HZ)
51 #define NFS_WRITEBACK_DELAY (5*HZ)
52 #define NFS_WRITEBACK_LOCKDELAY (60*HZ)
53 #define NFS_COMMIT_DELAY (5*HZ)
54
55 /*
56 * Size of the lookup cache in units of number of entries cached.
57 * It is better not to make this too large although the optimum
58 * depends on a usage and environment.
59 */
60 #define NFS_LOOKUP_CACHE_SIZE 64
61
62 /*
63 * superblock magic number for NFS
64 */
65 #define NFS_SUPER_MAGIC 0x6969
66
NFS_I(struct inode * inode)67 static inline struct nfs_inode_info *NFS_I(struct inode *inode)
68 {
69 return &inode->u.nfs_i;
70 }
71
72 #define NFS_FH(inode) (&(inode)->u.nfs_i.fh)
73 #define NFS_SERVER(inode) (&(inode)->i_sb->u.nfs_sb.s_server)
74 #define NFS_CLIENT(inode) (NFS_SERVER(inode)->client)
75 #define NFS_PROTO(inode) (NFS_SERVER(inode)->rpc_ops)
76 #define NFS_REQUESTLIST(inode) (NFS_SERVER(inode)->rw_requests)
77 #define NFS_ADDR(inode) (RPC_PEERADDR(NFS_CLIENT(inode)))
78 #define NFS_CONGESTED(inode) (RPC_CONGESTED(NFS_CLIENT(inode)))
79 #define NFS_COOKIEVERF(inode) ((inode)->u.nfs_i.cookieverf)
80 #define NFS_READTIME(inode) ((inode)->u.nfs_i.read_cache_jiffies)
81 #define NFS_MTIME_UPDATE(inode) ((inode)->u.nfs_i.cache_mtime_jiffies)
82 #define NFS_CACHE_CTIME(inode) ((inode)->u.nfs_i.read_cache_ctime)
83 #define NFS_CACHE_MTIME(inode) ((inode)->u.nfs_i.read_cache_mtime)
84 #define NFS_CACHE_ISIZE(inode) ((inode)->u.nfs_i.read_cache_isize)
85 #define NFS_NEXTSCAN(inode) ((inode)->u.nfs_i.nextscan)
86 #define NFS_CACHEINV(inode) \
87 do { \
88 NFS_READTIME(inode) = jiffies - NFS_MAXATTRTIMEO(inode) - 1; \
89 } while (0)
90 #define NFS_ATTRTIMEO(inode) ((inode)->u.nfs_i.attrtimeo)
91 #define NFS_MINATTRTIMEO(inode) \
92 (S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmin \
93 : NFS_SERVER(inode)->acregmin)
94 #define NFS_MAXATTRTIMEO(inode) \
95 (S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmax \
96 : NFS_SERVER(inode)->acregmax)
97 #define NFS_ATTRTIMEO_UPDATE(inode) ((inode)->u.nfs_i.attrtimeo_timestamp)
98
99 #define NFS_FLAGS(inode) ((inode)->u.nfs_i.flags)
100 #define NFS_REVALIDATING(inode) (NFS_FLAGS(inode) & NFS_INO_REVALIDATING)
101 #define NFS_STALE(inode) (NFS_FLAGS(inode) & NFS_INO_STALE)
102
103 #define NFS_FILEID(inode) ((inode)->u.nfs_i.fileid)
104
105 /* Inode Flags */
106 #define NFS_USE_READDIRPLUS(inode) ((NFS_FLAGS(inode) & NFS_INO_ADVISE_RDPLUS) ? 1 : 0)
107
108 /*
109 * These are the default flags for swap requests
110 */
111 #define NFS_RPC_SWAPFLAGS (RPC_TASK_SWAPPER|RPC_TASK_ROOTCREDS)
112
113 /* Flags in the RPC client structure */
114 #define NFS_CLNTF_BUFSIZE 0x0001 /* readdir buffer in longwords */
115
116 #define NFS_RW_SYNC 0x0001 /* O_SYNC handling */
117 #define NFS_RW_SWAP 0x0002 /* This is a swap request */
118
119 /*
120 * When flushing a cluster of dirty pages, there can be different
121 * strategies:
122 */
123 #define FLUSH_AGING 0 /* only flush old buffers */
124 #define FLUSH_SYNC 1 /* file being synced, or contention */
125 #define FLUSH_WAIT 2 /* wait for completion */
126 #define FLUSH_STABLE 4 /* commit to stable storage */
127
128 static inline
page_offset(struct page * page)129 loff_t page_offset(struct page *page)
130 {
131 return ((loff_t)page->index) << PAGE_CACHE_SHIFT;
132 }
133
134 static inline
page_index(struct page * page)135 unsigned long page_index(struct page *page)
136 {
137 return page->index;
138 }
139
140 #ifdef __KERNEL__
141 /*
142 * linux/fs/nfs/inode.c
143 */
144 extern struct super_block *nfs_read_super(struct super_block *, void *, int);
145 extern void nfs_zap_caches(struct inode *);
146 extern int nfs_inode_is_stale(struct inode *, struct nfs_fh *,
147 struct nfs_fattr *);
148 extern struct inode *nfs_fhget(struct dentry *, struct nfs_fh *,
149 struct nfs_fattr *);
150 extern int __nfs_refresh_inode(struct inode *, struct nfs_fattr *);
151 extern int nfs_revalidate(struct dentry *);
152 extern int nfs_permission(struct inode *, int);
153 extern int nfs_open(struct inode *, struct file *);
154 extern int nfs_release(struct inode *, struct file *);
155 extern int __nfs_revalidate_inode(struct nfs_server *, struct inode *);
156 extern int nfs_check_stale(struct inode *);
157 extern int nfs_notify_change(struct dentry *, struct iattr *);
158
159 /*
160 * linux/fs/nfs/file.c
161 */
162 extern struct inode_operations nfs_file_inode_operations;
163 extern struct file_operations nfs_file_operations;
164 extern struct address_space_operations nfs_file_aops;
165
166 static __inline__ struct rpc_cred *
nfs_file_cred(struct file * file)167 nfs_file_cred(struct file *file)
168 {
169 struct rpc_cred *cred = NULL;
170 if (file)
171 cred = (struct rpc_cred *)file->private_data;
172 #ifdef RPC_DEBUG
173 if (cred && cred->cr_magic != RPCAUTH_CRED_MAGIC)
174 out_of_line_bug();
175 #endif
176 return cred;
177 }
178
179 /*
180 * linux/fs/nfs/dir.c
181 */
182 extern struct inode_operations nfs_dir_inode_operations;
183 extern struct file_operations nfs_dir_operations;
184 extern struct dentry_operations nfs_dentry_operations;
185
186 /*
187 * linux/fs/nfs/symlink.c
188 */
189 extern struct inode_operations nfs_symlink_inode_operations;
190
191 /*
192 * linux/fs/nfs/locks.c
193 */
194 extern int nfs_lock(struct file *, int, struct file_lock *);
195
196 /*
197 * linux/fs/nfs/unlink.c
198 */
199 extern int nfs_async_unlink(struct dentry *);
200 extern void nfs_complete_unlink(struct dentry *);
201
202 /*
203 * linux/fs/nfs/write.c
204 */
205 extern int nfs_writepage(struct page *);
206 extern int nfs_flush_incompatible(struct file *file, struct page *page);
207 extern int nfs_updatepage(struct file *, struct page *, unsigned int, unsigned int);
208 /*
209 * Try to write back everything synchronously (but check the
210 * return value!)
211 */
212 extern int nfs_sync_file(struct inode *, unsigned long, unsigned int, int);
213 extern int nfs_flush_file(struct inode *, unsigned long, unsigned int, int);
214 extern int nfs_flush_list(struct list_head *, int, int);
215 extern int nfs_scan_lru_dirty(struct nfs_server *, struct list_head *);
216 extern int nfs_scan_lru_dirty_timeout(struct nfs_server *, struct list_head *);
217 #ifdef CONFIG_NFS_V3
218 extern int nfs_commit_file(struct inode *, int);
219 extern int nfs_commit_list(struct list_head *, int);
220 extern int nfs_scan_lru_commit(struct nfs_server *, struct list_head *);
221 extern int nfs_scan_lru_commit_timeout(struct nfs_server *, struct list_head *);
222 #endif
223
224 static inline int
nfs_have_read(struct inode * inode)225 nfs_have_read(struct inode *inode)
226 {
227 return !list_empty(&inode->u.nfs_i.read);
228 }
229
230 static inline int
nfs_have_writebacks(struct inode * inode)231 nfs_have_writebacks(struct inode *inode)
232 {
233 return !list_empty(&inode->u.nfs_i.writeback);
234 }
235
236 static inline int
nfs_wb_all(struct inode * inode)237 nfs_wb_all(struct inode *inode)
238 {
239 int error = nfs_sync_file(inode, 0, 0, FLUSH_WAIT);
240 return (error < 0) ? error : 0;
241 }
242
243 /*
244 * Write back all requests on one page - we do this before reading it.
245 */
246 static inline int
nfs_wb_page(struct inode * inode,struct page * page)247 nfs_wb_page(struct inode *inode, struct page* page)
248 {
249 int error = nfs_sync_file(inode, page_index(page), 1, FLUSH_WAIT | FLUSH_STABLE);
250 return (error < 0) ? error : 0;
251 }
252
253 /*
254 * linux/fs/nfs/read.c
255 */
256 extern int nfs_readpage(struct file *, struct page *);
257 extern int nfs_pagein_inode(struct inode *, unsigned long, unsigned int);
258 extern int nfs_pagein_list(struct list_head *, int);
259 extern int nfs_scan_lru_read(struct nfs_server *, struct list_head *);
260 extern int nfs_scan_lru_read_timeout(struct nfs_server *, struct list_head *);
261
262 #define NFS_SetPageSync(page) set_bit(PG_fs_1, &(page)->flags)
263 #define NFS_ClearPageSync(page) clear_bit(PG_fs_1, &(page)->flags)
264 #define NFS_TestClearPageSync(page) test_and_clear_bit(PG_fs_1, &(page)->flags)
265
266 /*
267 * linux/fs/nfs/direct.c
268 */
269 extern int nfs_direct_IO(int, struct file *, struct kiobuf *, unsigned long, int);
270
271 /*
272 * linux/fs/mount_clnt.c
273 * (Used only by nfsroot module)
274 */
275 extern int nfsroot_mount(struct sockaddr_in *, char *, struct nfs_fh *,
276 int, int);
277
278 /* linux/net/ipv4/ipconfig.c: trims ip addr off front of name, too. */
279 extern u32 root_nfs_parse_addr(char *name); /*__init*/
280
281 /*
282 * inline functions
283 */
284 static inline int
nfs_revalidate_inode(struct nfs_server * server,struct inode * inode)285 nfs_revalidate_inode(struct nfs_server *server, struct inode *inode)
286 {
287 if (time_before(jiffies, NFS_READTIME(inode)+NFS_ATTRTIMEO(inode)))
288 return NFS_STALE(inode) ? -ESTALE : 0;
289 return __nfs_revalidate_inode(server, inode);
290 }
291
292 static inline int
nfs_refresh_inode(struct inode * inode,struct nfs_fattr * fattr)293 nfs_refresh_inode(struct inode *inode, struct nfs_fattr *fattr)
294 {
295 if ((fattr->valid & NFS_ATTR_FATTR) == 0)
296 return 0;
297 return __nfs_refresh_inode(inode,fattr);
298 }
299
300 /*
301 * This function will be used to simulate weak cache consistency
302 * under NFSv2 when the NFSv3 attribute patch is included.
303 * For the moment, we just call nfs_refresh_inode().
304 */
305 static __inline__ int
nfs_write_attributes(struct inode * inode,struct nfs_fattr * fattr)306 nfs_write_attributes(struct inode *inode, struct nfs_fattr *fattr)
307 {
308 if ((fattr->valid & NFS_ATTR_FATTR) && !(fattr->valid & NFS_ATTR_WCC)) {
309 fattr->pre_size = NFS_CACHE_ISIZE(inode);
310 fattr->pre_mtime = NFS_CACHE_MTIME(inode);
311 fattr->pre_ctime = NFS_CACHE_CTIME(inode);
312 fattr->valid |= NFS_ATTR_WCC;
313 }
314 return nfs_refresh_inode(inode, fattr);
315 }
316
317 static inline loff_t
nfs_size_to_loff_t(__u64 size)318 nfs_size_to_loff_t(__u64 size)
319 {
320 loff_t maxsz = (((loff_t) ULONG_MAX) << PAGE_CACHE_SHIFT) + PAGE_CACHE_SIZE - 1;
321 if (size > maxsz)
322 return maxsz;
323 return (loff_t) size;
324 }
325
326 static inline ino_t
nfs_fileid_to_ino_t(u64 fileid)327 nfs_fileid_to_ino_t(u64 fileid)
328 {
329 ino_t ino = (ino_t) fileid;
330 if (sizeof(ino_t) < sizeof(u64))
331 ino ^= fileid >> (sizeof(u64)-sizeof(ino_t)) * 8;
332 return ino;
333 }
334
335 static inline time_t
nfs_time_to_secs(__u64 time)336 nfs_time_to_secs(__u64 time)
337 {
338 return (time_t)(time >> 32);
339 }
340
341 /* NFS root */
342
343 extern void * nfs_root_data(void);
344
345 #define nfs_wait_event(clnt, wq, condition) \
346 ({ \
347 int __retval = 0; \
348 if (clnt->cl_intr) { \
349 sigset_t oldmask; \
350 rpc_clnt_sigmask(clnt, &oldmask); \
351 __retval = wait_event_interruptible(wq, condition); \
352 rpc_clnt_sigunmask(clnt, &oldmask); \
353 } else \
354 wait_event(wq, condition); \
355 __retval; \
356 })
357
358 #ifdef CONFIG_NFS_V3
359
360 #define NFS_JUKEBOX_RETRY_TIME (5 * HZ)
361 static inline int
nfs_async_handle_jukebox(struct rpc_task * task)362 nfs_async_handle_jukebox(struct rpc_task *task)
363 {
364 if (task->tk_status != -EJUKEBOX)
365 return 0;
366 task->tk_status = 0;
367 rpc_restart_call(task);
368 rpc_delay(task, NFS_JUKEBOX_RETRY_TIME);
369 return 1;
370 }
371
372 #else
373
374 static inline int
nfs_async_handle_jukebox(struct rpc_task * task)375 nfs_async_handle_jukebox(struct rpc_task *task)
376 {
377 return 0;
378 }
379 #endif /* CONFIG_NFS_V3 */
380
381 #endif /* __KERNEL__ */
382
383 /*
384 * NFS debug flags
385 */
386 #define NFSDBG_VFS 0x0001
387 #define NFSDBG_DIRCACHE 0x0002
388 #define NFSDBG_LOOKUPCACHE 0x0004
389 #define NFSDBG_PAGECACHE 0x0008
390 #define NFSDBG_PROC 0x0010
391 #define NFSDBG_XDR 0x0020
392 #define NFSDBG_FILE 0x0040
393 #define NFSDBG_ROOT 0x0080
394 #define NFSDBG_ALL 0xFFFF
395
396 #ifdef __KERNEL__
397 # undef ifdebug
398 # ifdef NFS_DEBUG
399 # define ifdebug(fac) if (nfs_debug & NFSDBG_##fac)
400 # else
401 # define ifdebug(fac) if (0)
402 # endif
403 #endif /* __KERNEL */
404
405 #endif
406