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;
|
const int last_pass = mirror_maximum_passes-1;
|
||||||
int pass;
|
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;
|
struct bitset_mapping *map = serve->mirror->dirty_map;
|
||||||
|
|
||||||
for (pass=0; pass < mirror_maximum_passes; pass++) {
|
for (pass=0; pass < mirror_maximum_passes; pass++) {
|
||||||
@@ -333,7 +333,7 @@ void* control_serve(void* client_uncast)
|
|||||||
return NULL;
|
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;
|
pthread_t control_thread;
|
||||||
struct control_params* control_params;
|
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;
|
struct sockaddr_un bind_address;
|
||||||
|
|
||||||
if (!params->control_socket_name)
|
if (!params->control_socket_name)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
params->control = socket(AF_UNIX, SOCK_STREAM, 0);
|
params->control_fd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
SERVER_ERROR_ON_FAILURE(params->control,
|
SERVER_ERROR_ON_FAILURE(params->control_fd ,
|
||||||
"Couldn't create control socket");
|
"Couldn't create control socket");
|
||||||
|
|
||||||
memset(&bind_address, 0, sizeof(bind_address));
|
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 */
|
unlink(params->control_socket_name); /* ignore failure */
|
||||||
|
|
||||||
SERVER_ERROR_ON_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",
|
"Couldn't bind control socket to %s",
|
||||||
params->control_socket_name
|
params->control_socket_name
|
||||||
);
|
);
|
||||||
|
|
||||||
SERVER_ERROR_ON_FAILURE(
|
SERVER_ERROR_ON_FAILURE(
|
||||||
listen(params->control, 5),
|
listen(params->control_fd , 5),
|
||||||
"Couldn't listen on control socket"
|
"Couldn't listen on control socket"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
#ifndef __CONTROL_H
|
#ifndef __CONTROL_H
|
||||||
#define __CONTROL_H
|
#define __CONTROL_H
|
||||||
|
|
||||||
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);
|
||||||
void serve_open_control_socket(struct mode_serve_params* params);
|
void serve_open_control_socket(struct server* params);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@@ -43,7 +43,7 @@ void exit_err( char *msg )
|
|||||||
}
|
}
|
||||||
|
|
||||||
void params_serve(
|
void params_serve(
|
||||||
struct mode_serve_params* out,
|
struct server* out,
|
||||||
char* s_ip_address,
|
char* s_ip_address,
|
||||||
char* s_port,
|
char* s_port,
|
||||||
char* s_file,
|
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_read(struct mode_readwrite_params* params);
|
||||||
void do_write(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);
|
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 default_deny = 0; // not on by default
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
struct mode_serve_params serve;
|
struct server serve;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
c = getopt_long(argc, argv, serve_short_options, serve_options, NULL);
|
c = getopt_long(argc, argv, serve_short_options, serve_options, NULL);
|
||||||
|
@@ -30,11 +30,11 @@ struct mirror_status {
|
|||||||
|
|
||||||
struct control_params {
|
struct control_params {
|
||||||
int socket;
|
int socket;
|
||||||
struct mode_serve_params* serve;
|
struct server* serve;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define MAX_NBD_CLIENTS 16
|
#define MAX_NBD_CLIENTS 16
|
||||||
struct mode_serve_params {
|
struct server {
|
||||||
/** address/port to bind to */
|
/** address/port to bind to */
|
||||||
union mysockaddr bind_to;
|
union mysockaddr bind_to;
|
||||||
/** does an empty ACL mean "deny all"? */
|
/** does an empty ACL mean "deny all"? */
|
||||||
@@ -72,7 +72,7 @@ struct mode_serve_params {
|
|||||||
|
|
||||||
struct mirror_status* mirror;
|
struct mirror_status* mirror;
|
||||||
int server_fd;
|
int server_fd;
|
||||||
int control;
|
int control_fd;
|
||||||
|
|
||||||
char* block_allocation_map;
|
char* block_allocation_map;
|
||||||
|
|
||||||
@@ -94,7 +94,7 @@ struct client_params {
|
|||||||
int fileno;
|
int fileno;
|
||||||
char* mapped;
|
char* mapped;
|
||||||
|
|
||||||
struct mode_serve_params* serve; /* FIXME: remove above duplication */
|
struct server* serve; /* FIXME: remove above duplication */
|
||||||
};
|
};
|
||||||
|
|
||||||
/* FIXME: wrong place */
|
/* 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 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)
|
if (serve->mirror)
|
||||||
bitset_set_range(serve->mirror->dirty_map, from, len);
|
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 errno_old = errno;
|
||||||
int result = fcntl(serve->server_fd, F_GETFD, 0) < 0;
|
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. */
|
/** 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;
|
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
|
* goes through the current list, waits for any threads that have finished
|
||||||
* and returns the next slot free (or -1 if there are none).
|
* 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;
|
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.
|
* address doesn't match, or if there are too many clients already connected.
|
||||||
*/
|
*/
|
||||||
void accept_nbd_client(
|
void accept_nbd_client(
|
||||||
struct mode_serve_params* params,
|
struct server* params,
|
||||||
int client_fd,
|
int client_fd,
|
||||||
union mysockaddr* client_address)
|
union mysockaddr* client_address)
|
||||||
{
|
{
|
||||||
@@ -596,7 +596,7 @@ void accept_nbd_client(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Accept either an NBD or control socket connection, dispatch appropriately */
|
/** 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) {
|
while (1) {
|
||||||
int activity_fd, client_fd;
|
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->server_fd, &fds);
|
||||||
FD_SET(params->close_signal[0], &fds);
|
FD_SET(params->close_signal[0], &fds);
|
||||||
if (params->control_socket_name)
|
if (params->control_socket_name)
|
||||||
FD_SET(params->control, &fds);
|
FD_SET(params->control_fd, &fds);
|
||||||
|
|
||||||
SERVER_ERROR_ON_FAILURE(select(FD_SETSIZE, &fds,
|
SERVER_ERROR_ON_FAILURE(select(FD_SETSIZE, &fds,
|
||||||
NULL, NULL, NULL), "select() failed");
|
NULL, NULL, NULL), "select() failed");
|
||||||
@@ -617,7 +617,7 @@ void serve_accept_loop(struct mode_serve_params* params)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
activity_fd = FD_ISSET(params->server_fd, &fds) ? params->server_fd:
|
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);
|
client_fd = accept(activity_fd, &client_address.generic, &socklen);
|
||||||
|
|
||||||
SERVER_ERROR_ON_FAILURE(
|
SERVER_ERROR_ON_FAILURE(
|
||||||
@@ -627,7 +627,7 @@ void serve_accept_loop(struct mode_serve_params* params)
|
|||||||
|
|
||||||
if (activity_fd == params->server_fd)
|
if (activity_fd == params->server_fd)
|
||||||
accept_nbd_client(params, client_fd, &client_address);
|
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);
|
accept_control_connection(params, client_fd, &client_address);
|
||||||
|
|
||||||
SERVER_ERROR_ON_FAILURE(
|
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
|
/** Initialisation function that sets up the initial allocation map, i.e. so
|
||||||
* we know which blocks of the file are allocated.
|
* 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);
|
int fd = open(params->filename, O_RDONLY);
|
||||||
off64_t size;
|
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 */
|
/** 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;
|
int i;
|
||||||
|
|
||||||
close(params->server_fd);
|
close(params->server_fd);
|
||||||
close(params->control);
|
close(params->control_fd);
|
||||||
if (params->acl)
|
if (params->acl)
|
||||||
free(params->acl);
|
free(params->acl);
|
||||||
//free(params->filename);
|
//free(params->filename);
|
||||||
@@ -688,7 +688,7 @@ void serve_cleanup(struct mode_serve_params* params)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Full lifecycle of the server */
|
/** 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_accept, NULL);
|
||||||
pthread_mutex_init(¶ms->l_io, NULL);
|
pthread_mutex_init(¶ms->l_io, NULL);
|
||||||
|
Reference in New Issue
Block a user