Skip to content

Commit e73102e

Browse files
committed
btrfs-progs: mkfs: print errno string instead of numeric values
The preferred error message should have a prefix with problem description and then the errno description as we use the negative errno convention almost everywhere. - drop additional %d in the message if %m is present - replace %d with %m Signed-off-by: David Sterba <[email protected]>
1 parent a195088 commit e73102e

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

mkfs/main.c

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,8 @@ static int setup_quota_root(struct btrfs_fs_info *fs_info)
902902
}
903903
ret = btrfs_create_root(trans, fs_info, BTRFS_QUOTA_TREE_OBJECTID);
904904
if (ret < 0) {
905-
error("failed to create quota root: %d (%m)", ret);
905+
errno = -ret;
906+
error("failed to create quota root: %m");
906907
goto fail;
907908
}
908909
quota_root = fs_info->quota_root;
@@ -914,7 +915,8 @@ static int setup_quota_root(struct btrfs_fs_info *fs_info)
914915
ret = btrfs_insert_empty_item(trans, quota_root, &path, &key,
915916
sizeof(*qsi));
916917
if (ret < 0) {
917-
error("failed to insert qgroup status item: %d (%m)", ret);
918+
errno = -ret;
919+
error("failed to insert qgroup status item: %m");
918920
goto fail;
919921
}
920922

@@ -938,7 +940,8 @@ static int setup_quota_root(struct btrfs_fs_info *fs_info)
938940
/* Currently mkfs will only create one subvolume */
939941
ret = insert_qgroup_items(trans, fs_info, BTRFS_FS_TREE_OBJECTID);
940942
if (ret < 0) {
941-
error("failed to insert qgroup items: %d (%m)", ret);
943+
errno = -ret;
944+
error("failed to insert qgroup items: %m");
942945
goto fail;
943946
}
944947

@@ -953,7 +956,8 @@ static int setup_quota_root(struct btrfs_fs_info *fs_info)
953956
if (simple) {
954957
ret = touch_root_subvol(fs_info);
955958
if (ret) {
956-
error("failed to touch root dir for simple quota accounting %d (%m)", ret);
959+
errno = -ret;
960+
error("failed to touch root dir for simple quota accounting: %m");
957961
goto fail;
958962
}
959963
}
@@ -964,12 +968,15 @@ static int setup_quota_root(struct btrfs_fs_info *fs_info)
964968
*/
965969
ret = qgroup_verify_all(fs_info);
966970
if (ret < 0) {
967-
error("qgroup rescan failed: %d (%m)", ret);
971+
errno = -ret;
972+
error("qgroup rescan failed: %m");
968973
return ret;
969974
}
970975
ret = repair_qgroups(fs_info, &qgroup_repaired, true);
971-
if (ret < 0)
972-
error("failed to fill qgroup info: %d (%m)", ret);
976+
if (ret < 0) {
977+
errno = -ret;
978+
error("failed to fill qgroup info: %m");
979+
}
973980
return ret;
974981
fail:
975982
btrfs_abort_transaction(trans, ret);
@@ -1897,14 +1904,16 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
18971904

18981905
ret = create_metadata_block_groups(root, mixed, &allocation);
18991906
if (ret) {
1900-
error("failed to create default block groups: %d", ret);
1907+
errno = -ret;
1908+
error("failed to create default block groups: %m");
19011909
goto error;
19021910
}
19031911

19041912
if (features.incompat_flags & BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE) {
19051913
ret = setup_raid_stripe_tree_root(fs_info);
19061914
if (ret < 0) {
1907-
error("failed to initialize raid-stripe-tree: %d (%m)", ret);
1915+
errno = -ret;
1916+
error("failed to initialize raid-stripe-tree: %m");
19081917
goto out;
19091918
}
19101919
}
@@ -1919,21 +1928,24 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
19191928

19201929
ret = create_data_block_groups(trans, root, mixed, &allocation);
19211930
if (ret) {
1922-
error("failed to create default data block groups: %d", ret);
1931+
errno = -ret;
1932+
error("failed to create default data block groups: %m");
19231933
goto error;
19241934
}
19251935

19261936
if (features.incompat_flags & BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2) {
19271937
ret = create_global_roots(trans, nr_global_roots);
19281938
if (ret) {
1929-
error("failed to create global roots: %d", ret);
1939+
errno = -ret;
1940+
error("failed to create global roots: %m");
19301941
goto error;
19311942
}
19321943
}
19331944

19341945
ret = make_root_dir(trans, root);
19351946
if (ret) {
1936-
error("failed to setup the root directory: %d", ret);
1947+
errno = -ret;
1948+
error("failed to setup the root directory: %m");
19371949
goto error;
19381950
}
19391951

@@ -1976,8 +1988,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
19761988
prepare_ctx[i].file, dev_byte_count,
19771989
sectorsize, sectorsize, sectorsize);
19781990
if (ret) {
1979-
error("unable to add %s to filesystem: %d",
1980-
prepare_ctx[i].file, ret);
1991+
errno = -ret;
1992+
error("unable to add %s to filesystem: %m",
1993+
prepare_ctx[i].file);
19811994
goto error;
19821995
}
19831996
if (bconf.verbose >= LOG_INFO) {
@@ -1996,7 +2009,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
19962009
ret = create_raid_groups(trans, root, data_profile,
19972010
metadata_profile, mixed, &allocation);
19982011
if (ret) {
1999-
error("unable to create raid groups: %d", ret);
2012+
errno = -ret;
2013+
error("unable to create raid groups: %m");
20002014
goto out;
20012015
}
20022016

@@ -2031,7 +2045,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
20312045
ret = btrfs_make_subvolume(trans, BTRFS_DATA_RELOC_TREE_OBJECTID,
20322046
false);
20332047
if (ret) {
2034-
error("unable to create data reloc tree: %d", ret);
2048+
errno = -ret;
2049+
error("unable to create data reloc tree: %m");
20352050
goto out;
20362051
}
20372052

@@ -2065,7 +2080,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
20652080
&subvols, compression,
20662081
compression_level);
20672082
if (ret) {
2068-
error("error while filling filesystem: %d", ret);
2083+
errno = -ret;
2084+
error("error while filling filesystem: %m");
20692085
btrfs_abort_transaction(trans, ret);
20702086
goto out;
20712087
}
@@ -2087,8 +2103,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
20872103
ret = btrfs_mkfs_shrink_fs(fs_info, &shrink_size,
20882104
shrink_rootdir);
20892105
if (ret < 0) {
2090-
error("error while shrinking filesystem: %d",
2091-
ret);
2106+
errno = -ret;
2107+
error("error while shrinking filesystem: %m");
20922108
goto out;
20932109
}
20942110
} else {
@@ -2103,15 +2119,17 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
21032119
ret = cleanup_temp_chunks(fs_info, &allocation, data_profile,
21042120
metadata_profile, metadata_profile);
21052121
if (ret < 0) {
2106-
error("failed to cleanup temporary chunks: %d", ret);
2122+
errno = -ret;
2123+
error("failed to cleanup temporary chunks: %m");
21072124
goto out;
21082125
}
21092126

21102127
if (features.runtime_flags & BTRFS_FEATURE_RUNTIME_QUOTA ||
21112128
features.incompat_flags & BTRFS_FEATURE_INCOMPAT_SIMPLE_QUOTA) {
21122129
ret = setup_quota_root(fs_info);
21132130
if (ret < 0) {
2114-
error("failed to initialize quota: %d (%m)", ret);
2131+
errno = -ret;
2132+
error("failed to initialize quota: %m");
21152133
goto out;
21162134
}
21172135
}
@@ -2184,8 +2202,8 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
21842202

21852203
if (!ret && close_ret) {
21862204
ret = close_ret;
2187-
error("failed to close ctree, the filesystem may be inconsistent: %d",
2188-
ret);
2205+
errno = -ret;
2206+
error("failed to close ctree, filesystem may be inconsistent: %m");
21892207
}
21902208

21912209
btrfs_close_all_devices();

0 commit comments

Comments
 (0)