Rename control to control_fd and struct mode_serve_params to struct server
This commit is contained in:
@@ -55,7 +55,7 @@ void* mirror_runner(void* serve_params_uncast)
|
||||
{
|
||||
const int last_pass = mirror_maximum_passes-1;
|
||||
int pass;
|
||||
struct mode_serve_params *serve = (struct mode_serve_params*) serve_params_uncast;
|
||||
struct server *serve = (struct server*) serve_params_uncast;
|
||||
struct bitset_mapping *map = serve->mirror->dirty_map;
|
||||
|
||||
for (pass=0; pass < mirror_maximum_passes; pass++) {
|
||||
@@ -333,7 +333,7 @@ void* control_serve(void* client_uncast)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void accept_control_connection(struct mode_serve_params* params, int client_fd, union mysockaddr* client_address)
|
||||
void accept_control_connection(struct server* params, int client_fd, union mysockaddr* client_address)
|
||||
{
|
||||
pthread_t control_thread;
|
||||
struct control_params* control_params;
|
||||
@@ -353,15 +353,15 @@ void accept_control_connection(struct mode_serve_params* params, int client_fd,
|
||||
);
|
||||
}
|
||||
|
||||
void serve_open_control_socket(struct mode_serve_params* params)
|
||||
void serve_open_control_socket(struct server* params)
|
||||
{
|
||||
struct sockaddr_un bind_address;
|
||||
|
||||
if (!params->control_socket_name)
|
||||
return;
|
||||
|
||||
params->control = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
SERVER_ERROR_ON_FAILURE(params->control,
|
||||
params->control_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
SERVER_ERROR_ON_FAILURE(params->control_fd ,
|
||||
"Couldn't create control socket");
|
||||
|
||||
memset(&bind_address, 0, sizeof(bind_address));
|
||||
@@ -371,13 +371,13 @@ void serve_open_control_socket(struct mode_serve_params* params)
|
||||
unlink(params->control_socket_name); /* ignore failure */
|
||||
|
||||
SERVER_ERROR_ON_FAILURE(
|
||||
bind(params->control, &bind_address, sizeof(bind_address)),
|
||||
bind(params->control_fd , &bind_address, sizeof(bind_address)),
|
||||
"Couldn't bind control socket to %s",
|
||||
params->control_socket_name
|
||||
);
|
||||
|
||||
SERVER_ERROR_ON_FAILURE(
|
||||
listen(params->control, 5),
|
||||
listen(params->control_fd , 5),
|
||||
"Couldn't listen on control socket"
|
||||
);
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#ifndef __CONTROL_H
|
||||
#define __CONTROL_H
|
||||
|
||||
void accept_control_connection(struct mode_serve_params* params, int client_fd, union mysockaddr* client_address);
|
||||
void serve_open_control_socket(struct mode_serve_params* params);
|
||||
void accept_control_connection(struct server* params, int client_fd, union mysockaddr* client_address);
|
||||
void serve_open_control_socket(struct server* params);
|
||||
|
||||
#endif
|
||||
|
||||
|
@@ -43,7 +43,7 @@ void exit_err( char *msg )
|
||||
}
|
||||
|
||||
void params_serve(
|
||||
struct mode_serve_params* out,
|
||||
struct server* out,
|
||||
char* s_ip_address,
|
||||
char* s_port,
|
||||
char* s_file,
|
||||
@@ -161,7 +161,7 @@ void params_readwrite(
|
||||
}
|
||||
}
|
||||
|
||||
void do_serve(struct mode_serve_params* params);
|
||||
void do_serve(struct server* params);
|
||||
void do_read(struct mode_readwrite_params* params);
|
||||
void do_write(struct mode_readwrite_params* params);
|
||||
void do_remote_command(char* command, char* mode, int argc, char** argv);
|
||||
@@ -290,7 +290,7 @@ int mode_serve( int argc, char *argv[] )
|
||||
int default_deny = 0; // not on by default
|
||||
int err = 0;
|
||||
|
||||
struct mode_serve_params serve;
|
||||
struct server serve;
|
||||
|
||||
while (1) {
|
||||
c = getopt_long(argc, argv, serve_short_options, serve_options, NULL);
|
||||
|
@@ -30,11 +30,11 @@ struct mirror_status {
|
||||
|
||||
struct control_params {
|
||||
int socket;
|
||||
struct mode_serve_params* serve;
|
||||
struct server* serve;
|
||||
};
|
||||
|
||||
#define MAX_NBD_CLIENTS 16
|
||||
struct mode_serve_params {
|
||||
struct server {
|
||||
/** address/port to bind to */
|
||||
union mysockaddr bind_to;
|
||||
/** does an empty ACL mean "deny all"? */
|
||||
@@ -72,7 +72,7 @@ struct mode_serve_params {
|
||||
|
||||
struct mirror_status* mirror;
|
||||
int server_fd;
|
||||
int control;
|
||||
int control_fd;
|
||||
|
||||
char* block_allocation_map;
|
||||
|
||||
@@ -94,7 +94,7 @@ struct client_params {
|
||||
int fileno;
|
||||
char* mapped;
|
||||
|
||||
struct mode_serve_params* serve; /* FIXME: remove above duplication */
|
||||
struct server* serve; /* FIXME: remove above duplication */
|
||||
};
|
||||
|
||||
/* FIXME: wrong place */
|
||||
|
26
src/serve.c
26
src/serve.c
@@ -20,13 +20,13 @@
|
||||
|
||||
static const int block_allocation_resolution = 4096;//128<<10;
|
||||
|
||||
static inline void dirty(struct mode_serve_params *serve, off64_t from, int len)
|
||||
static inline void dirty(struct server *serve, off64_t from, int len)
|
||||
{
|
||||
if (serve->mirror)
|
||||
bitset_set_range(serve->mirror->dirty_map, from, len);
|
||||
}
|
||||
|
||||
int server_detect_closed(struct mode_serve_params* serve)
|
||||
int server_detect_closed(struct server* serve)
|
||||
{
|
||||
int errno_old = errno;
|
||||
int result = fcntl(serve->server_fd, F_GETFD, 0) < 0;
|
||||
@@ -461,7 +461,7 @@ int is_included_in_acl(int list_length, struct ip_and_mask (*list)[], union myso
|
||||
}
|
||||
|
||||
/** Prepares a listening socket for the NBD server, binding etc. */
|
||||
void serve_open_server_socket(struct mode_serve_params* params)
|
||||
void serve_open_server_socket(struct server* params)
|
||||
{
|
||||
int optval=1;
|
||||
|
||||
@@ -497,7 +497,7 @@ void serve_open_server_socket(struct mode_serve_params* params)
|
||||
* goes through the current list, waits for any threads that have finished
|
||||
* and returns the next slot free (or -1 if there are none).
|
||||
*/
|
||||
int cleanup_and_find_client_slot(struct mode_serve_params* params)
|
||||
int cleanup_and_find_client_slot(struct server* params)
|
||||
{
|
||||
int slot=-1, i;
|
||||
|
||||
@@ -538,7 +538,7 @@ int cleanup_and_find_client_slot(struct mode_serve_params* params)
|
||||
* address doesn't match, or if there are too many clients already connected.
|
||||
*/
|
||||
void accept_nbd_client(
|
||||
struct mode_serve_params* params,
|
||||
struct server* params,
|
||||
int client_fd,
|
||||
union mysockaddr* client_address)
|
||||
{
|
||||
@@ -596,7 +596,7 @@ void accept_nbd_client(
|
||||
}
|
||||
|
||||
/** Accept either an NBD or control socket connection, dispatch appropriately */
|
||||
void serve_accept_loop(struct mode_serve_params* params)
|
||||
void serve_accept_loop(struct server* params)
|
||||
{
|
||||
while (1) {
|
||||
int activity_fd, client_fd;
|
||||
@@ -608,7 +608,7 @@ void serve_accept_loop(struct mode_serve_params* params)
|
||||
FD_SET(params->server_fd, &fds);
|
||||
FD_SET(params->close_signal[0], &fds);
|
||||
if (params->control_socket_name)
|
||||
FD_SET(params->control, &fds);
|
||||
FD_SET(params->control_fd, &fds);
|
||||
|
||||
SERVER_ERROR_ON_FAILURE(select(FD_SETSIZE, &fds,
|
||||
NULL, NULL, NULL), "select() failed");
|
||||
@@ -617,7 +617,7 @@ void serve_accept_loop(struct mode_serve_params* params)
|
||||
return;
|
||||
|
||||
activity_fd = FD_ISSET(params->server_fd, &fds) ? params->server_fd:
|
||||
params->control;
|
||||
params->control_fd;
|
||||
client_fd = accept(activity_fd, &client_address.generic, &socklen);
|
||||
|
||||
SERVER_ERROR_ON_FAILURE(
|
||||
@@ -627,7 +627,7 @@ void serve_accept_loop(struct mode_serve_params* params)
|
||||
|
||||
if (activity_fd == params->server_fd)
|
||||
accept_nbd_client(params, client_fd, &client_address);
|
||||
if (activity_fd == params->control)
|
||||
if (activity_fd == params->control_fd)
|
||||
accept_control_connection(params, client_fd, &client_address);
|
||||
|
||||
SERVER_ERROR_ON_FAILURE(
|
||||
@@ -640,7 +640,7 @@ void serve_accept_loop(struct mode_serve_params* params)
|
||||
/** Initialisation function that sets up the initial allocation map, i.e. so
|
||||
* we know which blocks of the file are allocated.
|
||||
*/
|
||||
void serve_init_allocation_map(struct mode_serve_params* params)
|
||||
void serve_init_allocation_map(struct server* params)
|
||||
{
|
||||
int fd = open(params->filename, O_RDONLY);
|
||||
off64_t size;
|
||||
@@ -655,12 +655,12 @@ void serve_init_allocation_map(struct mode_serve_params* params)
|
||||
}
|
||||
|
||||
/** Closes sockets, frees memory and waits for all client threads to finish */
|
||||
void serve_cleanup(struct mode_serve_params* params)
|
||||
void serve_cleanup(struct server* params)
|
||||
{
|
||||
int i;
|
||||
|
||||
close(params->server_fd);
|
||||
close(params->control);
|
||||
close(params->control_fd);
|
||||
if (params->acl)
|
||||
free(params->acl);
|
||||
//free(params->filename);
|
||||
@@ -688,7 +688,7 @@ void serve_cleanup(struct mode_serve_params* params)
|
||||
}
|
||||
|
||||
/** Full lifecycle of the server */
|
||||
void do_serve(struct mode_serve_params* params)
|
||||
void do_serve(struct server* params)
|
||||
{
|
||||
pthread_mutex_init(¶ms->l_accept, NULL);
|
||||
pthread_mutex_init(¶ms->l_io, NULL);
|
||||
|
Reference in New Issue
Block a user