Received: by 2002:ac0:bc90:0:0:0:0:0 with SMTP id a16csp5580280img; Wed, 27 Mar 2019 11:05:10 -0700 (PDT) X-Google-Smtp-Source: APXvYqx5HuVyNrPZq8ftuqE/IdIyqA3ZxCeARPKU2o96GI+X5NjOmqYNwIEUXZkWNUM4yTyzcYKv X-Received: by 2002:a62:209c:: with SMTP id m28mr23741297pfj.94.1553709910094; Wed, 27 Mar 2019 11:05:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1553709910; cv=none; d=google.com; s=arc-20160816; b=VzEV0LPH/QFDI5aNLIAramZMwV1fOtMaj7RZ/0CbWG0NS7472B70wvmhNtaEUJgu49 GPeYwqP8EEhq9JaEIbe3H+H8zdVcTct0v4qTVDqRbIdFbSLr2pM9PDzvFGr9OybOp52Y npI3Js9kUBsCMZZx33A/LdyLfEccu7rPCEqGnptSMMTRfX6lMUEFFPTZ9v4P3OTXBvfL B+VFEIj/YKttAFaP17nn2lQE/af1fCUWa8hWA5pqxhE/o2QOWGc5jBkTTRS4Ybt11XTS dNHjX6IsFHwwdpbQxHKyhFEWmEW9OrwwslutT4lJmnVPTOC4aUR1mHPJGyQUVnr1Tjns EdRw== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=e+0NQAr9F3hxzsut4GDNzvwsfoqoZSEbt5MRKrfMhBQ=; b=MDdtq86X+B0LL9+mbvBumYFpuaFyGKBTetaW/KTyKDqEejvLWMo8aT99aIfpq3BK67 V2/jHrh55BFH9I1DrpeKznBVUpejBunsBe8T6yCgMz25kpIJJmqRQJDxpBn08mDR+P9D jlyCE1cA/ORxFX3p8NVbAn6eo6DuXu3uCFHLTjO3sV/VUu9H8IudkBs/vXCg9LBA/Ol9 lBR51ph8ANotpVyiZ7jM5e+bHnqHZM9apsnPyr6/cm/LvUOA0GX+rkyquq9rQcc2GbSU kgh/H4FgbzkrPwiaYKADiltMvKmIAqVQ0txHgCISotYhkQ1HI6yeWIVg7KYTv6qNOJp8 EpmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I5PdoVnM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m19si6059838pgk.76.2019.03.27.11.04.54; Wed, 27 Mar 2019 11:05:10 -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=I5PdoVnM; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732765AbfC0SDm (ORCPT + 99 others); Wed, 27 Mar 2019 14:03:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:43984 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732685AbfC0SDk (ORCPT ); Wed, 27 Mar 2019 14:03:40 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1630B217F5; Wed, 27 Mar 2019 18:03:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1553709819; bh=hVPfTA1SzKeA4IWVriWiwUs1b+vTqgjQ0p9tgEmDNKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I5PdoVnMAnr2WSmrzu9m73zScjw17+N9mV5DxM18POobAPAa88K6+5lqLU7W1mNlT WPHA+l4Jp0XCmSyc/dTElpKNiS/l8wjbOYhZqJF9X93ZjXtkgRZr7iCv4FV7g5Jalw G2YB672aZfAH5RYO1pQ6c112/orODmlIpyR3oWhM= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Eric Whitney , Theodore Ts'o , Sasha Levin , linux-ext4@vger.kernel.org Subject: [PATCH AUTOSEL 5.0 058/262] ext4: fix bigalloc cluster freeing when hole punching under load Date: Wed, 27 Mar 2019 13:58:33 -0400 Message-Id: <20190327180158.10245-58-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190327180158.10245-1-sashal@kernel.org> References: <20190327180158.10245-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Eric Whitney [ 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 @@ int ext4_ext_remove_space(struct inode *inode, ext4_lblk_t start, 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