Formatted all code using indent
This commit is contained in:
@@ -43,223 +43,206 @@
|
||||
|
||||
int flexnbd_build_signal_fd(void)
|
||||
{
|
||||
sigset_t mask;
|
||||
int sfd;
|
||||
sigset_t mask;
|
||||
int sfd;
|
||||
|
||||
sigemptyset( &mask );
|
||||
sigaddset( &mask, SIGTERM );
|
||||
sigaddset( &mask, SIGQUIT );
|
||||
sigaddset( &mask, SIGINT );
|
||||
sigemptyset(&mask);
|
||||
sigaddset(&mask, SIGTERM);
|
||||
sigaddset(&mask, SIGQUIT);
|
||||
sigaddset(&mask, SIGINT);
|
||||
|
||||
FATAL_UNLESS( 0 == pthread_sigmask( SIG_BLOCK, &mask, NULL ),
|
||||
"Signal blocking failed" );
|
||||
FATAL_UNLESS(0 == pthread_sigmask(SIG_BLOCK, &mask, NULL),
|
||||
"Signal blocking failed");
|
||||
|
||||
sfd = signalfd( -1, &mask, 0 );
|
||||
FATAL_IF( -1 == sfd, "Failed to get a signal fd" );
|
||||
sfd = signalfd(-1, &mask, 0);
|
||||
FATAL_IF(-1 == sfd, "Failed to get a signal fd");
|
||||
|
||||
return sfd;
|
||||
return sfd;
|
||||
}
|
||||
|
||||
|
||||
void flexnbd_create_shared(
|
||||
struct flexnbd * flexnbd,
|
||||
const char * s_ctrl_sock)
|
||||
void flexnbd_create_shared(struct flexnbd *flexnbd,
|
||||
const char *s_ctrl_sock)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
if ( s_ctrl_sock ){
|
||||
flexnbd->control =
|
||||
control_create( flexnbd, s_ctrl_sock );
|
||||
}
|
||||
else {
|
||||
flexnbd->control = NULL;
|
||||
}
|
||||
NULLCHECK(flexnbd);
|
||||
if (s_ctrl_sock) {
|
||||
flexnbd->control = control_create(flexnbd, s_ctrl_sock);
|
||||
} else {
|
||||
flexnbd->control = NULL;
|
||||
}
|
||||
|
||||
flexnbd->signal_fd = flexnbd_build_signal_fd();
|
||||
flexnbd->signal_fd = flexnbd_build_signal_fd();
|
||||
}
|
||||
|
||||
|
||||
struct flexnbd * flexnbd_create_serving(
|
||||
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,
|
||||
int use_killswitch)
|
||||
struct flexnbd *flexnbd_create_serving(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,
|
||||
int use_killswitch)
|
||||
{
|
||||
struct flexnbd * flexnbd = xmalloc( sizeof( struct flexnbd ) );
|
||||
flexnbd->serve = server_create(
|
||||
flexnbd,
|
||||
s_ip_address,
|
||||
s_port,
|
||||
s_file,
|
||||
default_deny,
|
||||
acl_entries,
|
||||
s_acl_entries,
|
||||
max_nbd_clients,
|
||||
use_killswitch,
|
||||
1);
|
||||
flexnbd_create_shared( flexnbd, s_ctrl_sock );
|
||||
struct flexnbd *flexnbd = xmalloc(sizeof(struct flexnbd));
|
||||
flexnbd->serve = server_create(flexnbd,
|
||||
s_ip_address,
|
||||
s_port,
|
||||
s_file,
|
||||
default_deny,
|
||||
acl_entries,
|
||||
s_acl_entries,
|
||||
max_nbd_clients, use_killswitch, 1);
|
||||
flexnbd_create_shared(flexnbd, s_ctrl_sock);
|
||||
|
||||
// Beats installing one handler per client instance
|
||||
if ( use_killswitch ) {
|
||||
struct sigaction act = {
|
||||
.sa_sigaction = client_killswitch_hit,
|
||||
.sa_flags = SA_RESTART | SA_SIGINFO
|
||||
};
|
||||
// Beats installing one handler per client instance
|
||||
if (use_killswitch) {
|
||||
struct sigaction act = {
|
||||
.sa_sigaction = client_killswitch_hit,
|
||||
.sa_flags = SA_RESTART | SA_SIGINFO
|
||||
};
|
||||
|
||||
FATAL_UNLESS(
|
||||
0 == sigaction( CLIENT_KILLSWITCH_SIGNAL, &act, NULL ),
|
||||
"Installing client killswitch signal failed"
|
||||
);
|
||||
}
|
||||
FATAL_UNLESS(0 == sigaction(CLIENT_KILLSWITCH_SIGNAL, &act, NULL),
|
||||
"Installing client killswitch signal failed");
|
||||
}
|
||||
|
||||
return flexnbd;
|
||||
return flexnbd;
|
||||
}
|
||||
|
||||
struct flexnbd * flexnbd_create_listening(
|
||||
char* s_ip_address,
|
||||
char* s_port,
|
||||
char* s_file,
|
||||
char* s_ctrl_sock,
|
||||
int default_deny,
|
||||
int acl_entries,
|
||||
char** s_acl_entries )
|
||||
struct flexnbd *flexnbd_create_listening(char *s_ip_address,
|
||||
char *s_port,
|
||||
char *s_file,
|
||||
char *s_ctrl_sock,
|
||||
int default_deny,
|
||||
int acl_entries,
|
||||
char **s_acl_entries)
|
||||
{
|
||||
struct flexnbd * flexnbd = xmalloc( sizeof( struct flexnbd ) );
|
||||
flexnbd->serve = server_create(
|
||||
flexnbd,
|
||||
s_ip_address,
|
||||
s_port,
|
||||
s_file,
|
||||
default_deny,
|
||||
acl_entries,
|
||||
s_acl_entries,
|
||||
1, 0, 0);
|
||||
flexnbd_create_shared( flexnbd, s_ctrl_sock );
|
||||
struct flexnbd *flexnbd = xmalloc(sizeof(struct flexnbd));
|
||||
flexnbd->serve = server_create(flexnbd,
|
||||
s_ip_address,
|
||||
s_port,
|
||||
s_file,
|
||||
default_deny,
|
||||
acl_entries, s_acl_entries, 1, 0, 0);
|
||||
flexnbd_create_shared(flexnbd, s_ctrl_sock);
|
||||
|
||||
// listen can't use killswitch, as mirror may pause on sending things
|
||||
// for a very long time.
|
||||
// listen can't use killswitch, as mirror may pause on sending things
|
||||
// for a very long time.
|
||||
|
||||
return flexnbd;
|
||||
return flexnbd;
|
||||
}
|
||||
|
||||
void flexnbd_spawn_control(struct flexnbd * flexnbd )
|
||||
void flexnbd_spawn_control(struct flexnbd *flexnbd)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
NULLCHECK( flexnbd->control );
|
||||
NULLCHECK(flexnbd);
|
||||
NULLCHECK(flexnbd->control);
|
||||
|
||||
pthread_t * control_thread = &flexnbd->control->thread;
|
||||
pthread_t *control_thread = &flexnbd->control->thread;
|
||||
|
||||
FATAL_UNLESS( 0 == pthread_create(
|
||||
control_thread,
|
||||
NULL,
|
||||
control_runner,
|
||||
flexnbd->control ),
|
||||
"Couldn't create the control thread" );
|
||||
FATAL_UNLESS(0 == pthread_create(control_thread,
|
||||
NULL,
|
||||
control_runner,
|
||||
flexnbd->control),
|
||||
"Couldn't create the control thread");
|
||||
}
|
||||
|
||||
void flexnbd_stop_control( struct flexnbd * flexnbd )
|
||||
void flexnbd_stop_control(struct flexnbd *flexnbd)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
NULLCHECK( flexnbd->control );
|
||||
NULLCHECK(flexnbd);
|
||||
NULLCHECK(flexnbd->control);
|
||||
|
||||
control_signal_close( flexnbd->control );
|
||||
pthread_t tid = flexnbd->control->thread;
|
||||
FATAL_UNLESS( 0 == pthread_join( tid, NULL ),
|
||||
"Failed joining the control thread" );
|
||||
debug( "Control thread %p pthread_join returned", tid );
|
||||
control_signal_close(flexnbd->control);
|
||||
pthread_t tid = flexnbd->control->thread;
|
||||
FATAL_UNLESS(0 == pthread_join(tid, NULL),
|
||||
"Failed joining the control thread");
|
||||
debug("Control thread %p pthread_join returned", tid);
|
||||
}
|
||||
|
||||
|
||||
int flexnbd_signal_fd( struct flexnbd * flexnbd )
|
||||
int flexnbd_signal_fd(struct flexnbd *flexnbd)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
return flexnbd->signal_fd;
|
||||
NULLCHECK(flexnbd);
|
||||
return flexnbd->signal_fd;
|
||||
}
|
||||
|
||||
void flexnbd_destroy( struct flexnbd * flexnbd )
|
||||
void flexnbd_destroy(struct flexnbd *flexnbd)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
if ( flexnbd->control ) {
|
||||
control_destroy( flexnbd->control );
|
||||
}
|
||||
NULLCHECK(flexnbd);
|
||||
if (flexnbd->control) {
|
||||
control_destroy(flexnbd->control);
|
||||
}
|
||||
|
||||
close( flexnbd->signal_fd );
|
||||
free( flexnbd );
|
||||
close(flexnbd->signal_fd);
|
||||
free(flexnbd);
|
||||
}
|
||||
|
||||
|
||||
struct server * flexnbd_server( struct flexnbd * flexnbd )
|
||||
struct server *flexnbd_server(struct flexnbd *flexnbd)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
return flexnbd->serve;
|
||||
NULLCHECK(flexnbd);
|
||||
return flexnbd->serve;
|
||||
}
|
||||
|
||||
void flexnbd_replace_acl( struct flexnbd * flexnbd, struct acl * acl )
|
||||
void flexnbd_replace_acl(struct flexnbd *flexnbd, struct acl *acl)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
server_replace_acl( flexnbd_server(flexnbd), acl );
|
||||
NULLCHECK(flexnbd);
|
||||
server_replace_acl(flexnbd_server(flexnbd), acl);
|
||||
}
|
||||
|
||||
|
||||
struct status * flexnbd_status_create( struct flexnbd * flexnbd )
|
||||
struct status *flexnbd_status_create(struct flexnbd *flexnbd)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
struct status * status;
|
||||
NULLCHECK(flexnbd);
|
||||
struct status *status;
|
||||
|
||||
status = status_create( flexnbd_server( flexnbd ) );
|
||||
return status;
|
||||
status = status_create(flexnbd_server(flexnbd));
|
||||
return status;
|
||||
}
|
||||
|
||||
void flexnbd_set_server( struct flexnbd * flexnbd, struct server * serve )
|
||||
void flexnbd_set_server(struct flexnbd *flexnbd, struct server *serve)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
flexnbd->serve = serve;
|
||||
NULLCHECK(flexnbd);
|
||||
flexnbd->serve = serve;
|
||||
}
|
||||
|
||||
|
||||
/* Get the default_deny of the current server object. */
|
||||
int flexnbd_default_deny( struct flexnbd * flexnbd )
|
||||
int flexnbd_default_deny(struct flexnbd *flexnbd)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
return server_default_deny( flexnbd->serve );
|
||||
NULLCHECK(flexnbd);
|
||||
return server_default_deny(flexnbd->serve);
|
||||
}
|
||||
|
||||
|
||||
void make_writable( const char * filename )
|
||||
void make_writable(const char *filename)
|
||||
{
|
||||
NULLCHECK( filename );
|
||||
FATAL_IF_NEGATIVE( chmod( filename, S_IWUSR ),
|
||||
"Couldn't chmod %s: %s",
|
||||
filename,
|
||||
strerror( errno ) );
|
||||
NULLCHECK(filename);
|
||||
FATAL_IF_NEGATIVE(chmod(filename, S_IWUSR),
|
||||
"Couldn't chmod %s: %s", filename, strerror(errno));
|
||||
}
|
||||
|
||||
|
||||
int flexnbd_serve( struct flexnbd * flexnbd )
|
||||
int flexnbd_serve(struct flexnbd *flexnbd)
|
||||
{
|
||||
NULLCHECK( flexnbd );
|
||||
int success;
|
||||
struct self_pipe * open_signal = NULL;
|
||||
NULLCHECK(flexnbd);
|
||||
int success;
|
||||
struct self_pipe *open_signal = NULL;
|
||||
|
||||
if ( flexnbd->control ){
|
||||
debug( "Spawning control thread" );
|
||||
flexnbd_spawn_control( flexnbd );
|
||||
open_signal = flexnbd->control->open_signal;
|
||||
}
|
||||
if (flexnbd->control) {
|
||||
debug("Spawning control thread");
|
||||
flexnbd_spawn_control(flexnbd);
|
||||
open_signal = flexnbd->control->open_signal;
|
||||
}
|
||||
|
||||
success = do_serve( flexnbd->serve, open_signal );
|
||||
debug("do_serve success is %d", success );
|
||||
success = do_serve(flexnbd->serve, open_signal);
|
||||
debug("do_serve success is %d", success);
|
||||
|
||||
if ( flexnbd->control ) {
|
||||
debug( "Stopping control thread" );
|
||||
flexnbd_stop_control( flexnbd );
|
||||
debug("Control thread stopped");
|
||||
}
|
||||
if (flexnbd->control) {
|
||||
debug("Stopping control thread");
|
||||
flexnbd_stop_control(flexnbd);
|
||||
debug("Control thread stopped");
|
||||
}
|
||||
|
||||
return success;
|
||||
return success;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user