aboutsummaryrefslogtreecommitdiffstats
path: root/fs/btrfs/extent-tree.c
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-02-01 14:51:59 -0500
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:00 -0400
commit47e4bb988c853d9af79d76fc5135aee9eeffed77 (patch)
tree93ddba509c3dcc20676a1b7419ac09fedbac003a /fs/btrfs/extent-tree.c
parent80ea96b1f3bd2431e0d71c9df6ab45c3de0c5840 (diff)
Btrfs: Insert extent record and the first backref in a single balance
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs/btrfs/extent-tree.c')
-rw-r--r--fs/btrfs/extent-tree.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index fa54ea590078..0fc8dfd58da9 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -1664,12 +1664,13 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1664 u64 root_used; 1664 u64 root_used;
1665 u64 search_start = 0; 1665 u64 search_start = 0;
1666 u64 new_hint; 1666 u64 new_hint;
1667 u32 sizes[2];
1667 struct btrfs_fs_info *info = root->fs_info; 1668 struct btrfs_fs_info *info = root->fs_info;
1668 struct btrfs_root *extent_root = info->extent_root; 1669 struct btrfs_root *extent_root = info->extent_root;
1669 struct btrfs_extent_item extent_item; 1670 struct btrfs_extent_item *extent_item;
1671 struct btrfs_extent_ref *ref;
1670 struct btrfs_path *path; 1672 struct btrfs_path *path;
1671 1673 struct btrfs_key keys[2];
1672 btrfs_set_stack_extent_refs(&extent_item, 1);
1673 1674
1674 new_hint = max(hint_byte, root->fs_info->alloc_start); 1675 new_hint = max(hint_byte, root->fs_info->alloc_start);
1675 if (new_hint < btrfs_super_total_bytes(&info->super_copy)) 1676 if (new_hint < btrfs_super_total_bytes(&info->super_copy))
@@ -1707,20 +1708,37 @@ int btrfs_alloc_extent(struct btrfs_trans_handle *trans,
1707 WARN_ON(trans->alloc_exclude_nr); 1708 WARN_ON(trans->alloc_exclude_nr);
1708 trans->alloc_exclude_start = ins->objectid; 1709 trans->alloc_exclude_start = ins->objectid;
1709 trans->alloc_exclude_nr = ins->offset; 1710 trans->alloc_exclude_nr = ins->offset;
1710 ret = btrfs_insert_item(trans, extent_root, ins, &extent_item,
1711 sizeof(extent_item));
1712 1711
1713 trans->alloc_exclude_start = 0; 1712 memcpy(&keys[0], ins, sizeof(*ins));
1714 trans->alloc_exclude_nr = 0; 1713 keys[1].offset = hash_extent_ref(root_objectid, ref_generation,
1715 BUG_ON(ret); 1714 owner, owner_offset);
1715 keys[1].objectid = ins->objectid;
1716 keys[1].type = BTRFS_EXTENT_REF_KEY;
1717 sizes[0] = sizeof(*extent_item);
1718 sizes[1] = sizeof(*ref);
1716 1719
1717 path = btrfs_alloc_path(); 1720 path = btrfs_alloc_path();
1718 BUG_ON(!path); 1721 BUG_ON(!path);
1719 ret = btrfs_insert_extent_backref(trans, extent_root, path, 1722
1720 ins->objectid, root_objectid, 1723 ret = btrfs_insert_empty_items(trans, extent_root, path, keys,
1721 ref_generation, owner, owner_offset); 1724 sizes, 2);
1722 1725
1723 BUG_ON(ret); 1726 BUG_ON(ret);
1727 extent_item = btrfs_item_ptr(path->nodes[0], path->slots[0],
1728 struct btrfs_extent_item);
1729 btrfs_set_extent_refs(path->nodes[0], extent_item, 1);
1730 ref = btrfs_item_ptr(path->nodes[0], path->slots[0] + 1,
1731 struct btrfs_extent_ref);
1732
1733 btrfs_set_ref_root(path->nodes[0], ref, root_objectid);
1734 btrfs_set_ref_generation(path->nodes[0], ref, ref_generation);
1735 btrfs_set_ref_objectid(path->nodes[0], ref, owner);
1736 btrfs_set_ref_offset(path->nodes[0], ref, owner_offset);
1737
1738 btrfs_mark_buffer_dirty(path->nodes[0]);
1739
1740 trans->alloc_exclude_start = 0;
1741 trans->alloc_exclude_nr = 0;
1724 btrfs_free_path(path); 1742 btrfs_free_path(path);
1725 finish_current_insert(trans, extent_root); 1743 finish_current_insert(trans, extent_root);
1726 pending_ret = del_pending_extents(trans, extent_root); 1744 pending_ret = del_pending_extents(trans, extent_root);