[PATCH] NFS: Write optimization for short files and small O_SYNC writes.
[deliverable/linux.git] / include / linux / nfs_page.h
CommitLineData
1da177e4
LT
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 a dirty buffer
24 */
25#define PG_BUSY 0
26#define PG_NEED_COMMIT 1
27#define PG_NEED_RESCHED 2
28
29struct 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 */
42};
43
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))
47
48extern 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);
53extern void nfs_clear_request(struct nfs_page *req);
54extern void nfs_release_request(struct nfs_page *req);
55
56
57extern void nfs_list_add_request(struct nfs_page *, struct list_head *);
58
59extern int nfs_scan_list(struct list_head *, struct list_head *,
60 unsigned long, unsigned int);
61extern int nfs_coalesce_requests(struct list_head *, struct list_head *,
62 unsigned int);
63extern int nfs_wait_on_request(struct nfs_page *);
64extern void nfs_unlock_request(struct nfs_page *req);
65
66/*
67 * Lock the page of an asynchronous request without incrementing the wb_count
68 */
69static inline int
70nfs_lock_request_dontget(struct nfs_page *req)
71{
72 if (test_and_set_bit(PG_BUSY, &req->wb_flags))
73 return 0;
74 return 1;
75}
76
77/*
78 * Lock the page of an asynchronous request
79 */
80static inline int
81nfs_lock_request(struct nfs_page *req)
82{
83 if (test_and_set_bit(PG_BUSY, &req->wb_flags))
84 return 0;
85 atomic_inc(&req->wb_count);
86 return 1;
87}
88
89
90/**
91 * nfs_list_remove_request - Remove a request from its wb_list
92 * @req: request
93 */
94static inline void
95nfs_list_remove_request(struct nfs_page *req)
96{
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();
102 }
103 list_del_init(&req->wb_list);
104 req->wb_list_head = NULL;
105}
106
107static inline int
108nfs_defer_commit(struct nfs_page *req)
109{
110 if (test_and_set_bit(PG_NEED_COMMIT, &req->wb_flags))
111 return 0;
112 return 1;
113}
114
115static inline void
116nfs_clear_commit(struct nfs_page *req)
117{
118 smp_mb__before_clear_bit();
119 clear_bit(PG_NEED_COMMIT, &req->wb_flags);
120 smp_mb__after_clear_bit();
121}
122
123static inline int
124nfs_defer_reschedule(struct nfs_page *req)
125{
126 if (test_and_set_bit(PG_NEED_RESCHED, &req->wb_flags))
127 return 0;
128 return 1;
129}
130
131static inline void
132nfs_clear_reschedule(struct nfs_page *req)
133{
134 smp_mb__before_clear_bit();
135 clear_bit(PG_NEED_RESCHED, &req->wb_flags);
136 smp_mb__after_clear_bit();
137}
138
139static inline struct nfs_page *
140nfs_list_entry(struct list_head *head)
141{
142 return list_entry(head, struct nfs_page, wb_list);
143}
144
145static inline
146loff_t req_offset(struct nfs_page *req)
147{
148 return (((loff_t)req->wb_index) << PAGE_CACHE_SHIFT) + req->wb_offset;
149}
150
151#endif /* _LINUX_NFS_PAGE_H */
This page took 0.080736 seconds and 5 git commands to generate.