aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/volumes.c
diff options
context:
space:
mode:
authorFilipe David Borba Manana <fdmanana@gmail.com>2013-07-30 07:03:04 -0400
committerChris Mason <chris.mason@fusionio.com>2013-09-01 08:04:43 -0400
commit395927a9d8e64af518c2ccdbfbbdf9184b558315 (patch)
treea42f503f5b3258b42069fa917db6aedb3def97a9 /fs/btrfs/volumes.c
parent6596a9281995a3c7dee8ca6666bd169fffc928e1 (diff)
Btrfs: optimize function btrfs_read_chunk_tree
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. Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> Reviewed-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Diffstat (limited to 'fs/btrfs/volumes.c')
-rw-r--r--fs/btrfs/volumes.c30
1 files changed, 11 insertions, 19 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 557a7438f929..93f39b1e7173 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5646,14 +5646,15 @@ int btrfs_read_chunk_tree(struct btrfs_root *root)
5646 mutex_lock(&uuid_mutex); 5646 mutex_lock(&uuid_mutex);
5647 lock_chunks(root); 5647 lock_chunks(root);
5648 5648
5649 /* first we search for all of the device items, and then we 5649 /*
5650 * read in all of the chunk items. This way we can create chunk 5650 * Read all device items, and then all the chunk items. All
5651 * mappings that reference all of the devices that are afound 5651 * device items are found before any chunk item (their object id
5652 * is smaller than the lowest possible object id for a chunk
5653 * item - BTRFS_FIRST_CHUNK_TREE_OBJECTID).
5652 */ 5654 */
5653 key.objectid = BTRFS_DEV_ITEMS_OBJECTID; 5655 key.objectid = BTRFS_DEV_ITEMS_OBJECTID;
5654 key.offset = 0; 5656 key.offset = 0;
5655 key.type = 0; 5657 key.type = 0;
5656again:
5657 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); 5658 ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
5658 if (ret < 0) 5659 if (ret < 0)
5659 goto error; 5660 goto error;
@@ -5669,17 +5670,13 @@ again:
5669 break; 5670 break;
5670 } 5671 }
5671 btrfs_item_key_to_cpu(leaf, &found_key, slot); 5672 btrfs_item_key_to_cpu(leaf, &found_key, slot);
5672 if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { 5673 if (found_key.type == BTRFS_DEV_ITEM_KEY) {
5673 if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) 5674 struct btrfs_dev_item *dev_item;
5674 break; 5675 dev_item = btrfs_item_ptr(leaf, slot,
5675 if (found_key.type == BTRFS_DEV_ITEM_KEY) {
5676 struct btrfs_dev_item *dev_item;
5677 dev_item = btrfs_item_ptr(leaf, slot,
5678 struct btrfs_dev_item); 5676 struct btrfs_dev_item);
5679 ret = read_one_dev(root, leaf, dev_item); 5677 ret = read_one_dev(root, leaf, dev_item);
5680 if (ret) 5678 if (ret)
5681 goto error; 5679 goto error;
5682 }
5683 } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { 5680 } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) {
5684 struct btrfs_chunk *chunk; 5681 struct btrfs_chunk *chunk;
5685 chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); 5682 chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk);
@@ -5689,11 +5686,6 @@ again:
5689 } 5686 }
5690 path->slots[0]++; 5687 path->slots[0]++;
5691 } 5688 }
5692 if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) {
5693 key.objectid = 0;
5694 btrfs_release_path(path);
5695 goto again;
5696 }
5697 ret = 0; 5689 ret = 0;
5698error: 5690error:
5699 unlock_chunks(root); 5691 unlock_chunks(root);