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>
17 #include <linux/sunrpc/debug.h>
18 #include <linux/sunrpc/auth.h>
20 #include <linux/nfs.h>
21 #include <linux/nfs2.h>
22 #include <linux/nfs3.h>
23 #include <linux/nfs_xdr.h>
26 * Enable debugging support for nfs client.
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.
38 * Note that at most server->rsize bytes of the cache memory are used.
40 #define NFS_MAX_DIRCACHE 16
42 #define NFS_MAX_FILE_IO_BUFFER_SIZE 32768
43 #define NFS_DEF_FILE_IO_BUFFER_SIZE 4096
46 * The upper limit on timeouts for the exponential backoff algorithm.
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)
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.
59 #define NFS_LOOKUP_CACHE_SIZE 64
62 * superblock magic number for NFS
64 #define NFS_SUPER_MAGIC 0x6969
66 #define NFS_FH(dentry) ((struct nfs_fh *) ((dentry)->d_fsdata))
67 #define NFS_DSERVER(dentry) (&(dentry)->d_sb->u.nfs_sb.s_server)
68 #define NFS_SERVER(inode) (&(inode)->i_sb->u.nfs_sb.s_server)
69 #define NFS_CLIENT(inode) (NFS_SERVER(inode)->client)
70 #define NFS_PROTO(inode) (NFS_SERVER(inode)->rpc_ops)
71 #define NFS_REQUESTLIST(inode) (NFS_SERVER(inode)->rw_requests)
72 #define NFS_ADDR(inode) (RPC_PEERADDR(NFS_CLIENT(inode)))
73 #define NFS_CONGESTED(inode) (RPC_CONGESTED(NFS_CLIENT(inode)))
74 #define NFS_COOKIEVERF(inode) ((inode)->u.nfs_i.cookieverf)
75 #define NFS_READTIME(inode) ((inode)->u.nfs_i.read_cache_jiffies)
76 #define NFS_CACHE_CTIME(inode) ((inode)->u.nfs_i.read_cache_ctime)
77 #define NFS_CACHE_MTIME(inode) ((inode)->u.nfs_i.read_cache_mtime)
78 #define NFS_CACHE_ATIME(inode) ((inode)->u.nfs_i.read_cache_atime)
79 #define NFS_CACHE_ISIZE(inode) ((inode)->u.nfs_i.read_cache_isize)
80 #define NFS_NEXTSCAN(inode) ((inode)->u.nfs_i.nextscan)
81 #define NFS_CACHEINV(inode) \
83 NFS_READTIME(inode) = jiffies - NFS_MAXATTRTIMEO(inode) - 1; \
85 #define NFS_ATTRTIMEO(inode) ((inode)->u.nfs_i.attrtimeo)
86 #define NFS_MINATTRTIMEO(inode) \
87 (S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmin \
88 : NFS_SERVER(inode)->acregmin)
89 #define NFS_MAXATTRTIMEO(inode) \
90 (S_ISDIR(inode->i_mode)? NFS_SERVER(inode)->acdirmax \
91 : NFS_SERVER(inode)->acregmax)
92 #define NFS_ATTRTIMEO_UPDATE(inode) ((inode)->u.nfs_i.attrtimeo_timestamp)
94 #define NFS_FLAGS(inode) ((inode)->u.nfs_i.flags)
95 #define NFS_REVALIDATING(inode) (NFS_FLAGS(inode) & NFS_INO_REVALIDATING)
97 #define NFS_FILEID(inode) ((inode)->u.nfs_i.fileid)
98 #define NFS_FSID(inode) ((inode)->u.nfs_i.fsid)
101 #define NFS_USE_READDIRPLUS(inode) ((NFS_FLAGS(inode) & NFS_INO_ADVISE_RDPLUS) ? 1 : 0)
104 * These are the default flags for swap requests
106 #define NFS_RPC_SWAPFLAGS (RPC_TASK_SWAPPER|RPC_TASK_ROOTCREDS)
108 /* Flags in the RPC client structure */
109 #define NFS_CLNTF_BUFSIZE 0x0001 /* readdir buffer in longwords */
111 #define NFS_RW_SYNC 0x0001 /* O_SYNC handling */
112 #define NFS_RW_SWAP 0x0002 /* This is a swap request */
115 * When flushing a cluster of dirty pages, there can be different
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 */
124 loff_t
page_offset(struct page
*page
)
126 return ((loff_t
)page
->index
) << PAGE_CACHE_SHIFT
;
130 unsigned long page_index(struct page
*page
)
137 * linux/fs/nfs/inode.c
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 struct inode
*nfs_fhget(struct dentry
*, struct nfs_fh
*,
144 extern int nfs_refresh_inode(struct inode
*, struct nfs_fattr
*);
145 extern int nfs_revalidate(struct dentry
*);
146 extern int nfs_open(struct inode
*, struct file
*);
147 extern int nfs_release(struct inode
*, struct file
*);
148 extern int __nfs_revalidate_inode(struct nfs_server
*, struct dentry
*);
149 extern int nfs_notify_change(struct dentry
*, struct iattr
*);
152 * linux/fs/nfs/file.c
154 extern struct inode_operations nfs_file_inode_operations
;
155 extern struct file_operations nfs_file_operations
;
156 extern struct address_space_operations nfs_file_aops
;
158 static __inline__
struct rpc_cred
*
159 nfs_file_cred(struct file
*file
)
161 struct rpc_cred
*cred
= (struct rpc_cred
*)(file
->private_data
);
163 if (cred
&& cred
->cr_magic
!= RPCAUTH_CRED_MAGIC
)
172 extern struct inode_operations nfs_dir_inode_operations
;
173 extern struct file_operations nfs_dir_operations
;
174 extern struct dentry_operations nfs_dentry_operations
;
177 * linux/fs/nfs/symlink.c
179 extern struct inode_operations nfs_symlink_inode_operations
;
182 * linux/fs/nfs/locks.c
184 extern int nfs_lock(struct file
*, int, struct file_lock
*);
187 * linux/fs/nfs/unlink.c
189 extern int nfs_async_unlink(struct dentry
*);
190 extern void nfs_complete_unlink(struct dentry
*);
193 * linux/fs/nfs/write.c
195 extern int nfs_writepage(struct file
*file
, struct page
*);
196 extern int nfs_flush_incompatible(struct file
*file
, struct page
*page
);
197 extern int nfs_updatepage(struct file
*, struct page
*, unsigned int, unsigned int);
199 * Try to write back everything synchronously (but check the
202 extern int nfs_sync_file(struct inode
*, struct file
*, unsigned long, unsigned int, int);
203 extern int nfs_flush_file(struct inode
*, struct file
*, unsigned long, unsigned int, int);
204 extern int nfs_flush_timeout(struct inode
*, int);
206 extern int nfs_commit_file(struct inode
*, struct file
*, unsigned long, unsigned int, int);
207 extern int nfs_commit_timeout(struct inode
*, int);
211 nfs_have_read(struct inode
*inode
)
213 return !list_empty(&inode
->u
.nfs_i
.read
);
217 nfs_have_writebacks(struct inode
*inode
)
219 return !list_empty(&inode
->u
.nfs_i
.writeback
);
223 nfs_wb_all(struct inode
*inode
)
225 int error
= nfs_sync_file(inode
, 0, 0, 0, FLUSH_WAIT
);
226 return (error
< 0) ? error
: 0;
230 * Write back all requests on one page - we do this before reading it.
233 nfs_wb_page(struct inode
*inode
, struct page
* page
)
235 int error
= nfs_sync_file(inode
, 0, page_index(page
), 1, FLUSH_WAIT
| FLUSH_STABLE
);
236 return (error
< 0) ? error
: 0;
240 * Write back all pending writes for one user..
243 nfs_wb_file(struct inode
*inode
, struct file
*file
)
245 int error
= nfs_sync_file(inode
, file
, 0, 0, FLUSH_WAIT
);
246 return (error
< 0) ? error
: 0;
250 * linux/fs/nfs/read.c
252 extern int nfs_readpage(struct file
*, struct page
*);
253 extern int nfs_pagein_inode(struct inode
*, unsigned long, unsigned int);
254 extern int nfs_pagein_timeout(struct inode
*);
257 * linux/fs/mount_clnt.c
258 * (Used only by nfsroot module)
260 extern int nfs_mount(struct sockaddr_in
*, char *, struct nfs_fh
*);
261 extern int nfs3_mount(struct sockaddr_in
*, char *, struct nfs_fh
*);
267 nfs_revalidate_inode(struct nfs_server
*server
, struct dentry
*dentry
)
269 struct inode
*inode
= dentry
->d_inode
;
270 if (time_before(jiffies
, NFS_READTIME(inode
)+NFS_ATTRTIMEO(inode
)))
272 return __nfs_revalidate_inode(server
, dentry
);
276 nfs_size_to_loff_t(__u64 size
)
278 loff_t maxsz
= (((loff_t
) ULONG_MAX
) << PAGE_CACHE_SHIFT
) + PAGE_CACHE_SIZE
- 1;
281 return (loff_t
) size
;
285 nfs_fileid_to_ino_t(u64 fileid
)
287 ino_t ino
= (ino_t
) fileid
;
288 if (sizeof(ino_t
) < sizeof(u64
))
289 ino
^= fileid
>> (sizeof(u64
)-sizeof(ino_t
)) * 8;
294 nfs_time_to_secs(__u64 time
)
296 return (time_t)(time
>> 32);
301 extern void * nfs_root_data(void);
303 #define nfs_wait_event(clnt, wq, condition) \
306 if (clnt->cl_intr) { \
308 rpc_clnt_sigmask(clnt, &oldmask); \
309 __retval = wait_event_interruptible(wq, condition); \
310 rpc_clnt_sigunmask(clnt, &oldmask); \
312 wait_event(wq, condition); \
316 #endif /* __KERNEL__ */
321 #define NFSDBG_VFS 0x0001
322 #define NFSDBG_DIRCACHE 0x0002
323 #define NFSDBG_LOOKUPCACHE 0x0004
324 #define NFSDBG_PAGECACHE 0x0008
325 #define NFSDBG_PROC 0x0010
326 #define NFSDBG_XDR 0x0020
327 #define NFSDBG_FILE 0x0040
328 #define NFSDBG_ROOT 0x0080
329 #define NFSDBG_ALL 0xFFFF
334 # define ifdebug(fac) if (nfs_debug & NFSDBG_##fac)
336 # define ifdebug(fac) if (0)
338 #endif /* __KERNEL */