diff options
author | Simon Rettberg | 2017-11-07 16:39:58 +0100 |
---|---|---|
committer | Simon Rettberg | 2017-11-07 16:39:58 +0100 |
commit | b11e3e4a2804779a1444c4f4ab2f564e960f8474 (patch) | |
tree | ef307052772c732b6e55deb6fed4ca5d589e11da | |
parent | [SERVER] Use multiConnect() to find uplink for replication (diff) | |
download | dnbd3-b11e3e4a2804779a1444c4f4ab2f564e960f8474.tar.gz dnbd3-b11e3e4a2804779a1444c4f4ab2f564e960f8474.tar.xz dnbd3-b11e3e4a2804779a1444c4f4ab2f564e960f8474.zip |
[SERVER] Properly clamp to 4k borders in updateCachemap()
Refs #3231
-rw-r--r-- | src/server/image.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/server/image.c b/src/server/image.c index f0db0a8..d5dd208 100644 --- a/src/server/image.c +++ b/src/server/image.c @@ -110,8 +110,15 @@ void image_updateCachemap(dnbd3_image_t *image, uint64_t start, uint64_t end, co assert( image != NULL ); // This should always be block borders due to how the protocol works, but better be safe // than accidentally mark blocks as cached when they really aren't entirely cached. - end &= ~(uint64_t)(DNBD3_BLOCK_SIZE - 1); - start = (uint64_t)(start + DNBD3_BLOCK_SIZE - 1) & ~(uint64_t)(DNBD3_BLOCK_SIZE - 1); + if ( set ) { + // If we set as cached, move "inwards" in case we're not at 4k border + end &= ~(uint64_t)(DNBD3_BLOCK_SIZE - 1); + start = (uint64_t)(start + DNBD3_BLOCK_SIZE - 1) & ~(uint64_t)(DNBD3_BLOCK_SIZE - 1); + } else { + // If marking as NOT cached, move "outwards" in case we're not at 4k border + start &= ~(uint64_t)(DNBD3_BLOCK_SIZE - 1); + end = (uint64_t)(end + DNBD3_BLOCK_SIZE - 1) & ~(uint64_t)(DNBD3_BLOCK_SIZE - 1); + } bool dirty = false; uint64_t pos = start; spin_lock( &image->lock ); |