initial commit with v2.6.9
[linux-2.6.9-moxart.git] / include / linux / nfs_page.h
blob39e4895bcdb421b54ff147abe68580ffb0a598a8
1 /*
2 * linux/include/linux/nfs_page.h
4 * Copyright (C) 2000 Trond Myklebust
6 * NFS page cache wrapper.
7 */
9 #ifndef _LINUX_NFS_PAGE_H
10 #define _LINUX_NFS_PAGE_H
13 #include <linux/list.h>
14 #include <linux/pagemap.h>
15 #include <linux/wait.h>
16 #include <linux/nfs_fs_sb.h>
17 #include <linux/sunrpc/auth.h>
18 #include <linux/nfs_xdr.h>
20 #include <asm/atomic.h>
23 * Valid flags for a dirty buffer
25 #define PG_BUSY 0
26 #define PG_NEED_COMMIT 1
27 #define PG_NEED_RESCHED 2
29 struct nfs_page {
30 struct list_head wb_list, /* Defines state of page: */
31 *wb_list_head; /* read/write/commit */
32 struct page *wb_page; /* page to read in/write out */
33 struct nfs_open_context *wb_context; /* File state context info */
34 atomic_t wb_complete; /* i/os we're waiting for */
35 unsigned long wb_index; /* Offset >> PAGE_CACHE_SHIFT */
36 unsigned int wb_offset, /* Offset & ~PAGE_CACHE_MASK */
37 wb_pgbase, /* Start of page data */
38 wb_bytes; /* Length of request */
39 atomic_t wb_count; /* reference count */
40 unsigned long wb_flags;
41 struct nfs_writeverf wb_verf; /* Commit cookie */
44 #define NFS_WBACK_BUSY(req) (test_bit(PG_BUSY,&(req)->wb_flags))
45 #define NFS_NEED_COMMIT(req) (test_bit(PG_NEED_COMMIT,&(req)->wb_flags))
46 #define NFS_NEED_RESCHED(req) (test_bit(PG_NEED_RESCHED,&(req)->wb_flags))
48 extern struct nfs_page *nfs_create_request(struct nfs_open_context *ctx,
49 struct inode *inode,
50 struct page *page,
51 unsigned int offset,
52 unsigned int count);
53 extern void nfs_clear_request(struct nfs_page *req);
54 extern void nfs_release_request(struct nfs_page *req);
57 extern void nfs_list_add_request(struct nfs_page *, struct list_head *);
59 extern int nfs_scan_list(struct list_head *, struct list_head *,
60 unsigned long, unsigned int);
61 extern int nfs_coalesce_requests(struct list_head *, struct list_head *,
62 unsigned int);
63 extern int nfs_wait_on_request(struct nfs_page *);
64 extern void nfs_unlock_request(struct nfs_page *req);
67 * Lock the page of an asynchronous request without incrementing the wb_count
69 static inline int
70 nfs_lock_request_dontget(struct nfs_page *req)
72 if (test_and_set_bit(PG_BUSY, &req->wb_flags))
73 return 0;
74 return 1;
78 * Lock the page of an asynchronous request
80 static inline int
81 nfs_lock_request(struct nfs_page *req)
83 if (test_and_set_bit(PG_BUSY, &req->wb_flags))
84 return 0;
85 atomic_inc(&req->wb_count);
86 return 1;
90 /**
91 * nfs_list_remove_request - Remove a request from its wb_list
92 * @req: request
94 static inline void
95 nfs_list_remove_request(struct nfs_page *req)
97 if (list_empty(&req->wb_list))
98 return;
99 if (!NFS_WBACK_BUSY(req)) {
100 printk(KERN_ERR "NFS: unlocked request attempted removed from list!\n");
101 BUG();
103 list_del_init(&req->wb_list);
104 req->wb_list_head = NULL;
107 static inline int
108 nfs_defer_commit(struct nfs_page *req)
110 if (test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags))
111 return 0;
112 return 1;
115 static inline void
116 nfs_clear_commit(struct nfs_page *req)
118 smp_mb__before_clear_bit();
119 clear_bit(PG_NEED_COMMIT, &req->wb_flags);
120 smp_mb__after_clear_bit();
123 static inline int
124 nfs_defer_reschedule(struct nfs_page *req)
126 if (test_and_set_bit(PG_NEED_RESCHED, &req->wb_flags))
127 return 0;
128 return 1;
131 static inline void
132 nfs_clear_reschedule(struct nfs_page *req)
134 smp_mb__before_clear_bit();
135 clear_bit(PG_NEED_RESCHED, &req->wb_flags);
136 smp_mb__after_clear_bit();
139 static inline struct nfs_page *
140 nfs_list_entry(struct list_head *head)
142 return list_entry(head, struct nfs_page, wb_list);
145 static inline
146 loff_t req_offset(struct nfs_page *req)
148 return (((loff_t)req->wb_index) << PAGE_CACHE_SHIFT) + req->wb_offset;
151 #endif /* _LINUX_NFS_PAGE_H */