import mars-71.tgz

This commit is contained in:
Thomas Schoebel-Theuer 2011-03-04 16:14:20 +01:00
parent fac0abd8ce
commit aa208e44d4
4 changed files with 67 additions and 48 deletions

2
mars.h
View File

@ -265,7 +265,7 @@ extern int mars_power_button_recursive(struct mars_brick *brick, bool val, int
#ifdef _STRATEGY // call this only in strategy bricks, never in ordinary bricks #ifdef _STRATEGY // call this only in strategy bricks, never in ordinary bricks
#define MARS_ARGV_MAX 4 #define MARS_ARGV_MAX 4
#define MARS_PATH_MAX 64 #define MARS_PATH_MAX 128
extern char *my_id(void); extern char *my_id(void);

View File

@ -46,8 +46,10 @@ static int _connect(struct client_output *output, const char *str)
if (!output->path) { if (!output->path) {
output->path = kstrdup(str, GFP_MARS); output->path = kstrdup(str, GFP_MARS);
status = -ENOMEM; status = -ENOMEM;
if (!output->path) if (!output->path) {
MARS_DBG("no mem\n");
goto done; goto done;
}
status = -EINVAL; status = -EINVAL;
output->host = strchr(output->path, '@'); output->host = strchr(output->path, '@');
if (!output->host) { if (!output->host) {
@ -60,12 +62,18 @@ static int _connect(struct client_output *output, const char *str)
} }
status = mars_create_sockaddr(&sockaddr, output->host); status = mars_create_sockaddr(&sockaddr, output->host);
if (unlikely(status < 0)) if (unlikely(status < 0)) {
MARS_DBG("no sockaddr, status = %d\n", status);
goto done; goto done;
}
status = mars_create_socket(&output->socket, &sockaddr, false); status = mars_create_socket(&output->socket, &sockaddr, false);
if (unlikely(status < 0)) { if (unlikely(status < 0)) {
output->socket = NULL; if (status == -EINPROGRESS) {
MARS_DBG("operation is in progress....\n");
goto really_done; // give it a chance next time
}
MARS_DBG("no socket, status = %d\n", status);
goto done; goto done;
} }
@ -76,15 +84,21 @@ static int _connect(struct client_output *output, const char *str)
}; };
status = mars_send_struct(&output->socket, &cmd, mars_cmd_meta); status = mars_send_struct(&output->socket, &cmd, mars_cmd_meta);
if (unlikely(status < 0)) if (unlikely(status < 0)) {
MARS_DBG("send of connect failed, status = %d\n", status);
goto done; goto done;
} }
}
if (status >= 0) { if (status >= 0) {
struct mars_cmd cmd = { struct mars_cmd cmd = {
.cmd_code = CMD_GETINFO, .cmd_code = CMD_GETINFO,
}; };
status = mars_send_struct(&output->socket, &cmd, mars_cmd_meta); status = mars_send_struct(&output->socket, &cmd, mars_cmd_meta);
if (unlikely(status < 0)) {
MARS_DBG("send of getinfo failed, status = %d\n", status);
goto done;
}
} }
done: done:
@ -92,6 +106,7 @@ done:
MARS_INF("cannot connect to remote host '%s' (status = %d) -- retrying\n", output->host ? output->host : "NULL", status); MARS_INF("cannot connect to remote host '%s' (status = %d) -- retrying\n", output->host ? output->host : "NULL", status);
_kill_socket(output); _kill_socket(output);
} }
really_done:
return status; return status;
} }

View File

@ -123,20 +123,16 @@ EXPORT_SYMBOL_GPL(mars_create_sockaddr);
int mars_create_socket(struct socket **sock, struct sockaddr_storage *addr, bool is_server) int mars_create_socket(struct socket **sock, struct sockaddr_storage *addr, bool is_server)
{ {
struct sockaddr null_bind = {};
struct sockaddr *sockaddr = (void*)addr; struct sockaddr *sockaddr = (void*)addr;
int x_true = 1; int x_true = 1;
int status; int status = 0;
if (!is_server) {
sockaddr = &null_bind;
}
if (!*sock) {
status = sock_create_kern(AF_INET, SOCK_STREAM, IPPROTO_TCP, sock); status = sock_create_kern(AF_INET, SOCK_STREAM, IPPROTO_TCP, sock);
if (status < 0) { if (unlikely(status < 0)) {
*sock = NULL; *sock = NULL;
MARS_ERR("cannot create socket, status = %d\n", status); MARS_ERR("cannot create socket, status = %d\n", status);
return status; goto done;
} }
/* TODO: improve this by a table-driven approach /* TODO: improve this by a table-driven approach
@ -158,21 +154,28 @@ int mars_create_socket(struct socket **sock, struct sockaddr_storage *addr, bool
_check(status); _check(status);
status = kernel_setsockopt(*sock, IPPROTO_TCP, TCP_KEEPIDLE, (char*)&default_tcp_params.tcp_keepidle, sizeof(default_tcp_params.tcp_keepidle)); status = kernel_setsockopt(*sock, IPPROTO_TCP, TCP_KEEPIDLE, (char*)&default_tcp_params.tcp_keepidle, sizeof(default_tcp_params.tcp_keepidle));
_check(status); _check(status);
status = kernel_bind(*sock, sockaddr, sizeof(*sockaddr));
if (status < 0) {
MARS_ERR("bind failed, status = %d\n", status);
return status;
} }
if (!is_server) { if (is_server) {
sockaddr = (void*)addr; status = kernel_bind(*sock, sockaddr, sizeof(*sockaddr));
if (unlikely(status < 0)) {
MARS_ERR("bind failed, status = %d\n", status);
sock_release(*sock);
*sock = NULL;
goto done;
}
status = kernel_listen(*sock, 16);
if (status < 0) {
MARS_ERR("listen failed, status = %d\n", status);
}
} else {
status = kernel_connect(*sock, sockaddr, sizeof(*sockaddr), 0); status = kernel_connect(*sock, sockaddr, sizeof(*sockaddr), 0);
if (status < 0) { if (status < 0) {
MARS_ERR("connect failed, status = %d\n", status); MARS_ERR("connect failed, status = %d\n", status);
} }
} }
done:
return status; return status;
} }
EXPORT_SYMBOL_GPL(mars_create_socket); EXPORT_SYMBOL_GPL(mars_create_socket);

View File

@ -9,7 +9,8 @@ my $mars = "/mars";
my $host = `uname -n` or die "cannot determine my network node name\n"; my $host = `uname -n` or die "cannot determine my network node name\n";
chomp $host; chomp $host;
my $ip = `ip a` or die "cannot determine my IP address\n"; my $ip = `ip a` or die "cannot determine my IP address\n";
$ip =~ s/\A.*inet +(?!127\.0\.)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*\Z/$1/ms or die "cannot parse my IP address\n"; $ip =~ s/\A.*inet +(?!127\.0\.)([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+).*?\Z/$1/ms or die "cannot parse my IP address\n";
print "my IP is $ip\n";
umask 0177; umask 0177;
die "only root may use this tool\n" unless `whoami` eq "root\n"; # getpid() seems to be missing in perlfunc die "only root may use this tool\n" unless `whoami` eq "root\n"; # getpid() seems to be missing in perlfunc
@ -20,7 +21,7 @@ die "only root may use this tool\n" unless `whoami` eq "root\n"; # getpid() seem
sub check_id { sub check_id {
my $str = shift; my $str = shift;
die "identifier '$str' has disallowed characters" unless $str =~ m/^[A-Za-z_][A-Za-z0-9_]*$/; die "identifier '$str' has disallowed characters" unless $str =~ m/^[A-Za-z_][-A-Za-z0-9_]*$/;
die "identifier '$str' is too long (only 16 chars allowed)" if length($str) > 16; die "identifier '$str' is too long (only 16 chars allowed)" if length($str) > 16;
} }
@ -214,8 +215,8 @@ sub create_res {
system("rm -f $tmp/syncstatus-$host"); system("rm -f $tmp/syncstatus-$host");
symlink("0", "$tmp/syncstatus-$host") or die "cannot start initial sync\n"; symlink("0", "$tmp/syncstatus-$host") or die "cannot start initial sync\n";
system("rm -f $tmp/connect-$host"); system("rm -f $tmp/connect-$host");
symlink($primary, "$tmp/connect-$host") or die "cannot create peer symlink\n"; symlink($primary, "$tmp/connect-$host") or die "cannot create peer connect symlink\n";
symlink($host, "$tmp/connect-$primary") unless ( -l "$tmp/connect-$primary" or -l "$tmp/off.connect-$primary" ); symlink($host, "$tmp/connect-$primary") unless -l "$tmp/connect-$primary";
print "successfully joined resource '$res'\n"; print "successfully joined resource '$res'\n";
} }
} }