Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3654525pxb; Mon, 24 Jan 2022 14:32:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5liYkKkFBm/icznteU5vIXr4FbtfbhhYQr1YtP8JqoUDdZ6TQOZoJpkND42SS9n2AYpq8 X-Received: by 2002:a05:6a00:1a4f:b0:4c9:e7b7:d84b with SMTP id h15-20020a056a001a4f00b004c9e7b7d84bmr4509347pfv.61.1643063563127; Mon, 24 Jan 2022 14:32:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063563; cv=none; d=google.com; s=arc-20160816; b=XBNCXX659dZNYYrTfA8S5JdKaPeJOKrlFxfYl8ygqOPIQ+B17TdeX7wZQVKl7186K9 M5/NkiAb1POeVK/2a8rebf+nipnyqkKYn3h4lbWT39kCPbg4MDKp52rU/juPocj5wKBp F+tcCCflCoz6+FZrFL+vhFsKrGCpOm5ZyYbCPho7z5PHYYxhiTgC8JVGqOouhcYs8cXC vUD2wO8dwD9HmvCffDaEuTqQoe1wFF9sPlSJs+GCwPIprvqYs1CGc8cDs+1Gd6dsbeAl bOHiGpp8cX+mUvmqL5GPWA3ixkt88849eOyhRUmp5NtTOwPx4+RHebKJng+XZnJm8vHN 49uQ== 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=Q5QNC0yA8ekCvxddAChTL7bQ/nsa8yAgQgnNHeazchI=; b=NgpO0iYq4XTSZRaKde4BpMeZQImnagsWxompRIbui7ILCB0wfDxXU7FqzlxX3LYkRW v89iWhRfoq/QxC9m5e/ATGZPH+Fwc6l2JFmX+2LMKrcrgrXQ+6xzFupFPquMsNX6mlpj RtvDbXSiQsmJRwoOK+DvDymYmVnKE0FSJxuG5KCiII3HGBihMo9U9S+s03J6NdBRPcLI pSutpnSQH29YpfbZt0M54vceNPNh7YUkqx/GPdTS4923UCRRfXzM7Bce6BkJgYMXgETn kBVc0Hk/7Cr0wz/kgysnSdmLVwqpwBMWuiPQ3DbznK8QEc8pmRpXWMG4pw7tKEYaYch6 pekg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Leruon5V; 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 y8si10517935pfq.133.2022.01.24.14.32.31; Mon, 24 Jan 2022 14:32:43 -0800 (PST) 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=Leruon5V; 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 S1588057AbiAXWah (ORCPT + 99 others); Mon, 24 Jan 2022 17:30:37 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:56218 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1456183AbiAXViC (ORCPT ); Mon, 24 Jan 2022 16:38:02 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B5A6961516; Mon, 24 Jan 2022 21:38:00 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B091C36AE7; Mon, 24 Jan 2022 21:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643060280; bh=r3t9De6Vv16FA1XPz2GR0dzvGr6aoOUnk+n2LPMHXP0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Leruon5Vc1bLKi1LU0j+/xKUOp/ZML3em0KVZ6A34MRWWM9CAI1abn5qZ2eFTuaBw rG7TTer68BTKA9gVTlwFp2334SixO1rbezxQ2+J1Viihr4h7JMyyfb4VXExRwkpe2m oLV76i/Lh6YUB6c1EXWhXp1BeT/wYUNhve0EB7O4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Xin Yin , Harshad Shirwadkar , Theodore Tso , stable@kernel.org Subject: [PATCH 5.16 0896/1039] ext4: use ext4_ext_remove_space() for fast commit replay delete range Date: Mon, 24 Jan 2022 19:44:45 +0100 Message-Id: <20220124184155.406199813@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@linuxfoundation.org> User-Agent: quilt/0.66 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: Xin Yin commit 0b5b5a62b945a141e64011b2f90ee7e46f14be98 upstream. For now ,we use ext4_punch_hole() during fast commit replay delete range procedure. But it will be affected by inode->i_size, which may not correct during fast commit replay procedure. The following test will failed. -create & write foo (len 1000K) -falloc FALLOC_FL_ZERO_RANGE foo (range 400K - 600K) -create & fsync bar -falloc FALLOC_FL_PUNCH_HOLE foo (range 300K-500K) -fsync foo -crash before a full commit After the fast_commit reply procedure, the range 400K-500K will not be removed. Because in this case, when calling ext4_punch_hole() the inode->i_size is 0, and it just retruns with doing nothing. Change to use ext4_ext_remove_space() instead of ext4_punch_hole() to remove blocks of inode directly. Signed-off-by: Xin Yin Reviewed-by: Harshad Shirwadkar Link: https://lore.kernel.org/r/20211223032337.5198-2-yinxin.x@bytedance.com Signed-off-by: Theodore Ts'o Cc: stable@kernel.org Signed-off-by: Greg Kroah-Hartman --- fs/ext4/fast_commit.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) --- a/fs/ext4/fast_commit.c +++ b/fs/ext4/fast_commit.c @@ -1812,11 +1812,14 @@ ext4_fc_replay_del_range(struct super_bl } } - ret = ext4_punch_hole(inode, - le32_to_cpu(lrange.fc_lblk) << sb->s_blocksize_bits, - le32_to_cpu(lrange.fc_len) << sb->s_blocksize_bits); - if (ret) - jbd_debug(1, "ext4_punch_hole returned %d", ret); + down_write(&EXT4_I(inode)->i_data_sem); + ret = ext4_ext_remove_space(inode, lrange.fc_lblk, + lrange.fc_lblk + lrange.fc_len - 1); + up_write(&EXT4_I(inode)->i_data_sem); + if (ret) { + iput(inode); + return 0; + } ext4_ext_replay_shrink_inode(inode, i_size_read(inode) >> sb->s_blocksize_bits); ext4_mark_inode_dirty(NULL, inode);