From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59D4AC2D0C3 for ; Mon, 16 Dec 2019 18:17:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 30572207FF for ; Mon, 16 Dec 2019 18:17:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576520228; bh=364GGQrlE6OQHEpJXW3US8s53v1PHNi3/gNpEqfS8gU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=UjgmXxtXCU9gRWPe8HWyjPlMczeyK/Sr3KDBhBXICKJWGWTdOqhDCh5c0RsLRv0HJ puXmEV9fbRlMD7vIRkDqq9wxdgrgv4pdR3t9Kdqu+MQ2VtsYRV+HWmOMQmIa7OmSyR wQGEUXTkTy2eDHBnGJpDsS9NA4DayCwfG8TnTKTo= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731203AbfLPSRG (ORCPT ); Mon, 16 Dec 2019 13:17:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:40496 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731429AbfLPSRG (ORCPT ); Mon, 16 Dec 2019 13:17:06 -0500 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 E4399206E0; Mon, 16 Dec 2019 18:17:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576520225; bh=364GGQrlE6OQHEpJXW3US8s53v1PHNi3/gNpEqfS8gU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=mn5bD9t5VvkkbRJNOEKBt27mYm+UBmmihhtcdrp2OqAkjTGUYp82NODhFAxJbj6RF vu3tNl0QvD4E58rBeGLQBANi8ocSN4Wa0YUzLujy/exa82bH5K1wsKwL8YovrVmTS9 xSf342SEkWIXXtBUZ4U1mweVKf410W5fbaBB1JOE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Josef Bacik , Nikolay Borisov , David Sterba Subject: [PATCH 5.4 067/177] btrfs: use btrfs_block_group_cache_done in update_block_group Date: Mon, 16 Dec 2019 18:48:43 +0100 Message-Id: <20191216174834.482657428@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191216174811.158424118@linuxfoundation.org> References: <20191216174811.158424118@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Josef Bacik commit a60adce85f4bb5c1ef8ffcebadd702cafa2f3696 upstream. When free'ing extents in a block group we check to see if the block group is not cached, and then cache it if we need to. However we'll just carry on as long as we're loading the cache. This is problematic because we are dirtying the block group here. If we are fast enough we could do a transaction commit and clear the free space cache while we're still loading the space cache in another thread. This truncates the free space inode, which will keep it from loading the space cache. Fix this by using the btrfs_block_group_cache_done helper so that we try to load the space cache unconditionally here, which will result in the caller waiting for the fast caching to complete and keep us from truncating the free space inode. CC: stable@vger.kernel.org # 4.4+ Signed-off-by: Josef Bacik Reviewed-by: Nikolay Borisov Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/block-group.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/fs/btrfs/block-group.c +++ b/fs/btrfs/block-group.c @@ -2662,7 +2662,7 @@ int btrfs_update_block_group(struct btrf * is because we need the unpinning stage to actually add the * space back to the block group, otherwise we will leak space. */ - if (!alloc && cache->cached == BTRFS_CACHE_NO) + if (!alloc && !btrfs_block_group_cache_done(cache)) btrfs_cache_block_group(cache, 1); byte_in_group = bytenr - cache->key.objectid;