diff --git a/check/qgroup-verify.c b/check/qgroup-verify.c index 8d49b79a..f0e3c683 100644 --- a/check/qgroup-verify.c +++ b/check/qgroup-verify.c @@ -1521,8 +1521,7 @@ int print_extent_state(struct btrfs_fs_info *info, u64 subvol) tree_blocks = ulist_alloc(0); if (!tree_blocks) { - fprintf(stderr, - "ERROR: Out of memory while allocating ulist.\n"); + error("out of memory while allocating ulist"); return ENOMEM; } @@ -1536,15 +1535,14 @@ int print_extent_state(struct btrfs_fs_info *info, u64 subvol) ret = scan_extents(info, bg->start, bg->start + bg->length - 1); if (ret) { - fprintf(stderr, "ERROR: while scanning extent tree: %d\n", - ret); + error("while scanning extent tree: %d", ret); goto out; } } ret = map_implied_refs(info); if (ret) { - fprintf(stderr, "ERROR: while mapping refs: %d\n", ret); + error("while mapping refs: %d", ret); goto out; } diff --git a/cmds/replace.c b/cmds/replace.c index 00eb725d..0af8856d 100644 --- a/cmds/replace.c +++ b/cmds/replace.c @@ -202,9 +202,7 @@ static int cmd_replace_start(const struct cmd_struct *cmd, status_args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT; ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &status_args); if (ret < 0) { - fprintf(stderr, - "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %m", - path); + error("ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %m", path); if (status_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT) fprintf(stderr, ", %s\n", replace_dev_result2string(status_args.result)); @@ -325,9 +323,7 @@ static int cmd_replace_start(const struct cmd_struct *cmd, ret = ioctl(fdmnt, BTRFS_IOC_DEV_REPLACE, &start_args); if (do_not_background) { if (ret < 0) { - fprintf(stderr, - "ERROR: ioctl(DEV_REPLACE_START) failed on \"%s\": %m", - path); + error("ioctl(DEV_REPLACE_START) failed on \"%s\": %m", path); if (start_args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT) fprintf(stderr, ", %s\n", replace_dev_result2string(start_args.result)); @@ -429,8 +425,7 @@ static int print_replace_status(int fd, const char *path, int once) args.result = BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT; ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args); if (ret < 0) { - fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %m", - path); + error("ioctl(DEV_REPLACE_STATUS) failed on \"%s\": %m", path); if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT) fprintf(stderr, ", %s\n", replace_dev_result2string(args.result)); @@ -579,8 +574,7 @@ static int cmd_replace_cancel(const struct cmd_struct *cmd, ret = ioctl(fd, BTRFS_IOC_DEV_REPLACE, &args); close_file_or_dir(fd, dirstream); if (ret < 0) { - fprintf(stderr, "ERROR: ioctl(DEV_REPLACE_CANCEL) failed on \"%s\": %m", - path); + error("ioctl(DEV_REPLACE_CANCEL) failed on \"%s\": %m", path); if (args.result != BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_RESULT) fprintf(stderr, ", %s\n", replace_dev_result2string(args.result)); diff --git a/cmds/subvolume.c b/cmds/subvolume.c index a1befc63..c28cf8e5 100644 --- a/cmds/subvolume.c +++ b/cmds/subvolume.c @@ -1485,7 +1485,7 @@ static int cmd_subvol_show(const struct cmd_struct *cmd, int argc, char **argv) } if (ret) { - fprintf(stderr, "ERROR: quota query failed: %m"); + error("quota query failed: %m"); goto out; } 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 #include #include -#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; diff --git a/crypto/hash-speedtest.c b/crypto/hash-speedtest.c index 639666be..21e7697e 100644 --- a/crypto/hash-speedtest.c +++ b/crypto/hash-speedtest.c @@ -28,6 +28,7 @@ #include "crypto/crc32c.h" #include "crypto/sha.h" #include "crypto/blake2.h" +#include "common/messages.h" #ifdef __x86_64__ static const int cycles_supported = 1; @@ -206,8 +207,7 @@ int main(int argc, char **argv) { switch (c) { case 'c': if (!cycles_supported) { - fprintf(stderr, - "ERROR: cannot measure cycles on this arch, use --time\n"); + error("cannot measure cycles on this arch, use --time"); return 1; } units = UNITS_CYCLES; @@ -217,14 +217,14 @@ int main(int argc, char **argv) { break; case 'p': if (perf_init() == -1) { - fprintf(stderr, -"ERROR: cannot initialize perf, please check sysctl kernel.perf_event_paranoid: %m\n"); + error( +"cannot initialize perf, please check sysctl kernel.perf_event_paranoid: %m"); return 1; } units = UNITS_PERF; break; default: - fprintf(stderr, "ERROR: unknown option\n"); + error("unknown option"); return 1; } } diff --git a/crypto/hash-vectest.c b/crypto/hash-vectest.c index c0905d71..1540f581 100644 --- a/crypto/hash-vectest.c +++ b/crypto/hash-vectest.c @@ -19,6 +19,7 @@ #include "crypto/crc32c.h" #include "crypto/sha.h" #include "crypto/blake2.h" +#include "common/messages.h" struct hash_testvec { const char *plaintext; @@ -157,7 +158,7 @@ int test_hash(const struct hash_testspec *spec) ret = spec->hash((const u8 *)vec->plaintext, vec->psize, csum); if (ret < 0) { - printf("ERROR: hash %s = %d\n", spec->name, ret); + error("hash %s = %d", spec->name, ret); return 1; } if (memcmp(csum, vec->digest, spec->digest_size) == 0) {