Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1597037ybl; Tue, 3 Dec 2019 09:34:24 -0800 (PST) X-Google-Smtp-Source: APXvYqy1NCLek1swzY75uI+0x/s2lDV8o0brEAmcB/jyMSH/TGF+LD7e01nYmP36GsUs7hjimqqt X-Received: by 2002:a9d:7592:: with SMTP id s18mr4233590otk.130.1575394464673; Tue, 03 Dec 2019 09:34:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575394464; cv=none; d=google.com; s=arc-20160816; b=vs1DdH5Y4zLhhyLSrP7ZIlrdnVIvP8uDok6Y3n6GiGNqZqx0FTdFmeiOB9fJFFmZ2J nTm5Xs7v6HTnPBCMXk10gCFqsvcR0GQpnA5mx785Z2k33SribqnY9q6BzoUmPR61Kpfq h/WQWDcOaX2JXRHbCznrQwS74rix0VoYM9s69N3YS6KYPDdcMELmOQ0+NH1lAp2eG/l4 r0RIxyIqECnUg6DIf+IOyNjvwUMT3o/8DVX/y0Xx/VoruaQMcsibI2jCWDh3qQeYKI7u srDF0g4fAJTq0X14wo+rovJXzPIpOlD9BuIwo/jXYqdfzvMKrQjFfmN7n8UEx474RrbQ XfZQ== 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:dkim-signature; bh=9e0Pec+yEuFjtL1EQoStuL//MtVWVks3aE7PRsZm+II=; b=txTvewL/VabrB6hCK3pN7BgVK3annmF3BGxhb+vo0H4Ys9LhXO7dTSylC7R1dYIpv2 rTktOE/pqvHJwITqWaZMTWfmeICDFR0uRbg3F96Ufw5RMlGqgq9OOQvPr3lQF8pwkts/ qjJOovgcYYvxKXdzvkTL8OIleeHc24lvw234PRGgpVjMbsUMhrybM03Zh1brCBibloq5 LTEiyWwN0KIhxspt3/EfPFouPuMAR+FbE9kOWxaxlVe9hnTSbzFjr8zJ4ZRW55CJqabH N6T3s+PqC6PS075br3ksSKaqTQ8GNRreGY5WT/5kA0wZwOoR+wd93tZFly22/em7qg5H axGQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=yzWRAuQs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g17si1620017otg.160.2019.12.03.09.34.10; Tue, 03 Dec 2019 09:34:24 -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; dkim=pass header.i=@kernel.org header.s=default header.b=yzWRAuQs; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727183AbfLCRdK (ORCPT + 99 others); Tue, 3 Dec 2019 12:33:10 -0500 Received: from mail.kernel.org ([198.145.29.99]:34286 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726074AbfLCRdK (ORCPT ); Tue, 3 Dec 2019 12:33:10 -0500 Received: from localhost (unknown [104.132.0.81]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C9C32073B; Tue, 3 Dec 2019 17:33:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1575394389; bh=L6bfw+QYF4n6bm/yWyEeXWAiOWxcna6+5qT5/wHY2DQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=yzWRAuQslIzLXKtM0DWjbL1bui0cXnluPqReXwPUqAk1GL45OjwJPNKmti06o+0/c M5LU7MK4qmIA4vJM2f8BiIFu1M2az8x4Q6Hh3YsTr8oOdRhnsDNg/MxHGdhpYxc52C bKLWVu+r2C9eJYEMb0lLhIoqakXpV6kCxQB/9E80= Date: Tue, 3 Dec 2019 09:33:08 -0800 From: Jaegeuk Kim To: Damien Le Moal Cc: linux-f2fs-devel@lists.sourceforge.net, linux-kernel@vger.kernel.org, Chao Yu , linux-fsdevel@vger.kernel.org, Javier Gonzalez , Shinichiro Kawasaki Subject: Re: [PATCH v2] f2fs: Fix direct IO handling Message-ID: <20191203173308.GA41093@jaegeuk-macbookpro.roam.corp.google.com> References: <20191126075719.1046485-1-damien.lemoal@wdc.com> <20191126234428.GB20652@jaegeuk-macbookpro.roam.corp.google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191126234428.GB20652@jaegeuk-macbookpro.roam.corp.google.com> User-Agent: Mutt/1.8.2 (2017-04-18) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Thank you for checking the patch. I found some regressions in xfstests, so want to follow the Damien's one like below. Thanks, === From 9df6f09e3a09ed804aba4b56ff7cd9524c002e69 Mon Sep 17 00:00:00 2001 From: Jaegeuk Kim Date: Tue, 26 Nov 2019 15:01:42 -0800 Subject: [PATCH] f2fs: preallocate DIO blocks when forcing buffered_io The previous preallocation and DIO decision like below. allow_outplace_dio !allow_outplace_dio f2fs_force_buffered_io (*) No_Prealloc / Buffered_IO Prealloc / Buffered_IO !f2fs_force_buffered_io No_Prealloc / DIO Prealloc / DIO But, Javier reported Case (*) where zoned device bypassed preallocation but fell back to buffered writes in f2fs_direct_IO(), resulting in stale data being read. In order to fix the issue, actually we need to preallocate blocks whenever we fall back to buffered IO like this. No change is made in the other cases. allow_outplace_dio !allow_outplace_dio f2fs_force_buffered_io (*) Prealloc / Buffered_IO Prealloc / Buffered_IO !f2fs_force_buffered_io No_Prealloc / DIO Prealloc / DIO Reported-and-tested-by: Javier Gonzalez Signed-off-by: Damien Le Moal Tested-by: Shin'ichiro Kawasaki Signed-off-by: Jaegeuk Kim --- fs/f2fs/data.c | 13 ------------- fs/f2fs/file.c | 43 +++++++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/fs/f2fs/data.c b/fs/f2fs/data.c index a034cd0ce021..fc40a72f7827 100644 --- a/fs/f2fs/data.c +++ b/fs/f2fs/data.c @@ -1180,19 +1180,6 @@ int f2fs_preallocate_blocks(struct kiocb *iocb, struct iov_iter *from) int err = 0; bool direct_io = iocb->ki_flags & IOCB_DIRECT; - /* convert inline data for Direct I/O*/ - if (direct_io) { - err = f2fs_convert_inline_inode(inode); - if (err) - return err; - } - - if (direct_io && allow_outplace_dio(inode, iocb, from)) - return 0; - - if (is_inode_flag_set(inode, FI_NO_PREALLOC)) - return 0; - map.m_lblk = F2FS_BLK_ALIGN(iocb->ki_pos); map.m_len = F2FS_BYTES_TO_BLK(iocb->ki_pos + iov_iter_count(from)); if (map.m_len > map.m_lblk) diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c index c0560d62dbee..0e1b12a4a4d6 100644 --- a/fs/f2fs/file.c +++ b/fs/f2fs/file.c @@ -3386,18 +3386,41 @@ static ssize_t f2fs_file_write_iter(struct kiocb *iocb, struct iov_iter *from) ret = -EAGAIN; goto out; } - } else { - preallocated = true; - target_size = iocb->ki_pos + iov_iter_count(from); + goto write; + } - err = f2fs_preallocate_blocks(iocb, from); - if (err) { - clear_inode_flag(inode, FI_NO_PREALLOC); - inode_unlock(inode); - ret = err; - goto out; - } + if (is_inode_flag_set(inode, FI_NO_PREALLOC)) + goto write; + + if (iocb->ki_flags & IOCB_DIRECT) { + /* + * Convert inline data for Direct I/O before entering + * f2fs_direct_IO(). + */ + err = f2fs_convert_inline_inode(inode); + if (err) + goto out_err; + /* + * If force_buffere_io() is true, we have to allocate + * blocks all the time, since f2fs_direct_IO will fall + * back to buffered IO. + */ + if (!f2fs_force_buffered_io(inode, iocb, from) && + allow_outplace_dio(inode, iocb, from)) + goto write; + } + preallocated = true; + target_size = iocb->ki_pos + iov_iter_count(from); + + err = f2fs_preallocate_blocks(iocb, from); + if (err) { +out_err: + clear_inode_flag(inode, FI_NO_PREALLOC); + inode_unlock(inode); + ret = err; + goto out; } +write: ret = __generic_file_write_iter(iocb, from); clear_inode_flag(inode, FI_NO_PREALLOC); -- 2.19.0.605.g01d371f741-goog