From patchwork Thu Oct 19 18:15:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 10018115 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 EFCC760215 for ; Thu, 19 Oct 2017 18:16:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E9FAF28DCD for ; Thu, 19 Oct 2017 18:16:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE3BE28DEA; Thu, 19 Oct 2017 18:16:19 +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 7D16328DCD for ; Thu, 19 Oct 2017 18:16:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753989AbdJSSQR (ORCPT ); Thu, 19 Oct 2017 14:16:17 -0400 Received: from mail-qt0-f195.google.com ([209.85.216.195]:43980 "EHLO mail-qt0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752466AbdJSSQO (ORCPT ); Thu, 19 Oct 2017 14:16:14 -0400 Received: by mail-qt0-f195.google.com with SMTP id j58so15596732qtj.0 for ; Thu, 19 Oct 2017 11:16:13 -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=bU6uUaNXGFFp7JUrl2S59VcC52Vf7Tok63xoMPK+0qs=; b=I6EZIDzJ9ewyJH9mxvc2lDK28jkzgGFkAssBOOMrCaiv3XycqKQ7dgVpkJA7KApoWX Om2HdzOxRl+1fOpqG2VqoqpvbJ6/aFYB5kn73Pw0To8nDIN8FPflH5By8cggJTAnH5zn hWI6Io4fL5lcqL2UI8SZcTUfXL/XXPFsDFptrWuGCfAmFv8FPGPHtK+MiKY9HYIGSP66 F7gfLzJCeVZrPqL+Y305j+6HWd4mnR7uCnEaTS5N4VKaeAexW/yJNzeidrXPC050b//c Vg1zZikvBOBC9NGFDcKqiJ1G3FKy0fvwCpHsIjO6lbfs6a7RSGmVNCMBktbF968rc/7b rv3w== 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=bU6uUaNXGFFp7JUrl2S59VcC52Vf7Tok63xoMPK+0qs=; b=BnKQK1oSK0z2UWpcrcTkVoqMG01hAfTEPhZL7iBkoy85SogwB80Cd7ph4d2QqDzkvO BDZJ5EKOEhyGzGB4N/e9CkUxTGIVbgoHC7AcVLXau0kMgjv9Ze/2eCQLR0F8R+E2H70j XPyA9ia5KPaWNoGQPKQ327f58y8UQKKUX9ncL0UhQCVObT09z8v/JFdOhkv1kpKmkxmH sSjDImmIPG6Rfa9zSE8UfIo4Kbk/oTYQMr3J6t5Xnsv0LU/0uQ0z05VEoQlNn40brFKT zJPYZb6a845TtawohLUVOW9yhQ1PA1Rl1YohzRN59puU+o/Z8MhxNBbRKfGcRDo1ZTRv 9opA== X-Gm-Message-State: AMCzsaW71/oQRbrXeCTb7Xl8OQ6ur6z+FaObu7IoKzdLYaQhnFmGbFcZ MYDLdfTnO+YAj6ge+dCZ0Bhy7R35 X-Google-Smtp-Source: ABhQp+SKoZAXzR8+NkE7BGwaTDFeDj6EkJAcXKd7mPQ0pgg/xAaCO2w9rZMR/WfZRe0zB/CDDYOMUw== X-Received: by 10.200.56.215 with SMTP id g23mr3239117qtc.251.1508436973333; Thu, 19 Oct 2017 11:16:13 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id d42sm10001715qta.60.2017.10.19.11.16.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Oct 2017 11:16:12 -0700 (PDT) From: Josef Bacik To: kernel-team@fb.com, linux-btrfs@vger.kernel.org Subject: [PATCH 5/8] btrfs: add a comp_refs() helper Date: Thu, 19 Oct 2017 14:15:59 -0400 Message-Id: <1508436962-6851-6-git-send-email-josef@toxicpanda.com> X-Mailer: git-send-email 2.7.5 In-Reply-To: <1508436962-6851-1-git-send-email-josef@toxicpanda.com> References: <1508436962-6851-1-git-send-email-josef@toxicpanda.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 */