summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSimon Rettberg2013-09-17 15:44:50 +0200
committerSimon Rettberg2013-09-17 15:44:50 +0200
commit0228f3c86fefa582ec77b6aa97e89363b0f9b329 (patch)
tree06ab97b80477b043512afeb919e50f6675968d92 /src
parent[SERVER] Fix generation of alt-server list for client (diff)
downloaddnbd3-0228f3c86fefa582ec77b6aa97e89363b0f9b329.tar.gz
dnbd3-0228f3c86fefa582ec77b6aa97e89363b0f9b329.tar.xz
dnbd3-0228f3c86fefa582ec77b6aa97e89363b0f9b329.zip
[SERVER] Properly decrease uplink.queueLen when removing a client
Diffstat (limited to 'src')
-rw-r--r--src/server/image.c9
-rw-r--r--src/server/uplink.c6
2 files changed, 9 insertions, 6 deletions
diff --git a/src/server/image.c b/src/server/image.c
index 13e2e5b..a7cc427 100644
--- a/src/server/image.c
+++ b/src/server/image.c
@@ -1029,7 +1029,7 @@ int image_generateCrcFile(char *image)
void image_printAll()
{
- int i, percent, pending;
+ int i, percent, pending, j;
char buffer[100] = { 0 };
spin_lock( &_images_lock );
for (i = 0; i < _num_images; ++i) {
@@ -1040,7 +1040,12 @@ void image_printAll()
printf( " Complete: %d%%\n", percent );
if ( _images[i]->uplink != NULL ) {
host_to_string( &_images[i]->uplink->currentServer, buffer, sizeof(buffer) );
- pending = _images[i]->uplink->queueLen;
+ pending = 0;
+ spin_lock( &_images[i]->uplink->queueLock );
+ for (j = 0; j < _images[i]->uplink->queueLen; ++j) {
+ if ( _images[i]->uplink->queue[j].status != ULR_FREE ) pending++;
+ }
+ spin_unlock( &_images[i]->uplink->queueLock );
printf( " Uplink: %s -- %d pending requests\n", buffer, pending );
}
printf( " Users: %d\n", _images[i]->users );
diff --git a/src/server/uplink.c b/src/server/uplink.c
index 61b353f..67936d5 100644
--- a/src/server/uplink.c
+++ b/src/server/uplink.c
@@ -103,13 +103,11 @@ void uplink_shutdown(dnbd3_image_t *image)
void uplink_removeClient(dnbd3_connection_t *uplink, dnbd3_client_t *client)
{
spin_lock( &uplink->queueLock );
- for (int i = 0; i < uplink->queueLen; ++i) {
+ for (int i = uplink->queueLen - 1; i >= 0; --i) {
if ( uplink->queue[i].client == client ) {
- // Lock on the send mutex as the uplink thread might just be writing to the client
- pthread_mutex_lock( &client->sendMutex );
uplink->queue[i].client = NULL;
uplink->queue[i].status = ULR_FREE;
- pthread_mutex_unlock( &client->sendMutex );
+ if ( i > 20 && uplink->queueLen == i + 1 ) uplink->queueLen--;
}
}
spin_unlock( &uplink->queueLock );