light: show runtime connection status information

This commit is contained in:
Thomas Schoebel-Theuer 2013-04-11 14:58:36 +02:00
parent cc0b41ca79
commit f5fae8e4ba
7 changed files with 75 additions and 0 deletions

View File

@ -196,6 +196,32 @@ config MARS_LOADAVG_LIMIT
---help---
Normally ON.
config MARS_SHOW_CONNECTIONS
bool "show connection status symlinks"
depends on MARS
default n
---help---
Normally OFF.
When enabled, the status of all current network connections is
written to /mars/resource-$resource/local-$host/connect-*
showing the current status of all network connections by
the following encoding:
-1 = connection is closed (not intended to start)
0 = connection is interrupted / not established
1 = connection is established at TCP level
Warning! the symlinks are not deleted by the kernel. You have
to cleanup old symlinks by yourself in userspace.
When you forget the cleanup in regular intervals, you may
end up with thoundands of symlinks accumulating in the
/mars/resource-$resource/local-$host/ directory over a
longer time.
If unsure, say N here.
#config MARS_HUNG
# bool "hangup on kernel stacktrace (EXPERIMENTAL!!!)"
# depends on MARS && MARS_BIGMODULE!=m

View File

@ -31,6 +31,7 @@ static void _kill_thread(struct client_threadinfo *ti, const char *name)
static void _kill_socket(struct client_output *output)
{
output->brick->connection_state = 1;
if (mars_socket_is_alive(&output->socket)) {
MARS_DBG("shutdown socket\n");
mars_shutdown_socket(&output->socket);
@ -485,6 +486,7 @@ static int sender_thread(void *data)
_do_timeout(output, &output->mref_list, false);
continue;
}
brick->connection_state = 2;
do_kill = true;
/* Re-Submit any waiting requests
*/
@ -584,6 +586,7 @@ static int client_switch(struct client_brick *brick)
if (brick->power.button) {
mars_power_led_off((void*)brick, false);
if (!output->sender.thread) {
brick->connection_state = 1;
output->sender.thread = brick_thread_create(sender_thread, output, "mars_sender%d", thread_count++);
if (unlikely(!output->sender.thread)) {
MARS_ERR("cannot start sender thread\n");
@ -597,6 +600,7 @@ static int client_switch(struct client_brick *brick)
} else {
mars_power_led_on((void*)brick, false);
_kill_thread(&output->sender, "sender");
brick->connection_state = 0;
if (!output->sender.thread) {
mars_power_led_off((void*)brick, !output->sender.thread);
}

View File

@ -26,6 +26,8 @@ struct client_brick {
int max_flying; // limit on parallelism
int io_timeout; // > 0: report IO errors after timeout (in seconds)
bool limit_mode;
// readonly from outside
int connection_state; // 0 = switched off, 1 = not connected, 2 = connected
};
struct client_input {

View File

@ -204,6 +204,7 @@ ctl_table mars_table[] = {
#ifdef CONFIG_MARS_DEBUG
INT_ENTRY("show_debug_messages", brick_say_debug, 0600),
INT_ENTRY("show_statistics", global_show_statist, 0600),
INT_ENTRY("show_connections", global_show_connections, 0600),
#endif
INT_ENTRY("logger_completion_semantics", trans_logger_completion_semantics, 0600),
INT_ENTRY("logger_do_crc", trans_logger_do_crc, 0600),

View File

@ -164,6 +164,7 @@ extern int mars_power_button_recursive(struct mars_brick *brick, bool val, bool
// statistics
extern int global_show_statist;
extern int global_show_connections;
void show_statistics(struct mars_global *global, const char *class);

View File

@ -1571,6 +1571,25 @@ EXPORT_SYMBOL_GPL(make_brick_all);
/////////////////////////////////////////////////////////////////////////
// generic symlink updates
void update_client_links(struct client_brick *brick)
{
char val[8];
const char *name;
name = backskip_replace(brick->brick_path, '/', true, "/local-%s/connection-", my_id());
if (unlikely(!name))
return; // silently
sprintf(val, "%d", brick->connection_state - 1);
mars_symlink(val, name, NULL, 0);
brick_string_free(name);
}
/////////////////////////////////////////////////////////////////////////
// statistics
int global_show_statist =
@ -1581,6 +1600,14 @@ int global_show_statist =
#endif
EXPORT_SYMBOL_GPL(global_show_statist);
int global_show_connections =
#ifdef CONFIG_MARS_SHOW_CONNECTIONS
1;
#else
0;
#endif
EXPORT_SYMBOL_GPL(global_show_connections);
static
void _show_one(struct mars_brick *test, int *brick_count)
{
@ -1637,6 +1664,19 @@ void show_statistics(struct mars_global *global, const char *class)
int dent_count = 0;
int brick_count = 0;
// update all connection state symlinks
if (global_show_connections) {
down_read(&global->brick_mutex);
for (tmp = global->brick_anchor.next; tmp != &global->brick_anchor; tmp = tmp->next) {
struct mars_brick *test;
test = container_of(tmp, struct mars_brick, global_brick_link);
if (test->type == (void*)&client_brick_type) {
update_client_links((void*)test);
}
}
up_read(&global->brick_mutex);
}
if (!global_show_statist)
return; // silently

View File

@ -633,6 +633,7 @@ sub create_res {
mkdir("$tmp/userspace") unless -d "$tmp/userspace";
mkdir("$tmp/defaults") unless -d "$tmp/defaults";
mkdir("$tmp/defaults-$host");
mkdir("$tmp/local-$host");
mkdir("$tmp/actual-$host");
my $todo = "$tmp/todo-$host";
mkdir($todo);