diff mbox series

[1/3] btrfs-progs: csum-change: add error handling for search old csums

Message ID 274dd5b77399abb5881916d466a6a010455a1565.1718775066.git.wqu@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs-progs: csum-change enhancement | expand

Commit Message

Qu Wenruo June 19, 2024, 5:33 a.m. UTC
Inside delete_old_data_csums(), after calling btrfs_search_slot() there
is no error handling at all.

Fix it by doing a proper error detection and abort the current transaction.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 tune/change-csum.c | 7 +++++++
 1 file changed, 7 insertions(+)
diff mbox series

Patch

diff --git a/tune/change-csum.c b/tune/change-csum.c
index 0e7db20f5e6d..0f95cdb25533 100644
--- a/tune/change-csum.c
+++ b/tune/change-csum.c
@@ -395,6 +395,13 @@  static int delete_old_data_csums(struct btrfs_fs_info *fs_info)
 		int nr;
 
 		ret = btrfs_search_slot(trans, csum_root, &last_key, &path, -1, 1);
+		if (ret < 0) {
+			errno = -ret;
+			error("failed to search the last old csum item: %m");
+			btrfs_abort_transaction(trans, ret);
+			return ret;
+		}
+		assert(ret > 0);
 
 		nr = btrfs_header_nritems(path.nodes[0]);
 		/* No item left (empty csum tree), exit. */