summaryrefslogtreecommitdiffstats
path: root/src/server/uplink.c
diff options
context:
space:
mode:
authorSimon Rettberg2017-10-25 16:50:20 +0200
committerSimon Rettberg2017-10-25 16:50:20 +0200
commit1ee52f4a92bce337c8d5d5481c984b6ae483c613 (patch)
tree7d2668aeb6502ec5e1cf4f318790452b6ab715cd /src/server/uplink.c
parent[SERVER] Only start reloading images if no other reload is in progress (diff)
downloaddnbd3-1ee52f4a92bce337c8d5d5481c984b6ae483c613.tar.gz
dnbd3-1ee52f4a92bce337c8d5d5481c984b6ae483c613.tar.xz
dnbd3-1ee52f4a92bce337c8d5d5481c984b6ae483c613.zip
[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.
Diffstat (limited to 'src/server/uplink.c')
-rw-r--r--src/server/uplink.c9
1 files changed, 7 insertions, 2 deletions
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;
}