2018-04-04 01:23:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2014-05-08 05:06:09 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Facebook. All rights reserved.
|
|
|
|
*/
|
|
|
|
|
2016-06-01 19:18:25 +08:00
|
|
|
#include <linux/types.h>
|
2014-05-08 05:06:09 +08:00
|
|
|
#include "btrfs-tests.h"
|
|
|
|
#include "../ctree.h"
|
|
|
|
#include "../transaction.h"
|
|
|
|
#include "../disk-io.h"
|
|
|
|
#include "../qgroup.h"
|
2015-04-16 17:18:36 +08:00
|
|
|
#include "../backref.h"
|
2014-05-08 05:06:09 +08:00
|
|
|
|
|
|
|
static int insert_normal_tree_ref(struct btrfs_root *root, u64 bytenr,
|
|
|
|
u64 num_bytes, u64 parent, u64 root_objectid)
|
|
|
|
{
|
|
|
|
struct btrfs_trans_handle trans;
|
|
|
|
struct btrfs_extent_item *item;
|
|
|
|
struct btrfs_extent_inline_ref *iref;
|
|
|
|
struct btrfs_tree_block_info *block_info;
|
|
|
|
struct btrfs_path *path;
|
|
|
|
struct extent_buffer *leaf;
|
|
|
|
struct btrfs_key ins;
|
|
|
|
u32 size = sizeof(*item) + sizeof(*iref) + sizeof(*block_info);
|
|
|
|
int ret;
|
|
|
|
|
2018-05-10 20:44:40 +08:00
|
|
|
btrfs_init_dummy_trans(&trans, NULL);
|
2014-05-08 05:06:09 +08:00
|
|
|
|
|
|
|
ins.objectid = bytenr;
|
|
|
|
ins.type = BTRFS_EXTENT_ITEM_KEY;
|
|
|
|
ins.offset = num_bytes;
|
|
|
|
|
|
|
|
path = btrfs_alloc_path();
|
|
|
|
if (!path) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_ROOT);
|
2014-05-08 05:06:09 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
path->leave_spinning = 1;
|
|
|
|
ret = btrfs_insert_empty_item(&trans, root, path, &ins, size);
|
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't insert ref %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
btrfs_free_path(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
leaf = path->nodes[0];
|
|
|
|
item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_extent_item);
|
|
|
|
btrfs_set_extent_refs(leaf, item, 1);
|
|
|
|
btrfs_set_extent_generation(leaf, item, 1);
|
|
|
|
btrfs_set_extent_flags(leaf, item, BTRFS_EXTENT_FLAG_TREE_BLOCK);
|
|
|
|
block_info = (struct btrfs_tree_block_info *)(item + 1);
|
2018-03-27 20:44:18 +08:00
|
|
|
btrfs_set_tree_block_level(leaf, block_info, 0);
|
2014-05-08 05:06:09 +08:00
|
|
|
iref = (struct btrfs_extent_inline_ref *)(block_info + 1);
|
|
|
|
if (parent > 0) {
|
|
|
|
btrfs_set_extent_inline_ref_type(leaf, iref,
|
|
|
|
BTRFS_SHARED_BLOCK_REF_KEY);
|
|
|
|
btrfs_set_extent_inline_ref_offset(leaf, iref, parent);
|
|
|
|
} else {
|
|
|
|
btrfs_set_extent_inline_ref_type(leaf, iref, BTRFS_TREE_BLOCK_REF_KEY);
|
|
|
|
btrfs_set_extent_inline_ref_offset(leaf, iref, root_objectid);
|
|
|
|
}
|
|
|
|
btrfs_free_path(path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int add_tree_ref(struct btrfs_root *root, u64 bytenr, u64 num_bytes,
|
|
|
|
u64 parent, u64 root_objectid)
|
|
|
|
{
|
|
|
|
struct btrfs_trans_handle trans;
|
|
|
|
struct btrfs_extent_item *item;
|
|
|
|
struct btrfs_path *path;
|
|
|
|
struct btrfs_key key;
|
|
|
|
u64 refs;
|
|
|
|
int ret;
|
|
|
|
|
2018-05-10 20:44:40 +08:00
|
|
|
btrfs_init_dummy_trans(&trans, NULL);
|
2014-05-08 05:06:09 +08:00
|
|
|
|
|
|
|
key.objectid = bytenr;
|
|
|
|
key.type = BTRFS_EXTENT_ITEM_KEY;
|
|
|
|
key.offset = num_bytes;
|
|
|
|
|
|
|
|
path = btrfs_alloc_path();
|
|
|
|
if (!path) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_ROOT);
|
2014-05-08 05:06:09 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
path->leave_spinning = 1;
|
|
|
|
ret = btrfs_search_slot(&trans, root, &key, path, 0, 1);
|
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find extent ref");
|
2014-05-08 05:06:09 +08:00
|
|
|
btrfs_free_path(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = btrfs_item_ptr(path->nodes[0], path->slots[0],
|
|
|
|
struct btrfs_extent_item);
|
|
|
|
refs = btrfs_extent_refs(path->nodes[0], item);
|
|
|
|
btrfs_set_extent_refs(path->nodes[0], item, refs + 1);
|
|
|
|
btrfs_release_path(path);
|
|
|
|
|
|
|
|
key.objectid = bytenr;
|
|
|
|
if (parent) {
|
|
|
|
key.type = BTRFS_SHARED_BLOCK_REF_KEY;
|
|
|
|
key.offset = parent;
|
|
|
|
} else {
|
|
|
|
key.type = BTRFS_TREE_BLOCK_REF_KEY;
|
|
|
|
key.offset = root_objectid;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = btrfs_insert_empty_item(&trans, root, path, &key, 0);
|
|
|
|
if (ret)
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("failed to insert backref");
|
2014-05-08 05:06:09 +08:00
|
|
|
btrfs_free_path(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int remove_extent_item(struct btrfs_root *root, u64 bytenr,
|
|
|
|
u64 num_bytes)
|
|
|
|
{
|
|
|
|
struct btrfs_trans_handle trans;
|
|
|
|
struct btrfs_key key;
|
|
|
|
struct btrfs_path *path;
|
|
|
|
int ret;
|
|
|
|
|
2018-05-10 20:44:40 +08:00
|
|
|
btrfs_init_dummy_trans(&trans, NULL);
|
2014-05-08 05:06:09 +08:00
|
|
|
|
|
|
|
key.objectid = bytenr;
|
|
|
|
key.type = BTRFS_EXTENT_ITEM_KEY;
|
|
|
|
key.offset = num_bytes;
|
|
|
|
|
|
|
|
path = btrfs_alloc_path();
|
|
|
|
if (!path) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_ROOT);
|
2014-05-08 05:06:09 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
path->leave_spinning = 1;
|
|
|
|
|
|
|
|
ret = btrfs_search_slot(&trans, root, &key, path, -1, 1);
|
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("didn't find our key %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
btrfs_free_path(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
btrfs_del_item(&trans, root, path);
|
|
|
|
btrfs_free_path(path);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int remove_extent_ref(struct btrfs_root *root, u64 bytenr,
|
|
|
|
u64 num_bytes, u64 parent, u64 root_objectid)
|
|
|
|
{
|
|
|
|
struct btrfs_trans_handle trans;
|
|
|
|
struct btrfs_extent_item *item;
|
|
|
|
struct btrfs_path *path;
|
|
|
|
struct btrfs_key key;
|
|
|
|
u64 refs;
|
|
|
|
int ret;
|
|
|
|
|
2018-05-10 20:44:40 +08:00
|
|
|
btrfs_init_dummy_trans(&trans, NULL);
|
2014-05-08 05:06:09 +08:00
|
|
|
|
|
|
|
key.objectid = bytenr;
|
|
|
|
key.type = BTRFS_EXTENT_ITEM_KEY;
|
|
|
|
key.offset = num_bytes;
|
|
|
|
|
|
|
|
path = btrfs_alloc_path();
|
|
|
|
if (!path) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_ROOT);
|
2014-05-08 05:06:09 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
path->leave_spinning = 1;
|
|
|
|
ret = btrfs_search_slot(&trans, root, &key, path, 0, 1);
|
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find extent ref");
|
2014-05-08 05:06:09 +08:00
|
|
|
btrfs_free_path(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
item = btrfs_item_ptr(path->nodes[0], path->slots[0],
|
|
|
|
struct btrfs_extent_item);
|
|
|
|
refs = btrfs_extent_refs(path->nodes[0], item);
|
|
|
|
btrfs_set_extent_refs(path->nodes[0], item, refs - 1);
|
|
|
|
btrfs_release_path(path);
|
|
|
|
|
|
|
|
key.objectid = bytenr;
|
|
|
|
if (parent) {
|
|
|
|
key.type = BTRFS_SHARED_BLOCK_REF_KEY;
|
|
|
|
key.offset = parent;
|
|
|
|
} else {
|
|
|
|
key.type = BTRFS_TREE_BLOCK_REF_KEY;
|
|
|
|
key.offset = root_objectid;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = btrfs_search_slot(&trans, root, &key, path, -1, 1);
|
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find backref %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
btrfs_free_path(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
btrfs_del_item(&trans, root, path);
|
|
|
|
btrfs_free_path(path);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:25 +08:00
|
|
|
static int test_no_shared_qgroup(struct btrfs_root *root,
|
|
|
|
u32 sectorsize, u32 nodesize)
|
2014-05-08 05:06:09 +08:00
|
|
|
{
|
|
|
|
struct btrfs_trans_handle trans;
|
|
|
|
struct btrfs_fs_info *fs_info = root->fs_info;
|
2015-04-16 17:18:36 +08:00
|
|
|
struct ulist *old_roots = NULL;
|
|
|
|
struct ulist *new_roots = NULL;
|
2014-05-08 05:06:09 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-05-10 20:44:40 +08:00
|
|
|
btrfs_init_dummy_trans(&trans, fs_info);
|
2014-05-08 05:06:09 +08:00
|
|
|
|
2018-05-17 06:00:44 +08:00
|
|
|
test_msg("qgroup basic add");
|
2018-07-18 14:45:33 +08:00
|
|
|
ret = btrfs_create_qgroup(&trans, BTRFS_FS_TREE_OBJECTID);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't create a qgroup %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-04-16 17:18:36 +08:00
|
|
|
/*
|
2016-05-20 09:18:45 +08:00
|
|
|
* Since the test trans doesn't have the complicated delayed refs,
|
2015-04-16 17:18:36 +08:00
|
|
|
* we can only call btrfs_qgroup_account_extent() directly to test
|
|
|
|
* quota.
|
|
|
|
*/
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
|
|
|
|
false);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2015-04-16 17:18:36 +08:00
|
|
|
ulist_free(old_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
ret = insert_normal_tree_ref(root, nodesize, nodesize, 0,
|
|
|
|
BTRFS_FS_TREE_OBJECTID);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
|
|
|
|
false);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2015-04-16 17:18:36 +08:00
|
|
|
ulist_free(old_roots);
|
|
|
|
ulist_free(new_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2015-04-16 17:18:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-18 14:45:39 +08:00
|
|
|
ret = btrfs_qgroup_account_extent(&trans, nodesize, nodesize, old_roots,
|
|
|
|
new_roots);
|
2015-04-16 17:18:36 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't account space for a qgroup %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID,
|
|
|
|
nodesize, nodesize)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("qgroup counts didn't match expected values");
|
2014-05-08 05:06:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
2015-04-16 17:18:36 +08:00
|
|
|
old_roots = NULL;
|
|
|
|
new_roots = NULL;
|
|
|
|
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
|
|
|
|
false);
|
2015-04-16 17:18:36 +08:00
|
|
|
if (ret) {
|
|
|
|
ulist_free(old_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2015-04-16 17:18:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
2014-05-08 05:06:09 +08:00
|
|
|
|
2016-06-01 19:18:25 +08:00
|
|
|
ret = remove_extent_item(root, nodesize, nodesize);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret)
|
|
|
|
return -EINVAL;
|
|
|
|
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
|
|
|
|
false);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2015-04-16 17:18:36 +08:00
|
|
|
ulist_free(old_roots);
|
|
|
|
ulist_free(new_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2015-04-16 17:18:36 +08:00
|
|
|
return ret;
|
2014-05-08 05:06:09 +08:00
|
|
|
}
|
|
|
|
|
2018-07-18 14:45:39 +08:00
|
|
|
ret = btrfs_qgroup_account_extent(&trans, nodesize, nodesize, old_roots,
|
|
|
|
new_roots);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't account space for a qgroup %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID, 0, 0)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("qgroup counts didn't match expected values");
|
2014-05-08 05:06:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Add a ref for two different roots to make sure the shared value comes out
|
|
|
|
* right, also remove one of the roots and make sure the exclusive count is
|
|
|
|
* adjusted properly.
|
|
|
|
*/
|
2016-06-01 19:18:25 +08:00
|
|
|
static int test_multiple_refs(struct btrfs_root *root,
|
|
|
|
u32 sectorsize, u32 nodesize)
|
2014-05-08 05:06:09 +08:00
|
|
|
{
|
|
|
|
struct btrfs_trans_handle trans;
|
|
|
|
struct btrfs_fs_info *fs_info = root->fs_info;
|
2015-04-16 17:18:36 +08:00
|
|
|
struct ulist *old_roots = NULL;
|
|
|
|
struct ulist *new_roots = NULL;
|
2014-05-08 05:06:09 +08:00
|
|
|
int ret;
|
|
|
|
|
2018-05-10 20:44:40 +08:00
|
|
|
btrfs_init_dummy_trans(&trans, fs_info);
|
2014-05-08 05:06:09 +08:00
|
|
|
|
2018-05-17 06:00:44 +08:00
|
|
|
test_msg("qgroup multiple refs test");
|
2014-05-08 05:06:09 +08:00
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
/*
|
|
|
|
* We have BTRFS_FS_TREE_OBJECTID created already from the
|
|
|
|
* previous test.
|
|
|
|
*/
|
2018-07-18 14:45:33 +08:00
|
|
|
ret = btrfs_create_qgroup(&trans, BTRFS_FIRST_FREE_OBJECTID);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't create a qgroup %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
|
|
|
|
false);
|
2015-04-16 17:18:36 +08:00
|
|
|
if (ret) {
|
|
|
|
ulist_free(old_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2015-04-16 17:18:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
ret = insert_normal_tree_ref(root, nodesize, nodesize, 0,
|
|
|
|
BTRFS_FS_TREE_OBJECTID);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
|
|
|
|
false);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2015-04-16 17:18:36 +08:00
|
|
|
ulist_free(old_roots);
|
|
|
|
ulist_free(new_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-18 14:45:39 +08:00
|
|
|
ret = btrfs_qgroup_account_extent(&trans, nodesize, nodesize, old_roots,
|
|
|
|
new_roots);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't account space for a qgroup %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID,
|
2016-06-01 19:18:25 +08:00
|
|
|
nodesize, nodesize)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("qgroup counts didn't match expected values");
|
2014-05-08 05:06:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
|
|
|
|
false);
|
2015-04-16 17:18:36 +08:00
|
|
|
if (ret) {
|
|
|
|
ulist_free(old_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2015-04-16 17:18:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
ret = add_tree_ref(root, nodesize, nodesize, 0,
|
|
|
|
BTRFS_FIRST_FREE_OBJECTID);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
|
|
|
|
false);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2015-04-16 17:18:36 +08:00
|
|
|
ulist_free(old_roots);
|
|
|
|
ulist_free(new_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-18 14:45:39 +08:00
|
|
|
ret = btrfs_qgroup_account_extent(&trans, nodesize, nodesize, old_roots,
|
|
|
|
new_roots);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't account space for a qgroup %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID,
|
|
|
|
nodesize, 0)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("qgroup counts didn't match expected values");
|
2014-05-08 05:06:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FIRST_FREE_OBJECTID,
|
|
|
|
nodesize, 0)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("qgroup counts didn't match expected values");
|
2014-05-08 05:06:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &old_roots,
|
|
|
|
false);
|
2015-04-16 17:18:36 +08:00
|
|
|
if (ret) {
|
|
|
|
ulist_free(old_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2015-04-16 17:18:36 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
ret = remove_extent_ref(root, nodesize, nodesize, 0,
|
|
|
|
BTRFS_FIRST_FREE_OBJECTID);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
btrfs: add a flag to iterate_inodes_from_logical to find all extent refs for uncompressed extents
The LOGICAL_INO ioctl provides a backward mapping from extent bytenr and
offset (encoded as a single logical address) to a list of extent refs.
LOGICAL_INO complements TREE_SEARCH, which provides the forward mapping
(extent ref -> extent bytenr and offset, or logical address). These are
useful capabilities for programs that manipulate extents and extent
references from userspace (e.g. dedup and defrag utilities).
When the extents are uncompressed (and not encrypted and not other),
check_extent_in_eb performs filtering of the extent refs to remove any
extent refs which do not contain the same extent offset as the 'logical'
parameter's extent offset. This prevents LOGICAL_INO from returning
references to more than a single block.
To find the set of extent references to an uncompressed extent from [a, b),
userspace has to run a loop like this pseudocode:
for (i = a; i < b; ++i)
extent_ref_set += LOGICAL_INO(i);
At each iteration of the loop (up to 32768 iterations for a 128M extent),
data we are interested in is collected in the kernel, then deleted by
the filter in check_extent_in_eb.
When the extents are compressed (or encrypted or other), the 'logical'
parameter must be an extent bytenr (the 'a' parameter in the loop).
No filtering by extent offset is done (or possible?) so the result is
the complete set of extent refs for the entire extent. This removes
the need for the loop, since we get all the extent refs in one call.
Add an 'ignore_offset' argument to iterate_inodes_from_logical,
[...several levels of function call graph...], and check_extent_in_eb, so
that we can disable the extent offset filtering for uncompressed extents.
This flag can be set by an improved version of the LOGICAL_INO ioctl to
get either behavior as desired.
There is no functional change in this patch. The new flag is always
false.
Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org>
Reviewed-by: David Sterba <dsterba@suse.com>
[ minor coding style fixes ]
Signed-off-by: David Sterba <dsterba@suse.com>
2017-09-23 01:58:45 +08:00
|
|
|
ret = btrfs_find_all_roots(&trans, fs_info, nodesize, 0, &new_roots,
|
|
|
|
false);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2015-04-16 17:18:36 +08:00
|
|
|
ulist_free(old_roots);
|
|
|
|
ulist_free(new_roots);
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't find old roots: %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-18 14:45:39 +08:00
|
|
|
ret = btrfs_qgroup_account_extent(&trans, nodesize, nodesize, old_roots,
|
|
|
|
new_roots);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't account space for a qgroup %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FIRST_FREE_OBJECTID,
|
|
|
|
0, 0)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("qgroup counts didn't match expected values");
|
2014-05-08 05:06:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
if (btrfs_verify_qgroup_counts(fs_info, BTRFS_FS_TREE_OBJECTID,
|
|
|
|
nodesize, nodesize)) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("qgroup counts didn't match expected values");
|
2014-05-08 05:06:09 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:25 +08:00
|
|
|
int btrfs_test_qgroups(u32 sectorsize, u32 nodesize)
|
2014-05-08 05:06:09 +08:00
|
|
|
{
|
2016-06-21 02:14:09 +08:00
|
|
|
struct btrfs_fs_info *fs_info = NULL;
|
2014-05-08 05:06:09 +08:00
|
|
|
struct btrfs_root *root;
|
|
|
|
struct btrfs_root *tmp_root;
|
|
|
|
int ret = 0;
|
|
|
|
|
2016-06-15 21:22:56 +08:00
|
|
|
fs_info = btrfs_alloc_dummy_fs_info(nodesize, sectorsize);
|
2016-06-21 02:14:09 +08:00
|
|
|
if (!fs_info) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_FS_INFO);
|
2016-06-21 02:14:09 +08:00
|
|
|
return -ENOMEM;
|
2014-05-08 05:06:09 +08:00
|
|
|
}
|
|
|
|
|
2016-06-15 21:22:56 +08:00
|
|
|
root = btrfs_alloc_dummy_root(fs_info);
|
2016-06-21 02:14:09 +08:00
|
|
|
if (IS_ERR(root)) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_ROOT);
|
2016-06-21 02:14:09 +08:00
|
|
|
ret = PTR_ERR(root);
|
2014-05-08 05:06:09 +08:00
|
|
|
goto out;
|
|
|
|
}
|
2016-06-21 02:14:09 +08:00
|
|
|
|
2014-06-15 09:20:26 +08:00
|
|
|
/* We are using this root as our extent root */
|
|
|
|
root->fs_info->extent_root = root;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some of the paths we test assume we have a filled out fs_info, so we
|
|
|
|
* just need to add the root in there so we don't panic.
|
|
|
|
*/
|
|
|
|
root->fs_info->tree_root = root;
|
|
|
|
root->fs_info->quota_root = root;
|
2016-09-03 03:40:02 +08:00
|
|
|
set_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags);
|
2014-05-08 05:06:09 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Can't use bytenr 0, some things freak out
|
|
|
|
* *cough*backref walking code*cough*
|
|
|
|
*/
|
2016-06-15 21:22:56 +08:00
|
|
|
root->node = alloc_test_extent_buffer(root->fs_info, nodesize);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (!root->node) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't allocate dummy buffer");
|
2014-05-08 05:06:09 +08:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto out;
|
|
|
|
}
|
2014-06-12 09:47:37 +08:00
|
|
|
btrfs_set_header_level(root->node, 0);
|
|
|
|
btrfs_set_header_nritems(root->node, 0);
|
2016-06-01 19:18:25 +08:00
|
|
|
root->alloc_bytenr += 2 * nodesize;
|
2014-05-08 05:06:09 +08:00
|
|
|
|
2016-06-15 21:22:56 +08:00
|
|
|
tmp_root = btrfs_alloc_dummy_root(fs_info);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (IS_ERR(tmp_root)) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_ROOT);
|
2014-05-08 05:06:09 +08:00
|
|
|
ret = PTR_ERR(tmp_root);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
tmp_root->root_key.objectid = BTRFS_FS_TREE_OBJECTID;
|
2014-05-08 05:06:09 +08:00
|
|
|
root->fs_info->fs_root = tmp_root;
|
|
|
|
ret = btrfs_insert_fs_root(root->fs_info, tmp_root);
|
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't insert fs root %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-06-15 21:22:56 +08:00
|
|
|
tmp_root = btrfs_alloc_dummy_root(fs_info);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (IS_ERR(tmp_root)) {
|
2019-03-16 00:28:46 +08:00
|
|
|
test_std_err(TEST_ALLOC_ROOT);
|
2014-05-08 05:06:09 +08:00
|
|
|
ret = PTR_ERR(tmp_root);
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2016-06-01 19:18:28 +08:00
|
|
|
tmp_root->root_key.objectid = BTRFS_FIRST_FREE_OBJECTID;
|
2014-05-08 05:06:09 +08:00
|
|
|
ret = btrfs_insert_fs_root(root->fs_info, tmp_root);
|
|
|
|
if (ret) {
|
2018-05-17 06:00:42 +08:00
|
|
|
test_err("couldn't insert fs root %d", ret);
|
2014-05-08 05:06:09 +08:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2018-05-17 06:00:44 +08:00
|
|
|
test_msg("running qgroup tests");
|
2016-06-01 19:18:25 +08:00
|
|
|
ret = test_no_shared_qgroup(root, sectorsize, nodesize);
|
2014-05-08 05:06:09 +08:00
|
|
|
if (ret)
|
|
|
|
goto out;
|
2016-06-01 19:18:25 +08:00
|
|
|
ret = test_multiple_refs(root, sectorsize, nodesize);
|
2014-05-08 05:06:09 +08:00
|
|
|
out:
|
|
|
|
btrfs_free_dummy_root(root);
|
2016-06-21 02:14:09 +08:00
|
|
|
btrfs_free_dummy_fs_info(fs_info);
|
2014-05-08 05:06:09 +08:00
|
|
|
return ret;
|
|
|
|
}
|