path: root/utils.c
diff options
authorChris Mason <>2009-05-29 16:35:30 -0400
committerChris Mason <>2009-06-08 13:30:36 -0400
commit95d3f20b51e9b2ee21822313ad4f31279396407b (patch)
treeb120e33ca9ad3f04a0a32b62451e6ba5926b2ca0 /utils.c
parent2d39a83829bfc26f0c79b33fca64540c634f7f18 (diff)
This commit introduces a new kind of back reference for btrfs metadata. Once a filesystem has been mounted with this commit, IT WILL NO LONGER BE MOUNTABLE BY OLDER KERNELS. The new back ref provides information about pointer's key, level and in which tree the pointer lives. This information allow us to find the pointer by searching the tree. The shortcoming of the new back ref is that it only works for pointers in tree blocks referenced by their owner trees. This is mostly a problem for snapshots, where resolving one of these fuzzy back references would be O(number_of_snapshots) and quite slow. The solution used here is to use the fuzzy back references in the common case where a given tree block is only referenced by one root, and use the full back references when multiple roots have a reference
Diffstat (limited to 'utils.c')
1 files changed, 11 insertions, 14 deletions
diff --git a/utils.c b/utils.c
index a87c5a86..2f4c6e14 100644
--- a/utils.c
+++ b/utils.c
@@ -63,7 +63,6 @@ int make_btrfs(int fd, const char *device, const char *label,
struct extent_buffer *buf;
struct btrfs_root_item root_item;
struct btrfs_disk_key disk_key;
- struct btrfs_extent_ref *extent_ref;
struct btrfs_extent_item *extent_item;
struct btrfs_inode_item *inode_item;
struct btrfs_chunk *chunk;
@@ -115,6 +114,7 @@ int make_btrfs(int fd, const char *device, const char *label,
btrfs_set_header_bytenr(buf, blocks[1]);
btrfs_set_header_nritems(buf, 4);
btrfs_set_header_generation(buf, 1);
+ btrfs_set_header_backref_rev(buf, BTRFS_MIXED_BACKREF_REV);
btrfs_set_header_owner(buf, BTRFS_ROOT_TREE_OBJECTID);
write_extent_buffer(buf, super.fsid, (unsigned long)
btrfs_header_fsid(buf), BTRFS_FSID_SIZE);
@@ -200,7 +200,8 @@ int make_btrfs(int fd, const char *device, const char *label,
BUG_ON(blocks[i] < blocks[i - 1]);
/* create extent item */
- itemoff = itemoff - sizeof(struct btrfs_extent_item);
+ itemoff -= sizeof(struct btrfs_extent_item) +
+ sizeof(struct btrfs_tree_block_info);
btrfs_set_disk_key_objectid(&disk_key, blocks[i]);
btrfs_set_disk_key_offset(&disk_key, leafsize);
btrfs_set_disk_key_type(&disk_key, BTRFS_EXTENT_ITEM_KEY);
@@ -208,29 +209,25 @@ int make_btrfs(int fd, const char *device, const char *label,
btrfs_set_item_offset(buf, btrfs_item_nr(buf, nritems),
btrfs_set_item_size(buf, btrfs_item_nr(buf, nritems),
- sizeof(struct btrfs_extent_item));
+ sizeof(struct btrfs_extent_item) +
+ sizeof(struct btrfs_tree_block_info));
extent_item = btrfs_item_ptr(buf, nritems,
struct btrfs_extent_item);
btrfs_set_extent_refs(buf, extent_item, 1);
+ btrfs_set_extent_generation(buf, extent_item, 1);
+ btrfs_set_extent_flags(buf, extent_item,
/* create extent ref */
ref_root = reference_root_table[i];
- itemoff = itemoff - sizeof(struct btrfs_extent_ref);
btrfs_set_disk_key_objectid(&disk_key, blocks[i]);
- btrfs_set_disk_key_offset(&disk_key, blocks[i]);
- btrfs_set_disk_key_type(&disk_key, BTRFS_EXTENT_REF_KEY);
+ btrfs_set_disk_key_offset(&disk_key, ref_root);
+ btrfs_set_disk_key_type(&disk_key, BTRFS_TREE_BLOCK_REF_KEY);
btrfs_set_item_key(buf, &disk_key, nritems);
btrfs_set_item_offset(buf, btrfs_item_nr(buf, nritems),
- btrfs_set_item_size(buf, btrfs_item_nr(buf, nritems),
- sizeof(struct btrfs_extent_ref));
- extent_ref = btrfs_item_ptr(buf, nritems,
- struct btrfs_extent_ref);
- btrfs_set_ref_root(buf, extent_ref, ref_root);
- btrfs_set_ref_generation(buf, extent_ref, 1);
- btrfs_set_ref_objectid(buf, extent_ref, 0);
- btrfs_set_ref_num_refs(buf, extent_ref, 1);
+ btrfs_set_item_size(buf, btrfs_item_nr(buf, nritems), 0);
btrfs_set_header_bytenr(buf, blocks[2]);