From 0349e9c9e250c52fa9ba24c2bc0a882e777cf5a7 Mon Sep 17 00:00:00 2001 From: Ming-Hung Tsai Date: Wed, 12 Aug 2020 10:53:10 +0800 Subject: [PATCH] [space-maps/disk] Show the block address in exception string --- persistent-data/space-maps/disk.cc | 32 ++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/persistent-data/space-maps/disk.cc b/persistent-data/space-maps/disk.cc index 614a38d..6e6fc71 100644 --- a/persistent-data/space-maps/disk.cc +++ b/persistent-data/space-maps/disk.cc @@ -43,11 +43,19 @@ namespace { bitmap_header const *data = reinterpret_cast(raw); crc32c sum(BITMAP_CSUM_XOR); sum.append(&data->not_used, MD_BLOCK_SIZE - sizeof(uint32_t)); - if (sum.get_sum() != to_cpu(data->csum)) - throw checksum_error("bad checksum in space map bitmap"); + if (sum.get_sum() != to_cpu(data->csum)) { + std::ostringstream out; + out << "bad checksum in space map bitmap (block " + << location << ")"; + throw checksum_error(out.str()); + } - if (to_cpu(data->blocknr) != location) - throw checksum_error("bad block nr in space map bitmap"); + if (to_cpu(data->blocknr) != location) { + std::ostringstream out; + out << "bad block nr in space map bitmap (block " + << location << ")"; + throw checksum_error(out.str()); + } } virtual bool check_raw(void const *raw) const { @@ -77,11 +85,19 @@ namespace { metadata_index const *mi = reinterpret_cast(raw); crc32c sum(INDEX_CSUM_XOR); sum.append(&mi->padding_, MD_BLOCK_SIZE - sizeof(uint32_t)); - if (sum.get_sum() != to_cpu(mi->csum_)) - throw checksum_error("bad checksum in metadata index block"); + if (sum.get_sum() != to_cpu(mi->csum_)) { + std::ostringstream out; + out << "bad checksum in metadata index block (block " + << location << ")"; + throw checksum_error(out.str()); + } - if (to_cpu(mi->blocknr_) != location) - throw checksum_error("bad block nr in metadata index block"); + if (to_cpu(mi->blocknr_) != location) { + std::ostringstream out; + out << "bad block nr in metadata index block (block " + << location << ")"; + throw checksum_error(out.str()); + } } virtual bool check_raw(void const *raw) const {