summaryrefslogtreecommitdiffstats
path: root/src/server
diff options
context:
space:
mode:
authorSimon Rettberg2017-10-25 16:46:06 +0200
committerSimon Rettberg2017-10-25 16:46:06 +0200
commit471c1fbbd23b21a2592eedadf583babc5d1288a5 (patch)
tree8bc28c055bc993b65db8f0a2b6aa9e15d35a199e /src/server
parent[SERVER] Improve handling of byte stats counters (diff)
downloaddnbd3-471c1fbbd23b21a2592eedadf583babc5d1288a5.tar.gz
dnbd3-471c1fbbd23b21a2592eedadf583babc5d1288a5.tar.xz
dnbd3-471c1fbbd23b21a2592eedadf583babc5d1288a5.zip
[SERVER] Only start reloading images if no other reload is in progress
Diffstat (limited to 'src/server')
-rw-r--r--src/server/image.c16
1 files changed, 12 insertions, 4 deletions
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 );