Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1018073yba; Thu, 4 Apr 2019 02:32:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqygkeBxTShZbbVzINK307xXabYjyEX/6TGJm2yMCj8A670OYDJGpXOXspGxgPCRKBZzXpTb X-Received: by 2002:a62:ee0a:: with SMTP id e10mr4821352pfi.6.1554370334262; Thu, 04 Apr 2019 02:32:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554370334; cv=none; d=google.com; s=arc-20160816; b=nffH4BCjQIXpVceBL0XrZly90uxLTVZl2lTAcStKn/gJDxjlrReThrxMPWbCTBO9cS XW+HIQ8cQV5COyWjJOuRoQP2wayLHQ4Jm31tN7JLti+udeBfpqzjjYEWLDPCeikMxkRy PmK4qYptEojs2ejaci4sAw3Mqa5L0XCEph3Fzp1PngNXe2oKa0k6XZ8YJ1VK9LecTZAw M1veEaEq71OhUexoXMmqgWIjxozfS5JD2EBEfG/0Bj9iwV7aoiDtHGGX3/k64QZvxhUr YO7gzykM0ukQ1rgm2QC4Uq75jk1U8D7ErZ50ZE3IAO9KSU1iLd0eb+aNK0mu8SO66gYX 6vLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TWeKbnCaq3OCjSc6OGy5eBFYZkdmMJjyuDjB1VvcxIY=; b=zTysp9u6E7biIGop7bAhuWwoEsY9o8ATH17MQPNwrRa5STWh01vDhkUR8pv7Dk14HJ LgmkRXmcOxbiSSIs7JCYALHtEFSY0nq3W4LQSDdjp6ttbbpk+ucbdhVZ22hscYx5xNgt eKPJ/Umc7zm6fALBatTk1q1ul537K2K4QlEvwE00uKtvjgkTKYAGK0lTl1/iJ8e66snr KUWNvN1R11T9bojONEZRcab8tqQBooZYOCxqBTgILrVJfuskmtD9HQ6dOxJtyC/LVipd R3GPBz4F2y4KXRRLLVZ+0cI/CQAfYqN1OBXFanLS56rXZS1cudManuwGsxqVzW+3whKe R1Uw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=Zetvo7DV; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w7si9893937plp.341.2019.04.04.02.31.59; Thu, 04 Apr 2019 02:32:14 -0700 (PDT) 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=Zetvo7DV; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732879AbfDDJJq (ORCPT + 99 others); Thu, 4 Apr 2019 05:09:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:49014 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731719AbfDDJJo (ORCPT ); Thu, 4 Apr 2019 05:09:44 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (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 9292A214AF; Thu, 4 Apr 2019 09:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1554368983; bh=NZHwJHAtqPSQbuHknju41mfXyfSWeczpwIwzIQwcNvQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Zetvo7DVmPJAwDAFMNdLrXdQboI5fETU6uHeDjGU55TRLKJ37umLbV3oiHAoyNwL+ rHs0dHx+ASVlMIO4hQ/7ozN0e1aMf/qTx4qElbTXMQwmmhl7NJth2azRCU204J540O NzBj9G3sJhzeVjmYLmHLj9X0yra72jQAdtsHetJQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Eric Whitney , Theodore Tso , Sasha Levin Subject: [PATCH 5.0 054/246] ext4: fix bigalloc cluster freeing when hole punching under load Date: Thu, 4 Apr 2019 10:45:54 +0200 Message-Id: <20190404084620.908464492@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190404084619.236418459@linuxfoundation.org> References: <20190404084619.236418459@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 5.0-stable review patch. If anyone has any objections, please let me know. ------------------ [ Upstream commit 7bd75230b43727b258a4f7a59d62114cffe1b6c8 ] Ext4 may not free clusters correctly when punching holes in bigalloc file systems under high load conditions. If it's not possible to extend and restart the journal in ext4_ext_rm_leaf() when preparing to remove blocks from a punched region, a retry of the entire punch operation is triggered in ext4_ext_remove_space(). This causes a partial cluster to be set to the first cluster in the extent found to the right of the punched region. However, if the punch operation prior to the retry had made enough progress to delete one or more extents and a partial cluster candidate for freeing had already been recorded, the retry would overwrite the partial cluster. The loss of this information makes it impossible to correctly free the original partial cluster in all cases. This bug can cause generic/476 to fail when run as part of xfstests-bld's bigalloc and bigalloc_1k test cases. The failure is reported when e2fsck detects bad iblocks counts greater than expected in units of whole clusters and also detects a number of negative block bitmap differences equal to the iblocks discrepancy in cluster units. Signed-off-by: Eric Whitney Signed-off-by: Theodore Ts'o Signed-off-by: Sasha Levin --- fs/ext4/extents.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/fs/ext4/extents.c b/fs/ext4/extents.c index 240b6dea5441..252bbbb5a2f4 100644 --- a/fs/ext4/extents.c +++ b/fs/ext4/extents.c @@ -2956,14 +2956,17 @@ again: if (err < 0) goto out; - } else if (sbi->s_cluster_ratio > 1 && end >= ex_end) { + } else if (sbi->s_cluster_ratio > 1 && end >= ex_end && + partial.state == initial) { /* - * If there's an extent to the right its first cluster - * contains the immediate right boundary of the - * truncated/punched region. Set partial_cluster to - * its negative value so it won't be freed if shared - * with the current extent. The end < ee_block case - * is handled in ext4_ext_rm_leaf(). + * If we're punching, there's an extent to the right. + * If the partial cluster hasn't been set, set it to + * that extent's first cluster and its state to nofree + * so it won't be freed should it contain blocks to be + * removed. If it's already set (tofree/nofree), we're + * retrying and keep the original partial cluster info + * so a cluster marked tofree as a result of earlier + * extent removal is not lost. */ lblk = ex_end + 1; err = ext4_ext_search_right(inode, path, &lblk, &pblk, -- 2.19.1