aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs
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
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')
-rw-r--r--fs/nfs/pagelist.c76
-rw-r--r--fs/nfs/write.c54
2 files changed, 67 insertions, 63 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
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index 1d72096c4d22..dbc89fa7e9d5 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -79,7 +79,7 @@ static struct nfs_page * nfs_update_request(struct nfs_open_context*,
79 unsigned int, unsigned int); 79 unsigned int, unsigned int);
80static int nfs_wait_on_write_congestion(struct address_space *, int); 80static int nfs_wait_on_write_congestion(struct address_space *, int);
81static int nfs_wait_on_requests(struct inode *, unsigned long, unsigned int); 81static int nfs_wait_on_requests(struct inode *, unsigned long, unsigned int);
82static int nfs_flush_mapping(struct address_space *mapping, struct writeback_control *wbc, int how); 82static long nfs_flush_mapping(struct address_space *mapping, struct writeback_control *wbc, int how);
83static const struct rpc_call_ops nfs_write_partial_ops; 83static const struct rpc_call_ops nfs_write_partial_ops;
84static const struct rpc_call_ops nfs_write_full_ops; 84static const struct rpc_call_ops nfs_write_full_ops;
85static const struct rpc_call_ops nfs_commit_ops; 85static const struct rpc_call_ops nfs_commit_ops;
@@ -400,10 +400,8 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
400 goto out; 400 goto out;
401 } 401 }
402 err = nfs_commit_inode(inode, wb_priority(wbc)); 402 err = nfs_commit_inode(inode, wb_priority(wbc));
403 if (err > 0) { 403 if (err > 0)
404 wbc->nr_to_write -= err;
405 err = 0; 404 err = 0;
406 }
407out: 405out:
408 clear_bit(BDI_write_congested, &bdi->state); 406 clear_bit(BDI_write_congested, &bdi->state);
409 wake_up_all(&nfs_write_congestion); 407 wake_up_all(&nfs_write_congestion);
@@ -607,31 +605,6 @@ static void nfs_cancel_commit_list(struct list_head *head)
607 } 605 }
608} 606}
609 607
610/*
611 * nfs_scan_dirty - Scan an inode for dirty requests
612 * @inode: NFS inode to scan
613 * @dst: destination list
614 * @idx_start: lower bound of page->index to scan.
615 * @npages: idx_start + npages sets the upper bound to scan.
616 *
617 * Moves requests from the inode's dirty page list.
618 * The requests are *not* checked to ensure that they form a contiguous set.
619 */
620static int
621nfs_scan_dirty(struct inode *inode, struct list_head *dst, unsigned long idx_start, unsigned int npages)
622{
623 struct nfs_inode *nfsi = NFS_I(inode);
624 int res = 0;
625
626 if (nfsi->ndirty != 0) {
627 res = nfs_scan_lock_dirty(nfsi, dst, idx_start, npages);
628 nfsi->ndirty -= res;
629 if ((nfsi->ndirty == 0) != list_empty(&nfsi->dirty))
630 printk(KERN_ERR "NFS: desynchronized value of nfs_i.ndirty.\n");
631 }
632 return res;
633}
634
635#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 608#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
636/* 609/*
637 * nfs_scan_commit - Scan an inode for commit requests 610 * nfs_scan_commit - Scan an inode for commit requests
@@ -1467,22 +1440,19 @@ static inline int nfs_commit_list(struct inode *inode, struct list_head *head, i
1467} 1440}
1468#endif 1441#endif
1469 1442
1470static int nfs_flush_mapping(struct address_space *mapping, struct writeback_control *wbc, int how) 1443static long nfs_flush_mapping(struct address_space *mapping, struct writeback_control *wbc, int how)
1471{ 1444{
1472 struct nfs_inode *nfsi = NFS_I(mapping->host); 1445 struct nfs_inode *nfsi = NFS_I(mapping->host);
1473 LIST_HEAD(head); 1446 LIST_HEAD(head);
1474 pgoff_t index = wbc->range_start >> PAGE_CACHE_SHIFT; 1447 long res;
1475 unsigned long npages = 1 + (wbc->range_end >> PAGE_CACHE_SHIFT) - index;
1476 int res;
1477 1448
1478 spin_lock(&nfsi->req_lock); 1449 spin_lock(&nfsi->req_lock);
1479 res = nfs_scan_dirty(mapping->host, &head, index, npages); 1450 res = nfs_scan_dirty(mapping, wbc, &head);
1480 spin_unlock(&nfsi->req_lock); 1451 spin_unlock(&nfsi->req_lock);
1481 if (res) { 1452 if (res) {
1482 int error = nfs_flush_list(mapping->host, &head, res, how); 1453 int error = nfs_flush_list(mapping->host, &head, res, how);
1483 if (error < 0) 1454 if (error < 0)
1484 return error; 1455 return error;
1485 wbc->nr_to_write -= res;
1486 } 1456 }
1487 return res; 1457 return res;
1488} 1458}
@@ -1506,13 +1476,21 @@ int nfs_commit_inode(struct inode *inode, int how)
1506} 1476}
1507#endif 1477#endif
1508 1478
1509int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start, 1479long nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
1510 unsigned int npages, int how) 1480 unsigned int npages, int how)
1511{ 1481{
1512 struct nfs_inode *nfsi = NFS_I(inode); 1482 struct nfs_inode *nfsi = NFS_I(inode);
1483 struct address_space *mapping = inode->i_mapping;
1484 struct writeback_control wbc = {
1485 .bdi = mapping->backing_dev_info,
1486 .sync_mode = WB_SYNC_ALL,
1487 .nr_to_write = LONG_MAX,
1488 .range_start = ((loff_t)idx_start) << PAGE_CACHE_SHIFT,
1489 .range_end = ((loff_t)(idx_start + npages - 1)) << PAGE_CACHE_SHIFT,
1490 };
1513 LIST_HEAD(head); 1491 LIST_HEAD(head);
1514 int nocommit = how & FLUSH_NOCOMMIT; 1492 int nocommit = how & FLUSH_NOCOMMIT;
1515 int pages, ret; 1493 long pages, ret;
1516 1494
1517 how &= ~FLUSH_NOCOMMIT; 1495 how &= ~FLUSH_NOCOMMIT;
1518 spin_lock(&nfsi->req_lock); 1496 spin_lock(&nfsi->req_lock);
@@ -1520,7 +1498,7 @@ int nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
1520 ret = nfs_wait_on_requests_locked(inode, idx_start, npages); 1498 ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
1521 if (ret != 0) 1499 if (ret != 0)
1522 continue; 1500 continue;
1523 pages = nfs_scan_dirty(inode, &head, idx_start, npages); 1501 pages = nfs_scan_dirty(mapping, &wbc, &head);
1524 if (pages != 0) { 1502 if (pages != 0) {
1525 spin_unlock(&nfsi->req_lock); 1503 spin_unlock(&nfsi->req_lock);
1526 if (how & FLUSH_INVALIDATE) { 1504 if (how & FLUSH_INVALIDATE) {