From patchwork Wed Jul 25 05:58:38 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liubo X-Patchwork-Id: 1235501 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id DD133DFFC1 for ; Wed, 25 Jul 2012 06:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756326Ab2GYGAe (ORCPT ); Wed, 25 Jul 2012 02:00:34 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:19021 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751818Ab2GYF7l (ORCPT ); Wed, 25 Jul 2012 01:59:41 -0400 X-IronPort-AV: E=Sophos;i="4.77,652,1336320000"; d="scan'208";a="5475684" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 25 Jul 2012 13:58:44 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id q6P5xWGx005253 for ; Wed, 25 Jul 2012 13:59:40 +0800 Received: from localhost.localdomain ([10.167.225.27]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2012072514000593-856931 ; Wed, 25 Jul 2012 14:00:05 +0800 From: Liu Bo To: Subject: [PATCH 2/6 v3][RFC] Btrfs: add helper function to test if we can merge state Date: Wed, 25 Jul 2012 13:58:38 +0800 Message-Id: <1343195922-31405-3-git-send-email-liubo2009@cn.fujitsu.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1343195922-31405-1-git-send-email-liubo2009@cn.fujitsu.com> References: <1343195922-31405-1-git-send-email-liubo2009@cn.fujitsu.com> X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/07/25 14:00:05, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2012/07/25 14:00:14, Serialize complete at 2012/07/25 14:00:14 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org This is a helper function to test if two states are adjacent. It is used for applying rwlock for extent state. Signed-off-by: Liu Bo --- fs/btrfs/extent_io.c | 27 +++++++++++++++++++++++++++ 1 files changed, 27 insertions(+), 0 deletions(-) diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c index 1858d86..4c6dd85 100644 --- a/fs/btrfs/extent_io.c +++ b/fs/btrfs/extent_io.c @@ -473,6 +473,33 @@ void extent_io_tree_panic(struct extent_io_tree *tree, int err) "thread while locked."); } +static int test_merge_state(struct extent_io_tree *tree, + struct extent_state *state) +{ + struct extent_state *other; + struct rb_node *other_node; + + if (state->state & (EXTENT_IOBITS | EXTENT_BOUNDARY)) + return 0; + + other_node = rb_prev(&state->rb_node); + if (other_node) { + other = rb_entry(other_node, struct extent_state, rb_node); + if (other->end == state->start - 1 && + other->state == state->state) + return 1; + } + other_node = rb_next(&state->rb_node); + if (other_node) { + other = rb_entry(other_node, struct extent_state, rb_node); + if (other->start == state->end + 1 && + other->state == state->state) + return 1; + } + + return 0; +} + /* * clear some bits on a range in the tree. This may require splitting * or inserting elements in the tree, so the gfp mask is used to