summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2020-03-20 12:08:10 +0100
committerSimon Rettberg2020-03-20 12:08:10 +0100
commita9f5b836d9fddb3e1851c5b0a77c566b0f267ead (patch)
tree559a867b661e477553ce26884a74b00f572d26d3
parent[SHARED] crc32: Don't skip table lookup if PCLMUL is unavailable (diff)
downloaddnbd3-a9f5b836d9fddb3e1851c5b0a77c566b0f267ead.tar.gz
dnbd3-a9f5b836d9fddb3e1851c5b0a77c566b0f267ead.tar.xz
dnbd3-a9f5b836d9fddb3e1851c5b0a77c566b0f267ead.zip
[SERVER] Fix warnings, add assertions
-rw-r--r--src/server/globals.h2
-rw-r--r--src/server/image.c7
-rw-r--r--src/server/uplink.c15
3 files changed, 15 insertions, 9 deletions
diff --git a/src/server/globals.h b/src/server/globals.h
index 5cee92a..08ec303 100644
--- a/src/server/globals.h
+++ b/src/server/globals.h
@@ -103,7 +103,7 @@ struct _dnbd3_uplink
atomic_uint_fast64_t bytesReceived; // Number of bytes received by the uplink since startup.
atomic_uint_fast64_t bytesReceivedLastSave; // Number of bytes received when we last saved the cache map
int queueLen; // length of queue
- uint32_t idleTime; // How many seconds the uplink was idle (apart from keep-alives)
+ int idleTime; // How many seconds the uplink was idle (apart from keep-alives)
dnbd3_queue_entry_t *queue;
atomic_uint_fast32_t queueId;
dnbd3_alt_local_t altData[SERVER_MAX_ALTS];
diff --git a/src/server/image.c b/src/server/image.c
index 0ec1d58..ef40325 100644
--- a/src/server/image.c
+++ b/src/server/image.c
@@ -440,6 +440,7 @@ dnbd3_image_t* image_lock(dnbd3_image_t *image)
mutex_lock( &imageListLock );
for (i = 0; i < _num_images; ++i) {
if ( _images[i] == image ) {
+ assert( _images[i]->id == image->id );
image->users++;
mutex_unlock( &imageListLock );
return image;
@@ -470,6 +471,7 @@ dnbd3_image_t* image_release(dnbd3_image_t *image)
// responsible for freeing it
for (int i = 0; i < _num_images; ++i) {
if ( _images[i] == image ) { // Found, do nothing
+ assert( _images[i]->id == image->id );
mutex_unlock( &imageListLock );
return NULL;
}
@@ -509,6 +511,7 @@ static dnbd3_image_t* image_remove(dnbd3_image_t *image)
mutex_lock( &imageListLock );
for ( int i = _num_images - 1; i >= 0; --i ) {
if ( _images[i] == image ) {
+ assert( _images[i]->id == image->id );
_images[i] = NULL;
mustFree = ( image->users == 0 );
}
@@ -1088,7 +1091,7 @@ bool image_create(char *image, int revision, uint64_t size)
logadd( LOG_ERROR, "revision id invalid: %d", revision );
return false;
}
- char path[PATHLEN], cache[PATHLEN];
+ char path[PATHLEN], cache[PATHLEN+4];
char *lastSlash = strrchr( image, '/' );
if ( lastSlash == NULL ) {
snprintf( path, PATHLEN, "%s/%s.r%d", _basePath, image, revision );
@@ -1099,7 +1102,7 @@ bool image_create(char *image, int revision, uint64_t size)
*lastSlash = '/';
snprintf( path, PATHLEN, "%s/%s.r%d", _basePath, image, revision );
}
- snprintf( cache, PATHLEN, "%s.map", path );
+ snprintf( cache, PATHLEN+4, "%s.map", path );
size = (size + DNBD3_BLOCK_SIZE - 1) & ~(uint64_t)(DNBD3_BLOCK_SIZE - 1);
const int mapsize = IMGSIZE_TO_MAPBYTES(size);
// Write files
diff --git a/src/server/uplink.c b/src/server/uplink.c
index a7f140f..f5ac6ac 100644
--- a/src/server/uplink.c
+++ b/src/server/uplink.c
@@ -403,8 +403,9 @@ bool uplink_request(dnbd3_uplink_t *uplink, dnbd3_client_t *client, uint64_t han
mutex_unlock( &uplink->sendMutex );
logadd( LOG_DEBUG2, "Cannot do direct uplink request: No socket open" );
} else {
- const bool ret = dnbd3_get_block( uplink->current.fd, req.start, req.end - req.start,
- req.handle, COND_HOPCOUNT( uplink->current.version, hops ) );
+ const bool ret = dnbd3_get_block( uplink->current.fd, req.start,
+ (uint32_t)( req.end - req.start ), req.handle,
+ COND_HOPCOUNT( uplink->current.version, hops ) );
if ( unlikely( !ret ) ) {
markRequestUnsent( uplink, req.handle );
uplink->image->problem.uplink = true;
@@ -426,7 +427,8 @@ success_ref:
if ( client != NULL ) {
// Was from client -- potential prefetch
// Same size as this request, but consider end of image...
- uint32_t len = MIN( uplink->image->virtualFilesize - req.end, req.end - req.start );
+ uint32_t len = (uint32_t)MIN( uplink->image->virtualFilesize - req.end,
+ req.end - req.start );
// Also don't prefetch if we cross a hash block border and BGR mode == hashblock
if ( len > 0 && ( _backgroundReplication != BGR_HASHBLOCK
|| req.start % HASH_BLOCK_SIZE == (req.end-1) % HASH_BLOCK_SIZE ) ) {
@@ -592,7 +594,8 @@ static void* uplink_mainloop(void *data)
}
declare_now;
uint32_t timepassed = timing_diff( &lastKeepalive, &now );
- if ( timepassed >= SERVER_UPLINK_KEEPALIVE_INTERVAL || ( timepassed >= 2 && uplink->idleTime < _bgrWindowSize ) ) {
+ if ( timepassed >= SERVER_UPLINK_KEEPALIVE_INTERVAL
+ || ( timepassed >= 2 && uplink->idleTime < _bgrWindowSize ) ) {
lastKeepalive = now;
uplink->idleTime += timepassed;
// Keep-alive
@@ -714,8 +717,8 @@ static void sendQueuedRequests(dnbd3_uplink_t *uplink, bool newOnly)
dnbd3_request_t *hdr = &reqs[count++];
hdr->magic = dnbd3_packet_magic;
hdr->cmd = CMD_GET_BLOCK;
- hdr->size = it->to - it->from;
- hdr->offset_small = it->from;
+ hdr->size = (uint32_t)( it->to - it->from );
+ hdr->offset = it->from; // Offset first, then hops! (union)
hdr->hops = COND_HOPCOUNT( uplink->current.version, it->hopCount );
hdr->handle = it->handle;
fixup_request( *hdr );