From 3de54fac10b3dbdcfc3573e175078c7104837ef3 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Thu, 17 Dec 2015 14:20:12 +0100 Subject: [SERVER] image_markComplete now handles locking so we remove() unlocked --- CMakeLists.txt | 2 +- src/server/image.c | 19 ++++++++++++------- src/server/uplink.c | 14 ++++++-------- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index cf85392..628e36e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ if(CMAKE_C_COMPILER MATCHES "clang") SET(CMAKE_C_FLAGS_RELEASE "-std=c99 -O2 -Wno-unused-result -D_GNU_SOURCE -DNDEBUG -Wno-multichar -fno-strict-aliasing") elseif (CMAKE_C_COMPILER MATCHES "(cc-)|(cc$)") message( "Using (g)cc flags." ) - SET(CMAKE_C_FLAGS_DEBUG "-std=c99 -O0 -g -Wall -Wextra -Wpedantic -D_GNU_SOURCE -D_DEBUG -Wno-multichar -fno-strict-aliasing") + SET(CMAKE_C_FLAGS_DEBUG "-std=c99 -O0 -pg -g -Wall -Wextra -Wpedantic -D_GNU_SOURCE -D_DEBUG -Wno-multichar -fno-strict-aliasing") SET(CMAKE_C_FLAGS_RELEASE "-std=c99 -O2 -Wno-unused-result -D_GNU_SOURCE -DNDEBUG -Wno-multichar -fno-strict-aliasing") else() message( FATAL_ERROR "Could not determine compiler type." ) diff --git a/src/server/image.c b/src/server/image.c index 1d1d6b7..6d486c4 100644 --- a/src/server/image.c +++ b/src/server/image.c @@ -162,17 +162,22 @@ void image_updateCachemap(dnbd3_image_t *image, uint64_t start, uint64_t end, co /** * Mark image as complete by freeing the cache_map and deleting the map file on disk - * DOES NOT LOCK ON THE IMAGE, DO SO BEFORE CALLING + * Locks on: image.lock */ void image_markComplete(dnbd3_image_t *image) { + char mapfile[PATHLEN] = ""; assert( image != NULL ); - if ( image->cache_map == NULL ) return; - free( image->cache_map ); - image->cache_map = NULL; - char mapfile[strlen( image->path ) + 4 + 1]; - sprintf( mapfile, "%s.map", image->path ); - remove( mapfile ); + spin_lock( &image->lock ); + if ( image->cache_map != NULL ) { + free( image->cache_map ); + image->cache_map = NULL; + snprintf( mapfile, PATHLEN, "%s.map", image->path ); + } + spin_unlock( &image->lock ); + if ( mapfile[0] != '\0' ) { + remove( mapfile ); + } } /** diff --git a/src/server/uplink.c b/src/server/uplink.c index fa95fba..8be8e5a 100644 --- a/src/server/uplink.c +++ b/src/server/uplink.c @@ -314,13 +314,14 @@ static void* uplink_mainloop(void *data) if ( waitTime > 5000 ) waitTime = 5000; numSocks = epoll_wait( fdEpoll, events, MAXEVENTS, waitTime ); if ( _shutdown || link->shutdown ) goto cleanup; - if ( numSocks < 0 ) { // Error? + if ( numSocks == -1 ) { // Error? + if ( errno == EINTR ) continue; logadd( LOG_DEBUG1, "epoll_wait() error %d", (int)errno); usleep( 10000 ); continue; } // Check all events - for (i = 0; i < numSocks; ++i) { + for ( i = 0; i < numSocks; ++i ) { // Check for errors.... if ( (events[i].events & (EPOLLERR | EPOLLHUP | EPOLLRDHUP)) || !(events[i].events & EPOLLIN) ) { if ( events[i].data.fd == link->signal ) { @@ -362,7 +363,7 @@ static void* uplink_mainloop(void *data) const time_t now = time( NULL ); // Send keep alive if nothing is happening if ( link->fd != -1 && link->replicationHandle == 0 && now > nextKeepalive ) { - nextKeepalive = now + 29; + nextKeepalive = now + 20; if ( !uplink_sendKeepalive( link->fd ) ) { const int fd = link->fd; link->fd = -1; @@ -379,11 +380,8 @@ static void* uplink_mainloop(void *data) if ( image_isComplete( link->image ) ) { // Quit work if image is complete logadd( LOG_INFO, "Replication of %s complete.", link->image->lower_name ); - if ( spin_trylock( &link->image->lock ) == 0 ) { - image_markComplete( link->image ); - spin_unlock( &link->image->lock ); - goto cleanup; - } + image_markComplete( link->image ); + goto cleanup; } else { // Not complete - do measurement altservers_findUplink( link ); // This will set RTT_INPROGRESS (synchronous) -- cgit v1.2.3-55-g7522