From patchwork Thu Feb 6 12:02:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Shilong X-Patchwork-Id: 3595661 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 4EBD59F382 for ; Thu, 6 Feb 2014 12:04:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 7E1D42011E for ; Thu, 6 Feb 2014 12:04:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD28320145 for ; Thu, 6 Feb 2014 12:04:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756220AbaBFMEi (ORCPT ); Thu, 6 Feb 2014 07:04:38 -0500 Received: from mail-pb0-f50.google.com ([209.85.160.50]:37147 "EHLO mail-pb0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756213AbaBFMEh (ORCPT ); Thu, 6 Feb 2014 07:04:37 -0500 Received: by mail-pb0-f50.google.com with SMTP id rq2so1660004pbb.23 for ; Thu, 06 Feb 2014 04:04:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=25iG3Hn8g67sxT/FJJigtjX9AtJhl/AyQw4YfkP0ohw=; b=EMXm9PUdXv97cb0ilOSPGUvS4SZSs/sKKtU9NOhGiWWCwoSimQaWNU/i/snP7KEH2y GfzUSAhyLFI9HIitCQ/vX3NpKKpBVhN1vTuijL9kDPW2H1BuR35CwUvXzXUWok8Iua0X ssktchxA/7ujw9CWmhfU4uCAp1bZacWbyw/39Hn821MOv3Yamsw2qH346plX+S0U6p74 fKgag1UqvniXahFiJTwBh+9q0Pjj8duYBWc+H1DZG+w5rRGS4/RAmRGmepiaTWDZ0hHA F4iYepgxyX3Ert7Tqi7RuLoZZ4eCgHLPLLU/l4zsGd5pLCvSZ8zxebcOSryrH1yEDOT4 lHgQ== X-Received: by 10.66.221.199 with SMTP id qg7mr226917pac.88.1391688277052; Thu, 06 Feb 2014 04:04:37 -0800 (PST) Received: from linux-b0ol.site ([223.65.190.181]) by mx.google.com with ESMTPSA id n6sm2863338pbj.22.2014.02.06.04.04.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Feb 2014 04:04:36 -0800 (PST) From: Wang Shilong To: linux-btrfs@vger.kernel.org Subject: [PATCH v2 1/2 ] Btrfs: switch to btrfs_previous_extent_item() Date: Thu, 6 Feb 2014 20:02:29 +0800 Message-Id: <1391688149-2319-1-git-send-email-wangshilong1991@gmail.com> X-Mailer: git-send-email 1.8.4 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.3 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 From: Wang Shilong Since we have introduced btrfs_previous_extent_item() to search previous extent item, just switch into it. Signed-off-by: Wang Shilong Reviewed-by: Filipe Manana --- Changelog: v1->v2: set @found_key properly and fix return value(thanks to Filipe) --- fs/btrfs/backref.c | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) diff --git a/fs/btrfs/backref.c b/fs/btrfs/backref.c index c39891c..4dedb89 100644 --- a/fs/btrfs/backref.c +++ b/fs/btrfs/backref.c @@ -1325,38 +1325,13 @@ int extent_from_logical(struct btrfs_fs_info *fs_info, u64 logical, if (ret < 0) return ret; - while (1) { - u32 nritems; - if (path->slots[0] == 0) { - btrfs_set_path_blocking(path); - ret = btrfs_prev_leaf(fs_info->extent_root, path); - if (ret != 0) { - if (ret > 0) { - pr_debug("logical %llu is not within " - "any extent\n", logical); - ret = -ENOENT; - } - return ret; - } - } else { - path->slots[0]--; - } - nritems = btrfs_header_nritems(path->nodes[0]); - if (nritems == 0) { - pr_debug("logical %llu is not within any extent\n", - logical); - return -ENOENT; - } - if (path->slots[0] == nritems) - path->slots[0]--; - - btrfs_item_key_to_cpu(path->nodes[0], found_key, - path->slots[0]); - if (found_key->type == BTRFS_EXTENT_ITEM_KEY || - found_key->type == BTRFS_METADATA_ITEM_KEY) - break; + ret = btrfs_previous_extent_item(fs_info->extent_root, path, 0); + if (ret) { + if (ret > 0) + ret = -ENOENT; + return ret; } - + btrfs_item_key_to_cpu(path->nodes[0], found_key, path->slots[0]); if (found_key->type == BTRFS_METADATA_ITEM_KEY) size = fs_info->extent_root->leafsize; else if (found_key->type == BTRFS_EXTENT_ITEM_KEY)