Commit 008630c1 authored by Yan's avatar Yan Committed by Chris Mason

Properly delete csum item in btrfs_truncate_in_trans.

When 'item_end' is equal to 'inode->i_size',   'found_type' is updated
and current item is skipped. This behavior is correct for extent item,
but incorrect for csum item. For example, there is a csum item with
'offset == 0'. When deleting the inode,  'inode->i_size' is set to 0,
so the csum item isn't deleted.
Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 34a38218
...@@ -611,13 +611,14 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans, ...@@ -611,13 +611,14 @@ static int btrfs_truncate_in_trans(struct btrfs_trans_handle *trans,
item_end += btrfs_file_extent_inline_len(leaf, item_end += btrfs_file_extent_inline_len(leaf,
item); item);
} }
item_end--;
} }
if (found_type == BTRFS_CSUM_ITEM_KEY) { if (found_type == BTRFS_CSUM_ITEM_KEY) {
ret = btrfs_csum_truncate(trans, root, path, ret = btrfs_csum_truncate(trans, root, path,
inode->i_size); inode->i_size);
BUG_ON(ret); BUG_ON(ret);
} }
if (item_end <= inode->i_size) { if (item_end < inode->i_size) {
if (found_type == BTRFS_DIR_ITEM_KEY) { if (found_type == BTRFS_DIR_ITEM_KEY) {
found_type = BTRFS_INODE_ITEM_KEY; found_type = BTRFS_INODE_ITEM_KEY;
} else if (found_type == BTRFS_EXTENT_ITEM_KEY) { } else if (found_type == BTRFS_EXTENT_ITEM_KEY) {
......
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