Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp3440321ybg; Mon, 28 Oct 2019 12:52:51 -0700 (PDT) X-Google-Smtp-Source: APXvYqygKnRQmZDMrqQzvm9kLX+39Tixl+MrlXCUz9HJJRJkN+pmNIJzWI/qRB4xjVN7K2nb6zi+ X-Received: by 2002:a17:906:c801:: with SMTP id cx1mr18741285ejb.266.1572292371504; Mon, 28 Oct 2019 12:52:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1572292371; cv=none; d=google.com; s=arc-20160816; b=vK/Jxd0/mLQW3GZlRy04IuXEnSIiNauOccZ7InepN6bDwWb1Dzko5vvPJ5uVKTOTmt litUGhknDVrO0BEb6bESpbcL2JCnfR8ATAQxJ3CZBXtsmrEINZfYRZ86cyADBxQvi+7n 7dQBUSzpPiBGyh28YZLQDoNNFVdENwAddfV9+ZgQGWb/cxmkh0ct61mFmUsa4rIfGJR8 FN1suDstzd7rl9ciV+Q7EKuxLVYEFR8CXAoLjr5jNaZMkD4kx5gcio3VZR4fiJ6iTufG aevL1JvHjplxf6BSR7I3n0R4UrMRH67WesK1J9kChLJzQxHTSOnoacWvefAyT2rEdQVA 41YA== 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=G6CFq/h8k/c9oWEGqBl9JxHFVW55BNMnE9xk8vXWFJc=; b=YCeuu65XkhlRaUCTYEYjjyMwTYpM/XPIpmminaHOXMED+fqlDpYvudK/VOTkDXtQ7e 79YDnM/Rtfc3i8IRmsdm8SNW7ICf6liitjl1AjOAZglpMRjYTEhm2g9qsxty5rznVn3J mXlwEMB7YSTud8CPK71k6wUypgXfd6/OLQu3y/zf5UoymIlekMLZcUt1gySCKernd83H c1cpl+li8PsneDoMyl2+hZJ5YClPvuXdk6aSMdC4hNb73Py0H6f+tL8IRQgryL8iZkZe yP2l+2VWYuruXM4xKDMvpim+oXKQYPfnxBTI3RTD4/Hb9sx5vtSDCY8mbI7pK3UxFqxy cnkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=J4jFXinL; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-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 gq18si6985602ejb.41.2019.10.28.12.52.26; Mon, 28 Oct 2019 12:52:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-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=@mbobrowski-org.20150623.gappssmtp.com header.s=20150623 header.b=J4jFXinL; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388347AbfJ1KvY (ORCPT + 99 others); Mon, 28 Oct 2019 06:51:24 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:35705 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388345AbfJ1KvY (ORCPT ); Mon, 28 Oct 2019 06:51:24 -0400 Received: by mail-pf1-f195.google.com with SMTP id d13so5594189pfq.2 for ; Mon, 28 Oct 2019 03:51:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mbobrowski-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=G6CFq/h8k/c9oWEGqBl9JxHFVW55BNMnE9xk8vXWFJc=; b=J4jFXinLsX5dmwoyvFzhhoocnfyONCPBLWxTe23x2/t4nHuRk8IBRma6i1y4Dg11rG 1y5wXczUJYFBHaTrmnR00M5mGOqtXLrLxyJfj9ox5qp5NiEiba9hADYVBYcbucKgpKrt 2I8ght4J88dXiNHUUtNhHTk0Ty9oYuLaTXNGpELwJf0NOA2mZ8Qk4CLGn6lNhXkwsqM4 o+QjUrX17iHQrfNJgIjEdHO+3LN6Ag7v/LiUZlxSQsIUK9+YOdzCzZkG1vDAGWHNbR0y 0Yd0zVxM0Ms7CAs4o1mlkzjqGhotCuYv2FYuSxNt2z+rtNXIsbK/WZHM+QYC2Hy82LTp DJ/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=G6CFq/h8k/c9oWEGqBl9JxHFVW55BNMnE9xk8vXWFJc=; b=rAvEnBJBMb/hwIfJjTI1z6TsqvMMqgVmHkA8EDz0DupOf4qjepqyBaq17XNUgcs4ux U9wfvbkpMSnGpPaDMeMyqrui4re/ho3XP0FHK+likBOxJ5YYxjJ0bVuJA3Jp+7KMKEWF 9fRseB3LY9sMpV6DqZU1v4a6eGx19TZHy3DTh5b94TNq0hU5n5PHbj0qQTL9C6JTpeTW nhVCzGLKWL/y/3raF34SZr6WEo7HI7jJS06IZeQoCxU4c5am/oPa5+YcwmCfY+QhCDeN itvCapIzlRC2sSMB+52hTD88KlacQgwbXT7mbIt6PRR5ckRj167Lb2hyuRs4PJkWwNer uJuw== X-Gm-Message-State: APjAAAXi/10JIY1HF51tXJWSJOKIE6SxUJiksO+MGSW+m08hQ8VvpyDK O+i/FDkq1gKnwLDiyJwXWZpV X-Received: by 2002:a63:c40e:: with SMTP id h14mr19858935pgd.254.1572259883449; Mon, 28 Oct 2019 03:51:23 -0700 (PDT) Received: from poseidon.bobrowski.net (d114-78-127-22.bla803.nsw.optusnet.com.au. [114.78.127.22]) by smtp.gmail.com with ESMTPSA id m4sm8948764pjs.8.2019.10.28.03.51.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Oct 2019 03:51:22 -0700 (PDT) Date: Mon, 28 Oct 2019 21:51:16 +1100 From: Matthew Bobrowski To: tytso@mit.edu, jack@suse.cz, adilger.kernel@dilger.ca Cc: linux-ext4@vger.kernel.org, linux-fsdevel@vger.kernel.org, hch@infradead.org, david@fromorbit.com, darrick.wong@oracle.com Subject: [PATCH v6 03/11] ext4: iomap that extends beyond EOF should be marked dirty Message-ID: <2c5b5fc06d1ba70676f09dfc5430ea1c4bafc631.1572255425.git.mbobrowski@mbobrowski.org> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org This patch addresses what Dave Chinner had discovered and fixed within commit: 7684e2c4384d. This changes does not have any user visible impact for ext4 as none of the current users of ext4_iomap_begin() that extend files depend on IOMAP_F_DIRTY. When doing a direct IO that spans the current EOF, and there are written blocks beyond EOF that extend beyond the current write, the only metadata update that needs to be done is a file size extension. However, we don't mark such iomaps as IOMAP_F_DIRTY to indicate that there is IO completion metadata updates required, and hence we may fail to correctly sync file size extensions made in IO completion when O_DSYNC writes are being used and the hardware supports FUA. Hence when setting IOMAP_F_DIRTY, we need to also take into account whether the iomap spans the current EOF. If it does, then we need to mark it dirty so that IO completion will call generic_write_sync() to flush the inode size update to stable storage correctly. Signed-off-by: Matthew Bobrowski Reviewed-by: Jan Kara Reviewed-by: Ritesh Harjani --- fs/ext4/inode.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 0a9ea291cfab..da2ca81e3d9c 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3523,8 +3523,14 @@ static int ext4_iomap_begin(struct inode *inode, loff_t offset, loff_t length, return ret; } + /* + * Writes that span EOF might trigger an I/O size update on completion, + * so consider them to be dirty for the purposes of O_DSYNC, even if + * there is no other metadata changes being made or are pending here. + */ iomap->flags = 0; - if (ext4_inode_datasync_dirty(inode)) + if (ext4_inode_datasync_dirty(inode) || + offset + length > i_size_read(inode)) iomap->flags |= IOMAP_F_DIRTY; iomap->bdev = inode->i_sb->s_bdev; iomap->dax_dev = sbi->s_daxdev; -- 2.20.1