Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp1166102ybv; Thu, 13 Feb 2020 17:14:07 -0800 (PST) X-Google-Smtp-Source: APXvYqz8MM66T5zm3P8QfMe0xwvL5+TUHo8WXEevUBRt5/zZelgmGCgsntnh/8S+Emh7Yvy9E/bQ X-Received: by 2002:a9d:7ad9:: with SMTP id m25mr270139otn.13.1581642847679; Thu, 13 Feb 2020 17:14:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581642847; cv=none; d=google.com; s=arc-20160816; b=ZTd4opn1cy0Bd3zBIOTDFuXV2OPTaHBJ+Lvp1bdyu2AHn0AZjxTYKeUrX5joA7mTG3 L0GZSX3LcjpIcbwpo1TwviHEJ/+blYYW4OXYaZdZccQYwy5Ll/VA+g5EIRLuPbSf2LBf 21Y4k5HAHrf7bGxr28YW1encFN0iLSh5yBUjGuXroy49CXhNNmZu48+qiNUBTKpr7GOF KzjnqM9JzrZSCc8HGCAb5jEca3A6Cjwf5SVgB160ywPfSaeb7dXyylsILNrgSKXB5B+5 j0isj7oQCIKCHu78fssAu9ORfb8qk5ZxVmfxu+PrBb97aYzlQ8aH0JcO2pxKCUBWRU91 5R8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:to :from:date:dkim-signature; bh=ta2kzoNM0SS0eVOl2+D0bZiyqfw7WyJnM7WIk8TmM04=; b=Pk4yn0TOXHM65P2EEaPICRANqLNhTZKGGDXE4IuZj5Y+oVzTogqQyt5KvT0hntaJDG Vf8onJtH2Xl2ltFHKt/317emN4ktNFRxQvN2a6iIpAAMo5sFZQF+LQRWBfK66jPgncqi xy5FK1nD+lf5+NU4MbI/dCyLZoFlxLJhUhTZwVZJyyLwO2EuUNkeOwtBj8M7J/0JLyoh 8nceeFMzuY37fXu6WbMszzFEGETOBe6n6mRP+3YLm4fv/y3xRXgJSBFVaZmbGNrrxnFL NBwjy7K7c7mbdOuh0G2qFH+Xg80aqQ6YDuCxsRB2eFhuHg+5CEYRhlK+PdniKbm3AG0D XL0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=v2abwC2W; 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 e25si2122084otk.62.2020.02.13.17.13.51; Thu, 13 Feb 2020 17:14:07 -0800 (PST) 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=v2abwC2W; 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 S1728061AbgBNBNm (ORCPT + 99 others); Thu, 13 Feb 2020 20:13:42 -0500 Received: from mail.kernel.org ([198.145.29.99]:45054 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727604AbgBNBNm (ORCPT ); Thu, 13 Feb 2020 20:13:42 -0500 Received: from localhost (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (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 49D2520848; Fri, 14 Feb 2020 01:13:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1581642821; bh=1I5Av8GRv6y5/2c2uoawZIwNDflYotcNf7jvh+xAvMQ=; h=Date:From:To:Subject:References:In-Reply-To:From; b=v2abwC2WVOaYOIj2aei7KvR6/8EzZiRm8Elb0H6S2EYUbykAaSgfDJ7aVt0hjwMeM KB6aTrHtl2imXOEESVoA8NgrBEJHIW2qE5lOleX4ehqpFX3OsJzqETvqaXnWBvEOh/ fGvDcHnoLsTwKAWGD4ehninq9w75Ue+nLlJf5N7c= Date: Thu, 13 Feb 2020 20:13:39 -0500 From: Sasha Levin To: dsterba@suse.cz, Greg Kroah-Hartman , linux-kernel@vger.kernel.org, stable@vger.kernel.org, Josef Bacik , David Sterba Subject: Re: [PATCH 4.9 083/116] btrfs: free block groups after freeing fs trees Message-ID: <20200214011339.GB1734@sasha-vm> References: <20200213151842.259660170@linuxfoundation.org> <20200213151915.106400155@linuxfoundation.org> <20200213205533.GR2902@suse.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Disposition: inline In-Reply-To: <20200213205533.GR2902@suse.cz> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Feb 13, 2020 at 09:55:33PM +0100, David Sterba wrote: >On Thu, Feb 13, 2020 at 07:20:27AM -0800, Greg Kroah-Hartman wrote: >> From: Josef Bacik >> >> [ Upstream commit 4e19443da1941050b346f8fc4c368aa68413bc88 ] >> >> Sometimes when running generic/475 we would trip the >> WARN_ON(cache->reserved) check when free'ing the block groups on umount. >> This is because sometimes we don't commit the transaction because of IO >> errors and thus do not cleanup the tree logs until at umount time. >> >> These blocks are still reserved until they are cleaned up, but they >> aren't cleaned up until _after_ we do the free block groups work. Fix >> this by moving the free after free'ing the fs roots, that way all of the >> tree logs are cleaned up and we have a properly cleaned fs. A bunch of >> loops of generic/475 confirmed this fixes the problem. >> >> CC: stable@vger.kernel.org # 4.9+ >> Signed-off-by: Josef Bacik >> Reviewed-by: David Sterba >> Signed-off-by: David Sterba >> Signed-off-by: Sasha Levin >> --- >> fs/btrfs/disk-io.c | 9 +++++++++ >> 1 file changed, 9 insertions(+) >> >> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c >> index eab5a9065f093..439b5f5dc3274 100644 >> --- a/fs/btrfs/disk-io.c >> +++ b/fs/btrfs/disk-io.c >> @@ -3864,6 +3864,15 @@ void close_ctree(struct btrfs_root *root) >> clear_bit(BTRFS_FS_OPEN, &fs_info->flags); >> free_root_pointers(fs_info, true); >> >> + /* >> + * We must free the block groups after dropping the fs_roots as we could >> + * have had an IO error and have left over tree log blocks that aren't >> + * cleaned up until the fs roots are freed. This makes the block group >> + * accounting appear to be wrong because there's pending reserved bytes, >> + * so make sure we do the block group cleanup afterwards. >> + */ >> + btrfs_free_block_groups(fs_info); > >Something's wrong here. The patch 4e19443da1 moves the >btrfs_free_block_groups() call and the stable backport lacks the "-" >line. However the patch applies cleanly on 4.9.213. > >3855 btrfs_free_block_groups(fs_info); >^^^^ > >3856 >3857 /* >3858 * we must make sure there is not any read request to >3859 * submit after we stopping all workers. >3860 */ >3861 invalidate_inode_pages2(fs_info->btree_inode->i_mapping); >3862 btrfs_stop_all_workers(fs_info); >3863 >3864 clear_bit(BTRFS_FS_OPEN, &fs_info->flags); >3865 free_root_pointers(fs_info, 1); >3866 >3867 /* >3868 * We must free the block groups after dropping the fs_roots as we could >3869 * have had an IO error and have left over tree log blocks that aren't >3870 * cleaned up until the fs roots are freed. This makes the block group >3871 * accounting appear to be wrong because there's pending reserved bytes, >3872 * so make sure we do the block group cleanup afterwards. >3873 */ >3874 btrfs_free_block_groups(fs_info); > >The first one should not be there. Sigh, sorry about that. The story behind this is that for this patch to apply, we first must have 5cdd7db6c5c9 ("Btrfs: fix assertion failure when freeing block groups at close_ctree()") which moves the btrfs_free_block_groups() call to line 3863 in your code above. I somehow goofed up picking it up and (probably) messed up the rebase when it went missing, sorry again. I'll fix it up for the next release. -- Thanks, Sasha