From faeb780fb33f79092f27b92dc5bbc13a8e7d6cbd Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 30 Jan 2015 16:14:59 +0100 Subject: [SERVER] Use shared file handle for reading --- src/server/integrity.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'src/server/integrity.c') diff --git a/src/server/integrity.c b/src/server/integrity.c index 547f8d3..efc54c5 100644 --- a/src/server/integrity.c +++ b/src/server/integrity.c @@ -121,9 +121,9 @@ static void* integrity_main(void * data UNUSED) if ( checkQueue[i].image == NULL ) continue; dnbd3_image_t * const image = image_lock( checkQueue[i].image ); checkQueue[i].image = NULL; + if ( i + 1 == queueLen ) queueLen--; if ( image == NULL ) continue; // We have the image. Call image_release() some time - if ( i + 1 == queueLen ) queueLen--; spin_lock( &image->lock ); if ( image->crc32 != NULL && image->filesize != 0 ) { int const blocks[2] = { checkQueue[i].block, -1 }; @@ -137,15 +137,11 @@ static void* integrity_main(void * data UNUSED) } memcpy( buffer, image->crc32, required ); spin_unlock( &image->lock ); - int fd = open( image->path, O_RDONLY ); - if ( fd >= 0 ) { - if ( image_checkBlocksCrc32( fd, (uint32_t*)buffer, blocks, fileSize ) ) { - //printf( "[DEBUG] CRC check of block %d for %s succeeded :-)\n", blocks[0], image->lower_name ); - } else { - memlogf( "[WARNING] Hash check for block %d of %s failed!", blocks[0], image->lower_name ); - image_updateCachemap( image, blocks[0] * HASH_BLOCK_SIZE, (blocks[0] + 1) * HASH_BLOCK_SIZE, false ); - } - close( fd ); + if ( image_checkBlocksCrc32( image->readFd, (uint32_t*)buffer, blocks, fileSize ) ) { + //printf( "[DEBUG] CRC check of block %d for %s succeeded :-)\n", blocks[0], image->lower_name ); + } else { + memlogf( "[WARNING] Hash check for block %d of %s failed!", blocks[0], image->lower_name ); + image_updateCachemap( image, blocks[0] * HASH_BLOCK_SIZE, (blocks[0] + 1) * HASH_BLOCK_SIZE, false ); } pthread_mutex_lock( &integrityQueueLock ); } else { -- cgit v1.2.3-55-g7522