From patchwork Tue Sep 11 17:57:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10596053 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 C585614BD for ; Tue, 11 Sep 2018 17:58:14 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B1FB9297BD for ; Tue, 11 Sep 2018 17:58:14 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5F99297EF; Tue, 11 Sep 2018 17:58:14 +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 4418D297BD for ; Tue, 11 Sep 2018 17:58:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728078AbeIKW6i (ORCPT ); Tue, 11 Sep 2018 18:58:38 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:42884 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727044AbeIKW6i (ORCPT ); Tue, 11 Sep 2018 18:58:38 -0400 Received: by mail-qt0-f193.google.com with SMTP id z8-v6so29175507qto.9 for ; Tue, 11 Sep 2018 10:58:12 -0700 (PDT) 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=hzyvopuFy3G16gAatddPvXF3q9SROipAO8YCp4Hh1HQ=; b=qwJDsfYDjmnfQMWBRPfQ3YZaNO6qHf1u+i+g3iXOvAvyzpklESkivb9FBxrMgmxakP 3fvX8fCVyZFtZnXTAp5oa4SBLhxZQ8TzITvLi5cBTfDkdbDG0v9/LwHQmLVLFrKcFKZW /NH8Xr0fntNHE04YSrt5lGZOWE8XhciX4jZH+rGc2P1tqu/HFsMOrFMjs8MjFwkMRrDX rQgM7ry/ww1r0VmRVLW7kVQR6gy0s15ODUkSfuF9qozuB4ozFQZuxJYJpIc++eHej0S9 SNRB9R7ro/e2DfbXcri1RiAZunUdT4a7UWsgd4vtgnCXvqfRrEqRAJlvY13n51Kvt6KV GUgg== 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=hzyvopuFy3G16gAatddPvXF3q9SROipAO8YCp4Hh1HQ=; b=VE2FbNDco56GAdXMzB50LvQ/RLeDev1xmusnHYwnhfND8bX+Eooi9H/vPOVxE5EcPA 1Il5OHNq4SHTdmQmTSxHDjSnbGUArP8k3b55Zy22XDKX7F1UmUnUZK7DBquBnj69RTbo MU9HgcRCyBy8eqRFi74+xJNOv1syjboZDyTdZCxe78TaS6P1cfXhh4TzeoHTmHb+P9U/ my/e3mmf+4B87xVmtU7eEq9du/bM4PAAYsXif4Qaqd/zGfSkpwJV/WrFfZG+4uXY0zwr DkD7zRrQk6N0P0ZsBXhsFs5bj+3dajALn5mj1eu5YGacipgMsL2H+LviULyfmYTnlQS5 tk6A== X-Gm-Message-State: APzg51At8i2C/Z2TEzmsmlXujDHuhjk/Q0N18mdwZIWIFXo/WWHCArtu tsEQ7T4Mu4Ahir5mdRg/tJXDLw== X-Google-Smtp-Source: ANB0Vdb0Mmz9Jh372vIetixc7HIDImq0CqCdG2/BwVwIxkaYeUJqOltTMCGd5wuaUENkUZpqkP/PRw== X-Received: by 2002:a0c:c3c6:: with SMTP id p6-v6mr19012194qvi.146.1536688691816; Tue, 11 Sep 2018 10:58:11 -0700 (PDT) Received: from localhost ([107.15.81.208]) by smtp.gmail.com with ESMTPSA id n25-v6sm13452123qtb.32.2018.09.11.10.58.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 11 Sep 2018 10:58:10 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Cc: Josef Bacik Subject: [PATCH 01/36] btrfs: add btrfs_delete_ref_head helper Date: Tue, 11 Sep 2018 13:57:32 -0400 Message-Id: <20180911175807.26181-2-josef@toxicpanda.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180911175807.26181-1-josef@toxicpanda.com> References: <20180911175807.26181-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 --- 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 62ff545ba1f7..3a9e4ac21794 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -393,6 +393,20 @@ btrfs_select_ref_head(struct btrfs_trans_handle *trans) 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(&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 d9f2a4ebd5db..7769177b489e 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_trans_handle *trans); diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f77226d8020a..d24a0de4a2e7 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2492,12 +2492,9 @@ static int cleanup_ref_head(struct btrfs_trans_handle *trans, spin_unlock(&delayed_refs->lock); return 1; } - delayed_refs->num_heads--; - rb_erase(&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(&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);