btrfs: mixed backrefs
PATCH 2/6 btrfs: mixed backrefs
The dead tree avoidance patch removes the need to modify the reference counts of child blocks when a non shared tree block is cow'd. But we still have to update back ref for all pointers in the block. This is because the location of tree block is recorded in back ref items. We can solve this by introducing a new type of back ref. The new back ref provide information about the owner tree and level of the block in which the pointer lives. These information allow us to find the block by tree searching. The shortcoming of the new back ref is that it only works for pointers in tree blocks referenced by their owner trees. when a tree block loses its owner tree's reference, we update back ref for all pointers in the block to full back ref.
This patch is the core part of the mixed backrefs.
---
fs/btrfs/ctree.h +97 -60
@@ -421,23 +421,48 @@ struct btrfs_path { unsigned int keep_locks:1; unsigned int skip_locking:1; unsigned int leave_spinning:1; + unsigned int search_commit_root:1; };/* * items in the extent btree are used to record the objectid of the * owner of the block and the number of references */ +struct btrfs_extent_item { -__le32 refs; +__le64 refs; +__le64 generation; +__le64 flags; } __attribute__ ((__packed__ )); -struct btrfs_extent_ref { + +#define BTRFS_EXTENT_FLAG_DATA (1ULL << 0) +#define BTRFS_EXTENT_FLAG_TREE_BLOCK (1ULL << 1) + +/* following flags only apply to tree blocks */ + +/* tree block is not referenced by its owner tree */ +#define BTRFS_BLOCK_NO_OWNER_REF (1ULL << 8) +/* use full backrefs for extent pointers in the block */ +#define BTRFS_BLOCK_FULL_BACKREF (1ULL << 9) + +struct btrfs_tree_block_info { +struct btrfs_disk_key key; +u8 level; +} __attribute__ ((__packed__ )); + +struct btrfs_extent_data_ref {__le64 root; -__le64 generation;__le64 objectid; -__le32 num_refs; +__le64 offset; +__le32 count; +} __attribute__ ((__packed__ )); + +struct btrfs_shared_data_ref { +__le32 count; } __attribute__ ((__packed__ )); +/* dev extents record free space on individual devices. The owner * field points back to the chunk allocation mapping tree that allocated * the extent. The chunk tree uuid field is a way to double check the owner
@@ -891,7 +916,6 @@ struct btrfs_fs_info {* in ram representation of the tree. extent_root is used for all allocations * and for the extent tree extent_root root. */ -struct btrfs_dirty_root ;struct btrfs_root {struct extent_buffer *node;
@@ -1018,7 +1042,16 @@ struct btrfs_root {* are used, and how many references there are to each block */ #define BTRFS_EXTENT_ITEM_KEY 168 -#define BTRFS_EXTENT_REF_KEY 180 + +#define BTRFS_TREE_BLOCK_INFO_KEY 174 + +#define BTRFS_TREE_BLOCK_REF_KEY 180 + +#define BTRFS_SHARED_BLOCK_REF_KEY 181 + +#define BTRFS_EXTENT_DATA_REF_KEY 186 + +#define BTRFS_SHARED_DATA_REF_KEY 187/* * block groups give us hints into the extent allocation trees. Which
@@ -1318,24 +1351,39 @@ static inline u8 *btrfs_dev_extent_chunkreturn (u8 *)((unsigned long )dev + ptr); } -/* struct btrfs_extent_ref */ -BTRFS_SETGET_FUNCS(ref_root, struct btrfs_extent_ref, root, 64); -BTRFS_SETGET_FUNCS(ref_generation, struct btrfs_extent_ref, generation, 64); -BTRFS_SETGET_FUNCS(ref_objectid, struct btrfs_extent_ref, objectid, 64); -BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32); +/* struct btrfs_extent_item */ +BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 64); +BTRFS_SETGET_FUNCS(extent_generation, struct btrfs_extent_item, + generation,64 ); +BTRFS_SETGET_FUNCS(extent_flags, struct btrfs_extent_item, flags, 64); -BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64); -BTRFS_SETGET_STACK_FUNCS(stack_ref_generation, struct btrfs_extent_ref, - generation,64 ); -BTRFS_SETGET_STACK_FUNCS(stack_ref_objectid, struct btrfs_extent_ref, - objectid,64 ); -BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref, - num_refs,32 ); +BTRFS_SETGET_FUNCS(tree_block_level, struct btrfs_tree_block_info, level, 8); -/* struct btrfs_extent_item */ -BTRFS_SETGET_FUNCS(extent_refs, struct btrfs_extent_item, refs, 32); -BTRFS_SETGET_STACK_FUNCS(stack_extent_refs, struct btrfs_extent_item, - refs,32 ); +static inline void btrfs_tree_block_key (struct extent_buffer *eb, +struct btrfs_tree_block_info *item, +struct btrfs_disk_key *key) +{ + read_eb_member(eb, item, struct btrfs_tree_block_info, key, key); +} + +static inline void btrfs_set_tree_block_key (struct extent_buffer *eb, +struct btrfs_tree_block_info *item, +struct btrfs_disk_key *key) +{ + write_eb_member(eb, item, struct btrfs_tree_block_info, key, key); +} + +BTRFS_SETGET_FUNCS(extent_data_ref_root, struct btrfs_extent_data_ref, + root,64 ); +BTRFS_SETGET_FUNCS(extent_data_ref_objectid, struct btrfs_extent_data_ref, + objectid,64 ); +BTRFS_SETGET_FUNCS(extent_data_ref_offset, struct btrfs_extent_data_ref, + offset,64 ); +BTRFS_SETGET_FUNCS(extent_data_ref_count, struct btrfs_extent_data_ref, + count,32 ); + +BTRFS_SETGET_FUNCS(shared_data_ref_count, struct btrfs_shared_data_ref, + count,32 );/* struct btrfs_node */ BTRFS_SETGET_FUNCS(key_blockptr, struct btrfs_key_ptr, blockptr, 64);
@@ -1791,39 +1839,32 @@ int btrfs_update_pinned_extents(struct bint btrfs_drop_leaf_ref (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct extent_buffer *leaf);int btrfs_cross_ref_exist (struct btrfs_trans_handle *trans, -struct btrfs_root *root,u64 objectid,u64 bytenr); +struct btrfs_root *root, +u64 objectid,u64 offset,u64 bytenr);int btrfs_copy_pinned (struct btrfs_root *root,struct extent_io_tree *copy);struct btrfs_block_group_cache *btrfs_lookup_block_group (struct btrfs_fs_info *info,u64 bytenr); +void btrfs_put_block_group (struct btrfs_block_group_cache *cache);u64 btrfs_find_block_group (struct btrfs_root *root,u64 search_start,u64 search_hint,int owner);struct extent_buffer *btrfs_alloc_free_block (struct btrfs_trans_handle *trans, -struct btrfs_root *root, -u32 blocksize,u64 parent, -u64 root_objectid, -u64 ref_generation, -int level, -u64 hint, -u64 empty_size); +struct btrfs_root *root,u32 blocksize, +u64 parent,u64 root_objectid, +struct btrfs_disk_key *key,int level, +u64 hint,u64 empty_size);struct extent_buffer *btrfs_init_new_buffer (struct btrfs_trans_handle *trans,struct btrfs_root *root,u64 bytenr,u32 blocksize,int level); -int btrfs_alloc_extent (struct btrfs_trans_handle *trans, -struct btrfs_root *root, -u64 num_bytes,u64 parent,u64 min_bytes, -u64 root_objectid,u64 ref_generation, -u64 owner,u64 empty_size,u64 hint_byte, -u64 search_end,struct btrfs_key *ins,u64 data); -int btrfs_alloc_reserved_extent (struct btrfs_trans_handle *trans, -struct btrfs_root *root,u64 parent, -u64 root_objectid,u64 ref_generation, -u64 owner,struct btrfs_key *ins); -int btrfs_alloc_logged_extent (struct btrfs_trans_handle *trans, -struct btrfs_root *root,u64 parent, -u64 root_objectid,u64 ref_generation, -u64 owner,struct btrfs_key *ins); +int btrfs_alloc_reserved_file_extent (struct btrfs_trans_handle *trans, +struct btrfs_root *root, +u64 root_objectid,u64 owner, +u64 offset,struct btrfs_key *ins); +int btrfs_alloc_logged_file_extent (struct btrfs_trans_handle *trans, +struct btrfs_root *root, +u64 root_objectid,u64 owner,u64 offset, +struct btrfs_key *ins); int btrfs_reserve_extent(struct btrfs_trans_handle *trans, struct btrfs_root *root, u64 num_bytes, u64 min_alloc_size,
@@ -1831,18 +1872,17 @@ int btrfs_reserve_extent(struct btrfs_tr u64 search_end, struct btrfs_key *ins, u64 data);int btrfs_inc_ref (struct btrfs_trans_handle *trans,struct btrfs_root *root, -struct extent_buffer *orig_buf,struct extent_buffer *buf, -u32 *nr_extents); -int btrfs_cache_ref (struct btrfs_trans_handle *trans,struct btrfs_root *root, -struct extent_buffer *buf,u32 nr_extents); -int btrfs_update_ref (struct btrfs_trans_handle *trans, -struct btrfs_root *root,struct extent_buffer *orig_buf, -struct extent_buffer *buf,int start_slot,int nr); +struct extent_buffer *buf,int full_backref); +int btrfs_dec_ref (struct btrfs_trans_handle *trans,struct btrfs_root *root, +struct extent_buffer *buf,int full_backref); +int btrfs_set_block_flags (struct btrfs_trans_handle *trans, +struct btrfs_root *root, +u64 bytenr,u64 num_bytes,u64 flags);int btrfs_free_extent (struct btrfs_trans_handle *trans,struct btrfs_root *root,u64 bytenr,u64 num_bytes,u64 parent, -u64 root_objectid,u64 ref_generation, -u64 owner_objectid,int pin); +u64 root_objectid,u64 owner,u64 offset); +int btrfs_free_reserved_extent (struct btrfs_root *root,u64 start,u64 len); int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans, struct btrfs_root *root,
@@ -1850,13 +1890,8 @@ int btrfs_finish_extent_commit(struct btint btrfs_inc_extent_ref (struct btrfs_trans_handle *trans,struct btrfs_root *root,u64 bytenr,u64 num_bytes,u64 parent, -u64 root_objectid,u64 ref_generation, -u64 owner_objectid); -int btrfs_update_extent_ref (struct btrfs_trans_handle *trans, -struct btrfs_root *root,u64 bytenr,u64 num_bytes, -u64 orig_parent,u64 parent, -u64 root_objectid,u64 ref_generation, -u64 owner_objectid); +u64 root_objectid,u64 owner,u64 offset); +int btrfs_write_dirty_block_groups (struct btrfs_trans_handle *trans,struct btrfs_root *root);int btrfs_extent_readonly (struct btrfs_root *root,u64 bytenr);
@@ -1919,6 +1954,8 @@ int btrfs_copy_root(struct btrfs_trans_hstruct btrfs_root *root, struct extent_buffer *buf, struct extent_buffer **cow_ret, u64 new_root_objectid); +int btrfs_block_can_be_shared (struct btrfs_root *root, +struct extent_buffer *buf);int btrfs_extend_item (struct btrfs_trans_handle *trans,struct btrfs_root *root,struct btrfs_path *path,u32 data_size); int btrfs_truncate_item(struct btrfs_trans_handle *trans,
fs/btrfs/extent-tree.c +1153 -768
2,594 lines not on this page · raw message