From patchwork Mon Sep 11 21:12:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Josef Bacik X-Patchwork-Id: 9948143 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 A1CE76024A for ; Mon, 11 Sep 2017 21:13:12 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8882228D62 for ; Mon, 11 Sep 2017 21:13:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D2F328D64; Mon, 11 Sep 2017 21:13:12 +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 1873228D62 for ; Mon, 11 Sep 2017 21:13:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751470AbdIKVNJ (ORCPT ); Mon, 11 Sep 2017 17:13:09 -0400 Received: from mail-qk0-f196.google.com ([209.85.220.196]:36331 "EHLO mail-qk0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751049AbdIKVM6 (ORCPT ); Mon, 11 Sep 2017 17:12:58 -0400 Received: by mail-qk0-f196.google.com with SMTP id i14so6150826qke.3 for ; Mon, 11 Sep 2017 14:12:58 -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=2Nm+5DVimlCG6tYJe/VPFHVSP76EfCChY4SnkDityBs=; b=NhqBTTTrYs1jszqv5x76PHs+Wn0HVNhfetAJywpol+FKcI9ma+ZttW7bVWfPoDS+wN uQnJfR3m0au8AzfFXklu1nEr66TWzpxqJIGbjGCV8nzLentB+lxGsFMLnackg1GFuzBR 1iS8JqkjQs6EBifZCFRP/PHFTDsWpNk17VFGik69vopvsC0oOM72DLbvZYOK2JXkIpxY +q2zJKwP52GI0WMBA/Ygr6Leyk+JGOWPhz28VoVHN6UbgCVna7PRDF/TVxYU5Ss/9z/o M9cKMEgU8y8fETPDRpXAkk6+aro0YLKdbRIAxcmb3kZ6/f3uZ9XDksFBEf5xFnoA+UIV GSRg== 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=2Nm+5DVimlCG6tYJe/VPFHVSP76EfCChY4SnkDityBs=; b=nBRan1Kn6V7DX9BwY88rTz5mjUN3i36acI1MdTwyvUFYvIgtYHiCv2KmJBXWgqpjb0 r1a0cTHeXTN//sVF+Gr5mV6QkDKiyE7dPF7JxHPQz72+ADWP0G6fNlPyM/ykKDn2LS5Q wUyB9U+/9TznE1ydiKGUKvRYyxPiGorJPGVxp6VQMl7wvx0VpTQEdGnXjOdH19WcvpDb Eq+t1+UlDeePPGvRH5vNAR7oLSGDMj80aO9N/MqrDolLxQL23/7FZOLmZiPcxzUbVeWV NBAG21xEX819Ld/LZr3Bdq7Cx/brMjwiVBfqrrYi+CJK/DtNYy0pUJypo9kZoPJpKbJt GLSw== X-Gm-Message-State: AHPjjUhzB+c1vfdlJuMlKJyyZXRFDZj0wfj9JcxpUsDj5gDdfk7PjiRn PXmZN5PP7mNzCvM3hhw= X-Google-Smtp-Source: ADKCNb4js9Px3uQ2ynt9yTaT2IUnJ+GJiZq3hN6DNYtNs2Qp2PuJbHH7ZXeYTfwHH/bABZovklYmmA== X-Received: by 10.55.159.130 with SMTP id i124mr17866153qke.339.1505164377957; Mon, 11 Sep 2017 14:12:57 -0700 (PDT) Received: from localhost ([2606:a000:4381:1201:225:22ff:feb3:e51a]) by smtp.gmail.com with ESMTPSA id n12sm6574304qkn.83.2017.09.11.14.12.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 11 Sep 2017 14:12:57 -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 09/10] btrfs: add a comp_refs() helper Date: Mon, 11 Sep 2017 17:12:35 -0400 Message-Id: <1505164356-13474-10-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 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 c5de6c7..da209cb 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 */