From 471c1fbbd23b21a2592eedadf583babc5d1288a5 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 25 Oct 2017 16:46:06 +0200 Subject: [SERVER] Only start reloading images if no other reload is in progress --- LOCKS | 2 +- src/server/image.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/LOCKS b/LOCKS index a28e42a..7ba01ca 100644 --- a/LOCKS +++ b/LOCKS @@ -10,10 +10,10 @@ track of what's going on. ;) ===== SERVER ===== This is a list of used locks, in the order they have to be aquired if you must hold multiple locks: +remoteCloneLock | reloadLock _clients_lock _clients[].lock integrityQueueLock -remoteCloneLock | reloadLock _images_lock _images[].lock pendingLockConsume diff --git a/src/server/image.c b/src/server/image.c index f277ed0..1905df1 100644 --- a/src/server/image.c +++ b/src/server/image.c @@ -570,9 +570,13 @@ bool image_loadAll(char *path) dnbd3_image_t *imgHandle; if ( path == NULL ) path = _basePath; + if ( pthread_mutex_trylock( &reloadLock ) != 0 ) { + logadd( LOG_MINOR, "Could not (re)load image list, already in progress." ); + return false; + } if ( _removeMissingImages ) { // Check if all loaded images still exist on disk - logadd( LOG_DEBUG1, "Checking for vanished images" ); + logadd( LOG_INFO, "Checking for vanished images" ); spin_lock( &imageListLock ); for ( int i = _num_images - 1; i >= 0; --i ) { if ( _shutdown ) break; @@ -595,6 +599,8 @@ bool image_loadAll(char *path) spin_lock( &imgHandle->lock ); const bool freeImg = ( imgHandle->users == 0 ); spin_unlock( &imgHandle->lock ); + // We unlocked, but the image has been removed from the list already, so + // there's no way the users-counter can increase at this point. if ( freeImg ) { // Image is not in use anymore, free the dangling entry immediately spin_unlock( &imageListLock ); // image_free might do several fs operations; unlock @@ -603,11 +609,13 @@ bool image_loadAll(char *path) } } spin_unlock( &imageListLock ); - if ( _shutdown ) return true; + if ( _shutdown ) { + pthread_mutex_unlock( &reloadLock ); + return true; + } } // Now scan for new images - logadd( LOG_DEBUG1, "Scanning for new or modified images" ); - pthread_mutex_lock( &reloadLock ); + logadd( LOG_INFO, "Scanning for new or modified images" ); ret = image_load_all_internal( path, path ); pthread_mutex_unlock( &reloadLock ); logadd( LOG_INFO, "Finished scanning %s", path ); -- cgit v1.2.3-55-g7522