Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2758458yba; Mon, 8 Apr 2019 04:12:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqxcJc+ET1KStXL7VU5MpQ9RAI+Cu8cLKvv6Cz2iV/T3j1LKzM/l+Gmu553jtRLURv2g0loY X-Received: by 2002:a63:1064:: with SMTP id 36mr27760298pgq.155.1554721925337; Mon, 08 Apr 2019 04:12:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554721925; cv=none; d=google.com; s=arc-20160816; b=ZD0ytRKGJ5LYdJHV64QlcN87uWrN/63/PnFKn7emLIPGRoyoqtMNFQBPml9jVDNk7U xDrgjMih9X5gFitP4PWGnyuX8Ec0y326j28o8n/JzqugKeemfwWidvR7emTi63rucLlG bNC+mu1j5KTRb4qKa+V+fMhTf7Jtmgrd0b0rpuKBQJb/QKpp6wVcyzEMLHBqMmyB47Ic 3Jm33rR9S7tepb2sgURUAa/DF4XiFjUnGuTA20dkDoPDiZGePniMYXOpvi/lFUO1U428 EZEhQiMrdB6QCV2bhwp/GsVZ9bjL+8fPhpGF6JzyDihCpFtsb0FsqnsTwDnbbcN//w7X yb7w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=Or20GEWsusCmp4zzCjgoTeyZPSiTwdeuaSspGotxKKQ=; b=fkCHWkk+IhXDdbmiFXlR65T0oCdIUBqkIM36Rut6vjJou4O0uO1t9C+oTWjfk22lnc MDFk/93WqCv/ZomKHIO/dA1SclyuSJLp/VRYiEHtW+d4X8f9Ewf1YcCRGLOsp6jQ8JoU weGJEaEtD57IKE9bWlzh5lsV7GPviRGR/ld45pxAww3UWfotPV3GGnzNxy8vOFBpg966 iJDcTnRDX5JIp0+/w2MzdNECq1C+qPuntn9Cgf2uhvtFp6XulupLR3x2v0CSNshJSPZT MumqeaQuF23dbIA24Asp2XzWEytX67jP3S/sR5vr96zC1zCJ14HRGMEhmCL8th+bmogE WxPw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 129si26086271pga.379.2019.04.08.04.11.49; Mon, 08 Apr 2019 04:12:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726403AbfDHLLL (ORCPT + 99 others); Mon, 8 Apr 2019 07:11:11 -0400 Received: from mx2.suse.de ([195.135.220.15]:54040 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725881AbfDHLLL (ORCPT ); Mon, 8 Apr 2019 07:11:11 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id B7778AE80; Mon, 8 Apr 2019 11:11:09 +0000 (UTC) Received: by quack2.suse.cz (Postfix, from userid 1000) id 117871E424A; Mon, 8 Apr 2019 13:11:08 +0200 (CEST) Date: Mon, 8 Apr 2019 13:11:08 +0200 From: Jan Kara To: ZhangXiaoxu Cc: viro@zeniv.linux.org.uk, tytso@mit.edu, adilger.kernel@dilger.ca, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-ext4@vger.kernel.org, yi.zhang@huawei.com Subject: Re: [PATCH] fs/buffer.c: Fix data corruption when buffer write with IO error Message-ID: <20190408111108.GB18662@quack2.suse.cz> References: <1554534793-31444-1-git-send-email-zhangxiaoxu5@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1554534793-31444-1-git-send-email-zhangxiaoxu5@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat 06-04-19 15:13:13, ZhangXiaoxu wrote: > When the buffer write failed, 'end_buffer_write_sync' and > 'end_buffer_async_write' will clear the uptodate flag. But the > data in the buffer maybe newer than disk. In some case, this > will lead data corruption. > > For example: ext4 flush metadata to disk failed, it will clear > the uptodate flag. when a new coming call want the buffer, it will > read it from the disk(because the buffer no uptodate flag). But > the journal not checkpoint now, it will read old data from disk. > If read successfully, ext4 will write the old data to the new > journal, the data will corruption. > > So, don't clear the uptodate flag when write the buffer failed. > > Signed-off-by: ZhangXiaoxu Thanks for the patch. But what are the chances that after the write has failed the read will succeed? Also there were places that were using buffer_uptodate() to detect IO errors. Did you check all those got converted to using buffer_write_io_error() instead? Honza > --- > fs/buffer.c | 2 -- > 1 file changed, 2 deletions(-) > > diff --git a/fs/buffer.c b/fs/buffer.c > index ce35760..9fe1827 100644 > --- a/fs/buffer.c > +++ b/fs/buffer.c > @@ -172,7 +172,6 @@ void end_buffer_write_sync(struct buffer_head *bh, int uptodate) > } else { > buffer_io_error(bh, ", lost sync page write"); > mark_buffer_write_io_error(bh); > - clear_buffer_uptodate(bh); > } > unlock_buffer(bh); > put_bh(bh); > @@ -325,7 +324,6 @@ void end_buffer_async_write(struct buffer_head *bh, int uptodate) > } else { > buffer_io_error(bh, ", lost async page write"); > mark_buffer_write_io_error(bh); > - clear_buffer_uptodate(bh); > SetPageError(page); > } > > -- > 2.7.4 > -- Jan Kara SUSE Labs, CR