blob: db40e4590ba2e644371f226b3795bfc81d478b71 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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/*
Trond Myklebustc6a556b2005-06-22 17:16:30 +000023 * Valid flags for the radix tree
24 */
25#define NFS_PAGE_TAG_WRITEBACK 1
26
27/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * 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
34struct 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
53extern 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);
58extern void nfs_clear_request(struct nfs_page *req);
59extern void nfs_release_request(struct nfs_page *req);
60
61
62extern void nfs_list_add_request(struct nfs_page *, struct list_head *);
63
64extern int nfs_scan_list(struct list_head *, struct list_head *,
65 unsigned long, unsigned int);
66extern int nfs_coalesce_requests(struct list_head *, struct list_head *,
67 unsigned int);
68extern int nfs_wait_on_request(struct nfs_page *);
69extern void nfs_unlock_request(struct nfs_page *req);
Trond Myklebustc6a556b2005-06-22 17:16:30 +000070extern int nfs_set_page_writeback_locked(struct nfs_page *req);
71extern void nfs_clear_page_writeback(struct nfs_page *req);
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
74/*
75 * Lock the page of an asynchronous request without incrementing the wb_count
76 */
77static inline int
78nfs_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 */
88static inline int
89nfs_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 */
102static inline void
103nfs_list_remove_request(struct nfs_page *req)
104{
105 if (list_empty(&req->wb_list))
106 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 list_del_init(&req->wb_list);
108 req->wb_list_head = NULL;
109}
110
111static inline int
112nfs_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
119static inline void
120nfs_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
127static inline int
128nfs_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
135static inline void
136nfs_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
143static inline struct nfs_page *
144nfs_list_entry(struct list_head *head)
145{
146 return list_entry(head, struct nfs_page, wb_list);
147}
148
149static inline
150loff_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 */