Skip to content
API Documentation
BastionGuard™
BadBlockMap Class Reference

#include <bad_block_map.hpp>

Public Member Functions

void mark_readable (uint64_t offset, uint64_t length)
void mark_bad (uint64_t offset, uint64_t length)
void mark_slow (uint64_t offset, uint64_t length)
std::vector< BlockRange > readable_ranges () const
std::vector< BlockRange > bad_ranges () const
std::vector< BlockRange > slow_ranges () const
bool is_known_bad (uint64_t offset, uint64_t length) const
void merge_adjacent ()

Private Member Functions

void mark (uint64_t offset, uint64_t length, RangeState state)
std::vector< BlockRange > filtered (RangeState state) const

Private Attributes

std::vector< BlockRange > ranges_

Detailed Description

Definition at line 18 of file bad_block_map.hpp.

Member Function Documentation

◆ bad_ranges()

std::vector< BlockRange > BadBlockMap::bad_ranges ( ) const

Definition at line 21 of file bad_block_map.cpp.

21 {
23}
std::vector< BlockRange > filtered(RangeState state) const

References Bad, and filtered().

Referenced by RescueImager::create_image().

◆ filtered()

std::vector< BlockRange > BadBlockMap::filtered ( RangeState state) const
private

Definition at line 79 of file bad_block_map.cpp.

79 {
80 std::vector<BlockRange> out;
81 for (const auto& range : ranges_) {
82 if (range.state == state) out.push_back(range);
83 }
84 return out;
85}
std::vector< BlockRange > ranges_

References ranges_.

Referenced by bad_ranges(), readable_ranges(), and slow_ranges().

◆ is_known_bad()

bool BadBlockMap::is_known_bad ( uint64_t offset,
uint64_t length ) const

Definition at line 29 of file bad_block_map.cpp.

29 {
30 const uint64_t end = offset + length;
31 for (const auto& range : ranges_) {
32 if (range.state != RangeState::Bad) continue;
33 const uint64_t range_end = range.offset + range.length;
34 if (offset < range_end && end > range.offset) {
35 return true;
36 }
37 }
38 return false;
39}

References Bad, and ranges_.

◆ mark()

void BadBlockMap::mark ( uint64_t offset,
uint64_t length,
RangeState state )
private

Definition at line 73 of file bad_block_map.cpp.

73 {
74 if (length == 0) return;
75 ranges_.push_back(BlockRange{offset, length, state});
77}
void merge_adjacent()

References merge_adjacent(), and ranges_.

Referenced by mark_bad(), mark_readable(), and mark_slow().

◆ mark_bad()

void BadBlockMap::mark_bad ( uint64_t offset,
uint64_t length )

Definition at line 9 of file bad_block_map.cpp.

9 {
10 mark(offset, length, RangeState::Bad);
11}
void mark(uint64_t offset, uint64_t length, RangeState state)

References Bad, and mark().

Referenced by FaultTolerantReader::read_rescue_recursive().

◆ mark_readable()

void BadBlockMap::mark_readable ( uint64_t offset,
uint64_t length )

Definition at line 5 of file bad_block_map.cpp.

5 {
6 mark(offset, length, RangeState::Readable);
7}

References mark(), and Readable.

Referenced by FaultTolerantReader::read_at(), and FaultTolerantReader::read_rescue_recursive().

◆ mark_slow()

void BadBlockMap::mark_slow ( uint64_t offset,
uint64_t length )

Definition at line 13 of file bad_block_map.cpp.

13 {
14 mark(offset, length, RangeState::Slow);
15}

References mark(), and Slow.

Referenced by FaultTolerantReader::read_rescue_recursive().

◆ merge_adjacent()

void BadBlockMap::merge_adjacent ( )

Definition at line 41 of file bad_block_map.cpp.

41 {
42 if (ranges_.empty()) return;
43
44 std::sort(ranges_.begin(), ranges_.end(), [](const BlockRange& a, const BlockRange& b) {
45 if (a.state != b.state) return static_cast<int>(a.state) < static_cast<int>(b.state);
46 return a.offset < b.offset;
47 });
48
49 std::vector<BlockRange> merged;
50 merged.reserve(ranges_.size());
51 merged.push_back(ranges_.front());
52
53 for (size_t i = 1; i < ranges_.size(); ++i) {
54 auto& last = merged.back();
55 const auto& current = ranges_[i];
56 const uint64_t last_end = last.offset + last.length;
57
58 if (last.state == current.state && current.offset <= last_end) {
59 const uint64_t new_end = std::max<uint64_t>(last_end, current.offset + current.length);
60 last.length = new_end - last.offset;
61 } else {
62 merged.push_back(current);
63 }
64 }
65
66 std::sort(merged.begin(), merged.end(), [](const BlockRange& a, const BlockRange& b) {
67 return a.offset < b.offset;
68 });
69
70 ranges_.swap(merged);
71}

References ranges_.

Referenced by RescueImager::create_image(), and mark().

◆ readable_ranges()

std::vector< BlockRange > BadBlockMap::readable_ranges ( ) const

Definition at line 17 of file bad_block_map.cpp.

17 {
19}

References filtered(), and Readable.

◆ slow_ranges()

std::vector< BlockRange > BadBlockMap::slow_ranges ( ) const

Definition at line 25 of file bad_block_map.cpp.

25 {
27}

References filtered(), and Slow.

Referenced by RescueImager::create_image().

Member Data Documentation

◆ ranges_

std::vector<BlockRange> BadBlockMap::ranges_
private

Definition at line 35 of file bad_block_map.hpp.

Referenced by filtered(), is_known_bad(), mark(), and merge_adjacent().


The documentation for this class was generated from the following files: