leaf = path->nodes[0];
ei = btrfs_item_ptr(leaf, path->slots[0],
struct btrfs_file_extent_item);
+ inode->i_blocks += (offset + size - found_end) >> 9;
}
if (found_end < offset) {
ptr = btrfs_file_extent_inline_start(ei) + found_size;
insert:
btrfs_release_path(root, path);
datasize = offset + size - key.offset;
+ inode->i_blocks += datasize >> 9;
datasize = btrfs_file_extent_calc_inline_size(datasize);
ret = btrfs_insert_empty_item(trans, root, path, &key,
datasize);
goto out_unlock;
}
btrfs_set_trans_block_group(trans, inode);
- inode->i_blocks += num_bytes >> 9;
hint_byte = 0;
if ((end_of_last_block & 4095) == 0) {
if (found_key.type != BTRFS_EXTENT_DATA_KEY)
goto out;
- if (found_key.offset != last_offset) {
+ if (found_key.offset < last_offset) {
WARN_ON(1);
btrfs_print_leaf(root, leaf);
printk("inode %lu found offset %Lu expected %Lu\n",
last_offset = extent_end;
path->slots[0]++;
}
- if (last_offset < inode->i_size) {
+ if (0 && last_offset < inode->i_size) {
WARN_ON(1);
btrfs_print_leaf(root, leaf);
printk("inode %lu found offset %Lu size %Lu\n", inode->i_ino,
extent);
if (btrfs_file_extent_disk_bytenr(leaf,
extent)) {
- inode->i_blocks -=
- (old_num - new_num) >> 9;
+ dec_i_blocks(inode, old_num - new_num);
}
btrfs_set_file_extent_num_bytes(leaf, extent,
new_num);
u32 new_size;
new_size = btrfs_file_extent_calc_inline_size(
inline_limit - key.offset);
+ dec_i_blocks(inode, (extent_end - key.offset) -
+ (inline_limit - key.offset));
btrfs_truncate_item(trans, root, path,
new_size, 1);
}
btrfs_release_path(root, path);
extent = NULL;
if (found_extent && disk_bytenr != 0) {
- inode->i_blocks -= extent_num_bytes >> 9;
+ dec_i_blocks(inode, extent_num_bytes);
ret = btrfs_free_extent(trans, root,
disk_bytenr,
disk_num_bytes,
u32 new_size;
new_size = btrfs_file_extent_calc_inline_size(
extent_end - end);
+ dec_i_blocks(inode, (extent_end - key.offset) -
+ (extent_end - end));
btrfs_truncate_item(trans, root, path, new_size, 0);
}
/* create bookend, splitting the extent in two */
}
out:
btrfs_free_path(path);
+ btrfs_check_file(root, inode);
return ret;
}
ret = btrfs_insert_file_extent(trans, root, inode->i_ino,
start, ins.objectid, ins.offset,
ins.offset);
+ inode->i_blocks += ins.offset >> 9;
btrfs_check_file(root, inode);
num_bytes -= cur_alloc_size;
alloc_hint = ins.objectid + ins.offset;
btrfs_drop_extent_cache(inode, orig_start,
orig_start + orig_num_bytes - 1);
btrfs_add_ordered_inode(inode);
+ btrfs_update_inode(trans, root, inode);
out:
btrfs_end_transaction(trans, root);
return ret;
if (!(old & EXTENT_DELALLOC) && (bits & EXTENT_DELALLOC)) {
struct btrfs_root *root = BTRFS_I(inode)->root;
spin_lock(&root->fs_info->delalloc_lock);
+ BTRFS_I(inode)->delalloc_bytes += end - start + 1;
root->fs_info->delalloc_bytes += end - start + 1;
spin_unlock(&root->fs_info->delalloc_lock);
}
printk("warning: delalloc account %Lu %Lu\n",
end - start + 1, root->fs_info->delalloc_bytes);
root->fs_info->delalloc_bytes = 0;
+ BTRFS_I(inode)->delalloc_bytes = 0;
} else {
root->fs_info->delalloc_bytes -= end - start + 1;
+ BTRFS_I(inode)->delalloc_bytes -= end - start + 1;
}
spin_unlock(&root->fs_info->delalloc_lock);
}
btrfs_set_file_extent_num_bytes(leaf, fi,
extent_num_bytes);
num_dec = (orig_num_bytes -
- extent_num_bytes) >> 9;
- if (extent_start != 0) {
- inode->i_blocks -= num_dec;
- }
+ extent_num_bytes);
+ if (extent_start != 0)
+ dec_i_blocks(inode, num_dec);
btrfs_mark_buffer_dirty(leaf);
} else {
extent_num_bytes =
btrfs_file_extent_disk_num_bytes(leaf,
fi);
/* FIXME blocksize != 4096 */
- num_dec = btrfs_file_extent_num_bytes(leaf,
- fi) >> 9;
+ num_dec = btrfs_file_extent_num_bytes(leaf, fi);
if (extent_start != 0) {
found_extent = 1;
- inode->i_blocks -= num_dec;
+ dec_i_blocks(inode, num_dec);
}
root_gen = btrfs_header_generation(leaf);
root_owner = btrfs_header_owner(leaf);
}
- } else if (extent_type == BTRFS_FILE_EXTENT_INLINE &&
- !del_item) {
- u32 newsize = inode->i_size - found_key.offset;
- newsize = btrfs_file_extent_calc_inline_size(newsize);
- ret = btrfs_truncate_item(trans, root, path,
- newsize, 1);
- BUG_ON(ret);
+ } else if (extent_type == BTRFS_FILE_EXTENT_INLINE) {
+ if (!del_item) {
+ u32 newsize = inode->i_size - found_key.offset;
+ dec_i_blocks(inode, item_end + 1 -
+ found_key.offset - newsize);
+ newsize =
+ btrfs_file_extent_calc_inline_size(newsize);
+ ret = btrfs_truncate_item(trans, root, path,
+ newsize, 1);
+ BUG_ON(ret);
+ } else {
+ dec_i_blocks(inode, item_end + 1 -
+ found_key.offset);
+ }
}
delete:
if (del_item) {
struct btrfs_iget_args *args = p;
inode->i_ino = args->ino;
BTRFS_I(inode)->root = args->root;
+ BTRFS_I(inode)->delalloc_bytes = 0;
extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS);
extent_io_tree_init(&BTRFS_I(inode)->io_tree,
inode->i_mapping, GFP_NOFS);
extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS);
extent_io_tree_init(&BTRFS_I(inode)->io_tree,
inode->i_mapping, GFP_NOFS);
+ BTRFS_I(inode)->delalloc_bytes = 0;
BTRFS_I(inode)->root = root;
if (mode & S_IFDIR)
extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS);
extent_io_tree_init(&BTRFS_I(inode)->io_tree,
inode->i_mapping, GFP_NOFS);
+ BTRFS_I(inode)->delalloc_bytes = 0;
BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
}
dir->i_sb->s_dirt = 1;
struct inode *inode = dentry->d_inode;
generic_fillattr(inode, stat);
stat->blksize = PAGE_CACHE_SIZE;
+ stat->blocks = inode->i_blocks + (BTRFS_I(inode)->delalloc_bytes >> 9);
return 0;
}
extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS);
extent_io_tree_init(&BTRFS_I(inode)->io_tree,
inode->i_mapping, GFP_NOFS);
+ BTRFS_I(inode)->delalloc_bytes = 0;
BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
}
dir->i_sb->s_dirt = 1;