Skip to content

Commit 3172d27

Browse files
committed
btrfs-progs: mkfs: make transaction start and commit errors verbose
Use the templated error message for transaction failures, use the same pattern assigning the ret and errno. Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 682f676 commit 3172d27

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed

mkfs/main.c

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ static int create_metadata_block_groups(struct btrfs_root *root, bool mixed,
165165

166166
root->fs_info->system_allocs = 0;
167167
ret = btrfs_commit_transaction(trans, root);
168+
if (ret) {
169+
errno = -ret;
170+
error_msg(ERROR_MSG_COMMIT_TRANS, "%m");
171+
}
168172
err:
169173
return ret;
170174
}
@@ -687,8 +691,13 @@ static int cleanup_temp_chunks(struct btrfs_fs_info *fs_info,
687691
key.objectid = found_key.objectid + found_key.offset;
688692
}
689693
out:
690-
if (trans)
691-
btrfs_commit_transaction(trans, root);
694+
if (trans) {
695+
ret = btrfs_commit_transaction(trans, root);
696+
if (ret) {
697+
errno = -ret;
698+
error_msg(ERROR_MSG_COMMIT_TRANS, "%m");
699+
}
700+
}
692701
btrfs_release_path(&path);
693702
return ret;
694703
}
@@ -1111,8 +1120,12 @@ static int setup_raid_stripe_tree_root(struct btrfs_fs_info *fs_info)
11111120
int ret;
11121121

11131122
trans = btrfs_start_transaction(fs_info->tree_root, 0);
1114-
if (IS_ERR(trans))
1115-
return PTR_ERR(trans);
1123+
if (IS_ERR(trans)) {
1124+
ret = PTR_ERR(trans);
1125+
errno = -ret;
1126+
error_msg(ERROR_MSG_START_TRANS, "%m");
1127+
return ret;
1128+
}
11161129

11171130
stripe_root = btrfs_create_tree(trans, fs_info, &key);
11181131
if (IS_ERR(stripe_root)) {
@@ -1124,8 +1137,11 @@ static int setup_raid_stripe_tree_root(struct btrfs_fs_info *fs_info)
11241137
add_root_to_dirty_list(stripe_root);
11251138

11261139
ret = btrfs_commit_transaction(trans, fs_info->tree_root);
1127-
if (ret)
1140+
if (ret) {
1141+
errno = -ret;
1142+
error_msg(ERROR_MSG_COMMIT_TRANS, "%m");
11281143
return ret;
1144+
}
11291145

11301146
return 0;
11311147
}

0 commit comments

Comments
 (0)