mirror: Add --bind to our mirror mode.
Mirroring doesn't actually work yet, of course.
This commit is contained in:
@@ -173,9 +173,12 @@ int control_mirror(struct control_params* client, int linesc, char** lines)
|
||||
int fd, map_fd;
|
||||
struct mirror_status *mirror;
|
||||
union mysockaddr connect_to;
|
||||
union mysockaddr connect_from;
|
||||
int use_connect_from = 0;
|
||||
uint64_t max_bytes_per_second;
|
||||
int action_at_finish;
|
||||
|
||||
|
||||
if (linesc < 2) {
|
||||
write_socket("1: mirror takes at least two parameters");
|
||||
return -1;
|
||||
@@ -193,13 +196,21 @@ int control_mirror(struct control_params* client, int linesc, char** lines)
|
||||
}
|
||||
connect_to.v4.sin_port = htobe16(connect_to.v4.sin_port);
|
||||
|
||||
max_bytes_per_second = 0;
|
||||
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]);
|
||||
}
|
||||
|
||||
action_at_finish = ACTION_PROXY;
|
||||
if (linesc > 3) {
|
||||
if (linesc > 4) {
|
||||
if (strcmp("proxy", lines[3]) == 0)
|
||||
action_at_finish = ACTION_PROXY;
|
||||
else if (strcmp("exit", lines[3]) == 0)
|
||||
@@ -212,13 +223,18 @@ int control_mirror(struct control_params* client, int linesc, char** lines)
|
||||
}
|
||||
}
|
||||
|
||||
if (linesc > 4) {
|
||||
if (linesc > 5) {
|
||||
write_socket("1: unrecognised parameters to mirror");
|
||||
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);
|
||||
|
||||
|
||||
remote_size = socket_nbd_read_hello(fd);
|
||||
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 );
|
||||
}
|
||||
|
||||
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 ){
|
||||
case 'h':
|
||||
@@ -273,6 +273,8 @@ void read_mirror_param( int c, char **sock, char **ip_addr, char **ip_port )
|
||||
case 'p':
|
||||
*ip_port = optarg;
|
||||
break;
|
||||
case 'b':
|
||||
*bind_addr = optarg;
|
||||
case 'v':
|
||||
set_debug(1);
|
||||
break;
|
||||
@@ -426,13 +428,13 @@ int mode_mirror( int argc, char *argv[] )
|
||||
{
|
||||
int c;
|
||||
char *sock = NULL;
|
||||
char *remote_argv[3] = {0};
|
||||
char *remote_argv[4] = {0};
|
||||
int err = 0;
|
||||
|
||||
while (1) {
|
||||
c = getopt_long( argc, argv, mirror_short_options, mirror_options, NULL);
|
||||
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 ){
|
||||
@@ -445,7 +447,10 @@ int mode_mirror( int argc, char *argv[] )
|
||||
}
|
||||
if ( err ) { exit_err( mirror_help_text ); }
|
||||
|
||||
if (argv[2] == NULL)
|
||||
do_remote_command( "mirror", sock, 2, remote_argv );
|
||||
else
|
||||
do_remote_command( "mirror", sock, 3, remote_argv );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -136,10 +136,11 @@ struct option mirror_options[] = {
|
||||
GETOPT_SOCK,
|
||||
GETOPT_ADDR,
|
||||
GETOPT_PORT,
|
||||
GETOPT_BIND,
|
||||
GETOPT_VERBOSE,
|
||||
{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[] =
|
||||
"Usage: flexnbd " CMD_MIRROR " <options>\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_PORT ",-p <PORT>\tThe port to mirror to.\n"
|
||||
SOCK_LINE
|
||||
BIND_LINE
|
||||
VERBOSE_LINE;
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user