diff options
Diffstat (limited to 'fs/nfs/write.c')
-rw-r--r-- | fs/nfs/write.c | 53 |
1 files changed, 35 insertions, 18 deletions
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 9f9845859fc1..e560a78995a3 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
@@ -313,19 +313,34 @@ static int nfs_writepages_callback(struct page *page, struct writeback_control * | |||
313 | int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc) | 313 | int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc) |
314 | { | 314 | { |
315 | struct inode *inode = mapping->host; | 315 | struct inode *inode = mapping->host; |
316 | unsigned long *bitlock = &NFS_I(inode)->flags; | ||
316 | struct nfs_pageio_descriptor pgio; | 317 | struct nfs_pageio_descriptor pgio; |
317 | int err; | 318 | int err; |
318 | 319 | ||
320 | /* Stop dirtying of new pages while we sync */ | ||
321 | err = wait_on_bit_lock(bitlock, NFS_INO_FLUSHING, | ||
322 | nfs_wait_bit_killable, TASK_KILLABLE); | ||
323 | if (err) | ||
324 | goto out_err; | ||
325 | |||
319 | nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES); | 326 | nfs_inc_stats(inode, NFSIOS_VFSWRITEPAGES); |
320 | 327 | ||
321 | nfs_pageio_init_write(&pgio, inode, wb_priority(wbc)); | 328 | nfs_pageio_init_write(&pgio, inode, wb_priority(wbc)); |
322 | err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio); | 329 | err = write_cache_pages(mapping, wbc, nfs_writepages_callback, &pgio); |
323 | nfs_pageio_complete(&pgio); | 330 | nfs_pageio_complete(&pgio); |
331 | |||
332 | clear_bit_unlock(NFS_INO_FLUSHING, bitlock); | ||
333 | smp_mb__after_clear_bit(); | ||
334 | wake_up_bit(bitlock, NFS_INO_FLUSHING); | ||
335 | |||
324 | if (err < 0) | 336 | if (err < 0) |
325 | return err; | 337 | goto out_err; |
326 | if (pgio.pg_error < 0) | 338 | err = pgio.pg_error; |
327 | return pgio.pg_error; | 339 | if (err < 0) |
340 | goto out_err; | ||
328 | return 0; | 341 | return 0; |
342 | out_err: | ||
343 | return err; | ||
329 | } | 344 | } |
330 | 345 | ||
331 | /* | 346 | /* |
@@ -404,7 +419,6 @@ nfs_mark_request_commit(struct nfs_page *req) | |||
404 | struct nfs_inode *nfsi = NFS_I(inode); | 419 | struct nfs_inode *nfsi = NFS_I(inode); |
405 | 420 | ||
406 | spin_lock(&inode->i_lock); | 421 | spin_lock(&inode->i_lock); |
407 | nfsi->ncommit++; | ||
408 | set_bit(PG_CLEAN, &(req)->wb_flags); | 422 | set_bit(PG_CLEAN, &(req)->wb_flags); |
409 | radix_tree_tag_set(&nfsi->nfs_page_tree, | 423 | radix_tree_tag_set(&nfsi->nfs_page_tree, |
410 | req->wb_index, | 424 | req->wb_index, |
@@ -524,6 +538,12 @@ static void nfs_cancel_commit_list(struct list_head *head) | |||
524 | } | 538 | } |
525 | 539 | ||
526 | #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) | 540 | #if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) |
541 | static int | ||
542 | nfs_need_commit(struct nfs_inode *nfsi) | ||
543 | { | ||
544 | return radix_tree_tagged(&nfsi->nfs_page_tree, NFS_PAGE_TAG_COMMIT); | ||
545 | } | ||
546 | |||
527 | /* | 547 | /* |
528 | * nfs_scan_commit - Scan an inode for commit requests | 548 | * nfs_scan_commit - Scan an inode for commit requests |
529 | * @inode: NFS inode to scan | 549 | * @inode: NFS inode to scan |
@@ -538,16 +558,18 @@ static int | |||
538 | nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) | 558 | nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) |
539 | { | 559 | { |
540 | struct nfs_inode *nfsi = NFS_I(inode); | 560 | struct nfs_inode *nfsi = NFS_I(inode); |
541 | int res = 0; | ||
542 | 561 | ||
543 | if (nfsi->ncommit != 0) { | 562 | if (!nfs_need_commit(nfsi)) |
544 | res = nfs_scan_list(nfsi, dst, idx_start, npages, | 563 | return 0; |
545 | NFS_PAGE_TAG_COMMIT); | 564 | |
546 | nfsi->ncommit -= res; | 565 | return nfs_scan_list(nfsi, dst, idx_start, npages, NFS_PAGE_TAG_COMMIT); |
547 | } | ||
548 | return res; | ||
549 | } | 566 | } |
550 | #else | 567 | #else |
568 | static inline int nfs_need_commit(struct nfs_inode *nfsi) | ||
569 | { | ||
570 | return 0; | ||
571 | } | ||
572 | |||
551 | static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) | 573 | static inline int nfs_scan_commit(struct inode *inode, struct list_head *dst, pgoff_t idx_start, unsigned int npages) |
552 | { | 574 | { |
553 | return 0; | 575 | return 0; |
@@ -820,7 +842,7 @@ static int nfs_write_rpcsetup(struct nfs_page *req, | |||
820 | data->args.stable = NFS_UNSTABLE; | 842 | data->args.stable = NFS_UNSTABLE; |
821 | if (how & FLUSH_STABLE) { | 843 | if (how & FLUSH_STABLE) { |
822 | data->args.stable = NFS_DATA_SYNC; | 844 | data->args.stable = NFS_DATA_SYNC; |
823 | if (!NFS_I(inode)->ncommit) | 845 | if (!nfs_need_commit(NFS_I(inode))) |
824 | data->args.stable = NFS_FILE_SYNC; | 846 | data->args.stable = NFS_FILE_SYNC; |
825 | } | 847 | } |
826 | 848 | ||
@@ -1425,18 +1447,13 @@ static int nfs_write_mapping(struct address_space *mapping, int how) | |||
1425 | { | 1447 | { |
1426 | struct writeback_control wbc = { | 1448 | struct writeback_control wbc = { |
1427 | .bdi = mapping->backing_dev_info, | 1449 | .bdi = mapping->backing_dev_info, |
1428 | .sync_mode = WB_SYNC_NONE, | 1450 | .sync_mode = WB_SYNC_ALL, |
1429 | .nr_to_write = LONG_MAX, | 1451 | .nr_to_write = LONG_MAX, |
1430 | .range_start = 0, | 1452 | .range_start = 0, |
1431 | .range_end = LLONG_MAX, | 1453 | .range_end = LLONG_MAX, |
1432 | .for_writepages = 1, | 1454 | .for_writepages = 1, |
1433 | }; | 1455 | }; |
1434 | int ret; | ||
1435 | 1456 | ||
1436 | ret = __nfs_write_mapping(mapping, &wbc, how); | ||
1437 | if (ret < 0) | ||
1438 | return ret; | ||
1439 | wbc.sync_mode = WB_SYNC_ALL; | ||
1440 | return __nfs_write_mapping(mapping, &wbc, how); | 1457 | return __nfs_write_mapping(mapping, &wbc, how); |
1441 | } | 1458 | } |
1442 | 1459 | ||