提交 5be6f7f1 编写于 作者: C Chris Mason 提交者: David Woodhouse

Btrfs: dirindex optimizations

Signed-off-by: NChris Mason <chris.mason@oracle.com>
上级 7fcde0e3
...@@ -239,6 +239,7 @@ struct btrfs_fs_info { ...@@ -239,6 +239,7 @@ struct btrfs_fs_info {
struct radix_tree_root pinned_radix; struct radix_tree_root pinned_radix;
u64 last_inode_alloc; u64 last_inode_alloc;
u64 generation; u64 generation;
u64 highest_inode;
struct btrfs_transaction *running_transaction; struct btrfs_transaction *running_transaction;
struct btrfs_super_block *disk_super; struct btrfs_super_block *disk_super;
struct buffer_head *sb_buffer; struct buffer_head *sb_buffer;
...@@ -970,6 +971,8 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, ...@@ -970,6 +971,8 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans, int btrfs_lookup_inode_map(struct btrfs_trans_handle *trans,
struct btrfs_root *root, struct btrfs_path *path, struct btrfs_root *root, struct btrfs_path *path,
u64 objectid, int mod); u64 objectid, int mod);
int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
/* inode-item.c */ /* inode-item.c */
int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
*root, u64 objectid, struct btrfs_inode_item *root, u64 objectid, struct btrfs_inode_item
......
...@@ -92,6 +92,7 @@ int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -92,6 +92,7 @@ int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
int cow = mod != 0; int cow = mod != 0;
struct btrfs_disk_key *found_key; struct btrfs_disk_key *found_key;
struct btrfs_leaf *leaf; struct btrfs_leaf *leaf;
u32 overflow;
key.objectid = dir; key.objectid = dir;
key.flags = 0; key.flags = 0;
...@@ -119,8 +120,10 @@ int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root ...@@ -119,8 +120,10 @@ int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
if (btrfs_match_dir_item_name(root, path, name, name_len)) if (btrfs_match_dir_item_name(root, path, name, name_len))
return 0; return 0;
if (btrfs_disk_key_overflow(found_key) == 0) overflow = btrfs_disk_key_overflow(found_key);
if (overflow == 0)
return 1; return 1;
btrfs_set_key_overflow(&key, overflow - 1);
btrfs_release_path(root, path); btrfs_release_path(root, path);
} }
return 1; return 1;
......
...@@ -311,6 +311,7 @@ struct btrfs_root *open_ctree(struct super_block *sb) ...@@ -311,6 +311,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
fs_info->extent_root = extent_root; fs_info->extent_root = extent_root;
fs_info->inode_root = inode_root; fs_info->inode_root = inode_root;
fs_info->last_inode_alloc = 0; fs_info->last_inode_alloc = 0;
fs_info->highest_inode = 0;
fs_info->sb = sb; fs_info->sb = sb;
fs_info->btree_inode = new_inode(sb); fs_info->btree_inode = new_inode(sb);
fs_info->btree_inode->i_ino = 1; fs_info->btree_inode->i_ino = 1;
...@@ -360,12 +361,15 @@ printk("failed2\n"); ...@@ -360,12 +361,15 @@ printk("failed2\n");
ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info, ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info,
BTRFS_FS_TREE_OBJECTID, root); BTRFS_FS_TREE_OBJECTID, root);
mutex_unlock(&fs_info->fs_mutex);
BUG_ON(ret); BUG_ON(ret);
root->commit_root = root->node; root->commit_root = root->node;
get_bh(root->node); get_bh(root->node);
root->ref_cows = 1; root->ref_cows = 1;
root->fs_info->generation = root->root_key.offset + 1; root->fs_info->generation = root->root_key.offset + 1;
ret = btrfs_find_highest_inode(root, &root->fs_info->last_inode_alloc);
if (ret == 0)
fs_info->highest_inode = fs_info->last_inode_alloc;
mutex_unlock(&fs_info->fs_mutex);
return root; return root;
} }
......
...@@ -3,6 +3,37 @@ ...@@ -3,6 +3,37 @@
#include "disk-io.h" #include "disk-io.h"
#include "transaction.h" #include "transaction.h"
int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid)
{
struct btrfs_path *path;
int ret;
struct btrfs_leaf *l;
struct btrfs_root *root = fs_root->fs_info->inode_root;
struct btrfs_key search_key;
int slot;
path = btrfs_alloc_path();
BUG_ON(!path);
search_key.objectid = (u64)-1;
search_key.offset = (u64)-1;
ret = btrfs_search_slot(NULL, root, &search_key, path, 0, 0);
if (ret < 0)
goto error;
BUG_ON(ret == 0);
if (path->slots[0] > 0) {
slot = path->slots[0] - 1;
l = btrfs_buffer_leaf(path->nodes[0]);
*objectid = btrfs_disk_key_objectid(&l->items[slot].key);
} else {
*objectid = BTRFS_FIRST_FREE_OBJECTID;
}
ret = 0;
error:
btrfs_free_path(path);
return ret;
}
/* /*
* walks the btree of allocated inodes and find a hole. * walks the btree of allocated inodes and find a hole.
*/ */
...@@ -28,21 +59,6 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans, ...@@ -28,21 +59,6 @@ int btrfs_find_free_objectid(struct btrfs_trans_handle *trans,
btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY); btrfs_set_key_type(&search_key, BTRFS_INODE_MAP_ITEM_KEY);
search_start = fs_root->fs_info->last_inode_alloc; search_start = fs_root->fs_info->last_inode_alloc;
if (search_start == 0) {
struct btrfs_disk_key *last_key;
btrfs_init_path(path);
search_key.objectid = (u64)-1;
search_key.offset = (u64)-1;
ret = btrfs_search_slot(trans, root, &search_key, path, 0, 0);
if (ret < 0)
goto error;
BUG_ON(ret == 0);
if (path->slots[0] > 0)
path->slots[0]--;
l = btrfs_buffer_leaf(path->nodes[0]);
last_key = &l->items[path->slots[0]].key;
search_start = btrfs_disk_key_objectid(last_key);
}
search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID); search_start = max(search_start, BTRFS_FIRST_FREE_OBJECTID);
search_key.objectid = search_start; search_key.objectid = search_start;
search_key.offset = 0; search_key.offset = 0;
...@@ -129,6 +145,8 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans, ...@@ -129,6 +145,8 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
path->slots[0], struct btrfs_inode_map_item); path->slots[0], struct btrfs_inode_map_item);
btrfs_cpu_key_to_disk(&inode_item->key, location); btrfs_cpu_key_to_disk(&inode_item->key, location);
btrfs_mark_buffer_dirty(path->nodes[0]); btrfs_mark_buffer_dirty(path->nodes[0]);
if (objectid > fs_root->fs_info->highest_inode)
fs_root->fs_info->highest_inode = objectid;
out: out:
btrfs_release_path(inode_root, path); btrfs_release_path(inode_root, path);
btrfs_free_path(path); btrfs_free_path(path);
......
...@@ -482,6 +482,11 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir) ...@@ -482,6 +482,11 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
item = leaf->items + slot; item = leaf->items + slot;
if (btrfs_disk_key_objectid(&item->key) != key.objectid) if (btrfs_disk_key_objectid(&item->key) != key.objectid)
break; break;
if (btrfs_disk_key_offset(&item->key) >
root->fs_info->highest_inode) {
printk("stopping at highest inode %Lu\n", root->fs_info->highest_inode);
break;
}
if (btrfs_disk_key_type(&item->key) != BTRFS_DIR_INDEX_KEY) if (btrfs_disk_key_type(&item->key) != BTRFS_DIR_INDEX_KEY)
continue; continue;
if (btrfs_disk_key_offset(&item->key) < filp->f_pos) if (btrfs_disk_key_offset(&item->key) < filp->f_pos)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册