aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/pagelist.c
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2006-09-17 14:46:44 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2006-12-06 10:46:35 -0500
commit3f442547b76bf9fb70d7aecc41cf1980459253c9 (patch)
treeaab3982d110b01e028ce477cb02873ddf1abad36 /fs/nfs/pagelist.c
parent28c6925fce3927a9fe3c5b44af5fb266680fdcea (diff)
NFS: Clean up nfs_scan_dirty()
Pass down struct writeback control. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/pagelist.c')
-rw-r--r--fs/nfs/pagelist.c76
1 files changed, 51 insertions, 25 deletions
diff --git a/fs/nfs/pagelist.c b/fs/nfs/pagelist.c
index 829af323f288..e046c9b6a9dd 100644
--- a/fs/nfs/pagelist.c
+++ b/fs/nfs/pagelist.c
@@ -17,6 +17,7 @@
17#include <linux/nfs_page.h> 17#include <linux/nfs_page.h>
18#include <linux/nfs_fs.h> 18#include <linux/nfs_fs.h>
19#include <linux/nfs_mount.h> 19#include <linux/nfs_mount.h>
20#include <linux/writeback.h>
20 21
21#define NFS_PARANOIA 1 22#define NFS_PARANOIA 1
22 23
@@ -268,11 +269,10 @@ nfs_coalesce_requests(struct list_head *head, struct list_head *dst,
268 269
269#define NFS_SCAN_MAXENTRIES 16 270#define NFS_SCAN_MAXENTRIES 16
270/** 271/**
271 * nfs_scan_lock_dirty - Scan the radix tree for dirty requests 272 * nfs_scan_dirty - Scan the radix tree for dirty requests
272 * @nfsi: NFS inode 273 * @mapping: pointer to address space
274 * @wbc: writeback_control structure
273 * @dst: Destination list 275 * @dst: Destination list
274 * @idx_start: lower bound of page->index to scan
275 * @npages: idx_start + npages sets the upper bound to scan.
276 * 276 *
277 * Moves elements from one of the inode request lists. 277 * Moves elements from one of the inode request lists.
278 * If the number of requests is set to 0, the entire address_space 278 * If the number of requests is set to 0, the entire address_space
@@ -280,46 +280,72 @@ nfs_coalesce_requests(struct list_head *head, struct list_head *dst,
280 * The requests are *not* checked to ensure that they form a contiguous set. 280 * The requests are *not* checked to ensure that they form a contiguous set.
281 * You must be holding the inode's req_lock when calling this function 281 * You must be holding the inode's req_lock when calling this function
282 */ 282 */
283int 283long nfs_scan_dirty(struct address_space *mapping,
284nfs_scan_lock_dirty(struct nfs_inode *nfsi, struct list_head *dst, 284 struct writeback_control *wbc,
285 unsigned long idx_start, unsigned int npages) 285 struct list_head *dst)
286{ 286{
287 struct nfs_inode *nfsi = NFS_I(mapping->host);
287 struct nfs_page *pgvec[NFS_SCAN_MAXENTRIES]; 288 struct nfs_page *pgvec[NFS_SCAN_MAXENTRIES];
288 struct nfs_page *req; 289 struct nfs_page *req;
289 unsigned long idx_end; 290 pgoff_t idx_start, idx_end;
291 long count = wbc->nr_to_write;
292 long res = 0;
290 int found, i; 293 int found, i;
291 int res;
292 294
293 res = 0; 295 if (nfsi->ndirty == 0 || count <= 0)
294 if (npages == 0) 296 return 0;
295 idx_end = ~0; 297 if (wbc->range_cyclic) {
296 else 298 idx_start = 0;
297 idx_end = idx_start + npages - 1; 299 idx_end = ULONG_MAX;
300 } else if (wbc->range_end == 0) {
301 idx_start = wbc->range_start >> PAGE_CACHE_SHIFT;
302 idx_end = ULONG_MAX;
303 } else {
304 idx_start = wbc->range_start >> PAGE_CACHE_SHIFT;
305 idx_end = wbc->range_end >> PAGE_CACHE_SHIFT;
306 }
298 307
299 for (;;) { 308 for (;;) {
309 unsigned int toscan = NFS_SCAN_MAXENTRIES;
310
311 if (toscan > count)
312 toscan = count;
300 found = radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree, 313 found = radix_tree_gang_lookup_tag(&nfsi->nfs_page_tree,
301 (void **)&pgvec[0], idx_start, NFS_SCAN_MAXENTRIES, 314 (void **)&pgvec[0], idx_start, toscan,
302 NFS_PAGE_TAG_DIRTY); 315 NFS_PAGE_TAG_DIRTY);
316
317 /* Did we make progress? */
303 if (found <= 0) 318 if (found <= 0)
304 break; 319 break;
320
305 for (i = 0; i < found; i++) { 321 for (i = 0; i < found; i++) {
306 req = pgvec[i]; 322 req = pgvec[i];
307 if (req->wb_index > idx_end) 323 if (!wbc->range_cyclic && req->wb_index > idx_end)
308 goto out; 324 goto out;
309 325
310 idx_start = req->wb_index + 1; 326 /* Try to lock request and mark it for writeback */
327 if (!nfs_set_page_writeback_locked(req))
328 goto next;
329 radix_tree_tag_clear(&nfsi->nfs_page_tree,
330 req->wb_index, NFS_PAGE_TAG_DIRTY);
331 nfsi->ndirty--;
332 nfs_list_remove_request(req);
333 nfs_list_add_request(req, dst);
334 dec_zone_page_state(req->wb_page, NR_FILE_DIRTY);
335 res++;
336 if (res == LONG_MAX)
337 goto out;
338 count--;
339 if (count == 0)
340 goto out;
311 341
312 if (nfs_set_page_writeback_locked(req)) { 342next:
313 radix_tree_tag_clear(&nfsi->nfs_page_tree, 343 idx_start = req->wb_index + 1;
314 req->wb_index, NFS_PAGE_TAG_DIRTY);
315 nfs_list_remove_request(req);
316 nfs_list_add_request(req, dst);
317 dec_zone_page_state(req->wb_page, NR_FILE_DIRTY);
318 res++;
319 }
320 } 344 }
321 } 345 }
322out: 346out:
347 wbc->nr_to_write = count;
348 WARN_ON ((nfsi->ndirty == 0) != list_empty(&nfsi->dirty));
323 return res; 349 return res;
324} 350}
325 351