From patchwork Mon Dec 3 15:20:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10709797 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 2354D17D5 for ; Mon, 3 Dec 2018 15:20:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 13A5E2B31A for ; Mon, 3 Dec 2018 15:20:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 103972B434; Mon, 3 Dec 2018 15:20:47 +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 828322B31A for ; Mon, 3 Dec 2018 15:20:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726689AbeLCPUp (ORCPT ); Mon, 3 Dec 2018 10:20:45 -0500 Received: from mail-yb1-f195.google.com ([209.85.219.195]:33087 "EHLO mail-yb1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726549AbeLCPUp (ORCPT ); Mon, 3 Dec 2018 10:20:45 -0500 Received: by mail-yb1-f195.google.com with SMTP id f125so674840ybc.0 for ; Mon, 03 Dec 2018 07:20:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=toxicpanda-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pRCx2eP/l80aL+OLubW7i+4YyKvLhkbzZ3rfIZGfT4g=; b=EggwHEZUIePK54lc0IS05HffMMVGVyjTBzNhIhSjPAmLdnO/DpQJKFSS7FCxj6637X Z2WrDa1hK2PbyFV0cW+gF8zOOZ5SowVt+jil8XGiRMyVhgfmgOWQ5de0C4mkKqpii4gz v7liwSAEOKtiRu6osHoFs/DaozLEk7FY7ouCpAmvcxUbegOeP3kim2EcFyYXST1yJ41F d31uXhZwX0Y7BlvSzQ5jjDKjt2sgAimOdDIUtDyBIf2Kj7hrGRyO8U6D3cZZ3sSfIhnW s+mpGtSd01OCYYhFgQn+GWJ2r9J/b2l6S9tTECIRVWIWNTiwSMmSRNxHqehEBWs2qK2R YwqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pRCx2eP/l80aL+OLubW7i+4YyKvLhkbzZ3rfIZGfT4g=; b=HmEoSw8Q6D7ZxcQYJnLB6Z1EmJJ8NAoYyPh0AU+4O8CkRjuuiINFVfjs5ruzwEa16m MLguX2POt6QajwZkqZZGWddcrR6itvqNl+a3yu91DHHu0EsiBUkdFiPOBkSRt+z3Bz9f pbJHMlt00cEFx/OaH/4F0hlJoM5DxYllmm4khWQcLCPOluVs9paoV/OWFx7Rn0Jpsbzj fKP0rxPjsgEqT3sz5b/eUpNrLgoBIYe3scF0g3ScfqxxPCdfbbK9DQY/hyOAFA0ppaaU d2cKMB55NA4wGrzfMJLc4IjlTB/juIq10zNhtt6V743m+4BVNMibKust0+RJUuK+O1mN OYiQ== X-Gm-Message-State: AA+aEWbOacZZy55tu1zF7YbUD21l8vcHZb9E/5aMWuYUH/NXc6bhEbyw oPq+61iP/0pnCleD0TZHEOBJtSMRyIc= X-Google-Smtp-Source: AFSGD/Urd+IaPybVu+11T53mgtCNXGC87CCm1Pkcuzr0PKiErLzsBkbxPrL3KBhg3O/xx2duO3yymA== X-Received: by 2002:a25:d050:: with SMTP id h77-v6mr14796785ybg.423.1543850443411; Mon, 03 Dec 2018 07:20:43 -0800 (PST) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id l83sm4496666ywb.23.2018.12.03.07.20.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 03 Dec 2018 07:20:42 -0800 (PST) From: Josef Bacik To: linux-btrfs@vger.kernel.org, kernel-team@fb.com Cc: Josef Bacik Subject: [PATCH 01/10] btrfs: add btrfs_delete_ref_head helper Date: Mon, 3 Dec 2018 10:20:29 -0500 Message-Id: <20181203152038.21388-2-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20181203152038.21388-1-josef@toxicpanda.com> References: <20181203152038.21388-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 From: Josef Bacik We do this dance in cleanup_ref_head and check_ref_cleanup, unify it into a helper and cleanup the calling functions. Signed-off-by: Josef Bacik Reviewed-by: Omar Sandoval Reviewed-by: Nikolay Borisov --- fs/btrfs/delayed-ref.c | 14 ++++++++++++++ fs/btrfs/delayed-ref.h | 3 ++- fs/btrfs/extent-tree.c | 22 +++------------------- 3 files changed, 19 insertions(+), 20 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index 9301b3ad9217..b3e4c9fcb664 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -400,6 +400,20 @@ struct btrfs_delayed_ref_head *btrfs_select_ref_head( return head; } +void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, + struct btrfs_delayed_ref_head *head) +{ + lockdep_assert_held(&delayed_refs->lock); + lockdep_assert_held(&head->lock); + + rb_erase_cached(&head->href_node, &delayed_refs->href_root); + RB_CLEAR_NODE(&head->href_node); + atomic_dec(&delayed_refs->num_entries); + delayed_refs->num_heads--; + if (head->processing == 0) + delayed_refs->num_heads_ready--; +} + /* * Helper to insert the ref_node to the tail or merge with tail. * diff --git a/fs/btrfs/delayed-ref.h b/fs/btrfs/delayed-ref.h index 8e20c5cb5404..d2af974f68a1 100644 --- a/fs/btrfs/delayed-ref.h +++ b/fs/btrfs/delayed-ref.h @@ -261,7 +261,8 @@ static inline void btrfs_delayed_ref_unlock(struct btrfs_delayed_ref_head *head) { mutex_unlock(&head->mutex); } - +void btrfs_delete_ref_head(struct btrfs_delayed_ref_root *delayed_refs, + struct btrfs_delayed_ref_head *head); struct btrfs_delayed_ref_head *btrfs_select_ref_head( struct btrfs_delayed_ref_root *delayed_refs); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index d242a1174e50..c36b3a42f2bb 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2474,12 +2474,9 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, spin_unlock(&delayed_refs->lock); return 1; } - delayed_refs->num_heads--; - rb_erase_cached(&head->href_node, &delayed_refs->href_root); - RB_CLEAR_NODE(&head->href_node); + btrfs_delete_ref_head(delayed_refs, head); spin_unlock(&head->lock); spin_unlock(&delayed_refs->lock); - atomic_dec(&delayed_refs->num_entries); trace_run_delayed_ref_head(fs_info, head, 0); @@ -6984,22 +6981,9 @@ static noinline int check_ref_cleanup(struct btrfs_trans_handle *trans, if (!mutex_trylock(&head->mutex)) goto out; - /* - * at this point we have a head with no other entries. Go - * ahead and process it. - */ - rb_erase_cached(&head->href_node, &delayed_refs->href_root); - RB_CLEAR_NODE(&head->href_node); - atomic_dec(&delayed_refs->num_entries); - - /* - * we don't take a ref on the node because we're removing it from the - * tree, so we just steal the ref the tree was holding. - */ - delayed_refs->num_heads--; - if (head->processing == 0) - delayed_refs->num_heads_ready--; + btrfs_delete_ref_head(delayed_refs, head); head->processing = 0; + spin_unlock(&head->lock); spin_unlock(&delayed_refs->lock);