提交 a012a74e 编写于 作者: N Nikolay Borisov 提交者: David Sterba

btrfs: Make fill_holes take btrfs_inode

Signed-off-by: NNikolay Borisov <nborisov@suse.com>
Signed-off-by: NDavid Sterba <dsterba@suse.com>
上级 35339c24
...@@ -2224,22 +2224,23 @@ static int hole_mergeable(struct btrfs_inode *inode, struct extent_buffer *leaf, ...@@ -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, ...@@ -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, ...@@ -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, ...@@ -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 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -2298,9 +2298,8 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
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 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -2315,8 +2314,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
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 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode, ...@@ -2324,7 +2322,7 @@ static int fill_holes(struct btrfs_trans_handle *trans, struct inode *inode,
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) ...@@ -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) ...@@ -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);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册