Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp2393094ybl; Mon, 20 Jan 2020 02:02:15 -0800 (PST) X-Google-Smtp-Source: APXvYqyzJzmI0gJtHDHQwa4Mi6VwxR7DlHkUjnY7RMD86KumqjzVPpcEFpT9qy8sUXyStzlNU9oe X-Received: by 2002:aca:2407:: with SMTP id n7mr12356410oic.14.1579514535665; Mon, 20 Jan 2020 02:02:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579514535; cv=none; d=google.com; s=arc-20160816; b=scuFzOqznn0x/CXTg2e/rh0buhFxfXefByTG6+h+Wqm/+AVlBjBjxLlGcOvnwTfuQH fz/EWvLF5JPNRFFIv0kkb9ebcCktp4p1YbGsrgEUpfcgr/nFZUfvqBAQJWDhE9wS0ekF 7XbeE2Js/j4W3pcXdmmUeYy8iFzKb8I9mX30oFizIdz/HddehKNoE0ZTnXopA4D5mUfv rryayYcL1uATu0/djjPZbcoezmEiHO2Jnn6riC8RRbcfkFehc3qF5J32C8xIztP/hUqH HC7ZXXd5/vwLlrF+WKvEAchzvYwk3M5jstUCYmw6r2TpB/qYsAifK9ApnWFxHDIcPpcQ QHXQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=HOYg6oOVjkoARqNmUat2HnMfBYyFvzJhRCMU2t97tUg=; b=qmH7WU8BWDz+kq7nmEkyh4oqphFPTGV7cO49tBUV270EVxz+JzRCxYe+M4JZGDxw6l bbExT/fygdaBFis+mumujthjdLqEdzfcRFaGBrpcm5mDxckPm+o/U0iVPOxT3JPJxZFw qCZSrsw8GB595SOSBXeeE2rp4jr29slb5v2LptT36S2AoMieghN0sbnaov6SZOSgVfYw k14BOX5xfXHpAa8ynlghrIBhNoa9GMmYkaP9WDi9vouOEaQ/rrLwzOTpwdF2Bze2f+7b SdCZQAO8J+uzmj958ySLZFkDTxplW5T5y3x5Pe1T3k4i1h0lKz2jLKt0BPQw1XaQiI1k UHWg== 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 r6si18939076otq.95.2020.01.20.02.02.03; Mon, 20 Jan 2020 02:02:15 -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 S1726775AbgATKBG (ORCPT + 99 others); Mon, 20 Jan 2020 05:01:06 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:59682 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726039AbgATKBG (ORCPT ); Mon, 20 Jan 2020 05:01:06 -0500 Received: from DGGEMS414-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id C6974633E9A69DAE7EEF; Mon, 20 Jan 2020 18:01:04 +0800 (CST) Received: from szvp000203569.huawei.com (10.120.216.130) by DGGEMS414-HUB.china.huawei.com (10.3.19.214) with Microsoft SMTP Server id 14.3.439.0; Mon, 20 Jan 2020 18:00:58 +0800 From: Chao Yu To: CC: , , , Chao Yu Subject: [PATCH] f2fs: fix to force keeping write barrier for strict fsync mode Date: Mon, 20 Jan 2020 18:00:45 +0800 Message-ID: <20200120100045.70210-1-yuchao0@huawei.com> X-Mailer: git-send-email 2.18.0.rc1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.120.216.130] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; + if (unlikely(f2fs_readonly(inode->i_sb) || is_sbi_flag_set(sbi, SBI_CP_DISABLED))) return 0; -- 2.18.0.rc1