Commit b86652be authored by Josef Bacik's avatar Josef Bacik Committed by David Sterba

btrfs: fix error handling in btrfs_del_csums

Error injection stress would sometimes fail with checksums on disk that
did not have a corresponding extent.  This occurred because the pattern
in btrfs_del_csums was

	while (1) {
		ret = btrfs_search_slot();
		if (ret < 0)
			break;
	}
	ret = 0;
out:
	btrfs_free_path(path);
	return ret;

If we got an error from btrfs_search_slot we'd clear the error because
we were breaking instead of goto out.  Instead of using goto out, simply
handle the cases where we may leave a random value in ret, and get rid
of the

	ret = 0;
out:

pattern and simply allow break to have the proper error reporting.  With
this fix we properly abort the transaction and do not commit thinking we
successfully deleted the csum.
Reviewed-by: default avatarQu Wenruo <wqu@suse.com>
CC: stable@vger.kernel.org # 4.4+
Signed-off-by: default avatarJosef Bacik <josef@toxicpanda.com>
Reviewed-by: default avatarDavid Sterba <dsterba@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent 4c80a97d
...@@ -788,7 +788,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, ...@@ -788,7 +788,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
u64 end_byte = bytenr + len; u64 end_byte = bytenr + len;
u64 csum_end; u64 csum_end;
struct extent_buffer *leaf; struct extent_buffer *leaf;
int ret; int ret = 0;
const u32 csum_size = fs_info->csum_size; const u32 csum_size = fs_info->csum_size;
u32 blocksize_bits = fs_info->sectorsize_bits; u32 blocksize_bits = fs_info->sectorsize_bits;
...@@ -806,6 +806,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, ...@@ -806,6 +806,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
ret = btrfs_search_slot(trans, root, &key, path, -1, 1); ret = btrfs_search_slot(trans, root, &key, path, -1, 1);
if (ret > 0) { if (ret > 0) {
ret = 0;
if (path->slots[0] == 0) if (path->slots[0] == 0)
break; break;
path->slots[0]--; path->slots[0]--;
...@@ -862,7 +863,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, ...@@ -862,7 +863,7 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
ret = btrfs_del_items(trans, root, path, ret = btrfs_del_items(trans, root, path,
path->slots[0], del_nr); path->slots[0], del_nr);
if (ret) if (ret)
goto out; break;
if (key.offset == bytenr) if (key.offset == bytenr)
break; break;
} else if (key.offset < bytenr && csum_end > end_byte) { } else if (key.offset < bytenr && csum_end > end_byte) {
...@@ -906,8 +907,9 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, ...@@ -906,8 +907,9 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
ret = btrfs_split_item(trans, root, path, &key, offset); ret = btrfs_split_item(trans, root, path, &key, offset);
if (ret && ret != -EAGAIN) { if (ret && ret != -EAGAIN) {
btrfs_abort_transaction(trans, ret); btrfs_abort_transaction(trans, ret);
goto out; break;
} }
ret = 0;
key.offset = end_byte - 1; key.offset = end_byte - 1;
} else { } else {
...@@ -917,8 +919,6 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans, ...@@ -917,8 +919,6 @@ int btrfs_del_csums(struct btrfs_trans_handle *trans,
} }
btrfs_release_path(path); btrfs_release_path(path);
} }
ret = 0;
out:
btrfs_free_path(path); btrfs_free_path(path);
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