diff options
author | Jiri Pirko <jiri@resnulli.us> | 2014-05-12 15:44:44 +0200 |
---|---|---|
committer | Jiri Pirko <jiri@resnulli.us> | 2014-05-12 15:52:20 +0200 |
commit | 2551bec6d7bbc7b5c8ab301ed8de9a83f892de99 (patch) | |
tree | c4168f851850720c859d5abb2f59ffd4ba793b63 | |
parent | 0dc5ec792d35625094d8f0dc32d58fbdbc2c24d7 (diff) | |
download | libteam-2551bec6d7bbc7b5c8ab301ed8de9a83f892de99.tar.gz |
teamd: allow to change debug level during run
Signed-off-by: Jiri Pirko <jiri@resnulli.us>
-rw-r--r-- | teamd/teamd.c | 34 | ||||
-rw-r--r-- | teamd/teamd.h | 2 | ||||
-rw-r--r-- | teamd/teamd_state.c | 10 |
3 files changed, 43 insertions, 3 deletions
diff --git a/teamd/teamd.c b/teamd/teamd.c index a45a7fc..deffdc0 100644 --- a/teamd/teamd.c +++ b/teamd/teamd.c @@ -1149,19 +1149,47 @@ static const struct team_change_handler debug_change_handler = { .type_mask = TEAM_PORT_CHANGE | TEAM_OPTION_CHANGE | TEAM_IFINFO_CHANGE, }; +static int teamd_register_debug_handler(struct teamd_context *ctx) +{ + return team_change_handler_register_head(ctx->th, + &debug_change_handler, ctx); +} + static int teamd_register_default_handlers(struct teamd_context *ctx) { if (!ctx->debug) return 0; - return team_change_handler_register_head(ctx->th, - &debug_change_handler, ctx); + return teamd_register_debug_handler(ctx); +} + +static void teamd_unregister_debug_handler(struct teamd_context *ctx) +{ + team_change_handler_unregister(ctx->th, &debug_change_handler, ctx); } static void teamd_unregister_default_handlers(struct teamd_context *ctx) { if (!ctx->debug) return; - team_change_handler_unregister(ctx->th, &debug_change_handler, ctx); + teamd_unregister_debug_handler(ctx); +} + +int teamd_change_debug_level(struct teamd_context *ctx, unsigned int new_debug) +{ + int err = 0; + + if (!ctx->debug && new_debug) { + daemon_set_verbosity(LOG_DEBUG); + err = teamd_register_debug_handler(ctx); + } + if (ctx->debug && !new_debug) { + daemon_set_verbosity(LOG_WARNING); + teamd_unregister_debug_handler(ctx); + } + if (err) + return err; + ctx->debug = new_debug; + return 0; } static int teamd_init(struct teamd_context *ctx) diff --git a/teamd/teamd.h b/teamd/teamd.h index 46dbafc..71add22 100644 --- a/teamd/teamd.h +++ b/teamd/teamd.h @@ -254,6 +254,8 @@ int teamd_loop_callback_disable(struct teamd_context *ctx, const char *cb_name, void teamd_run_loop_quit(struct teamd_context *ctx, int err); void teamd_run_loop_restart(struct teamd_context *ctx); +int teamd_change_debug_level(struct teamd_context *ctx, unsigned int new_debug); + /* Runner structures */ extern const struct teamd_runner teamd_runner_broadcast; extern const struct teamd_runner teamd_runner_roundrobin; diff --git a/teamd/teamd_state.c b/teamd/teamd_state.c index ddfd855..6fbbfa9 100644 --- a/teamd/teamd_state.c +++ b/teamd/teamd_state.c @@ -639,6 +639,15 @@ static int setup_state_debug_level_get(struct teamd_context *ctx, return 0; } +static int setup_state_debug_level_set(struct teamd_context *ctx, + struct team_state_gsc *gsc, + void *priv) +{ + if (gsc->data.int_val < 0) + return -EINVAL; + return teamd_change_debug_level(ctx, gsc->data.int_val); +} + static int setup_state_daemonized_get(struct teamd_context *ctx, struct team_state_gsc *gsc, void *priv) @@ -688,6 +697,7 @@ static const struct teamd_state_val setup_state_vals[] = { .subpath = "debug_level", .type = TEAMD_STATE_ITEM_TYPE_INT, .getter = setup_state_debug_level_get, + .setter = setup_state_debug_level_set, }, { .subpath = "daemonized", |