2 * linux/include/linux/nfs_page.h
4 * Copyright (C) 2000 Trond Myklebust
6 * NFS page cache wrapper.
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
26 #define PG_NEED_COMMIT 1
27 #define PG_NEED_RESCHED 2
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
,
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
*,
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
70 nfs_lock_request_dontget(struct nfs_page
*req
)
72 if (test_and_set_bit(PG_BUSY
, &req
->wb_flags
))
78 * Lock the page of an asynchronous request
81 nfs_lock_request(struct nfs_page
*req
)
83 if (test_and_set_bit(PG_BUSY
, &req
->wb_flags
))
85 atomic_inc(&req
->wb_count
);
91 * nfs_list_remove_request - Remove a request from its wb_list
95 nfs_list_remove_request(struct nfs_page
*req
)
97 if (list_empty(&req
->wb_list
))
99 if (!NFS_WBACK_BUSY(req
)) {
100 printk(KERN_ERR
"NFS: unlocked request attempted removed from list!\n");
103 list_del_init(&req
->wb_list
);
104 req
->wb_list_head
= NULL
;
108 nfs_defer_commit(struct nfs_page
*req
)
110 if (test_and_set_bit(PG_NEED_COMMIT
, &req
->wb_flags
))
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();
124 nfs_defer_reschedule(struct nfs_page
*req
)
126 if (test_and_set_bit(PG_NEED_RESCHED
, &req
->wb_flags
))
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
);
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 */