aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorDavid Sterba <dsterba@suse.com>2022-09-16 19:29:25 +0200
committerDavid Sterba <dsterba@suse.com>2022-10-11 09:08:07 +0200
commit0e38e1c4f27ee3fb5a97165e498acf8e4abe269d (patch)
treee8bb6ced83f6b062510a8191018adf7facc8a1cd /common
parentb5aac254c71dbf92d4cf6ad77ba904350843861e (diff)
downloadbtrfs-progs-0e38e1c4f27ee3fb5a97165e498acf8e4abe269d.tar.gz
btrfs-progs: use error helper for messages in non-kernel code
Lots of code still uses fprintf(stderr, "...") that should be the error() helper. The kernel-shared code is left out of the conversion for now. Signed-off-by: David Sterba <dsterba@suse.com>
Diffstat (limited to 'common')
-rw-r--r--common/send-utils.c9
-rw-r--r--common/string-utils.c11
-rw-r--r--common/utils.c10
3 files changed, 13 insertions, 17 deletions
diff --git a/common/send-utils.c b/common/send-utils.c
index b7c681de..85c7f6ee 100644
--- a/common/send-utils.c
+++ b/common/send-utils.c
@@ -42,7 +42,7 @@ static int btrfs_get_root_id_by_sub_path(int mnt_fd, const char *sub_path,
subvol_fd = openat(mnt_fd, sub_path, O_RDONLY);
if (subvol_fd < 0) {
ret = -errno;
- fprintf(stderr, "ERROR: open %s failed: %m\n", sub_path);
+ error("open %s failed: %m", sub_path);
return ret;
}
@@ -87,8 +87,7 @@ static int btrfs_read_root_item_raw(int mnt_fd, u64 root_id, size_t buf_len,
while (1) {
ret = ioctl(mnt_fd, BTRFS_IOC_TREE_SEARCH, &args);
if (ret < 0) {
- fprintf(stderr,
- "ERROR: can't perform the search - %m\n");
+ error("can't perform the search: %m");
return 0;
}
/* the ioctl returns the number of item it found in nr_items */
@@ -116,8 +115,8 @@ static int btrfs_read_root_item_raw(int mnt_fd, u64 root_id, size_t buf_len,
btrfs_search_header_type(sh) == BTRFS_ROOT_ITEM_KEY) {
if (btrfs_search_header_len(sh) > buf_len) {
/* btrfs-progs is too old for kernel */
- fprintf(stderr,
- "ERROR: buf for read_root_item_raw() is too small, get newer btrfs tools!\n");
+ error(
+ "buf for read_root_item_raw() is too small, get newer btrfs tools");
return -EOVERFLOW;
}
memcpy(buf, item, btrfs_search_header_len(sh));
diff --git a/common/string-utils.c b/common/string-utils.c
index 016c96ac..62f2d0ed 100644
--- a/common/string-utils.c
+++ b/common/string-utils.c
@@ -18,7 +18,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
-#include "string-utils.h"
+#include "common/string-utils.h"
+#include "common/messages.h"
int string_is_numerical(const char *str)
{
@@ -53,8 +54,7 @@ u64 arg_strtou64(const char *str)
value = strtoull(str, &ptr_parse_end, 0);
if (ptr_parse_end && *ptr_parse_end != '\0') {
- fprintf(stderr, "ERROR: %s is not a valid numeric value.\n",
- str);
+ error("%s is not a valid numeric value", str);
exit(1);
}
@@ -63,12 +63,11 @@ u64 arg_strtou64(const char *str)
* unexpected number to us, so let's do the check ourselves.
*/
if (str[0] == '-') {
- fprintf(stderr, "ERROR: %s: negative value is invalid.\n",
- str);
+ error("%s: negative value is invalid", str);
exit(1);
}
if (value == ULLONG_MAX) {
- fprintf(stderr, "ERROR: %s is too large.\n", str);
+ error("%s is too large", str);
exit(1);
}
return value;
diff --git a/common/utils.c b/common/utils.c
index 7edfe13c..974acfc8 100644
--- a/common/utils.c
+++ b/common/utils.c
@@ -367,17 +367,15 @@ int test_num_disk_vs_raid(u64 metadata_profile, u64 data_profile,
warning("DUP is not recommended on filesystem with multiple devices");
}
if (metadata_profile & ~allowed) {
- fprintf(stderr,
- "ERROR: unable to create FS with metadata profile %s "
- "(have %llu devices but %d devices are required)\n",
+ error("unable to create FS with metadata profile %s "
+ "(have %llu devices but %d devices are required)",
btrfs_group_profile_str(metadata_profile), dev_cnt,
btrfs_bg_type_to_devs_min(metadata_profile));
return 1;
}
if (data_profile & ~allowed) {
- fprintf(stderr,
- "ERROR: unable to create FS with data profile %s "
- "(have %llu devices but %d devices are required)\n",
+ error("ERROR: unable to create FS with data profile %s "
+ "(have %llu devices but %d devices are required)",
btrfs_group_profile_str(data_profile), dev_cnt,
btrfs_bg_type_to_devs_min(data_profile));
return 1;