improve the balancing code
PATCH 1/1 improve the balancing code
This patch contains some random changes required by the balancing code.
Signed-off-by Yan Zheng <[email protected]>
---
fs/btrfs/ctree.c +18 -137
@@ -594,7 +594,7 @@ static int comp_keys(struct btrfs_disk_k/* * same as comp_keys only with two btrfs_key's */ -static int comp_cpu_keys (struct btrfs_key *k1,struct btrfs_key *k2) +int btrfs_comp_cpu_keys (struct btrfs_key *k1,struct btrfs_key *k2) {if (k1->objectid > k2->objectid)return 1 ;
@@ -970,6 +970,12 @@ static int bin_search(struct extent_buffreturn -1 ; } +int btrfs_bin_search (struct extent_buffer *eb,struct btrfs_key *key, +int level,int *slot) +{ +return bin_search (eb, key, level, slot); +} +/* given a node and slot number, this reads the blocks it points to. The * extent buffer is returned with a reference taken (but unlocked). * NULL is returned on error.
@@ -1709,10 +1715,17 @@ int btrfs_search_slot(struct btrfs_trans lowest_unlock =2 ; again: -if (p->skip_locking) - b =btrfs_root_node (root); -else - b =btrfs_lock_root_node (root); +if (p->search_commit_root) { + b = root->commit_root; +extent_buffer_get (b); +if (!p->skip_locking) +btrfs_tree_lock (b); + }else { +if (p->skip_locking) + b =btrfs_root_node (root); +else + b =btrfs_lock_root_node (root); + }while (b) { level =btrfs_header_level (b);
@@ -1852,138 +1865,6 @@ done:return ret; } -int btrfs_merge_path (struct btrfs_trans_handle *trans, -struct btrfs_root *root, -struct btrfs_key *node_keys, -u64 *nodes,int lowest_level) -{ -struct extent_buffer *eb; -struct extent_buffer *parent; -struct btrfs_key key; -u64 bytenr; -u64 generation; -u32 blocksize; -int level; -int slot; -int key_match; -int ret; - - eb =btrfs_lock_root_node (root); - ret =btrfs_cow_block (trans, root, eb,NULL ,0 , &eb); -BUG_ON (ret); - -btrfs_set_lock_blocking (eb); - - parent = eb; -while (1 ) { - level =btrfs_header_level (parent); -if (level ==0 || level <= lowest_level) -break ; - - ret =bin_search (parent, &node_keys[lowest_level], level, - &slot); -if (ret && slot >0 ) - slot--; - - bytenr =btrfs_node_blockptr (parent, slot); -if (nodes[level -1 ] == bytenr) -break ; - - blocksize =btrfs_level_size (root, level -1 ); - generation =btrfs_node_ptr_generation (parent, slot); -btrfs_node_key_to_cpu (eb, &key, slot); - key_match = !memcmp (&key, &node_keys[level -1 ],sizeof (key)); - -if (generation == trans->transid) { - eb =read_tree_block (root, bytenr, blocksize, - generation); -btrfs_tree_lock (eb); -btrfs_set_lock_blocking (eb); - } - -/* -* if node keys match and node pointer hasn't been modified -* in the running transaction, we can merge the path. for -* blocks owened by reloc trees, the node pointer check is -* skipped, this is because these blocks are fully controlled -* by the space balance code, no one else can modify them. -*/ -if (!nodes[level -1 ] || !key_match || - (generation == trans->transid && -btrfs_header_owner (eb) !=BTRFS_TREE_RELOC_OBJECTID )) { -if (level ==1 || level == lowest_level +1 ) { -if (generation == trans->transid) { -btrfs_tree_unlock (eb); -free_extent_buffer (eb); - } -break ; - } - -if (generation != trans->transid) { - eb =read_tree_block (root, bytenr, blocksize, - generation); -btrfs_tree_lock (eb); -btrfs_set_lock_blocking (eb); - } - - ret =btrfs_cow_block (trans, root, eb, parent, slot, - &eb); -BUG_ON (ret); - -if (root->root_key.objectid == -BTRFS_TREE_RELOC_OBJECTID ) { -if (!nodes[level -1 ]) { - nodes[level -1 ] = eb->start; -memcpy (&node_keys[level -1 ], &key, -sizeof (node_keys[0 ])); - }else { -WARN_ON (1 ); - } - } - -btrfs_tree_unlock (parent); -free_extent_buffer (parent); - parent = eb; -continue ; - } - -btrfs_set_node_blockptr (parent, slot, nodes[level -1 ]); -btrfs_set_node_ptr_generation (parent, slot, trans->transid); -btrfs_mark_buffer_dirty (parent); - - ret =btrfs_inc_extent_ref (trans, root, - nodes[level -1 ], - blocksize, parent->start, -btrfs_header_owner (parent), -btrfs_header_generation (parent), - level -1 ); -BUG_ON (ret); - -/* -* If the block was created in the running transaction, -* it's possible this is the last reference to it, so we -* should drop the subtree. -*/ -if (generation == trans->transid) { - ret =btrfs_drop_subtree (trans, root, eb, parent); -BUG_ON (ret); -btrfs_tree_unlock (eb); -free_extent_buffer (eb); - }else { - ret =btrfs_free_extent (trans, root, bytenr, - blocksize, parent->start, -btrfs_header_owner (parent), -btrfs_header_generation (parent), - level -1 ,1 ); -BUG_ON (ret); - } -break ; - } -btrfs_tree_unlock (parent); -free_extent_buffer (parent); -return 0 ; -} -/* * adjust the pointers going up the tree, starting at level * making sure the right key of each node is points to 'key'.
fs/btrfs/ctree.h +19 -29
97 lines not on this page · raw message
fs/btrfs/disk-io.c +1 -11
@@ -36,7 +36,6 @@#include "print-tree.h" #include "async-thread.h" #include "locking.h" -#include "ref-cache.h" #include "tree-log.h" #include "free-space-cache.h"
@@ -886,7 +885,6 @@ static int __setup_root(u32 nodesize, u3 { root->node =NULL ; root->commit_root =NULL ; - root->ref_tree =NULL ; root->sectorsize = sectorsize; root->nodesize = nodesize; root->leafsize = leafsize;
@@ -922,9 +920,6 @@ static int __setup_root(u32 nodesize, u3extent_io_tree_init (&root->dirty_log_pages, fs_info->btree_inode->i_mapping,GFP_NOFS ); -btrfs_leaf_ref_tree_init (&root->ref_tree_struct); - root->ref_tree = &root->ref_tree_struct; -memset (&root->root_key,0 ,sizeof (root->root_key));memset (&root->root_item,0 ,sizeof (root->root_item));memset (&root->defrag_progress,0 ,sizeof (root->defrag_progress));
@@ -1553,7 +1548,6 @@ struct btrfs_root *open_ctree(struct supINIT_LIST_HEAD (&fs_info->ordered_operations);spin_lock_init (&fs_info->delalloc_lock);spin_lock_init (&fs_info->new_trans_lock); -spin_lock_init (&fs_info->ref_cache_lock);init_completion (&fs_info->kobj_unregister); fs_info->tree_root = tree_root;
@@ -1614,10 +1608,6 @@ struct btrfs_root *open_ctree(struct sup fs_info->btree_inode->i_mapping, GFP_NOFS); fs_info->do_barriers =1 ; -INIT_LIST_HEAD (&fs_info->dead_reloc_roots); -btrfs_leaf_ref_tree_init (&fs_info->reloc_ref_tree); -btrfs_leaf_ref_tree_init (&fs_info->shared_ref_tree); -BTRFS_I (fs_info->btree_inode)->root = tree_root;memset (&BTRFS_I (fs_info->btree_inode)->location,0 ,sizeof (struct btrfs_key ));
@@ -1885,7 +1875,7 @@ struct btrfs_root *open_ctree(struct sup }if (!(sb->s_flags &MS_RDONLY )) { - ret =btrfs_cleanup_reloc_trees (tree_root); + ret =btrfs_recover_relocation (tree_root);BUG_ON (ret); }
fs/btrfs/extent-tree.c +10 -1
@@ -30,7 +30,6 @@#include "transaction.h" #include "volumes.h" #include "locking.h" -#include "ref-cache.h" #include "free-space-cache.h" static int update_reserved_extents(struct btrfs_root *root,
@@ -5861,6 +5860,16 @@ static int __alloc_chunk_for_shrink(strureturn 0 ; } +int btrfs_prepare_block_group_relocation (struct btrfs_root *root, +struct btrfs_block_group_cache *group) + +{ +__alloc_chunk_for_shrink (root, group,1 ); +set_block_group_readonly (group); +return 0 ; +} + +#if 0 static int __insert_orphan_inode (struct btrfs_trans_handle *trans,struct btrfs_root *root,u64 objectid,u64 size)
fs/btrfs/inode.c +0 -1
@@ -48,7 +48,6 @@#include "ordered-data.h" #include "xattr.h" #include "tree-log.h" -#include "ref-cache.h" #include "compression.h" #include "locking.h"
fs/btrfs/Makefile +2 -2
@@ -6,5 +6,5 @@ btrfs-y += super.o ctree.o extent-tree.o transaction.o inode.o file.o tree-defrag.o \ extent_map.o sysfs.o struct-funcs.o xattr.o ordered-data.o \ extent_io.o volumes.o async-thread.o ioctl.o locking.o orphan.o \ - ref-cache.o export.o tree-log.o acl.o free-space-cache.o zlib.o \ - compression.o delayed-ref.o + export.o tree-log.o acl.o free-space-cache.o zlib.o \ + compression.o delayed-ref.o relocation.o
fs/btrfs/transaction.c +0 -1
@@ -25,7 +25,6 @@#include "disk-io.h" #include "transaction.h" #include "locking.h" -#include "ref-cache.h" #include "tree-log.h" #define BTRFS_ROOT_TRANS_TAG 0
fs/btrfs/volumes.c +0 -2
@@ -1670,8 +1670,6 @@ static int btrfs_relocate_chunk(struct bint ret;int i; -printk (KERN_INFO "btrfs relocating chunk %llu\n" , - (unsigned long long )chunk_offset); root = root->fs_info->chunk_root; extent_root = root->fs_info->extent_root; em_tree = &root->fs_info->mapping_tree.map_tree;