[PATCH] teamd: add an option to force log output to stdout, stderr or syslog
by Hangbin Liu
By default, libdaemon prints the logs to stderr, and switches to syslog
if the precess daemonizes.
When some users, e.g. NetworkManager, run teamd foreground, the logs printed
in syslog will as coming from NetworkManager, with mixed NetworkManager's
own debug logs, which makes people feel a mess and hard to debug.
Add option -l to support force teamd log output to stdout, stderr or
syslog. Also add a global env TEAM_LOG_OUTPUT, which could be used for
old version compatibility.
Signed-off-by: Hangbin Liu <liuhangbin(a)gmail.com>
---
man/teamd.8 | 3 +++
teamd/teamd.c | 18 +++++++++++++++++-
teamd/teamd.h | 1 +
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/man/teamd.8 b/man/teamd.8
index 03b525c..3d27eae 100644
--- a/man/teamd.8
+++ b/man/teamd.8
@@ -69,6 +69,9 @@ Use the specified PID file.
.B "\-g, \-\-debug"
Turns on debugging messages. Repeating the option increases verbosity.
.TP
+.B "\-l, \-\-log-output"
+Force teamd log output to stdout, stderr or syslog.
+.TP
.B "\-r, \-\-force-recreate"
Force team device recreation in case it already exists.
.TP
diff --git a/teamd/teamd.c b/teamd/teamd.c
index aac2511..6c47312 100644
--- a/teamd/teamd.c
+++ b/teamd/teamd.c
@@ -107,6 +107,7 @@ static void print_help(const struct teamd_context *ctx) {
" file will be ignored)\n"
" -p --pid-file=FILE Use the specified PID file\n"
" -g --debug Increase verbosity\n"
+ " -l --log-output Force teamd log output to stdout, stderr or syslog\n"
" -r --force-recreate Force team device recreation in case it\n"
" already exists\n"
" -o --take-over Take over the device if it already exists\n"
@@ -140,6 +141,7 @@ static int parse_command_line(struct teamd_context *ctx,
{ "config", required_argument, NULL, 'c' },
{ "pid-file", required_argument, NULL, 'p' },
{ "debug", no_argument, NULL, 'g' },
+ { "log-output", required_argument, NULL, 'l' },
{ "force-recreate", no_argument, NULL, 'r' },
{ "take-over", no_argument, NULL, 'o' },
{ "no-quit-destroy", no_argument, NULL, 'N' },
@@ -152,7 +154,7 @@ static int parse_command_line(struct teamd_context *ctx,
{ NULL, 0, NULL, 0 }
};
- while ((opt = getopt_long(argc, argv, "hdkevf:c:p:groNt:nDZ:Uu",
+ while ((opt = getopt_long(argc, argv, "hdkevf:c:p:gl:roNt:nDZ:Uu",
long_options, NULL)) >= 0) {
switch(opt) {
@@ -191,6 +193,10 @@ static int parse_command_line(struct teamd_context *ctx,
case 'g':
ctx->debug++;
break;
+ case 'l':
+ free(ctx->log_output);
+ ctx->log_output = strdup(optarg);
+ break;
case 'r':
ctx->force_recreate = true;
break;
@@ -1494,6 +1500,16 @@ static int teamd_start(struct teamd_context *ctx, enum teamd_exit_code *p_ret)
/* Child */
}
+ ctx->log_output = ctx->log_output ? : getenv("TEAM_LOG_OUTPUT");
+ if (ctx->log_output) {
+ if (strcmp(ctx->log_output, "stdout") == 0)
+ daemon_log_use = DAEMON_LOG_STDOUT;
+ else if (strcmp(ctx->log_output, "stderr") == 0)
+ daemon_log_use = DAEMON_LOG_STDERR;
+ else if (strcmp(ctx->log_output, "syslog") == 0)
+ daemon_log_use = DAEMON_LOG_SYSLOG;
+ }
+
if (daemon_close_all(-1) < 0) {
teamd_log_err("Failed to close all file descriptors.");
daemon_retval_send(errno);
diff --git a/teamd/teamd.h b/teamd/teamd.h
index 3934fc2..01bd022 100644
--- a/teamd/teamd.h
+++ b/teamd/teamd.h
@@ -99,6 +99,7 @@ struct teamd_context {
enum teamd_command cmd;
bool daemonize;
unsigned int debug;
+ char * log_output;
bool force_recreate;
bool take_over;
bool no_quit_destroy;
--
2.5.5
5 years, 5 months
Re: [patch libteam 3/3] teamd: lacp: introduce support for multiple
hwaddr policies
by Jiri Pirko
Wed, Sep 19, 2018 at 05:27:26PM CEST, alexpe(a)mellanox.com wrote:
>Allow user to change hwaddr policy for lacp runner, similar to
>what is currently supported for ab runner:
>- same_all - regular behaviour for LACP. team device will have MAC
> of the first enslaved port or explicit MAC configured with hwaddr
> option. All ports will have the same MAC as their team device.
>- no_change - ports will not change their MAC. team device
> will have MAC of the first enslaved port.
>
>Signed-off-by: Alexander Petrovskiy <alexpe(a)mellanox.com>
Looks ok.
5 years, 5 months
Re: [patch libteam 2/3] teamd: lacp: allow user to set LACP System
ID via config (runner.system_id)
by Jiri Pirko
Wed, Sep 19, 2018 at 05:27:25PM CEST, alexpe(a)mellanox.com wrote:
>Normally lacp runner is using Aggreagtor's MAC for LACP System ID
>to be carried in LACPDUs.
>Make this value configurable by the user, so lacp runner will send
>custom LACP System ID for all actor ports of the team device.
>
>Signed-off-by: Alexander Petrovskiy <alexpe(a)mellanox.com>
>---
> man/teamd.conf.5 | 3 +++
> teamd/teamd_runner_lacp.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---
> 2 files changed, 48 insertions(+), 3 deletions(-)
>
>diff --git a/man/teamd.conf.5 b/man/teamd.conf.5
>index a252042..8862a4f 100644
>--- a/man/teamd.conf.5
>+++ b/man/teamd.conf.5
>@@ -227,6 +227,9 @@ Same as for load balance runner.
> .BR "runner.tx_balancer.balancing_interval " (int)
> Same as for load balance runner.
> .TP
>+.BR "runner.system_id " (string)
>+Desired System ID. Usual MAC address format is accepted.
>+.TP
> .BR "runner.sys_prio " (int)
> System priority, value can be 0 \(en 65535.
> .RS 7
>diff --git a/teamd/teamd_runner_lacp.c b/teamd/teamd_runner_lacp.c
>index 7b8f0a7..c068028 100644
>--- a/teamd/teamd_runner_lacp.c
>+++ b/teamd/teamd_runner_lacp.c
>@@ -142,7 +142,9 @@ struct lacp {
> #define LACP_CFG_DFLT_MIN_PORTS 1
> enum lacp_agg_select_policy agg_select_policy;
> #define LACP_CFG_DFLT_AGG_SELECT_POLICY LACP_AGG_SELECT_LACP_PRIO
>- } cfg;
>+ bool system_id_explicit;
>+ uint8_t system_id[ETH_ALEN]; /* ID */;
>+ } cfg;
> struct teamd_balancer *tb;
> };
>
>@@ -245,10 +247,35 @@ found:
> return 0;
> }
>
>+static int lacp_parse_system_hwaddr(uint8_t *system, const char *system_str)
>+{
>+ int err;
>+ char *hwaddr;
>+ unsigned int hwaddr_len;
Reverse christmas tree ordering please:
******
****
**
>+
>+ err = teamd_parse_hwaddr(system_str, &hwaddr, &hwaddr_len);
>+ if (err) {
>+ teamd_log_err("Failed to parse hardware address for system id.");
>+ return err;
>+ }
>+
>+ if (hwaddr_len != ETH_ALEN) {
>+ teamd_log_err("Passed hardware address for system id has incorrect length (%d), expected: (%d).",
>+ hwaddr_len, ETH_ALEN);
This is not aligned correctly. Should be:
teamd_log_err("Passed hardware address for system id has incorrect length (%d), expected: (%d).",
hwaddr_len, ETH_ALEN);
>+ err = -EINVAL;
>+ goto free_hwaddr;
>+ }
>+ memcpy(system, hwaddr, hwaddr_len);
>+free_hwaddr:
>+ free(hwaddr);
>+ return err;
>+}
>+
> static int lacp_load_config(struct teamd_context *ctx, struct lacp *lacp)
> {
> int err;
> int tmp;
>+ const char *system_id;
> const char *agg_select_policy_name;
>
> err = teamd_config_bool_get(ctx, &lacp->cfg.active, "$.runner.active");
>@@ -256,6 +283,18 @@ static int lacp_load_config(struct teamd_context *ctx, struct lacp *lacp)
> lacp->cfg.active = LACP_CFG_DFLT_ACTIVE;
> teamd_log_dbg("Using active \"%d\".", lacp->cfg.active);
>
>+ err = teamd_config_string_get(ctx, &system_id, "$.runner.system_id");
>+ if (!err) {
>+ err = lacp_parse_system_hwaddr(lacp->cfg.system_id, system_id);
>+ if (err) {
>+ teamd_log_err("\"system_id\" value is invalid.");
>+ return -EINVAL;
>+ }
>+ lacp->cfg.system_id_explicit = true;
>+ }
>+ teamd_log_dbg("Using explicit system_id \"%d\", system_id value \"%s\".",
>+ lacp->cfg.system_id_explicit, system_id);
This log should reside withing the previous "if" boundaries.
Also, lacp->cfg.system_id_explicit is bool. I believe this a is
forgotten part from previous version.
>+
> err = teamd_config_int_get(ctx, &tmp, "$.runner.sys_prio");
> if (err) {
> lacp->cfg.sys_prio = LACP_CFG_DFLT_SYS_PRIO;
>@@ -891,7 +930,10 @@ static void lacp_port_actor_system_update(struct lacp_port *lacp_port)
> {
> struct lacpdu_info *actor = &lacp_port->actor;
>
>- memcpy(actor->system, lacp_port->ctx->hwaddr, ETH_ALEN);
>+ if (lacp_port->lacp->cfg.system_id_explicit)
>+ memcpy(actor->system, lacp_port->lacp->cfg.system_id, ETH_ALEN);
>+ else
>+ memcpy(actor->system, lacp_port->ctx->hwaddr, ETH_ALEN);
> }
>
> static void lacp_port_actor_init(struct lacp_port *lacp_port)
>@@ -1046,7 +1088,7 @@ static int lacpdu_send(struct lacp_port *lacp_port)
> ll_slow = ll_my;
> memcpy(ll_slow.sll_addr, slow_addr, ll_slow.sll_halen);
>
>- memcpy(lacp_port->actor.system, lacp_port->ctx->hwaddr, ETH_ALEN);
>+ lacp_port_actor_system_update(lacp_port);
>
> hwaddr = team_get_ifinfo_orig_hwaddr(lacp_port->tdport->team_ifinfo);
> hwaddr_len = team_get_ifinfo_orig_hwaddr_len(lacp_port->tdport->team_ifinfo);
>--
>2.6.4
>
5 years, 5 months
[patch libteam] teamd/teamd_runner_lacp: lacp_port_set_state
by MK Lim
if new state is PORT_STATE_DEFAULTED, set lacp_port->partner.state
to 0x02
This ensures LACPDU is sent to update the far side when local
local port transitions from default to current
Currently, local port moves from default to current without
sending LACPDU until 30sec later. This causes traffic disruption
because far side has not completed negotiation
Using 0x02 also cause LACPDU to be sent every 1 sec as long as
port remains in defaulted state and LACP mode used is "active"
---
teamd/teamd_runner_lacp.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/teamd/teamd_runner_lacp.c b/teamd/teamd_runner_lacp.c
index 7b8f0a7..555aa06 100644
--- a/teamd/teamd_runner_lacp.c
+++ b/teamd/teamd_runner_lacp.c
@@ -965,7 +965,12 @@ static int lacp_port_set_state(struct lacp_port *lacp_port,
case PORT_STATE_DEFAULTED:
teamd_loop_callback_disable(lacp_port->ctx,
LACP_TIMEOUT_CB_NAME, lacp_port);
- /* fall through */
+ memset(&lacp_port->partner, 0, sizeof(lacp_port->partner));
+ lacp_port->partner.state |= INFO_STATE_LACP_TIMEOUT;
+ err = lacp_port_partner_update(lacp_port);
+ if (err)
+ return err;
+ break;
case PORT_STATE_DISABLED:
memset(&lacp_port->partner, 0, sizeof(lacp_port->partner));
err = lacp_port_partner_update(lacp_port);
--
2.15.1 (Apple Git-101)
5 years, 5 months