From patchwork Mon Jul 29 18:35:49 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Filipe Manana X-Patchwork-Id: 2835106 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 7556F9F7D6 for ; Mon, 29 Jul 2013 18:36:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 798BE2017C for ; Mon, 29 Jul 2013 18:36:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D73A2011F for ; Mon, 29 Jul 2013 18:36:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754428Ab3G2SgD (ORCPT ); Mon, 29 Jul 2013 14:36:03 -0400 Received: from mail-we0-f175.google.com ([74.125.82.175]:41172 "EHLO mail-we0-f175.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751909Ab3G2SgC (ORCPT ); Mon, 29 Jul 2013 14:36:02 -0400 Received: by mail-we0-f175.google.com with SMTP id q58so4286833wes.20 for ; Mon, 29 Jul 2013 11:36:00 -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=W0P4s470DHQkUJtbWaz+/EgiDc3bY9Xb168pPmJg4Dk=; b=PvWE1x/dUMBKF8+YCKauUsw7T+CxtWqgYg9qb+ylqF6bDsF1qZrJiXsWWVEP9Os3pt nfVF44c4a77t5Su1WNY02K+V2PXuoFfASwMbAVst7siYOOG1R8c9LP0f5e4ia+imQn6v MAH5+hCsfHHnzPsbcnXTTEIhd2DlhyVBeMReJ8g+48b3peGbzVDfnkQvOi61TbeP9ejf 3pAqx2qnHFbQW24czi12uPBPjdeu3E3XIQwo96K797+HoofEc8lzzjt9bc6sKRl0loHf jkSY5hUAxDjeODcD8TnP6kvv0fyMOiSm0QLYwFy8XKqgFxSyWgfBfGtJd58zVGjXfCeC F4Gg== X-Received: by 10.194.219.198 with SMTP id pq6mr44434660wjc.58.1375122960444; Mon, 29 Jul 2013 11:36:00 -0700 (PDT) Received: from storm-desktop.lan (bl9-171-157.dsl.telepac.pt. [85.242.171.157]) by mx.google.com with ESMTPSA id jf9sm12212485wic.5.2013.07.29.11.35.59 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Jul 2013 11:35:59 -0700 (PDT) From: Filipe David Borba Manana To: linux-btrfs@vger.kernel.org Cc: jbacik@fusionio.com, Filipe David Borba Manana Subject: [PATCH v2] Btrfs-progs: optimize function btrfs_read_chunk_tree Date: Mon, 29 Jul 2013 19:35:49 +0100 Message-Id: <1375122949-6596-1-git-send-email-fdmanana@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1373062984-12641-1-git-send-email-fdmanana@gmail.com> References: <1373062984-12641-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=-8.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 After reading all device items from the chunk tree, don't exit the loop and then navigate down the tree again to find the chunk items. Instead just read all device items and chunk items with a single tree search. This is possible because all device items are found before any chunk item in the chunks tree. This is a port of the corresponding kernel patch to keep both kernel and btrfs-progs identical: https://patchwork.kernel.org/patch/2835105/ Signed-off-by: Filipe David Borba Manana Reviewed-by: Miao Xie --- V2: Simplified logic inside the loop (suggested by Josef Bacik on irc). volumes.c | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/volumes.c b/volumes.c index 0ff2283..2c69f28 100644 --- a/volumes.c +++ b/volumes.c @@ -1718,14 +1718,13 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) if (!path) return -ENOMEM; - /* first we search for all of the device items, and then we - * read in all of the chunk items. This way we can create chunk - * mappings that reference all of the devices that are afound - */ + /* Read all device items, and then all the chunk items. All + device items are found before any chunk item (their object id + is smaller than the lowest possible object id for a chunk + item - BTRFS_FIRST_CHUNK_TREE_OBJECTID). */ key.objectid = BTRFS_DEV_ITEMS_OBJECTID; key.offset = 0; key.type = 0; -again: ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); while(1) { leaf = path->nodes[0]; @@ -1739,16 +1738,12 @@ again: break; } btrfs_item_key_to_cpu(leaf, &found_key, slot); - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) - break; - if (found_key.type == BTRFS_DEV_ITEM_KEY) { - struct btrfs_dev_item *dev_item; - dev_item = btrfs_item_ptr(leaf, slot, + if (found_key.type == BTRFS_DEV_ITEM_KEY) { + struct btrfs_dev_item *dev_item; + dev_item = btrfs_item_ptr(leaf, slot, struct btrfs_dev_item); - ret = read_one_dev(root, leaf, dev_item); - BUG_ON(ret); - } + ret = read_one_dev(root, leaf, dev_item); + BUG_ON(ret); } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { struct btrfs_chunk *chunk; chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); @@ -1757,11 +1752,6 @@ again: } path->slots[0]++; } - if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { - key.objectid = 0; - btrfs_release_path(root, path); - goto again; - } ret = 0; error: