From mboxrd@z Thu Jan 1 00:00:00 1970 From: npiggin@suse.de Subject: [patch 1/7] mm: write_cache_pages writepage error fix Date: Tue, 21 Oct 2008 19:09:48 +1100 Message-ID: <20081021081138.768065000@nick.local0.net> References: <20081021080947.032757000@suse.de> Cc: linux-fsdevel@vger.kernel.org To: akpm@linux-foundation.org Return-path: Received: from cantor2.suse.de ([195.135.220.15]:47868 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751508AbYJUIP1 (ORCPT ); Tue, 21 Oct 2008 04:15:27 -0400 Content-Disposition: inline; filename=mm-wcp-writepage-error-fix.patch Sender: linux-fsdevel-owner@vger.kernel.org List-ID: 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. Signed-off-by: Nick Piggin --- Index: linux-2.6/mm/page-writeback.c =================================================================== --- linux-2.6.orig/mm/page-writeback.c +++ linux-2.6/mm/page-writeback.c @@ -931,12 +931,16 @@ retry: } ret = (*writepage)(page, wbc, data); - - if (unlikely(ret == AOP_WRITEPAGE_ACTIVATE)) { - unlock_page(page); - ret = 0; - } - if (ret || (--nr_to_write <= 0)) + if (unlikely(ret)) { + if (ret == AOP_WRITEPAGE_ACTIVATE) { + unlock_page(page); + ret = 0; + } else { + done = 1; + break; + } + } + if (--nr_to_write <= 0) done = 1; if (wbc->nonblocking && bdi_write_congested(bdi)) { wbc->encountered_congestion = 1; --