uint64_t end = offset + length;
while (i != buffer_map.end()) {
Buffer *b = i->second.get();
- if (b->offset >= offset + length) {
+ if (b->offset >= end) {
break;
}
if (b->offset < offset) {
uint64_t front = offset - b->offset;
- if (b->offset + b->length > offset + length) {
+ if (b->end() > end) {
// drop middle (split)
- uint64_t tail = b->offset + b->length - (offset + length);
+ uint64_t tail = b->end() - end;
if (b->data.length()) {
bufferlist bl;
bl.substr_of(b->data, b->length - tail, tail);
} else {
_add_buffer(new Buffer(this, b->state, b->seq, end, tail));
}
+ assert(cache->buffer_size >= b->length - front);
cache->buffer_size -= b->length - front;
b->truncate(front);
cache->_audit_lru("discard end 1");
return;
} else {
// drop tail
+ assert(cache->buffer_size >= b->length - front);
cache->buffer_size -= b->length - front;
b->truncate(front);
++i;