From patchwork Mon Sep 11 21:12:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9948129 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 38C906024A for ; Mon, 11 Sep 2017 21:12:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20F2628D62 for ; Mon, 11 Sep 2017 21:12:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 15BA628D64; Mon, 11 Sep 2017 21:12:53 +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 AB67C28D62 for ; Mon, 11 Sep 2017 21:12:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751424AbdIKVMu (ORCPT ); Mon, 11 Sep 2017 17:12:50 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:36288 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751224AbdIKVMn (ORCPT ); Mon, 11 Sep 2017 17:12:43 -0400 Received: by mail-qk0-f194.google.com with SMTP id i14so6150537qke.3 for ; Mon, 11 Sep 2017 14:12:43 -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=UeE5pX5BifOljOre8wz/hrvM+Za3Nb43ObMx7fTyzak=; b=gf0H+xEp7Nf1O6SzPqFgJcax3PClylnZLf5VJqLvoGcjmGC9VJ7fXU1hi2s3cNFisY F1olFIN+DQkxdzdGGzE/NZlrGUAYHE2g1Qejqa19SU6Om1d0qdi5rJwNUcn26fB2dQwi TsaDHvyPAgmQaHczAv4aTVYSu2xhcZkoA6acK37yIwPR8PIexSnMddc6Et+cFGXyuBtr imMRjz9ENG+Oj9zUBbKEtcC6Sy3Ld/ZLYGNKytrzog5k5lWVz+SjGY7Qwy8IIQRXc1Zb KyyO0P+98TMNYbZSf9OSwaXxvEGKRvAM0yzAU32x5MqEp4wbQ8yu4PVAFv7S9X8M/IeU oHrA== 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=UeE5pX5BifOljOre8wz/hrvM+Za3Nb43ObMx7fTyzak=; b=e7VME/c6gDcGo3FmWP2VfzA9AGusT40wZNtQAYe3SIWEInmnX9FbC56vjdU5KLviYC 4H+pgOlVZy0qGflhdgG2CK8xdNgwkjPn7/tC/wCBQ9ukUupvmMpLwuTIk9H4U2K9fr+K sg7SZ+YPqiBPgQ5/b0dKmAv/t0IyUV3K5b0Xh+i1pDmK/Qbw/5V8rXVw30TNVOwTmMmR miKgmujcf4ftz6v1dNH5cWUayZYuS29lteDkiaKUvv7AN6dPejiv5rwNp51+Rp3zkoUJ D2SOceYmdWPhAqgy6toNUp7SP8GeXfNAvCnM0czxjMKWdEdVW+zv53zCOUfqMYUuQxue rqxg== X-Gm-Message-State: AHPjjUhLsqq4m6SRzSHawcmtx47m7ALQqQHww9dWs2cbeTVwLNd3ZH1d qetWFJ1LEQIYtLSW X-Google-Smtp-Source: AOwi7QCPgVLxfDWP6kk6CRmhY/5c6/YwfMcffu4zh/1HeiCqM1/j0qYVHR1GyybjZKq6UeN0NPS2tw== X-Received: by 10.233.244.72 with SMTP id z8mr16126463qkl.148.1505164362795; Mon, 11 Sep 2017 14:12:42 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id r18sm6625839qtr.91.2017.09.11.14.12.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Sep 2017 14:12:42 -0700 (PDT) From: josef@toxicpanda.com X-Google-Original-From: jbacik@fb.com To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Cc: Josef Bacik Subject: [PATCH 02/10] btrfs: move extent_op cleanup to a helper Date: Mon, 11 Sep 2017 17:12:28 -0400 Message-Id: <1505164356-13474-3-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1505164356-13474-1-git-send-email-jbacik@fb.com> References: <1505164356-13474-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 From: Josef Bacik 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 --- 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 636aac0..47780b7 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2519,6 +2519,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. @@ -2599,16 +2619,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) { @@ -2618,33 +2628,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; } @@ -2693,6 +2687,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,