From 16001eb9eb64f5ce8f1bfb4920f1379747b8ed0e Mon Sep 17 00:00:00 2001 From: Alex Young Date: Wed, 6 Jun 2012 13:44:38 +0100 Subject: [PATCH] Move checking for a closed client out of server_lock_io and into client_serve_request --- src/client.c | 18 +++++++++++------- src/control.c | 26 ++++++++------------------ src/serve.c | 8 -------- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/src/client.c b/src/client.c index 90564f5..7bf0916 100644 --- a/src/client.c +++ b/src/client.c @@ -298,20 +298,24 @@ int client_serve_request(struct client* client) { struct nbd_request request; int request_err; - - if ( !client_read_request( client, &request ) ) { return 1; } + int success = 1; + + if ( !client_read_request( client, &request ) ) { return success; } if ( !client_request_needs_reply( client, request, &request_err ) ) { return request_err; } - if ( server_lock_io( client->serve ) ){ - client_reply( client, request ); - server_unlock_io( client->serve ); + server_lock_io( client->serve ); + + if ( server_detect_closed( client->serve ) ) { + success = 0; } else { - return 1; + client_reply( client, request ); } - return 0; + server_unlock_io( client->serve ); + + return success; } diff --git a/src/control.c b/src/control.c index bd3eb79..b30c59c 100644 --- a/src/control.c +++ b/src/control.c @@ -71,10 +71,7 @@ void* mirror_runner(void* serve_params_uncast) pthread_mutex_lock(&serve->l_accept), "Problem with accept lock" ); - SERVER_ERROR_ON_FAILURE( - pthread_mutex_lock(&serve->l_io), - "Problem with I/O lock" - ); + server_lock_io( serve ); } while (current < serve->size) { @@ -97,11 +94,9 @@ void* mirror_runner(void* serve_params_uncast) * is likely to slow things down but will be * safe. */ - if (pass < last_pass) - SERVER_ERROR_ON_FAILURE( - pthread_mutex_lock(&serve->l_io), - "Problem with I/O lock" - ); + if (pass < last_pass) { + server_lock_io( serve ); + } /** FIXME: do something useful with bytes/second */ @@ -117,11 +112,9 @@ void* mirror_runner(void* serve_params_uncast) /* now mark it clean */ bitset_clear_range(map, current, run); - if (pass < last_pass) - SERVER_ERROR_ON_FAILURE( - pthread_mutex_unlock(&serve->l_io), - "Problem with I/O unlock" - ); + if (pass < last_pass) { + server_unlock_io( serve ); + } written += run; } @@ -157,10 +150,7 @@ void* mirror_runner(void* serve_params_uncast) pthread_mutex_unlock(&serve->l_accept), "Problem with accept unlock" ); - SERVER_ERROR_ON_FAILURE( - pthread_mutex_unlock(&serve->l_io), - "Problem with I/O unlock" - ); + server_unlock_io( serve ); return NULL; } diff --git a/src/serve.c b/src/serve.c index bc11fa8..0b8a35b 100644 --- a/src/serve.c +++ b/src/serve.c @@ -45,14 +45,6 @@ int server_lock_io( struct server * serve) "Problem with I/O lock" ); - if (server_detect_closed(serve)) { - SERVER_ERROR_ON_FAILURE( - pthread_mutex_unlock(&serve->l_io), - "Problem with I/O unlock" - ); - return 0; - } - return 1; }