From patchwork Thu Aug 30 17:42:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10582489 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6A84317DE for ; Thu, 30 Aug 2018 17:43:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 599F128676 for ; Thu, 30 Aug 2018 17:43:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4DBFE2C363; Thu, 30 Aug 2018 17:43:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E399528676 for ; Thu, 30 Aug 2018 17:43:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727749AbeH3Vqo (ORCPT ); Thu, 30 Aug 2018 17:46:44 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:42514 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726878AbeH3Vqn (ORCPT ); Thu, 30 Aug 2018 17:46:43 -0400 Received: by mail-qt0-f193.google.com with SMTP id z8-v6so11281428qto.9 for ; Thu, 30 Aug 2018 10:43:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=cdGLSjoEMzv5wkf8dGrK1Mg8LFxsgil57MfSR7TIG9s=; b=YTsYUfJU+IyL0vuutjMj4tSxwUGwdNIbal3TctEMHTzOSMnB3CeKn79UdSxdd/Ef7G rfCMVTwlJppAvzfEq1OUafrPFAQdzO8PF+f1w0eghLzQQhSE2lmV76iB7kU4X+4A5Aat n3d8ATxr/iI5ox3e6hBJi5HoQ3dE9WLAz+XgRjQuS0SUk5pqU/okNjX+aP1Gt8gvA4vq qEWgodXBikrMOmBr6JW+wKJ3hcH63fkp6LkS+Hs1aM91czp4KdX3T+avZIqz7S7i61jb UnnMdExHmZ5Q0fTnBHGYlbO6fDaaY9NO/+NOcamBCvt8ZQgg34xOHXOb8ckTY+Zp8g5c sy9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=cdGLSjoEMzv5wkf8dGrK1Mg8LFxsgil57MfSR7TIG9s=; b=Z3wnwxOFljR/buszVJTgscOE1m9oGHc8swzpyPhzj9UnGu6GyPMinHuf1NkEya7uKy CBAkCoHZPWIZlZ5No78nr4bUG9la8GJNZoxVECFGrYrJ4IhGjWSo3x0f58HB7Od+p8L8 4PAtnsrRnj8Be7e6gb7fzs7ZeBX/NxfJghJZxWIgqD8X4AxehqK3RdN/69jpEfQUQlbR BEQMTrz9/mQk5Jvd0PER2yt/+zK1AH7JX8OQ9QGq1fr/QEMbsTGQkLjUsU4V/n9yykWi +/dQNHBvgiLWAjE1z5yK/mMdkROjN1q+fBEMnFsL2FbZVeirknNp2Ap4tVVHlD9CkcI8 pYFg== X-Gm-Message-State: APzg51D+EmwiGizkFmAzVSiOZUJ1h++QOcrfDuHnzygsXMLIhbWeAA5e oNqhbxHmmYpmSOEnSNn7VO0lTXqkMsxhOw== X-Google-Smtp-Source: ANB0VdbN6ERtW0OlwtXOyRgvvQzgLoRSihOh9THgYWpdTECU4qTZ5HfLbMp3JIPEasdCzC7Rc0Sbiw== X-Received: by 2002:a37:6512:: with SMTP id z18-v6mr12339244qkb.269.1535651007612; Thu, 30 Aug 2018 10:43:27 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id p5-v6sm4148146qkd.81.2018.08.30.10.43.26 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 30 Aug 2018 10:43:26 -0700 (PDT) From: Josef Bacik To: linux-btrfs@vger.kernel.org Subject: [PATCH 33/35] btrfs: fix insert_reserved error handling Date: Thu, 30 Aug 2018 13:42:23 -0400 Message-Id: <20180830174225.2200-34-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180830174225.2200-1-josef@toxicpanda.com> References: <20180830174225.2200-1-josef@toxicpanda.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Signed-off-by: Josef Bacik Reviewed-by: Nikolay Borisov --- fs/btrfs/extent-tree.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 132a1157982c..fd9169f80de0 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2405,6 +2405,9 @@ static int run_one_delayed_ref(struct btrfs_trans_handle *trans, insert_reserved); else BUG(); + if (ret && insert_reserved) + btrfs_pin_extent(trans->fs_info, node->bytenr, + node->num_bytes, 1); return ret; } @@ -8227,21 +8230,14 @@ static int alloc_reserved_tree_block(struct btrfs_trans_handle *trans, } 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; }