Make max_nbd_clients configurable per struct server
This commit is contained in:
@@ -269,7 +269,7 @@ int mode_serve( int argc, char *argv[] )
|
|||||||
}
|
}
|
||||||
if ( err ) { exit_err( serve_help_text ); }
|
if ( err ) { exit_err( serve_help_text ); }
|
||||||
|
|
||||||
serve = server_create( ip_addr, ip_port, file, sock, default_deny, argc - optind, argv + optind );
|
serve = server_create( ip_addr, ip_port, file, sock, default_deny, argc - optind, argv + optind, MAX_NBD_CLIENTS );
|
||||||
do_serve( serve );
|
do_serve( serve );
|
||||||
server_destroy( serve );
|
server_destroy( serve );
|
||||||
|
|
||||||
|
24
src/serve.c
24
src/serve.c
@@ -43,10 +43,13 @@ struct server * server_create (
|
|||||||
char *s_ctrl_sock,
|
char *s_ctrl_sock,
|
||||||
int default_deny,
|
int default_deny,
|
||||||
int acl_entries,
|
int acl_entries,
|
||||||
char** s_acl_entries )
|
char** s_acl_entries,
|
||||||
|
int max_nbd_clients)
|
||||||
{
|
{
|
||||||
struct server * out;
|
struct server * out;
|
||||||
out = xmalloc( sizeof( struct server ) );
|
out = xmalloc( sizeof( struct server ) );
|
||||||
|
out->max_nbd_clients = max_nbd_clients;
|
||||||
|
out->nbd_client = xmalloc( max_nbd_clients * sizeof( struct client_tbl_entry ) );
|
||||||
|
|
||||||
out->tcp_backlog = 10; /* does this need to be settable? */
|
out->tcp_backlog = 10; /* does this need to be settable? */
|
||||||
|
|
||||||
@@ -108,6 +111,7 @@ void server_destroy( struct server * serve )
|
|||||||
|
|
||||||
free( serve->filename_incomplete );
|
free( serve->filename_incomplete );
|
||||||
|
|
||||||
|
free( serve->nbd_client );
|
||||||
free( serve );
|
free( serve );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -265,10 +269,10 @@ int cleanup_client_thread( struct client_tbl_entry * entry )
|
|||||||
return tryjoin_client_thread( entry, pthread_tryjoin_np );
|
return tryjoin_client_thread( entry, pthread_tryjoin_np );
|
||||||
}
|
}
|
||||||
|
|
||||||
void cleanup_client_threads( struct client_tbl_entry * entries )
|
void cleanup_client_threads( struct client_tbl_entry * entries, size_t entries_len )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
for( i = 0; i < MAX_NBD_CLIENTS; i++ ) {
|
for( i = 0; i < entries_len; i++ ) {
|
||||||
cleanup_client_thread( &entries[i] );
|
cleanup_client_thread( &entries[i] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,9 +298,9 @@ int cleanup_and_find_client_slot(struct server* params)
|
|||||||
|
|
||||||
int slot=-1, i;
|
int slot=-1, i;
|
||||||
|
|
||||||
cleanup_client_threads( params->nbd_client );
|
cleanup_client_threads( params->nbd_client, params->max_nbd_clients );
|
||||||
|
|
||||||
for ( i = 0; i < MAX_NBD_CLIENTS; i++ ) {
|
for ( i = 0; i < params->max_nbd_clients; i++ ) {
|
||||||
if( params->nbd_client[i].thread == 0 && slot == -1 ){
|
if( params->nbd_client[i].thread == 0 && slot == -1 ){
|
||||||
slot = i;
|
slot = i;
|
||||||
break;
|
break;
|
||||||
@@ -470,7 +474,7 @@ void server_audit_clients( struct server * serve)
|
|||||||
* server_accept loop will see a second acl_updated signal as
|
* server_accept loop will see a second acl_updated signal as
|
||||||
* soon as it hits select, and a second audit will be run.
|
* soon as it hits select, and a second audit will be run.
|
||||||
*/
|
*/
|
||||||
for( i = 0; i < MAX_NBD_CLIENTS; i++ ) {
|
for( i = 0; i < serve->max_nbd_clients; i++ ) {
|
||||||
entry = &serve->nbd_client[i];
|
entry = &serve->nbd_client[i];
|
||||||
if ( 0 == entry->thread ) { continue; }
|
if ( 0 == entry->thread ) { continue; }
|
||||||
if ( server_acl_accepts( serve, &entry->address ) ) { continue; }
|
if ( server_acl_accepts( serve, &entry->address ) ) { continue; }
|
||||||
@@ -495,14 +499,14 @@ void server_close_clients( struct server *params )
|
|||||||
int i, j;
|
int i, j;
|
||||||
struct client_tbl_entry *entry;
|
struct client_tbl_entry *entry;
|
||||||
|
|
||||||
for( i = 0; i < MAX_NBD_CLIENTS; i++ ) {
|
for( i = 0; i < params->max_nbd_clients; i++ ) {
|
||||||
entry = ¶ms->nbd_client[i];
|
entry = ¶ms->nbd_client[i];
|
||||||
|
|
||||||
if ( entry->thread != 0 ) {
|
if ( entry->thread != 0 ) {
|
||||||
client_signal_stop( entry->client );
|
client_signal_stop( entry->client );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for( j = 0; j < MAX_NBD_CLIENTS; j++ ) {
|
for( j = 0; j < params->max_nbd_clients; j++ ) {
|
||||||
join_client_thread( ¶ms->nbd_client[j] );
|
join_client_thread( ¶ms->nbd_client[j] );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -561,7 +565,7 @@ int server_accept( struct server * params )
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( self_pipe_fd_isset( params->vacuum_signal, &fds ) ) {
|
if ( self_pipe_fd_isset( params->vacuum_signal, &fds ) ) {
|
||||||
cleanup_client_threads( params->nbd_client );
|
cleanup_client_threads( params->nbd_client, params->max_nbd_clients );
|
||||||
self_pipe_signal_clear( params->vacuum_signal );
|
self_pipe_signal_clear( params->vacuum_signal );
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -660,7 +664,7 @@ void serve_cleanup(struct server* params,
|
|||||||
pthread_join(mirror_t, NULL);
|
pthread_join(mirror_t, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i < MAX_NBD_CLIENTS; i++) {
|
for (i=0; i < params->max_nbd_clients; i++) {
|
||||||
void* status;
|
void* status;
|
||||||
pthread_t thread_id = params->nbd_client[i].thread;
|
pthread_t thread_id = params->nbd_client[i].thread;
|
||||||
|
|
||||||
|
14
src/serve.h
14
src/serve.h
@@ -80,11 +80,19 @@ struct server {
|
|||||||
|
|
||||||
struct bitset_mapping* allocation_map;
|
struct bitset_mapping* allocation_map;
|
||||||
|
|
||||||
struct client_tbl_entry nbd_client[MAX_NBD_CLIENTS];
|
int max_nbd_clients;
|
||||||
|
struct client_tbl_entry *nbd_client;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct server * server_create( char* s_ip_address, char* s_port, char* s_file,
|
struct server * server_create(
|
||||||
char *s_ctrl_sock, int default_deny, int acl_entries, char** s_acl_entries );
|
char* s_ip_address,
|
||||||
|
char* s_port,
|
||||||
|
char* s_file,
|
||||||
|
char *s_ctrl_sock,
|
||||||
|
int default_deny,
|
||||||
|
int acl_entries,
|
||||||
|
char** s_acl_entries,
|
||||||
|
int max_nbd_clients );
|
||||||
void server_destroy( struct server * );
|
void server_destroy( struct server * );
|
||||||
int server_is_closed(struct server* serve);
|
int server_is_closed(struct server* serve);
|
||||||
void server_dirty(struct server *serve, off64_t from, int len);
|
void server_dirty(struct server *serve, off64_t from, int len);
|
||||||
|
@@ -61,7 +61,7 @@ void teardown( void )
|
|||||||
|
|
||||||
START_TEST( test_replaces_acl )
|
START_TEST( test_replaces_acl )
|
||||||
{
|
{
|
||||||
struct server * s = server_create( "127.0.0.1", "0", dummy_file, NULL, 0, 0, NULL );
|
struct server * s = server_create( "127.0.0.1", "0", dummy_file, NULL, 0, 0, NULL, 1);
|
||||||
struct acl * new_acl = acl_create( 0, NULL, 0 );
|
struct acl * new_acl = acl_create( 0, NULL, 0 );
|
||||||
|
|
||||||
server_replace_acl( s, new_acl );
|
server_replace_acl( s, new_acl );
|
||||||
@@ -74,7 +74,7 @@ END_TEST
|
|||||||
|
|
||||||
START_TEST( test_signals_acl_updated )
|
START_TEST( test_signals_acl_updated )
|
||||||
{
|
{
|
||||||
struct server * s = server_create( "127.0.0.1", "0", dummy_file, NULL, 0, 0, NULL );
|
struct server * s = server_create( "127.0.0.1", "0", dummy_file, NULL, 0, 0, NULL, 1 );
|
||||||
struct acl * new_acl = acl_create( 0, NULL, 0 );
|
struct acl * new_acl = acl_create( 0, NULL, 0 );
|
||||||
|
|
||||||
server_replace_acl( s, new_acl );
|
server_replace_acl( s, new_acl );
|
||||||
@@ -141,7 +141,7 @@ START_TEST( test_acl_update_closes_bad_client )
|
|||||||
* and socket out of the server structure, we should be testing
|
* and socket out of the server structure, we should be testing
|
||||||
* a client socket.
|
* a client socket.
|
||||||
*/
|
*/
|
||||||
struct server * s = server_create( "127.0.0.7", "0", dummy_file, NULL, 0, 0, NULL );
|
struct server * s = server_create( "127.0.0.7", "0", dummy_file, NULL, 0, 0, NULL, 1 );
|
||||||
struct acl * new_acl = acl_create( 0, NULL, 1 );
|
struct acl * new_acl = acl_create( 0, NULL, 1 );
|
||||||
struct client * c;
|
struct client * c;
|
||||||
struct client_tbl_entry * entry;
|
struct client_tbl_entry * entry;
|
||||||
@@ -183,7 +183,7 @@ END_TEST
|
|||||||
|
|
||||||
START_TEST( test_acl_update_leaves_good_client )
|
START_TEST( test_acl_update_leaves_good_client )
|
||||||
{
|
{
|
||||||
struct server * s = server_create( "127.0.0.7", "0", dummy_file, NULL, 0, 0, NULL );
|
struct server * s = server_create( "127.0.0.7", "0", dummy_file, NULL, 0, 0, NULL, 1 );
|
||||||
|
|
||||||
char *lines[] = {"127.0.0.1"};
|
char *lines[] = {"127.0.0.1"};
|
||||||
struct acl * new_acl = acl_create( 1, lines, 1 );
|
struct acl * new_acl = acl_create( 1, lines, 1 );
|
||||||
|
Reference in New Issue
Block a user