Commit 3bb1a1bc authored by Yan Zheng's avatar Yan Zheng Committed by Chris Mason

Btrfs: Remove offset field from struct btrfs_extent_ref

The offset field in struct btrfs_extent_ref records the position
inside file that file extent is referenced by. In the new back
reference system, tree leaves holding references to file extent
are recorded explicitly. We can scan these tree leaves very quickly, so the
offset field is not required.

This patch also makes the back reference system check the objectid
when extents are in deleting.
Signed-off-by: default avatarYan Zheng <zheng.yan@oracle.com>
parent a76a3cd4
......@@ -254,8 +254,7 @@ int noinline __btrfs_cow_block(struct btrfs_trans_handle *trans,
ret = btrfs_alloc_reserved_extent(trans, root, parent_start,
root->root_key.objectid,
trans->transid, level, 0,
&ins);
trans->transid, level, &ins);
BUG_ON(ret);
cow = btrfs_init_new_buffer(trans, root, prealloc_dest,
buf->len);
......@@ -333,7 +332,7 @@ int noinline __btrfs_cow_block(struct btrfs_trans_handle *trans,
buf->len, buf->start,
root->root_key.objectid,
btrfs_header_generation(buf),
0, 0, 1);
level, 1);
}
free_extent_buffer(buf);
add_root_to_dirty_list(root);
......@@ -347,7 +346,7 @@ int noinline __btrfs_cow_block(struct btrfs_trans_handle *trans,
WARN_ON(btrfs_header_generation(parent) != trans->transid);
btrfs_free_extent(trans, root, buf->start, buf->len,
parent_start, btrfs_header_owner(parent),
btrfs_header_generation(parent), 0, 0, 1);
btrfs_header_generation(parent), level, 1);
}
if (unlock_orig)
btrfs_tree_unlock(buf);
......@@ -927,7 +926,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
ret = btrfs_update_extent_ref(trans, root, child->start,
mid->start, child->start,
root->root_key.objectid,
trans->transid, level - 1, 0);
trans->transid, level - 1);
BUG_ON(ret);
add_root_to_dirty_list(root);
......@@ -940,7 +939,8 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
free_extent_buffer(mid);
ret = btrfs_free_extent(trans, root, mid->start, mid->len,
mid->start, root->root_key.objectid,
btrfs_header_generation(mid), 0, 0, 1);
btrfs_header_generation(mid),
level, 1);
/* once for the root ptr */
free_extent_buffer(mid);
return ret;
......@@ -1006,7 +1006,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
wret = btrfs_free_extent(trans, root, bytenr,
blocksize, parent->start,
btrfs_header_owner(parent),
generation, 0, 0, 1);
generation, level, 1);
if (wret)
ret = wret;
} else {
......@@ -1055,7 +1055,7 @@ static noinline int balance_level(struct btrfs_trans_handle *trans,
wret = btrfs_free_extent(trans, root, bytenr, blocksize,
parent->start,
btrfs_header_owner(parent),
root_gen, 0, 0, 1);
root_gen, level, 1);
if (wret)
ret = wret;
} else {
......@@ -1691,13 +1691,13 @@ int btrfs_merge_path(struct btrfs_trans_handle *trans,
blocksize, parent->start,
btrfs_header_owner(parent),
btrfs_header_generation(parent),
level - 1, 0);
level - 1);
BUG_ON(ret);
ret = btrfs_free_extent(trans, root, bytenr,
blocksize, parent->start,
btrfs_header_owner(parent),
btrfs_header_generation(parent),
level - 1, 0, 1);
level - 1, 1);
BUG_ON(ret);
if (generation == trans->transid) {
......@@ -1973,7 +1973,7 @@ static int noinline insert_new_root(struct btrfs_trans_handle *trans,
ret = btrfs_update_extent_ref(trans, root, lower->start,
lower->start, c->start,
root->root_key.objectid,
trans->transid, level - 1, 0);
trans->transid, level - 1);
BUG_ON(ret);
/* the super has an extra ref to root->node */
......@@ -3213,7 +3213,7 @@ noinline int btrfs_del_leaf(struct btrfs_trans_handle *trans,
btrfs_level_size(root, 0),
path->nodes[1]->start,
btrfs_header_owner(path->nodes[1]),
root_gen, 0, 0, 1);
root_gen, 0, 1);
return ret;
}
/*
......
......@@ -374,7 +374,6 @@ struct btrfs_extent_ref {
__le64 root;
__le64 generation;
__le64 objectid;
__le64 offset;
__le32 num_refs;
} __attribute__ ((__packed__));
......@@ -1082,7 +1081,6 @@ static inline u8 *btrfs_dev_extent_chunk_tree_uuid(struct btrfs_dev_extent *dev)
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_offset, struct btrfs_extent_ref, offset, 64);
BTRFS_SETGET_FUNCS(ref_num_refs, struct btrfs_extent_ref, num_refs, 32);
BTRFS_SETGET_STACK_FUNCS(stack_ref_root, struct btrfs_extent_ref, root, 64);
......@@ -1090,8 +1088,6 @@ 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_offset, struct btrfs_extent_ref,
offset, 64);
BTRFS_SETGET_STACK_FUNCS(stack_ref_num_refs, struct btrfs_extent_ref,
num_refs, 32);
......@@ -1522,29 +1518,20 @@ struct extent_buffer *btrfs_alloc_free_block(struct btrfs_trans_handle *trans,
struct extent_buffer *btrfs_init_new_buffer(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 bytenr, u32 blocksize);
int btrfs_insert_extent_backref(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
struct btrfs_path *path,
u64 bytenr, u64 parent,
u64 root_objectid, u64 ref_generation,
u64 owner, u64 owner_offset);
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 owner_offset,
u64 empty_size, u64 hint_byte,
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, u64 owner_offset,
struct btrfs_key *ins);
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, u64 owner_offset,
struct btrfs_key *ins);
u64 owner, struct btrfs_key *ins);
int btrfs_reserve_extent(struct btrfs_trans_handle *trans,
struct btrfs_root *root,
u64 num_bytes, u64 min_alloc_size,
......@@ -1563,7 +1550,7 @@ 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, u64 owner_offset, int pin);
u64 owner_objectid, int pin);
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,
......@@ -1572,12 +1559,12 @@ int 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, u64 owner_offset);
u64 owner_objectid);
int btrfs_update_extent_ref(struct btrfs_trans_handle *trans,
struct btrfs_root *root, u64 bytenr,
u64 orig_parent, u64 parent,
u64 root_objectid, u64 ref_generation,
u64 owner, u64 owner_offset);
u64 owner_objectid);
int btrfs_write_dirty_block_groups(struct btrfs_trans_handle *trans,
struct btrfs_root *root);
int btrfs_free_block_groups(struct btrfs_fs_info *info);
......
This diff is collapsed.
......@@ -788,8 +788,7 @@ int noinline btrfs_drop_extents(struct btrfs_trans_handle *trans,
le64_to_cpu(old.disk_num_bytes),
leaf->start,
root->root_key.objectid,
trans->transid,
ins.objectid, ins.offset);
trans->transid, ins.objectid);
BUG_ON(ret);
}
btrfs_release_path(root, path);
......@@ -808,8 +807,7 @@ int noinline btrfs_drop_extents(struct btrfs_trans_handle *trans,
disk_bytenr,
le64_to_cpu(old.disk_num_bytes),
leaf_start, root_owner,
root_gen, key.objectid,
key.offset, 0);
root_gen, key.objectid, 0);
BUG_ON(ret);
*hint_byte = disk_bytenr;
}
......
......@@ -647,8 +647,7 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end)
ins.type = BTRFS_EXTENT_ITEM_KEY;
ret = btrfs_alloc_reserved_extent(trans, root, leaf->start,
root->root_key.objectid,
trans->transid, inode->i_ino,
ordered_extent->file_offset, &ins);
trans->transid, inode->i_ino, &ins);
BUG_ON(ret);
btrfs_release_path(root, path);
......@@ -1734,8 +1733,7 @@ noinline int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans,
ret = btrfs_free_extent(trans, root, extent_start,
extent_num_bytes,
leaf->start, root_owner,
root_gen, inode->i_ino,
found_key.offset, 0);
root_gen, inode->i_ino, 0);
BUG_ON(ret);
}
next:
......
......@@ -658,7 +658,7 @@ long btrfs_ioctl_clone(struct file *file, unsigned long src_fd)
ds, dl, leaf->start,
root->root_key.objectid,
trans->transid,
inode->i_ino, key.offset);
inode->i_ino);
BUG_ON(ret);
}
}
......
......@@ -102,11 +102,10 @@ void btrfs_print_leaf(struct btrfs_root *root, struct extent_buffer *l)
case BTRFS_EXTENT_REF_KEY:
ref = btrfs_item_ptr(l, i, struct btrfs_extent_ref);
printk("\t\textent back ref root %llu gen %llu "
"owner %llu offset %llu num_refs %lu\n",
"owner %llu num_refs %lu\n",
(unsigned long long)btrfs_ref_root(l, ref),
(unsigned long long)btrfs_ref_generation(l, ref),
(unsigned long long)btrfs_ref_objectid(l, ref),
(unsigned long long)btrfs_ref_offset(l, ref),
(unsigned long)btrfs_ref_num_refs(l, ref));
break;
......
......@@ -460,8 +460,7 @@ static noinline int overwrite_item(struct btrfs_trans_handle *trans,
ins.objectid, ins.offset,
path->nodes[0]->start,
root->root_key.objectid,
trans->transid,
key->objectid, key->offset);
trans->transid, key->objectid);
} else {
/*
* insert the extent pointer in the extent
......@@ -471,7 +470,7 @@ static noinline int overwrite_item(struct btrfs_trans_handle *trans,
path->nodes[0]->start,
root->root_key.objectid,
trans->transid, key->objectid,
key->offset, &ins);
&ins);
BUG_ON(ret);
}
}
......@@ -2534,8 +2533,7 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
dst_path->nodes[0]->start,
BTRFS_TREE_LOG_OBJECTID,
trans->transid,
ins_keys[i].objectid,
ins_keys[i].offset);
ins_keys[i].objectid);
BUG_ON(ret);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment