From patchwork Sun Oct 15 10:35:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 10007127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 89B2D601E9 for ; Sun, 15 Oct 2017 10:35:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7626828A17 for ; Sun, 15 Oct 2017 10:35:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6AEA728A4A; Sun, 15 Oct 2017 10:35:29 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID 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 CFE6328A17 for ; Sun, 15 Oct 2017 10:35:28 +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 9CDED6077DE4; Sun, 15 Oct 2017 10:35:27 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org 9CDED6077DE4 Authentication-Results: bastion01.phx2.fedoraproject.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="MhW9yPry" Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 7CEAD2174FFCC; Sun, 15 Oct 2017 10:35:27 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id 064A32174FFCF; Sun, 15 Oct 2017 10:35:22 +0000 (UTC) Received: from smtp-mm-osuosl01.fedoraproject.org (smtp-mm-osuosl01.vpn.fedoraproject.org [192.168.1.23]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id E2D962174FFCE for ; Sun, 15 Oct 2017 10:35:21 +0000 (UTC) Received: from mail-pf0-x242.google.com (mail-pf0-x242.google.com [IPv6:2607:f8b0:400e:c00::242]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by smtp-mm-osuosl01.fedoraproject.org (Postfix) with ESMTPS id 9B79998069 for ; Sun, 15 Oct 2017 10:35:21 +0000 (UTC) Received: by mail-pf0-x242.google.com with SMTP id z11so13679755pfk.4 for ; Sun, 15 Oct 2017 03:35:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=fyunxieDk9Vcdtvh1meZnmW1gtD6CNJdO3A7Y4fEUqY=; b=MhW9yPryGOzOxtbflovCQRU/Y2oAHzfsGWrMShisPIGl+s8w4cIOpR51BnHT43INqH 19wGn9u3Ey+c7evL6V5KG+GRPIkQfXhRmR23hSzaDqeoSwX3Cl0rBmQ9a0DuBdkw22e9 RBB5qyvqPH6DV03XB0Ef52GX/T8MqFoQUNQ3R3RNTFrj4sASjkhr9zKe2ejyQUoY1CUR EsiMza7VDEq/33MUhG06SIds3e2QvNYansKfsrPIQUj4QHy9TuducAxyqLekqtv4wvS1 jGSLzzOIY7GdZtv09YIEwFGM6QEAPMi+A9hfWDsvThIeWp0ELHlw1dCpYlRtPiYvM4sN PSJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=fyunxieDk9Vcdtvh1meZnmW1gtD6CNJdO3A7Y4fEUqY=; b=JBK8bfbOUCXwPopK2FD+vmGDc9ATADD/pcxbqiVD3ZyuInleFtJrBy0NbHUSC4REcY DiQdywy19wKkjoqEugfYxiJRpepywgohs8THAinzsoXtVp3++TEoXlwFFup32MB5pl51 REe1l7yWcgLpTFKlLn5dOSRM/KmkHhKR2rWvhH9joePK84wAsc48lEE17O0I87zLbt28 9divUbH3PKJvbDRIsQ6S9v5DOefGUNVU+RgB2LbZzfXnUrepwWKAQD4UlqC37A3LtVJs CEYZAev7SHoAlxS9jyyTVCvaIthHrtV2wlS9jrwgi+3tkJAsLa8OErLfH8abEBHl7Y+R aApA== X-Gm-Message-State: AMCzsaUbySj+TUPRR/8CZ88rAqoy5hq2o1uf+9bIq7NVWX1RIDi5Tc9n TzMycGe5Xs9ITizCplH0jKbWoN7K X-Google-Smtp-Source: AOwi7QCm1hnn14RRuyg41nTmf8RbbV2tq+b0p/97U3U0tX5Yzjxx428N9z0Jcz4cm7hSjiK5ez0d1A== X-Received: by 10.159.229.136 with SMTP id az8mr4641427plb.59.1508063720856; Sun, 15 Oct 2017 03:35:20 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id j12sm8513458pgs.35.2017.10.15.03.35.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Oct 2017 03:35:20 -0700 (PDT) From: Xin Long To: libteam@lists.fedorahosted.org, Jiri Pirko Subject: [PATCH] teamd: add port_hwaddr_changed for ab runner Date: Sun, 15 Oct 2017 18:35:12 +0800 Message-Id: <0acf53a1f5177bc3c45c25726f14680eb9ca4243.1508063712.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 Message-ID-Hash: GUYIGLKH2TLJUSQ5DWOGDQLZPVBLKHEV X-Message-ID-Hash: GUYIGLKH2TLJUSQ5DWOGDQLZPVBLKHEV X-MailFrom: lucien.xin@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; 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 X-Mailman-Version: 3.1.0 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 This patch to fix a events processing race issue when adding two ports into one team dev with ab mode with same_all hwaddr policy: team0 original hwaddr: 00:00:00:00:00:0a port1 original hwaddr: 00:00:00:00:00:01 port2 original hwaddr: 00:00:00:00:00:02 There are two sockets in teamd: nl_cli.sock_event for ifinfo updates and nl_sock_event for ports/options changes. Druing adding two ports, the events on these two sockets could be: nl_sock_event: [1] -- [2] -- [1]: port1 added event (added by enslaving port1) [2]: port2 added event (added by enslaving port2) nl_cli.sock_event: [a1] -- [b0] -- [c1] -- [d2] -- [e2] -- [f1] -- [a1]: port1 ifinfo event (added by setting port1's master) [b0]: team0 ifinfo event (added by setting team0's hwaddr) [c1]: port1 ifinfo event (added by set port1's hwaddr) [d2]: port2 ifinfo event (added by set port2's master) [e2]: port2 ifinfo event (added by set port2's hwaddr) [f1]: port1 ifinfo event (added by set port1's hwaddr) teamd can make sure the order for their processing is as above on the same socket, but not between two sockets. So if these events processing order is (monitoring team/ports' ifinfo, hwaddr, master): [ 1]: team0->ifinfo = 00:00:00:00:00:0a team0->hwaddr = 00:00:00:00:00:01 port1->hwaddr = 00:00:00:00:00:0a [a1]: port1->ifinfo = 00:00:00:00:00:01 port1->master = team0 [ 2]: port2->ifinfo = 00:00:00:00:00:02 port2->hwaddr = 00:00:00:00:00:0a (team0->ifinfo is not set updated, it's still 00:00:00:00:00:0a) [b0]: team0->ifinfo = 00:00:00:00:00:01 port1->hwaddr = 00:00:00:00:00:01 (port2->master is not yet set, port2->hwaddr couldn't be updated) [c1]: no changes [d2]: port2->ifinfo = 00:00:00:00:00:0a port2->master = team0 (too late !!!) [e2]: no changes [f1]: no changes Then: team0 final hwaddr: 00:00:00:00:00:01 port1 final hwaddr: 00:00:00:00:00:01 port2 final hwaddr: 00:00:00:00:00:0a <----- issue This patch is to add port_hwaddr_changed for ab runner, in [e2] where we set it's hwaddr with team0 (port2->hwaddr = 00:00:00:00:00:01) IF port2->hwaddr != team0->ifinfo. I think the same issue also exists in lacp and lb mode for which I will fix them in another patches. Reported-by: Jon Nikolakakis Signed-off-by: Xin Long --- teamd/teamd_runner_activebackup.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) -- 2.1.0 diff --git a/teamd/teamd_runner_activebackup.c b/teamd/teamd_runner_activebackup.c index aec3a73..2745a4f 100644 --- a/teamd/teamd_runner_activebackup.c +++ b/teamd/teamd_runner_activebackup.c @@ -39,6 +39,8 @@ struct ab_hwaddr_policy { const char *name; int (*hwaddr_changed)(struct teamd_context *ctx, struct ab *ab); + int (*port_hwaddr_changed)(struct teamd_context *ctx, struct ab *ab, + struct teamd_port *tdport); int (*port_added)(struct teamd_context *ctx, struct ab *ab, struct teamd_port *tdport); int (*active_set)(struct teamd_context *ctx, struct ab *ab, @@ -95,6 +97,26 @@ static int ab_hwaddr_policy_same_all_hwaddr_changed(struct teamd_context *ctx, return 0; } +static int ab_hwaddr_policy_same_all_port_hwaddr_changed( + struct teamd_context *ctx, + struct ab *ab, + struct teamd_port *tdport) +{ + int err; + + if (!memcmp(team_get_ifinfo_hwaddr(tdport->team_ifinfo), + ctx->hwaddr, ctx->hwaddr_len)) + return 0; + + err = team_hwaddr_set(ctx->th, tdport->ifindex, ctx->hwaddr, + ctx->hwaddr_len); + if (err) + teamd_log_err("%s: Failed to set port hardware address.", + tdport->ifname); + + return err; +} + static int ab_hwaddr_policy_same_all_port_added(struct teamd_context *ctx, struct ab *ab, struct teamd_port *tdport) @@ -114,6 +136,7 @@ static int ab_hwaddr_policy_same_all_port_added(struct teamd_context *ctx, static const struct ab_hwaddr_policy ab_hwaddr_policy_same_all = { .name = "same_all", .hwaddr_changed = ab_hwaddr_policy_same_all_hwaddr_changed, + .port_hwaddr_changed = ab_hwaddr_policy_same_all_port_hwaddr_changed, .port_added = ab_hwaddr_policy_same_all_port_added, }; @@ -411,6 +434,21 @@ static int ab_event_watch_hwaddr_changed(struct teamd_context *ctx, void *priv) return 0; } +static int ab_event_watch_port_hwaddr_changed(struct teamd_context *ctx, + struct teamd_port *tdport, + void *priv) +{ + struct ab *ab = priv; + + if (!teamd_port_present(ctx, tdport)) + return 0; + + if (ab->hwaddr_policy->port_hwaddr_changed) + return ab->hwaddr_policy->port_hwaddr_changed(ctx, ab, tdport); + + return 0; +} + static int ab_port_load_config(struct teamd_context *ctx, struct ab_port *ab_port) { @@ -491,6 +529,7 @@ static int ab_event_watch_prio_option_changed(struct teamd_context *ctx, static const struct teamd_event_watch_ops ab_event_watch_ops = { .hwaddr_changed = ab_event_watch_hwaddr_changed, + .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, .option_changed = ab_event_watch_prio_option_changed,