diff --git a/src/client.c b/src/client.c index 0e3a200..90564f5 100644 --- a/src/client.c +++ b/src/client.c @@ -294,34 +294,6 @@ void client_reply( struct client* client, struct nbd_request request ) } -int client_lock_io( struct client * client ) -{ - CLIENT_ERROR_ON_FAILURE( - pthread_mutex_lock(&client->serve->l_io), - "Problem with I/O lock" - ); - - if (server_detect_closed(client->serve)) { - CLIENT_ERROR_ON_FAILURE( - pthread_mutex_unlock(&client->serve->l_io), - "Problem with I/O unlock" - ); - return 0; - } - - return 1; -} - - -void client_unlock_io( struct client * client ) -{ - CLIENT_ERROR_ON_FAILURE( - pthread_mutex_unlock(&client->serve->l_io), - "Problem with I/O unlock" - ); -} - - int client_serve_request(struct client* client) { struct nbd_request request; @@ -332,9 +304,9 @@ int client_serve_request(struct client* client) return request_err; } - if ( client_lock_io( client ) ){ + if ( server_lock_io( client->serve ) ){ client_reply( client, request ); - client_unlock_io( client ); + server_unlock_io( client->serve ); } else { return 1; } diff --git a/src/serve.c b/src/serve.c index 4523f25..bc11fa8 100644 --- a/src/serve.c +++ b/src/serve.c @@ -38,6 +38,33 @@ void server_dirty(struct server *serve, off64_t from, int len) bitset_set_range(serve->mirror->dirty_map, from, len); } +int server_lock_io( struct server * serve) +{ + SERVER_ERROR_ON_FAILURE( + pthread_mutex_lock(&serve->l_io), + "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; +} + + +void server_unlock_io( struct server* serve ) +{ + SERVER_ERROR_ON_FAILURE( + pthread_mutex_unlock(&serve->l_io), + "Problem with I/O unlock" + ); +} + static int testmasks[9] = { 0,128,192,224,240,248,252,254,255 }; /** Test whether AF_INET or AF_INET6 sockaddr is included in the given access diff --git a/src/serve.h b/src/serve.h index b1e112b..b166f76 100644 --- a/src/serve.h +++ b/src/serve.h @@ -84,6 +84,8 @@ struct server { int server_detect_closed(struct server* serve); void server_dirty(struct server *serve, off64_t from, int len); +int server_lock_io( struct server * serve); +void server_unlock_io( struct server* serve ); void serve_signal_close( struct server *serve );