From patchwork Tue Dec 15 06:54:08 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miao Xie X-Patchwork-Id: 67533 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nBF6ni2h002922 for ; Tue, 15 Dec 2009 06:49:44 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753445AbZLOGtn (ORCPT ); Tue, 15 Dec 2009 01:49:43 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752337AbZLOGtn (ORCPT ); Tue, 15 Dec 2009 01:49:43 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:52003 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1750909AbZLOGtm (ORCPT ); Tue, 15 Dec 2009 01:49:42 -0500 Received: from tang.cn.fujitsu.com (tang.cn.fujitsu.com [10.167.250.3]) by song.cn.fujitsu.com (Postfix) with ESMTP id 0F9DB170044; Tue, 15 Dec 2009 14:49:40 +0800 (CST) Received: from 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 nBF6mHiX018541; Tue, 15 Dec 2009 14:48:17 +0800 Received: from [127.0.0.1] (unknown [10.167.141.211]) by fnst.cn.fujitsu.com (Postfix) with ESMTPA id 13575D430D; Tue, 15 Dec 2009 14:49:59 +0800 (CST) Message-ID: <4B273290.6090503@cn.fujitsu.com> Date: Tue, 15 Dec 2009 14:54:08 +0800 From: Miao Xie Reply-To: miaox@cn.fujitsu.com User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 MIME-Version: 1.0 To: Chris Mason CC: Linux Btrfs Subject: [PATCH 1/4] btrfs: fix the bug that __tree_search() returns the wrong result in extent_map.c Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c index 46bea0f..16744f4 100644 --- a/fs/btrfs/extent_map.c +++ b/fs/btrfs/extent_map.c @@ -136,20 +136,15 @@ static struct rb_node *__tree_search(struct rb_root *root, u64 offset, if (prev_ret) { orig_prev = prev; - while (prev && offset >= extent_map_end(prev_entry)) { - prev = rb_next(prev); - prev_entry = rb_entry(prev, struct extent_map, rb_node); - } + if (prev && offset < prev_entry->start) + prev = rb_prev(prev); *prev_ret = prev; prev = orig_prev; } if (next_ret) { - prev_entry = rb_entry(prev, struct extent_map, rb_node); - while (prev && offset < prev_entry->start) { - prev = rb_prev(prev); - prev_entry = rb_entry(prev, struct extent_map, rb_node); - } + if (prev && offset >= extent_map_end(prev_entry)) + prev = rb_next(prev); *next_ret = prev; } return NULL;