From patchwork Fri Sep 29 19:44:00 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9978571 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 6BF8460311 for ; Fri, 29 Sep 2017 19:44:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5D24E298AB for ; Fri, 29 Sep 2017 19:44:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 508D1298AD; Fri, 29 Sep 2017 19:44:57 +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 DE684298AB for ; Fri, 29 Sep 2017 19:44:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752600AbdI2Toz (ORCPT ); Fri, 29 Sep 2017 15:44:55 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:46628 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752556AbdI2Tob (ORCPT ); Fri, 29 Sep 2017 15:44:31 -0400 Received: by mail-qt0-f193.google.com with SMTP id s18so931291qta.3 for ; Fri, 29 Sep 2017 12:44:31 -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=Wx7jQhwvl/1VXN/9/Y7ZxD4kus8+OkYD2KfxbbkJqkk=; b=0Gm4Yad3V3jse1mwHm+2DeVBbrlFVOBveBtA/bcrkWNgVBj1X+/gN8AsE11YAK3Bai vLq6jZ3sCDIH/k6TXcvL39Cq4LO+BRk3jaUXSZtxC4ohV/CX8LnSpZQ0lQ6UbdwkSQJt dg+Cq7FpXW6ANnjbj+86S3WcdkAWM94pdxfjjk95TRrKHJMNA/cluBYdPS10s+Zl4zqz 1wnSCEUFmWUTYBAL5cg3vJnMSmdlG0RD+CY7YCtK9EXgnD4i72t3XPUcgvBW7pej4ZZ9 ondVq1wmzSuMHSQIRf1lELif90KXXOJGQx4YhHckTubMBZsKaBvh41XrCDolAZgNAQVf Bthw== 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=Wx7jQhwvl/1VXN/9/Y7ZxD4kus8+OkYD2KfxbbkJqkk=; b=Ebph2ezt+zwwPdkZ4mxa3ETJOx+OVhuTuimPNgiOTaCXdrs4X+9ProUvHsiAj+LoiO ydh1Kt2Xhs6+v2+9zT60c7ltyerGYBmHb6eN0Hop23xiON+cmpMMV07elioHl6nto1ee +j3DIgyLUxniUu5g7Ro3oLG3rK+Q1iLmSkFeDsCKK/cgHRCuIrK0zg2tcSuIn12W/gBQ IxGrl3Yc7IiLbyQEeXjc8s7HhyXKwTzEgMGl49Lh/oaF7L/sNTbPlliy5+cFkFEdXRnD 41Wrl77V/MMYf2zgVhtXnDv6GRAtlnFaGGy5DHs9jbYBN8EcA/307ChZSAuE4N//iHbK 2GoQ== X-Gm-Message-State: AMCzsaWGDCTkIpFEBJmP5SKz5Qd/3b7kOSJehqIxVI3E9INlLpU5WtVn 1N1Tr83UlqaQpj0OQJMDpHGFbQ== X-Google-Smtp-Source: AOwi7QBzYt3bX6djACjPAaqmskpRVzI6KegQRGqx5jM/pnGjRymDcRpcsUR0YOzIxM0sBB4ILIpgyA== X-Received: by 10.200.23.252 with SMTP id r57mr8093258qtk.76.1506714271105; Fri, 29 Sep 2017 12:44:31 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id x20sm3235122qtb.20.2017.09.29.12.44.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Sep 2017 12:44:30 -0700 (PDT) From: Josef Bacik X-Google-Original-From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 16/21] btrfs: add a comp_refs() helper Date: Fri, 29 Sep 2017 15:44:00 -0400 Message-Id: <1506714245-23072-17-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 Instead of open-coding the delayed ref comparisons, add a helper to do the comparisons generically and use that everywhere. We compare sequence numbers last for following patches. Signed-off-by: Josef Bacik --- fs/btrfs/delayed-ref.c | 54 ++++++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/fs/btrfs/delayed-ref.c b/fs/btrfs/delayed-ref.c index bc940bb374cf..c4cfadb9768c 100644 --- a/fs/btrfs/delayed-ref.c +++ b/fs/btrfs/delayed-ref.c @@ -85,6 +85,34 @@ static int comp_data_refs(struct btrfs_delayed_data_ref *ref1, return 0; } +static int comp_refs(struct btrfs_delayed_ref_node *ref1, + struct btrfs_delayed_ref_node *ref2, + bool check_seq) +{ + int ret = 0; + if (ref1->type < ref2->type) + return -1; + if (ref1->type > ref2->type) + return 1; + if (ref1->type == BTRFS_TREE_BLOCK_REF_KEY || + ref1->type == BTRFS_SHARED_BLOCK_REF_KEY) + ret = comp_tree_refs(btrfs_delayed_node_to_tree_ref(ref1), + btrfs_delayed_node_to_tree_ref(ref2)); + else + ret = comp_data_refs(btrfs_delayed_node_to_data_ref(ref1), + btrfs_delayed_node_to_data_ref(ref2)); + if (ret) + return ret; + if (check_seq) { + if (ref1->seq < ref2->seq) + return -1; + if (ref1->seq > ref2->seq) + return 1; + } + return 0; +} + + /* insert a new ref to head ref rbtree */ static struct btrfs_delayed_ref_head *htree_insert(struct rb_root *root, struct rb_node *node) @@ -217,18 +245,7 @@ static bool merge_ref(struct btrfs_trans_handle *trans, if (seq && next->seq >= seq) goto next; - if (next->type != ref->type) - goto next; - - if ((ref->type == BTRFS_TREE_BLOCK_REF_KEY || - ref->type == BTRFS_SHARED_BLOCK_REF_KEY) && - comp_tree_refs(btrfs_delayed_node_to_tree_ref(ref), - btrfs_delayed_node_to_tree_ref(next))) - goto next; - if ((ref->type == BTRFS_EXTENT_DATA_REF_KEY || - ref->type == BTRFS_SHARED_DATA_REF_KEY) && - comp_data_refs(btrfs_delayed_node_to_data_ref(ref), - btrfs_delayed_node_to_data_ref(next))) + if (comp_refs(ref, next, false)) goto next; if (ref->action == next->action) { @@ -402,18 +419,7 @@ add_delayed_ref_tail_merge(struct btrfs_trans_handle *trans, exist = list_entry(href->ref_list.prev, struct btrfs_delayed_ref_node, list); /* No need to compare bytenr nor is_head */ - if (exist->type != ref->type || exist->seq != ref->seq) - goto add_tail; - - if ((exist->type == BTRFS_TREE_BLOCK_REF_KEY || - exist->type == BTRFS_SHARED_BLOCK_REF_KEY) && - comp_tree_refs(btrfs_delayed_node_to_tree_ref(exist), - btrfs_delayed_node_to_tree_ref(ref))) - goto add_tail; - if ((exist->type == BTRFS_EXTENT_DATA_REF_KEY || - exist->type == BTRFS_SHARED_DATA_REF_KEY) && - comp_data_refs(btrfs_delayed_node_to_data_ref(exist), - btrfs_delayed_node_to_data_ref(ref))) + if (comp_refs(exist, ref, true)) goto add_tail; /* Now we are sure we can merge */