Commit 395927a9 authored by Filipe David Borba Manana's avatar Filipe David Borba Manana Committed by Chris Mason

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: default avatarFilipe David Borba Manana <fdmanana@gmail.com>
Reviewed-by: default avatarMiao Xie <miaox@cn.fujitsu.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent 6596a928
...@@ -5646,14 +5646,15 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) ...@@ -5646,14 +5646,15 @@ int btrfs_read_chunk_tree(struct btrfs_root *root)
mutex_lock(&uuid_mutex); mutex_lock(&uuid_mutex);
lock_chunks(root); lock_chunks(root);
/* 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 * Read all device items, and then all the chunk items. All
* mappings that reference all of the devices that are afound * 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.objectid = BTRFS_DEV_ITEMS_OBJECTID;
key.offset = 0; key.offset = 0;
key.type = 0; key.type = 0;
again:
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
if (ret < 0) if (ret < 0)
goto error; goto error;
...@@ -5669,17 +5670,13 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) ...@@ -5669,17 +5670,13 @@ int btrfs_read_chunk_tree(struct btrfs_root *root)
break; break;
} }
btrfs_item_key_to_cpu(leaf, &found_key, slot); btrfs_item_key_to_cpu(leaf, &found_key, slot);
if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) { if (found_key.type == BTRFS_DEV_ITEM_KEY) {
if (found_key.objectid != BTRFS_DEV_ITEMS_OBJECTID) struct btrfs_dev_item *dev_item;
break; 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); struct btrfs_dev_item);
ret = read_one_dev(root, leaf, dev_item); ret = read_one_dev(root, leaf, dev_item);
if (ret) if (ret)
goto error; goto error;
}
} else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) { } else if (found_key.type == BTRFS_CHUNK_ITEM_KEY) {
struct btrfs_chunk *chunk; struct btrfs_chunk *chunk;
chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk); chunk = btrfs_item_ptr(leaf, slot, struct btrfs_chunk);
...@@ -5689,11 +5686,6 @@ int btrfs_read_chunk_tree(struct btrfs_root *root) ...@@ -5689,11 +5686,6 @@ int btrfs_read_chunk_tree(struct btrfs_root *root)
} }
path->slots[0]++; path->slots[0]++;
} }
if (key.objectid == BTRFS_DEV_ITEMS_OBJECTID) {
key.objectid = 0;
btrfs_release_path(path);
goto again;
}
ret = 0; ret = 0;
error: error:
unlock_chunks(root); unlock_chunks(root);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment