From patchwork Fri Sep 29 19:43:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9978549 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 6DFEF60311 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 60FE22766D for ; Fri, 29 Sep 2017 19:44:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 55E04284C9; 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 495292766D for ; Fri, 29 Sep 2017 19:44:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752534AbdI2ToW (ORCPT ); Fri, 29 Sep 2017 15:44:22 -0400 Received: from mail-qk0-f193.google.com ([209.85.220.193]:36022 "EHLO mail-qk0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752472AbdI2ToV (ORCPT ); Fri, 29 Sep 2017 15:44:21 -0400 Received: by mail-qk0-f193.google.com with SMTP id z14so406481qkg.3 for ; Fri, 29 Sep 2017 12:44:20 -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=j8fABnui5Yws/aNSYVhkEPoUxY2Er1M1u8WKrecLfHY=; b=EzRq6FPsU/JcNlj3kfXKya+YcKrNm8h5uwDTQYYC5UtNGabnA4Gwn393RHZPluGfVI nsTQFSnA/8+iCBNGxFDGD5C2t+qevuj1uWavpiz7jBVV8eFnyw37DHC/XG1B0OHDotDC gwV8PxxwPgYlYfuVqBCYUrZVEuOwIGDYEk+W0+Iw3XdYd5q/9g27uqOiaIvCP0MVekJ4 ANlOsJHGh1+0nRdeE4svuiLJUQJIUd/GslTFPcfILlssikjPTKqXgnPkIxF6xRgyTQ64 GOf66kgBT+uKyADAEp72RZOjk8w88DF6hsblbSANr0a68bTPf38unXn3nAHs86/Mta8W 2qjA== 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=j8fABnui5Yws/aNSYVhkEPoUxY2Er1M1u8WKrecLfHY=; b=i6UgIxafvawTe20YP7Whl0y10bJRQWm1W43PY/ZbaBYWJS8KhhH29hdSuhdSoXbG+2 b8VfY+YdC8sM+cp9HQu5rFfcMeH453zoz3AmaoYAJ1PdPgBBxp+bmUG1H0BQUJqYrtfy to9z7egO7eRHHYUTH7hORSP9vGN4imq7U2E29GhJEblmurXO6sDhlR1ywa5Dz4BOv4S4 ueGxNDV1nWGu+RtjWglRdT+WNRL48fQBIKokoFrd91IzmAJYA0YkAKYPQdpeXTLIvnd8 c6Tcy2/x6A2Uu+XSQiF7pFR9FzRTx96mGrwt0EXUg9B4qlu8G3CEqwoH3If94a9RRfgb rBwQ== X-Gm-Message-State: AMCzsaVewtvCzkZQTgB6Fp/rl6SZiMOTYa/+VDXYVJoZpCEZzUCUZ6hO O4Ty14cMsxWLZgqHVAYPB4aNFAe5 X-Google-Smtp-Source: AOwi7QDe/qRRBNSC8TdbHj11feh0I34rmMgRRE59xEpFRsxm0GoxYew80oCmOi3P6mN7I+C/1owy5A== X-Received: by 10.55.21.99 with SMTP id f96mr4968584qkh.315.1506714260379; Fri, 29 Sep 2017 12:44:20 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id y63sm3071531qky.75.2017.09.29.12.44.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Sep 2017 12:44:19 -0700 (PDT) From: Josef Bacik X-Google-Original-From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 08/21] btrfs: add a helper to return a head ref Date: Fri, 29 Sep 2017 15:43:52 -0400 Message-Id: <1506714245-23072-9-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 Simplify the error handling in __btrfs_run_delayed_refs by breaking out the code used to return a head back to the delayed_refs tree for processing into a helper function. Signed-off-by: Josef Bacik Reviewed-by: David Sterba --- fs/btrfs/extent-tree.c | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c index 00d86c8afaef..f356b4a66186 100644 --- a/fs/btrfs/extent-tree.c +++ b/fs/btrfs/extent-tree.c @@ -2576,6 +2576,17 @@ select_delayed_ref(struct btrfs_delayed_ref_head *head) return ref; } +static void +unselect_delayed_ref_head(struct btrfs_delayed_ref_root *delayed_refs, + struct btrfs_delayed_ref_head *head) +{ + spin_lock(&delayed_refs->lock); + head->processing = 0; + delayed_refs->num_heads_ready++; + spin_unlock(&delayed_refs->lock); + btrfs_delayed_ref_unlock(head); +} + /* * Returns 0 on success or if called with an already aborted transaction. * Returns -ENOMEM or -EIO on failure and will abort the transaction. @@ -2649,11 +2660,7 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, if (ref && ref->seq && btrfs_check_delayed_seq(fs_info, delayed_refs, ref->seq)) { spin_unlock(&locked_ref->lock); - spin_lock(&delayed_refs->lock); - locked_ref->processing = 0; - delayed_refs->num_heads_ready++; - spin_unlock(&delayed_refs->lock); - btrfs_delayed_ref_unlock(locked_ref); + unselect_delayed_ref_head(delayed_refs, locked_ref); locked_ref = NULL; cond_resched(); count++; @@ -2699,14 +2706,11 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, */ if (must_insert_reserved) locked_ref->must_insert_reserved = 1; - spin_lock(&delayed_refs->lock); - locked_ref->processing = 0; - delayed_refs->num_heads_ready++; - spin_unlock(&delayed_refs->lock); + unselect_delayed_ref_head(delayed_refs, + locked_ref); btrfs_debug(fs_info, "run_delayed_extent_op returned %d", ret); - btrfs_delayed_ref_unlock(locked_ref); return ret; } continue; @@ -2764,11 +2768,7 @@ static noinline int __btrfs_run_delayed_refs(struct btrfs_trans_handle *trans, btrfs_free_delayed_extent_op(extent_op); if (ret) { - spin_lock(&delayed_refs->lock); - locked_ref->processing = 0; - delayed_refs->num_heads_ready++; - spin_unlock(&delayed_refs->lock); - btrfs_delayed_ref_unlock(locked_ref); + unselect_delayed_ref_head(delayed_refs, locked_ref); btrfs_put_delayed_ref(ref); btrfs_debug(fs_info, "run_one_delayed_ref returned %d", ret);