From patchwork Fri Sep 29 19:43:54 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9978575 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 612FC60311 for ; Fri, 29 Sep 2017 19:45:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53D9B298AB for ; Fri, 29 Sep 2017 19:45:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48BBF298AE; Fri, 29 Sep 2017 19:45:01 +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=-6.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 C4E90298AB for ; Fri, 29 Sep 2017 19:45:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752602AbdI2To7 (ORCPT ); Fri, 29 Sep 2017 15:44:59 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:51961 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752472AbdI2ToX (ORCPT ); Fri, 29 Sep 2017 15:44:23 -0400 Received: by mail-qt0-f195.google.com with SMTP id q4so910298qtq.8 for ; Fri, 29 Sep 2017 12:44:23 -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=sSxqHi6+NeHxwvJW9JPjgJyyjfmApl6YDuu2LArWl6M=; b=LnNcq/+tKEHg0edCZw56DnoNqlvwNE3SWqZPtyAQ2eevkY7XE2ti0oZVfG9QzK2CNt aFjmktqMojoxBKvaWD+/21nLqtYUWoVRxOzyEqTeH9FUFsg7Pl8SM3CWbx5v6cOFSX5U myN+akVYUB3kAeNNp7avg5eWpoARX4WMK3sEBz+6S/YrgysnyAMo373Aodo9goQ2GDxn vq5Dch/L4gSUCkbTZ74fAJVd1f6EtxwPqTBjJnuwUyydauYmN3YI8Ogcy2DiPJ5MJ9FG nQRX9bnTOTrIOhB+YcEkYPG4vMFjrJQ6Fmf+djzDmArwG48moScavs7kA8T1Q9HtZbWu mX7w== 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=sSxqHi6+NeHxwvJW9JPjgJyyjfmApl6YDuu2LArWl6M=; b=EMQ/6yaDwLQebVrZmQs13DneUCPdCmg65sB8AkzetVNlqAkJi8P/WwgwI8bqVT/5Yu tF56biJMNvAYw/5CZUMR5MATejLw8U+hfBjtunNDDXgqOnOfQN3s7iZl9FJuFfrsHek5 Qngdxljr9f8ttxVJu3Q91xNTb6fW1cJ4ucRbT9KCiBOdzcGxowooLDfhEfMyvYpMGwR9 THY1Y/PBM7onHE1IcEhv8YFvOnzHzofHE6mfmRvVuzR2+9DpN5v5zlYpWy98F2mNkMav l3ORxqMiqhMsgHavjHGneo39EYRcWlNXCKXBfCg3OS15Z5yLCrO6AIIduyvNYuvpeH7X 1V8A== X-Gm-Message-State: AMCzsaWE3/LiKDCDqSc5+wiIH97JMHUKd1jJy1ll/f+/VavSz+9PowS9 iZPY1qhJo96ApDQZPUeMjfuVDmy6 X-Google-Smtp-Source: AOwi7QC9qhajolgtS4lx8QuchGXQdwWtFPJ0ymRPkzT8in4Fzoa5rQBzGNhWAp003sWF4H/SKe9ziQ== X-Received: by 10.200.47.114 with SMTP id k47mr8279304qta.109.1506714263151; Fri, 29 Sep 2017 12:44:23 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id d186sm3053293qkg.46.2017.09.29.12.44.22 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Sep 2017 12:44:22 -0700 (PDT) From: Josef Bacik X-Google-Original-From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 10/21] btrfs: breakout empty head cleanup to a helper Date: Fri, 29 Sep 2017 15:43:54 -0400 Message-Id: <1506714245-23072-11-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506714245-23072-1-git-send-email-jbacik@fb.com> References: <1506714245-23072-1-git-send-email-jbacik@fb.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 Move this code out to a helper function to further simplivy __btrfs_run_delayed_refs. Signed-off-by: Josef Bacik Reviewed-by: David Sterba --- fs/btrfs/extent-tree.c | 80 ++++++++++++++++++++++++++++---------------------- 1 file changed, 45 insertions(+), 35 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f4048b23c7be..bae2eac11db7 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2607,6 +2607,43 @@ static int cleanup_extent_op(struct btrfs_trans_handle *trans, return ret ? ret : 1; } +static int cleanup_ref_head(struct btrfs_trans_handle *trans, + struct btrfs_fs_info *fs_info, + struct btrfs_delayed_ref_head *head) +{ + struct btrfs_delayed_ref_root *delayed_refs; + int ret; + + delayed_refs = &trans->transaction->delayed_refs; + + ret = cleanup_extent_op(trans, fs_info, head); + if (ret < 0) { + unselect_delayed_ref_head(delayed_refs, head); + btrfs_debug(fs_info, "run_delayed_extent_op returned %d", ret); + return ret; + } else if (ret) { + return ret; + } + + /* + * Need to drop our head ref lock and re-acquire the delayed ref lock + * and then re-check to make sure nobody got added. + */ + spin_unlock(&head->lock); + spin_lock(&delayed_refs->lock); + spin_lock(&head->lock); + if (!list_empty(&head->ref_list) || head->extent_op) { + spin_unlock(&head->lock); + spin_unlock(&delayed_refs->lock); + return 1; + } + head->node.in_tree = 0; + delayed_refs->num_heads--; + rb_erase(&head->href_node, &delayed_refs->href_root); + spin_unlock(&delayed_refs->lock); + return 0; +} + /* * Returns 0 on success or if called with an already aborted transaction. * Returns -ENOMEM or -EIO on failure and will abort the transaction. @@ -2688,47 +2725,20 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, } if (!ref) { - - - /* All delayed refs have been processed, Go ahead - * and send the head node to run_one_delayed_ref, - * so that any accounting fixes can happen - */ - ref = &locked_ref->node; - - ret = cleanup_extent_op(trans, fs_info, locked_ref); - if (ret < 0) { - unselect_delayed_ref_head(delayed_refs, - locked_ref); - btrfs_debug(fs_info, - "run_delayed_extent_op returned %d", - ret); - return ret; - } else if (ret > 0) { + ret = cleanup_ref_head(trans, fs_info, locked_ref); + if (ret > 0 ) { /* We dropped our lock, we need to loop. */ ret = 0; continue; + } else if (ret) { + return ret; } - /* - * Need to drop our head ref lock and re-acquire the - * delayed ref lock and then re-check to make sure - * nobody got added. + /* All delayed refs have been processed, Go ahead + * and send the head node to run_one_delayed_ref, + * so that any accounting fixes can happen */ - spin_unlock(&locked_ref->lock); - spin_lock(&delayed_refs->lock); - spin_lock(&locked_ref->lock); - if (!list_empty(&locked_ref->ref_list) || - locked_ref->extent_op) { - spin_unlock(&locked_ref->lock); - spin_unlock(&delayed_refs->lock); - continue; - } - ref->in_tree = 0; - delayed_refs->num_heads--; - rb_erase(&locked_ref->href_node, - &delayed_refs->href_root); - spin_unlock(&delayed_refs->lock); + ref = &locked_ref->node; } else { actual_count++; ref->in_tree = 0;