From patchwork Thu Jul 4 15:48:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 2823852 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id E495B9F9D2 for ; Thu, 4 Jul 2013 15:50:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9E1A42014B for ; Thu, 4 Jul 2013 15:50:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A27E620145 for ; Thu, 4 Jul 2013 15:50:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756525Ab3GDPuN (ORCPT ); Thu, 4 Jul 2013 11:50:13 -0400 Received: from mail-wi0-f181.google.com ([209.85.212.181]:54072 "EHLO mail-wi0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755123Ab3GDPuM (ORCPT ); Thu, 4 Jul 2013 11:50:12 -0400 Received: by mail-wi0-f181.google.com with SMTP id hq4so1371126wib.14 for ; Thu, 04 Jul 2013 08:50:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=7kf1H7G7Qu9SjA1x7bxqnz/KPqLBi9guxL9H9L7sWQw=; b=hNHm38P/H5puMFyocmnrxpoF3/he1M4ehM+JMon0rmHa0GsGRtobF5/2PdsSHEx+xj E/6E3sNaTDw/CcxEUtKYDlK5KkShUk+ug4JyFMcmQyD1MvNoUAuj4EDX+vpkK2vwc69u 9BJm1aRBkaFHbWpm6UUjg0uZbwUgBzfJv/HOpWuZfyk5DXAIHfUtPLoZZ+Ve0OHWbdDK LGRNyLMg0kmRDXs4DFafCtG2WIPIUuwWalbXC/rFF2zha8Y/w87Y+xcA7j4cX/MhDq1l FHL1/xw5FfXzuzy/T5+dpGdOQE++jADZmvFsGqRY3R61cvI5j1xB1nAKdD4gNeXLuV2T lBmQ== X-Received: by 10.180.185.101 with SMTP id fb5mr3721661wic.44.1372953010955; Thu, 04 Jul 2013 08:50:10 -0700 (PDT) Received: from storm-desktop.lan (bl10-255-64.dsl.telepac.pt. [85.243.255.64]) by mx.google.com with ESMTPSA id fs8sm35674181wib.0.2013.07.04.08.50.08 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Jul 2013 08:50:09 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: Filipe David Borba Manana Subject: [PATCH] Btrfs-progs: fix optimization in btrfs_lookup_extent_info Date: Thu, 4 Jul 2013 16:48:39 +0100 Message-Id: <1372952919-21010-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1372869173-15043-1-git-send-email-fdmanana@gmail.com> References: <1372869173-15043-1-git-send-email-fdmanana@gmail.com> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If we did a tree search with the goal to find a metadata item but the search failed with return value 1, we attempt to see if in the same leaf there's a corresponding extent item, and if there's one, just use it instead of doing another tree search for this extent item. The check in the leaf was wrong because it was seeking for a metadata item instead of an extent item. This optimization was also being triggered incorrectly, as it was evaluating path->slots which always evaluates to true. The goal was to see if the leaf level slot was greater than zero (i.e. not the first item in the leaf). Signed-off-by: Filipe David Borba Manana --- extent-tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/extent-tree.c b/extent-tree.c index b0cfe0a..22e6247 100644 --- a/extent-tree.c +++ b/extent-tree.c @@ -1515,12 +1515,13 @@ again: * to make sure. */ if (ret > 0 && metadata) { - if (path->slots) { + if (path->slots[0]) { path->slots[0]--; btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]); if (key.objectid == bytenr && - key.type == BTRFS_METADATA_ITEM_KEY) + key.type == BTRFS_EXTENT_ITEM_KEY && + key.offset == root->leafsize) ret = 0; }