diff options
author | Simon Rettberg | 2024-07-04 16:21:17 +0200 |
---|---|---|
committer | Simon Rettberg | 2024-07-04 16:21:17 +0200 |
commit | 1b3068f57a7c23e5ab86744afc2690140245698f (patch) | |
tree | ab89f54e00362712d123894ec42814c07173a4fd | |
parent | [server] Avoid redefining container_of (diff) | |
download | dnbd3-1b3068f57a7c23e5ab86744afc2690140245698f.tar.gz dnbd3-1b3068f57a7c23e5ab86744afc2690140245698f.tar.xz dnbd3-1b3068f57a7c23e5ab86744afc2690140245698f.zip |
[SERVER] integrity: Add comments, line wraps, add check for full scan
-rw-r--r-- | src/server/integrity.c | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/server/integrity.c b/src/server/integrity.c index 91e53b8..5a436ee 100644 --- a/src/server/integrity.c +++ b/src/server/integrity.c @@ -24,7 +24,7 @@ typedef struct { dnbd3_image_t *image; // Image to check int block; // Block to check - int count; // How many blocks to check starting at .block + int count; // How many blocks to check starting at .block (CHECK_ALL for entire image) } queue_entry; static pthread_t thread; @@ -91,19 +91,36 @@ start_over: for (int i = 0; i < queueLen; ++i) { if ( freeSlot == -1 && checkQueue[i].image == NULL ) { freeSlot = i; - } else if ( checkQueue[i].image == image && checkQueue[i].block <= block ) { + continue; + } + if ( checkQueue[i].image != image ) { + continue; + } + // There is an existing check request for the given image, see if we can merge + if ( block == -1 ) { + // New request is supposed to check entire image, reset existing queue item + checkQueue[i].block = 0; + checkQueue[i].count = CHECK_ALL; + mutex_unlock( &integrityQueueLock ); + return; + } + if ( checkQueue[i].block <= block ) { + // The block to check is after the block to check in queue if ( checkQueue[i].count == CHECK_ALL ) { - logadd( LOG_DEBUG2, "Dominated by full image scan request (%d/%d) (at %d)", i, queueLen, checkQueue[i].block ); + logadd( LOG_DEBUG2, "Dominated by full image scan request (%d/%d) (at %d)", + i, queueLen, checkQueue[i].block ); } else if ( checkQueue[i].block + checkQueue[i].count == block ) { checkQueue[i].count += 1; - logadd( LOG_DEBUG2, "Attaching to existing check request (%d/%d) (at %d, %d to go)", i, queueLen, checkQueue[i].block, checkQueue[i].count ); + logadd( LOG_DEBUG2, "Attaching to existing check request (%d/%d) (at %d, %d to go)", + i, queueLen, checkQueue[i].block, checkQueue[i].count ); } else if ( checkQueue[i].block + checkQueue[i].count > block ) { - logadd( LOG_DEBUG2, "Dominated by existing check request (%d/%d) (at %d, %d to go)", i, queueLen, checkQueue[i].block, checkQueue[i].count ); + logadd( LOG_DEBUG2, "Dominated by existing check request (%d/%d) (at %d, %d to go)", + i, queueLen, checkQueue[i].block, checkQueue[i].count ); } else { - continue; + continue; // Keep looking } mutex_unlock( &integrityQueueLock ); - return; + return; // Nothing to do for one of the reasons above } } if ( freeSlot == -1 ) { |