From patchwork Mon Apr 15 08:56:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xin Long X-Patchwork-Id: 10900343 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 E601C17E1 for ; Mon, 15 Apr 2019 08:56:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CF90F28409 for ; Mon, 15 Apr 2019 08:56:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C36A7288AE; Mon, 15 Apr 2019 08:56:57 +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 544FE28409 for ; Mon, 15 Apr 2019 08:56:57 +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 6B4C76040BD7; Mon, 15 Apr 2019 08:56:56 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 bastion01.phx2.fedoraproject.org 6B4C76040BD7 Received: from mailman01.phx2.fedoraproject.org (localhost [IPv6:::1]) by mailman01.phx2.fedoraproject.org (Postfix) with ESMTP id 5030120089D46; Mon, 15 Apr 2019 08:56:56 +0000 (UTC) Received: by mailman01.phx2.fedoraproject.org (Postfix, from userid 991) id D8A8E20089D46; Mon, 15 Apr 2019 08:56:51 +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 BE5A720089D45 for ; Mon, 15 Apr 2019 08:56:50 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "GTS CA 1O1" (verified OK)) by smtp-mm-ib01.fedoraproject.org (Postfix) with ESMTPS id 55567605D2EB for ; Mon, 15 Apr 2019 08:56:50 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id e6so8255935pgc.4 for ; Mon, 15 Apr 2019 01:56:50 -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; bh=og2cBITzZCPLTGmaaqd1acNpDMKy/HXHjcw6m+FQPjE=; b=fe0hTAcG6DeuJy4Vnki2uIdZQrA81jzThDLT6FfbyxuoJwInFcWnET55Uw2XQfeYix bymVp0kinGTn9TVaYqvW04p67icjcuERrkq6y4/IJfmUtiey4GgpKHKP2Wr+RV1dsON+ MypejvWOyRasSF9CMBfawC6JQNEzpD2i7hlrmoIo9YXY6TgJnWVZ7ofwESlfjPxKB6cK 0dNsoFPK2wDSlNSsxoRUvILheE9XOT/Dvm8D/v0ockPyfdDd0Oi26BlCpE6rc0okiwFg B6+G7zyMAXQEo3LkUtRF9PpzFBBeKgASsQ3m09tG4OMGMmlin2XqeB8F+BhIhw3HHa1J nxjQ== X-Gm-Message-State: APjAAAU+oDOxWuckaOon/01C7DSzyD9bwTKhkxBEyUfeorOWM8rNOYov 3dVqYbGJmoGkQ2NWDgb0gqG3hvQg X-Google-Smtp-Source: APXvYqzV3WEfR6Pz7FN0KVkwwhJN0S0zRMZh0vYm47ZyqdN6RKtyeH5gtp0syb4vo63ksYZFpUKKjA== X-Received: by 2002:a63:be02:: with SMTP id l2mr65180083pgf.48.1555318608819; Mon, 15 Apr 2019 01:56:48 -0700 (PDT) Received: from localhost ([209.132.188.80]) by smtp.gmail.com with ESMTPSA id h187sm93989852pfc.52.2019.04.15.01.56.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 15 Apr 2019 01:56:48 -0700 (PDT) From: Xin Long To: libteam@lists.fedorahosted.org Subject: [PATCH] teamd: use enabled option_changed to sync enabled to link_up for lb runner Date: Mon, 15 Apr 2019 16:56:35 +0800 Message-Id: <6114637903690d18d7c61f12cade93d3c72850ed.1555318595.git.lucien.xin@gmail.com> X-Mailer: git-send-email 2.1.0 Message-ID-Hash: NT6B5E7VYQPN622TWTAMKL6U744UHQMQ X-Message-ID-Hash: NT6B5E7VYQPN622TWTAMKL6U744UHQMQ X-MailFrom: lucien.xin@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 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 LiLiang found an issue that after adding two ports into a team device with lb mode their enabled option sometimes is false. It was caused by the unexpected events order: 0. team_port_add() in kernel. 1. port_change event A1 sent to userspace. 2. option_change event B1 sent to userspace. 3. port_change event A2 sent to userspace IF port is up now. 4. process port_change event A1 and set port's enabled option 'false'. 5. option_change event B2 sent to userspace. 6. process option_change event B1 and sync enabled option (value = 1). 7. process port_change event A2 and do nothing as enabled option is 1. 8. process option_change event B2 and sync enabled option (value = 0). In kernel, when the port is still down after dev_open(), which happens more often since it changed to use netif_oper_up() to check the state instead of netif_carrier_ok(), the event A2 in Step 3 can be sent at any moment. When it's ahead of Step 4, Step 7 won't set enabled option to 1 as Step 8 comes late. As the port up event can be triggered by dev_watchdog at anytime in kernel, the port_change and option_change events order can not be controlled. What can only be done here is to correct it at Step 8, to sync enabled option to link_up. So this patch is to add enabled option_changed for lb mode to do this sync. Reported-by: LiLiang Signed-off-by: Xin Long --- teamd/teamd_runner_loadbalance.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/teamd/teamd_runner_loadbalance.c b/teamd/teamd_runner_loadbalance.c index b9bfc13..a581472 100644 --- a/teamd/teamd_runner_loadbalance.c +++ b/teamd/teamd_runner_loadbalance.c @@ -109,12 +109,27 @@ static int lb_event_watch_port_hwaddr_changed(struct teamd_context *ctx, return err; } +static int lb_event_watch_enabled_option_changed(struct teamd_context *ctx, + struct team_option *option, + void *priv) +{ + struct teamd_port *tdport; + + tdport = teamd_get_port(ctx, team_get_option_port_ifindex(option)); + if (!tdport) + return 0; + + return lb_event_watch_port_link_changed(ctx, tdport, priv); +} + static const struct teamd_event_watch_ops lb_port_watch_ops = { .hwaddr_changed = lb_event_watch_hwaddr_changed, .port_hwaddr_changed = lb_event_watch_port_hwaddr_changed, .port_added = lb_event_watch_port_added, .port_removed = lb_event_watch_port_removed, .port_link_changed = lb_event_watch_port_link_changed, + .option_changed = lb_event_watch_enabled_option_changed, + .option_changed_match_name = "enabled", }; static int lb_init(struct teamd_context *ctx, void *priv)