From 053ca3b9a9601467d5ce30c56c3cea078c897f57 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 4 Jul 2018 14:39:43 +0200 Subject: [SERVER] Refactor uplink/cache handling, improve crc checking The cacheFd is now moved to the uplink data structure and will only be handled by the uplink thread. The integrity checker now supports checking all blocks of an image. This will be triggered automatically whenever a check for a single block failed. Also, if a crc check on startup fails, the image won't be discarded anymore, but rather a full check will be initiated. Furthermore, when calling image_updateCacheMap() on an image that was previously complete, the cache map will now be re-initialized, and a new uplink connection created. --- src/server/altservers.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) (limited to 'src/server/altservers.c') diff --git a/src/server/altservers.c b/src/server/altservers.c index 4a2b8d5..575b849 100644 --- a/src/server/altservers.c +++ b/src/server/altservers.c @@ -18,7 +18,6 @@ static dnbd3_signal_t* runSignal = NULL; static dnbd3_alt_server_t altServers[SERVER_MAX_ALTS]; static int numAltServers = 0; static pthread_spinlock_t altServersLock; -static bool initDone = false; static pthread_t altThread; @@ -31,6 +30,12 @@ void altservers_init() // Init spinlock spin_init( &pendingLockWrite, PTHREAD_PROCESS_PRIVATE ); spin_init( &altServersLock, PTHREAD_PROCESS_PRIVATE ); + // Init signal + runSignal = signal_new(); + if ( runSignal == NULL ) { + logadd( LOG_ERROR, "Error creating signal object. Uplink feature unavailable." ); + exit( EXIT_FAILURE ); + } memset( altServers, 0, SERVER_MAX_ALTS * sizeof(dnbd3_alt_server_t) ); if ( 0 != thread_create( &altThread, NULL, &altservers_main, (void *)NULL ) ) { logadd( LOG_ERROR, "Could not start altservers connector thread" ); @@ -44,12 +49,11 @@ void altservers_init() pending[i] = NULL; } spin_unlock( &pendingLockWrite ); - initDone = true; } void altservers_shutdown() { - if ( !initDone ) return; + if ( runSignal == NULL ) return; signal_call( runSignal ); // Wake altservers thread up thread_join( altThread, NULL ); } @@ -407,18 +411,11 @@ static void *altservers_main(void *data UNUSED) dnbd3_host_t servers[ALTS + 1]; serialized_buffer_t serialized; struct timespec start, end; - ticks nextCacheMapSave, nextCloseUnusedFd; + ticks nextCloseUnusedFd; setThreadName( "altserver-check" ); blockNoncriticalSignals(); - timing_gets( &nextCacheMapSave, 90 ); timing_gets( &nextCloseUnusedFd, 900 ); - // Init signal - runSignal = signal_new(); - if ( runSignal == NULL ) { - logadd( LOG_WARNING, "error creating signal object. Uplink feature unavailable." ); - goto cleanup; - } // LOOP while ( !_shutdown ) { // Wait 5 seconds max. @@ -598,13 +595,8 @@ static void *altservers_main(void *data UNUSED) pthread_mutex_unlock( &pendingLockConsume ); } // Save cache maps of all images if applicable - // TODO: Has nothing to do with alt servers really, maybe move somewhere else? declare_now; - if ( timing_reached( &nextCacheMapSave, &now ) ) { - timing_gets( &nextCacheMapSave, SERVER_CACHE_MAP_SAVE_INTERVAL ); - image_saveAllCacheMaps(); - } - // TODO: More random crap + // TODO: Has nothing to do with alt servers really, maybe move somewhere else? if ( _closeUnusedFd && timing_reached( &nextCloseUnusedFd, &now ) ) { timing_gets( &nextCloseUnusedFd, 900 ); image_closeUnusedFd(); -- cgit v1.2.3-55-g7522