This commit is contained in:
Alex Young
2012-06-21 11:37:18 +01:00
21 changed files with 521 additions and 298 deletions

View File

@@ -19,6 +19,7 @@ struct client *client_create( struct server *serve, int socket )
struct client *c;
c = xmalloc( sizeof( struct server ) );
c->stopped = 0;
c->socket = socket;
c->serve = serve;
@@ -88,11 +89,9 @@ void write_not_zeroes(struct client* client, uint64_t from, int len)
for (i=0; i<client->serve->size; i+=map->resolution) {
int here = (from >= i && from < i+map->resolution);
if (here)
fprintf(stderr, ">");
if (here) { fprintf(stderr, ">"); }
fprintf(stderr, bitset_is_set_at(map, i) ? "1" : "0");
if (here)
fprintf(stderr, "<");
if (here) { fprintf(stderr, "<"); }
}
fprintf(stderr, "\n");
}
@@ -172,6 +171,7 @@ int client_read_request( struct client * client , struct nbd_request *out_reques
"select() failed");
if ( self_pipe_fd_isset( client->stop_signal, &fds ) ){
debug("Client received stop signal.");
return 0;
}
@@ -181,7 +181,7 @@ int client_read_request( struct client * client , struct nbd_request *out_reques
return 0; /* neat point to close the socket */
}
else {
FATAL_IF_NEGATIVE(-1, "Error reading request");
fatal("Error reading request");
}
}
@@ -239,8 +239,9 @@ int client_request_needs_reply( struct client * client, struct nbd_request reque
{
debug("request type %d", request.type);
if (request.magic != REQUEST_MAGIC)
if (request.magic != REQUEST_MAGIC) {
fatal("Bad magic %08x", request.magic);
}
switch (request.type)
{
@@ -376,12 +377,11 @@ void client_cleanup(struct client* client,
{
info("client cleanup");
if (client->socket)
close(client->socket);
if (client->mapped)
if (client->socket) { close(client->socket); }
if (client->mapped) {
munmap(client->mapped, client->serve->size);
if (client->fileno)
close(client->fileno);
}
if (client->fileno) { close(client->fileno); }
}
void* client_serve(void* client_uncast)
@@ -390,7 +390,6 @@ void* client_serve(void* client_uncast)
error_set_handler((cleanup_handler*) client_cleanup, client);
//client_open_file(client);
FATAL_IF_NEGATIVE(
open_and_mmap(
client->serve->filename,
@@ -404,6 +403,7 @@ void* client_serve(void* client_uncast)
while (client_serve_request(client) == 0)
;
client->stopped = 1;
FATAL_IF_NEGATIVE(
close(client->socket),
@@ -411,6 +411,7 @@ void* client_serve(void* client_uncast)
client->socket
);
debug("Cleaning up normally in thread %p", pthread_self());
client_cleanup(client, 0);
return NULL;