From 0228f3c86fefa582ec77b6aa97e89363b0f9b329 Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Tue, 17 Sep 2013 15:44:50 +0200 Subject: [SERVER] Properly decrease uplink.queueLen when removing a client --- src/server/image.c | 9 +++++++-- src/server/uplink.c | 6 ++---- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'src') 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 ); -- cgit v1.2.3-55-g7522