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=unavailable 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 14F1CC7658C for ; Thu, 27 Feb 2020 14:28:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D3C0124656 for ; Thu, 27 Feb 2020 14:28:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582813732; bh=/iuYmGxKkhEQ8WmsH4Hhfvfu+Oar/Tmm+cjOuYZFPVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=hKQgdlVqb3vTRL99AGknTvUC6Mz4Bex12gfDkY+iblTxwdSPFfHiLZxTzwsLFvNiZ X5BiITzKGg08n7L0W0neFCCSxSrgxZ8GypC2vlkfqrnNJrTGvdxY7+wYm9dOOOfsgQ w0eoH20b13JCcIHKnQK2z4oCWv0JycaUnJgljOjg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388021AbgB0OHG (ORCPT ); Thu, 27 Feb 2020 09:07:06 -0500 Received: from mail.kernel.org ([198.145.29.99]:44284 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388001AbgB0OG5 (ORCPT ); Thu, 27 Feb 2020 09:06:57 -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 A7CC820578; Thu, 27 Feb 2020 14:06:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1582812417; bh=/iuYmGxKkhEQ8WmsH4Hhfvfu+Oar/Tmm+cjOuYZFPVA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c0ccpi+NGETd9Am6rUzVxgBsgwf3QGeon+eRL+y5iB3G07N3YmsvlVHjOJ7qcS7GG 0jWmuiAeAODFrbc+4VgOX7cFfqR4FUOebuEVI9PpAkF4SEy8okW72mqq2sEYWwfhjE UUEsA+6BDQB9NirmnvEUUhrN9Dt+sYjGRp48HJxc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Johannes Thumshirn , Nikolay Borisov , Qu Wenruo , Josef Bacik , David Sterba Subject: [PATCH 5.4 010/135] btrfs: handle logged extent failure properly Date: Thu, 27 Feb 2020 14:35:50 +0100 Message-Id: <20200227132230.586544434@linuxfoundation.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227132228.710492098@linuxfoundation.org> References: <20200227132228.710492098@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Josef Bacik commit bd727173e4432fe6cb70ba108dc1f3602c5409d7 upstream. If we're allocating a logged extent we attempt to insert an extent record for the file extent directly. We increase space_info->bytes_reserved, because the extent entry addition will call btrfs_update_block_group(), which will convert the ->bytes_reserved to ->bytes_used. However if we fail at any point while inserting the extent entry we will bail and leave space on ->bytes_reserved, which will trigger a WARN_ON() on umount. Fix this by pinning the space if we fail to insert, which is what happens in every other failure case that involves adding the extent entry. CC: stable@vger.kernel.org # 5.4+ Reviewed-by: Johannes Thumshirn Reviewed-by: Nikolay Borisov Reviewed-by: Qu Wenruo Signed-off-by: Josef Bacik Reviewed-by: David Sterba Signed-off-by: David Sterba Signed-off-by: Greg Kroah-Hartman --- fs/btrfs/extent-tree.c | 2 ++ 1 file changed, 2 insertions(+) --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -4411,6 +4411,8 @@ int btrfs_alloc_logged_file_extent(struc ret = alloc_reserved_file_extent(trans, 0, root_objectid, 0, owner, offset, ins, 1); + if (ret) + btrfs_pin_extent(fs_info, ins->objectid, ins->offset, 1); btrfs_put_block_group(block_group); return ret; }