[thin_trim] more bug fixing

This commit is contained in:
Joe Thornber 2016-04-08 17:07:04 +01:00
parent 77902767d7
commit 3fb4177656

View File

@ -39,8 +39,6 @@ namespace {
range[0] = block_to_byte(b); range[0] = block_to_byte(b);
range[1] = block_to_byte(e) - range[0]; range[1] = block_to_byte(e) - range[0];
cerr << "emitting discard for blocks (" << b << ", " << e << "]\n";
if (ioctl(fd_, BLKDISCARD, &range)) if (ioctl(fd_, BLKDISCARD, &range))
throw runtime_error("discard ioctl failed"); throw runtime_error("discard ioctl failed");
} }
@ -99,9 +97,14 @@ namespace {
highest_ = b; highest_ = b;
if (count) { if (count) {
if (last_referenced_ && (b > *last_referenced_ + 1)) if (last_referenced_) {
if (b > *last_referenced_ + 1)
emitter_.emit(*last_referenced_ + 1, b); emitter_.emit(*last_referenced_ + 1, b);
} else if (b > 0) {
emitter_.emit(0, b);
}
last_referenced_ = b; last_referenced_ = b;
} }
} }
@ -109,7 +112,7 @@ namespace {
void complete() { void complete() {
if (last_referenced_) { if (last_referenced_) {
if (*last_referenced_ != *highest_) if (*last_referenced_ != *highest_)
emitter_.emit(*last_referenced_, *highest_ + 1ull); emitter_.emit(*last_referenced_ + 1ull, *highest_ + 1ull);
} else if (highest_) } else if (highest_)
emitter_.emit(0ull, *highest_ + 1); emitter_.emit(0ull, *highest_ + 1);
@ -122,17 +125,13 @@ namespace {
}; };
int trim(string const &metadata_dev, string const &data_dev) { int trim(string const &metadata_dev, string const &data_dev) {
cerr << "in trim\n";
// We can trim any block that has zero count in the data // We can trim any block that has zero count in the data
// space map. // space map.
block_manager<>::ptr bm = open_bm(metadata_dev, block_manager<>::READ_ONLY); block_manager<>::ptr bm = open_bm(metadata_dev, block_manager<>::READ_ONLY);
metadata md(bm); metadata md(bm);
if (!md.data_sm_->get_nr_free()) { if (!md.data_sm_->get_nr_free())
cerr << "All data blocks allocated, nothing to discard\n";
return 0; return 0;
}
discard_emitter de(data_dev, md.sb_.data_block_size_, discard_emitter de(data_dev, md.sb_.data_block_size_,
md.data_sm_->get_nr_blocks()); md.data_sm_->get_nr_blocks());