From patchwork Fri Aug 3 06:43:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hangbin Liu X-Patchwork-Id: 10554599 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A02E215E9 for ; Fri, 3 Aug 2018 06:44:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 88C6D2BFA7 for ; Fri, 3 Aug 2018 06:44:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7C45E2BFF9; Fri, 3 Aug 2018 06:44:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from bastion.fedoraproject.org (bastion01.fedoraproject.org [209.132.181.2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E95C72BFA7 for ; Fri, 3 Aug 2018 06:44:35 +0000 (UTC) Received: from mailman01.phx2.fedoraproject.org (mailman01.phx2.fedoraproject.org [10.5.126.36]) by bastion01.phx2.fedoraproject.org (Postfix) with ESMTP id 2DBFA64D32A1; Fri, 3 Aug 2018 06:44:35 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org 2DBFA64D32A1 Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 1D3F421FA7916; Fri, 3 Aug 2018 06:44:35 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id 8B27A21FA7916; Fri, 3 Aug 2018 06:44:30 +0000 (UTC) Received: from smtp-mm-ib01.fedoraproject.org (smtp-mm-ib01.vpn.fedoraproject.org [192.168.1.83]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 47BAD21FA790E for ; Fri, 3 Aug 2018 06:44:29 +0000 (UTC) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by smtp-mm-ib01.fedoraproject.org (Postfix) with ESMTPS id C2FC2605D2D8 for ; Fri, 3 Aug 2018 06:44:28 +0000 (UTC) Received: by mail-pf1-f194.google.com with SMTP id b11-v6so2720103pfo.3 for ; Thu, 02 Aug 2018 23:44:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=8hVnhQ1JO+LEjH9lrQ0ADlpoy5EOTfE6sdOMWaXhSoU=; b=KN8v9CV6HiTH8Wqq0Wy3BdO8/knBJou8YHIOyH9Csc9NxSvc/I45CEl+AtOYdJdkMQ cAjvhoGtGpbUir/XyFRkZw3ZLrSQUjKOBoAwVmx7a3ZdpTAsdIxkc8oqhQhUBjBaoE5B ELvxvWZDrFVg0t/XfY6PvYGnBKbziZUJpDVZIt6mkc3OJQ/wUMWTtSRre+nmTV/nuxw5 qjvT5wHk1h4lJO5cgWkZ7MJ/hwTfoo2kshVcyLxZDoGaYtCISBXzwJlX1aZ1qe/TPWyQ O7wlRaPN/zlPXMjEa1V7ib8XVBlGpA5VzOyHIXGNweSDLnHg0HUX3A/hkJewo3E0OXzq yZHA== X-Gm-Message-State: AOUpUlF/6kLE3g81WToj3hyWEy0fa342xaQ8RIIgk12MGCC4dJv5zVpQ 5cIocugPtiavInAxKRzruptwiFGF X-Google-Smtp-Source: AAOMgpffi+j7f9CekASJKgIdLKTiP/KHm5meQGcvt65TXhjrfKi0HEjEtigqiBWriB1TXXgS8K2O0Q== X-Received: by 2002:a63:da56:: with SMTP id l22-v6mr2398493pgj.179.1533278667593; Thu, 02 Aug 2018 23:44:27 -0700 (PDT) Received: from leo.usersys.redhat.com ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id p66-v6sm6339751pfd.65.2018.08.02.23.44.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Aug 2018 23:44:26 -0700 (PDT) From: Hangbin Liu To: libteam@lists.fedorahosted.org Subject: [PATCHv2] teamd: add port_master_ifindex_changed for teamd_event_watch_ops Date: Fri, 3 Aug 2018 14:43:49 +0800 Message-Id: <1533278629-26147-1-git-send-email-liuhangbin@gmail.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1531965888-28201-1-git-send-email-liuhangbin@gmail.com> References: <1531965888-28201-1-git-send-email-liuhangbin@gmail.com> Message-ID-Hash: FYMUL6M2NCSCGTUKLEAEKYEENM4LMIMF X-Message-ID-Hash: FYMUL6M2NCSCGTUKLEAEKYEENM4LMIMF X-MailFrom: liuhangbin@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header CC: Jiri Pirko , Jamie Bainbridge , Hangbin Liu X-Mailman-Version: 3.1.1 Precedence: list List-Id: Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP When configure two active-backup teams, one slave each, put them down and up in a loop and test traffic each loop, eventually one of the teams will not accept/transmit traffic as there is no active port. Like this: \#/bin/bash \# In this scenario we add eth1 to team1, eth2 to team2. WAIT=2 COUNT=0 start_team() { num=$1 teamd -o -n -U -d -t team$num -c '{"runner": {"name": "activebackup"},"link_watch": {"name": "ethtool"}}' -gg teamdctl team$num port add eth$num } while :; do echo "===========================================================" let "COUNT++" echo "Loop $COUNT" if teamdctl team1 state | grep -q "active port: eth1" && \ teamdctl team2 state | grep -q "active port: eth2"; then echo "Pass" else echo "FAIL" exit 1 fi teamd -k -t team1 teamd -k -t team2 sleep "$WAIT" start_team 1 & start_team 2 & sleep "$WAIT" done Failure as follows: ]# teamdctl teamX state dump "runner": { "active_port": "" }, This happens because teamd_port_present() fails in the codepath ab_link_watch_handler() -> teamd_for_each_tdport() -> teamd_get_next_tdport() as the link states notification received later than interface up notification. So the teamd_for_each_tdport() for loop can never run against the tdports bound to the ctx and a port is never set active. Currently we only reproduced this with active-backup mode. Fix it by adding a new teamd_event_watch_ops port_master_ifindex_changed for ab mode. V2: update commit description from Jamie Bainbridge's reply. Signed-off-by: Hangbin Liu --- teamd/teamd.h | 5 +++++ teamd/teamd_events.c | 19 +++++++++++++++++++ teamd/teamd_ifinfo_watch.c | 5 +++++ teamd/teamd_runner_activebackup.c | 8 ++++++++ 4 files changed, 37 insertions(+) diff --git a/teamd/teamd.h b/teamd/teamd.h index 5dbfb9b..3934fc2 100644 --- a/teamd/teamd.h +++ b/teamd/teamd.h @@ -189,6 +189,9 @@ struct teamd_event_watch_ops { struct teamd_port *tdport, void *priv); int (*port_ifname_changed)(struct teamd_context *ctx, struct teamd_port *tdport, void *priv); + int (*port_master_ifindex_changed)(struct teamd_context *ctx, + struct teamd_port *tdport, + void *priv); int (*option_changed)(struct teamd_context *ctx, struct team_option *option, void *priv); char *option_changed_match_name; @@ -208,6 +211,8 @@ int teamd_event_ifinfo_hwaddr_changed(struct teamd_context *ctx, struct team_ifinfo *ifinfo); int teamd_event_ifinfo_ifname_changed(struct teamd_context *ctx, struct team_ifinfo *ifinfo); +int teamd_event_ifinfo_master_ifindex_changed(struct teamd_context *ctx, + struct team_ifinfo *ifinfo); int teamd_event_ifinfo_admin_state_changed(struct teamd_context *ctx, struct team_ifinfo *ifinfo); int teamd_events_init(struct teamd_context *ctx); diff --git a/teamd/teamd_events.c b/teamd/teamd_events.c index 1a95974..65aa46a 100644 --- a/teamd/teamd_events.c +++ b/teamd/teamd_events.c @@ -167,6 +167,25 @@ int teamd_event_ifinfo_ifname_changed(struct teamd_context *ctx, return 0; } +int teamd_event_ifinfo_master_ifindex_changed(struct teamd_context *ctx, + struct team_ifinfo *ifinfo) +{ + struct event_watch_item *watch; + uint32_t ifindex = team_get_ifinfo_ifindex(ifinfo); + struct teamd_port *tdport = teamd_get_port(ctx, ifindex); + int err; + + list_for_each_node_entry(watch, &ctx->event_watch_list, list) { + if (watch->ops->port_master_ifindex_changed && tdport) { + err = watch->ops->port_master_ifindex_changed(ctx, tdport, + watch->priv); + if (err) + return err; + } + } + return 0; +} + int teamd_event_ifinfo_admin_state_changed(struct teamd_context *ctx, struct team_ifinfo *ifinfo) { diff --git a/teamd/teamd_ifinfo_watch.c b/teamd/teamd_ifinfo_watch.c index f334ff6..6a19532 100644 --- a/teamd/teamd_ifinfo_watch.c +++ b/teamd/teamd_ifinfo_watch.c @@ -59,6 +59,11 @@ static int ifinfo_change_handler_func(struct team_handle *th, void *priv, if (err) return err; } + if (team_is_ifinfo_master_ifindex_changed(ifinfo)) { + err = teamd_event_ifinfo_master_ifindex_changed(ctx, ifinfo); + if (err) + return err; + } } return 0; } diff --git a/teamd/teamd_runner_activebackup.c b/teamd/teamd_runner_activebackup.c index 8a3447f..f92d341 100644 --- a/teamd/teamd_runner_activebackup.c +++ b/teamd/teamd_runner_activebackup.c @@ -520,6 +520,13 @@ static int ab_event_watch_port_link_changed(struct teamd_context *ctx, return ab_link_watch_handler(ctx, priv); } +static int ab_event_watch_port_master_ifindex_changed(struct teamd_context *ctx, + struct teamd_port *tdport, + void *priv) +{ + return ab_link_watch_handler(ctx, priv); +} + static int ab_event_watch_prio_option_changed(struct teamd_context *ctx, struct team_option *option, void *priv) @@ -532,6 +539,7 @@ static const struct teamd_event_watch_ops ab_event_watch_ops = { .port_hwaddr_changed = ab_event_watch_port_hwaddr_changed, .port_added = ab_event_watch_port_added, .port_link_changed = ab_event_watch_port_link_changed, + .port_master_ifindex_changed = ab_event_watch_port_master_ifindex_changed, .option_changed = ab_event_watch_prio_option_changed, .option_changed_match_name = "priority", };