From 773afad3e6b8507bf53452e3154906af848c07f3 Mon Sep 17 00:00:00 2001 From: Qu Wenruo Date: Thu, 26 Aug 2021 14:40:35 +0800 Subject: [PATCH] btrfs-progs: slightly enhance btrfs_format_csum() - Change it void The old one always return csum_size. - Use snprintf() Signed-off-by: Qu Wenruo Signed-off-by: David Sterba --- check/main.c | 17 +++++++++++++++++ common/utils.c | 14 ++++++++------ common/utils.h | 2 +- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/check/main.c b/check/main.c index a27efe56..e27b8c45 100644 --- a/check/main.c +++ b/check/main.c @@ -7959,6 +7959,23 @@ static int record_unaligned_extent_rec(struct extent_record *rec) } } + if (skip) + continue; + + /* + * If we repaired something and restarted we could potentially + * try to add this unaligned record multiple times, so check + * before we add a new one. + */ + list_for_each_entry(urec, &dest_root->unaligned_extent_recs, list) { + if (urec->objectid == dest_root->objectid && + urec->owner == dback->owner && + urec->bytenr == rec->start) { + skip = true; + break; + } + } + if (skip) continue; diff --git a/common/utils.c b/common/utils.c index e944c43a..7e213146 100644 --- a/common/utils.c +++ b/common/utils.c @@ -385,18 +385,20 @@ enum btrfs_csum_type parse_csum_type(const char *s) return 0; } -int btrfs_format_csum(u16 csum_type, const u8 *data, char *output) +void btrfs_format_csum(u16 csum_type, const u8 *data, char *output) { int i; + int cur = 0; const int csum_size = btrfs_csum_type_size(csum_type); - sprintf(output, "0x"); + output[0] = '\0'; + snprintf(output, BTRFS_CSUM_STRING_LEN, "0x"); + cur += strlen("0x"); for (i = 0; i < csum_size; i++) { - output += 2; - sprintf(output, "%02x", data[i]); + snprintf(output + cur, BTRFS_CSUM_STRING_LEN - cur, "%02x", + data[i]); + cur += 2; } - - return csum_size; } int get_device_info(int fd, u64 devid, diff --git a/common/utils.h b/common/utils.h index c5f57cc5..45a4cea3 100644 --- a/common/utils.h +++ b/common/utils.h @@ -46,7 +46,7 @@ enum btrfs_csum_type parse_csum_type(const char *s); /* 2 for "0x", 2 for each byte, plus nul */ #define BTRFS_CSUM_STRING_LEN (2 + 2 * BTRFS_CSUM_SIZE + 1) -int btrfs_format_csum(u16 csum_type, const u8 *data, char *output); +void btrfs_format_csum(u16 csum_type, const u8 *data, char *output); u64 parse_size_from_string(const char *s); u64 parse_qgroupid(const char *p); u64 arg_strtou64(const char *str);