Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp3852614yba; Tue, 9 Apr 2019 06:14:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqwk/NkvFnpZNnNAOTxeuflCTeIOjhRbc6Kh6K+nevjhfPTHJyKKAyP+zHcutpb51RQ2xM6Q X-Received: by 2002:a17:902:8b8c:: with SMTP id ay12mr35692839plb.192.1554815695899; Tue, 09 Apr 2019 06:14:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554815695; cv=none; d=google.com; s=arc-20160816; b=YOK/N9t89YOtitHuAqTF0olT5rhdx8A4azhC3Zw3QmabDrTy5/RoEVprh9gpmsRm6b TAeB/D5uo3O/g9yj4xYkJkPjpDs7ZugNUN6gOjiHo45p90ha00tIv28yYPOTrdgldY6G jF1F6ZIs9Wkcv8uHHBhX1SMgJMlikOi+pp6prFX8Thfc8Ur0xGljNd67CKodmXAjYuZN WmVbBN8wpRXQ1IORCHD1SYFgMoJuqlcIIAS7Uhb29308W8nKjyLYnsPyd3q4tfQwMXlT L5J+8rPlhA4e+Y5VIpJII9xIP7VTYhGf3Pik/fPKL3YsVTzn0UBGa7wqIRkOe9k+17eo grQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from; bh=LsWO5PC3WmTG2uutIKZUSS32//sPzX4lWmfpQKfvEKU=; b=DYuHEkqa5LvAp5LWruo0rMaZFKvoNYxjgQixMJsjB0pn3J8ierEwkjusvF147rqlH+ vibUd8lyBe8Walca6XvcGSUY7K2ZLJd+JKEbYYPL9novrVYK1h+g0FIj5rn52Zi38RDs f7p1uE5C/bCDvLb/UFWXAeoqDQG+N3j38frjuuZ7eqKwYChGTqbffY0DPz4o5WiMogrc mXVp5zdNDhYEQV2HZWmMDsPsvVlwvH5jbfEGzPcWd8P+L2f5b0/mAhyQwb5Vr9VcJYK5 yScwo862N3dqvH57SQacJShcEBjKehs7/GlK5SnFimg8hNJn60A1vla71htEbMDqVKHN jOsQ== 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 t21si28616102plr.366.2019.04.09.06.14.39; Tue, 09 Apr 2019 06:14:55 -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 S1727338AbfDINMj (ORCPT + 99 others); Tue, 9 Apr 2019 09:12:39 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:6717 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727070AbfDINMi (ORCPT ); Tue, 9 Apr 2019 09:12:38 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 374B09D1F641A5F1B7F6; Tue, 9 Apr 2019 21:12:32 +0800 (CST) Received: from [127.0.0.1] (10.184.189.120) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.408.0; Tue, 9 Apr 2019 21:12:25 +0800 From: "zhangxiaoxu (A)" Subject: Re: [PATCH] fs/buffer.c: Fix data corruption when buffer write with IO error To: Jan Kara CC: , , , , , , References: <1554534793-31444-1-git-send-email-zhangxiaoxu5@huawei.com> <20190408111108.GB18662@quack2.suse.cz> Message-ID: Date: Tue, 9 Apr 2019 21:11:22 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <20190408111108.GB18662@quack2.suse.cz> Content-Type: text/plain; charset="utf-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.184.189.120] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 4/8/2019 7:11 PM, Jan Kara wrote: > 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 > I encountered this situation when using iscsi target as the ext4 volume, if the network down a while when ext4 write metadata to disk, and maybe read will success after the network recovered. In my testcase, just create and delete files, when disconnect the network, the dir entry maybe corruption. I add some logs when read entry buffer from disk, the buffer stats maybe buffer_write_io_error() and !buffer_uptodate(). In this case, the ext4 will corruption high probability. Because the buffer is read from disk, and some newer information just on journal. In this case, we should not read buffer from the disk. I don't know any other filesystem how to use the uptodate flag. But I think uptodate means the buffer is valid and newer than disk, am I right? I just test ext4 use the xfstest. Any other idea about my problem?