Move checking for a closed client out of server_lock_io and into client_serve_request
This commit is contained in:
18
src/client.c
18
src/client.c
@@ -298,20 +298,24 @@ int client_serve_request(struct client* client)
|
|||||||
{
|
{
|
||||||
struct nbd_request request;
|
struct nbd_request request;
|
||||||
int request_err;
|
int request_err;
|
||||||
|
int success = 1;
|
||||||
if ( !client_read_request( client, &request ) ) { return 1; }
|
|
||||||
|
if ( !client_read_request( client, &request ) ) { return success; }
|
||||||
if ( !client_request_needs_reply( client, request, &request_err ) ) {
|
if ( !client_request_needs_reply( client, request, &request_err ) ) {
|
||||||
return request_err;
|
return request_err;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( server_lock_io( client->serve ) ){
|
server_lock_io( client->serve );
|
||||||
client_reply( client, request );
|
|
||||||
server_unlock_io( client->serve );
|
if ( server_detect_closed( client->serve ) ) {
|
||||||
|
success = 0;
|
||||||
} else {
|
} else {
|
||||||
return 1;
|
client_reply( client, request );
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
server_unlock_io( client->serve );
|
||||||
|
|
||||||
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -71,10 +71,7 @@ void* mirror_runner(void* serve_params_uncast)
|
|||||||
pthread_mutex_lock(&serve->l_accept),
|
pthread_mutex_lock(&serve->l_accept),
|
||||||
"Problem with accept lock"
|
"Problem with accept lock"
|
||||||
);
|
);
|
||||||
SERVER_ERROR_ON_FAILURE(
|
server_lock_io( serve );
|
||||||
pthread_mutex_lock(&serve->l_io),
|
|
||||||
"Problem with I/O lock"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
while (current < serve->size) {
|
while (current < serve->size) {
|
||||||
@@ -97,11 +94,9 @@ void* mirror_runner(void* serve_params_uncast)
|
|||||||
* is likely to slow things down but will be
|
* is likely to slow things down but will be
|
||||||
* safe.
|
* safe.
|
||||||
*/
|
*/
|
||||||
if (pass < last_pass)
|
if (pass < last_pass) {
|
||||||
SERVER_ERROR_ON_FAILURE(
|
server_lock_io( serve );
|
||||||
pthread_mutex_lock(&serve->l_io),
|
}
|
||||||
"Problem with I/O lock"
|
|
||||||
);
|
|
||||||
|
|
||||||
/** FIXME: do something useful with bytes/second */
|
/** FIXME: do something useful with bytes/second */
|
||||||
|
|
||||||
@@ -117,11 +112,9 @@ void* mirror_runner(void* serve_params_uncast)
|
|||||||
/* now mark it clean */
|
/* now mark it clean */
|
||||||
bitset_clear_range(map, current, run);
|
bitset_clear_range(map, current, run);
|
||||||
|
|
||||||
if (pass < last_pass)
|
if (pass < last_pass) {
|
||||||
SERVER_ERROR_ON_FAILURE(
|
server_unlock_io( serve );
|
||||||
pthread_mutex_unlock(&serve->l_io),
|
}
|
||||||
"Problem with I/O unlock"
|
|
||||||
);
|
|
||||||
|
|
||||||
written += run;
|
written += run;
|
||||||
}
|
}
|
||||||
@@ -157,10 +150,7 @@ void* mirror_runner(void* serve_params_uncast)
|
|||||||
pthread_mutex_unlock(&serve->l_accept),
|
pthread_mutex_unlock(&serve->l_accept),
|
||||||
"Problem with accept unlock"
|
"Problem with accept unlock"
|
||||||
);
|
);
|
||||||
SERVER_ERROR_ON_FAILURE(
|
server_unlock_io( serve );
|
||||||
pthread_mutex_unlock(&serve->l_io),
|
|
||||||
"Problem with I/O unlock"
|
|
||||||
);
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@@ -45,14 +45,6 @@ int server_lock_io( struct server * serve)
|
|||||||
"Problem with I/O lock"
|
"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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user