- ret = btrfs_rmap_block(&root->fs_info->mapping_tree,
- cache->key.objectid, bytenr, 0,
+ ret = btrfs_rmap_block(fs_info, cache->key.objectid, bytenr, 0,
&logical, &nr, &stripe_len);
BUG_ON(ret);
while (nr--) {
clear_extent_dirty(free_space_cache, logical[nr],
&logical, &nr, &stripe_len);
BUG_ON(ret);
while (nr--) {
clear_extent_dirty(free_space_cache, logical[nr],
if (key.objectid > last) {
hole_size = key.objectid - last;
set_extent_dirty(free_space_cache, last,
if (key.objectid > last) {
hole_size = key.objectid - last;
set_extent_dirty(free_space_cache, last,
block_group->key.offset > last) {
hole_size = block_group->key.objectid +
block_group->key.offset - last;
block_group->key.offset > last) {
hole_size = block_group->key.objectid +
block_group->key.offset - last;
- set_extent_dirty(free_space_cache, last,
- last + hole_size - 1, GFP_NOFS);
+ set_extent_dirty(free_space_cache, last, last + hole_size - 1);
if (!cache) {
printk("Unable to find block group for %llu\n",
(unsigned long long)search_start);
if (!cache) {
printk("Unable to find block group for %llu\n",
(unsigned long long)search_start);
-static noinline u32 extent_data_ref_count(struct btrfs_root *root,
- struct btrfs_path *path,
+static noinline u32 extent_data_ref_count(struct btrfs_path *path,
-static int setup_inline_extent_backref(struct btrfs_trans_handle *trans,
- struct btrfs_root *root,
+static int setup_inline_extent_backref(struct btrfs_root *root,
struct btrfs_path *path,
struct btrfs_extent_inline_ref *iref,
u64 parent, u64 root_objectid,
struct btrfs_path *path,
struct btrfs_extent_inline_ref *iref,
u64 parent, u64 root_objectid,
ret = update_inline_extent_backref(trans, root, path, iref,
refs_to_add);
} else if (ret == -ENOENT) {
ret = update_inline_extent_backref(trans, root, path, iref,
refs_to_add);
} else if (ret == -ENOENT) {
- ret = setup_inline_extent_backref(trans, root, path, iref,
+ ret = setup_inline_extent_backref(root, path, iref,
btrfs_item_key_to_cpu(path->nodes[0], &key,
path->slots[0]);
if (key.objectid == bytenr &&
btrfs_item_key_to_cpu(path->nodes[0], &key,
path->slots[0]);
if (key.objectid == bytenr &&
ret = process_func(trans, root, bytenr, num_bytes,
parent, ref_root, level - 1, 0);
if (ret) {
ret = process_func(trans, root, bytenr, num_bytes,
parent, ref_root, level - 1, 0);
if (ret) {
BUG_ON(ret);
clear_extent_bits(block_group_cache, start, end,
BUG_ON(ret);
clear_extent_bits(block_group_cache, start, end,
cache = (struct btrfs_block_group_cache *)(unsigned long)ptr;
ret = write_one_cache_group(trans, root, path, cache);
cache = (struct btrfs_block_group_cache *)(unsigned long)ptr;
ret = write_one_cache_group(trans, root, path, cache);
- ret = update_space_info(extent_root->fs_info, flags,
- 0, 0, &space_info);
+ ret = update_space_info(fs_info, flags, 0, 0, &space_info);
- ret = btrfs_alloc_chunk(trans, extent_root, &start, &num_bytes,
+ ret = btrfs_alloc_chunk(trans, fs_info, &start, &num_bytes,
- ret = btrfs_make_block_group(trans, extent_root, 0, space_info->flags,
+ ret = btrfs_make_block_group(trans, fs_info, 0, space_info->flags,
start = cache->key.objectid;
end = start + cache->key.offset - 1;
set_extent_bits(&info->block_group_cache, start, end,
start = cache->key.objectid;
end = start + cache->key.offset - 1;
set_extent_bits(&info->block_group_cache, start, end,
old_val = btrfs_block_group_used(&cache->item);
num_bytes = min(total, cache->key.offset - byte_in_group);
old_val = btrfs_block_group_used(&cache->item);
num_bytes = min(total, cache->key.offset - byte_in_group);
cache->space_info->bytes_used -= num_bytes;
if (mark_free) {
set_extent_dirty(&info->free_space_cache,
cache->space_info->bytes_used -= num_bytes;
if (mark_free) {
set_extent_dirty(&info->free_space_cache,
if (ret)
break;
update_pinned_extents(root, start, end + 1 - start, 0);
if (ret)
break;
update_pinned_extents(root, start, end + 1 - start, 0);
- clear_extent_dirty(unpin, start, end, GFP_NOFS);
- set_extent_dirty(free_space_cache, start, end, GFP_NOFS);
+ clear_extent_dirty(unpin, start, end);
+ set_extent_dirty(free_space_cache, start, end);
- clear_extent_bits(&info->extent_ins, start, end, EXTENT_LOCKED,
- GFP_NOFS);
+ clear_extent_bits(&info->extent_ins, start, end, EXTENT_LOCKED);
- clear_extent_bits(pending_del, start, end, EXTENT_LOCKED,
- GFP_NOFS);
+ clear_extent_bits(pending_del, start, end, EXTENT_LOCKED);
if (!test_range_bit(extent_ins, start, end,
EXTENT_LOCKED, 0)) {
if (!test_range_bit(extent_ins, start, end,
EXTENT_LOCKED, 0)) {
(unsigned long)priv;
clear_extent_bits(extent_ins, start, end,
(unsigned long)priv;
clear_extent_bits(extent_ins, start, end,
set_extent_bits(&root->fs_info->pending_del,
bytenr, bytenr + num_bytes - 1,
set_extent_bits(&root->fs_info->pending_del,
bytenr, bytenr + num_bytes - 1,
set_state_private(&root->fs_info->pending_del,
bytenr, (unsigned long)extent_op);
return 0;
set_state_private(&root->fs_info->pending_del,
bytenr, (unsigned long)extent_op);
return 0;
ins->type = BTRFS_EXTENT_ITEM_KEY;
search_start = stripe_align(root, search_start);
ins->type = BTRFS_EXTENT_ITEM_KEY;
search_start = stripe_align(root, search_start);
- search_start = round_up(bg_offset + num_bytes,
- BTRFS_STRIPE_LEN) + bg_offset;
+ search_start = round_up(
+ bg_offset + num_bytes, BTRFS_STRIPE_LEN) +
+ bg_cache->key.objectid;
alloc_profile = info->avail_data_alloc_bits &
info->data_alloc_profile;
data = BTRFS_BLOCK_GROUP_DATA | alloc_profile;
alloc_profile = info->avail_data_alloc_bits &
info->data_alloc_profile;
data = BTRFS_BLOCK_GROUP_DATA | alloc_profile;
alloc_profile = info->avail_system_alloc_bits &
info->system_alloc_profile;
data = BTRFS_BLOCK_GROUP_SYSTEM | alloc_profile;
alloc_profile = info->avail_system_alloc_bits &
info->system_alloc_profile;
data = BTRFS_BLOCK_GROUP_SYSTEM | alloc_profile;
ret = find_free_extent(trans, root, num_bytes, empty_size,
search_start, search_end, hint_byte, ins,
trans->alloc_exclude_start,
trans->alloc_exclude_nr, data);
ret = find_free_extent(trans, root, num_bytes, empty_size,
search_start, search_end, hint_byte, ins,
trans->alloc_exclude_start,
trans->alloc_exclude_nr, data);
- BUG_ON(ret);
- clear_extent_dirty(&root->fs_info->free_space_cache,
- ins->objectid, ins->objectid + ins->offset - 1,
- GFP_NOFS);
+ if (ret < 0)
+ return ret;
+ clear_extent_dirty(&info->free_space_cache,
+ ins->objectid, ins->objectid + ins->offset - 1);
- ret = update_block_group(trans, root, ins->objectid, root->nodesize,
+ ret = update_block_group(trans, root, ins->objectid, fs_info->nodesize,
set_extent_bits(&root->fs_info->extent_ins, ins->objectid,
ins->objectid + ins->offset - 1,
set_extent_bits(&root->fs_info->extent_ins, ins->objectid,
ins->objectid + ins->offset - 1,
set_state_private(&root->fs_info->extent_ins,
ins->objectid, (unsigned long)extent_op);
} else {
set_state_private(&root->fs_info->extent_ins,
ins->objectid, (unsigned long)extent_op);
} else {
if (!buf) {
btrfs_free_extent(trans, root, ins.objectid, ins.offset,
0, root->root_key.objectid, level, 0);
if (!buf) {
btrfs_free_extent(trans, root, ins.objectid, ins.offset,
0, root->root_key.objectid, level, 0);
}
while(1) {
ret = find_first_extent_bit(&info->free_space_cache, 0,
&start, &end, EXTENT_DIRTY);
if (ret)
break;
}
while(1) {
ret = find_first_extent_bit(&info->free_space_cache, 0,
&start, &end, EXTENT_DIRTY);
if (ret)
break;
cache->key.objectid, bytenr,
0, &logical, &nr, &stripe_len);
if (ret)
cache->key.objectid, bytenr,
0, &logical, &nr, &stripe_len);
if (ret)
+
+ /*
+ * Skip 0 sized block group, don't insert them into block
+ * group cache tree, as its length is 0, it won't get
+ * freed at close_ctree() time.
+ */
+ if (found_key.offset == 0) {
+ free(cache);
+ continue;
+ }
+
bit = BLOCK_GROUP_METADATA;
}
set_avail_alloc_bits(info, cache->flags);
bit = BLOCK_GROUP_METADATA;
}
set_avail_alloc_bits(info, cache->flags);
/* use EXTENT_LOCKED to prevent merging */
set_extent_bits(block_group_cache, found_key.objectid,
found_key.objectid + found_key.offset - 1,
/* use EXTENT_LOCKED to prevent merging */
set_extent_bits(block_group_cache, found_key.objectid,
found_key.objectid + found_key.offset - 1,
bit = block_group_state_bits(type);
ret = set_extent_bits(block_group_cache, chunk_offset,
chunk_offset + size - 1,
bit = block_group_state_bits(type);
ret = set_extent_bits(block_group_cache, chunk_offset,
chunk_offset + size - 1,
u64 type, u64 chunk_objectid, u64 chunk_offset,
u64 size)
{
int ret;
u64 type, u64 chunk_objectid, u64 chunk_offset,
u64 size)
{
int ret;
- cache = btrfs_add_block_group(root->fs_info, bytes_used, type,
+ cache = btrfs_add_block_group(fs_info, bytes_used, type,
ret = btrfs_insert_item(trans, extent_root, &cache->key, &cache->item,
sizeof(cache->item));
BUG_ON(ret);
ret = btrfs_insert_item(trans, extent_root, &cache->key, &cache->item,
sizeof(cache->item));
BUG_ON(ret);
* before doing any block allocation.
*/
int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
* before doing any block allocation.
*/
int btrfs_make_block_groups(struct btrfs_trans_handle *trans,
- total_bytes = btrfs_super_total_bytes(root->fs_info->super_copy);
- group_align = 64 * root->sectorsize;
+ total_bytes = btrfs_super_total_bytes(fs_info->super_copy);
+ group_align = 64 * fs_info->sectorsize;
- ret = update_space_info(root->fs_info, group_type, group_size,
+ ret = update_space_info(fs_info, group_type, group_size,
set_extent_bits(block_group_cache, cur_start,
cur_start + group_size - 1,
set_extent_bits(block_group_cache, cur_start,
cur_start + group_size - 1,
BUG_ON(!cache);
ret = btrfs_insert_item(trans, extent_root, &cache->key, &cache->item,
BUG_ON(!cache);
ret = btrfs_insert_item(trans, extent_root, &cache->key, &cache->item,
static int free_chunk_item(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info,
static int free_chunk_item(struct btrfs_trans_handle *trans,
struct btrfs_fs_info *fs_info,
- clear_extent_bits(&fs_info->block_group_cache, bytenr, bytenr + len,
- (unsigned int)-1, GFP_NOFS);
+ clear_extent_bits(&fs_info->block_group_cache, bytenr, bytenr + len - 1,
+ (unsigned int)-1);
ret = free_space_info(fs_info, flags, len, 0, NULL);
if (ret < 0)
goto out;
ret = free_space_info(fs_info, flags, len, 0, NULL);
if (ret < 0)
goto out;
- ret = free_chunk_item(trans, fs_info, bytenr, len);
+ ret = free_chunk_item(trans, fs_info, bytenr);
set_extent_bits(&root->fs_info->block_group_cache,
cache->key.objectid,
cache->key.objectid + cache->key.offset -1,
set_extent_bits(&root->fs_info->block_group_cache,
cache->key.objectid,
cache->key.objectid + cache->key.offset -1,
key.objectid, key.offset, 1, 0);
BUG_ON(ret);
} else if (key.type == BTRFS_METADATA_ITEM_KEY) {
key.objectid, key.offset, 1, 0);
BUG_ON(ret);
} else if (key.type == BTRFS_METADATA_ITEM_KEY) {
- key.objectid, root->nodesize, 1, 0);
- BUG_ON(ret);
+ key.objectid, fs_info->nodesize, 1, 0);
+ if (ret)
+ goto out;
{
u64 end = start + num_bytes - 1;
set_extent_bits(&root->fs_info->pinned_extents,
{
u64 end = start + num_bytes - 1;
set_extent_bits(&root->fs_info->pinned_extents,
end = start + cache->key.offset - 1;
clear_extent_bits(&root->fs_info->pinned_extents,
end = start + cache->key.offset - 1;
clear_extent_bits(&root->fs_info->pinned_extents,
cache->key.objectid, bytenr,
0, &logical, &nr, &stripe_len);
if (ret)
cache->key.objectid, bytenr,
0, &logical, &nr, &stripe_len);
if (ret)