mirror: Add --bind to our mirror mode.
Mirroring doesn't actually work yet, of course.
This commit is contained in:
@@ -173,14 +173,17 @@ int control_mirror(struct control_params* client, int linesc, char** lines)
|
|||||||
int fd, map_fd;
|
int fd, map_fd;
|
||||||
struct mirror_status *mirror;
|
struct mirror_status *mirror;
|
||||||
union mysockaddr connect_to;
|
union mysockaddr connect_to;
|
||||||
|
union mysockaddr connect_from;
|
||||||
|
int use_connect_from = 0;
|
||||||
uint64_t max_bytes_per_second;
|
uint64_t max_bytes_per_second;
|
||||||
int action_at_finish;
|
int action_at_finish;
|
||||||
|
|
||||||
|
|
||||||
if (linesc < 2) {
|
if (linesc < 2) {
|
||||||
write_socket("1: mirror takes at least two parameters");
|
write_socket("1: mirror takes at least two parameters");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (parse_ip_to_sockaddr(&connect_to.generic, lines[0]) == 0) {
|
if (parse_ip_to_sockaddr(&connect_to.generic, lines[0]) == 0) {
|
||||||
write_socket("1: bad IP address");
|
write_socket("1: bad IP address");
|
||||||
return -1;
|
return -1;
|
||||||
@@ -192,14 +195,22 @@ int control_mirror(struct control_params* client, int linesc, char** lines)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
connect_to.v4.sin_port = htobe16(connect_to.v4.sin_port);
|
connect_to.v4.sin_port = htobe16(connect_to.v4.sin_port);
|
||||||
|
|
||||||
max_bytes_per_second = 0;
|
|
||||||
if (linesc > 2) {
|
if (linesc > 2) {
|
||||||
|
if (parse_ip_to_sockaddr(&connect_from.generic, lines[2]) == 0) {
|
||||||
|
write_socket("1: bad bind address");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
use_connect_from = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
max_bytes_per_second = 0;
|
||||||
|
if (linesc > 3) {
|
||||||
max_bytes_per_second = atoi(lines[2]);
|
max_bytes_per_second = atoi(lines[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
action_at_finish = ACTION_PROXY;
|
action_at_finish = ACTION_PROXY;
|
||||||
if (linesc > 3) {
|
if (linesc > 4) {
|
||||||
if (strcmp("proxy", lines[3]) == 0)
|
if (strcmp("proxy", lines[3]) == 0)
|
||||||
action_at_finish = ACTION_PROXY;
|
action_at_finish = ACTION_PROXY;
|
||||||
else if (strcmp("exit", lines[3]) == 0)
|
else if (strcmp("exit", lines[3]) == 0)
|
||||||
@@ -212,12 +223,17 @@ int control_mirror(struct control_params* client, int linesc, char** lines)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (linesc > 4) {
|
if (linesc > 5) {
|
||||||
write_socket("1: unrecognised parameters to mirror");
|
write_socket("1: unrecognised parameters to mirror");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** I don't like use_connect_from but socket_connect doesn't take *mysockaddr :( */
|
||||||
|
if (use_connect_from)
|
||||||
|
fd = socket_connect(&connect_to.generic, &connect_from.generic);
|
||||||
|
else
|
||||||
|
fd = socket_connect(&connect_to.generic, NULL);
|
||||||
|
|
||||||
fd = socket_connect(&connect_to.generic, NULL);
|
|
||||||
|
|
||||||
remote_size = socket_nbd_read_hello(fd);
|
remote_size = socket_nbd_read_hello(fd);
|
||||||
remote_size = remote_size; // shush compiler
|
remote_size = remote_size; // shush compiler
|
||||||
|
@@ -257,7 +257,7 @@ void read_acl_param( int c, char **sock )
|
|||||||
read_sock_param( c, sock, acl_help_text );
|
read_sock_param( c, sock, acl_help_text );
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_mirror_param( int c, char **sock, char **ip_addr, char **ip_port )
|
void read_mirror_param( int c, char **sock, char **ip_addr, char **ip_port, char **bind_addr )
|
||||||
{
|
{
|
||||||
switch( c ){
|
switch( c ){
|
||||||
case 'h':
|
case 'h':
|
||||||
@@ -273,6 +273,8 @@ void read_mirror_param( int c, char **sock, char **ip_addr, char **ip_port )
|
|||||||
case 'p':
|
case 'p':
|
||||||
*ip_port = optarg;
|
*ip_port = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'b':
|
||||||
|
*bind_addr = optarg;
|
||||||
case 'v':
|
case 'v':
|
||||||
set_debug(1);
|
set_debug(1);
|
||||||
break;
|
break;
|
||||||
@@ -426,13 +428,13 @@ int mode_mirror( int argc, char *argv[] )
|
|||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
char *sock = NULL;
|
char *sock = NULL;
|
||||||
char *remote_argv[3] = {0};
|
char *remote_argv[4] = {0};
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
c = getopt_long( argc, argv, mirror_short_options, mirror_options, NULL);
|
c = getopt_long( argc, argv, mirror_short_options, mirror_options, NULL);
|
||||||
if ( -1 == c ) break;
|
if ( -1 == c ) break;
|
||||||
read_mirror_param( c, &sock, &remote_argv[0], &remote_argv[1] );
|
read_mirror_param( c, &sock, &remote_argv[0], &remote_argv[1], &remote_argv[2] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( NULL == sock ){
|
if ( NULL == sock ){
|
||||||
@@ -444,8 +446,11 @@ int mode_mirror( int argc, char *argv[] )
|
|||||||
err = 1;
|
err = 1;
|
||||||
}
|
}
|
||||||
if ( err ) { exit_err( mirror_help_text ); }
|
if ( err ) { exit_err( mirror_help_text ); }
|
||||||
|
|
||||||
do_remote_command( "mirror", sock, 2, remote_argv );
|
if (argv[2] == NULL)
|
||||||
|
do_remote_command( "mirror", sock, 2, remote_argv );
|
||||||
|
else
|
||||||
|
do_remote_command( "mirror", sock, 3, remote_argv );
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@@ -136,10 +136,11 @@ struct option mirror_options[] = {
|
|||||||
GETOPT_SOCK,
|
GETOPT_SOCK,
|
||||||
GETOPT_ADDR,
|
GETOPT_ADDR,
|
||||||
GETOPT_PORT,
|
GETOPT_PORT,
|
||||||
|
GETOPT_BIND,
|
||||||
GETOPT_VERBOSE,
|
GETOPT_VERBOSE,
|
||||||
{0}
|
{0}
|
||||||
};
|
};
|
||||||
static char mirror_short_options[] = "hs:l:p:" SOPT_VERBOSE;
|
static char mirror_short_options[] = "hs:l:p:b:" SOPT_VERBOSE;
|
||||||
static char mirror_help_text[] =
|
static char mirror_help_text[] =
|
||||||
"Usage: flexnbd " CMD_MIRROR " <options>\n\n"
|
"Usage: flexnbd " CMD_MIRROR " <options>\n\n"
|
||||||
"Start mirroring from the server with control socket SOCK to one at ADDR:PORT.\n\n"
|
"Start mirroring from the server with control socket SOCK to one at ADDR:PORT.\n\n"
|
||||||
@@ -147,6 +148,7 @@ static char mirror_help_text[] =
|
|||||||
"\t--" OPT_ADDR ",-l <ADDR>\tThe address to mirror to.\n"
|
"\t--" OPT_ADDR ",-l <ADDR>\tThe address to mirror to.\n"
|
||||||
"\t--" OPT_PORT ",-p <PORT>\tThe port to mirror to.\n"
|
"\t--" OPT_PORT ",-p <PORT>\tThe port to mirror to.\n"
|
||||||
SOCK_LINE
|
SOCK_LINE
|
||||||
|
BIND_LINE
|
||||||
VERBOSE_LINE;
|
VERBOSE_LINE;
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user