Commit b06359a3 authored by Nikolay Borisov's avatar Nikolay Borisov Committed by David Sterba

btrfs: make btrfs_cont_expand take btrfs_inode

Reviewed-by: default avatarJohannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: default avatarNikolay Borisov <nborisov@suse.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 217f42eb
...@@ -3118,7 +3118,7 @@ int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans, ...@@ -3118,7 +3118,7 @@ int btrfs_update_inode_fallback(struct btrfs_trans_handle *trans,
int btrfs_orphan_add(struct btrfs_trans_handle *trans, int btrfs_orphan_add(struct btrfs_trans_handle *trans,
struct btrfs_inode *inode); struct btrfs_inode *inode);
int btrfs_orphan_cleanup(struct btrfs_root *root); int btrfs_orphan_cleanup(struct btrfs_root *root);
int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size); int btrfs_cont_expand(struct btrfs_inode *inode, loff_t oldsize, loff_t size);
void btrfs_add_delayed_iput(struct inode *inode); void btrfs_add_delayed_iput(struct inode *inode);
void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info); void btrfs_run_delayed_iputs(struct btrfs_fs_info *fs_info);
int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info); int btrfs_wait_on_delayed_iputs(struct btrfs_fs_info *fs_info);
......
...@@ -1628,7 +1628,7 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from, ...@@ -1628,7 +1628,7 @@ static int btrfs_write_check(struct kiocb *iocb, struct iov_iter *from,
/* Expand hole size to cover write data, preventing empty gap */ /* Expand hole size to cover write data, preventing empty gap */
loff_t end_pos = round_up(pos + count, fs_info->sectorsize); loff_t end_pos = round_up(pos + count, fs_info->sectorsize);
ret = btrfs_cont_expand(inode, oldsize, end_pos); ret = btrfs_cont_expand(BTRFS_I(inode), oldsize, end_pos);
if (ret) { if (ret) {
current->backing_dev_info = NULL; current->backing_dev_info = NULL;
return ret; return ret;
...@@ -3348,7 +3348,7 @@ static long btrfs_fallocate(struct file *file, int mode, ...@@ -3348,7 +3348,7 @@ static long btrfs_fallocate(struct file *file, int mode,
* But that's a minor problem and won't do much harm BTW. * But that's a minor problem and won't do much harm BTW.
*/ */
if (alloc_start > inode->i_size) { if (alloc_start > inode->i_size) {
ret = btrfs_cont_expand(inode, i_size_read(inode), ret = btrfs_cont_expand(BTRFS_I(inode), i_size_read(inode),
alloc_start); alloc_start);
if (ret) if (ret)
goto out; goto out;
......
...@@ -4847,14 +4847,14 @@ static int maybe_insert_hole(struct btrfs_root *root, struct btrfs_inode *inode, ...@@ -4847,14 +4847,14 @@ static int maybe_insert_hole(struct btrfs_root *root, struct btrfs_inode *inode,
* these file extents so that btrfs_get_extent will return a EXTENT_MAP_HOLE for * these file extents so that btrfs_get_extent will return a EXTENT_MAP_HOLE for
* the range between oldsize and size * the range between oldsize and size
*/ */
int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) int btrfs_cont_expand(struct btrfs_inode *inode, loff_t oldsize, loff_t size)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_root *root = inode->root;
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_fs_info *fs_info = root->fs_info;
struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; struct extent_io_tree *io_tree = &inode->io_tree;
struct extent_map *em = NULL; struct extent_map *em = NULL;
struct extent_state *cached_state = NULL; struct extent_state *cached_state = NULL;
struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; struct extent_map_tree *em_tree = &inode->extent_tree;
u64 hole_start = ALIGN(oldsize, fs_info->sectorsize); u64 hole_start = ALIGN(oldsize, fs_info->sectorsize);
u64 block_end = ALIGN(size, fs_info->sectorsize); u64 block_end = ALIGN(size, fs_info->sectorsize);
u64 last_byte; u64 last_byte;
...@@ -4867,18 +4867,18 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) ...@@ -4867,18 +4867,18 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
* rest of the block before we expand the i_size, otherwise we could * rest of the block before we expand the i_size, otherwise we could
* expose stale data. * expose stale data.
*/ */
err = btrfs_truncate_block(BTRFS_I(inode), oldsize, 0, 0); err = btrfs_truncate_block(inode, oldsize, 0, 0);
if (err) if (err)
return err; return err;
if (size <= hole_start) if (size <= hole_start)
return 0; return 0;
btrfs_lock_and_flush_ordered_range(BTRFS_I(inode), hole_start, btrfs_lock_and_flush_ordered_range(inode, hole_start, block_end - 1,
block_end - 1, &cached_state); &cached_state);
cur_offset = hole_start; cur_offset = hole_start;
while (1) { while (1) {
em = btrfs_get_extent(BTRFS_I(inode), NULL, 0, cur_offset, em = btrfs_get_extent(inode, NULL, 0, cur_offset,
block_end - cur_offset); block_end - cur_offset);
if (IS_ERR(em)) { if (IS_ERR(em)) {
err = PTR_ERR(em); err = PTR_ERR(em);
...@@ -4892,22 +4892,22 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) ...@@ -4892,22 +4892,22 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) { if (!test_bit(EXTENT_FLAG_PREALLOC, &em->flags)) {
struct extent_map *hole_em; struct extent_map *hole_em;
err = maybe_insert_hole(root, BTRFS_I(inode), err = maybe_insert_hole(root, inode, cur_offset,
cur_offset, hole_size); hole_size);
if (err) if (err)
break; break;
err = btrfs_inode_set_file_extent_range(BTRFS_I(inode), err = btrfs_inode_set_file_extent_range(inode,
cur_offset, hole_size); cur_offset, hole_size);
if (err) if (err)
break; break;
btrfs_drop_extent_cache(BTRFS_I(inode), cur_offset, btrfs_drop_extent_cache(inode, cur_offset,
cur_offset + hole_size - 1, 0); cur_offset + hole_size - 1, 0);
hole_em = alloc_extent_map(); hole_em = alloc_extent_map();
if (!hole_em) { if (!hole_em) {
set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, set_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
&BTRFS_I(inode)->runtime_flags); &inode->runtime_flags);
goto next; goto next;
} }
hole_em->start = cur_offset; hole_em->start = cur_offset;
...@@ -4927,14 +4927,13 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size) ...@@ -4927,14 +4927,13 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
write_unlock(&em_tree->lock); write_unlock(&em_tree->lock);
if (err != -EEXIST) if (err != -EEXIST)
break; break;
btrfs_drop_extent_cache(BTRFS_I(inode), btrfs_drop_extent_cache(inode, cur_offset,
cur_offset,
cur_offset + cur_offset +
hole_size - 1, 0); hole_size - 1, 0);
} }
free_extent_map(hole_em); free_extent_map(hole_em);
} else { } else {
err = btrfs_inode_set_file_extent_range(BTRFS_I(inode), err = btrfs_inode_set_file_extent_range(inode,
cur_offset, hole_size); cur_offset, hole_size);
if (err) if (err)
break; break;
...@@ -4982,7 +4981,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr) ...@@ -4982,7 +4981,7 @@ static int btrfs_setsize(struct inode *inode, struct iattr *attr)
* this truncation. * this truncation.
*/ */
btrfs_drew_write_lock(&root->snapshot_lock); btrfs_drew_write_lock(&root->snapshot_lock);
ret = btrfs_cont_expand(inode, oldsize, newsize); ret = btrfs_cont_expand(BTRFS_I(inode), oldsize, newsize);
if (ret) { if (ret) {
btrfs_drew_write_unlock(&root->snapshot_lock); btrfs_drew_write_unlock(&root->snapshot_lock);
return ret; return ret;
......
...@@ -654,7 +654,7 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src, ...@@ -654,7 +654,7 @@ static noinline int btrfs_clone_files(struct file *file, struct file *file_src,
if (destoff > inode->i_size) { if (destoff > inode->i_size) {
const u64 wb_start = ALIGN_DOWN(inode->i_size, bs); const u64 wb_start = ALIGN_DOWN(inode->i_size, bs);
ret = btrfs_cont_expand(inode, inode->i_size, destoff); ret = btrfs_cont_expand(BTRFS_I(inode), inode->i_size, destoff);
if (ret) if (ret)
return ret; return ret;
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment