aboutsummaryrefslogtreecommitdiffstats
path: root/fs/nfs/write.c
diff options
context:
space:
mode:
authorTrond Myklebust <Trond.Myklebust@netapp.com>2006-10-09 16:18:38 -0400
committerTrond Myklebust <Trond.Myklebust@netapp.com>2006-12-06 10:46:35 -0500
commit1c75950b9a2254ef08f986e00ad20266ae9ba7f1 (patch)
treecc1a242601b27b8128c8c385f1b858a7b863f155 /fs/nfs/write.c
parent3f442547b76bf9fb70d7aecc41cf1980459253c9 (diff)
NFS: cleanup of nfs_sync_inode_wait()
Allow callers to directly pass it a struct writeback_control. Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
Diffstat (limited to 'fs/nfs/write.c')
-rw-r--r--fs/nfs/write.c93
1 files changed, 81 insertions, 12 deletions
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index dbc89fa7e9d5..310fdeca6250 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -80,6 +80,7 @@ static struct nfs_page * nfs_update_request(struct nfs_open_context*,
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 long 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 int nfs_wb_page_priority(struct inode *inode, struct page *page, int how);
83static const struct rpc_call_ops nfs_write_partial_ops; 84static const struct rpc_call_ops nfs_write_partial_ops;
84static const struct rpc_call_ops nfs_write_full_ops; 85static const struct rpc_call_ops nfs_write_full_ops;
85static const struct rpc_call_ops nfs_commit_ops; 86static const struct rpc_call_ops nfs_commit_ops;
@@ -1476,29 +1477,38 @@ int nfs_commit_inode(struct inode *inode, int how)
1476} 1477}
1477#endif 1478#endif
1478 1479
1479long nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start, 1480long nfs_sync_mapping_wait(struct address_space *mapping, struct writeback_control *wbc, int how)
1480 unsigned int npages, int how)
1481{ 1481{
1482 struct inode *inode = mapping->host;
1482 struct nfs_inode *nfsi = NFS_I(inode); 1483 struct nfs_inode *nfsi = NFS_I(inode);
1483 struct address_space *mapping = inode->i_mapping; 1484 unsigned long idx_start, idx_end;
1484 struct writeback_control wbc = { 1485 unsigned int npages = 0;
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 };
1491 LIST_HEAD(head); 1486 LIST_HEAD(head);
1492 int nocommit = how & FLUSH_NOCOMMIT; 1487 int nocommit = how & FLUSH_NOCOMMIT;
1493 long pages, ret; 1488 long pages, ret;
1494 1489
1490 /* FIXME */
1491 if (wbc->range_cyclic)
1492 idx_start = 0;
1493 else {
1494 idx_start = wbc->range_start >> PAGE_CACHE_SHIFT;
1495 idx_end = wbc->range_end >> PAGE_CACHE_SHIFT;
1496 if (idx_end > idx_start) {
1497 unsigned long l_npages = 1 + idx_end - idx_start;
1498 npages = l_npages;
1499 if (sizeof(npages) != sizeof(l_npages) &&
1500 (unsigned long)npages != l_npages)
1501 npages = 0;
1502 }
1503 }
1495 how &= ~FLUSH_NOCOMMIT; 1504 how &= ~FLUSH_NOCOMMIT;
1496 spin_lock(&nfsi->req_lock); 1505 spin_lock(&nfsi->req_lock);
1497 do { 1506 do {
1507 wbc->pages_skipped = 0;
1498 ret = nfs_wait_on_requests_locked(inode, idx_start, npages); 1508 ret = nfs_wait_on_requests_locked(inode, idx_start, npages);
1499 if (ret != 0) 1509 if (ret != 0)
1500 continue; 1510 continue;
1501 pages = nfs_scan_dirty(mapping, &wbc, &head); 1511 pages = nfs_scan_dirty(mapping, wbc, &head);
1502 if (pages != 0) { 1512 if (pages != 0) {
1503 spin_unlock(&nfsi->req_lock); 1513 spin_unlock(&nfsi->req_lock);
1504 if (how & FLUSH_INVALIDATE) { 1514 if (how & FLUSH_INVALIDATE) {
@@ -1509,11 +1519,16 @@ long nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
1509 spin_lock(&nfsi->req_lock); 1519 spin_lock(&nfsi->req_lock);
1510 continue; 1520 continue;
1511 } 1521 }
1522 if (wbc->pages_skipped != 0)
1523 continue;
1512 if (nocommit) 1524 if (nocommit)
1513 break; 1525 break;
1514 pages = nfs_scan_commit(inode, &head, idx_start, npages); 1526 pages = nfs_scan_commit(inode, &head, idx_start, npages);
1515 if (pages == 0) 1527 if (pages == 0) {
1528 if (wbc->pages_skipped != 0)
1529 continue;
1516 break; 1530 break;
1531 }
1517 if (how & FLUSH_INVALIDATE) { 1532 if (how & FLUSH_INVALIDATE) {
1518 spin_unlock(&nfsi->req_lock); 1533 spin_unlock(&nfsi->req_lock);
1519 nfs_cancel_commit_list(&head); 1534 nfs_cancel_commit_list(&head);
@@ -1530,6 +1545,60 @@ long nfs_sync_inode_wait(struct inode *inode, unsigned long idx_start,
1530 return ret; 1545 return ret;
1531} 1546}
1532 1547
1548/*
1549 * flush the inode to disk.
1550 */
1551int nfs_wb_all(struct inode *inode)
1552{
1553 struct address_space *mapping = inode->i_mapping;
1554 struct writeback_control wbc = {
1555 .bdi = mapping->backing_dev_info,
1556 .sync_mode = WB_SYNC_ALL,
1557 .nr_to_write = LONG_MAX,
1558 .range_cyclic = 1,
1559 };
1560 int ret;
1561
1562 ret = nfs_sync_mapping_wait(mapping, &wbc, 0);
1563 if (ret >= 0)
1564 return 0;
1565 return ret;
1566}
1567
1568int nfs_sync_mapping_range(struct address_space *mapping, loff_t range_start, loff_t range_end, int how)
1569{
1570 struct writeback_control wbc = {
1571 .bdi = mapping->backing_dev_info,
1572 .sync_mode = WB_SYNC_ALL,
1573 .nr_to_write = LONG_MAX,
1574 .range_start = range_start,
1575 .range_end = range_end,
1576 };
1577 int ret;
1578
1579 ret = nfs_sync_mapping_wait(mapping, &wbc, how);
1580 if (ret >= 0)
1581 return 0;
1582 return ret;
1583}
1584
1585static int nfs_wb_page_priority(struct inode *inode, struct page *page, int how)
1586{
1587 loff_t range_start = page_offset(page);
1588 loff_t range_end = range_start + (loff_t)(PAGE_CACHE_SIZE - 1);
1589
1590 return nfs_sync_mapping_range(inode->i_mapping, range_start, range_end, how | FLUSH_STABLE);
1591}
1592
1593/*
1594 * Write back all requests on one page - we do this before reading it.
1595 */
1596int nfs_wb_page(struct inode *inode, struct page* page)
1597{
1598 return nfs_wb_page_priority(inode, page, 0);
1599}
1600
1601
1533int __init nfs_init_writepagecache(void) 1602int __init nfs_init_writepagecache(void)
1534{ 1603{
1535 nfs_wdata_cachep = kmem_cache_create("nfs_write_data", 1604 nfs_wdata_cachep = kmem_cache_create("nfs_write_data",