aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/ctree.h
diff options
context:
space:
mode:
authorZheng Yan <zheng.yan@oracle.com>2008-09-26 10:09:34 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-26 10:09:34 -0400
commit1a40e23b95da45051ee4d74374c58ae87a14051c (patch)
tree77faffd3f9d3a26c22e6cf03b83762c95d687596 /fs/btrfs/ctree.h
parent5b21f2ed3f2947b5195b65c9fdbdd9e52904cc03 (diff)
Btrfs: update space balancing code
This patch updates the space balancing code to utilize the new backref format. Before, btrfs-vol -b would break any COW links on data blocks or metadata. This was slow and caused the amount of space used to explode if a large number of snapshots were present. The new code can keeps the sharing of all data extents and most of the tree blocks. To maintain the sharing of data extents, the space balance code uses a seperate inode hold data extent pointers, then updates the references to point to the new location. To maintain the sharing of tree blocks, the space balance code uses reloc trees to relocate tree blocks in reference counted roots. There is one reloc tree for each subvol, and all reloc trees share same root key objectid. Reloc trees are snapshots of the latest committed roots of subvols (root->commit_root). To relocate a tree block referenced by a subvol, there are two steps. COW the block through subvol's reloc tree, then update block pointer in the subvol to point to the new block. Since all reloc trees share same root key objectid, doing special handing for tree blocks owned by them is easy. Once a tree block has been COWed in one reloc tree, we can use the resulting new block directly when the same block is required to COW again through other reloc trees. In this way, relocated tree blocks are shared between reloc trees, so they are also shared between subvols. Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/ctree.h')
-rw-r--r--fs/btrfs/ctree.h26
1 files changed, 25 insertions, 1 deletions
diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h
index 3e62a1b0a1f7..2775e270881e 100644
--- a/fs/btrfs/ctree.h
+++ b/fs/btrfs/ctree.h
@@ -604,6 +604,7 @@ struct btrfs_fs_info {
604 struct mutex chunk_mutex; 604 struct mutex chunk_mutex;
605 struct mutex drop_mutex; 605 struct mutex drop_mutex;
606 struct mutex volume_mutex; 606 struct mutex volume_mutex;
607 struct mutex tree_reloc_mutex;
607 struct list_head trans_list; 608 struct list_head trans_list;
608 struct list_head hashers; 609 struct list_head hashers;
609 struct list_head dead_roots; 610 struct list_head dead_roots;
@@ -647,6 +648,10 @@ struct btrfs_fs_info {
647 struct task_struct *cleaner_kthread; 648 struct task_struct *cleaner_kthread;
648 int thread_pool_size; 649 int thread_pool_size;
649 650
651 /* tree relocation relocated fields */
652 struct extent_io_tree reloc_mapping_tree;
653 struct list_head dead_reloc_roots;
654 struct btrfs_leaf_ref_tree reloc_ref_tree;
650 struct btrfs_leaf_ref_tree shared_ref_tree; 655 struct btrfs_leaf_ref_tree shared_ref_tree;
651 656
652 struct kobject super_kobj; 657 struct kobject super_kobj;
@@ -698,6 +703,7 @@ struct btrfs_root {
698 struct btrfs_leaf_ref_tree ref_tree_struct; 703 struct btrfs_leaf_ref_tree ref_tree_struct;
699 struct btrfs_dirty_root *dirty_root; 704 struct btrfs_dirty_root *dirty_root;
700 struct btrfs_root *log_root; 705 struct btrfs_root *log_root;
706 struct btrfs_root *reloc_root;
701 707
702 struct btrfs_root_item root_item; 708 struct btrfs_root_item root_item;
703 struct btrfs_key root_key; 709 struct btrfs_key root_key;
@@ -1517,7 +1523,6 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
1517struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans, 1523struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans,
1518 struct btrfs_root *root, 1524 struct btrfs_root *root,
1519 u64 bytenr, u32 blocksize); 1525 u64 bytenr, u32 blocksize);
1520int btrfs_shrink_extent_tree(struct btrfs_root *root, u64 new_size);
1521int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans, 1526int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
1522 struct btrfs_root *root, 1527 struct btrfs_root *root,
1523 struct btrfs_path *path, 1528 struct btrfs_path *path,
@@ -1582,10 +1587,29 @@ int btrfs_make_block_group(struct btrfs_trans_handle *trans,
1582 struct btrfs_root *root, u64 bytes_used, 1587 struct btrfs_root *root, u64 bytes_used,
1583 u64 type, u64 chunk_objectid, u64 chunk_offset, 1588 u64 type, u64 chunk_objectid, u64 chunk_offset,
1584 u64 size); 1589 u64 size);
1590int btrfs_remove_block_group(struct btrfs_trans_handle *trans,
1591 struct btrfs_root *root, u64 group_start);
1592int btrfs_relocate_block_group(struct btrfs_root *root, u64 group_start);
1593int btrfs_free_reloc_root(struct btrfs_root *root);
1594int btrfs_drop_dead_reloc_roots(struct btrfs_root *root);
1595int btrfs_add_reloc_mapping(struct btrfs_root *root, u64 orig_bytenr,
1596 u64 num_bytes, u64 new_bytenr);
1597int btrfs_get_reloc_mapping(struct btrfs_root *root, u64 orig_bytenr,
1598 u64 num_bytes, u64 *new_bytenr);
1599void btrfs_free_reloc_mappings(struct btrfs_root *root);
1600int btrfs_reloc_tree_cache_ref(struct btrfs_trans_handle *trans,
1601 struct btrfs_root *root,
1602 struct extent_buffer *buf, u64 orig_start);
1603int btrfs_add_dead_reloc_root(struct btrfs_root *root);
1604int btrfs_cleanup_reloc_trees(struct btrfs_root *root);
1585/* ctree.c */ 1605/* ctree.c */
1586int btrfs_previous_item(struct btrfs_root *root, 1606int btrfs_previous_item(struct btrfs_root *root,
1587 struct btrfs_path *path, u64 min_objectid, 1607 struct btrfs_path *path, u64 min_objectid,
1588 int type); 1608 int type);
1609int btrfs_merge_path(struct btrfs_trans_handle *trans,
1610 struct btrfs_root *root,
1611 struct btrfs_key *node_keys,
1612 u64 *nodes, int lowest_level);
1589int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans, 1613int btrfs_set_item_key_safe(struct btrfs_trans_handle *trans,
1590 struct btrfs_root *root, struct btrfs_path *path, 1614 struct btrfs_root *root, struct btrfs_path *path,
1591 struct btrfs_key *new_key); 1615 struct btrfs_key *new_key);