import of ftp.dlink.com/GPL/DSMG-600_reB/ppclinux.tar.gz
[linux-2.4.21-pre4.git] / 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/mm.h>
15 #include <linux/wait.h>
16 #include <linux/sunrpc/auth.h>
17 #include <linux/nfs_xdr.h>
18
19 /*
20  * Valid flags for a dirty buffer
21  */
22 #define PG_BUSY                 0
23
24 struct nfs_page {
25         struct list_head        wb_hash,        /* Inode */
26                                 wb_lru,         /* superblock lru list */
27                                 wb_list,        /* Defines state of page: */
28                                 *wb_list_head;  /*      read/write/commit */
29         struct file             *wb_file;
30         struct inode            *wb_inode;
31         struct rpc_cred         *wb_cred;
32         struct page             *wb_page;       /* page to read in/write out */
33         wait_queue_head_t       wb_wait;        /* wait queue */
34         unsigned long           wb_timeout;     /* when to read/write/commit */
35         unsigned int            wb_offset,      /* Offset of read/write */
36                                 wb_bytes,       /* Length of request */
37                                 wb_count;       /* reference count */
38         unsigned long           wb_flags;
39         struct nfs_writeverf    wb_verf;        /* Commit cookie */
40 };
41
42 #define NFS_WBACK_BUSY(req)     (test_bit(PG_BUSY,&(req)->wb_flags))
43
44 extern  struct nfs_page *nfs_create_request(struct rpc_cred *, struct inode *,
45                                             struct page *,
46                                             unsigned int, unsigned int);
47 extern  void nfs_clear_request(struct nfs_page *req);
48 extern  void nfs_release_request(struct nfs_page *req);
49
50
51 extern  void nfs_list_add_request(struct nfs_page *, struct list_head *);
52
53 extern  int nfs_scan_lru(struct list_head *, struct list_head *, int);
54 extern  int nfs_scan_lru_timeout(struct list_head *, struct list_head *, int);
55 extern  int nfs_scan_list(struct list_head *, struct list_head *,
56                           struct file *, unsigned long, unsigned int);
57 extern  int nfs_coalesce_requests(struct list_head *, struct list_head *,
58                                   unsigned int);
59 extern  int nfs_wait_on_request(struct nfs_page *);
60
61 extern  spinlock_t nfs_wreq_lock;
62
63 /*
64  * Lock the page of an asynchronous request without incrementing the wb_count
65  */
66 static inline int
67 nfs_lock_request_dontget(struct nfs_page *req)
68 {
69         if (test_and_set_bit(PG_BUSY, &req->wb_flags))
70                 return 0;
71         return 1;
72 }
73
74 /*
75  * Lock the page of an asynchronous request
76  */
77 static inline int
78 nfs_lock_request(struct nfs_page *req)
79 {
80         if (test_and_set_bit(PG_BUSY, &req->wb_flags))
81                 return 0;
82         req->wb_count++;
83         return 1;
84 }
85
86 static inline void
87 nfs_unlock_request(struct nfs_page *req)
88 {
89         if (!NFS_WBACK_BUSY(req)) {
90                 printk(KERN_ERR "NFS: Invalid unlock attempted\n");
91                 BUG();
92         }
93         smp_mb__before_clear_bit();
94         clear_bit(PG_BUSY, &req->wb_flags);
95         smp_mb__after_clear_bit();
96         if (waitqueue_active(&req->wb_wait))
97                 wake_up_all(&req->wb_wait);
98         nfs_release_request(req);
99 }
100
101 /**
102  * nfs_list_remove_request - Remove a request from its wb_list
103  * @req: request
104  */
105 static inline void
106 nfs_list_remove_request(struct nfs_page *req)
107 {
108         if (list_empty(&req->wb_list))
109                 return;
110         if (!NFS_WBACK_BUSY(req)) {
111                 printk(KERN_ERR "NFS: unlocked request attempted removed from list!\n");
112                 BUG();
113         }
114         list_del_init(&req->wb_list);
115         req->wb_list_head = NULL;
116 }
117
118 static inline struct nfs_page *
119 nfs_list_entry(struct list_head *head)
120 {
121         return list_entry(head, struct nfs_page, wb_list);
122 }
123
124 static inline struct nfs_page *
125 nfs_inode_wb_entry(struct list_head *head)
126 {
127         return list_entry(head, struct nfs_page, wb_hash);
128 }
129
130 static inline void
131 __nfs_add_lru(struct list_head *head, struct nfs_page *req)
132 {
133         list_add_tail(&req->wb_lru, head);
134 }
135
136 static inline void
137 __nfs_del_lru(struct nfs_page *req)
138 {
139         if (list_empty(&req->wb_lru))
140                 return;
141         list_del_init(&req->wb_lru);
142 }
143
144 static inline struct nfs_page *
145 nfs_lru_entry(struct list_head *head)
146 {
147         return list_entry(head, struct nfs_page, wb_lru);
148 }
149
150 #endif /* _LINUX_NFS_PAGE_H */