From patchwork Fri Sep 29 19:43:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9978551 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 904146037F for ; Fri, 29 Sep 2017 19:44:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82ED12766D for ; Fri, 29 Sep 2017 19:44:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 77E5B28458; Fri, 29 Sep 2017 19:44:26 +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 E456128446 for ; Fri, 29 Sep 2017 19:44:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752547AbdI2ToY (ORCPT ); Fri, 29 Sep 2017 15:44:24 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:50889 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752432AbdI2ToW (ORCPT ); Fri, 29 Sep 2017 15:44:22 -0400 Received: by mail-qt0-f195.google.com with SMTP id f15so923181qtf.7 for ; Fri, 29 Sep 2017 12:44:22 -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=4XwEAqkgLusE+bjtdhOc8n36aUfyhPYwPlch/5eBJFk=; b=iH2Iw16LpWobBG4C3WPMbFeaJQskPBCyvt6mVIyNbA6kKQ7Kfdn2zKvxJe3C3EdWVN FwFGwrrbRlN6HdLM+fw7KbACkDEYVkt+XrpWCd6zrEcMXhrXps0TQ3LZAHNMaPR0q9u6 2S7EnaAPv8iGA7+MRx2lbv2olgr5ieWfKQFcF7CXnkYEbw14HvmNh71F4Hwy9npSoswe cblQIHaIrtcyMRtUEcobm/ch2FtnVxFvnXnKYHL/il1pbVHvKkLiJtDydtEK4tuOiLsv RfiRqwy2Y7iBAdono9P1eUTkoEQpMfQ3/B1Q6SHrhKY2DbE8oU7xPVCj4ZuqF8hjhhco K2sw== 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=4XwEAqkgLusE+bjtdhOc8n36aUfyhPYwPlch/5eBJFk=; b=S7Swm586+TnSaZw4n7T1DijZ1Mj2Wu9ZLjWYfjSBG0k+K6/1WYQIzjj+Q7d9WaTNYU 7wrROMCGh0a9zVEaGe/9yqv5d+wqATbe9rBn3ykB0kXGB3NCYKrTYqSxWSVEWHwWufs5 qtxPzd5/Q4yU8tHBFjArDC47X/NMSqH/9rOrFDuTnQv8MDva8IT7ZW1TZWo+YGMfbGEv xMODoxLfYr4xUn86EmYuJEi44uEivm9lt/79ANVtjjswG6sYhOzlL3NnyqJtl50cmBCy TkGyi3g+h0TbXYT5cZfAbyqiFRmrTjPHqhtuTu2dTpO6gnw9/QU7AslXi/lCwwJjW9Op EzkA== X-Gm-Message-State: AMCzsaUMxDuajJt5HzxtpFOsw3VCB3GiRF/CfxvjMme/DjsoeulLnJ+x LnlpghyVnWKklcgncQvFEI477A== X-Google-Smtp-Source: AOwi7QCqibYzvvUlA1FyXGO1kzPkcFxShQElIjLBP9HhUpqaUMFP77lkghgkEaR2hnVTQ3EaiolrqQ== X-Received: by 10.200.8.166 with SMTP id v35mr8277361qth.306.1506714261830; Fri, 29 Sep 2017 12:44:21 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id y138sm3102539qka.69.2017.09.29.12.44.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Sep 2017 12:44:21 -0700 (PDT) From: Josef Bacik X-Google-Original-From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 09/21] btrfs: move extent_op cleanup to a helper Date: Fri, 29 Sep 2017 15:43:53 -0400 Message-Id: <1506714245-23072-10-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 the extent_op cleanup for an empty head ref to a helper function to help simplify __btrfs_run_delayed_refs. Signed-off-by: Josef Bacik Reviewed-by: David Sterba --- fs/btrfs/extent-tree.c | 77 ++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index f356b4a66186..f4048b23c7be 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2587,6 +2587,26 @@ unselect_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, btrfs_delayed_ref_unlock(head); } +static int cleanup_extent_op(struct btrfs_trans_handle *trans, + struct btrfs_fs_info *fs_info, + struct btrfs_delayed_ref_head *head) +{ + struct btrfs_delayed_extent_op *extent_op = head->extent_op; + int ret; + + if (!extent_op) + return 0; + head->extent_op = NULL; + if (head->must_insert_reserved) { + btrfs_free_delayed_extent_op(extent_op); + return 0; + } + spin_unlock(&head->lock); + ret = run_delayed_extent_op(trans, fs_info, &head->node, extent_op); + btrfs_free_delayed_extent_op(extent_op); + return ret ? ret : 1; +} + /* * Returns 0 on success or if called with an already aborted transaction. * Returns -ENOMEM or -EIO on failure and will abort the transaction. @@ -2667,16 +2687,6 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, continue; } - /* - * record the must insert reserved flag before we - * drop the spin lock. - */ - must_insert_reserved = locked_ref->must_insert_reserved; - locked_ref->must_insert_reserved = 0; - - extent_op = locked_ref->extent_op; - locked_ref->extent_op = NULL; - if (!ref) { @@ -2686,33 +2696,17 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, */ ref = &locked_ref->node; - if (extent_op && must_insert_reserved) { - btrfs_free_delayed_extent_op(extent_op); - extent_op = NULL; - } - - if (extent_op) { - spin_unlock(&locked_ref->lock); - ret = run_delayed_extent_op(trans, fs_info, - ref, extent_op); - btrfs_free_delayed_extent_op(extent_op); - - if (ret) { - /* - * Need to reset must_insert_reserved if - * there was an error so the abort stuff - * can cleanup the reserved space - * properly. - */ - if (must_insert_reserved) - locked_ref->must_insert_reserved = 1; - unselect_delayed_ref_head(delayed_refs, - locked_ref); - btrfs_debug(fs_info, - "run_delayed_extent_op returned %d", - ret); - return ret; - } + 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) { + /* We dropped our lock, we need to loop. */ + ret = 0; continue; } @@ -2761,6 +2755,15 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, WARN_ON(1); } } + /* + * record the must insert reserved flag before we + * drop the spin lock. + */ + must_insert_reserved = locked_ref->must_insert_reserved; + locked_ref->must_insert_reserved = 0; + + extent_op = locked_ref->extent_op; + locked_ref->extent_op = NULL; spin_unlock(&locked_ref->lock); ret = run_one_delayed_ref(trans, fs_info, ref, extent_op,