This source file includes following definitions.
- do_read_nfs_sync
- nfs_read_cb
- do_read_nfs_async
- nfs_readpage
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 #include <linux/sched.h>
22 #include <linux/kernel.h>
23 #include <linux/errno.h>
24 #include <linux/fcntl.h>
25 #include <linux/stat.h>
26 #include <linux/mm.h>
27 #include <linux/nfs_fs.h>
28 #include <linux/nfsiod.h>
29 #include <linux/malloc.h>
30 #include <linux/pagemap.h>
31
32 #include <asm/segment.h>
33 #include <asm/system.h>
34
35 #undef DEBUG_BIO
36 #ifdef DEBUG_BIO
37 #define dprintk(args...) printk(## args)
38 #else
39 #define dprintk(args...)
40 #endif
41
42 static inline int
43 do_read_nfs_sync(struct inode * inode, struct page * page)
44 {
45 struct nfs_fattr fattr;
46 int result, refresh = 0;
47 int count = PAGE_SIZE;
48 int rsize = NFS_SERVER(inode)->rsize;
49 char *buf = (char *) page_address(page);
50 unsigned long pos = page->offset;
51
52 dprintk("NFS: do_read_nfs_sync(%p)\n", page);
53
54 set_bit(PG_locked, &page->flags);
55 clear_bit(PG_error, &page->flags);
56
57 do {
58 if (count < rsize)
59 rsize = count;
60 result = nfs_proc_read(NFS_SERVER(inode), NFS_FH(inode),
61 pos, rsize, buf, &fattr);
62 dprintk("nfs_proc_read(%s, (%x,%lx), %ld, %d, %p) = %d\n",
63 NFS_SERVER(inode)->hostname,
64 inode->i_dev, inode->i_ino,
65 pos, rsize, buf, result);
66
67
68
69
70 if (result < 0)
71 goto io_error;
72 refresh = 1;
73 count -= result;
74 pos += result;
75 buf += result;
76 if (result < rsize)
77 break;
78 } while (count);
79
80 memset(buf, 0, count);
81 set_bit(PG_uptodate, &page->flags);
82 result = 0;
83
84 io_error:
85 if (refresh)
86 nfs_refresh_inode(inode, &fattr);
87 clear_bit(PG_locked, &page->flags);
88 wake_up(&page->wait);
89 return result;
90 }
91
92
93
94
95
96 static void
97 nfs_read_cb(int result, struct nfsiod_req *req)
98 {
99 struct page *page = (struct page *) req->rq_cdata;
100 static int succ = 0, fail = 0;
101
102 dprintk("BIO: received callback for page %p, result %d\n",
103 page, result);
104
105 if (result >= 0
106 && (result = nfs_proc_read_reply(&req->rq_rpcreq)) >= 0) {
107 succ++;
108 set_bit(PG_uptodate, &page->flags);
109 } else {
110 fail++;
111 printk("BIO: %d successful reads, %d failures\n", succ, fail);
112 set_bit(PG_error, &page->flags);
113 }
114 clear_bit(PG_locked, &page->flags);
115 wake_up(&page->wait);
116 free_page(page_address(page));
117 }
118
119 static inline int
120 do_read_nfs_async(struct inode *inode, struct page *page)
121 {
122 struct nfsiod_req *req;
123 int result = -1;
124
125 dprintk("NFS: do_read_nfs_async(%p)\n", page);
126
127 set_bit(PG_locked, &page->flags);
128 clear_bit(PG_error, &page->flags);
129
130 if (!(req = nfsiod_reserve(NFS_SERVER(inode), nfs_read_cb)))
131 goto done;
132 result = nfs_proc_read_request(&req->rq_rpcreq,
133 NFS_SERVER(inode), NFS_FH(inode),
134 page->offset, PAGE_SIZE,
135 (__u32 *) page_address(page));
136 if (result >= 0) {
137 req->rq_cdata = page;
138 page->count++;
139 result = nfsiod_enqueue(req);
140 if (result >= 0)
141 dprintk("NFS: enqueued async READ request.\n");
142 }
143 if (result < 0) {
144 dprintk("NFS: deferring async READ request.\n");
145 nfsiod_release(req);
146 clear_bit(PG_locked, &page->flags);
147 wake_up(&page->wait);
148 }
149
150 done:
151 return result < 0? result : 0;
152 }
153
154 int
155 nfs_readpage(struct inode *inode, struct page *page)
156 {
157 unsigned long address;
158 int error = -1;
159
160 dprintk("NFS: nfs_readpage %08lx\n", page_address(page));
161 address = page_address(page);
162 page->count++;
163 if (!PageError(page) && NFS_SERVER(inode)->rsize >= PAGE_SIZE)
164 error = do_read_nfs_async(inode, page);
165 if (error < 0)
166 error = do_read_nfs_sync(inode, page);
167 free_page(address);
168 return error;
169 }