btrfs: Remove V0 extent support
The v0 compat code was introduced in commit 5d4f98a28c
("Btrfs: Mixed back reference (FORWARD ROLLING FORMAT CHANGE)") 9
years ago, which was merged in 2.6.31. This means that the code is
there to support filesystems which are _VERY_ old and if you are using
btrfs on such an old kernel, you have much bigger problems. This coupled
with the fact that no one is likely testing/maintining this code likely
means it has bugs lurking. All things considered I think 43 kernel
releases later it's high time this remnant of the past got removed.
This patch removes all code wrapped in #ifdefs but leaves the BUG_ONs in case
we have a v0 with no support intact as a sort of safety-net.
Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:

committed by
David Sterba

parent
4de426cd39
commit
a79865c680
@@ -867,17 +867,7 @@ search_again:
|
||||
num_refs = btrfs_extent_refs(leaf, ei);
|
||||
extent_flags = btrfs_extent_flags(leaf, ei);
|
||||
} else {
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
struct btrfs_extent_item_v0 *ei0;
|
||||
BUG_ON(item_size != sizeof(*ei0));
|
||||
ei0 = btrfs_item_ptr(leaf, path->slots[0],
|
||||
struct btrfs_extent_item_v0);
|
||||
num_refs = btrfs_extent_refs_v0(leaf, ei0);
|
||||
/* FIXME: this isn't correct for data */
|
||||
extent_flags = BTRFS_BLOCK_FLAG_FULL_BACKREF;
|
||||
#else
|
||||
BUG();
|
||||
#endif
|
||||
}
|
||||
BUG_ON(num_refs == 0);
|
||||
} else {
|
||||
@@ -1036,89 +1026,6 @@ out_free:
|
||||
* tree block info structure.
|
||||
*/
|
||||
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
static int convert_extent_item_v0(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_fs_info *fs_info,
|
||||
struct btrfs_path *path,
|
||||
u64 owner, u32 extra_size)
|
||||
{
|
||||
struct btrfs_root *root = fs_info->extent_root;
|
||||
struct btrfs_extent_item *item;
|
||||
struct btrfs_extent_item_v0 *ei0;
|
||||
struct btrfs_extent_ref_v0 *ref0;
|
||||
struct btrfs_tree_block_info *bi;
|
||||
struct extent_buffer *leaf;
|
||||
struct btrfs_key key;
|
||||
struct btrfs_key found_key;
|
||||
u32 new_size = sizeof(*item);
|
||||
u64 refs;
|
||||
int ret;
|
||||
|
||||
leaf = path->nodes[0];
|
||||
BUG_ON(btrfs_item_size_nr(leaf, path->slots[0]) != sizeof(*ei0));
|
||||
|
||||
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
|
||||
ei0 = btrfs_item_ptr(leaf, path->slots[0],
|
||||
struct btrfs_extent_item_v0);
|
||||
refs = btrfs_extent_refs_v0(leaf, ei0);
|
||||
|
||||
if (owner == (u64)-1) {
|
||||
while (1) {
|
||||
if (path->slots[0] >= btrfs_header_nritems(leaf)) {
|
||||
ret = btrfs_next_leaf(root, path);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
BUG_ON(ret > 0); /* Corruption */
|
||||
leaf = path->nodes[0];
|
||||
}
|
||||
btrfs_item_key_to_cpu(leaf, &found_key,
|
||||
path->slots[0]);
|
||||
BUG_ON(key.objectid != found_key.objectid);
|
||||
if (found_key.type != BTRFS_EXTENT_REF_V0_KEY) {
|
||||
path->slots[0]++;
|
||||
continue;
|
||||
}
|
||||
ref0 = btrfs_item_ptr(leaf, path->slots[0],
|
||||
struct btrfs_extent_ref_v0);
|
||||
owner = btrfs_ref_objectid_v0(leaf, ref0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
btrfs_release_path(path);
|
||||
|
||||
if (owner < BTRFS_FIRST_FREE_OBJECTID)
|
||||
new_size += sizeof(*bi);
|
||||
|
||||
new_size -= sizeof(*ei0);
|
||||
ret = btrfs_search_slot(trans, root, &key, path,
|
||||
new_size + extra_size, 1);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
BUG_ON(ret); /* Corruption */
|
||||
|
||||
btrfs_extend_item(fs_info, path, new_size);
|
||||
|
||||
leaf = path->nodes[0];
|
||||
item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
|
||||
btrfs_set_extent_refs(leaf, item, refs);
|
||||
/* FIXME: get real generation */
|
||||
btrfs_set_extent_generation(leaf, item, 0);
|
||||
if (owner < BTRFS_FIRST_FREE_OBJECTID) {
|
||||
btrfs_set_extent_flags(leaf, item,
|
||||
BTRFS_EXTENT_FLAG_TREE_BLOCK |
|
||||
BTRFS_BLOCK_FLAG_FULL_BACKREF);
|
||||
bi = (struct btrfs_tree_block_info *)(item + 1);
|
||||
/* FIXME: get first key of the block */
|
||||
memzero_extent_buffer(leaf, (unsigned long)bi, sizeof(*bi));
|
||||
btrfs_set_tree_block_level(leaf, bi, (int)owner);
|
||||
} else {
|
||||
btrfs_set_extent_flags(leaf, item, BTRFS_EXTENT_FLAG_DATA);
|
||||
}
|
||||
btrfs_mark_buffer_dirty(leaf);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* is_data == BTRFS_REF_TYPE_BLOCK, tree block type is required,
|
||||
* is_data == BTRFS_REF_TYPE_DATA, data type is requried,
|
||||
@@ -1247,17 +1154,6 @@ again:
|
||||
if (parent) {
|
||||
if (!ret)
|
||||
return 0;
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
key.type = BTRFS_EXTENT_REF_V0_KEY;
|
||||
btrfs_release_path(path);
|
||||
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
|
||||
if (ret < 0) {
|
||||
err = ret;
|
||||
goto fail;
|
||||
}
|
||||
if (!ret)
|
||||
return 0;
|
||||
#endif
|
||||
goto fail;
|
||||
}
|
||||
|
||||
@@ -1400,13 +1296,6 @@ static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans,
|
||||
ref2 = btrfs_item_ptr(leaf, path->slots[0],
|
||||
struct btrfs_shared_data_ref);
|
||||
num_refs = btrfs_shared_data_ref_count(leaf, ref2);
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
} else if (key.type == BTRFS_EXTENT_REF_V0_KEY) {
|
||||
struct btrfs_extent_ref_v0 *ref0;
|
||||
ref0 = btrfs_item_ptr(leaf, path->slots[0],
|
||||
struct btrfs_extent_ref_v0);
|
||||
num_refs = btrfs_ref_count_v0(leaf, ref0);
|
||||
#endif
|
||||
} else {
|
||||
BUG();
|
||||
}
|
||||
@@ -1422,14 +1311,6 @@ static noinline int remove_extent_data_ref(struct btrfs_trans_handle *trans,
|
||||
btrfs_set_extent_data_ref_count(leaf, ref1, num_refs);
|
||||
else if (key.type == BTRFS_SHARED_DATA_REF_KEY)
|
||||
btrfs_set_shared_data_ref_count(leaf, ref2, num_refs);
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
else {
|
||||
struct btrfs_extent_ref_v0 *ref0;
|
||||
ref0 = btrfs_item_ptr(leaf, path->slots[0],
|
||||
struct btrfs_extent_ref_v0);
|
||||
btrfs_set_ref_count_v0(leaf, ref0, num_refs);
|
||||
}
|
||||
#endif
|
||||
btrfs_mark_buffer_dirty(leaf);
|
||||
}
|
||||
return ret;
|
||||
@@ -1469,13 +1350,6 @@ static noinline u32 extent_data_ref_count(struct btrfs_path *path,
|
||||
ref2 = btrfs_item_ptr(leaf, path->slots[0],
|
||||
struct btrfs_shared_data_ref);
|
||||
num_refs = btrfs_shared_data_ref_count(leaf, ref2);
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
} else if (key.type == BTRFS_EXTENT_REF_V0_KEY) {
|
||||
struct btrfs_extent_ref_v0 *ref0;
|
||||
ref0 = btrfs_item_ptr(leaf, path->slots[0],
|
||||
struct btrfs_extent_ref_v0);
|
||||
num_refs = btrfs_ref_count_v0(leaf, ref0);
|
||||
#endif
|
||||
} else {
|
||||
WARN_ON(1);
|
||||
}
|
||||
@@ -1503,15 +1377,6 @@ static noinline int lookup_tree_block_ref(struct btrfs_trans_handle *trans,
|
||||
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
|
||||
if (ret > 0)
|
||||
ret = -ENOENT;
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
if (ret == -ENOENT && parent) {
|
||||
btrfs_release_path(path);
|
||||
key.type = BTRFS_EXTENT_REF_V0_KEY;
|
||||
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
|
||||
if (ret > 0)
|
||||
ret = -ENOENT;
|
||||
}
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1676,22 +1541,6 @@ again:
|
||||
|
||||
leaf = path->nodes[0];
|
||||
item_size = btrfs_item_size_nr(leaf, path->slots[0]);
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
if (item_size < sizeof(*ei)) {
|
||||
if (!insert) {
|
||||
err = -ENOENT;
|
||||
goto out;
|
||||
}
|
||||
ret = convert_extent_item_v0(trans, fs_info, path, owner,
|
||||
extra_size);
|
||||
if (ret < 0) {
|
||||
err = ret;
|
||||
goto out;
|
||||
}
|
||||
leaf = path->nodes[0];
|
||||
item_size = btrfs_item_size_nr(leaf, path->slots[0]);
|
||||
}
|
||||
#endif
|
||||
BUG_ON(item_size < sizeof(*ei));
|
||||
|
||||
ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
|
||||
@@ -2416,17 +2265,6 @@ again:
|
||||
|
||||
leaf = path->nodes[0];
|
||||
item_size = btrfs_item_size_nr(leaf, path->slots[0]);
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
if (item_size < sizeof(*ei)) {
|
||||
ret = convert_extent_item_v0(trans, fs_info, path, (u64)-1, 0);
|
||||
if (ret < 0) {
|
||||
err = ret;
|
||||
goto out;
|
||||
}
|
||||
leaf = path->nodes[0];
|
||||
item_size = btrfs_item_size_nr(leaf, path->slots[0]);
|
||||
}
|
||||
#endif
|
||||
BUG_ON(item_size < sizeof(*ei));
|
||||
ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
|
||||
__run_delayed_extent_op(extent_op, leaf, ei);
|
||||
@@ -3238,12 +3076,6 @@ static noinline int check_committed_ref(struct btrfs_root *root,
|
||||
|
||||
ret = 1;
|
||||
item_size = btrfs_item_size_nr(leaf, path->slots[0]);
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
if (item_size < sizeof(*ei)) {
|
||||
WARN_ON(item_size != sizeof(struct btrfs_extent_item_v0));
|
||||
goto out;
|
||||
}
|
||||
#endif
|
||||
ei = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
|
||||
|
||||
if (item_size != sizeof(*ei) +
|
||||
@@ -6888,11 +6720,7 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
|
||||
break;
|
||||
extent_slot--;
|
||||
}
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
item_size = btrfs_item_size_nr(path->nodes[0], extent_slot);
|
||||
if (found_extent && item_size < sizeof(*ei))
|
||||
found_extent = 0;
|
||||
#endif
|
||||
|
||||
if (!found_extent) {
|
||||
BUG_ON(iref);
|
||||
ret = remove_extent_backref(trans, path, NULL,
|
||||
@@ -6968,41 +6796,6 @@ static int __btrfs_free_extent(struct btrfs_trans_handle *trans,
|
||||
|
||||
leaf = path->nodes[0];
|
||||
item_size = btrfs_item_size_nr(leaf, extent_slot);
|
||||
#ifdef BTRFS_COMPAT_EXTENT_TREE_V0
|
||||
if (item_size < sizeof(*ei)) {
|
||||
BUG_ON(found_extent || extent_slot != path->slots[0]);
|
||||
ret = convert_extent_item_v0(trans, info, path, owner_objectid,
|
||||
0);
|
||||
if (ret < 0) {
|
||||
btrfs_abort_transaction(trans, ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
btrfs_release_path(path);
|
||||
path->leave_spinning = 1;
|
||||
|
||||
key.objectid = bytenr;
|
||||
key.type = BTRFS_EXTENT_ITEM_KEY;
|
||||
key.offset = num_bytes;
|
||||
|
||||
ret = btrfs_search_slot(trans, extent_root, &key, path,
|
||||
-1, 1);
|
||||
if (ret) {
|
||||
btrfs_err(info,
|
||||
"umm, got %d back from search, was looking for %llu",
|
||||
ret, bytenr);
|
||||
btrfs_print_leaf(path->nodes[0]);
|
||||
}
|
||||
if (ret < 0) {
|
||||
btrfs_abort_transaction(trans, ret);
|
||||
goto out;
|
||||
}
|
||||
|
||||
extent_slot = path->slots[0];
|
||||
leaf = path->nodes[0];
|
||||
item_size = btrfs_item_size_nr(leaf, extent_slot);
|
||||
}
|
||||
#endif
|
||||
BUG_ON(item_size < sizeof(*ei));
|
||||
ei = btrfs_item_ptr(leaf, extent_slot,
|
||||
struct btrfs_extent_item);
|
||||
|
Reference in New Issue
Block a user