From: Nick Piggin In write_cache_pages(), if ret signals a real error, but we still have some pages left in the pagevec, done would be set to 1, but the remaining pages would continue to be processed and ret will be overwritten in the process. It could easily be overwritten with success, and thus success will be returned even if there is an error. Thus the caller is told all writes succeeded, wheras in reality some did not. Fix this by bailing immediately if there is an error, and retaining the first error code. This is a data interity bug. [akpm@linux-foundation.org: fix all the other done=1 cases too] Signed-off-by: Nick Piggin Cc: Matthew Wilcox Signed-off-by: Andrew Morton --- mm/page-writeback.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff -puN mm/page-writeback.c~mm-write_cache_pages-writepage-error-fix mm/page-writeback.c --- a/mm/page-writeback.c~mm-write_cache_pages-writepage-error-fix +++ a/mm/page-writeback.c @@ -865,7 +865,6 @@ int write_cache_pages(struct address_spa { struct backing_dev_info *bdi = mapping->backing_dev_info; int ret = 0; - int done = 0; struct pagevec pvec; int nr_pages; pgoff_t index; @@ -891,10 +890,10 @@ int write_cache_pages(struct address_spa scanned = 1; } retry: - while (!done && (index <= end) && + while ((index <= end) && (nr_pages = pagevec_lookup_tag(&pvec, mapping, &index, - PAGECACHE_TAG_DIRTY, - min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) { + PAGECACHE_TAG_DIRTY, + min(end - index, (pgoff_t)PAGEVEC_SIZE-1) + 1))) { unsigned i; scanned = 1; @@ -903,9 +902,9 @@ retry: /* * At this point we hold neither mapping->tree_lock nor - * lock on the page itself: the page may be truncated or - * invalidated (changing page->mapping to NULL), or even - * swizzled back from swapper_space to tmpfs file + * lock on the page itself: the page may be truncated + * or invalidated (changing page->mapping to NULL), or + * even swizzled back from swapper_space to tmpfs file * mapping */ lock_page(page); @@ -916,8 +915,8 @@ retry: } if (!wbc->range_cyclic && page->index > end) { - done = 1; unlock_page(page); + goto bail; continue; } @@ -937,16 +936,16 @@ retry: ret = 0; } if (ret || (--nr_to_write <= 0)) - done = 1; + goto bail; if (wbc->nonblocking && bdi_write_congested(bdi)) { wbc->encountered_congestion = 1; - done = 1; + goto bail; } } pagevec_release(&pvec); cond_resched(); } - if (!scanned && !done) { + if (!scanned) { /* * We hit the last page and there is more work to be done: wrap * back to the start of the file @@ -961,7 +960,11 @@ retry: wbc->nr_to_write = nr_to_write; } +out: return ret; +bail: + pagevec_release(&pvec); + goto out; } EXPORT_SYMBOL(write_cache_pages); _