[PATCH] NFS: Make searching and waiting on busy writeback requests more efficient.
[safe/jmp/linux-2.6] / include / linux / nfs_page.h
1 /*
2  * linux/include/linux/nfs_page.h
3  *
4  * Copyright (C) 2000 Trond Myklebust
5  *
6  * NFS page cache wrapper.
7  */
8
9 #ifndef _LINUX_NFS_PAGE_H
10 #define _LINUX_NFS_PAGE_H
11
12
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>
19
20 #include <asm/atomic.h>
21
22 /*
23  * Valid flags for the radix tree
24  */
25 #define NFS_PAGE_TAG_WRITEBACK  1
26
27 /*
28  * Valid flags for a dirty buffer
29  */
30 #define PG_BUSY                 0
31 #define PG_NEED_COMMIT          1
32 #define PG_NEED_RESCHED         2
33
34 struct nfs_page {
35         struct list_head        wb_list,        /* Defines state of page: */
36                                 *wb_list_head;  /*      read/write/commit */
37         struct page             *wb_page;       /* page to read in/write out */
38         struct nfs_open_context *wb_context;    /* File state context info */
39         atomic_t                wb_complete;    /* i/os we're waiting for */
40         unsigned long           wb_index;       /* Offset >> PAGE_CACHE_SHIFT */
41         unsigned int            wb_offset,      /* Offset & ~PAGE_CACHE_MASK */
42                                 wb_pgbase,      /* Start of page data */
43                                 wb_bytes;       /* Length of request */
44         atomic_t                wb_count;       /* reference count */
45         unsigned long           wb_flags;
46         struct nfs_writeverf    wb_verf;        /* Commit cookie */
47 };
48
49 #define NFS_WBACK_BUSY(req)     (test_bit(PG_BUSY,&(req)->wb_flags))
50 #define NFS_NEED_COMMIT(req)    (test_bit(PG_NEED_COMMIT,&(req)->wb_flags))
51 #define NFS_NEED_RESCHED(req)   (test_bit(PG_NEED_RESCHED,&(req)->wb_flags))
52
53 extern  struct nfs_page *nfs_create_request(struct nfs_open_context *ctx,
54                                             struct inode *inode,
55                                             struct page *page,
56                                             unsigned int offset,
57                                             unsigned int count);
58 extern  void nfs_clear_request(struct nfs_page *req);
59 extern  void nfs_release_request(struct nfs_page *req);
60
61
62 extern  void nfs_list_add_request(struct nfs_page *, struct list_head *);
63
64 extern  int nfs_scan_list(struct list_head *, struct list_head *,
65                           unsigned long, unsigned int);
66 extern  int nfs_coalesce_requests(struct list_head *, struct list_head *,
67                                   unsigned int);
68 extern  int nfs_wait_on_request(struct nfs_page *);
69 extern  void nfs_unlock_request(struct nfs_page *req);
70 extern  int nfs_set_page_writeback_locked(struct nfs_page *req);
71 extern  void nfs_clear_page_writeback(struct nfs_page *req);
72
73
74 /*
75  * Lock the page of an asynchronous request without incrementing the wb_count
76  */
77 static inline int
78 nfs_lock_request_dontget(struct nfs_page *req)
79 {
80         if (test_and_set_bit(PG_BUSY, &req->wb_flags))
81                 return 0;
82         return 1;
83 }
84
85 /*
86  * Lock the page of an asynchronous request
87  */
88 static inline int
89 nfs_lock_request(struct nfs_page *req)
90 {
91         if (test_and_set_bit(PG_BUSY, &req->wb_flags))
92                 return 0;
93         atomic_inc(&req->wb_count);
94         return 1;
95 }
96
97
98 /**
99  * nfs_list_remove_request - Remove a request from its wb_list
100  * @req: request
101  */
102 static inline void
103 nfs_list_remove_request(struct nfs_page *req)
104 {
105         if (list_empty(&req->wb_list))
106                 return;
107         list_del_init(&req->wb_list);
108         req->wb_list_head = NULL;
109 }
110
111 static inline int
112 nfs_defer_commit(struct nfs_page *req)
113 {
114         if (test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags))
115                 return 0;
116         return 1;
117 }
118
119 static inline void
120 nfs_clear_commit(struct nfs_page *req)
121 {
122         smp_mb__before_clear_bit();
123         clear_bit(PG_NEED_COMMIT, &req->wb_flags);
124         smp_mb__after_clear_bit();
125 }
126
127 static inline int
128 nfs_defer_reschedule(struct nfs_page *req)
129 {
130         if (test_and_set_bit(PG_NEED_RESCHED, &req->wb_flags))
131                 return 0;
132         return 1;
133 }
134
135 static inline void
136 nfs_clear_reschedule(struct nfs_page *req)
137 {
138         smp_mb__before_clear_bit();
139         clear_bit(PG_NEED_RESCHED, &req->wb_flags);
140         smp_mb__after_clear_bit();
141 }
142
143 static inline struct nfs_page *
144 nfs_list_entry(struct list_head *head)
145 {
146         return list_entry(head, struct nfs_page, wb_list);
147 }
148
149 static inline
150 loff_t req_offset(struct nfs_page *req)
151 {
152         return (((loff_t)req->wb_index) << PAGE_CACHE_SHIFT) + req->wb_offset;
153 }
154
155 #endif /* _LINUX_NFS_PAGE_H */