diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/server/altservers.c | 12 | ||||
-rw-r--r-- | src/server/altservers.h | 2 | ||||
-rw-r--r-- | src/server/globals.h | 2 | ||||
-rw-r--r-- | src/server/image.c | 18 |
4 files changed, 19 insertions, 15 deletions
diff --git a/src/server/altservers.c b/src/server/altservers.c index 17e8e4b..8962e15 100644 --- a/src/server/altservers.c +++ b/src/server/altservers.c @@ -67,9 +67,11 @@ int altservers_load() while ( !feof( fp ) ) { if ( fgets( buffer, 1000, fp ) == NULL ) break; int isPrivate = FALSE; - for (line = buffer;;) { // Trim left and scan for "-" prefix + int isClientOnly = FALSE; + for (line = buffer; *line != '\0'; ) { // Trim left and scan for "-" prefix if ( *line == '-' ) isPrivate = TRUE; - else if ( *line != ' ' || *line != '\t' ) break; + else if ( *line == '+' ) isClientOnly = TRUE; + else if ( *line != ' ' && *line != '\t' ) break; line++; } trim_right( line ); @@ -80,14 +82,14 @@ int altservers_load() memlogf( "[WARNING] Invalid entry in alt-servers file ignored: '%s'", line ); continue; } - if ( altservers_add( &host, space, isPrivate ) ) ++count; + if ( altservers_add( &host, space, isPrivate, isClientOnly ) ) ++count; } fclose( fp ); printf( "[DEBUG] Added %d alt servers\n", count ); return count; } -int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate) +int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate, const int isClientOnly) { int i, freeSlot = -1; spin_lock( &altServersLock ); @@ -109,6 +111,7 @@ int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate) } altServers[freeSlot].host = *host; altServers[freeSlot].isPrivate = isPrivate; + altServers[freeSlot].isClientOnly = isClientOnly; if ( comment != NULL ) snprintf( altServers[freeSlot].comment, COMMENT_LENGTH, "%s", comment ); spin_unlock( &altServersLock ); return TRUE; @@ -236,6 +239,7 @@ int altservers_get(dnbd3_host_t *output, int size) for (i = 0; i < numAltServers; ++i) { if ( altServers[i].host.type == 0 ) continue; // Slot is empty if ( _proxyPrivateOnly && !altServers[i].isPrivate ) continue; // Config says to consider private alt-servers only? ignore! + if ( altServers[i].isClientOnly ) continue; if ( altServers[i].numFails > SERVER_MAX_UPLINK_FAILS // server failed X times in a row && now - altServers[i].lastFail > SERVER_BAD_UPLINK_IGNORE ) continue; // and last fail was not too long ago? ignore! // server seems ok, include in output and reset its fail counter diff --git a/src/server/altservers.h b/src/server/altservers.h index e07afce..de7643c 100644 --- a/src/server/altservers.h +++ b/src/server/altservers.h @@ -7,7 +7,7 @@ void altservers_init(); int altservers_load(); -int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate); +int altservers_add(dnbd3_host_t *host, const char *comment, const int isPrivate, const int isClientOnly); void altservers_findUplink(dnbd3_connection_t *uplink); diff --git a/src/server/globals.h b/src/server/globals.h index 921398d..7d333e0 100644 --- a/src/server/globals.h +++ b/src/server/globals.h @@ -73,7 +73,7 @@ typedef struct dnbd3_host_t host; int rtt[SERVER_RTT_PROBES]; int rttIndex; - int isPrivate; + int isPrivate, isClientOnly; time_t lastFail; int numFails; } dnbd3_alt_server_t; diff --git a/src/server/image.c b/src/server/image.c index 37eb11c..53b8aea 100644 --- a/src/server/image.c +++ b/src/server/image.c @@ -317,8 +317,11 @@ void image_release(dnbd3_image_t *image) return; } } + spin_unlock( &image->lock ); + spin_unlock( &_images_lock ); + // Not found, free + image_free( image ); } - // Not found, free spin_unlock( &image->lock ); spin_unlock( &_images_lock ); } @@ -366,7 +369,6 @@ void image_killUplinks() /** * Free image. DOES NOT check if it's in use. * Indirectly locks on image.lock, uplink.queueLock - * DO NOT lock on the image when calling. */ dnbd3_image_t* image_free(dnbd3_image_t *image) { @@ -1160,28 +1162,26 @@ static int image_ensureDiskSpace(uint64_t size) dnbd3_image_t *oldest = NULL; time_t mtime = 0; int i; - spin_lock( &_images_lock ); for (i = 0; i < _num_images; ++i) { if ( _images[i] == NULL ) continue; dnbd3_image_t *current = image_lock( _images[i] ); if ( current == NULL ) continue; if ( current->users == 1 ) { // Just from the lock above - if ( oldest == NULL || oldest->atime > _images[i]->atime ) { + if ( oldest == NULL || oldest->atime > current->atime ) { // Oldest access time so far - oldest = _images[i]; + oldest = current; if ( oldest->atime == 0 ) mtime = file_lastModification( oldest->path ); - } else if ( oldest->atime == 0 && _images[i]->atime == 0 ) { + } else if ( oldest->atime == 0 && current->atime == 0 ) { // Oldest access time is 0 (=never used since server startup), so take file modification time into account - const time_t m = file_lastModification( _images[i]->path ); + const time_t m = file_lastModification(current->path ); if ( m < mtime ) { mtime = m; - oldest = _images[i]; + oldest = current; } } } image_release( current ); } - spin_unlock( &_images_lock ); if ( oldest == NULL ) return FALSE; oldest = image_lock( oldest ); if ( oldest == NULL ) return FALSE; |