summaryrefslogtreecommitdiffstats
path: root/src/server/net.c
diff options
context:
space:
mode:
authorSimon Rettberg2019-08-29 23:05:26 +0200
committerSimon Rettberg2019-08-29 23:05:26 +0200
commit9d2d9c6de358b2cf1a602c999d2e0a7a664610f7 (patch)
treedf1beba5f5aa85e09c918cb139616980d08d5996 /src/server/net.c
parent[SERVER] Use weakref for cache maps (diff)
downloaddnbd3-9d2d9c6de358b2cf1a602c999d2e0a7a664610f7.tar.gz
dnbd3-9d2d9c6de358b2cf1a602c999d2e0a7a664610f7.tar.xz
dnbd3-9d2d9c6de358b2cf1a602c999d2e0a7a664610f7.zip
[SERVER] Tear down whole uplink on idle timeout
Keeping the uplink thread around forever even though we disconnected from the upstream server seems wasteful. Get rid of this and rear down the uplink entirely.
Diffstat (limited to 'src/server/net.c')
-rw-r--r--src/server/net.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/server/net.c b/src/server/net.c
index 12bcdad..00c9a8d 100644
--- a/src/server/net.c
+++ b/src/server/net.c
@@ -270,18 +270,15 @@ void* net_handleNewConnection(void *clientPtr)
bOk = true;
if ( image->ref_cacheMap != NULL ) {
dnbd3_uplink_t *uplink = ref_get_uplink( &image->uplinkref );
- if ( uplink == NULL || uplink->cacheFd == -1 || uplink->queueLen > SERVER_UPLINK_QUEUELEN_THRES ) {
+ if ( uplink != NULL && ( uplink->cacheFd == -1 || uplink->queueLen > SERVER_UPLINK_QUEUELEN_THRES ) ) {
bOk = ( rand() % 4 ) == 1;
}
- bool penalty = bOk && ( uplink == NULL || uplink->cacheFd == -1 );
- if ( uplink == NULL ) {
- uplink_init( image, -1, NULL, 0 );
- } else {
- ref_put( &uplink->reference );
- }
- if ( penalty ) { // Wait 100ms if local caching is not working so this
+ if ( bOk && uplink != NULL && uplink->cacheFd == -1 ) { // Wait 100ms if local caching is not working so this
usleep( 100000 ); // server gets a penalty and is less likely to be selected
}
+ if ( uplink != NULL ) {
+ ref_put( &uplink->reference );
+ }
}
if ( bOk ) {
mutex_lock( &image->lock );