Allocate the bitset in the foreground thread.
This prevents the possibility of a race in dereferencing it in the client threads.
This commit is contained in:
41
src/serve.c
41
src/serve.c
@@ -759,23 +759,24 @@ void serve_accept_loop(struct server* params)
|
|||||||
|
|
||||||
void* build_allocation_map_thread(void* serve_uncast)
|
void* build_allocation_map_thread(void* serve_uncast)
|
||||||
{
|
{
|
||||||
NULLCHECK(serve_uncast);
|
NULLCHECK( serve_uncast );
|
||||||
|
|
||||||
struct server* serve = (struct server*) serve_uncast;
|
struct server* serve = (struct server*) serve_uncast;
|
||||||
int fd = open(serve->filename, O_RDONLY);
|
|
||||||
FATAL_IF_NEGATIVE(fd, "Couldn't open %s", serve->filename);
|
|
||||||
|
|
||||||
serve->allocation_map =
|
NULLCHECK( serve->filename );
|
||||||
bitset_alloc(serve->size, block_allocation_resolution);
|
NULLCHECK( serve->allocation_map );
|
||||||
|
|
||||||
if (build_allocation_map(serve->allocation_map, fd)) {
|
int fd = open( serve->filename, O_RDONLY );
|
||||||
|
FATAL_IF_NEGATIVE( fd, "Couldn't open %s", serve->filename );
|
||||||
|
|
||||||
|
if ( build_allocation_map( serve->allocation_map, fd ) ) {
|
||||||
serve->allocation_map_built = 1;
|
serve->allocation_map_built = 1;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
warn("Didn't build allocation map for %s", serve->filename);
|
warn( "Didn't build allocation map for %s", serve->filename );
|
||||||
}
|
}
|
||||||
|
|
||||||
close(fd);
|
close( fd );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -785,18 +786,26 @@ void* build_allocation_map_thread(void* serve_uncast)
|
|||||||
void serve_init_allocation_map(struct server* params)
|
void serve_init_allocation_map(struct server* params)
|
||||||
{
|
{
|
||||||
NULLCHECK( params );
|
NULLCHECK( params );
|
||||||
|
NULLCHECK( params->filename );
|
||||||
|
|
||||||
int fd = open(params->filename, O_RDONLY);
|
int fd = open( params->filename, O_RDONLY );
|
||||||
off64_t size;
|
off64_t size;
|
||||||
|
|
||||||
FATAL_IF_NEGATIVE(fd, "Couldn't open %s", params->filename);
|
FATAL_IF_NEGATIVE(fd, "Couldn't open %s", params->filename );
|
||||||
size = lseek64(fd, 0, SEEK_END);
|
size = lseek64( fd, 0, SEEK_END );
|
||||||
params->size = size;
|
params->size = size;
|
||||||
FATAL_IF_NEGATIVE(size, "Couldn't find size of %s",
|
FATAL_IF_NEGATIVE( size, "Couldn't find size of %s",
|
||||||
params->filename);
|
params->filename );
|
||||||
FATAL_IF_NEGATIVE(pthread_create(¶ms->allocation_map_builder_thread,
|
|
||||||
NULL, build_allocation_map_thread, params),
|
params->allocation_map =
|
||||||
"Couldn't create thread");
|
bitset_alloc( params->size, block_allocation_resolution );
|
||||||
|
|
||||||
|
int ok = pthread_create( ¶ms->allocation_map_builder_thread,
|
||||||
|
NULL,
|
||||||
|
build_allocation_map_thread,
|
||||||
|
params );
|
||||||
|
|
||||||
|
FATAL_IF_NEGATIVE( ok, "Couldn't create thread" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user