mirror of https://github.com/torvalds/linux.git
btrfs: more trivial BTRFS_PATH_AUTO_FREE conversions
Convert more of the trivial pattern for the auto freeing of btrfs_path with goto -> return conversions where applicable. Signed-off-by: Sun YangKai <sunk67188@gmail.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
a1359d06d7
commit
7fc35cc559
|
|
@ -27,32 +27,26 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid,
|
||||||
u8 type, u64 subid)
|
u8 type, u64 subid)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_path *path = NULL;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct extent_buffer *eb;
|
struct extent_buffer *eb;
|
||||||
int slot;
|
int slot;
|
||||||
u32 item_size;
|
u32 item_size;
|
||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
|
|
||||||
if (WARN_ON_ONCE(!uuid_root)) {
|
if (WARN_ON_ONCE(!uuid_root))
|
||||||
ret = -ENOENT;
|
return -ENOENT;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
if (!path) {
|
if (!path)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
btrfs_uuid_to_key(uuid, type, &key);
|
btrfs_uuid_to_key(uuid, type, &key);
|
||||||
ret = btrfs_search_slot(NULL, uuid_root, &key, path, 0, 0);
|
ret = btrfs_search_slot(NULL, uuid_root, &key, path, 0, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
} else if (ret > 0) {
|
if (ret > 0)
|
||||||
ret = -ENOENT;
|
return -ENOENT;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
eb = path->nodes[0];
|
eb = path->nodes[0];
|
||||||
slot = path->slots[0];
|
slot = path->slots[0];
|
||||||
|
|
@ -64,7 +58,7 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid,
|
||||||
btrfs_warn(uuid_root->fs_info,
|
btrfs_warn(uuid_root->fs_info,
|
||||||
"uuid item with illegal size %lu!",
|
"uuid item with illegal size %lu!",
|
||||||
(unsigned long)item_size);
|
(unsigned long)item_size);
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
while (item_size) {
|
while (item_size) {
|
||||||
__le64 data;
|
__le64 data;
|
||||||
|
|
@ -78,8 +72,6 @@ static int btrfs_uuid_tree_lookup(struct btrfs_root *uuid_root, const u8 *uuid,
|
||||||
item_size -= sizeof(data);
|
item_size -= sizeof(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,7 +81,7 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typ
|
||||||
struct btrfs_fs_info *fs_info = trans->fs_info;
|
struct btrfs_fs_info *fs_info = trans->fs_info;
|
||||||
struct btrfs_root *uuid_root = fs_info->uuid_root;
|
struct btrfs_root *uuid_root = fs_info->uuid_root;
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_path *path = NULL;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct extent_buffer *eb;
|
struct extent_buffer *eb;
|
||||||
int slot;
|
int slot;
|
||||||
|
|
@ -100,18 +92,14 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typ
|
||||||
if (ret != -ENOENT)
|
if (ret != -ENOENT)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
if (WARN_ON_ONCE(!uuid_root)) {
|
if (WARN_ON_ONCE(!uuid_root))
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
btrfs_uuid_to_key(uuid, type, &key);
|
btrfs_uuid_to_key(uuid, type, &key);
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
if (!path) {
|
if (!path)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = btrfs_insert_empty_item(trans, uuid_root, path, &key,
|
ret = btrfs_insert_empty_item(trans, uuid_root, path, &key,
|
||||||
sizeof(subid_le));
|
sizeof(subid_le));
|
||||||
|
|
@ -134,15 +122,12 @@ int btrfs_uuid_tree_add(struct btrfs_trans_handle *trans, const u8 *uuid, u8 typ
|
||||||
btrfs_warn(fs_info,
|
btrfs_warn(fs_info,
|
||||||
"insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!",
|
"insert uuid item failed %d (0x%016llx, 0x%016llx) type %u!",
|
||||||
ret, key.objectid, key.offset, type);
|
ret, key.objectid, key.offset, type);
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
subid_le = cpu_to_le64(subid_cpu);
|
subid_le = cpu_to_le64(subid_cpu);
|
||||||
write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
|
write_extent_buffer(eb, &subid_le, offset, sizeof(subid_le));
|
||||||
out:
|
return 0;
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8 type,
|
int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8 type,
|
||||||
|
|
@ -151,7 +136,7 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
|
||||||
struct btrfs_fs_info *fs_info = trans->fs_info;
|
struct btrfs_fs_info *fs_info = trans->fs_info;
|
||||||
struct btrfs_root *uuid_root = fs_info->uuid_root;
|
struct btrfs_root *uuid_root = fs_info->uuid_root;
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_path *path = NULL;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct extent_buffer *eb;
|
struct extent_buffer *eb;
|
||||||
int slot;
|
int slot;
|
||||||
|
|
@ -161,29 +146,23 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
|
||||||
unsigned long move_src;
|
unsigned long move_src;
|
||||||
unsigned long move_len;
|
unsigned long move_len;
|
||||||
|
|
||||||
if (WARN_ON_ONCE(!uuid_root)) {
|
if (WARN_ON_ONCE(!uuid_root))
|
||||||
ret = -EINVAL;
|
return -EINVAL;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
btrfs_uuid_to_key(uuid, type, &key);
|
btrfs_uuid_to_key(uuid, type, &key);
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
if (!path) {
|
if (!path)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = btrfs_search_slot(trans, uuid_root, &key, path, -1, 1);
|
ret = btrfs_search_slot(trans, uuid_root, &key, path, -1, 1);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
btrfs_warn(fs_info, "error %d while searching for uuid item!",
|
btrfs_warn(fs_info, "error %d while searching for uuid item!",
|
||||||
ret);
|
ret);
|
||||||
goto out;
|
return ret;
|
||||||
}
|
|
||||||
if (ret > 0) {
|
|
||||||
ret = -ENOENT;
|
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
if (ret > 0)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
eb = path->nodes[0];
|
eb = path->nodes[0];
|
||||||
slot = path->slots[0];
|
slot = path->slots[0];
|
||||||
|
|
@ -192,8 +171,7 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
|
||||||
if (!IS_ALIGNED(item_size, sizeof(u64))) {
|
if (!IS_ALIGNED(item_size, sizeof(u64))) {
|
||||||
btrfs_warn(fs_info, "uuid item with illegal size %lu!",
|
btrfs_warn(fs_info, "uuid item with illegal size %lu!",
|
||||||
(unsigned long)item_size);
|
(unsigned long)item_size);
|
||||||
ret = -ENOENT;
|
return -ENOENT;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
while (item_size) {
|
while (item_size) {
|
||||||
__le64 read_subid;
|
__le64 read_subid;
|
||||||
|
|
@ -205,16 +183,12 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
|
||||||
item_size -= sizeof(read_subid);
|
item_size -= sizeof(read_subid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!item_size) {
|
if (!item_size)
|
||||||
ret = -ENOENT;
|
return -ENOENT;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
item_size = btrfs_item_size(eb, slot);
|
item_size = btrfs_item_size(eb, slot);
|
||||||
if (item_size == sizeof(subid)) {
|
if (item_size == sizeof(subid))
|
||||||
ret = btrfs_del_item(trans, uuid_root, path);
|
return btrfs_del_item(trans, uuid_root, path);
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
move_dst = offset;
|
move_dst = offset;
|
||||||
move_src = offset + sizeof(subid);
|
move_src = offset + sizeof(subid);
|
||||||
|
|
@ -222,9 +196,7 @@ int btrfs_uuid_tree_remove(struct btrfs_trans_handle *trans, const u8 *uuid, u8
|
||||||
memmove_extent_buffer(eb, move_dst, move_src, move_len);
|
memmove_extent_buffer(eb, move_dst, move_src, move_len);
|
||||||
btrfs_truncate_item(trans, path, item_size - sizeof(subid), 1);
|
btrfs_truncate_item(trans, path, item_size - sizeof(subid), 1);
|
||||||
|
|
||||||
out:
|
return 0;
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int btrfs_uuid_iter_rem(struct btrfs_root *uuid_root, u8 *uuid, u8 type,
|
static int btrfs_uuid_iter_rem(struct btrfs_root *uuid_root, u8 *uuid, u8 type,
|
||||||
|
|
@ -293,7 +265,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
|
||||||
{
|
{
|
||||||
struct btrfs_root *root = fs_info->uuid_root;
|
struct btrfs_root *root = fs_info->uuid_root;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
int slot;
|
int slot;
|
||||||
|
|
@ -301,10 +273,8 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
|
||||||
unsigned long offset;
|
unsigned long offset;
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
if (!path) {
|
if (!path)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
key.objectid = 0;
|
key.objectid = 0;
|
||||||
key.type = 0;
|
key.type = 0;
|
||||||
|
|
@ -312,17 +282,15 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
|
||||||
|
|
||||||
again_search_slot:
|
again_search_slot:
|
||||||
ret = btrfs_search_forward(root, &key, path, BTRFS_OLDEST_GENERATION);
|
ret = btrfs_search_forward(root, &key, path, BTRFS_OLDEST_GENERATION);
|
||||||
if (ret) {
|
if (ret < 0)
|
||||||
|
return ret;
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
ret = 0;
|
return 0;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (btrfs_fs_closing(fs_info)) {
|
if (btrfs_fs_closing(fs_info))
|
||||||
ret = -EINTR;
|
return -EINTR;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
cond_resched();
|
cond_resched();
|
||||||
leaf = path->nodes[0];
|
leaf = path->nodes[0];
|
||||||
slot = path->slots[0];
|
slot = path->slots[0];
|
||||||
|
|
@ -353,7 +321,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
|
||||||
ret = btrfs_check_uuid_tree_entry(fs_info, uuid,
|
ret = btrfs_check_uuid_tree_entry(fs_info, uuid,
|
||||||
key.type, subid_cpu);
|
key.type, subid_cpu);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
btrfs_release_path(path);
|
btrfs_release_path(path);
|
||||||
ret = btrfs_uuid_iter_rem(root, uuid, key.type,
|
ret = btrfs_uuid_iter_rem(root, uuid, key.type,
|
||||||
|
|
@ -369,7 +337,7 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
|
||||||
goto again_search_slot;
|
goto again_search_slot;
|
||||||
}
|
}
|
||||||
if (ret < 0 && ret != -ENOENT)
|
if (ret < 0 && ret != -ENOENT)
|
||||||
goto out;
|
return ret;
|
||||||
key.offset++;
|
key.offset++;
|
||||||
goto again_search_slot;
|
goto again_search_slot;
|
||||||
}
|
}
|
||||||
|
|
@ -386,8 +354,6 @@ int btrfs_uuid_tree_iterate(struct btrfs_fs_info *fs_info)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,7 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type)
|
||||||
{
|
{
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
struct btrfs_root *root = inode->root;
|
struct btrfs_root *root = inode->root;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -121,10 +121,8 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type)
|
||||||
while (1) {
|
while (1) {
|
||||||
/* 1 for the item being dropped */
|
/* 1 for the item being dropped */
|
||||||
trans = btrfs_start_transaction(root, 1);
|
trans = btrfs_start_transaction(root, 1);
|
||||||
if (IS_ERR(trans)) {
|
if (IS_ERR(trans))
|
||||||
ret = PTR_ERR(trans);
|
return PTR_ERR(trans);
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Walk backwards through all the items until we find one that
|
* Walk backwards through all the items until we find one that
|
||||||
|
|
@ -143,7 +141,7 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type)
|
||||||
path->slots[0]--;
|
path->slots[0]--;
|
||||||
} else if (ret < 0) {
|
} else if (ret < 0) {
|
||||||
btrfs_end_transaction(trans);
|
btrfs_end_transaction(trans);
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
|
btrfs_item_key_to_cpu(path->nodes[0], &key, path->slots[0]);
|
||||||
|
|
@ -161,17 +159,14 @@ static int drop_verity_items(struct btrfs_inode *inode, u8 key_type)
|
||||||
ret = btrfs_del_items(trans, root, path, path->slots[0], 1);
|
ret = btrfs_del_items(trans, root, path, path->slots[0], 1);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
btrfs_end_transaction(trans);
|
btrfs_end_transaction(trans);
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
count++;
|
count++;
|
||||||
btrfs_release_path(path);
|
btrfs_release_path(path);
|
||||||
btrfs_end_transaction(trans);
|
btrfs_end_transaction(trans);
|
||||||
}
|
}
|
||||||
ret = count;
|
|
||||||
btrfs_end_transaction(trans);
|
btrfs_end_transaction(trans);
|
||||||
out:
|
return count;
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -217,7 +212,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
|
||||||
const char *src, u64 len)
|
const char *src, u64 len)
|
||||||
{
|
{
|
||||||
struct btrfs_trans_handle *trans;
|
struct btrfs_trans_handle *trans;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_root *root = inode->root;
|
struct btrfs_root *root = inode->root;
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
|
|
@ -233,10 +228,8 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
|
||||||
while (len > 0) {
|
while (len > 0) {
|
||||||
/* 1 for the new item being inserted */
|
/* 1 for the new item being inserted */
|
||||||
trans = btrfs_start_transaction(root, 1);
|
trans = btrfs_start_transaction(root, 1);
|
||||||
if (IS_ERR(trans)) {
|
if (IS_ERR(trans))
|
||||||
ret = PTR_ERR(trans);
|
return PTR_ERR(trans);
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
key.objectid = btrfs_ino(inode);
|
key.objectid = btrfs_ino(inode);
|
||||||
key.type = key_type;
|
key.type = key_type;
|
||||||
|
|
@ -267,7 +260,6 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
|
||||||
btrfs_end_transaction(trans);
|
btrfs_end_transaction(trans);
|
||||||
}
|
}
|
||||||
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -296,7 +288,7 @@ static int write_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
|
||||||
static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
|
static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
|
||||||
char *dest, u64 len, struct folio *dest_folio)
|
char *dest, u64 len, struct folio *dest_folio)
|
||||||
{
|
{
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_root *root = inode->root;
|
struct btrfs_root *root = inode->root;
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
|
|
@ -404,7 +396,6 @@ static int read_key_bytes(struct btrfs_inode *inode, u8 key_type, u64 offset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
btrfs_free_path(path);
|
|
||||||
if (!ret)
|
if (!ret)
|
||||||
ret = copied;
|
ret = copied;
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
||||||
|
|
@ -1681,7 +1681,7 @@ static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
|
||||||
struct btrfs_root *root = fs_info->dev_root;
|
struct btrfs_root *root = fs_info->dev_root;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct btrfs_dev_extent *dev_extent;
|
struct btrfs_dev_extent *dev_extent;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
u64 search_start;
|
u64 search_start;
|
||||||
u64 hole_size;
|
u64 hole_size;
|
||||||
u64 max_hole_start;
|
u64 max_hole_start;
|
||||||
|
|
@ -1812,7 +1812,6 @@ static int find_free_dev_extent(struct btrfs_device *device, u64 num_bytes,
|
||||||
"max_hole_start=%llu max_hole_size=%llu search_end=%llu",
|
"max_hole_start=%llu max_hole_size=%llu search_end=%llu",
|
||||||
max_hole_start, max_hole_size, search_end);
|
max_hole_start, max_hole_size, search_end);
|
||||||
out:
|
out:
|
||||||
btrfs_free_path(path);
|
|
||||||
*start = max_hole_start;
|
*start = max_hole_start;
|
||||||
if (len)
|
if (len)
|
||||||
*len = max_hole_size;
|
*len = max_hole_size;
|
||||||
|
|
@ -1826,7 +1825,7 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_fs_info *fs_info = device->fs_info;
|
struct btrfs_fs_info *fs_info = device->fs_info;
|
||||||
struct btrfs_root *root = fs_info->dev_root;
|
struct btrfs_root *root = fs_info->dev_root;
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct btrfs_key found_key;
|
struct btrfs_key found_key;
|
||||||
struct extent_buffer *leaf = NULL;
|
struct extent_buffer *leaf = NULL;
|
||||||
|
|
@ -1845,7 +1844,7 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
|
||||||
ret = btrfs_previous_item(root, path, key.objectid,
|
ret = btrfs_previous_item(root, path, key.objectid,
|
||||||
BTRFS_DEV_EXTENT_KEY);
|
BTRFS_DEV_EXTENT_KEY);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
return ret;
|
||||||
leaf = path->nodes[0];
|
leaf = path->nodes[0];
|
||||||
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
|
btrfs_item_key_to_cpu(leaf, &found_key, path->slots[0]);
|
||||||
extent = btrfs_item_ptr(leaf, path->slots[0],
|
extent = btrfs_item_ptr(leaf, path->slots[0],
|
||||||
|
|
@ -1860,7 +1859,7 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
|
||||||
extent = btrfs_item_ptr(leaf, path->slots[0],
|
extent = btrfs_item_ptr(leaf, path->slots[0],
|
||||||
struct btrfs_dev_extent);
|
struct btrfs_dev_extent);
|
||||||
} else {
|
} else {
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
*dev_extent_len = btrfs_dev_extent_length(leaf, extent);
|
*dev_extent_len = btrfs_dev_extent_length(leaf, extent);
|
||||||
|
|
@ -1868,8 +1867,6 @@ static int btrfs_free_dev_extent(struct btrfs_trans_handle *trans,
|
||||||
ret = btrfs_del_item(trans, root, path);
|
ret = btrfs_del_item(trans, root, path);
|
||||||
if (ret == 0)
|
if (ret == 0)
|
||||||
set_bit(BTRFS_TRANS_HAVE_FREE_BGS, &trans->transaction->flags);
|
set_bit(BTRFS_TRANS_HAVE_FREE_BGS, &trans->transaction->flags);
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1897,7 +1894,7 @@ static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct btrfs_key found_key;
|
struct btrfs_key found_key;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
if (!path)
|
if (!path)
|
||||||
|
|
@ -1909,13 +1906,12 @@ static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
|
||||||
|
|
||||||
ret = btrfs_search_slot(NULL, fs_info->chunk_root, &key, path, 0, 0);
|
ret = btrfs_search_slot(NULL, fs_info->chunk_root, &key, path, 0, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
|
|
||||||
if (unlikely(ret == 0)) {
|
if (unlikely(ret == 0)) {
|
||||||
/* Corruption */
|
/* Corruption */
|
||||||
btrfs_err(fs_info, "corrupted chunk tree devid -1 matched");
|
btrfs_err(fs_info, "corrupted chunk tree devid -1 matched");
|
||||||
ret = -EUCLEAN;
|
return -EUCLEAN;
|
||||||
goto error;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = btrfs_previous_item(fs_info->chunk_root, path,
|
ret = btrfs_previous_item(fs_info->chunk_root, path,
|
||||||
|
|
@ -1928,10 +1924,7 @@ static noinline int find_next_devid(struct btrfs_fs_info *fs_info,
|
||||||
path->slots[0]);
|
path->slots[0]);
|
||||||
*devid_ret = found_key.offset + 1;
|
*devid_ret = found_key.offset + 1;
|
||||||
}
|
}
|
||||||
ret = 0;
|
return 0;
|
||||||
error:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -1942,7 +1935,7 @@ static int btrfs_add_dev_item(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_device *device)
|
struct btrfs_device *device)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_dev_item *dev_item;
|
struct btrfs_dev_item *dev_item;
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
|
|
@ -1961,7 +1954,7 @@ static int btrfs_add_dev_item(struct btrfs_trans_handle *trans,
|
||||||
&key, sizeof(*dev_item));
|
&key, sizeof(*dev_item));
|
||||||
btrfs_trans_release_chunk_metadata(trans);
|
btrfs_trans_release_chunk_metadata(trans);
|
||||||
if (ret)
|
if (ret)
|
||||||
goto out;
|
return ret;
|
||||||
|
|
||||||
leaf = path->nodes[0];
|
leaf = path->nodes[0];
|
||||||
dev_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_item);
|
dev_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_item);
|
||||||
|
|
@ -1987,10 +1980,7 @@ static int btrfs_add_dev_item(struct btrfs_trans_handle *trans,
|
||||||
write_extent_buffer(leaf, trans->fs_info->fs_devices->metadata_uuid,
|
write_extent_buffer(leaf, trans->fs_info->fs_devices->metadata_uuid,
|
||||||
ptr, BTRFS_FSID_SIZE);
|
ptr, BTRFS_FSID_SIZE);
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -2017,7 +2007,7 @@ static int btrfs_rm_dev_item(struct btrfs_trans_handle *trans,
|
||||||
{
|
{
|
||||||
struct btrfs_root *root = device->fs_info->chunk_root;
|
struct btrfs_root *root = device->fs_info->chunk_root;
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
|
|
@ -2031,16 +2021,12 @@ static int btrfs_rm_dev_item(struct btrfs_trans_handle *trans,
|
||||||
btrfs_reserve_chunk_metadata(trans, false);
|
btrfs_reserve_chunk_metadata(trans, false);
|
||||||
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
|
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
|
||||||
btrfs_trans_release_chunk_metadata(trans);
|
btrfs_trans_release_chunk_metadata(trans);
|
||||||
if (ret) {
|
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
ret = -ENOENT;
|
return -ENOENT;
|
||||||
goto out;
|
if (ret < 0)
|
||||||
}
|
|
||||||
|
|
||||||
ret = btrfs_del_item(trans, root, path);
|
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
return btrfs_del_item(trans, root, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -2626,7 +2612,7 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
|
||||||
BTRFS_DEV_LOOKUP_ARGS(args);
|
BTRFS_DEV_LOOKUP_ARGS(args);
|
||||||
struct btrfs_fs_info *fs_info = trans->fs_info;
|
struct btrfs_fs_info *fs_info = trans->fs_info;
|
||||||
struct btrfs_root *root = fs_info->chunk_root;
|
struct btrfs_root *root = fs_info->chunk_root;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
struct btrfs_dev_item *dev_item;
|
struct btrfs_dev_item *dev_item;
|
||||||
struct btrfs_device *device;
|
struct btrfs_device *device;
|
||||||
|
|
@ -2648,7 +2634,7 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
|
||||||
ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
|
ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
|
||||||
btrfs_trans_release_chunk_metadata(trans);
|
btrfs_trans_release_chunk_metadata(trans);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
|
|
||||||
leaf = path->nodes[0];
|
leaf = path->nodes[0];
|
||||||
next_slot:
|
next_slot:
|
||||||
|
|
@ -2657,7 +2643,7 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
break;
|
break;
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
leaf = path->nodes[0];
|
leaf = path->nodes[0];
|
||||||
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
|
btrfs_item_key_to_cpu(leaf, &key, path->slots[0]);
|
||||||
btrfs_release_path(path);
|
btrfs_release_path(path);
|
||||||
|
|
@ -2688,10 +2674,7 @@ static int btrfs_finish_sprout(struct btrfs_trans_handle *trans)
|
||||||
path->slots[0]++;
|
path->slots[0]++;
|
||||||
goto next_slot;
|
goto next_slot;
|
||||||
}
|
}
|
||||||
ret = 0;
|
return 0;
|
||||||
error:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path)
|
int btrfs_init_new_device(struct btrfs_fs_info *fs_info, const char *device_path)
|
||||||
|
|
@ -2946,7 +2929,7 @@ static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_device *device)
|
struct btrfs_device *device)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_root *root = device->fs_info->chunk_root;
|
struct btrfs_root *root = device->fs_info->chunk_root;
|
||||||
struct btrfs_dev_item *dev_item;
|
struct btrfs_dev_item *dev_item;
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
|
|
@ -2962,12 +2945,10 @@ static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
|
||||||
|
|
||||||
ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
|
ret = btrfs_search_slot(trans, root, &key, path, 0, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
|
|
||||||
if (ret > 0) {
|
if (ret > 0)
|
||||||
ret = -ENOENT;
|
return -ENOENT;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
leaf = path->nodes[0];
|
leaf = path->nodes[0];
|
||||||
dev_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_item);
|
dev_item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_dev_item);
|
||||||
|
|
@ -2981,8 +2962,6 @@ static noinline int btrfs_update_device(struct btrfs_trans_handle *trans,
|
||||||
btrfs_device_get_disk_total_bytes(device));
|
btrfs_device_get_disk_total_bytes(device));
|
||||||
btrfs_set_device_bytes_used(leaf, dev_item,
|
btrfs_set_device_bytes_used(leaf, dev_item,
|
||||||
btrfs_device_get_bytes_used(device));
|
btrfs_device_get_bytes_used(device));
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3035,7 +3014,7 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
|
||||||
struct btrfs_fs_info *fs_info = trans->fs_info;
|
struct btrfs_fs_info *fs_info = trans->fs_info;
|
||||||
struct btrfs_root *root = fs_info->chunk_root;
|
struct btrfs_root *root = fs_info->chunk_root;
|
||||||
int ret;
|
int ret;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
|
|
@ -3048,23 +3027,21 @@ static int btrfs_free_chunk(struct btrfs_trans_handle *trans, u64 chunk_offset)
|
||||||
|
|
||||||
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
|
ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
else if (unlikely(ret > 0)) { /* Logic error or corruption */
|
if (unlikely(ret > 0)) {
|
||||||
|
/* Logic error or corruption */
|
||||||
btrfs_err(fs_info, "failed to lookup chunk %llu when freeing",
|
btrfs_err(fs_info, "failed to lookup chunk %llu when freeing",
|
||||||
chunk_offset);
|
chunk_offset);
|
||||||
btrfs_abort_transaction(trans, -ENOENT);
|
btrfs_abort_transaction(trans, -ENOENT);
|
||||||
ret = -EUCLEAN;
|
return -EUCLEAN;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = btrfs_del_item(trans, root, path);
|
ret = btrfs_del_item(trans, root, path);
|
||||||
if (unlikely(ret < 0)) {
|
if (unlikely(ret < 0)) {
|
||||||
btrfs_err(fs_info, "failed to delete chunk %llu item", chunk_offset);
|
btrfs_err(fs_info, "failed to delete chunk %llu item", chunk_offset);
|
||||||
btrfs_abort_transaction(trans, ret);
|
btrfs_abort_transaction(trans, ret);
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -3501,7 +3478,7 @@ int btrfs_relocate_chunk(struct btrfs_fs_info *fs_info, u64 chunk_offset,
|
||||||
static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
|
static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
|
||||||
{
|
{
|
||||||
struct btrfs_root *chunk_root = fs_info->chunk_root;
|
struct btrfs_root *chunk_root = fs_info->chunk_root;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
struct btrfs_chunk *chunk;
|
struct btrfs_chunk *chunk;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
|
|
@ -3525,7 +3502,7 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
|
||||||
ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0);
|
ret = btrfs_search_slot(NULL, chunk_root, &key, path, 0, 0);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
mutex_unlock(&fs_info->reclaim_bgs_lock);
|
mutex_unlock(&fs_info->reclaim_bgs_lock);
|
||||||
goto error;
|
return ret;
|
||||||
}
|
}
|
||||||
if (unlikely(ret == 0)) {
|
if (unlikely(ret == 0)) {
|
||||||
/*
|
/*
|
||||||
|
|
@ -3535,9 +3512,8 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
|
||||||
* offset (one less than the previous one, wrong
|
* offset (one less than the previous one, wrong
|
||||||
* alignment and size).
|
* alignment and size).
|
||||||
*/
|
*/
|
||||||
ret = -EUCLEAN;
|
|
||||||
mutex_unlock(&fs_info->reclaim_bgs_lock);
|
mutex_unlock(&fs_info->reclaim_bgs_lock);
|
||||||
goto error;
|
return -EUCLEAN;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = btrfs_previous_item(chunk_root, path, key.objectid,
|
ret = btrfs_previous_item(chunk_root, path, key.objectid,
|
||||||
|
|
@ -3545,7 +3521,7 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
|
||||||
if (ret)
|
if (ret)
|
||||||
mutex_unlock(&fs_info->reclaim_bgs_lock);
|
mutex_unlock(&fs_info->reclaim_bgs_lock);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto error;
|
return ret;
|
||||||
if (ret > 0)
|
if (ret > 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
@ -3579,8 +3555,6 @@ static int btrfs_relocate_sys_chunks(struct btrfs_fs_info *fs_info)
|
||||||
} else if (WARN_ON(failed && retried)) {
|
} else if (WARN_ON(failed && retried)) {
|
||||||
ret = -ENOSPC;
|
ret = -ENOSPC;
|
||||||
}
|
}
|
||||||
error:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -4709,7 +4683,7 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
|
||||||
struct btrfs_balance_control *bctl;
|
struct btrfs_balance_control *bctl;
|
||||||
struct btrfs_balance_item *item;
|
struct btrfs_balance_item *item;
|
||||||
struct btrfs_disk_balance_args disk_bargs;
|
struct btrfs_disk_balance_args disk_bargs;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
@ -4724,17 +4698,14 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
|
||||||
|
|
||||||
ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
|
ret = btrfs_search_slot(NULL, fs_info->tree_root, &key, path, 0, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
if (ret > 0) { /* ret = -ENOENT; */
|
if (ret > 0) { /* ret = -ENOENT; */
|
||||||
ret = 0;
|
return 0;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bctl = kzalloc(sizeof(*bctl), GFP_NOFS);
|
bctl = kzalloc(sizeof(*bctl), GFP_NOFS);
|
||||||
if (!bctl) {
|
if (!bctl)
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
leaf = path->nodes[0];
|
leaf = path->nodes[0];
|
||||||
item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);
|
item = btrfs_item_ptr(leaf, path->slots[0], struct btrfs_balance_item);
|
||||||
|
|
@ -4771,8 +4742,6 @@ int btrfs_recover_balance(struct btrfs_fs_info *fs_info)
|
||||||
fs_info->balance_ctl = bctl;
|
fs_info->balance_ctl = bctl;
|
||||||
spin_unlock(&fs_info->balance_lock);
|
spin_unlock(&fs_info->balance_lock);
|
||||||
mutex_unlock(&fs_info->balance_mutex);
|
mutex_unlock(&fs_info->balance_mutex);
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -7452,7 +7421,7 @@ static void readahead_tree_node_children(struct extent_buffer *node)
|
||||||
int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
|
int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
|
||||||
{
|
{
|
||||||
struct btrfs_root *root = fs_info->chunk_root;
|
struct btrfs_root *root = fs_info->chunk_root;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct btrfs_key found_key;
|
struct btrfs_key found_key;
|
||||||
|
|
@ -7569,8 +7538,6 @@ int btrfs_read_chunk_tree(struct btrfs_fs_info *fs_info)
|
||||||
ret = 0;
|
ret = 0;
|
||||||
error:
|
error:
|
||||||
mutex_unlock(&uuid_mutex);
|
mutex_unlock(&uuid_mutex);
|
||||||
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -7670,7 +7637,7 @@ int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info)
|
||||||
{
|
{
|
||||||
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices, *seed_devs;
|
struct btrfs_fs_devices *fs_devices = fs_info->fs_devices, *seed_devs;
|
||||||
struct btrfs_device *device;
|
struct btrfs_device *device;
|
||||||
struct btrfs_path *path = NULL;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
|
|
@ -7692,8 +7659,6 @@ int btrfs_init_dev_stats(struct btrfs_fs_info *fs_info)
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
mutex_unlock(&fs_devices->device_list_mutex);
|
mutex_unlock(&fs_devices->device_list_mutex);
|
||||||
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -7702,7 +7667,7 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
|
||||||
{
|
{
|
||||||
struct btrfs_fs_info *fs_info = trans->fs_info;
|
struct btrfs_fs_info *fs_info = trans->fs_info;
|
||||||
struct btrfs_root *dev_root = fs_info->dev_root;
|
struct btrfs_root *dev_root = fs_info->dev_root;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct extent_buffer *eb;
|
struct extent_buffer *eb;
|
||||||
struct btrfs_dev_stats_item *ptr;
|
struct btrfs_dev_stats_item *ptr;
|
||||||
|
|
@ -7721,7 +7686,7 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
|
||||||
btrfs_warn(fs_info,
|
btrfs_warn(fs_info,
|
||||||
"error %d while searching for dev_stats item for device %s",
|
"error %d while searching for dev_stats item for device %s",
|
||||||
ret, btrfs_dev_name(device));
|
ret, btrfs_dev_name(device));
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == 0 &&
|
if (ret == 0 &&
|
||||||
|
|
@ -7732,7 +7697,7 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
|
||||||
btrfs_warn(fs_info,
|
btrfs_warn(fs_info,
|
||||||
"delete too small dev_stats item for device %s failed %d",
|
"delete too small dev_stats item for device %s failed %d",
|
||||||
btrfs_dev_name(device), ret);
|
btrfs_dev_name(device), ret);
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
@ -7746,7 +7711,7 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
|
||||||
btrfs_warn(fs_info,
|
btrfs_warn(fs_info,
|
||||||
"insert dev_stats item for device %s failed %d",
|
"insert dev_stats item for device %s failed %d",
|
||||||
btrfs_dev_name(device), ret);
|
btrfs_dev_name(device), ret);
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -7755,8 +7720,6 @@ static int update_dev_stat_item(struct btrfs_trans_handle *trans,
|
||||||
for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++)
|
for (i = 0; i < BTRFS_DEV_STAT_VALUES_MAX; i++)
|
||||||
btrfs_set_dev_stats_value(eb, ptr, i,
|
btrfs_set_dev_stats_value(eb, ptr, i,
|
||||||
btrfs_dev_stat_read(device, i));
|
btrfs_dev_stat_read(device, i));
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -8046,7 +8009,7 @@ static int verify_chunk_dev_extent_mapping(struct btrfs_fs_info *fs_info)
|
||||||
*/
|
*/
|
||||||
int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
|
int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
|
||||||
{
|
{
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct btrfs_root *root = fs_info->dev_root;
|
struct btrfs_root *root = fs_info->dev_root;
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
u64 prev_devid = 0;
|
u64 prev_devid = 0;
|
||||||
|
|
@ -8077,17 +8040,15 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
|
||||||
path->reada = READA_FORWARD;
|
path->reada = READA_FORWARD;
|
||||||
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
ret = btrfs_search_slot(NULL, root, &key, path, 0, 0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
|
|
||||||
if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
|
if (path->slots[0] >= btrfs_header_nritems(path->nodes[0])) {
|
||||||
ret = btrfs_next_leaf(root, path);
|
ret = btrfs_next_leaf(root, path);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
/* No dev extents at all? Not good */
|
/* No dev extents at all? Not good */
|
||||||
if (unlikely(ret > 0)) {
|
if (unlikely(ret > 0))
|
||||||
ret = -EUCLEAN;
|
return -EUCLEAN;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
while (1) {
|
while (1) {
|
||||||
struct extent_buffer *leaf = path->nodes[0];
|
struct extent_buffer *leaf = path->nodes[0];
|
||||||
|
|
@ -8113,20 +8074,19 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
|
||||||
btrfs_err(fs_info,
|
btrfs_err(fs_info,
|
||||||
"dev extent devid %llu physical offset %llu overlap with previous dev extent end %llu",
|
"dev extent devid %llu physical offset %llu overlap with previous dev extent end %llu",
|
||||||
devid, physical_offset, prev_dev_ext_end);
|
devid, physical_offset, prev_dev_ext_end);
|
||||||
ret = -EUCLEAN;
|
return -EUCLEAN;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = verify_one_dev_extent(fs_info, chunk_offset, devid,
|
ret = verify_one_dev_extent(fs_info, chunk_offset, devid,
|
||||||
physical_offset, physical_len);
|
physical_offset, physical_len);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
prev_devid = devid;
|
prev_devid = devid;
|
||||||
prev_dev_ext_end = physical_offset + physical_len;
|
prev_dev_ext_end = physical_offset + physical_len;
|
||||||
|
|
||||||
ret = btrfs_next_item(root, path);
|
ret = btrfs_next_item(root, path);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto out;
|
return ret;
|
||||||
if (ret > 0) {
|
if (ret > 0) {
|
||||||
ret = 0;
|
ret = 0;
|
||||||
break;
|
break;
|
||||||
|
|
@ -8134,10 +8094,7 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Ensure all chunks have corresponding dev extents */
|
/* Ensure all chunks have corresponding dev extents */
|
||||||
ret = verify_chunk_dev_extent_mapping(fs_info);
|
return verify_chunk_dev_extent_mapping(fs_info);
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
|
|
@ -29,9 +29,8 @@ int btrfs_getxattr(const struct inode *inode, const char *name,
|
||||||
{
|
{
|
||||||
struct btrfs_dir_item *di;
|
struct btrfs_dir_item *di;
|
||||||
struct btrfs_root *root = BTRFS_I(inode)->root;
|
struct btrfs_root *root = BTRFS_I(inode)->root;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
struct extent_buffer *leaf;
|
struct extent_buffer *leaf;
|
||||||
int ret = 0;
|
|
||||||
unsigned long data_ptr;
|
unsigned long data_ptr;
|
||||||
|
|
||||||
path = btrfs_alloc_path();
|
path = btrfs_alloc_path();
|
||||||
|
|
@ -41,26 +40,19 @@ int btrfs_getxattr(const struct inode *inode, const char *name,
|
||||||
/* lookup the xattr by name */
|
/* lookup the xattr by name */
|
||||||
di = btrfs_lookup_xattr(NULL, root, path, btrfs_ino(BTRFS_I(inode)),
|
di = btrfs_lookup_xattr(NULL, root, path, btrfs_ino(BTRFS_I(inode)),
|
||||||
name, strlen(name), 0);
|
name, strlen(name), 0);
|
||||||
if (!di) {
|
if (!di)
|
||||||
ret = -ENODATA;
|
return -ENODATA;
|
||||||
goto out;
|
if (IS_ERR(di))
|
||||||
} else if (IS_ERR(di)) {
|
return PTR_ERR(di);
|
||||||
ret = PTR_ERR(di);
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
leaf = path->nodes[0];
|
leaf = path->nodes[0];
|
||||||
/* if size is 0, that means we want the size of the attr */
|
/* if size is 0, that means we want the size of the attr */
|
||||||
if (!size) {
|
if (!size)
|
||||||
ret = btrfs_dir_data_len(leaf, di);
|
return btrfs_dir_data_len(leaf, di);
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* now get the data out of our dir_item */
|
/* now get the data out of our dir_item */
|
||||||
if (btrfs_dir_data_len(leaf, di) > size) {
|
if (btrfs_dir_data_len(leaf, di) > size)
|
||||||
ret = -ERANGE;
|
return -ERANGE;
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The way things are packed into the leaf is like this
|
* The way things are packed into the leaf is like this
|
||||||
|
|
@ -73,11 +65,7 @@ int btrfs_getxattr(const struct inode *inode, const char *name,
|
||||||
btrfs_dir_name_len(leaf, di));
|
btrfs_dir_name_len(leaf, di));
|
||||||
read_extent_buffer(leaf, buffer, data_ptr,
|
read_extent_buffer(leaf, buffer, data_ptr,
|
||||||
btrfs_dir_data_len(leaf, di));
|
btrfs_dir_data_len(leaf, di));
|
||||||
ret = btrfs_dir_data_len(leaf, di);
|
return btrfs_dir_data_len(leaf, di);
|
||||||
|
|
||||||
out:
|
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode,
|
int btrfs_setxattr(struct btrfs_trans_handle *trans, struct inode *inode,
|
||||||
|
|
@ -278,7 +266,7 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
||||||
struct btrfs_key key;
|
struct btrfs_key key;
|
||||||
struct inode *inode = d_inode(dentry);
|
struct inode *inode = d_inode(dentry);
|
||||||
struct btrfs_root *root = BTRFS_I(inode)->root;
|
struct btrfs_root *root = BTRFS_I(inode)->root;
|
||||||
struct btrfs_path *path;
|
BTRFS_PATH_AUTO_FREE(path);
|
||||||
int iter_ret = 0;
|
int iter_ret = 0;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
size_t total_size = 0, size_left = size;
|
size_t total_size = 0, size_left = size;
|
||||||
|
|
@ -354,8 +342,6 @@ ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size)
|
||||||
else
|
else
|
||||||
ret = total_size;
|
ret = total_size;
|
||||||
|
|
||||||
btrfs_free_path(path);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue