From patchwork Wed Feb 4 07:16:46 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 5774741 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C08ACBF440 for ; Wed, 4 Feb 2015 07:19:39 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ECEDE2024F for ; Wed, 4 Feb 2015 07:19:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E1766202E5 for ; Wed, 4 Feb 2015 07:19:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752060AbbBDHTe (ORCPT ); Wed, 4 Feb 2015 02:19:34 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:58963 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751483AbbBDHTc (ORCPT ); Wed, 4 Feb 2015 02:19:32 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="57098263" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Feb 2015 15:15:25 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t147IDD4020224 for ; Wed, 4 Feb 2015 15:18:13 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Wed, 4 Feb 2015 15:19:01 +0800 From: Qu Wenruo To: Subject: [PATCH 2/7] btrfs-progs: Introduce btrfs_next_slot() function to iterate to next slot in given level. Date: Wed, 4 Feb 2015 15:16:46 +0800 Message-ID: <1423034213-14018-3-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.2.2 In-Reply-To: <1423034213-14018-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1423034213-14018-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, 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 This will help a lot in level by level iteration. Signed-off-by: Qu Wenruo --- ctree.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ctree.h b/ctree.h index c52d3de..0dfe733 100644 --- a/ctree.h +++ b/ctree.h @@ -2340,13 +2340,18 @@ static inline int btrfs_next_tree_block(struct btrfs_root *root, return btrfs_next_leaf(root, path); } +static inline int btrfs_next_slot(struct btrfs_root *root, + struct btrfs_path *p, int level) +{ + ++p->slots[level]; + if (p->slots[level] >= btrfs_header_nritems(p->nodes[level])) + return btrfs_next_tree_block(root, p); + return 0; +} static inline int btrfs_next_item(struct btrfs_root *root, struct btrfs_path *p) { - ++p->slots[0]; - if (p->slots[0] >= btrfs_header_nritems(p->nodes[0])) - return btrfs_next_leaf(root, p); - return 0; + return btrfs_next_slot(root, p, 0); } int btrfs_prev_leaf(struct btrfs_root *root, struct btrfs_path *path);