Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp4735912pxb; Thu, 14 Oct 2021 10:55:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyVcwwMn0z7LejWLLE33JlJBGK0soP5tkxl/W2XSKBoUaYzeKd5fIe0UVdtQ3EuvABTcopq X-Received: by 2002:a17:90a:a085:: with SMTP id r5mr21871334pjp.8.1634234111161; Thu, 14 Oct 2021 10:55:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634234111; cv=none; d=google.com; s=arc-20160816; b=mJ0c74gR0m814B7LrpcLWDCIGwspS3mo4HbzbSjTT4UkdO2VTLcJkYj8INhG1mJD3P 9jyzHPl8U3/YQuFC6qpjl9sViSJe63Dbh7LCXx81UwsVDgj6j5B3vIGAOuXBgCw70M1g V1QVhqu74bjqvuN4/k5oX4PEgk+KsJjkW7imi3MdmeK+L1uAW7OBUYFIDYad+V+SK5dq iMPk7Hj4VWhnEeaAtTq/Zc0A0s7Djn4UAEiECSP50j4Kt5AanmDNIDFKejMQKU4X8wvB UxwCCRCw8l79fbSZocXcopDAYw0v+zNRxFUGcXzz8M+AlhYYZfNztkGH8W6xlB3Y2t4P EFZw== 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=wcpNLoxwjw55cmaUXlKKmDPBnaHVa53kWDMBYoiRUA8=; b=SmaaB85vRb1vmXOzFBOnVYl9nvG8V8CdmAO/YdbwSj05hrLFD/jqzzZEvOVry0Npw/ AlD24v2n10y7qjXiJUj8TWQWtofhl3+uCIWjXaWu8EDVoc97C7kzK+gwDB9QlOyF39lA Iwb6xKtxlMx5MJVtQ55Y+yLAM1pPAoQdhn1mMIbOKPXai2Z9SEF6ixZ2eae7f8IXc0w2 CV8KIR6nTP7mJgzpF6ePxS4i4O0PQ4e8OLMbpXEOu5+AWkZFvw8k+g0u99EUfc9EEZBc A9NIvO9SvEidq+/TWbNqlHQiSeGbYaJCZIlfObJriaLPBODT/7dgu5miJ9QA2K3dfp7m cJRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=tLs7p+Cm; 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 u8si5351699pfg.134.2021.10.14.10.54.56; Thu, 14 Oct 2021 10:55:11 -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=tLs7p+Cm; 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 S233199AbhJNPD7 (ORCPT + 99 others); Thu, 14 Oct 2021 11:03:59 -0400 Received: from mail.kernel.org ([198.145.29.99]:49670 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231783AbhJNPCk (ORCPT ); Thu, 14 Oct 2021 11:02:40 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 2D89161213; Thu, 14 Oct 2021 14:59:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1634223573; bh=k6lBR4/y3fkaS5nGWhR9R4qf/QCjtp+95GeKhYMgTB8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tLs7p+CmwRS3RRAc+p/A+C8S9M8rEeYeSpM4I2n3OL57TJeBK6Efw6DCOxPrQ9/1N Qv80w94GOq89Lla7Nf7UbOFUUcssZ8EQs+Tc6pntDpxe+tFbE5nqYTlm1rfhFor9eg 7AwInBsmHYeh14Re37mL300PYg2sbl3kep869vvs= 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.10 01/22] ext4: check and update i_disksize properly Date: Thu, 14 Oct 2021 16:54:07 +0200 Message-Id: <20211014145208.032762384@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211014145207.979449962@linuxfoundation.org> References: <20211014145207.979449962@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 63a292db7587..f0dcc09e220b 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -3090,35 +3090,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