btrfs: Make fill_holes take btrfs_inode

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
Nikolay Borisov 2017-02-20 13:50:47 +02:00 коммит произвёл David Sterba
Родитель 35339c245b
Коммит a012a74e78
1 изменённых файлов: 18 добавлений и 19 удалений

Просмотреть файл

@ -2224,22 +2224,23 @@ static int hole_mergeable(struct btrfs_inode *inode, struct extent_buffer *leaf,
return 0; return 0;
} }
static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode, static int fill_holes(struct btrfs_trans_handle *trans,
struct btrfs_path *path, u64 offset, u64 end) struct btrfs_inode *inode,
struct btrfs_path *path, u64 offset, u64 end)
{ {
struct btrfs_fs_info *fs_info = btrfs_sb(inode->i_sb); struct btrfs_fs_info *fs_info = btrfs_sb(inode->vfs_inode.i_sb);
struct btrfs_root *root = BTRFS_I(inode)->root; struct btrfs_root *root = inode->root;
struct extent_buffer *leaf; struct extent_buffer *leaf;
struct btrfs_file_extent_item *fi; struct btrfs_file_extent_item *fi;
struct extent_map *hole_em; struct extent_map *hole_em;
struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; struct extent_map_tree *em_tree = &inode->extent_tree;
struct btrfs_key key; struct btrfs_key key;
int ret; int ret;
if (btrfs_fs_incompat(fs_info, NO_HOLES)) if (btrfs_fs_incompat(fs_info, NO_HOLES))
goto out; goto out;
key.objectid = btrfs_ino(BTRFS_I(inode)); key.objectid = btrfs_ino(inode);
key.type = BTRFS_EXTENT_DATA_KEY; key.type = BTRFS_EXTENT_DATA_KEY;
key.offset = offset; key.offset = offset;
@ -2255,8 +2256,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
} }
leaf = path->nodes[0]; leaf = path->nodes[0];
if (hole_mergeable(BTRFS_I(inode), leaf, path->slots[0] - 1, if (hole_mergeable(inode, leaf, path->slots[0] - 1, offset, end)) {
offset, end)) {
u64 num_bytes; u64 num_bytes;
path->slots[0]--; path->slots[0]--;
@ -2271,7 +2271,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
goto out; goto out;
} }
if (hole_mergeable(BTRFS_I(inode), leaf, path->slots[0], offset, end)) { if (hole_mergeable(inode, leaf, path->slots[0], offset, end)) {
u64 num_bytes; u64 num_bytes;
key.offset = offset; key.offset = offset;
@ -2288,7 +2288,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
} }
btrfs_release_path(path); btrfs_release_path(path);
ret = btrfs_insert_file_extent(trans, root, btrfs_ino(BTRFS_I(inode)), ret = btrfs_insert_file_extent(trans, root, btrfs_ino(inode),
offset, 0, 0, end - offset, 0, end - offset, 0, 0, 0); offset, 0, 0, end - offset, 0, end - offset, 0, 0, 0);
if (ret) if (ret)
return ret; return ret;
@ -2298,9 +2298,8 @@ out:
hole_em = alloc_extent_map(); hole_em = alloc_extent_map();
if (!hole_em) { if (!hole_em) {
btrfs_drop_extent_cache(BTRFS_I(inode), offset, end - 1, 0); btrfs_drop_extent_cache(inode, offset, end - 1, 0);
set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, &inode->runtime_flags);
&BTRFS_I(inode)->runtime_flags);
} else { } else {
hole_em->start = offset; hole_em->start = offset;
hole_em->len = end - offset; hole_em->len = end - offset;
@ -2315,8 +2314,7 @@ out:
hole_em->generation = trans->transid; hole_em->generation = trans->transid;
do { do {
btrfs_drop_extent_cache(BTRFS_I(inode), offset, btrfs_drop_extent_cache(inode, offset, end - 1, 0);
end - 1, 0);
write_lock(&em_tree->lock); write_lock(&em_tree->lock);
ret = add_extent_mapping(em_tree, hole_em, 1); ret = add_extent_mapping(em_tree, hole_em, 1);
write_unlock(&em_tree->lock); write_unlock(&em_tree->lock);
@ -2324,7 +2322,7 @@ out:
free_extent_map(hole_em); free_extent_map(hole_em);
if (ret) if (ret)
set_bit(BTRFS_INODE_NEEDS_FULL_SYNC, set_bit(BTRFS_INODE_NEEDS_FULL_SYNC,
&BTRFS_I(inode)->runtime_flags); &inode->runtime_flags);
} }
return 0; return 0;
@ -2554,8 +2552,8 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
trans->block_rsv = &fs_info->trans_block_rsv; trans->block_rsv = &fs_info->trans_block_rsv;
if (cur_offset < drop_end && cur_offset < ino_size) { if (cur_offset < drop_end && cur_offset < ino_size) {
ret = fill_holes(trans, inode, path, cur_offset, ret = fill_holes(trans, BTRFS_I(inode), path,
drop_end); cur_offset, drop_end);
if (ret) { if (ret) {
/* /*
* If we failed then we didn't insert our hole * If we failed then we didn't insert our hole
@ -2626,7 +2624,8 @@ static int btrfs_punch_hole(struct inode *inode, loff_t offset, loff_t len)
* cur_offset == drop_end). * cur_offset == drop_end).
*/ */
if (cur_offset < ino_size && cur_offset < drop_end) { if (cur_offset < ino_size && cur_offset < drop_end) {
ret = fill_holes(trans, inode, path, cur_offset, drop_end); ret = fill_holes(trans, BTRFS_I(inode), path,
cur_offset, drop_end);
if (ret) { if (ret) {
/* Same comment as above. */ /* Same comment as above. */
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);