From 1ee52f4a92bce337c8d5d5481c984b6ae483c613 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 25 Oct 2017 16:50:20 +0200 Subject: [SERVER] uplink: Fix updating of global byte counter, fix incremental updates Incremental updating of the global byte counter would only work when background replication is disabled. Fix this. --- src/server/uplink.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/server/uplink.c') diff --git a/src/server/uplink.c b/src/server/uplink.c index 2f71a4c..771d18b 100644 --- a/src/server/uplink.c +++ b/src/server/uplink.c @@ -380,7 +380,6 @@ static void* uplink_mainloop(void *data) link->fd = -1; close( fd ); } - uplink_updateGlobalReceivedCounter( link ); } // See if we should trigger an RTT measurement spin_lock( &link->rttLock ); @@ -400,6 +399,8 @@ static void* uplink_mainloop(void *data) } altCheckInterval = MIN(altCheckInterval + 1, SERVER_RTT_DELAY_MAX); timing_set( &nextAltCheck, &now, altCheckInterval ); + // Use opportunity to update global byte counter + uplink_updateGlobalReceivedCounter( link ); } } else if ( rttTestResult == RTT_NOT_REACHABLE ) { spin_lock( &link->rttLock ); @@ -723,11 +724,15 @@ static void uplink_addCrc32(dnbd3_connection_t *uplink) } } +/** + * Only ever called from uplink thread, so only lock when updating global counter, + * the lastBytesReceived field is ony accessed by us. + */ static void uplink_updateGlobalReceivedCounter(dnbd3_connection_t *link) { spin_lock( &statisticsReceivedLock ); totalBytesReceived += ( link->bytesReceived - link->lastBytesReceived ); - link->lastBytesReceived = 0; spin_unlock( &statisticsReceivedLock ); + link->lastBytesReceived = link->bytesReceived; } -- cgit v1.2.3-55-g7522