Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3414158imu; Sun, 11 Nov 2018 14:31:04 -0800 (PST) X-Google-Smtp-Source: AJdET5cQgCn9287zn8G6s95Dv+yVPN1+K/cH0V/vp4shQ97gihfVeIb3XB7uth0O0SBim6kMZRrn X-Received: by 2002:a17:902:7b93:: with SMTP id w19-v6mr17844338pll.80.1541975464078; Sun, 11 Nov 2018 14:31:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541975464; cv=none; d=google.com; s=arc-20160816; b=b7qa5U5VOR8eAaHiJcUosSWDubx75iVbJI6cbYWUtc8yzOFQvccrzl83XerTFFhItF HPuZIg0H6FwEhMIFnzRftElmlMHHKIznw38Qc3EOF+kSClvU6SVR4ZjEqTMoNyPIB9CG wvW56v3KzOlK5lslCCakmdLmq6nI8YbjO3zTU6SGZrVytjOuGWf/oo1lwmq2Oetcr0La bGhQveDN0k26Yh0iHyhBHKjabhGDXUHIJ8KXaB1fQTgcbrU4p1jWcjCswtg9aCwdcLHI qDZDQ8EZ7HmERd18h61kT9iP3AMncm8FmOISga999dHdRYAQsh8HZXSzHHgkb5wyeE+J gxyg== 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=cs1BkGn1Wxx+YEvYopmr9WTHtXKP3bLJicijQRInRfU=; b=YAKsnwQRce/+6yQq8NcBORCcseNYIHEazxw+uv5S5MRdAs5QAp2S0scY0yJE3kvMts pN9HejLtCJEDlJNjx3xltzHckmCUwYP8JO/G7BUxZPIADZx/NOfAyIV3Y21WcOKowRu6 2r90truu4Kta/tyMz7LNdnC35DlINJtFuij/HSZGrBrbHdP/E8qwaC3Ao70wvQAp722P 2PtsdIz97/RjJtVmPqOXhJA1bd05c1WOP09ZelMXrTGTARmKtpxYLNbMoSUosc3pL2m/ 1qQXOjSl/OE7XwY9pcS+M5hCjG4kl+GkthxaQsvZlm3P01U+wz1ubr39xvRZw8CIe620 fAuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=I3qb712p; 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 12-v6si4736113plb.324.2018.11.11.14.30.49; Sun, 11 Nov 2018 14:31:04 -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=I3qb712p; 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 S1733215AbeKLISw (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:52 -0500 Received: from mail.kernel.org ([198.145.29.99]:39468 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730142AbeKLISv (ORCPT ); Mon, 12 Nov 2018 03:18:51 -0500 Received: from localhost (unknown [206.108.79.134]) (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 DBC32223D1; Sun, 11 Nov 2018 22:28:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975335; bh=QtUclkgBP9MKJ3bLwl/+OP+iQqUe3kYDB5zzFpyeKak=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I3qb712pHvRaV+naeiLB9XWYZFaK/3ws6B/fpLZWGfIRv0aExgDFauggAUi6jGJx3 bbhJ/4FONMoshSjlUenILcwsqpZrKBdR1tqh9DXOe8XUlAgGidedMYAb6vwLGdHsNo C1/J8/lwa0Jvba3qiMayX3WPinv8gSzDYIlohYKA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Nikolay Borisov , Josef Bacik , David Sterba Subject: [PATCH 4.19 352/361] btrfs: fix insert_reserved error handling Date: Sun, 11 Nov 2018 14:21:39 -0800 Message-Id: <20181111221701.635464174@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review 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 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Josef Bacik commit 80ee54bfe8a3850015585ebc84e8d207fcae6831 upstream. We were not handling the reserved byte accounting properly for data references. Metadata was fine, if it errored out the error paths would free the bytes_reserved count and pin the extent, but it even missed one of the error cases. So instead move this handling up into run_one_delayed_ref so we are sure that both cases are properly cleaned up in case of a transaction abort. CC: stable@vger.kernel.org # 4.18+ Reviewed-by: Nikolay Borisov 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 | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2366,6 +2366,9 @@ static int run_one_delayed_ref(struct bt insert_reserved); else BUG(); + if (ret && insert_reserved) + btrfs_pin_extent(trans->fs_info, node->bytenr, + node->num_bytes, 1); return ret; } @@ -7977,21 +7980,14 @@ static int alloc_reserved_tree_block(str } path = btrfs_alloc_path(); - if (!path) { - btrfs_free_and_pin_reserved_extent(fs_info, - extent_key.objectid, - fs_info->nodesize); + if (!path) return -ENOMEM; - } path->leave_spinning = 1; ret = btrfs_insert_empty_item(trans, fs_info->extent_root, path, &extent_key, size); if (ret) { btrfs_free_path(path); - btrfs_free_and_pin_reserved_extent(fs_info, - extent_key.objectid, - fs_info->nodesize); return ret; }