Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4835100pxb; Thu, 14 Oct 2021 12:58:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx8sIf630fIi6mOBkBZjvkktG8w27lZe2XUzJNu6vDqxAfmfAaexnNCVoDJCSBb3NwK9AIS X-Received: by 2002:a17:90b:1e4f:: with SMTP id pi15mr8374224pjb.231.1634241490841; Thu, 14 Oct 2021 12:58:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634241490; cv=none; d=google.com; s=arc-20160816; b=ZjjvPaEMPIH7uL6sgLo1rX/SxcucPNJ9RDpyopmmkX1MBrx0ogEGr4f8lYM8aU6EDe MnYj5KqIdQUSNBU9Zb4RdbazSuhYMYt3yCF5ZChKEbVDb4uJxmJSlz1Gj+C1Gu9dp0Z9 iLHHx/vpVqdTHGfRVfAOmsYBmDumEiPijD3xFR3kybLSJpfm5zhg8dbH/LBtk2j+zkkQ lUCelkuOlklg5D+tg7cd6NoIv0zkTNH/REkrgLv1Fh1YBqMqt1YqKf7fDJG9BWouVlYP QI5ZrPv5lHRaoVCib6VyVfCx9zIlB5fj2gCFGyi9Q2fdBUxEQLEik8n6mHUWP+FbnoqN u/8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LEZr6GO1h/k9dGht2bScIp0Zu6CYv88NhfBSmFdRTCw=; b=N41x+UMz9xbAI7F7D/XuyONUCDpuISd/ZkIZnufHZu4mC2iJixRXCkz0ANv+0IO7v3 5M9yAeNxfeVYU11YTCos8ht7f5BGwtTi4sSucCz3d86V3vmDgzJAxEPot1dyna54thtI nMFoqM/s/SSvtPCj5HsIrK3TFY9XRDJ3qWJrQPzL0YAhi2VeSmfy5DeDfHULX9Y94ZG5 Okl8zpvqTddlov7vzpJ5b5cPwM5u16iZ3nfnAKDNcwmuGTUPsIkH9+2qj+mXGsYg6iJ/ bKg/rJf5G4qxtLbkJQ0gNl844pGrPZCrtNI9m9cwB0Q9AhQyJD/n3DGqX0ViEnDGHGP8 H1ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E1Ss3j5w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u20si7448204pfg.199.2021.10.14.12.57.57; Thu, 14 Oct 2021 12:58:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=E1Ss3j5w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233310AbhJNPF5 (ORCPT + 99 others); Thu, 14 Oct 2021 11:05:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:51564 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233466AbhJNPES (ORCPT ); Thu, 14 Oct 2021 11:04:18 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5849F611CE; Thu, 14 Oct 2021 15:00:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634223635; bh=8L2qBI4o4/bdfydKxL/itud8i8SRLBD9j7MQr4AVCow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=E1Ss3j5wJEfJ311Eug7G4bwHGy0QlfRnEn99QMdjOrxMozUlzFSrVITw1ufvQirbR HD0u0y19JSeNcNC1Ggu1FwV2KDuNs768DFss9+XGfL9cqL+r+GhEYEQgMup8MN4cBr 0RJ3FmIjmBCkHN1shG6aZ+sppA64gUQXsYwBGWIA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Zhang Yi , Jan Kara , Theodore Tso , Sasha Levin Subject: [PATCH 5.14 01/30] ext4: check and update i_disksize properly Date: Thu, 14 Oct 2021 16:54:06 +0200 Message-Id: <20211014145209.566779985@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014145209.520017940@linuxfoundation.org> References: <20211014145209.520017940@linuxfoundation.org> User-Agent: quilt/0.66 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Zhang Yi [ Upstream commit 4df031ff5876d94b48dd9ee486ba5522382a06b2 ] After commit 3da40c7b0898 ("ext4: only call ext4_truncate when size <= isize"), i_disksize could always be updated to i_size in ext4_setattr(), and we could sure that i_disksize <= i_size since holding inode lock and if i_disksize < i_size there are delalloc writes pending in the range upto i_size. If the end of the current write is <= i_size, there's no need to touch i_disksize since writeback will push i_disksize upto i_size eventually. So we can switch to check i_size instead of i_disksize in ext4_da_write_end() when write to the end of the file. we also could remove ext4_mark_inode_dirty() together because we defer inode dirtying to generic_write_end() or ext4_da_write_inline_data_end(). Signed-off-by: Zhang Yi Reviewed-by: Jan Kara Signed-off-by: Theodore Ts'o Link: https://lore.kernel.org/r/20210716122024.1105856-2-yi.zhang@huawei.com Signed-off-by: Sasha Levin --- fs/ext4/inode.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 73daf9443e5e..a47ff8ce289b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3089,35 +3089,37 @@ static int ext4_da_write_end(struct file *file, end = start + copied - 1; /* - * generic_write_end() will run mark_inode_dirty() if i_size - * changes. So let's piggyback the i_disksize mark_inode_dirty - * into that. + * Since we are holding inode lock, we are sure i_disksize <= + * i_size. We also know that if i_disksize < i_size, there are + * delalloc writes pending in the range upto i_size. If the end of + * the current write is <= i_size, there's no need to touch + * i_disksize since writeback will push i_disksize upto i_size + * eventually. If the end of the current write is > i_size and + * inside an allocated block (ext4_da_should_update_i_disksize() + * check), we need to update i_disksize here as neither + * ext4_writepage() nor certain ext4_writepages() paths not + * allocating blocks update i_disksize. + * + * Note that we defer inode dirtying to generic_write_end() / + * ext4_da_write_inline_data_end(). */ new_i_size = pos + copied; - if (copied && new_i_size > EXT4_I(inode)->i_disksize) { + if (copied && new_i_size > inode->i_size) { if (ext4_has_inline_data(inode) || - ext4_da_should_update_i_disksize(page, end)) { + ext4_da_should_update_i_disksize(page, end)) ext4_update_i_disksize(inode, new_i_size); - /* We need to mark inode dirty even if - * new_i_size is less that inode->i_size - * bu greater than i_disksize.(hint delalloc) - */ - ret = ext4_mark_inode_dirty(handle, inode); - } } if (write_mode != CONVERT_INLINE_DATA && ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA) && ext4_has_inline_data(inode)) - ret2 = ext4_da_write_inline_data_end(inode, pos, len, copied, + ret = ext4_da_write_inline_data_end(inode, pos, len, copied, page); else - ret2 = generic_write_end(file, mapping, pos, len, copied, + ret = generic_write_end(file, mapping, pos, len, copied, page, fsdata); - copied = ret2; - if (ret2 < 0) - ret = ret2; + copied = ret; ret2 = ext4_journal_stop(handle); if (unlikely(ret2 && !ret)) ret = ret2; -- 2.33.0