Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp121524ybv; Tue, 4 Feb 2020 17:40:56 -0800 (PST) X-Google-Smtp-Source: APXvYqx1F7t10YOw0r3GO0zvL8ZRndeUksRtSf71Jy0lKR0/2BBcAAHAwh9f1sWsLhSMAIxribvG X-Received: by 2002:aca:1011:: with SMTP id 17mr1389665oiq.72.1580866856844; Tue, 04 Feb 2020 17:40:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580866856; cv=none; d=google.com; s=arc-20160816; b=sjbi4DbBIBaNvLLSYwybnwPRQIeyQVDyjxXbKp2jEhMwVbB+Day9nyk/rSheT1xP0d i0fHGDtJlLRZu0+e/DRq6hxZFVhRa4wH/dxpo+IhudN+00Q9Qdeamk2t6YDzkHQFqRQC eT5FPw1eND4L4IJM2zPZpAAgTe6BUViFtQXCoWOGB95A6Iejkk79xbgxQXhbsgTDp/+p 7fjwfFKP6rH/RrXNzNlThDH4hzJvkaLKX05rUzcGRTb4Ek2Npg7vqvc05Pb3emmYvVlU 9IZNp6ZfCQkVGt8hxHugoGPjPhYOxkPgn19hT5Qvx97Riz3slRP9SHSthGFmnOisKCAV CPgQ== 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:from:references:cc:to:subject; bh=2fK6zMfEnGUN3zm0KimX+IUR7M3QnDEwV0PIO8DrBCA=; b=BpzuwyCZXhBcs/hEx/HZa/KyqiIale+ZHgGhG1LYPBZiPf+0k6kfq0NuqDgQzcwcLK MIjRyNiqIG5sJH+ujvQ4cin31S4AjJCGah7WqjLo9yzQZUUKKLtl8Kca5s2Sapxae2H6 9p4h5DHP/GrO+VvgfoTRR/kF0iUEbLVHplxasRepUs1o1Y5QuwZbk7ynMRKgcSyvMMt9 kI6mZUxRwLx9kvEHge7tSAbEK/JsQOAlkUs82B6n9huC89CZr2DOtK6SyhbTVIBX13Iq RDc2s+rN1b6l0+OtJVlQCCNn50CmBnLZ7cWkQs9mxDhVNaub/U8imLgkYO6W6py5bL3N QaMA== 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 y24si11506896oih.24.2020.02.04.17.40.44; Tue, 04 Feb 2020 17:40:56 -0800 (PST) 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 S1727777AbgBEBjx (ORCPT + 99 others); Tue, 4 Feb 2020 20:39:53 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:53032 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727674AbgBEBjx (ORCPT ); Tue, 4 Feb 2020 20:39:53 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id E418031958F4B04BFA3; Wed, 5 Feb 2020 09:39:50 +0800 (CST) Received: from [10.134.22.195] (10.134.22.195) by smtp.huawei.com (10.3.19.213) with Microsoft SMTP Server (TLS) id 14.3.439.0; Wed, 5 Feb 2020 09:39:48 +0800 Subject: Re: [PATCH] f2fs: fix to force keeping write barrier for strict fsync mode To: Jaegeuk Kim CC: , , References: <20200120100045.70210-1-yuchao0@huawei.com> <20200123221855.GA7917@jaegeuk-macbookpro.roam.corp.google.com> From: Chao Yu Message-ID: <0d3f284a-5b98-3d6f-cc9f-47431053f42c@huawei.com> Date: Wed, 5 Feb 2020 09:39:47 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20200123221855.GA7917@jaegeuk-macbookpro.roam.corp.google.com> Content-Type: text/plain; charset="windows-1252" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.134.22.195] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020/1/24 6:18, Jaegeuk Kim wrote: > On 01/20, Chao Yu wrote: >> If barrier is enabled, for strict fsync mode, we should force to >> use atomic write semantics to avoid data corruption due to no >> barrier support in lower device. >> >> Signed-off-by: Chao Yu >> --- >> fs/f2fs/file.c | 7 +++++++ >> 1 file changed, 7 insertions(+) >> >> diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c >> index 86ddbb55d2b1..c9dd45f82fbd 100644 >> --- a/fs/f2fs/file.c >> +++ b/fs/f2fs/file.c >> @@ -241,6 +241,13 @@ static int f2fs_do_sync_file(struct file *file, loff_t start, loff_t end, >> }; >> unsigned int seq_id = 0; >> >> + /* >> + * for strict fsync mode, force to keep atomic write sematics to avoid >> + * data corruption if lower device doesn't support write barrier. >> + */ >> + if (!atomic && F2FS_OPTION(sbi).fsync_mode == FSYNC_MODE_STRICT) >> + atomic = true; > > This allows to relax IO ordering and cache flush. I'm not sure that's what you > want to do here for strict mode. I intend to solve potential data corruption mentioned in below report: https://www.mail-archive.com/linux-f2fs-devel@lists.sourceforge.net/msg15126.html It occurs in this scenario: - write page #0; persist - overwrite page #0 - fsync - write data page #0 OPU into device's cache - write inode page into device's cache - issue flush If SPO is triggered during flush command, inode page can be persisted before data page #0, so that after recovery, inode page can be recovered with new physical block address of data page #0, however there may contains dummy data in new physical block address. So what user see is after overwrite & fsync + SPO, old data in file was corrupted, if any user do care about such case, we can enhance to avoid the corruption in strict mode and suggest user to use fsync's strict mode. Thoughts? Thanks, > >> + >> if (unlikely(f2fs_readonly(inode->i_sb) || >> is_sbi_flag_set(sbi, SBI_CP_DISABLED))) >> return 0; >> -- >> 2.18.0.rc1 > . >