diff --git a/src/client.c b/src/client.c index 91b92b3..d23f303 100644 --- a/src/client.c +++ b/src/client.c @@ -412,6 +412,8 @@ void client_reply_to_write( struct client* client, struct nbd_request request ) } else { debug("No allocation map, writing directly."); + /* If we get cut off partway through reading this data: + * */ ERROR_IF_NEGATIVE( readloop( client->socket, client->mapped + request.from, diff --git a/src/serve.c b/src/serve.c index fb66800..8964d8a 100644 --- a/src/serve.c +++ b/src/serve.c @@ -757,20 +757,23 @@ void serve_accept_loop(struct server* params) while( server_accept( params ) ); } -void* build_allocation_map_thread(void* params1) +void* build_allocation_map_thread(void* serve_uncast) { - struct server* params = (struct server*) params1; - int fd = open(params->filename, O_RDONLY); - FATAL_IF_NEGATIVE(fd, "Couldn't open %s", params->filename); - NULLCHECK(params); + NULLCHECK(serve_uncast); - params->allocation_map = bitset_alloc(params->size, - block_allocation_resolution); + struct server* serve = (struct server*) serve_uncast; + int fd = open(serve->filename, O_RDONLY); + FATAL_IF_NEGATIVE(fd, "Couldn't open %s", serve->filename); - if (build_allocation_map(params->allocation_map, fd)) - params->allocation_map_built = 1; - else - warn("Didn't build allocation map for %s", params->filename); + serve->allocation_map = + bitset_alloc(serve->size, block_allocation_resolution); + + if (build_allocation_map(serve->allocation_map, fd)) { + serve->allocation_map_built = 1; + } + else { + warn("Didn't build allocation map for %s", serve->filename); + } close(fd); return NULL; @@ -805,6 +808,7 @@ void serve_signal_close( struct server * serve ) self_pipe_signal( serve->close_signal ); } + /* Block until the server closes the server_fd. */ void serve_wait_for_close( struct server * serve )