From 080a06ab22c8ac0841c06fe52ab4dbc982beafc1 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Fri, 6 Mar 2020 11:34:58 +0100 Subject: [SERVER] Reload cache maps periodically for local images If an image is incomplete, but has no upstream server that can be used for replication, reload the cache map from disk periodically, in case some other server instance is writing to the image. --- src/server/uplink.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/server/uplink.c') diff --git a/src/server/uplink.c b/src/server/uplink.c index e5ab9c0..e644e56 100644 --- a/src/server/uplink.c +++ b/src/server/uplink.c @@ -80,6 +80,8 @@ bool uplink_init(dnbd3_image_t *image, int sock, dnbd3_host_t *host, int version { if ( !_isProxy || _shutdown ) return false; assert( image != NULL ); + if ( sock == -1 && !altservers_imageHasAltServers( image->name ) ) + return false; // Nothing to do mutex_lock( &image->lock ); dnbd3_uplink_t *uplink = ref_get_uplink( &image->uplinkref ); if ( uplink != NULL ) { @@ -103,7 +105,7 @@ bool uplink_init(dnbd3_image_t *image, int sock, dnbd3_host_t *host, int version uplink->image = image; uplink->bytesReceived = 0; uplink->bytesReceivedLastSave = 0; - uplink->idleTime = 0; + uplink->idleTime = SERVER_UPLINK_IDLE_TIMEOUT - 90; uplink->queueLen = 0; uplink->cacheFd = -1; uplink->signal = signal_new(); @@ -634,7 +636,11 @@ static void* uplink_mainloop(void *data) } cleanup: ; dnbd3_image_t *image = uplink->image; - image->mapDirty = true; // Force writeout of cache map + dnbd3_cache_map_t *cache = ref_get_cachemap( image ); + if ( cache != NULL ) { + cache->dirty = true; // Force writeout of cache map + ref_put( &cache->reference ); + } mutex_lock( &image->lock ); bool exp = false; if ( atomic_compare_exchange_strong( &uplink->shutdown, &exp, true ) ) { -- cgit v1.2.3-55-g7522