Btrfs: dirindex optimizations
Signed-off-by: Chris Mason <chris.mason@oracle.com>
This commit is contained in:
parent
7fcde0e329
commit
5be6f7f174
|
@ -239,6 +239,7 @@ struct btrfs_fs_info {
|
|||
struct radix_tree_root pinned_radix;
|
||||
u64 last_inode_alloc;
|
||||
u64 generation;
|
||||
u64 highest_inode;
|
||||
struct btrfs_transaction *running_transaction;
|
||||
struct btrfs_super_block *disk_super;
|
||||
struct buffer_head *sb_buffer;
|
||||
|
@ -970,6 +971,8 @@ int btrfs_insert_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,
|
||||
u64 objectid, int mod);
|
||||
int btrfs_find_highest_inode(struct btrfs_root *fs_root, u64 *objectid);
|
||||
|
||||
/* inode-item.c */
|
||||
int btrfs_insert_inode(struct btrfs_trans_handle *trans, struct btrfs_root
|
||||
*root, u64 objectid, struct btrfs_inode_item
|
||||
|
|
|
@ -92,6 +92,7 @@ int btrfs_lookup_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
|
|||
int cow = mod != 0;
|
||||
struct btrfs_disk_key *found_key;
|
||||
struct btrfs_leaf *leaf;
|
||||
u32 overflow;
|
||||
|
||||
key.objectid = dir;
|
||||
key.flags = 0;
|
||||
|
@ -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))
|
||||
return 0;
|
||||
|
||||
if (btrfs_disk_key_overflow(found_key) == 0)
|
||||
overflow = btrfs_disk_key_overflow(found_key);
|
||||
if (overflow == 0)
|
||||
return 1;
|
||||
btrfs_set_key_overflow(&key, overflow - 1);
|
||||
btrfs_release_path(root, path);
|
||||
}
|
||||
return 1;
|
||||
|
|
|
@ -311,6 +311,7 @@ struct btrfs_root *open_ctree(struct super_block *sb)
|
|||
fs_info->extent_root = extent_root;
|
||||
fs_info->inode_root = inode_root;
|
||||
fs_info->last_inode_alloc = 0;
|
||||
fs_info->highest_inode = 0;
|
||||
fs_info->sb = sb;
|
||||
fs_info->btree_inode = new_inode(sb);
|
||||
fs_info->btree_inode->i_ino = 1;
|
||||
|
@ -360,12 +361,15 @@ printk("failed2\n");
|
|||
|
||||
ret = find_and_setup_root(sb->s_blocksize, tree_root, fs_info,
|
||||
BTRFS_FS_TREE_OBJECTID, root);
|
||||
mutex_unlock(&fs_info->fs_mutex);
|
||||
BUG_ON(ret);
|
||||
root->commit_root = root->node;
|
||||
get_bh(root->node);
|
||||
root->ref_cows = 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;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,37 @@
|
|||
#include "disk-io.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.
|
||||
*/
|
||||
|
@ -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);
|
||||
|
||||
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_key.objectid = search_start;
|
||||
search_key.offset = 0;
|
||||
|
@ -129,6 +145,8 @@ int btrfs_insert_inode_map(struct btrfs_trans_handle *trans,
|
|||
path->slots[0], struct btrfs_inode_map_item);
|
||||
btrfs_cpu_key_to_disk(&inode_item->key, location);
|
||||
btrfs_mark_buffer_dirty(path->nodes[0]);
|
||||
if (objectid > fs_root->fs_info->highest_inode)
|
||||
fs_root->fs_info->highest_inode = objectid;
|
||||
out:
|
||||
btrfs_release_path(inode_root, path);
|
||||
btrfs_free_path(path);
|
||||
|
|
|
@ -482,6 +482,11 @@ static int btrfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
|||
item = leaf->items + slot;
|
||||
if (btrfs_disk_key_objectid(&item->key) != key.objectid)
|
||||
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)
|
||||
continue;
|
||||
if (btrfs_disk_key_offset(&item->key) < filp->f_pos)
|
||||
|
|
Loading…
Reference in New Issue