diff options
author | Simon Rettberg | 2020-03-06 11:34:58 +0100 |
---|---|---|
committer | Simon Rettberg | 2020-03-06 11:48:39 +0100 |
commit | 080a06ab22c8ac0841c06fe52ab4dbc982beafc1 (patch) | |
tree | b33de9bc1cb0c974810dc187918eb5a1cfca0165 /src/server/uplink.c | |
parent | [SERVER] Add timer task for saving cache maps (diff) | |
download | dnbd3-080a06ab22c8ac0841c06fe52ab4dbc982beafc1.tar.gz dnbd3-080a06ab22c8ac0841c06fe52ab4dbc982beafc1.tar.xz dnbd3-080a06ab22c8ac0841c06fe52ab4dbc982beafc1.zip |
[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.
Diffstat (limited to 'src/server/uplink.c')
-rw-r--r-- | src/server/uplink.c | 10 |
1 files changed, 8 insertions, 2 deletions
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 ) ) { |