diff options
| author | Johann Latocha | 2012-02-11 01:34:07 +0100 |
|---|---|---|
| committer | Johann Latocha | 2012-02-11 01:34:07 +0100 |
| commit | 73e227959e02c3484085ce05c466a3ea0f3e5065 (patch) | |
| tree | b588d5dfb6d2645c721a6dbfe414a21119d4116e /src/server/net.c | |
| parent | [SERVER] Config reload fixed (diff) | |
| download | dnbd3-73e227959e02c3484085ce05c466a3ea0f3e5065.tar.gz dnbd3-73e227959e02c3484085ce05c466a3ea0f3e5065.tar.xz dnbd3-73e227959e02c3484085ce05c466a3ea0f3e5065.zip | |
[SERVER] Spinlocks to freeze threads while reloading config
Diffstat (limited to 'src/server/net.c')
| -rw-r--r-- | src/server/net.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/src/server/net.c b/src/server/net.c index e4be703..ab01f70 100644 --- a/src/server/net.c +++ b/src/server/net.c @@ -41,7 +41,6 @@ void *dnbd3_handle_query(void *dnbd3_client) dnbd3_reply_t reply; int image_file = -1; - dnbd3_image_t *image; struct in_addr server; int i = 0; @@ -52,10 +51,6 @@ void *dnbd3_handle_query(void *dnbd3_client) reply.error = 0; memcpy(reply.handle, request.handle, sizeof(request.handle)); - // TODO: lock CMD_GET_SERVERS and CMD_GET_SIZE because of reloading cfg... - // pthread_spin_lock(&_spinlock); - // pthread_spin_unlock(&_spinlock); - switch (request.cmd) { case CMD_GET_SERVERS: @@ -67,6 +62,7 @@ void *dnbd3_handle_query(void *dnbd3_client) continue; } + pthread_spin_lock(&client->spinlock); if (client->image->num_servers < MAX_NUMBER_SERVERS) reply.size = client->image->num_servers * sizeof(struct in_addr); else @@ -79,10 +75,13 @@ void *dnbd3_handle_query(void *dnbd3_client) inet_aton(client->image->servers[i], &server); send(client->sock, (char *) &server, sizeof(struct in_addr), 0); } + pthread_spin_unlock(&client->spinlock); continue; case CMD_GET_SIZE: - image = dnbd3_get_image(request.vid, request.rid); + pthread_spin_lock(&client->spinlock); + dnbd3_image_t *image = dnbd3_get_image(request.vid, request.rid); + pthread_spin_unlock(&client->spinlock); if(!image) { // image not found, send error |
